From ce69c1531d358e0565aa680f8853b7801c5bf63e Mon Sep 17 00:00:00 2001 From: Markus Hovorka Date: Fri, 1 Dec 2017 19:43:36 +0100 Subject: [PATCH] FEM: constraint flow velocity, add object, command, icon, task panel, etc --- src/Mod/Fem/App/CMakeLists.txt | 4 + src/Mod/Fem/CMakeLists.txt | 4 + src/Mod/Fem/Gui/Resources/Fem.qrc | 1 + .../icons/fem-constraint-flow-velocity.svg | 76 ++++++ src/Mod/Fem/Gui/Workbench.cpp | 6 +- src/Mod/Fem/InitGui.py | 1 + src/Mod/Fem/ObjectsFem.py | 11 + src/Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui | 234 ++++++++++++++++++ .../_CommandFemConstraintFlowVelocity.py | 59 +++++ .../_ViewProviderFemConstraintFlowVelocity.py | 137 ++++++++++ .../PyObjects/_FemConstraintFlowVelocity.py | 58 +++++ 11 files changed, 589 insertions(+), 2 deletions(-) create mode 100644 src/Mod/Fem/Gui/Resources/icons/fem-constraint-flow-velocity.svg create mode 100644 src/Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui create mode 100644 src/Mod/Fem/PyGui/_CommandFemConstraintFlowVelocity.py create mode 100644 src/Mod/Fem/PyGui/_ViewProviderFemConstraintFlowVelocity.py create mode 100644 src/Mod/Fem/PyObjects/_FemConstraintFlowVelocity.py diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index 191ce1b4f0..edfdc3cb66 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -101,6 +101,7 @@ SET(FemObjectsScripts_SRCS PyObjects/__init__.py PyObjects/_FemConstraintSelfWeight.py PyObjects/_FemConstraintBodyHeatSource.py + PyObjects/_FemConstraintFlowVelocity.py PyObjects/_FemElementFluid1D.py PyObjects/_FemElementGeometry1D.py PyObjects/_FemElementGeometry2D.py @@ -148,6 +149,7 @@ SET(FemGuiScripts_SRCS PyGui/_CommandFemAnalysis.py PyGui/_CommandFemConstraintSelfWeight.py PyGui/_CommandFemConstraintBodyHeatSource.py + PyGui/_CommandFemConstraintFlowVelocity.py PyGui/_CommandFemElementFluid1D.py PyGui/_CommandFemElementGeometry1D.py PyGui/_CommandFemElementGeometry2D.py @@ -181,6 +183,7 @@ SET(FemGuiScripts_SRCS PyGui/_TaskPanelFemSolverControl.py PyGui/_ViewProviderFemConstraintSelfWeight.py PyGui/_ViewProviderFemConstraintBodyHeatSource.py + PyGui/_ViewProviderFemConstraintFlowVelocity.py PyGui/_ViewProviderFemElementFluid1D.py PyGui/_ViewProviderFemElementGeometry1D.py PyGui/_ViewProviderFemElementGeometry2D.py @@ -204,6 +207,7 @@ SET(FemGuiScripts_SRCS PyGui/TaskPanelFemMeshRegion.ui PyGui/TaskPanelFemResultShow.ui PyGui/TaskPanelFemSolverCalculix.ui + PyGui/TaskPanelFemFlowVelocity.ui ) SET(FemTests_SRCS diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index d20f34ff64..82b56f9c8d 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -51,6 +51,7 @@ INSTALL( PyObjects/__init__.py PyObjects/_FemConstraintSelfWeight.py PyObjects/_FemConstraintBodyHeatSource.py + PyObjects/_FemConstraintFlowVelocity.py PyObjects/_FemElementFluid1D.py PyObjects/_FemElementGeometry1D.py PyObjects/_FemElementGeometry2D.py @@ -108,6 +109,7 @@ INSTALL( PyGui/FemSelectionWidgets.py PyGui/__init__.py PyGui/_CommandFemConstraintBodyHeatSource.py + PyGui/_CommandFemConstraintFlowVelocity.py PyGui/_CommandFemAnalysis.py PyGui/_CommandFemConstraintSelfWeight.py PyGui/_CommandFemElementFluid1D.py @@ -143,6 +145,7 @@ INSTALL( PyGui/_TaskPanelFemSolverControl.py PyGui/_ViewProviderFemConstraintSelfWeight.py PyGui/_ViewProviderFemConstraintBodyHeatSource.py + PyGui/_ViewProviderFemConstraintFlowVelocity.py PyGui/_ViewProviderFemElementFluid1D.py PyGui/_ViewProviderFemElementGeometry1D.py PyGui/_ViewProviderFemElementGeometry2D.py @@ -166,6 +169,7 @@ INSTALL( PyGui/TaskPanelFemMeshRegion.ui PyGui/TaskPanelFemResultShow.ui PyGui/TaskPanelFemSolverCalculix.ui + PyGui/TaskPanelFemFlowVelocity.ui DESTINATION Mod/Fem/PyGui ) diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index 86423fb570..5353abee67 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -16,6 +16,7 @@ icons/fem-constraint-contact.svg icons/fem-constraint-displacement.svg icons/fem-constraint-fixed.svg + icons/fem-constraint-flow-velocity.svg icons/fem-constraint-fluid-boundary.svg icons/fem-constraint-force.svg icons/fem-constraint-gear.svg diff --git a/src/Mod/Fem/Gui/Resources/icons/fem-constraint-flow-velocity.svg b/src/Mod/Fem/Gui/Resources/icons/fem-constraint-flow-velocity.svg new file mode 100644 index 0000000000..1856666aaf --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/fem-constraint-flow-velocity.svg @@ -0,0 +1,76 @@ + + + + + + + + image/svg+xml + + + + + + + V + + + diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 186b9d3f06..e6c0b5aa12 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -104,7 +104,8 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* fluid = new Gui::ToolBarItem(root); fluid->setCommand("Fluid Constraints"); - *fluid << "FEM_ConstraintFluidBoundary"; + *fluid << "FEM_ConstraintFluidBoundary" + << "FEM_AddConstraintFlowVelocity"; Gui::ToolBarItem* solve = new Gui::ToolBarItem(root); solve->setCommand("Solve"); @@ -167,7 +168,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* fluid = new Gui::MenuItem; fluid->setCommand("&Fluid Constraints"); - *fluid << "FEM_ConstraintFluidBoundary"; + *fluid << "FEM_ConstraintFluidBoundary" + << "FEM_AddConstraintFlowVelocity"; Gui::MenuItem* model = new Gui::MenuItem; root->insertItem(item, model); diff --git a/src/Mod/Fem/InitGui.py b/src/Mod/Fem/InitGui.py index c1b5271a8e..71abd69e53 100644 --- a/src/Mod/Fem/InitGui.py +++ b/src/Mod/Fem/InitGui.py @@ -48,6 +48,7 @@ class FemWorkbench (Workbench): import PyGui._CommandFemAnalysis import PyGui._CommandFemConstraintSelfWeight import PyGui._CommandFemConstraintBodyHeatSource + import PyGui._CommandFemConstraintFlowVelocity import PyGui._CommandFemElementFluid1D import PyGui._CommandFemElementGeometry1D import PyGui._CommandFemElementGeometry2D diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index 43b624658f..f8f49cace4 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -73,6 +73,17 @@ def makeConstraintFixed(doc, name="ConstraintFixed"): return obj +def makeConstraintFlowVelocity(doc, name="ConstraintFlowVelocity"): + '''makeConstraintFlowVelocity(document, [name]): makes a Fem ConstraintFlowVelocity object''' + obj = doc.addObject("Fem::ConstraintPython", name) + import PyObjects._FemConstraintFlowVelocity + PyObjects._FemConstraintFlowVelocity.Proxy(obj) + if FreeCAD.GuiUp: + import PyGui._ViewProviderFemConstraintFlowVelocity + PyGui._ViewProviderFemConstraintFlowVelocity.ViewProxy(obj.ViewObject) + return obj + + def makeConstraintFluidBoundary(doc, name="ConstraintFluidBoundary"): '''makeConstraintFluidBoundary(document, name): makes a Fem ConstraintForce object''' obj = doc.addObject("Fem::ConstraintForce", name) diff --git a/src/Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui b/src/Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui new file mode 100644 index 0000000000..83e4ad0328 --- /dev/null +++ b/src/Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui @@ -0,0 +1,234 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Constraint Properties + + + + + + Velocity x: + + + + + + + Velocity y: + + + + + + + Velocity z: + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + normal to boundary + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + + + velocityXBox + toggled(bool) + velocityXTxt + setEnabled(bool) + + + 230 + 44 + + + 230 + 18 + + + + + velocityXBox + toggled(bool) + velocityXTxt + setDisabled(bool) + + + 230 + 44 + + + 230 + 18 + + + + + velocityYBox + toggled(bool) + velocityYTxt + setEnabled(bool) + + + 347 + 53 + + + 184 + 53 + + + + + velocityYBox + toggled(bool) + velocityYTxt + setDisabled(bool) + + + 347 + 53 + + + 184 + 53 + + + + + velocityZBox + toggled(bool) + velocityZTxt + setEnabled(bool) + + + 347 + 87 + + + 184 + 87 + + + + + velocityZBox + toggled(bool) + velocityZTxt + setDisabled(bool) + + + 347 + 87 + + + 184 + 87 + + + + +
diff --git a/src/Mod/Fem/PyGui/_CommandFemConstraintFlowVelocity.py b/src/Mod/Fem/PyGui/_CommandFemConstraintFlowVelocity.py new file mode 100644 index 0000000000..65212cb915 --- /dev/null +++ b/src/Mod/Fem/PyGui/_CommandFemConstraintFlowVelocity.py @@ -0,0 +1,59 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2017 - Markus Hovorka * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + + +__title__ = "AddConstraintFlowVelocity" +__author__ = "Markus Hovorka" +__url__ = "http://www.freecadweb.org" + + +from PySide import QtCore + +import FreeCAD as App +import FreeCADGui as Gui +from PyGui import FemCommands + + +class Command(FemCommands.FemCommands): + + def __init__(self): + super(Command, self).__init__() + self.resources = { + 'Pixmap': 'fem-constraint-flow-velocity', + 'MenuText': QtCore.QT_TRANSLATE_NOOP( + "FEM_ConstraintFlowVelocity", + "Constraint Velocity"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP( + "FEM_ConstraintFlowVelocity", + "Creates a FEM constraint body heat flux")} + self.is_active = 'with_analysis' + + def Activated(self): + App.ActiveDocument.openTransaction( + "Create FemConstraintFlowVelocity") + Gui.addModule("ObjectsFem") + Gui.doCommand( + "FemGui.getActiveAnalysis().Member += " + "[ObjectsFem.makeConstraintFlowVelocity()]") + + +Gui.addCommand('FEM_AddConstraintFlowVelocity', Command()) diff --git a/src/Mod/Fem/PyGui/_ViewProviderFemConstraintFlowVelocity.py b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintFlowVelocity.py new file mode 100644 index 0000000000..19350da8dc --- /dev/null +++ b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintFlowVelocity.py @@ -0,0 +1,137 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2017 - Markus Hovorka * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + + +__title__ = "view provider for constraint flow velocity object" +__author__ = "Markus Hovorka, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FreeCAD as App +import FemUtils +import FemConstraint +from FreeCAD import Units + +import FreeCADGui as Gui +from . import FemSelectionWidgets + + +class ViewProxy(FemConstraint.ViewProxy): + + def getIcon(self): + return ":/icons/fem-constraint-flow-velocity.svg" + + def setEdit(self, vobj, mode=0): + task = _TaskPanel(vobj.Object) + Gui.Control.showDialog(task) + + def unsetEdit(self, vobj, mode=0): + Gui.Control.closeDialog() + + def doubleClicked(self, vobj): + if Gui.Control.activeDialog(): + Gui.Control.closeDialog() + Gui.ActiveDocument.setEdit(vobj.Object.Name) + return True + + +class _TaskPanel(object): + + def __init__(self, obj): + self._obj = obj + self._refWidget = FemSelectionWidgets.BoundarySelector() + self._refWidget.setReferences(obj.References) + self._paramWidget = Gui.PySideUic.loadUi( + App.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemFlowVelocity.ui") + self._initParamWidget() + self.form = [self._refWidget, self._paramWidget] + analysis = FemUtils.findAnalysisOfMember(obj) + self._mesh = FemUtils.getSingleMember(analysis, "Fem::FemMeshObject") + self._part = self._mesh.Part if self._mesh is not None else None + self._partVisible = None + self._meshVisible = None + + def open(self): + if self._mesh is not None and self._part is not None: + self._meshVisible = self._mesh.ViewObject.isVisible() + self._partVisible = self._part.ViewObject.isVisible() + self._mesh.ViewObject.hide() + self._part.ViewObject.show() + + def reject(self): + self._restoreVisibility() + return True + + def accept(self): + if self._obj.References != self._refWidget.references(): + self._obj.References = self._refWidget.references() + self._applyWidgetChanges() + self._obj.Document.recompute() + self._restoreVisibility() + return True + + def _restoreVisibility(self): + if self._mesh is not None and self._part is not None: + if self._meshVisible: + self._mesh.ViewObject.show() + else: + self._mesh.ViewObject.hide() + if self._partVisible: + self._part.ViewObject.show() + else: + self._part.ViewObject.hide() + + def _initParamWidget(self): + unit = "m/s" + self._paramWidget.velocityXTxt.setText( + str(self._obj.VelocityX) + unit) + self._paramWidget.velocityYTxt.setText( + str(self._obj.VelocityY) + unit) + self._paramWidget.velocityZTxt.setText( + str(self._obj.VelocityZ) + unit) + self._paramWidget.velocityXBox.setChecked( + not self._obj.VelocityXEnabled) + self._paramWidget.velocityYBox.setChecked( + not self._obj.VelocityYEnabled) + self._paramWidget.velocityZBox.setChecked( + not self._obj.VelocityZEnabled) + self._paramWidget.normalBox.setChecked( + self._obj.NormalToBoundary) + + def _applyWidgetChanges(self): + unit = "m/s" + self._obj.VelocityXEnabled = \ + not self._paramWidget.velocityXBox.isChecked() + if self._obj.VelocityXEnabled: + quantity = Units.Quantity(self._paramWidget.velocityXTxt.text()) + self._obj.VelocityX = float(quantity.getValueAs(unit)) + self._obj.VelocityYEnabled = \ + not self._paramWidget.velocityYBox.isChecked() + if self._obj.VelocityYEnabled: + quantity = Units.Quantity(self._paramWidget.velocityYTxt.text()) + self._obj.VelocityY = float(quantity.getValueAs(unit)) + self._obj.VelocityZEnabled = \ + not self._paramWidget.velocityZBox.isChecked() + if self._obj.VelocityZEnabled: + quantity = Units.Quantity(self._paramWidget.velocityZTxt.text()) + self._obj.VelocityZ = float(quantity.getValueAs(unit)) + self._obj.NormalToBoundary = self._paramWidget.normalBox.isChecked() diff --git a/src/Mod/Fem/PyObjects/_FemConstraintFlowVelocity.py b/src/Mod/Fem/PyObjects/_FemConstraintFlowVelocity.py new file mode 100644 index 0000000000..80b3e5a566 --- /dev/null +++ b/src/Mod/Fem/PyObjects/_FemConstraintFlowVelocity.py @@ -0,0 +1,58 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2017 - Markus Hovorka * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + + +__title__ = "the constraint flow velocity object" +__author__ = "Markus Hovorka, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FemConstraint + + +class Proxy(FemConstraint.Proxy): + + Type = "Fem::ConstraintFlowVelocity" + + def __init__(self, obj): + super(Proxy, self).__init__(obj) + obj.addProperty( + "App::PropertyFloat", "VelocityX", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyBool", "VelocityXEnabled", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyFloat", "VelocityY", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyBool", "VelocityYEnabled", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyFloat", "VelocityZ", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyBool", "VelocityZEnabled", + "Parameter", "Body heat flux") + obj.addProperty( + "App::PropertyBool", "NormalToBoundary", + "Parameter", "Body heat flux")