From 5238a5d5bcefc0bbb10b277d54d554a6eb295087 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Wed, 3 Jun 2020 23:48:44 +0200 Subject: [PATCH] FEM: move task panel in separate module, constraint flow velocity --- src/Mod/Fem/CMakeLists.txt | 1 + .../task_constraint_flowvelocity.py | 128 ++++++++++++++++++ .../view_constraint_flowvelocity.py | 101 +------------- 3 files changed, 132 insertions(+), 98 deletions(-) create mode 100644 src/Mod/Fem/femtaskpanels/task_constraint_flowvelocity.py diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index e05939e2fe..68f248a29e 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -350,6 +350,7 @@ SET(FemGuiObjects_SRCS SET(FemGuiTaskPanels_SRCS femtaskpanels/__init__.py femtaskpanels/task_constraint_electrostaticpotential.py + femtaskpanels/task_constraint_flowvelocity.py femtaskpanels/task_mesh_gmsh.py femtaskpanels/task_result_mechanical.py femtaskpanels/task_solver_ccxtools.py diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_flowvelocity.py b/src/Mod/Fem/femtaskpanels/task_constraint_flowvelocity.py new file mode 100644 index 0000000000..93c5a3f693 --- /dev/null +++ b/src/Mod/Fem/femtaskpanels/task_constraint_flowvelocity.py @@ -0,0 +1,128 @@ +# *************************************************************************** +# * Copyright (c) 2017 Markus Hovorka * +# * * +# * This file is part of the FreeCAD CAx development system. * +# * * +# * 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__ = "FreeCAD FEM constraint flow velocity task panel for the document object" +__author__ = "Markus Hovorka, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" + +## @package task_constraint_flowvelocity +# \ingroup FEM +# \brief task panel for constraint flow velocity object + +import FreeCAD +import FreeCADGui +from FreeCAD import Units + +from femguiutils import selection_widgets +from femtools import femutils +from femtools import membertools + + +class _TaskPanel(object): + + def __init__(self, obj): + self._obj = obj + self._refWidget = selection_widgets.BoundarySelector() + self._refWidget.setReferences(obj.References) + self._paramWidget = FreeCADGui.PySideUic.loadUi( + FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/FlowVelocity.ui" + ) + self._initParamWidget() + self.form = [self._refWidget, self._paramWidget] + analysis = obj.getParentGroup() + self._mesh = None + self._part = None + if analysis is not None: + self._mesh = membertools.get_single_member(analysis, "Fem::FemMeshObject") + if self._mesh is not None: + self._part = femutils.get_part_to_mesh(self._mesh) + 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): + FreeCADGui.ActiveDocument.resetEdit() + 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() + FreeCADGui.ActiveDocument.resetEdit() + 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/femviewprovider/view_constraint_flowvelocity.py b/src/Mod/Fem/femviewprovider/view_constraint_flowvelocity.py index e187e33ab5..b7a6b69932 100644 --- a/src/Mod/Fem/femviewprovider/view_constraint_flowvelocity.py +++ b/src/Mod/Fem/femviewprovider/view_constraint_flowvelocity.py @@ -1,5 +1,6 @@ # *************************************************************************** # * Copyright (c) 2017 Markus Hovorka * +# * Copyright (c) 2020 Bernd Hahnebach * # * * # * This file is part of the FreeCAD CAx development system. * # * * @@ -29,14 +30,8 @@ __url__ = "http://www.freecadweb.org" # \ingroup FEM # \brief view provider for constraint flow velocity object -import FreeCAD -import FreeCADGui -from FreeCAD import Units - -from femguiutils import selection_widgets +from femtaskpanels import task_constraint_flowvelocity from . import view_base_femconstraint -from femtools import femutils -from femtools import membertools class VPConstraintFlowVelocity(view_base_femconstraint.VPBaseFemConstraint): @@ -46,95 +41,5 @@ class VPConstraintFlowVelocity(view_base_femconstraint.VPBaseFemConstraint): self, vobj, mode, - _TaskPanel + task_constraint_flowvelocity._TaskPanel ) - - -class _TaskPanel(object): - - def __init__(self, obj): - self._obj = obj - self._refWidget = selection_widgets.BoundarySelector() - self._refWidget.setReferences(obj.References) - self._paramWidget = FreeCADGui.PySideUic.loadUi( - FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/FlowVelocity.ui" - ) - self._initParamWidget() - self.form = [self._refWidget, self._paramWidget] - analysis = obj.getParentGroup() - self._mesh = None - self._part = None - if analysis is not None: - self._mesh = membertools.get_single_member(analysis, "Fem::FemMeshObject") - if self._mesh is not None: - self._part = femutils.get_part_to_mesh(self._mesh) - 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): - FreeCADGui.ActiveDocument.resetEdit() - 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() - FreeCADGui.ActiveDocument.resetEdit() - 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()