From 33e4a5baede0b9bc92e1ef87ec478212a2a483e1 Mon Sep 17 00:00:00 2001 From: marioalexis84 <53127171+marioalexis84@users.noreply.github.com> Date: Mon, 20 May 2024 13:00:48 -0300 Subject: [PATCH] Fem: Improve constraint section print (#14046) Co-authored-by: Chris Hennes --- src/Mod/Fem/Gui/CMakeLists.txt | 1 + .../symbols/ConstraintSectionPrint.iv | 19 +++++++++++ .../Resources/ui/ConstraintSectionPrint.ui | 34 ++++++++++++++----- .../Fem/femobjects/constraint_sectionprint.py | 28 +++++++++++++++ .../calculix/write_constraint_sectionprint.py | 10 +++++- .../task_constraint_sectionprint.py | 27 ++++++++++++--- .../view_constraint_sectionprint.py | 10 ++++++ 7 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 src/Mod/Fem/Gui/Resources/symbols/ConstraintSectionPrint.iv diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 65d871e137..b86972b82a 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -361,6 +361,7 @@ SET(FemGuiSymbol_IV Resources/symbols/ConstraintPlaneRotation.iv Resources/symbols/ConstraintPressure.iv Resources/symbols/ConstraintRigidBody.iv + Resources/symbols/ConstraintSectionPrint.iv Resources/symbols/ConstraintSpring.iv Resources/symbols/ConstraintTemperature.iv Resources/symbols/ConstraintTie.iv diff --git a/src/Mod/Fem/Gui/Resources/symbols/ConstraintSectionPrint.iv b/src/Mod/Fem/Gui/Resources/symbols/ConstraintSectionPrint.iv new file mode 100644 index 0000000000..ddcb93fae9 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/symbols/ConstraintSectionPrint.iv @@ -0,0 +1,19 @@ +#Inventor V2.1 ascii + + +Separator { + + Separator { + + Translation { + translation 0 0.05 0 + + } + Cube { + width 0.75 + height 0.1 + depth 0.75 + + } + } +} diff --git a/src/Mod/Fem/Gui/Resources/ui/ConstraintSectionPrint.ui b/src/Mod/Fem/Gui/Resources/ui/ConstraintSectionPrint.ui index bdcc1d2c55..3e40f33bb6 100644 --- a/src/Mod/Fem/Gui/Resources/ui/ConstraintSectionPrint.ui +++ b/src/Mod/Fem/Gui/Resources/ui/ConstraintSectionPrint.ui @@ -15,17 +15,33 @@ - - - Qt::Vertical + + + + 0 + 0 + - - - 20 - 40 - + + Parameter - + + + + + + + Variable + + + + + + + + + + diff --git a/src/Mod/Fem/femobjects/constraint_sectionprint.py b/src/Mod/Fem/femobjects/constraint_sectionprint.py index ce3a816bed..8fbbeee087 100644 --- a/src/Mod/Fem/femobjects/constraint_sectionprint.py +++ b/src/Mod/Fem/femobjects/constraint_sectionprint.py @@ -31,6 +31,7 @@ __url__ = "https://www.freecad.org" from . import base_fempythonobject +_PropHelper = base_fempythonobject._PropHelper class ConstraintSectionPrint(base_fempythonobject.BaseFemPythonObject): """ @@ -41,3 +42,30 @@ class ConstraintSectionPrint(base_fempythonobject.BaseFemPythonObject): def __init__(self, obj): super(ConstraintSectionPrint, self).__init__(obj) + + for prop in self._get_properties(): + prop.add_to_object(obj) + + + def _get_properties(self): + prop = [] + + prop.append(_PropHelper( + type = "App::PropertyEnumeration", + name = "Variable", + group = "Constraint Section Print", + doc = "Set facial variable", + value = ["Section Force", "Heat Flux", "Drag Stress"] + ) + ) + + return prop + + + def onDocumentRestored(self, obj): + # update old project with new properties + for prop in self._get_properties(): + try: + obj.getPropertyByName(prop.name) + except: + prop.add_to_object(obj) diff --git a/src/Mod/Fem/femsolver/calculix/write_constraint_sectionprint.py b/src/Mod/Fem/femsolver/calculix/write_constraint_sectionprint.py index d791f14dfd..079385e8f6 100644 --- a/src/Mod/Fem/femsolver/calculix/write_constraint_sectionprint.py +++ b/src/Mod/Fem/femsolver/calculix/write_constraint_sectionprint.py @@ -64,8 +64,16 @@ def write_constraint(f, femobj, sectionprint_obj, ccxwriter): # floats read from ccx should use {:.13G}, see comment in writer module + variable = sectionprint_obj.Variable + if variable == "Section Force": + key = "SOF, SOM, SOAREA" + elif variable == "Heat Flux": + key = "FLUX" + elif variable == "Drag Stress": + key = "DRAG" + f.write( "*SECTION PRINT, SURFACE=SECTIONFACE{}, NAME=SECTIONPRINT{}\n" .format(sectionprint_obj.Name, sectionprint_obj.Name) ) - f.write("SOF, SOM, SOAREA\n") + f.write(key + "\n") diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_sectionprint.py b/src/Mod/Fem/femtaskpanels/task_constraint_sectionprint.py index 6948b4ba7c..b9ff745306 100644 --- a/src/Mod/Fem/femtaskpanels/task_constraint_sectionprint.py +++ b/src/Mod/Fem/femtaskpanels/task_constraint_sectionprint.py @@ -29,6 +29,7 @@ __url__ = "https://www.freecad.org" # \ingroup FEM # \brief task panel for constraint section print object +from PySide import QtCore from PySide import QtGui import FreeCAD @@ -52,6 +53,14 @@ class _TaskPanel: FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/ConstraintSectionPrint.ui" ) + self.init_parameter_widget() + + QtCore.QObject.connect( + self.parameterWidget.cb_variable, + QtCore.SIGNAL("currentIndexChanged(int)"), + self.variable_changed + ) + # geometry selection widget self.selectionWidget = selection_widgets.GeometryElementsSelection( obj.References, @@ -61,15 +70,11 @@ class _TaskPanel: ) # form made from param and selection widget - self.form = [self.parameterWidget, self.selectionWidget] + self.form = [self.selectionWidget, self.parameterWidget] def accept(self): # check values items = len(self.selectionWidget.references) - FreeCAD.Console.PrintMessage( - "Task panel: found references: {}\n{}\n" - .format(items, self.selectionWidget.references) - ) if items != 1: msgBox = QtGui.QMessageBox() @@ -87,6 +92,8 @@ class _TaskPanel: return False elif msgBox.clickedButton() == ignoreButton: pass + + self.obj.Variable = self.variable self.obj.References = self.selectionWidget.references self.recompute_and_set_back_all() return True @@ -102,3 +109,13 @@ class _TaskPanel: if self.selectionWidget.sel_server: FreeCADGui.Selection.removeObserver(self.selectionWidget.sel_server) doc.resetEdit() + + def init_parameter_widget(self): + self.variable = self.obj.Variable + self.variable_enum = self.obj.getEnumerationsOfProperty("Variable") + self.parameterWidget.cb_variable.addItems(self.variable_enum) + index = self.variable_enum.index(self.variable) + self.parameterWidget.cb_variable.setCurrentIndex(index) + + def variable_changed(self, index): + self.variable = self.variable_enum[index] diff --git a/src/Mod/Fem/femviewprovider/view_constraint_sectionprint.py b/src/Mod/Fem/femviewprovider/view_constraint_sectionprint.py index ea71654b17..f4f5f703d5 100644 --- a/src/Mod/Fem/femviewprovider/view_constraint_sectionprint.py +++ b/src/Mod/Fem/femviewprovider/view_constraint_sectionprint.py @@ -38,6 +38,12 @@ class VPConstraintSectionPrint(view_base_femconstraint.VPBaseFemConstraint): A View Provider for the ConstraintSectionPrint object """ + def __init__(self, vobj): + super().__init__(vobj) + mat = vobj.ShapeAppearance[0] + mat.DiffuseColor = (0.0, 0.165, 1.0, 0.0) + vobj.ShapeAppearance = mat + def setEdit(self, vobj, mode=0): view_base_femconstraint.VPBaseFemConstraint.setEdit( self, @@ -45,3 +51,7 @@ class VPConstraintSectionPrint(view_base_femconstraint.VPBaseFemConstraint): mode, task_constraint_sectionprint._TaskPanel ) + + def attach(self, vobj): + super().attach(vobj) + vobj.loadSymbol(self.resource_symbol_dir + "ConstraintSectionPrint.iv")