[FEM] electrostatic dialog revision

- use a quantity spinbox and do simple signal/slot handling in the UI file
This commit is contained in:
Uwe
2022-03-19 05:01:23 +01:00
parent aba3d40b2f
commit c360c6e5f5
2 changed files with 57 additions and 49 deletions

View File

@@ -16,13 +16,10 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="3">
<widget class="QCheckBox" name="potentialBox">
<item row="0" column="0">
<widget class="QLabel" name="potentialLbl">
<property name="text">
<string>unspecified</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Potential:</string>
</property>
</widget>
</item>
@@ -39,26 +36,47 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="potentialLbl">
<property name="text">
<string>Potential:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::InputField" name="potentialTxt">
<widget class="Gui::QuantitySpinBox" name="potentialQSB" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>1 V</string>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Electric potential in V</string>
</property>
<property name="keyboardTracking" stdset="0">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true">V</string>
</property>
<property name="minimum" stdset="0">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum" stdset="0">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep" stdset="0">
<double>1.000000000000000</double>
</property>
<property name="unit" stdset="0">
<string>V</string>
<property name="value" stdset="0">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QCheckBox" name="potentialBox">
<property name="text">
<string>unspecified</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
@@ -154,42 +172,42 @@
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>potentialBox</sender>
<sender>capacitanceBodyBox</sender>
<signal>toggled(bool)</signal>
<receiver>potentialTxt</receiver>
<slot>setEnabled(bool)</slot>
<receiver>capacitanceBody_spinBox</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>230</x>
<y>44</y>
<x>262</x>
<y>116</y>
</hint>
<hint type="destinationlabel">
<x>230</x>
<y>18</y>
<x>323</x>
<y>116</y>
</hint>
</hints>
</connection>
<connection>
<sender>potentialBox</sender>
<signal>toggled(bool)</signal>
<receiver>potentialTxt</receiver>
<receiver>potentialQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>230</x>
<y>44</y>
<x>301</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>230</x>
<y>18</y>
<x>206</x>
<y>19</y>
</hint>
</hints>
</connection>

View File

@@ -58,11 +58,6 @@ class _TaskPanel(object):
self._part = femutils.get_part_to_mesh(self._mesh)
self._partVisible = None
self._meshVisible = None
QtCore.QObject.connect(
self._paramWidget.capacitanceBodyBox,
QtCore.SIGNAL("stateChanged(int)"),
self.capacitanceBodyBox_checked
)
def open(self):
if self._mesh is not None and self._part is not None:
@@ -99,9 +94,8 @@ class _TaskPanel(object):
def _initParamWidget(self):
unit = "V"
q = Units.Quantity("{} {}".format(self._obj.Potential, unit))
self._paramWidget.potentialTxt.setText(
q.UserString)
self._paramWidget.potentialQSB.setProperty(
'rawValue', q.Value)
self._paramWidget.potentialBox.setChecked(
not self._obj.PotentialEnabled)
self._paramWidget.potentialConstantBox.setChecked(
@@ -127,9 +121,9 @@ class _TaskPanel(object):
if self._obj.PotentialEnabled:
# if the input widget shows not a green hook, but the user presses ok
# we could run into a syntax error on getting the quantity
quantity = None
potential = None
try:
quantity = Units.Quantity(self._paramWidget.potentialTxt.text())
potential = Units.Quantity(self._paramWidget.potentialQSB.text())
except ValueError:
FreeCAD.Console.PrintMessage(
"Wrong input. OK has been triggered without a green hook "
@@ -137,8 +131,8 @@ class _TaskPanel(object):
"Potential has not been set.\n"
.format(self._paramWidget.potentialTxt.text())
)
if quantity is not None:
self._obj.Potential = quantity.getValueAs(unit).Value
if potential is not None:
self._obj.Potential = potential.getValueAs(unit).Value
self._obj.PotentialConstant = self._paramWidget.potentialConstantBox.isChecked()
@@ -152,7 +146,3 @@ class _TaskPanel(object):
if self._obj.CapacitanceBodyEnabled:
self._paramWidget.capacitanceBody_spinBox.setEnabled(True)
self._obj.CapacitanceBody = self._paramWidget.capacitanceBody_spinBox.value()
def capacitanceBodyBox_checked(self, i):
self._paramWidget.capacitanceBody_spinBox.setEnabled(
not self._paramWidget.capacitanceBodyBox.isChecked())