diff --git a/src/App/Application.cpp b/src/App/Application.cpp index f65d14f111..d1811f4310 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1914,6 +1914,7 @@ void Application::initTypes() App::PropertyAcceleration ::init(); App::PropertyForce ::init(); App::PropertyPressure ::init(); + App::PropertyCurrentDensity ::init(); App::PropertyElectricPotential ::init(); App::PropertyVacuumPermittivity ::init(); App::PropertyInteger ::init(); diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index 6c422719ff..01cc7adb42 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -20,9 +20,7 @@ * * ***************************************************************************/ - #include "PreCompiled.h" - #ifndef _PreComp_ # include #endif @@ -88,7 +86,6 @@ Base::Quantity PropertyQuantity::createQuantityFromPy(PyObject *value) return quant; } - void PropertyQuantity::setPyObject(PyObject *value) { // Set the unit if Unit object supplied, else check the unit @@ -140,7 +137,6 @@ const boost::any PropertyQuantity::getPathValue(const ObjectIdentifier & /*path* TYPESYSTEM_SOURCE(App::PropertyQuantityConstraint, App::PropertyQuantity) - void PropertyQuantityConstraint::setConstraints(const Constraints* sConstrain) { _ConstStruct = sConstrain; @@ -151,7 +147,6 @@ const char* PropertyQuantityConstraint::getEditorName() const return "Gui::PropertyEditor::PropertyUnitConstraintItem"; } - const PropertyQuantityConstraint::Constraints* PropertyQuantityConstraint::getConstraints() const { return _ConstStruct; @@ -253,6 +248,18 @@ PropertyDistance::PropertyDistance() setUnit(Base::Unit::Length); } +//************************************************************************** +//************************************************************************** +// PropertyCurrentDensity +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +TYPESYSTEM_SOURCE(App::PropertyCurrentDensity, App::PropertyQuantity) + +PropertyCurrentDensity::PropertyCurrentDensity() +{ + setUnit(Base::Unit::CurrentDensity); +} + //************************************************************************** //************************************************************************** // PropertyElectricPotential diff --git a/src/App/PropertyUnits.h b/src/App/PropertyUnits.h index 4e9f5cd816..43f187c955 100644 --- a/src/App/PropertyUnits.h +++ b/src/App/PropertyUnits.h @@ -172,6 +172,19 @@ public: ~PropertyDistance() override = default; }; +/** CurrentDensity property + * This is a property for electric current densities. It is basically a float + * property. On the Gui it has a quantity of Ampere/m^2. + */ +class AppExport PropertyCurrentDensity: public PropertyQuantity +{ + TYPESYSTEM_HEADER_WITH_OVERRIDE(); + +public: + PropertyCurrentDensity(); + ~PropertyCurrentDensity() override = default; +}; + /** ElectricPotential property * This is a property for electric potentials. It is basically a float * property. On the Gui it has a quantity of Volt. diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt index 2ce0afa6a0..c0e51cea9e 100755 --- a/src/Mod/Fem/CMakeLists.txt +++ b/src/Mod/Fem/CMakeLists.txt @@ -169,6 +169,7 @@ SET(FemObjects_SRCS femobjects/constant_vacuumpermittivity.py femobjects/constraint_bodyheatsource.py femobjects/constraint_centrif.py + femobjects/constraint_currentdensity.py femobjects/constraint_electrostaticpotential.py femobjects/constraint_flowvelocity.py femobjects/constraint_initialflowvelocity.py @@ -565,6 +566,7 @@ SET(FemGuiTaskPanels_SRCS femtaskpanels/__init__.py femtaskpanels/task_constraint_bodyheatsource.py femtaskpanels/task_constraint_centrif.py + femtaskpanels/task_constraint_currentdensity.py femtaskpanels/task_constraint_electrostaticpotential.py femtaskpanels/task_constraint_flowvelocity.py femtaskpanels/task_constraint_initialflowvelocity.py @@ -603,6 +605,7 @@ SET(FemGuiViewProvider_SRCS femviewprovider/view_constant_vacuumpermittivity.py femviewprovider/view_constraint_bodyheatsource.py femviewprovider/view_constraint_centrif.py + femviewprovider/view_constraint_currentdensity.py femviewprovider/view_constraint_electrostaticpotential.py femviewprovider/view_constraint_flowvelocity.py femviewprovider/view_constraint_initialflowvelocity.py diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 9c7b83363d..6b6b4768ab 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -375,6 +375,7 @@ SET(FemGuiPythonUI_SRCS Resources/ui/ConstraintCentrif.ui Resources/ui/ConstraintTie.ui Resources/ui/ConstraintSectionPrint.ui + Resources/ui/CurrentDensity.ui Resources/ui/ElectrostaticPotential.ui Resources/ui/ElementFluid1D.ui Resources/ui/ElementGeometry1D.ui diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index 237c9dbc93..ed339d5213 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -1127,6 +1127,113 @@ bool CmdFemCreateNodesSet::isActive() } +//=========================================================================== +// FEM_CompEmConstraints (dropdown toolbar button for Electromagnetic constraints) +//=========================================================================== + +DEF_STD_CMD_ACL(CmdFemCompEmConstraints) + +CmdFemCompEmConstraints::CmdFemCompEmConstraints() + : Command("FEM_CompEmConstraints") +{ + sAppModule = "Fem"; + sGroup = QT_TR_NOOP("Fem"); + sMenuText = QT_TR_NOOP("Electromagnetic constraints..."); + sToolTipText = QT_TR_NOOP("Electromagnetic constraints"); + sWhatsThis = ""; + sStatusTip = sToolTipText; +} + +void CmdFemCompEmConstraints::activated(int iMsg) +{ + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); + if (iMsg == 0) + rcCmdMgr.runCommandByName("FEM_ConstraintElectrostaticPotential"); + else if (iMsg == 1) + rcCmdMgr.runCommandByName("FEM_ConstraintCurrentDensity"); + else + return; + + // Since the default icon is reset when enabling/disabling the command we have + // to explicitly set the icon of the used command. + Gui::ActionGroup* pcAction = qobject_cast(_pcAction); + QList a = pcAction->actions(); + + assert(iMsg < a.size()); + pcAction->setIcon(a[iMsg]->icon()); +} + +Gui::Action* CmdFemCompEmConstraints::createAction() +{ + Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); + pcAction->setDropDownMenu(true); + applyCommandData(this->className(), pcAction); + + QAction* cmd0 = pcAction->addAction(QString()); + cmd0->setIcon(Gui::BitmapFactory().iconFromTheme("FEM_ConstraintElectrostaticPotential")); + QAction* cmd1 = pcAction->addAction(QString()); + cmd1->setIcon(Gui::BitmapFactory().iconFromTheme("FEM_ConstraintCurrentDensity")); + + _pcAction = pcAction; + languageChange(); + + pcAction->setIcon(cmd0->icon()); + int defaultId = 0; + pcAction->setProperty("defaultAction", QVariant(defaultId)); + + return pcAction; +} + +void CmdFemCompEmConstraints::languageChange() +{ + Command::languageChange(); + + if (!_pcAction) + return; + + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); + + Gui::ActionGroup* pcAction = qobject_cast(_pcAction); + QList a = pcAction->actions(); + + Gui::Command* ConstraintElectrostaticPotential = + rcCmdMgr.getCommandByName("FEM_ConstraintElectrostaticPotential"); + if (ConstraintElectrostaticPotential) { + QAction* cmd0 = a[0]; + cmd0->setText(QApplication::translate("FEM_ConstraintElectrostaticPotential", + ConstraintElectrostaticPotential->getMenuText())); + cmd0->setToolTip(QApplication::translate("FEM_ConstraintElectrostaticPotential", + ConstraintElectrostaticPotential->getToolTipText())); + cmd0->setStatusTip(QApplication::translate("FEM_ConstraintElectrostaticPotential", + ConstraintElectrostaticPotential->getStatusTip())); + } + + Gui::Command* ConstraintCurrentDensity = + rcCmdMgr.getCommandByName("FEM_ConstraintCurrentDensity"); + if (ConstraintCurrentDensity) { + QAction* cmd1 = a[1]; + cmd1->setText(QApplication::translate("FEM_ConstraintCurrentDensity", + ConstraintCurrentDensity->getMenuText())); + cmd1->setToolTip(QApplication::translate("FEM_ConstraintCurrentDensity", + ConstraintCurrentDensity->getToolTipText())); + cmd1->setStatusTip(QApplication::translate("FEM_ConstraintCurrentDensity", + ConstraintCurrentDensity->getStatusTip())); + } +} + +bool CmdFemCompEmConstraints::isActive() +{ + // only if there is an active analysis + Fem::FemAnalysis* ActiveAnalysis = + FemGui::ActiveAnalysisObserver::instance()->getActiveObject(); + if (!ActiveAnalysis + || !ActiveAnalysis->getTypeId().isDerivedFrom(Fem::FemAnalysis::getClassTypeId())) + return false; + + return true; +} + + //================================================================================================ //================================================================================================ // commands vtk post processing @@ -1906,6 +2013,7 @@ void CreateFemCommands() rcCmdMgr.addCommand(new CmdFemConstraintTemperature()); rcCmdMgr.addCommand(new CmdFemConstraintTransform()); rcCmdMgr.addCommand(new CmdFemConstraintSpring()); + rcCmdMgr.addCommand(new CmdFemCompEmConstraints()); // mesh rcCmdMgr.addCommand(new CmdFemCreateNodesSet()); diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc index e234b02672..d3e26dd411 100755 --- a/src/Mod/Fem/Gui/Resources/Fem.qrc +++ b/src/Mod/Fem/Gui/Resources/Fem.qrc @@ -13,6 +13,7 @@ icons/FEM_ConstraintBodyHeatSource.svg icons/FEM_ConstraintCentrif.svg icons/FEM_ConstraintContact.svg + icons/FEM_ConstraintCurrentDensity.svg icons/FEM_ConstraintDisplacement.svg icons/FEM_ConstraintElectrostaticPotential.svg icons/FEM_ConstraintFixed.svg @@ -158,6 +159,7 @@ ui/ConstraintCentrif.ui ui/ConstraintSectionPrint.ui ui/ConstraintTie.ui + ui/CurrentDensity.ui ui/ElectrostaticPotential.ui ui/ElementFluid1D.ui ui/ElementGeometry1D.ui diff --git a/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCurrentDensity.svg b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCurrentDensity.svg new file mode 100644 index 0000000000..59109789a7 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/icons/FEM_ConstraintCurrentDensity.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + [vdwalts] + + + 2016-08-01 + 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/CurrentDensity.ui b/src/Mod/Fem/Gui/Resources/ui/CurrentDensity.ui new file mode 100644 index 0000000000..c2d528a4b9 --- /dev/null +++ b/src/Mod/Fem/Gui/Resources/ui/CurrentDensity.ui @@ -0,0 +1,79 @@ + + + Form + + + + 0 + 0 + 350 + 40 + + + + Constraint Properties + + + + + + Current density: + + + + + + + Qt::Horizontal + + + + 130 + 19 + + + + + + + + true + + + + 100 + 20 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + -1000000000000000000000.000000000000000 + + + 1000000000000000000000.000000000000000 + + + 100.000000000000000 + + + 0.000000000000000 + + + + + + + + Gui::QuantitySpinBox + QWidget +
Gui/QuantitySpinBox.h
+
+
+ + +
diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp index 22acd1a946..10c4a9c2e3 100755 --- a/src/Mod/Fem/Gui/Workbench.cpp +++ b/src/Mod/Fem/Gui/Workbench.cpp @@ -114,10 +114,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "FEM_ElementGeometry2D" << "FEM_ElementFluid1D"; - Gui::ToolBarItem* electrostat = new Gui::ToolBarItem(root); - electrostat->setCommand("Electrostatic Constraints"); - *electrostat - << "FEM_ConstraintElectrostaticPotential"; + Gui::ToolBarItem* electromag = new Gui::ToolBarItem(root); + electromag->setCommand("Electromagnetic Constraints"); + *electromag + << "FEM_CompEmConstraints"; Gui::ToolBarItem* fluid = new Gui::ToolBarItem(root); fluid->setCommand("Fluid Constraints"); @@ -244,9 +244,10 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "FEM_ElementFluid1D"; Gui::MenuItem* elec = new Gui::MenuItem; - elec->setCommand("&Electrostatic Constraints"); + elec->setCommand("&Electromagnetic Constraints"); *elec - << "FEM_ConstraintElectrostaticPotential"; + << "FEM_ConstraintElectrostaticPotential" + << "FEM_ConstraintCurrentDensity"; Gui::MenuItem* fluid = new Gui::MenuItem; fluid->setCommand("&Fluid Constraints"); diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py index fb9976e9e9..6f28572cee 100644 --- a/src/Mod/Fem/ObjectsFem.py +++ b/src/Mod/Fem/ObjectsFem.py @@ -113,6 +113,21 @@ def makeConstraintCentrif( return obj +def makeConstraintCurrentDensity( + doc, + name="ConstraintCurrentDensity" +): + """makeConstraintCurrentDensity(document, [name]): + makes a Fem CurrentDensity object""" + obj = doc.addObject("Fem::ConstraintPython", name) + from femobjects import constraint_currentdensity + constraint_currentdensity.ConstraintCurrentDensity(obj) + if FreeCAD.GuiUp: + from femviewprovider import view_constraint_currentdensity + view_constraint_currentdensity.VPConstraintCurrentDensity(obj.ViewObject) + return obj + + def makeConstraintContact( doc, name="ConstraintContact" diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py index 8935b0b9dd..de79368982 100644 --- a/src/Mod/Fem/femcommands/commands.py +++ b/src/Mod/Fem/femcommands/commands.py @@ -209,6 +209,23 @@ class _ConstraintCentrif(CommandManager): self.is_active = "with_analysis" self.do_activated = "add_obj_on_gui_set_edit" +class _ConstraintCurrentDensity(CommandManager): + "The FEM_ConstraintCurrentDensity command definition" + + def __init__(self): + super(_ConstraintCurrentDensity, self).__init__() + self.pixmap = "FEM_ConstraintCurrentDensity" + self.menutext = Qt.QT_TRANSLATE_NOOP( + "FEM_ConstraintCurrentDensity", + "Constraint current density" + ) + self.tooltip = Qt.QT_TRANSLATE_NOOP( + "FEM_ConstraintCurrentDensity", + "Creates a FEM constraint current density" + ) + self.is_active = "with_analysis" + self.do_activated = "add_obj_on_gui_set_edit" + class _ConstraintElectrostaticPotential(CommandManager): "The FEM_ConstraintElectrostaticPotential command definition" @@ -1112,6 +1129,10 @@ FreeCADGui.addCommand( "FEM_ConstraintCentrif", _ConstraintCentrif() ) +FreeCADGui.addCommand( + "FEM_ConstraintCurrentDensity", + _ConstraintCurrentDensity() +) FreeCADGui.addCommand( "FEM_ConstraintElectrostaticPotential", _ConstraintElectrostaticPotential() diff --git a/src/Mod/Fem/femobjects/constraint_currentdensity.py b/src/Mod/Fem/femobjects/constraint_currentdensity.py new file mode 100644 index 0000000000..1d8594478a --- /dev/null +++ b/src/Mod/Fem/femobjects/constraint_currentdensity.py @@ -0,0 +1,54 @@ +# *************************************************************************** +# * Copyright (c) 2023 Uwe Stöhr * +# * * +# * 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 current density document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package constraint_currentdensity +# \ingroup FEM +# \brief constraint body heat source object + +from . import base_fempythonobject + + +class ConstraintCurrentDensity(base_fempythonobject.BaseFemPythonObject): + + Type = "Fem::ConstraintCurrentDensity" + + def __init__(self, obj): + super(ConstraintCurrentDensity, self).__init__(obj) + self.add_properties(obj) + + def onDocumentRestored(self, obj): + self.add_properties(obj) + + def add_properties(self, obj): + if not hasattr(obj, "CurrentDensity"): + obj.addProperty( + "App::PropertyCurrentDensity", + "CurrentDensity", + "Parameter", + "Current Density" + ) + obj.CurrentDensity = 0.0 diff --git a/src/Mod/Fem/femtaskpanels/task_constraint_currentdensity.py b/src/Mod/Fem/femtaskpanels/task_constraint_currentdensity.py new file mode 100644 index 0000000000..437e689a22 --- /dev/null +++ b/src/Mod/Fem/femtaskpanels/task_constraint_currentdensity.py @@ -0,0 +1,123 @@ +# *************************************************************************** +# * Copyright (c) 2023 Uwe Stöhr * +# * * +# * 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 current density task panel for the document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package task_constraint_currentdensity +# \ingroup FEM +# \brief task panel for constraint current density 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/CurrentDensity.ui") + self._initParamWidget() + + # geometry selection widget + # start with Solid in list! + self._selectionWidget = selection_widgets.GeometryElementsSelection( + obj.References, + ["Solid", "Face"], + 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.currentDensityQSB.setProperty( + 'value', self._obj.CurrentDensity) + FreeCADGui.ExpressionBinding( + self._paramWidget.currentDensityQSB).bind(self._obj, "CurrentDensity") + self._paramWidget.currentDensityQSB.setProperty( + 'value', self._obj.CurrentDensity) + + def _applyWidgetChanges(self): + currentdensity = None + try: + currentdensity = self._paramWidget.currentDensityQSB.property('value') + except ValueError: + FreeCAD.Console.PrintMessage( + "Wrong input. Not recognised input: '{}' " + "Current density has not been set.\n" + .format(self._paramWidget.currentDensityQSB.text()) + ) + if currentdensity is not None: + self._obj.CurrentDensity = currentdensity diff --git a/src/Mod/Fem/femtest/app/test_object.py b/src/Mod/Fem/femtest/app/test_object.py index db1ff559c9..841005bd81 100644 --- a/src/Mod/Fem/femtest/app/test_object.py +++ b/src/Mod/Fem/femtest/app/test_object.py @@ -173,6 +173,10 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintContact", type_of_obj(ObjectsFem.makeConstraintContact(doc)) ) + self.assertEqual( + "Fem::ConstraintCurrentDensity", + type_of_obj(ObjectsFem.makeConstraintCurrentDensity(doc)) + ) self.assertEqual( "Fem::ConstraintDisplacement", type_of_obj(ObjectsFem.makeConstraintDisplacement(doc)) @@ -398,6 +402,10 @@ class TestObjectType(unittest.TestCase): ObjectsFem.makeConstraintContact(doc), "Fem::ConstraintContact" )) + self.assertTrue(is_of_type( + ObjectsFem.makeConstraintCurrentDensity(doc), + "Fem::ConstraintCurrentDensity" + )) self.assertTrue(is_of_type( ObjectsFem.makeConstraintDisplacement(doc), "Fem::ConstraintDisplacement" @@ -678,18 +686,33 @@ class TestObjectType(unittest.TestCase): "Fem::ConstraintContact" )) - # ConstraintDisplacement - constraint_dicplacement = ObjectsFem.makeConstraintDisplacement(doc) + # ConstraintCurrentDensity + constraint_currentdensity = ObjectsFem.makeConstraintCurrentDensity(doc) self.assertTrue(is_derived_from( - constraint_dicplacement, + constraint_currentdensity, "App::DocumentObject" )) self.assertTrue(is_derived_from( - constraint_dicplacement, + constraint_currentdensity, + "Fem::ConstraintPython" + )) + self.assertTrue(is_derived_from( + constraint_currentdensity, + "Fem::ConstraintCurrentDensity" + )) + + # ConstraintDisplacement + constraint_displacement = ObjectsFem.makeConstraintDisplacement(doc) + self.assertTrue(is_derived_from( + constraint_displacement, + "App::DocumentObject" + )) + self.assertTrue(is_derived_from( + constraint_displacement, "Fem::Constraint" )) self.assertTrue(is_derived_from( - constraint_dicplacement, + constraint_displacement, "Fem::ConstraintDisplacement" )) @@ -1431,13 +1454,19 @@ class TestObjectType(unittest.TestCase): ) self.assertTrue( ObjectsFem.makeConstraintBodyHeatSource( - doc).isDerivedFrom("Fem::ConstraintPython") + doc + ).isDerivedFrom("Fem::ConstraintPython") ) self.assertTrue( ObjectsFem.makeConstraintContact( doc ).isDerivedFrom("Fem::ConstraintContact") ) + self.assertTrue( + ObjectsFem.makeConstraintCurrentDensity( + doc + ).isDerivedFrom("Fem::ConstraintPython") + ) self.assertTrue( ObjectsFem.makeConstraintDisplacement( doc @@ -1696,6 +1725,7 @@ def create_all_fem_objects_doc( analysis.addObject(ObjectsFem.makeConstraintBearing(doc)) analysis.addObject(ObjectsFem.makeConstraintBodyHeatSource(doc)) analysis.addObject(ObjectsFem.makeConstraintContact(doc)) + analysis.addObject(ObjectsFem.makeConstraintCurrentDensity(doc)) analysis.addObject(ObjectsFem.makeConstraintDisplacement(doc)) analysis.addObject(ObjectsFem.makeConstraintElectrostaticPotential(doc)) analysis.addObject(ObjectsFem.makeConstraintFixed(doc)) diff --git a/src/Mod/Fem/femtest/app/test_open.py b/src/Mod/Fem/femtest/app/test_open.py index 808119b4f6..f3c81b28cc 100644 --- a/src/Mod/Fem/femtest/app/test_open.py +++ b/src/Mod/Fem/femtest/app/test_open.py @@ -168,6 +168,9 @@ class TestObjectOpen(unittest.TestCase): self, doc ): + import ObjectsFem + from femtools.femutils import type_of_obj + # see comments at file end, the code was created by some python code """ # see code lines after comment block for the smarter version @@ -183,6 +186,11 @@ class TestObjectOpen(unittest.TestCase): doc.ConstraintBodyHeatSource.Proxy.__class__ ) + self.assertEqual( + "Fem::ConstraintCurrentDensity", + type_of_obj(ObjectsFem.makeConstraintCurrentDensity(doc)) + ) + from femobjects.constraint_electrostaticpotential import ConstraintElectrostaticPotential self.assertEqual( ConstraintElectrostaticPotential, diff --git a/src/Mod/Fem/femtest/gui/test_open.py b/src/Mod/Fem/femtest/gui/test_open.py index a185b5026a..f6ffd0f010 100644 --- a/src/Mod/Fem/femtest/gui/test_open.py +++ b/src/Mod/Fem/femtest/gui/test_open.py @@ -148,6 +148,9 @@ class TestObjectOpen(unittest.TestCase): self, doc ): + import ObjectsFem + from femtools.femutils import type_of_obj + # see comments at file end, the code was created by some python code from femviewprovider.view_constraint_bodyheatsource import VPConstraintBodyHeatSource @@ -156,6 +159,11 @@ class TestObjectOpen(unittest.TestCase): doc.ConstraintBodyHeatSource.ViewObject.Proxy.__class__ ) + self.assertEqual( + "Fem::ConstraintCurrentDensity", + type_of_obj(ObjectsFem.makeConstraintCurrentDensity(doc)) + ) + from femviewprovider.view_constraint_electrostaticpotential \ import VPConstraintElectroStaticPotential self.assertEqual( diff --git a/src/Mod/Fem/femviewprovider/view_constraint_currentdensity.py b/src/Mod/Fem/femviewprovider/view_constraint_currentdensity.py new file mode 100644 index 0000000000..3dac559673 --- /dev/null +++ b/src/Mod/Fem/femviewprovider/view_constraint_currentdensity.py @@ -0,0 +1,44 @@ +# *************************************************************************** +# * Copyright (c) 2023 Uwe Stöhr * +# * * +# * 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 current density ViewProvider for the document object" +__author__ = "Uwe Stöhr" +__url__ = "https://www.freecadweb.org" + +## @package view_constraint_currentdensity +# \ingroup FEM +# \brief view provider for the constraint current density object + +from femtaskpanels import task_constraint_currentdensity +from . import view_base_femconstraint + + +class VPConstraintCurrentDensity(view_base_femconstraint.VPBaseFemConstraint): + + def setEdit(self, vobj, mode=0): + view_base_femconstraint.VPBaseFemConstraint.setEdit( + self, + vobj, + mode, + task_constraint_currentdensity._TaskPanel + )