diff --git a/src/Mod/Fem/CMakeLists.txt b/src/Mod/Fem/CMakeLists.txt
index 44a79d9a8fd8..2b713716d025 100755
--- a/src/Mod/Fem/CMakeLists.txt
+++ b/src/Mod/Fem/CMakeLists.txt
@@ -199,6 +199,8 @@ SET(FemObjectsScripts_SRCS
femobjects/_FemResultMechanical.py
femobjects/_FemSolverCalculix.py
femobjects/FemConstraint.py
+ femobjects/_FemBodySource.py
+ femobjects/_FemInitialValue.py
)
SET(FemAllScripts
@@ -276,6 +278,9 @@ SET(FemGuiScripts_SRCS
femguiobjects/_ViewProviderFemSolverCalculix.py
femguiobjects/FemSelectionWidgets.py
femguiobjects/ViewProviderFemConstraint.py
+ femguiobjects/_ViewProviderFemBodySource.py
+ femguiobjects/_ViewProviderFemInitialValue.py
+ femguiobjects/BodyConstraintWidget.py
)
diff --git a/src/Mod/Fem/Gui/Resources/Fem.qrc b/src/Mod/Fem/Gui/Resources/Fem.qrc
index 04cbc0624dfb..1162aeafb19a 100755
--- a/src/Mod/Fem/Gui/Resources/Fem.qrc
+++ b/src/Mod/Fem/Gui/Resources/Fem.qrc
@@ -8,6 +8,8 @@
icons/fem-add-fem-mesh.svg
icons/fem-add-material.svg
icons/fem-add-part.svg
+ icons/fem-add-body-source.svg
+ icons/fem-add-initial-value.svg
icons/fem-analysis.svg
icons/fem-clipping-plane-add.svg
diff --git a/src/Mod/Fem/Gui/Workbench.cpp b/src/Mod/Fem/Gui/Workbench.cpp
index 7ffe5894fd57..d2fb2387bcfb 100755
--- a/src/Mod/Fem/Gui/Workbench.cpp
+++ b/src/Mod/Fem/Gui/Workbench.cpp
@@ -104,11 +104,13 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Separator"
<< "FEM_ConstraintForce"
<< "FEM_ConstraintPressure"
+ << "FEM_BodyAcceleration"
<< "FEM_ConstraintSelfWeight";
Gui::ToolBarItem* thermal = new Gui::ToolBarItem(root);
thermal->setCommand("Thermal Constraints");
*thermal << "FEM_ConstraintInitialTemperature"
+ << "FEM_InitialTemperature"
<< "Separator"
<< "FEM_ConstraintTemperature"
<< "FEM_ConstraintHeatflux";
@@ -214,6 +216,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "FEM_ConstraintForce"
<< "FEM_ConstraintPressure"
<< "FEM_ConstraintSelfWeight"
+ << "FEM_BodyAcceleration"
<< "Separator"
<< "FEM_ConstraintBearing"
<< "FEM_ConstraintGear"
@@ -222,6 +225,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
Gui::MenuItem* thermal = new Gui::MenuItem;
thermal->setCommand("&Thermal Constraints");
*thermal << "FEM_ConstraintInitialTemperature"
+ << "FEM_InitialTemperature"
<< "Separator"
<< "FEM_ConstraintHeatflux"
<< "FEM_ConstraintTemperature"
diff --git a/src/Mod/Fem/ObjectsFem.py b/src/Mod/Fem/ObjectsFem.py
index 32c8b787cdc6..a40a7732a379 100644
--- a/src/Mod/Fem/ObjectsFem.py
+++ b/src/Mod/Fem/ObjectsFem.py
@@ -43,7 +43,7 @@ def makeConstraintBearing(doc, name="ConstraintBearing"):
obj = doc.addObject("Fem::ConstraintBearing", name)
return obj
-
+#DEPRECATED
def makeConstraintBodyHeatSource(doc, name="ConstraintBodyHeatSource"):
'''makeConstraintBodyHeatSource(document, [name]): makes a Fem ConstraintBodyHeatSource object'''
obj = doc.addObject("Fem::ConstraintPython", name)
@@ -118,7 +118,7 @@ def makeConstraintHeatflux(doc, name="ConstraintHeatflux"):
obj = doc.addObject("Fem::ConstraintHeatflux", name)
return obj
-
+#DEPRECATED
def makeConstraintInitialFlowVelocity(doc, name="ConstraintInitialFlowVelocity"):
'''makeConstraintInitialFlowVelocity(document, [name]): makes a Fem ConstraintInitialFlowVelocity object'''
obj = doc.addObject("Fem::ConstraintPython", name)
@@ -129,13 +129,42 @@ def makeConstraintInitialFlowVelocity(doc, name="ConstraintInitialFlowVelocity")
_ViewProviderFemConstraintInitialFlowVelocity.ViewProxy(obj.ViewObject)
return obj
-
+#DEPRECATED
def makeConstraintInitialTemperature(doc, name="ConstraintInitialTemperature"):
'''makeConstraintInitialTemperature(document, name): makes a Fem ConstraintInitialTemperature object'''
obj = doc.addObject("Fem::ConstraintInitialTemperature", name)
return obj
+def makeBodySource(doc, bodySource, name="BodySource"):
+ '''makeBodySource(document, [name]): creates an body source such as heat source, gravity'''
+ if not (name) and bodySource and 'Name' in bodySource:
+ name = "BodySource" + bodySource['Name']
+ obj = doc.addObject("Fem::FeaturePython", name) # App::DocumentObject can not add dynamic property
+ from femobjects import _FemBodySource
+ _FemBodySource._FemBodySource(obj)
+ obj.BodySource = bodySource
+
+ if FreeCAD.GuiUp:
+ from femguiobjects import _ViewProviderFemBodySource
+ _ViewProviderFemBodySource._ViewProvider(obj.ViewObject)
+ return obj
+
+
+def makeInitialValue(doc, initialValue, name="IntialValue"):
+ '''makeConstraintSelfWeight(document, [name]): creates an self weight object to define a gravity load'''
+ if not (name) and initialValue and 'Name' in initialValue:
+ name = initialValue['Name'] + 'InitialValue'
+ obj = doc.addObject("Fem::FeaturePython", name)
+ from femobjects import _FemInitialValue
+ _FemInitialValue._FemInitialValue(obj)
+ obj.InitialValue = initialValue
+ if FreeCAD.GuiUp:
+ from femguiobjects import _ViewProviderFemInitialValue
+ _ViewProviderFemInitialValue._ViewProvider(obj.ViewObject)
+ return obj
+
+
def makeConstraintPlaneRotation(doc, name="ConstraintPlaneRotation"):
'''makeConstraintPlaneRotation(document, [name]): makes a Fem ConstraintPlaneRotation object'''
obj = doc.addObject("Fem::ConstraintPlaneRotation", name)
diff --git a/src/Mod/Fem/femcommands/commands.py b/src/Mod/Fem/femcommands/commands.py
index aa129a0dbc1d..42834fe3df7b 100644
--- a/src/Mod/Fem/femcommands/commands.py
+++ b/src/Mod/Fem/femcommands/commands.py
@@ -105,6 +105,57 @@ def Activated(self):
FreeCADGui.doCommand("nodes = sg.getChildren()")
FreeCADGui.doCommand(line1 + line2 + line3)
+# where is the best place to put these constants?
+_DefaultInitialTemperature = "{'Name': 'Temperature', 'Symbol': u'T','ValueType': 'Expression', 'NumberOfComponents': 1, 'Unit': 'K', 'Value': 300}"
+_DefaultBodyAcceleration = "{'Name': 'Acceleration', 'Symbol': u'g','ValueType': 'Quantity', 'NumberOfComponents': 3, 'Unit': 'm/s^2', 'Value': [0, 0, -9.8]}"
+
+class _CommandFemInitialTemperature(CommandManager):
+ "The FEM_InitialTemperature command definition"
+ def __init__(self):
+ super(_CommandFemInitialTemperature, self).__init__()
+ self.resources = {
+ 'Pixmap': 'fem-add-initial-value',
+ 'MenuText': QtCore.QT_TRANSLATE_NOOP(
+ "FEM_InitialTemperature",
+ "initial temperature value"),
+ 'ToolTip': QtCore.QT_TRANSLATE_NOOP(
+ "FEM_InitialTemperature",
+ "Creates an initialtemperature value")}
+ self.is_active = 'with_analysis'
+
+ def Activated(self):
+ FreeCAD.ActiveDocument.openTransaction("Create Fem InitialValue")
+ FreeCADGui.addModule("ObjectsFem")
+ # fill with a customised BodyConstrainSettings python dict
+ FreeCADGui.doCommand("bcs = {}".format(_DefaultInitialTemperature))
+ FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeInitialValue(FreeCAD.ActiveDocument, bcs))")
+ FreeCADGui.doCommand("FreeCADGui.ActiveDocument.setEdit(FreeCAD.ActiveDocument.ActiveObject.Name)")
+ FreeCADGui.Selection.clearSelection()
+ FreeCAD.ActiveDocument.recompute()
+
+
+class _CommandFemBodyAcceleration(CommandManager):
+ "The FEM_BodyAcceleration command definition"
+ def __init__(self):
+ super(_CommandFemBodyAcceleration, self).__init__()
+ self.resources = {
+ 'Pixmap': 'fem-add-body-source',
+ 'MenuText': QtCore.QT_TRANSLATE_NOOP(
+ "FEM_BodyAcceleration",
+ "Constraint BodyAcceleration (gravity)"),
+ 'ToolTip': QtCore.QT_TRANSLATE_NOOP(
+ "FEM_BodyAcceleration",
+ "Creates a FEM body constraint of acceleration")}
+ self.is_active = 'with_analysis'
+
+ def Activated(self):
+ FreeCAD.ActiveDocument.openTransaction("Create Fem BodyAcceleration")
+ FreeCADGui.addModule("ObjectsFem")
+ # make a customised BodyConstrainSettings python dict
+ FreeCADGui.doCommand("bcs = {}".format(_DefaultBodyAcceleration))
+ FreeCADGui.doCommand("FemGui.getActiveAnalysis().addObject(ObjectsFem.makeBodySource(FreeCAD.ActiveDocument, bcs))")
+ FreeCAD.ActiveDocument.recompute()
+
class _CommandFemConstraintBodyHeatSource(CommandManager):
"The FEM_ConstraintBodyHeatSource command definition"
@@ -840,6 +891,8 @@ def Activated(self):
FreeCADGui.addCommand('FEM_ConstraintFlowVelocity', _CommandFemConstraintFlowVelocity())
FreeCADGui.addCommand('FEM_ConstraintInitialFlowVelocity', _CommandFemConstraintInitialFlowVelocity())
FreeCADGui.addCommand('FEM_ConstraintSelfWeight', _CommandFemConstraintSelfWeight())
+FreeCADGui.addCommand('FEM_InitialTemperature', _CommandFemInitialTemperature())
+FreeCADGui.addCommand('FEM_BodyAcceleration', _CommandFemBodyAcceleration())
FreeCADGui.addCommand('FEM_ElementFluid1D', _CommandFemElementFluid1D())
FreeCADGui.addCommand('FEM_ElementGeometry1D', _CommandFemElementGeometry1D())
FreeCADGui.addCommand('FEM_ElementGeometry2D', _CommandFemElementGeometry2D())