FEM: constraint tie, add Gui command, icon, implement task panel
Added plausibility checks to ViewProvider's accept() tie code formating
This commit is contained in:
@@ -404,6 +404,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/ConstraintTie.ui
|
||||
Resources/ui/ElectrostaticPotential.ui
|
||||
Resources/ui/ElementFluid1D.ui
|
||||
Resources/ui/ElementGeometry1D.ui
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<file>icons/fem-constraint-pulley.svg</file>
|
||||
<file>icons/fem-constraint-selfweight.svg</file>
|
||||
<file>icons/fem-constraint-temperature.svg</file>
|
||||
<file>icons/fem-constraint-tie.svg</file>
|
||||
<file>icons/fem-constraint-transform.svg</file>
|
||||
<file>icons/fem-element-fluid-1d.svg</file>
|
||||
<file>icons/fem-element-geometry-1d.svg</file>
|
||||
@@ -110,6 +111,7 @@
|
||||
<file>translations/Fem_vi.qm</file>
|
||||
<file>translations/Fem_zh-CN.qm</file>
|
||||
<file>translations/Fem_zh-TW.qm</file>
|
||||
<file>ui/ConstraintTie.ui</file>
|
||||
<file>ui/ElectrostaticPotential.ui</file>
|
||||
<file>ui/ElementFluid1D.ui</file>
|
||||
<file>ui/ElementGeometry1D.ui</file>
|
||||
|
||||
1283
src/Mod/Fem/Gui/Resources/icons/fem-constraint-tie.svg
Normal file
1283
src/Mod/Fem/Gui/Resources/icons/fem-constraint-tie.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 40 KiB |
110
src/Mod/Fem/Gui/Resources/ui/ConstraintTie.ui
Normal file
110
src/Mod/Fem/Gui/Resources/ui/ConstraintTie.ui
Normal file
@@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>350</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Tie parameter</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>1677215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Parameter</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_1">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="1" column="1">
|
||||
<widget class="Gui::InputField" name="if_tolerance">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0.0</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="singleStep" stdset="0">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum" stdset="0">
|
||||
<double>1000000000.000000000000000</double>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">mm</string>
|
||||
</property>
|
||||
<property name="decimals" stdset="0">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="value" stdset="0">
|
||||
<double>0.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="l_tolerance">
|
||||
<property name="text">
|
||||
<string>Tolerance: </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::InputField</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>Gui/InputField.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -110,6 +110,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
|
||||
<< "FEM_ConstraintDisplacement"
|
||||
<< "FEM_ConstraintPlaneRotation"
|
||||
<< "FEM_ConstraintContact"
|
||||
<< "FEM_ConstraintTie"
|
||||
<< "FEM_ConstraintTransform"
|
||||
<< "Separator"
|
||||
<< "FEM_ConstraintForce"
|
||||
@@ -220,6 +221,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
<< "FEM_ConstraintDisplacement"
|
||||
<< "FEM_ConstraintPlaneRotation"
|
||||
<< "FEM_ConstraintContact"
|
||||
<< "FEM_ConstraintTie"
|
||||
<< "FEM_ConstraintTransform"
|
||||
<< "Separator"
|
||||
<< "FEM_ConstraintForce"
|
||||
|
||||
@@ -245,6 +245,29 @@ class _ConstraintSelfWeight(CommandManager):
|
||||
self.add_obj_on_gui_noset_edit(self.__class__.__name__.lstrip("_"))
|
||||
|
||||
|
||||
class _ConstraintTie(CommandManager):
|
||||
"The FEM_ConstraintTie command definition"
|
||||
|
||||
def __init__(self):
|
||||
super(_ConstraintTie, self).__init__()
|
||||
self.resources = {
|
||||
"Pixmap": "fem-constraint-tie",
|
||||
"MenuText": QtCore.QT_TRANSLATE_NOOP(
|
||||
"FEM_ConstraintTie",
|
||||
"Constraint tie"
|
||||
),
|
||||
"Accel": "C, T",
|
||||
"ToolTip": QtCore.QT_TRANSLATE_NOOP(
|
||||
"FEM_ConstraintTie",
|
||||
"Creates a FEM constraint tie"
|
||||
)
|
||||
}
|
||||
self.is_active = "with_analysis"
|
||||
|
||||
def Activated(self):
|
||||
self.add_obj_on_gui_set_edit(self.__class__.__name__.lstrip("_"))
|
||||
|
||||
|
||||
class _ElementFluid1D(CommandManager):
|
||||
"The FEM_ElementFluid1D command definition"
|
||||
|
||||
@@ -1134,6 +1157,10 @@ FreeCADGui.addCommand(
|
||||
"FEM_ConstraintSelfWeight",
|
||||
_ConstraintSelfWeight()
|
||||
)
|
||||
FreeCADGui.addCommand(
|
||||
"FEM_ConstraintTie",
|
||||
_ConstraintTie()
|
||||
)
|
||||
FreeCADGui.addCommand(
|
||||
"FEM_ElementFluid1D",
|
||||
_ElementFluid1D()
|
||||
|
||||
@@ -33,7 +33,7 @@ import FreeCADGui
|
||||
import FemGui # needed to display the icons in TreeView
|
||||
|
||||
# for the panel
|
||||
from PySide import QtCore
|
||||
from PySide import QtCore, QtGui
|
||||
from . import FemSelectionWidgets
|
||||
|
||||
False if FemGui.__name__ else True # flake8, dummy FemGui usage
|
||||
@@ -68,9 +68,31 @@ class _ViewProviderFemConstraintTie:
|
||||
return
|
||||
|
||||
def setEdit(self, vobj, mode=0):
|
||||
# hide all meshes
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.isDerivedFrom("Fem::FemMeshObject"):
|
||||
o.ViewObject.hide()
|
||||
# show task panel
|
||||
taskd = _TaskPanelFemConstraintTie(self.Object)
|
||||
taskd.obj = vobj.Object
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
def unsetEdit(self, vobj, mode=0):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return True
|
||||
|
||||
def doubleClicked(self, vobj):
|
||||
guidoc = FreeCADGui.getDocument(vobj.Object.Document)
|
||||
# check if another VP is in edit mode
|
||||
# https://forum.freecadweb.org/viewtopic.php?t=13077#p104702
|
||||
if not guidoc.getInEdit():
|
||||
guidoc.setEdit(vobj.Object.Name)
|
||||
else:
|
||||
from PySide.QtGui import QMessageBox
|
||||
message = "Active Task Dialog found! Please close this one before opening a new one!"
|
||||
QMessageBox.critical(None, "Error in tree view", message)
|
||||
FreeCAD.Console.PrintError(message + "\n")
|
||||
return True
|
||||
|
||||
def __getstate__(self):
|
||||
@@ -78,3 +100,79 @@ class _ViewProviderFemConstraintTie:
|
||||
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
|
||||
class _TaskPanelFemConstraintTie:
|
||||
"""The TaskPanel for editing References property of FemConstraintTie objects"""
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
self.obj = obj
|
||||
|
||||
# parameter widget
|
||||
self.parameterWidget = FreeCADGui.PySideUic.loadUi(
|
||||
FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/ConstraintTie.ui"
|
||||
)
|
||||
QtCore.QObject.connect(
|
||||
self.parameterWidget.if_tolerance,
|
||||
QtCore.SIGNAL("valueChanged(Base::Quantity)"),
|
||||
self.tolerance_changed
|
||||
)
|
||||
self.init_parameter_widget()
|
||||
|
||||
# geometry selection widget
|
||||
self.selectionWidget = FemSelectionWidgets.GeometryElementsSelection(
|
||||
obj.References,
|
||||
["Face"]
|
||||
)
|
||||
|
||||
# form made from param and selection widget
|
||||
self.form = [self.parameterWidget, self.selectionWidget]
|
||||
|
||||
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 != 2:
|
||||
msgBox = QtGui.QMessageBox()
|
||||
msgBox.setIcon(QtGui.QMessageBox.Question)
|
||||
msgBox.setText(
|
||||
"Constraint Tie requires exactly two faces\n\nfound references: {}"
|
||||
.format(items)
|
||||
)
|
||||
msgBox.setWindowTitle("FreeCAD FEM Constraint Tie")
|
||||
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.Tolerance = self.tolerance
|
||||
self.obj.References = self.selectionWidget.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.selectionWidget.setback_listobj_visibility()
|
||||
if self.selectionWidget.sel_server:
|
||||
FreeCADGui.Selection.removeObserver(self.selectionWidget.sel_server)
|
||||
doc.resetEdit()
|
||||
|
||||
def init_parameter_widget(self):
|
||||
self.tolerance = self.obj.Tolerance
|
||||
self.parameterWidget.if_tolerance.setText(self.tolerance.UserString)
|
||||
|
||||
def tolerance_changed(self, base_quantity_value):
|
||||
self.tolerance = base_quantity_value
|
||||
|
||||
Reference in New Issue
Block a user