Fem: Enable expression for the centrif constraint task panel

This commit is contained in:
marioalexis
2024-10-08 16:46:40 -03:00
committed by Chris Hennes
parent d94c65ba3f
commit a5720ec496
3 changed files with 68 additions and 87 deletions

View File

@@ -28,71 +28,29 @@
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="l_rotation_frequency">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Rotation frequency f&lt;sub&gt;rot&lt;/sub&gt; [rps]</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
<property name="indent">
<number>-1</number>
<string>Rotation Frequency:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::InputField" name="if_rotation_frequency">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>revolutions per second</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>0 1/s</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000.000000000000000</double>
</property>
<widget class="Gui::QuantitySpinBox" name="qsb_rotation_frequency">
<property name="unit" stdset="0">
<string>1/s</string>
</property>
<property name="decimals" stdset="0">
<number>2</number>
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="toolTip">
<string>Revolutions per second</string>
</property>
<property name="alignment">
<set>Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
@@ -108,9 +66,9 @@
</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/>

View File

@@ -31,6 +31,8 @@ __url__ = "https://www.freecad.org"
from . import base_fempythonobject
_PropHelper = base_fempythonobject._PropHelper
class ConstraintCentrif(base_fempythonobject.BaseFemPythonObject):
"""
@@ -42,18 +44,36 @@ class ConstraintCentrif(base_fempythonobject.BaseFemPythonObject):
def __init__(self, obj):
super().__init__(obj)
obj.addProperty(
"App::PropertyFrequency",
"RotationFrequency",
"Constraint CENTRIF",
"set rotation frequency f<sub>rot",
)
obj.setPropertyStatus("RotationFrequency", "LockDynamic")
for prop in self._get_properties():
prop.add_to_object(obj)
obj.addProperty(
"App::PropertyLinkSubList",
"RotationAxis",
"Constraint CENTRIF",
"set line as axis of rotation",
def _get_properties(self):
prop = []
prop.append(
_PropHelper(
type="App::PropertyFrequency",
name="RotationFrequency",
group="Constraint Centrif",
doc="Set rotation frequency",
value="0 1/s",
)
)
obj.setPropertyStatus("RotationAxis", "LockDynamic")
prop.append(
_PropHelper(
type="App::PropertyLinkSubListGlobal",
name="RotationAxis",
group="Constraint Centrif",
doc="Set line as axis of rotation",
value=[],
)
)
return prop
def onDocumentRestored(self, obj):
# update old project with new properties
for prop in self._get_properties():
if prop.name == "RotationAxis":
# change RotationAxis to App::PropertyLinkSubListGlobal
prop.handle_change_type(obj, old_type="App::PropertyLinkSubList")

View File

@@ -48,35 +48,35 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
super().__init__(obj)
# parameter widget
self.parameterWidget = FreeCADGui.PySideUic.loadUi(
self.parameter_widget = FreeCADGui.PySideUic.loadUi(
FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/ConstraintCentrif.ui"
)
QtCore.QObject.connect(
self.parameterWidget.if_rotation_frequency,
self.parameter_widget.qsb_rotation_frequency,
QtCore.SIGNAL("valueChanged(Base::Quantity)"),
self.rotation_frequency_changed,
)
self.init_parameter_widget()
# axis of rotation selection widget
self.AxisSelectionWidget = selection_widgets.GeometryElementsSelection(
self.axis_selection_widget = selection_widgets.GeometryElementsSelection(
obj.RotationAxis, ["Edge"], False, False
)
# loaded body selection widget
self.BodySelectionWidget = selection_widgets.GeometryElementsSelection(
self.body_selection_widget = selection_widgets.GeometryElementsSelection(
obj.References, ["Solid"], False, False
)
# form made from param and selection widget
self.form = [self.parameterWidget, self.BodySelectionWidget, self.AxisSelectionWidget]
self.form = [self.parameter_widget, self.body_selection_widget, self.axis_selection_widget]
def accept(self):
# check values RotationAxis
items = len(self.AxisSelectionWidget.references)
items = len(self.axis_selection_widget.references)
FreeCAD.Console.PrintMessage(
"Task panel: found axis references: {}\n{}\n".format(
items, self.AxisSelectionWidget.references
items, self.axis_selection_widget.references
)
)
@@ -97,10 +97,10 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
pass
# check values BodyReference
items = len(self.BodySelectionWidget.references)
items = len(self.body_selection_widget.references)
FreeCAD.Console.PrintMessage(
"Task panel: found body references: {}\n{}\n".format(
items, self.BodySelectionWidget.references
items, self.body_selection_widget.references
)
)
@@ -137,20 +137,23 @@ class _TaskPanel(base_femtaskpanel._BaseTaskPanel):
pass
self.obj.RotationFrequency = self.rotation_frequency
self.obj.RotationAxis = self.AxisSelectionWidget.references
self.obj.References = self.BodySelectionWidget.references
self.AxisSelectionWidget.finish_selection()
self.BodySelectionWidget.finish_selection()
self.obj.RotationAxis = self.axis_selection_widget.references
self.obj.References = self.body_selection_widget.references
self.axis_selection_widget.finish_selection()
self.body_selection_widget.finish_selection()
return super().accept()
def reject(self):
self.AxisSelectionWidget.finish_selection()
self.BodySelectionWidget.finish_selection()
self.axis_selection_widget.finish_selection()
self.body_selection_widget.finish_selection()
return super().reject()
def init_parameter_widget(self):
self.rotation_frequency = self.obj.RotationFrequency
self.parameterWidget.if_rotation_frequency.setText(self.rotation_frequency.UserString)
FreeCADGui.ExpressionBinding(self.parameter_widget.qsb_rotation_frequency).bind(
self.obj, "RotationFrequency"
)
self.parameter_widget.qsb_rotation_frequency.setProperty("value", self.rotation_frequency)
def rotation_frequency_changed(self, base_quantity_value):
self.rotation_frequency = base_quantity_value