diff --git a/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui b/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui index e1756e8ecb..e658e30b70 100644 --- a/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui +++ b/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui @@ -28,71 +28,29 @@ - - 4 - - - - 0 - 0 - - - Rotation frequency f<sub>rot</sub> [rps] - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 0 - - - -1 + Rotation Frequency: - - - - 0 - 0 - - - - - 80 - 20 - - - - revolutions per second - - - Qt::LeftToRight - - - 0 1/s - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 1.000000000000000 - - - 1000000000.000000000000000 - + 1/s - - 2 + + 0.000000000000000 + + + Revolutions per second + + + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter + + + 1.000000000000000 0.000000000000000 @@ -108,9 +66,9 @@ - Gui::InputField - QLineEdit -
Gui/InputField.h
+ Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
diff --git a/src/Mod/Fem/femobjects/constraint_centrif.py b/src/Mod/Fem/femobjects/constraint_centrif.py index e2ef2b63d9..8b6569083d 100644 --- a/src/Mod/Fem/femobjects/constraint_centrif.py +++ b/src/Mod/Fem/femobjects/constraint_centrif.py @@ -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 frot", - ) - 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") diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py b/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py index f05498d72f..bf7def12ab 100644 --- a/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py +++ b/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py @@ -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