diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 2a26ba0fb6..4b1720427a 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -461,6 +461,7 @@ SET(FemGuiObjects_SRCS SET(FemGuiTaskPanels_SRCS femtaskpanels/__init__.py + femtaskpanels/task_constraint_centrif.py femtaskpanels/task_constraint_electrostaticpotential.py femtaskpanels/task_constraint_flowvelocity.py femtaskpanels/task_constraint_initialflowvelocity.py diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index dcb75c68d8..0c0a9a2437 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -365,6 +365,7 @@ INSTALL(FILES ${FemGuiIcon_SVG} DESTINATION "${CMAKE_INSTALL_DATADIR}/Mod/Fem/Re # Python modules ui files, they are copied as they are, thus the need not to be added to Fem.qrc # see https://forum.freecadweb.org/viewtopic.php?f=10&t=25833 SET(FemGuiPythonUI_SRCS + Resources/ui/ConstraintCentrif.ui Resources/ui/ConstraintTie.ui Resources/ui/ConstraintSectionPrint.ui Resources/ui/ElectrostaticPotential.ui diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index bc18c2a731..a5f8faf7da 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -10,6 +10,7 @@ icons/FEM_ConstraintBearing.svg + icons/FEM_ConstraintCentrif.svg icons/FEM_ConstraintContact.svg icons/FEM_ConstraintDisplacement.svg icons/FEM_ConstraintElectrostaticPotential.svg @@ -142,6 +143,7 @@ translations/Fem_zh-TW.qm + ui/ConstraintCentrif.ui ui/ConstraintSectionPrint.ui ui/ConstraintTie.ui ui/ElectrostaticPotential.ui diff --git a/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCentrif.svg b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCentrif.svg new file mode 100644 index 0000000000..001608e20c --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCentrif.svg @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + [Przemo Firszt] + + + 2015-07-28 + http://www.freecadweb.org/wiki/index.php?title=Artwork + + + FreeCAD + + + FreeCAD/src/Mod/ + + + FreeCAD LGPL2+ + + + https://www.gnu.org/copyleft/lesser.html + + + [agryson] Alexander Gryson + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui b/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui new file mode 100644 index 0000000000..8f600c9c07 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/ui/ConstraintCentrif.ui @@ -0,0 +1,131 @@ + + + Form + + + + 0 + 0 + 350 + 500 + + + + Centrif parameter + + + + + + + 16777215 + 1677215 + + + + Parameter + + + + + + 4 + + + + + + 0 + 0 + + + + Rotation frequency f<sub>rot</sub> [rps] + + + false + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 0 + + + -1 + + + + + + + + 0 + 0 + + + + + 80 + 20 + + + + revolutions per second + + + Qt::LeftToRight + + + 0.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 1.000000000000000 + + + 1000000000.000000000000000 + + + 1/s + + + 2 + + + 0.000000000000000 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index d3d66dc5d3..3ee529d0cb 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -142,6 +142,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" + << "FEM_ConstraintCentrif" << "FEM_ConstraintSelfWeight"; Gui::ToolBarItem* thermal = new Gui::ToolBarItem(root); @@ -268,6 +269,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Separator" << "FEM_ConstraintForce" << "FEM_ConstraintPressure" + << "FEM_ConstraintCentrif" << "FEM_ConstraintSelfWeight"; Gui::MenuItem* thermal = new Gui::MenuItem; diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index 8a84c30dda..4407df5e6f 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -162,6 +162,17 @@ class _ConstraintBodyHeatSource(CommandManager): self.do_activated = "add_obj_on_gui_noset_edit" +class _ConstraintCentrif(CommandManager): + "The FEM_ConstraintCentrif command definition" + + def __init__(self): + super(_ConstraintCentrif, self).__init__() + self.menuetext = "Constraint centrif" + self.tooltip = "Creates a FEM constraint centrif" + self.is_active = "with_analysis" + self.do_activated = "add_obj_on_gui_set_edit" + + class _ConstraintElectrostaticPotential(CommandManager): "The FEM_ConstraintElectrostaticPotential command definition" @@ -815,6 +826,10 @@ FreeCADGui.addCommand( "FEM_ConstraintBodyHeatSource", _ConstraintBodyHeatSource() ) +FreeCADGui.addCommand( + "FEM_ConstraintCentrif", + _ConstraintCentrif() +) FreeCADGui.addCommand( "FEM_ConstraintElectrostaticPotential", _ConstraintElectrostaticPotential() diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py b/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py new file mode 100644 index 0000000000..7d12846c20 --- /dev/null +++ b/src/Mod/Fem/femtaskpanels/task_constraint_centrif.py @@ -0,0 +1,173 @@ +# *************************************************************************** +# * Copyright (c) 2020 Bernd Hahnebach * +# * * +# * 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 centrif task panel for the document object" +__author__ = "Bernd Hahnebach" +__url__ = "https://www.freecadweb.org" + +## @package task_constraint_centrif +# \ingroup FEM +# \brief task panel for constraint centrif object + +from PySide import QtCore +from PySide import QtGui + +import FreeCAD +import FreeCADGui + +from femguiutils import selection_widgets + + +class _TaskPanel: + """ + The TaskPanel for editing References property of FemConstraintCentrif objects + """ + + def __init__(self, obj): + + self.obj = obj + + # parameter widget + self.parameterWidget = FreeCADGui.PySideUic.loadUi( + FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/ConstraintCentrif.ui" + ) + QtCore.QObject.connect( + self.parameterWidget.if_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( + obj.RotationAxis, + ["Edge"], + False, + False + ) + + # loaded body selection widget + self.BodySelectionWidget = selection_widgets.GeometryElementsSelection( + obj.References, + ["Solid"], + False, + False + ) + + # form made from param and selection widget + self.form = [self.parameterWidget, self.BodySelectionWidget, self.AxisSelectionWidget] + + def accept(self): + # check values RotationAxis + items = len(self.AxisSelectionWidget.references) + FreeCAD.Console.PrintMessage( + "Task panel: found axis references: {}\n{}\n" + .format(items, self.AxisSelectionWidget.references) + ) + + if items != 1: + msgBox = QtGui.QMessageBox() + msgBox.setIcon(QtGui.QMessageBox.Question) + msgBox.setText( + "Constraint Centrif requires exactly one line\n\nfound references: {}" + .format(items) + ) + msgBox.setWindowTitle("FreeCAD FEM Constraint Centrif - Axis selection") + retryButton = msgBox.addButton(QtGui.QMessageBox.Retry) + ignoreButton = msgBox.addButton(QtGui.QMessageBox.Ignore) + msgBox.exec_() + + if msgBox.clickedButton() == retryButton: + return False + elif msgBox.clickedButton() == ignoreButton: + pass + + # check values BodyReference + items = len(self.BodySelectionWidget.references) + FreeCAD.Console.PrintMessage( + "Task panel: found body references: {}\n{}\n" + .format(items, self.BodySelectionWidget.references) + ) + + # if no solid is added as reference all volume elements are used + """ + if items == 0: + msgBox = QtGui.QMessageBox() + msgBox.setIcon(QtGui.QMessageBox.Question) + msgBox.setText("Constraint Centrif requires at least one solid") + msgBox.setWindowTitle("FreeCAD FEM Constraint Centrif - Body selection") + retryButton = msgBox.addButton(QtGui.QMessageBox.Retry) + ignoreButton = msgBox.addButton(QtGui.QMessageBox.Ignore) + msgBox.exec_() + + if msgBox.clickedButton() == retryButton: + return False + elif msgBox.clickedButton() == ignoreButton: + pass + """ + + # check value RotationFrequency + if self.rotation_frequency == 0: + msgBox = QtGui.QMessageBox() + msgBox.setIcon(QtGui.QMessageBox.Question) + msgBox.setText("Rotational speed is zero") + msgBox.setWindowTitle("FreeCAD FEM Constraint Centrif - Rotational speed setting") + retryButton = msgBox.addButton(QtGui.QMessageBox.Retry) + ignoreButton = msgBox.addButton(QtGui.QMessageBox.Ignore) + msgBox.exec_() + + if msgBox.clickedButton() == retryButton: + return False + elif msgBox.clickedButton() == ignoreButton: + pass + + self.obj.RotationFrequency = self.rotation_frequency + self.obj.RotationAxis = self.AxisSelectionWidget.references + self.obj.References = self.BodySelectionWidget.references + self.recompute_and_set_back_all() + return True + + def reject(self): + self.recompute_and_set_back_all() + return True + + def recompute_and_set_back_all(self): + doc = FreeCADGui.getDocument(self.obj.Document) + doc.Document.recompute() + + self.AxisSelectionWidget.setback_listobj_visibility() + if self.AxisSelectionWidget.sel_server: + FreeCADGui.Selection.removeObserver(self.AxisSelectionWidget.sel_server) + + self.BodySelectionWidget.setback_listobj_visibility() + if self.BodySelectionWidget.sel_server: + FreeCADGui.Selection.removeObserver(self.BodySelectionWidget.sel_server) + + doc.resetEdit() + + def init_parameter_widget(self): + self.rotation_frequency = self.obj.RotationFrequency + self.parameterWidget.if_rotation_frequency.setText(self.rotation_frequency.UserString) + + def rotation_frequency_changed(self, base_quantity_value): + self.rotation_frequency = base_quantity_value diff --git a/src/Mod/Fem/femviewprovider/view_constraint_centrif.py b/src/Mod/Fem/femviewprovider/view_constraint_centrif.py index f68ad42916..1b2dd1a4c0 100644 --- a/src/Mod/Fem/femviewprovider/view_constraint_centrif.py +++ b/src/Mod/Fem/femviewprovider/view_constraint_centrif.py @@ -29,6 +29,7 @@ __url__ = "https://www.freecadweb.org" # \ingroup FEM # \brief view provider for constraint centrif object +from femtaskpanels import task_constraint_centrif from . import view_base_femconstraint @@ -37,4 +38,10 @@ class VPConstraintCentrif(view_base_femconstraint.VPBaseFemConstraint): A View Provider for the ConstraintCentrif object """ - pass + def setEdit(self, vobj, mode=0): + view_base_femconstraint.VPBaseFemConstraint.setEdit( + self, + vobj, + mode, + task_constraint_centrif._TaskPanel + )