From 14614d3eabfb483d625b8144a2d7c16737f6d47e Mon Sep 17 00:00:00 2001 From: Wilfried Hortschitz Date: Fri, 1 Dec 2017 19:43:41 +0100 Subject: [PATCH] FEM: constraint initial 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 + .../fem-constraint-initial-flow-velocity.svg | 62 +++++ src/Mod/Fem/Gui/Workbench.cpp | 8 +- src/Mod/Fem/InitGui.py | 1 + src/Mod/Fem/ObjectsFem.py | 11 + .../PyGui/TaskPanelFemInitialFlowVelocity.ui | 230 ++++++++++++++++++ ...CommandFemConstraintInitialFlowVelocity.py | 59 +++++ ...roviderFemConstraintInitialFlowVelocity.py | 129 ++++++++++ .../_FemConstraintInitialFlowVelocity.py | 55 +++++ 11 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 src/Mod/Fem/Gui/Resources/icons/fem-constraint-initial-flow-velocity.svg create mode 100644 src/Mod/Fem/PyGui/TaskPanelFemInitialFlowVelocity.ui create mode 100644 src/Mod/Fem/PyGui/_CommandFemConstraintInitialFlowVelocity.py create mode 100644 src/Mod/Fem/PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py create mode 100644 src/Mod/Fem/PyObjects/_FemConstraintInitialFlowVelocity.py diff --git a/src/Mod/Fem/App/CMakeLists.txt b/src/Mod/Fem/App/CMakeLists.txt index edfdc3cb66..054f0914a8 100644 --- a/src/Mod/Fem/App/CMakeLists.txt +++ b/src/Mod/Fem/App/CMakeLists.txt @@ -102,6 +102,7 @@ SET(FemObjectsScripts_SRCS PyObjects/_FemConstraintSelfWeight.py PyObjects/_FemConstraintBodyHeatSource.py PyObjects/_FemConstraintFlowVelocity.py + PyObjects/_FemConstraintInitialFlowVelocity.py PyObjects/_FemElementFluid1D.py PyObjects/_FemElementGeometry1D.py PyObjects/_FemElementGeometry2D.py @@ -150,6 +151,7 @@ SET(FemGuiScripts_SRCS PyGui/_CommandFemConstraintSelfWeight.py PyGui/_CommandFemConstraintBodyHeatSource.py PyGui/_CommandFemConstraintFlowVelocity.py + PyGui/_CommandFemConstraintInitialFlowVelocity.py PyGui/_CommandFemElementFluid1D.py PyGui/_CommandFemElementGeometry1D.py PyGui/_CommandFemElementGeometry2D.py @@ -184,6 +186,7 @@ SET(FemGuiScripts_SRCS PyGui/_ViewProviderFemConstraintSelfWeight.py PyGui/_ViewProviderFemConstraintBodyHeatSource.py PyGui/_ViewProviderFemConstraintFlowVelocity.py + PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py PyGui/_ViewProviderFemElementFluid1D.py PyGui/_ViewProviderFemElementGeometry1D.py PyGui/_ViewProviderFemElementGeometry2D.py @@ -208,6 +211,7 @@ SET(FemGuiScripts_SRCS PyGui/TaskPanelFemResultShow.ui PyGui/TaskPanelFemSolverCalculix.ui PyGui/TaskPanelFemFlowVelocity.ui + PyGui/TaskPanelFemInitialFlowVelocity.ui ) SET(FemTests_SRCS diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 82b56f9c8d..029374a7a0 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -52,6 +52,7 @@ INSTALL( PyObjects/_FemConstraintSelfWeight.py PyObjects/_FemConstraintBodyHeatSource.py PyObjects/_FemConstraintFlowVelocity.py + PyObjects/_FemConstraintInitialFlowVelocity.py PyObjects/_FemElementFluid1D.py PyObjects/_FemElementGeometry1D.py PyObjects/_FemElementGeometry2D.py @@ -110,6 +111,7 @@ INSTALL( PyGui/__init__.py PyGui/_CommandFemConstraintBodyHeatSource.py PyGui/_CommandFemConstraintFlowVelocity.py + PyGui/_CommandFemConstraintInitialFlowVelocity.py PyGui/_CommandFemAnalysis.py PyGui/_CommandFemConstraintSelfWeight.py PyGui/_CommandFemElementFluid1D.py @@ -146,6 +148,7 @@ INSTALL( PyGui/_ViewProviderFemConstraintSelfWeight.py PyGui/_ViewProviderFemConstraintBodyHeatSource.py PyGui/_ViewProviderFemConstraintFlowVelocity.py + PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py PyGui/_ViewProviderFemElementFluid1D.py PyGui/_ViewProviderFemElementGeometry1D.py PyGui/_ViewProviderFemElementGeometry2D.py @@ -170,6 +173,7 @@ INSTALL( PyGui/TaskPanelFemResultShow.ui PyGui/TaskPanelFemSolverCalculix.ui PyGui/TaskPanelFemFlowVelocity.ui + PyGui/TaskPanelFemInitialFlowVelocity.ui DESTINATION Mod/Fem/PyGui ) diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index 5353abee67..af198f224f 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -21,6 +21,7 @@ icons/fem-constraint-force.svg icons/fem-constraint-gear.svg icons/fem-constraint-heatflux.svg + icons/fem-constraint-initial-flow-velocity.svg icons/fem-constraint-InitialTemperature.svg icons/fem-constraint-planerotation.svg icons/fem-constraint-pressure.svg diff --git a/src/Mod/Fem/Gui/Resources/icons/fem-constraint-initial-flow-velocity.svg b/src/Mod/Fem/Gui/Resources/icons/fem-constraint-initial-flow-velocity.svg new file mode 100644 index 0000000000..a1c2983bf9 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/fem-constraint-initial-flow-velocity.svg @@ -0,0 +1,62 @@ + + + + + + + image/svg+xml + + + + + + + V + + + I + diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index e6c0b5aa12..7016384e41 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -104,7 +104,9 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* fluid = new Gui::ToolBarItem(root); fluid->setCommand("Fluid Constraints"); - *fluid << "FEM_ConstraintFluidBoundary" + *fluid << "FEM_AddConstraintInitialFlowVelocity" + << "Separator" + << "FEM_ConstraintFluidBoundary" << "FEM_AddConstraintFlowVelocity"; Gui::ToolBarItem* solve = new Gui::ToolBarItem(root); @@ -168,7 +170,9 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* fluid = new Gui::MenuItem; fluid->setCommand("&Fluid Constraints"); - *fluid << "FEM_ConstraintFluidBoundary" + *fluid << "FEM_AddConstraintInitialFlowVelocity" + << "Separator" + << "FEM_ConstraintFluidBoundary" << "FEM_AddConstraintFlowVelocity"; Gui::MenuItem* model = new Gui::MenuItem; diff --git a/src/Mod/Fem/InitGui.py b/src/Mod/Fem/InitGui.py index 71abd69e53..96d713176d 100644 --- a/src/Mod/Fem/InitGui.py +++ b/src/Mod/Fem/InitGui.py @@ -49,6 +49,7 @@ class FemWorkbench (Workbench): import PyGui._CommandFemConstraintSelfWeight import PyGui._CommandFemConstraintBodyHeatSource import PyGui._CommandFemConstraintFlowVelocity + import PyGui._CommandFemConstraintInitialFlowVelocity import PyGui._CommandFemElementFluid1D import PyGui._CommandFemElementGeometry1D import PyGui._CommandFemElementGeometry2D diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index f8f49cace4..02ab1811c5 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -108,6 +108,17 @@ def makeConstraintHeatflux(doc, name="ConstraintHeatflux"): return obj +def makeConstraintInitialFlowVelocity(doc, name="ConstraintInitialFlowVelocity"): + '''makeConstraintInitialFlowVelocity(document, [name]): makes a Fem ConstraintInitialFlowVelocity object''' + obj = doc.addObject("Fem::ConstraintPython", name) + import PyObjects._FemConstraintInitialFlowVelocity + PyObjects._FemConstraintInitialFlowVelocity.Proxy(obj) + if FreeCAD.GuiUp: + import PyGui._ViewProviderFemConstraintInitialFlowVelocity + PyGui._ViewProviderFemConstraintInitialFlowVelocity.ViewProxy(obj.ViewObject) + return obj + + def makeConstraintInitialTemperature(doc, name="ConstraintInitialTemperature"): '''makeConstraintInitialTemperature(document, name): makes a Fem ConstraintInitialTemperature object''' obj = doc.addObject("Fem::ConstraintInitialTemperature", name) diff --git a/src/Mod/Fem/PyGui/TaskPanelFemInitialFlowVelocity.ui b/src/Mod/Fem/PyGui/TaskPanelFemInitialFlowVelocity.ui new file mode 100644 index 0000000000..b20a5aecdc --- /dev/null +++ b/src/Mod/Fem/PyGui/TaskPanelFemInitialFlowVelocity.ui @@ -0,0 +1,230 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Constraint Properties + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Velocity x: + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + Velocity y: + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + Velocity z: + + + + + + + + + false + + + 1.000000000000000 + + + m/s + + + + + + + unspecified + + + true + + + + + + + + + + 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/_CommandFemConstraintInitialFlowVelocity.py b/src/Mod/Fem/PyGui/_CommandFemConstraintInitialFlowVelocity.py new file mode 100644 index 0000000000..4a83057b40 --- /dev/null +++ b/src/Mod/Fem/PyGui/_CommandFemConstraintInitialFlowVelocity.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__ = "AddConstraintInitialFlowVelocity" +__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-initial-flow-velocity', + 'MenuText': QtCore.QT_TRANSLATE_NOOP( + "FEM_ConstraintInitialFlowVelocity", + "Constraint Velocity"), + 'ToolTip': QtCore.QT_TRANSLATE_NOOP( + "FEM_ConstraintInitialFlowVelocity", + "Creates a FEM constraint body heat flux")} + self.is_active = 'with_analysis' + + def Activated(self): + App.ActiveDocument.openTransaction( + "Create FemConstraintInitialFlowVelocity") + Gui.addModule("ObjectsFem") + Gui.doCommand( + "FemGui.getActiveAnalysis().Member += " + "[ObjectsFem.makeConstraintInitialFlowVelocity()]") + + +Gui.addCommand('FEM_AddConstraintInitialFlowVelocity', Command()) diff --git a/src/Mod/Fem/PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py new file mode 100644 index 0000000000..7bb2066479 --- /dev/null +++ b/src/Mod/Fem/PyGui/_ViewProviderFemConstraintInitialFlowVelocity.py @@ -0,0 +1,129 @@ +# *************************************************************************** +# * * +# * 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 initial 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 + + +class ViewProxy(FemConstraint.ViewProxy): + + def getIcon(self): + return ":/icons/fem-constraint-initial-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._paramWidget = Gui.PySideUic.loadUi( + App.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemInitialFlowVelocity.ui") + self._initParamWidget() + self.form = [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): + 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) + + 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)) diff --git a/src/Mod/Fem/PyObjects/_FemConstraintInitialFlowVelocity.py b/src/Mod/Fem/PyObjects/_FemConstraintInitialFlowVelocity.py new file mode 100644 index 0000000000..59b09571e5 --- /dev/null +++ b/src/Mod/Fem/PyObjects/_FemConstraintInitialFlowVelocity.py @@ -0,0 +1,55 @@ +# *************************************************************************** +# * * +# * 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 initial flow velocity object" +__author__ = "Markus Hovorka, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + + +import FemConstraint + + +class Proxy(FemConstraint.Proxy): + + Type = "Fem::ConstraintInitialFlowVelocity" + + 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")