[FEM] add new constraint for magnetization

This commit is contained in:
Uwe
2023-02-08 06:24:18 +01:00
parent 2ffd650f20
commit f6abb77758
16 changed files with 1024 additions and 1 deletions

View File

@@ -96,6 +96,7 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WindowFlags fl )
<< Base::Unit::MagneticFieldStrength
<< Base::Unit::MagneticFlux
<< Base::Unit::MagneticFluxDensity
<< Base::Unit::Magnetization
<< Base::Unit::Pressure
<< Base::Unit::Power
<< Base::Unit::SpecificHeat

View File

@@ -174,6 +174,7 @@ SET(FemObjects_SRCS
femobjects/constraint_flowvelocity.py
femobjects/constraint_initialflowvelocity.py
femobjects/constraint_initialpressure.py
femobjects/constraint_magnetization.py
femobjects/constraint_sectionprint.py
femobjects/constraint_selfweight.py
femobjects/constraint_tie.py
@@ -579,6 +580,7 @@ SET(FemGuiTaskPanels_SRCS
femtaskpanels/task_constraint_flowvelocity.py
femtaskpanels/task_constraint_initialflowvelocity.py
femtaskpanels/task_constraint_initialpressure.py
femtaskpanels/task_constraint_magnetization.py
femtaskpanels/task_constraint_sectionprint.py
femtaskpanels/task_constraint_tie.py
femtaskpanels/task_element_fluid1D.py
@@ -618,6 +620,7 @@ SET(FemGuiViewProvider_SRCS
femviewprovider/view_constraint_flowvelocity.py
femviewprovider/view_constraint_initialflowvelocity.py
femviewprovider/view_constraint_initialpressure.py
femviewprovider/view_constraint_magnetization.py
femviewprovider/view_constraint_sectionprint.py
femviewprovider/view_constraint_selfweight.py
femviewprovider/view_constraint_tie.py

View File

@@ -384,6 +384,7 @@ SET(FemGuiPythonUI_SRCS
Resources/ui/FlowVelocity.ui
Resources/ui/InitialFlowVelocity.ui
Resources/ui/InitialPressure.ui
Resources/ui/Magnetization.ui
Resources/ui/Material.ui
Resources/ui/MaterialReinforcement.ui
Resources/ui/MeshBoundaryLayer.ui

View File

@@ -1261,6 +1261,8 @@ void CmdFemCompEmConstraints::activated(int iMsg)
rcCmdMgr.runCommandByName("FEM_ConstraintElectrostaticPotential");
else if (iMsg == 1)
rcCmdMgr.runCommandByName("FEM_ConstraintCurrentDensity");
else if (iMsg == 2)
rcCmdMgr.runCommandByName("FEM_ConstraintMagnetization");
else
return;
@@ -1283,6 +1285,8 @@ Gui::Action* CmdFemCompEmConstraints::createAction()
cmd0->setIcon(Gui::BitmapFactory().iconFromTheme("FEM_ConstraintElectrostaticPotential"));
QAction* cmd1 = pcAction->addAction(QString());
cmd1->setIcon(Gui::BitmapFactory().iconFromTheme("FEM_ConstraintCurrentDensity"));
QAction* cmd2 = pcAction->addAction(QString());
cmd2->setIcon(Gui::BitmapFactory().iconFromTheme("FEM_ConstraintMagnetization"));
_pcAction = pcAction;
languageChange();
@@ -1329,6 +1333,18 @@ void CmdFemCompEmConstraints::languageChange()
cmd1->setStatusTip(QApplication::translate("FEM_ConstraintCurrentDensity",
ConstraintCurrentDensity->getStatusTip()));
}
Gui::Command* ConstraintMagnetization =
rcCmdMgr.getCommandByName("FEM_ConstraintMagnetization");
if (ConstraintMagnetization) {
QAction* cmd2 = a[2];
cmd2->setText(QApplication::translate("FEM_ConstraintMagnetization",
ConstraintMagnetization->getMenuText()));
cmd2->setToolTip(QApplication::translate("FEM_ConstraintMagnetization",
ConstraintMagnetization->getToolTipText()));
cmd2->setStatusTip(QApplication::translate("FEM_ConstraintMagnetization",
ConstraintMagnetization->getStatusTip()));
}
}
bool CmdFemCompEmConstraints::isActive()

View File

@@ -25,6 +25,7 @@
<file>icons/FEM_ConstraintInitialFlowVelocity.svg</file>
<file>icons/FEM_ConstraintInitialPressure.svg</file>
<file>icons/FEM_ConstraintInitialTemperature.svg</file>
<file>icons/FEM_ConstraintMagnetization.svg</file>
<file>icons/FEM_ConstraintPlaneRotation.svg</file>
<file>icons/FEM_ConstraintPressure.svg</file>
<file>icons/FEM_ConstraintPulley.svg</file>
@@ -169,6 +170,7 @@
<file>ui/FlowVelocity.ui</file>
<file>ui/InitialFlowVelocity.ui</file>
<file>ui/InitialPressure.ui</file>
<file>ui/Magnetization.ui</file>
<file>ui/Material.ui</file>
<file>ui/MaterialReinforcement.ui</file>
<file>ui/MeshBoundaryLayer.ui</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -0,0 +1,446 @@
<?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>313</width>
<height>133</height>
</rect>
</property>
<property name="windowTitle">
<string>Constraint Properties</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="pressureLbl">
<property name="text">
<string>Magnetization</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="labelReal">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Real</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="labelImaginary">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Imaginary</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelX">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>x</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::QuantitySpinBox" name="realXQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Real part of potential x-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QCheckBox" name="reXunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="Gui::QuantitySpinBox" name="imagXQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Imaginary part of potential x-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QCheckBox" name="imXunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelY">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>y</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::QuantitySpinBox" name="realYQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Real part of potential y-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QCheckBox" name="reYunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="Gui::QuantitySpinBox" name="imagYQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Imaginary part of potential y-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QCheckBox" name="imYunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelZ">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>z</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="Gui::QuantitySpinBox" name="realZQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Real part of potential z-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="reZunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="Gui::QuantitySpinBox" name="imagZQSB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Imaginary part of potential z-component</string>
</property>
<property name="keyboardTracking">
<bool>true</bool>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
<property name="minimum">
<double>-1000000000000000000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000000000000000000.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QCheckBox" name="imZunspecBox">
<property name="toolTip">
<string>unspecified</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::QuantitySpinBox</class>
<extends>QWidget</extends>
<header>Gui/QuantitySpinBox.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>reXunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>realXQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>61</y>
</hint>
<hint type="destinationlabel">
<x>80</x>
<y>61</y>
</hint>
</hints>
</connection>
<connection>
<sender>reYunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>realYQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>87</y>
</hint>
<hint type="destinationlabel">
<x>80</x>
<y>87</y>
</hint>
</hints>
</connection>
<connection>
<sender>imZunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>imagZQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>297</x>
<y>113</y>
</hint>
<hint type="destinationlabel">
<x>224</x>
<y>113</y>
</hint>
</hints>
</connection>
<connection>
<sender>imYunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>imagYQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>297</x>
<y>87</y>
</hint>
<hint type="destinationlabel">
<x>224</x>
<y>87</y>
</hint>
</hints>
</connection>
<connection>
<sender>imXunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>imagXQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>297</x>
<y>61</y>
</hint>
<hint type="destinationlabel">
<x>224</x>
<y>61</y>
</hint>
</hints>
</connection>
<connection>
<sender>reZunspecBox</sender>
<signal>toggled(bool)</signal>
<receiver>realZQSB</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>113</y>
</hint>
<hint type="destinationlabel">
<x>80</x>
<y>113</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -246,7 +246,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
elec->setCommand("&Electromagnetic Constraints");
*elec
<< "FEM_ConstraintElectrostaticPotential"
<< "FEM_ConstraintCurrentDensity";
<< "FEM_ConstraintCurrentDensity"
<< "FEM_ConstraintMagnetization";
Gui::MenuItem* fluid = new Gui::MenuItem;
fluid->setCommand("&Fluid Constraints");

View File

@@ -268,6 +268,21 @@ def makeConstraintInitialTemperature(
return obj
def makeConstraintMagnetization(
doc,
name="ConstraintMagnetization"
):
"""makeConstraintMagnetization(document, [name]):
makes a Fem Magnetization object"""
obj = doc.addObject("Fem::ConstraintPython", name)
from femobjects import constraint_magnetization
constraint_magnetization.ConstraintMagnetization(obj)
if FreeCAD.GuiUp:
from femviewprovider import view_constraint_magnetization
view_constraint_magnetization.VPConstraintMagnetization(obj.ViewObject)
return obj
def makeConstraintPlaneRotation(
doc,
name="ConstraintPlaneRotation"

View File

@@ -295,6 +295,23 @@ class _ConstraintInitialPressure(CommandManager):
self.do_activated = "add_obj_on_gui_set_edit"
class _ConstraintMagnetization(CommandManager):
"The FEM_ConstraintMagnetization command definition"
def __init__(self):
super(_ConstraintMagnetization, self).__init__()
self.menutext = Qt.QT_TRANSLATE_NOOP(
"FEM_ConstraintMagnetization",
"Constraint magnetization"
)
self.tooltip = Qt.QT_TRANSLATE_NOOP(
"FEM_ConstraintMagnetization",
"Creates a FEM constraint magnetization"
)
self.is_active = "with_analysis"
self.do_activated = "add_obj_on_gui_set_edit"
class _ConstraintSectionPrint(CommandManager):
"The FEM_ConstraintSectionPrint command definition"
@@ -1166,6 +1183,10 @@ FreeCADGui.addCommand(
"FEM_ConstraintInitialPressure",
_ConstraintInitialPressure()
)
FreeCADGui.addCommand(
"FEM_ConstraintMagnetization",
_ConstraintMagnetization()
)
FreeCADGui.addCommand(
"FEM_ConstraintSectionPrint",
_ConstraintSectionPrint()

View File

@@ -0,0 +1,144 @@
# ***************************************************************************
# * Copyright (c) 2023 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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 magnetization document object"
__author__ = "Uwe Stöhr"
__url__ = "https://www.freecadweb.org"
## @package constraint_magnetization
# \ingroup FEM
# \brief constraint magnetization source object
from . import base_fempythonobject
class ConstraintMagnetization(base_fempythonobject.BaseFemPythonObject):
Type = "Fem::ConstraintMagnetization"
def __init__(self, obj):
super(ConstraintMagnetization, self).__init__(obj)
self.add_properties(obj)
def onDocumentRestored(self, obj):
self.add_properties(obj)
def add_properties(self, obj):
if not hasattr(obj, "Magnetization_re_1"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_re_1",
"Vector Potential",
"Real part of magnetization x-component"
)
obj.Magnetization_re_1 = "0 A/m"
if not hasattr(obj, "Magnetization_re_2"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_re_2",
"Vector Potential",
"Real part of magnetization y-component"
)
obj.Magnetization_re_2 = "0 A/m"
if not hasattr(obj, "Magnetization_re_3"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_re_3",
"Vector Potential",
"Real part of magnetization z-component"
)
obj.Magnetization_re_3 = "0 A/m"
if not hasattr(obj, "Magnetization_im_1"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_im_1",
"Vector Potential",
"Imaginary part of magnetization x-component"
)
obj.Magnetization_im_1 = "0 A/m"
if not hasattr(obj, "Magnetization_im_2"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_im_2",
"Vector Potential",
"Imaginary part of magnetization y-component"
)
obj.Magnetization_im_2 = "0 A/m"
if not hasattr(obj, "Magnetization_im_3"):
obj.addProperty(
"App::PropertyMagnetization",
"Magnetization_im_3",
"Vector Potential",
"Imaginary part of magnetization z-component"
)
obj.Magnetization_im_3 = "0 A/m"
# now the enable bools
if not hasattr(obj, "Magnetization_re_1_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_re_1_Disabled",
"Vector Potential",
""
)
obj.Magnetization_re_1_Disabled = True
if not hasattr(obj, "Magnetization_re_2_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_re_2_Disabled",
"Vector Potential",
""
)
obj.Magnetization_re_2_Disabled = True
if not hasattr(obj, "Magnetization_re_3_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_re_3_Disabled",
"Vector Potential",
""
)
obj.Magnetization_re_3_Disabled = True
if not hasattr(obj, "Magnetization_im_1_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_im_1_Disabled",
"Vector Potential",
""
)
obj.Magnetization_im_1_Disabled = True
if not hasattr(obj, "Magnetization_im_2_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_im_2_Disabled",
"Vector Potential",
""
)
obj.Magnetization_im_2_Disabled = True
if not hasattr(obj, "Magnetization_im_3_Disabled"):
obj.addProperty(
"App::PropertyBool",
"Magnetization_im_3_Disabled",
"Vector Potential",
""
)
obj.Magnetization_im_3_Disabled = True

View File

@@ -0,0 +1,187 @@
# ***************************************************************************
# * Copyright (c) 2023 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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 magnetization task panel for the document object"
__author__ = "Uwe Stöhr"
__url__ = "https://www.freecadweb.org"
## @package task_constraint_magnetization
# \ingroup FEM
# \brief task panel for constraint magnetization object
import FreeCAD
import FreeCADGui
from femguiutils import selection_widgets
from femtools import femutils
from femtools import membertools
class _TaskPanel(object):
def __init__(self, obj):
self._obj = obj
self._paramWidget = FreeCADGui.PySideUic.loadUi(
FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/Magnetization.ui")
self._initParamWidget()
# geometry selection widget
# magnetization is always a body force for 3D, therefore only allow solid
self._selectionWidget = selection_widgets.GeometryElementsSelection(
obj.References,
["Solid"],
True,
False
)
# form made from param and selection widget
self.form = [self._paramWidget, self._selectionWidget]
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):
self._restoreVisibility()
FreeCADGui.ActiveDocument.resetEdit()
return True
def accept(self):
if self._obj.References != self._selectionWidget.references:
self._obj.References = self._selectionWidget.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):
self._paramWidget.realXQSB.setProperty(
'value', self._obj.Magnetization_re_1)
FreeCADGui.ExpressionBinding(
self._paramWidget.realXQSB).bind(self._obj, "Magnetization_re_1")
self._paramWidget.realYQSB.setProperty(
'value', self._obj.Magnetization_re_2)
FreeCADGui.ExpressionBinding(
self._paramWidget.realYQSB).bind(self._obj, "Magnetization_re_2")
self._paramWidget.realZQSB.setProperty(
'value', self._obj.Magnetization_re_3)
FreeCADGui.ExpressionBinding(
self._paramWidget.realZQSB).bind(self._obj, "Magnetization_re_3")
self._paramWidget.imagXQSB.setProperty(
'value', self._obj.Magnetization_im_1)
FreeCADGui.ExpressionBinding(
self._paramWidget.imagXQSB).bind(self._obj, "Magnetization_im_1")
self._paramWidget.imagYQSB.setProperty(
'value', self._obj.Magnetization_im_2)
FreeCADGui.ExpressionBinding(
self._paramWidget.imagYQSB).bind(self._obj, "Magnetization_im_2")
self._paramWidget.imagZQSB.setProperty(
'value', self._obj.Magnetization_im_3)
FreeCADGui.ExpressionBinding(
self._paramWidget.imagZQSB).bind(self._obj, "Magnetization_im_3")
self._paramWidget.reXunspecBox.setChecked(
self._obj.Magnetization_re_1)
self._paramWidget.reYunspecBox.setChecked(
self._obj.Magnetization_re_2)
self._paramWidget.reZunspecBox.setChecked(
self._obj.Magnetization_re_3)
self._paramWidget.imXunspecBox.setChecked(
self._obj.Magnetization_im_1)
self._paramWidget.imYunspecBox.setChecked(
self._obj.Magnetization_im_2)
self._paramWidget.imZunspecBox.setChecked(
self._obj.Magnetization_im_3)
def _applyMagnetizationChanges(self, enabledBox, magnetizationQSB):
enabled = enabledBox.isChecked()
magnetization = None
try:
magnetization = magnetizationQSB.property('value')
except ValueError:
FreeCAD.Console.PrintMessage(
"Wrong input. Not recognised input: '{}' "
"Magnetization has not been set.\n".format(magnetizationQSB.text())
)
magnetization = '0.0 A/m'
return enabled, magnetization
def _applyWidgetChanges(self):
# apply the magnetizations and their enabled state
self._obj.Magnetization_re_1_Disabled, self._obj.Magnetization_re_1 = \
self._applyMagnetizationChanges(
self._paramWidget.reXunspecBox,
self._paramWidget.realXQSB
)
self._obj.Magnetization_re_2_Disabled, self._obj.Magnetization_re_2 = \
self._applyMagnetizationChanges(
self._paramWidget.reYunspecBox,
self._paramWidget.realYQSB
)
self._obj.Magnetization_re_3_Disabled, self._obj.Magnetization_re_3 = \
self._applyMagnetizationChanges(
self._paramWidget.reZunspecBox,
self._paramWidget.realZQSB
)
self._obj.Magnetization_im_1_Disabled, self._obj.Magnetization_im_1 = \
self._applyMagnetizationChanges(
self._paramWidget.imXunspecBox,
self._paramWidget.imagXQSB
)
self._obj.Magnetization_im_2_Disabled, self._obj.Magnetization_im_2 = \
self._applyMagnetizationChanges(
self._paramWidget.imYunspecBox,
self._paramWidget.imagYQSB
)
self._obj.Magnetization_im_3_Disabled, self._obj.Magnetization_im_3 = \
self._applyMagnetizationChanges(
self._paramWidget.imZunspecBox,
self._paramWidget.imagZQSB
)

View File

@@ -225,6 +225,10 @@ class TestObjectType(unittest.TestCase):
"Fem::ConstraintInitialTemperature",
type_of_obj(ObjectsFem.makeConstraintInitialTemperature(doc))
)
self.assertEqual(
"Fem::ConstraintMagnetization",
type_of_obj(ObjectsFem.makeConstraintMagnetization(doc))
)
self.assertEqual(
"Fem::ConstraintPlaneRotation",
type_of_obj(ObjectsFem.makeConstraintPlaneRotation(doc))
@@ -430,6 +434,10 @@ class TestObjectType(unittest.TestCase):
ObjectsFem.makeConstraintFluidBoundary(doc),
"Fem::ConstraintFluidBoundary"
))
self.assertTrue(is_of_type(
ObjectsFem.makeConstraintMagnetization(doc),
"Fem::ConstraintMagnetization"
))
self.assertTrue(is_of_type(
ObjectsFem.makeConstraintSpring(doc),
"Fem::ConstraintSpring"
@@ -784,6 +792,21 @@ class TestObjectType(unittest.TestCase):
"Fem::ConstraintFluidBoundary"
))
# ConstraintMagnetization
constraint_magnetization = ObjectsFem.makeConstraintMagnetization(doc)
self.assertTrue(is_derived_from(
constraint_magnetization,
"App::DocumentObject"
))
self.assertTrue(is_derived_from(
constraint_magnetization,
"Fem::ConstraintPython"
))
self.assertTrue(is_derived_from(
constraint_magnetization,
"Fem::ConstraintMagnetization"
))
# ConstraintSpring
constraint_spring = ObjectsFem.makeConstraintSpring(doc)
self.assertTrue(is_derived_from(
@@ -1513,6 +1536,11 @@ class TestObjectType(unittest.TestCase):
doc
).isDerivedFrom("Fem::ConstraintFluidBoundary")
)
self.assertTrue(
ObjectsFem.makeConstraintMagnetization(
doc
).isDerivedFrom("Fem::ConstraintPython")
)
self.assertTrue(
ObjectsFem.makeConstraintSpring(
doc
@@ -1767,6 +1795,7 @@ def create_all_fem_objects_doc(
analysis.addObject(ObjectsFem.makeConstraintInitialFlowVelocity(doc))
analysis.addObject(ObjectsFem.makeConstraintInitialPressure(doc))
analysis.addObject(ObjectsFem.makeConstraintInitialTemperature(doc))
analysis.addObject(ObjectsFem.makeConstraintMagnetization(doc))
analysis.addObject(ObjectsFem.makeConstraintPlaneRotation(doc))
analysis.addObject(ObjectsFem.makeConstraintPressure(doc))
analysis.addObject(ObjectsFem.makeConstraintPulley(doc))

View File

@@ -209,6 +209,11 @@ class TestObjectOpen(unittest.TestCase):
doc.ConstraintInitialFlowVelocity.Proxy.__class__
)
self.assertEqual(
"Fem::ConstraintMagnetization",
type_of_obj(ObjectsFem.makeConstraintMagnetization(doc))
)
from femobjects.constraint_selfweight import ConstraintSelfWeight
self.assertEqual(
ConstraintSelfWeight,

View File

@@ -184,6 +184,11 @@ class TestObjectOpen(unittest.TestCase):
doc.ConstraintInitialFlowVelocity.ViewObject.Proxy.__class__
)
self.assertEqual(
"Fem::ConstraintMagnetization",
type_of_obj(ObjectsFem.makeConstraintMagnetization(doc))
)
from femviewprovider.view_constraint_selfweight import VPConstraintSelfWeight
self.assertEqual(
VPConstraintSelfWeight,

View File

@@ -0,0 +1,44 @@
# ***************************************************************************
# * Copyright (c) 2023 Uwe Stöhr <uwestoehr@lyx.org> *
# * *
# * 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 magnetization ViewProvider for the document object"
__author__ = "Uwe Stöhr"
__url__ = "https://www.freecadweb.org"
## @package view_constraint_magnetization
# \ingroup FEM
# \brief view provider for constraint magnetization object
from femtaskpanels import task_constraint_magnetization
from . import view_base_femconstraint
class VPConstraintMagnetization(view_base_femconstraint.VPBaseFemConstraint):
def setEdit(self, vobj, mode=0):
view_base_femconstraint.VPBaseFemConstraint.setEdit(
self,
vobj,
mode,
task_constraint_magnetization._TaskPanel
)