Skip to content

Commit 42dfaa6

Browse files
authored
Merge pull request #9 from SebGue/SlotM15_GUI
[NF] GUI SlotM15
2 parents 805587d + 20fbf3a commit 42dfaa6

File tree

8 files changed

+774
-69
lines changed

8 files changed

+774
-69
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
"""File generated according to PMSlot15/gen_list.json
3+
WARNING! All changes made in this file will be lost!
4+
"""
5+
from pyleecan.GUI.Dialog.DMachineSetup.SMSlot.PMSlot15.Ui_PMSlot15 import Ui_PMSlot15
6+
7+
8+
class Gen_PMSlot15(Ui_PMSlot15):
9+
def setupUi(self, PMSlot15):
10+
"""Abstract class to update the widget according to the csv doc"""
11+
Ui_PMSlot15.setupUi(self, PMSlot15)
12+
# Setup of in_W0
13+
txt = self.tr(u"""Slot isthmus angular width.""")
14+
self.in_W0.setWhatsThis(txt)
15+
self.in_W0.setToolTip(txt)
16+
17+
# Setup of lf_W0
18+
self.lf_W0.validator().setBottom(0)
19+
txt = self.tr(u"""Slot isthmus angular width.""")
20+
self.lf_W0.setWhatsThis(txt)
21+
self.lf_W0.setToolTip(txt)
22+
23+
# Setup of in_Wmag
24+
txt = self.tr(u"""Magnet width""")
25+
self.in_Wmag.setWhatsThis(txt)
26+
self.in_Wmag.setToolTip(txt)
27+
28+
# Setup of lf_Wmag
29+
self.lf_Wmag.validator().setBottom(0)
30+
txt = self.tr(u"""Magnet width""")
31+
self.lf_Wmag.setWhatsThis(txt)
32+
self.lf_Wmag.setToolTip(txt)
33+
34+
# Setup of in_H0
35+
txt = self.tr(u"""Slot isthmus height.""")
36+
self.in_H0.setWhatsThis(txt)
37+
self.in_H0.setToolTip(txt)
38+
39+
# Setup of lf_H0
40+
self.lf_H0.validator().setBottom(0)
41+
txt = self.tr(u"""Slot isthmus height.""")
42+
self.lf_H0.setWhatsThis(txt)
43+
self.lf_H0.setToolTip(txt)
44+
45+
# Setup of in_Hmag
46+
txt = self.tr(u"""Magnet Height""")
47+
self.in_Hmag.setWhatsThis(txt)
48+
self.in_Hmag.setToolTip(txt)
49+
50+
# Setup of lf_Hmag
51+
self.lf_Hmag.validator().setBottom(0)
52+
txt = self.tr(u"""Magnet Height""")
53+
self.lf_Hmag.setWhatsThis(txt)
54+
self.lf_Hmag.setToolTip(txt)
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import PySide2.QtCore
4+
from numpy import pi
5+
from PySide2.QtCore import Signal
6+
from PySide2.QtWidgets import QWidget
7+
8+
from ......Classes.SlotM15 import SlotM15
9+
from ......GUI import gui_option
10+
from ......GUI.Dialog.DMachineSetup.SMSlot.PMSlot15.Gen_PMSlot15 import Gen_PMSlot15
11+
from ......Methods.Slot.Slot import SlotCheckError
12+
13+
translate = PySide2.QtCore.QCoreApplication.translate
14+
15+
16+
class PMSlot15(Gen_PMSlot15, QWidget):
17+
"""Page to set the Slot Magnet Type 14"""
18+
19+
# Signal to DMachineSetup to know that the save popup is needed
20+
saveNeeded = Signal()
21+
# Information for Slot combobox
22+
slot_name = "Polar Magnet with curved top and parallel sides"
23+
slot_type = SlotM15
24+
25+
def __init__(self, lamination=None):
26+
"""Initialize the widget according to lamination
27+
28+
Parameters
29+
----------
30+
self : PMSlot15
31+
A PMSlot15 widget
32+
lamination : Lamination
33+
current lamination to edit
34+
"""
35+
36+
# Build the interface according to the .ui file
37+
QWidget.__init__(self)
38+
self.setupUi(self)
39+
self.lamination = lamination
40+
self.slot = lamination.slot
41+
42+
# Set FloatEdit unit
43+
self.lf_W0.unit = "rad"
44+
self.lf_Wmag.unit = "m"
45+
self.lf_H0.unit = "m"
46+
self.lf_Hmag.unit = "m"
47+
self.lf_Rtopm.unit = "m"
48+
# Set unit name (m ou mm)
49+
wid_list = [
50+
self.unit_H0,
51+
self.unit_Hmag,
52+
self.unit_Rtopm,
53+
]
54+
for wid in wid_list:
55+
wid.setText("[" + gui_option.unit.get_m_name() + "]")
56+
57+
# Fill the fields with the machine values (if they're filled)
58+
self.lf_W0.setValue(self.slot.W0)
59+
self.lf_Wmag.setValue(self.slot.Wmag)
60+
self.lf_H0.setValue(self.slot.H0)
61+
self.lf_Hmag.setValue(self.slot.Hmag)
62+
self.lf_Rtopm.setValue(self.slot.Rtopm)
63+
64+
# Display the main output of the slot (surface, height...)
65+
self.w_out.comp_output()
66+
67+
# Connect the signal
68+
self.lf_W0.editingFinished.connect(self.set_W0)
69+
self.lf_Wmag.editingFinished.connect(self.set_Wmag)
70+
self.lf_H0.editingFinished.connect(self.set_H0)
71+
self.lf_Hmag.editingFinished.connect(self.set_Hmag)
72+
self.lf_Rtopm.editingFinished.connect(self.set_Rtopm)
73+
74+
def set_W0(self):
75+
"""Signal to update the value of W0 according to the line edit
76+
77+
Parameters
78+
----------
79+
self : PMSlot15
80+
A PMSlot15 object
81+
"""
82+
self.slot.W0 = self.lf_W0.value()
83+
self.w_out.comp_output()
84+
# Notify the machine GUI that the machine has changed
85+
self.saveNeeded.emit()
86+
87+
def set_Wmag(self):
88+
"""Signal to update the value of Wmag according to the line edit
89+
90+
Parameters
91+
----------
92+
self : PMSlot15
93+
A PMSlot15 object
94+
"""
95+
self.slot.Wmag = self.lf_Wmag.value()
96+
self.w_out.comp_output()
97+
# Notify the machine GUI that the machine has changed
98+
self.saveNeeded.emit()
99+
100+
def set_H0(self):
101+
"""Signal to update the value of H0 according to the line edit
102+
103+
Parameters
104+
----------
105+
self : PMSlot15
106+
A PMSlot15 object
107+
"""
108+
self.slot.H0 = self.lf_H0.value()
109+
self.w_out.comp_output()
110+
# Notify the machine GUI that the machine has changed
111+
self.saveNeeded.emit()
112+
113+
def set_Hmag(self):
114+
"""Signal to update the value of Hmag according to the line edit
115+
116+
Parameters
117+
----------
118+
self : PMSlot15
119+
A PMSlot15 object
120+
"""
121+
self.slot.Hmag = self.lf_Hmag.value()
122+
self.w_out.comp_output()
123+
# Notify the machine GUI that the machine has changed
124+
self.saveNeeded.emit()
125+
126+
def set_Rtopm(self):
127+
"""Signal to update the value of Rtopm according to the line edit
128+
129+
Parameters
130+
----------
131+
self : PMSlot15
132+
A PMSlot15 object
133+
"""
134+
self.slot.Rtopm = self.lf_Rtopm.value()
135+
self.w_out.comp_output()
136+
# Notify the machine GUI that the machine has changed
137+
self.saveNeeded.emit()
138+
139+
@staticmethod
140+
def check(lam):
141+
"""Check that the current machine have all the needed field set
142+
143+
Parameters
144+
----------
145+
lam: LamSlotMag
146+
Lamination to check
147+
148+
Returns
149+
-------
150+
error: str
151+
Error message (return None if no error)
152+
"""
153+
154+
# Check that everything is set
155+
if lam.slot.W0 is None:
156+
return "You must set W0 !"
157+
elif lam.slot.Wmag is None:
158+
return "You must set Wmag !"
159+
elif lam.slot.H0 is None:
160+
return "You must set H0 !"
161+
elif lam.slot.Hmag is None:
162+
return "You must set Hmag !"
163+
elif lam.slot.Rtopm is None:
164+
return "You must set Rtopm !"
165+
166+
# Constraints
167+
try:
168+
lam.slot.check()
169+
except SlotCheckError as error:
170+
return str(error)
171+
172+
# Output
173+
try:
174+
yoke_height = lam.comp_height_yoke()
175+
except Exception as error:
176+
return translate("Unable to compute yoke height:", "PMSlot15") + str(error)
177+
178+
if yoke_height <= 0:
179+
return translate(
180+
"The slot height is greater than the lamination !", "PMSlot15"
181+
)

0 commit comments

Comments
 (0)