Skip to content

Commit 3c63cd3

Browse files
committed
Fem: update body heat source
1 parent 0676d36 commit 3c63cd3

File tree

3 files changed

+215
-86
lines changed

3 files changed

+215
-86
lines changed

src/Mod/Fem/Gui/Resources/ui/BodyHeatSource.ui

+105-46
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,115 @@
1313
<property name="windowTitle">
1414
<string>Analysis feature properties</string>
1515
</property>
16-
<layout class="QHBoxLayout" name="horizontalLayout">
16+
<layout class="QVBoxLayout" name="horizontalLayout">
1717
<item>
18-
<widget class="QLabel" name="pressureLbl">
19-
<property name="text">
20-
<string>Body heat in W/kg:</string>
18+
<widget class="QGroupBox" name="gpb_heat_source">
19+
<property name="sizePolicy">
20+
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
21+
<horstretch>0</horstretch>
22+
<verstretch>0</verstretch>
23+
</sizepolicy>
2124
</property>
22-
</widget>
23-
</item>
24-
<item>
25-
<spacer name="horizontalSpacer">
26-
<property name="orientation">
27-
<enum>Qt::Horizontal</enum>
28-
</property>
29-
<property name="sizeHint" stdset="0">
30-
<size>
31-
<width>130</width>
32-
<height>19</height>
33-
</size>
34-
</property>
35-
</spacer>
36-
</item>
37-
<item>
38-
<widget class="Gui::QuantitySpinBox" name="bodyheatQSB">
39-
<property name="enabled">
40-
<bool>true</bool>
41-
</property>
42-
<property name="minimumSize">
43-
<size>
44-
<width>100</width>
45-
<height>20</height>
46-
</size>
47-
</property>
48-
<property name="alignment">
49-
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
50-
</property>
51-
<property name="keyboardTracking">
52-
<bool>true</bool>
53-
</property>
54-
<property name="minimum">
55-
<double>0.000000000000000</double>
56-
</property>
57-
<property name="maximum">
58-
<double>1000000000000000000000.000000000000000</double>
59-
</property>
60-
<property name="singleStep">
61-
<double>50.000000000000000</double>
25+
<property name="toolTip">
26+
<string/>
6227
</property>
63-
<property name="value">
64-
<double>0.000000000000000</double>
28+
<property name="title">
29+
<string>Heat Source</string>
6530
</property>
31+
<layout class="QFormLayout" name="f_layout_heat_source">
32+
<item row="0" column="0">
33+
<widget class="QLabel" name="lbl_dissipation_rat">
34+
<property name="text">
35+
<string>Dissipation Rate:</string>
36+
</property>
37+
</widget>
38+
</item>
39+
<item row="0" column="1">
40+
<widget class="QComboBox" name="cb_mode"/>
41+
</item>
42+
<item row="1" column="0">
43+
<widget class="QLabel" name="lbl_total_power">
44+
<property name="text">
45+
<string>Total Power:</string>
46+
</property>
47+
</widget>
48+
</item>
49+
<item row="1" column="1">
50+
<widget class="Gui::QuantitySpinBox" name="qsb_total_power">
51+
<property name="enabled">
52+
<bool>true</bool>
53+
</property>
54+
<property name="unit" stdset="0">
55+
<string notr="true">W</string>
56+
</property>
57+
<property name="minimumSize">
58+
<size>
59+
<width>100</width>
60+
<height>20</height>
61+
</size>
62+
</property>
63+
<property name="alignment">
64+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
65+
</property>
66+
<property name="keyboardTracking">
67+
<bool>true</bool>
68+
</property>
69+
<property name="minimum">
70+
<double>0.000000000000000</double>
71+
</property>
72+
<property name="maximum">
73+
<double>1000000000000000000000.000000000000000</double>
74+
</property>
75+
<property name="singleStep">
76+
<double>50.000000000000000</double>
77+
</property>
78+
<property name="value">
79+
<double>0.000000000000000</double>
80+
</property>
81+
</widget>
82+
</item>
83+
<item row="2" column="0">
84+
<widget class="QLabel" name="lbl_dissipation_rat">
85+
<property name="text">
86+
<string>Dissipation Rate:</string>
87+
</property>
88+
</widget>
89+
</item>
90+
<item row="2" column="1">
91+
<widget class="Gui::QuantitySpinBox" name="qsb_dissipation_rate">
92+
<property name="enabled">
93+
<bool>true</bool>
94+
</property>
95+
<property name="unit" stdset="0">
96+
<string notr="true">W/kg</string>
97+
</property>
98+
<property name="minimumSize">
99+
<size>
100+
<width>100</width>
101+
<height>20</height>
102+
</size>
103+
</property>
104+
<property name="alignment">
105+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
106+
</property>
107+
<property name="keyboardTracking">
108+
<bool>true</bool>
109+
</property>
110+
<property name="minimum">
111+
<double>0.000000000000000</double>
112+
</property>
113+
<property name="maximum">
114+
<double>1000000000000000000000.000000000000000</double>
115+
</property>
116+
<property name="singleStep">
117+
<double>50.000000000000000</double>
118+
</property>
119+
<property name="value">
120+
<double>0.000000000000000</double>
121+
</property>
122+
</widget>
123+
</item>
124+
</layout>
66125
</widget>
67126
</item>
68127
</layout>

src/Mod/Fem/femobjects/constraint_bodyheatsource.py

+52-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ***************************************************************************
22
# * Copyright (c) 2017 Markus Hovorka <[email protected]> *
33
# * Copyright (c) 2020 Bernd Hahnebach <[email protected]> *
4+
# * Copyright (c) 2024 Mario Passaglia <[email protected]> *
45
# * *
56
# * This file is part of the FreeCAD CAx development system. *
67
# * *
@@ -23,7 +24,7 @@
2324
# ***************************************************************************
2425

2526
__title__ = "FreeCAD FEM constraint body heat source document object"
26-
__author__ = "Markus Hovorka, Bernd Hahnebach"
27+
__author__ = "Markus Hovorka, Bernd Hahnebach, Mario Passaglia"
2728
__url__ = "https://www.freecad.org"
2829

2930
## @package constraint_bodyheatsource
@@ -32,25 +33,62 @@
3233

3334
from . import base_fempythonobject
3435

36+
_PropHelper = base_fempythonobject._PropHelper
3537

3638
class ConstraintBodyHeatSource(base_fempythonobject.BaseFemPythonObject):
3739

3840
Type = "Fem::ConstraintBodyHeatSource"
3941

4042
def __init__(self, obj):
4143
super(ConstraintBodyHeatSource, self).__init__(obj)
42-
self.add_properties(obj)
4344

44-
def onDocumentRestored(self, obj):
45-
self.add_properties(obj)
46-
47-
def add_properties(self, obj):
48-
if not hasattr(obj, "HeatSource"):
49-
obj.addProperty(
50-
"App::PropertyFloat",
51-
"HeatSource",
52-
"Base",
53-
"Body heat source"
45+
for prop in self._get_properties():
46+
prop.add_to_object(obj)
47+
48+
49+
def _get_properties(self):
50+
prop = []
51+
52+
prop.append(_PropHelper(
53+
type = "App::PropertyDissipationRate",
54+
name = "DissipationRate",
55+
group = "Constraint Body Heat Source",
56+
doc = "Power dissipated per unit mass",
57+
value = "0 W/kg"
58+
)
59+
)
60+
prop.append(_PropHelper(
61+
type = "App::PropertyPower",
62+
name = "TotalPower",
63+
group = "Constraint Body Heat Source",
64+
doc = "Total power dissipated",
65+
value = "0 W"
66+
)
67+
)
68+
prop.append(_PropHelper(
69+
type = "App::PropertyEnumeration",
70+
name = "Mode",
71+
group = "Constraint Body Heat Source",
72+
doc = "Switch quantity input mode",
73+
value = ["DissipationRate", "TotalPower"]
5474
)
55-
obj.setPropertyStatus("HeatSource", "LockDynamic")
56-
obj.HeatSource = 0.0
75+
)
76+
77+
return prop
78+
79+
80+
def onDocumentRestored(self, obj):
81+
# update old project with new properties
82+
for prop in self._get_properties():
83+
try:
84+
obj.getPropertyByName(prop.name)
85+
except:
86+
prop.add_to_object(obj)
87+
88+
# migrate old HeatSource property
89+
try:
90+
value = obj.getPropertyByName("HeatSource")
91+
obj.DissipationRate = FreeCAD.Units.Quantity(value, "W/kg")
92+
obj.Mode = "DissipationRate"
93+
except:
94+
pass

src/Mod/Fem/femtaskpanels/task_constraint_bodyheatsource.py

+58-26
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,31 @@
4141
class _TaskPanel(object):
4242

4343
def __init__(self, obj):
44-
self._obj = obj
44+
self.obj = obj
4545

4646
self._paramWidget = FreeCADGui.PySideUic.loadUi(
4747
FreeCAD.getHomePath() + "Mod/Fem/Resources/ui/BodyHeatSource.ui")
48-
self._initParamWidget()
48+
49+
self._init_param_widget()
50+
51+
QtCore.QObject.connect(
52+
self.parameterWidget.spb_dissipation_rate,
53+
QtCore.SIGNAL("valueChanged(Base::Quantity)"),
54+
self.dissipation_rate_changed
55+
)
56+
57+
QtCore.QObject.connect(
58+
self.parameterWidget.spb_total_power,
59+
QtCore.SIGNAL("valueChanged(Base::Quantity)"),
60+
self.total_power_changed
61+
)
62+
63+
QtCore.QObject.connect(
64+
self.parameterWidget.cb_mode,
65+
QtCore.SIGNAL("currentIndexChanged(int)"),
66+
self.mode_changed
67+
)
68+
4969

5070
# geometry selection widget
5171
# start with Solid in list!
@@ -77,20 +97,23 @@ def open(self):
7797
self._part.ViewObject.show()
7898

7999
def reject(self):
80-
self._restoreVisibility()
100+
self.restore_visibility()
81101
FreeCADGui.ActiveDocument.resetEdit()
82102
return True
83103

84104
def accept(self):
85-
if self._obj.References != self._selectionWidget.references:
86-
self._obj.References = self._selectionWidget.references
105+
self.obj.References = self._selectionWidget.references
106+
self.obj.DissipationRate = self.dissipation_rate
107+
self.obj.TotalPower = self.total_power
108+
self.obj.Mode = self.mode
109+
87110
self._applyWidgetChanges()
88-
self._obj.Document.recompute()
111+
self.obj.Document.recompute()
89112
FreeCADGui.ActiveDocument.resetEdit()
90-
self._restoreVisibility()
113+
self.restore_visibility()
91114
return True
92115

93-
def _restoreVisibility(self):
116+
def restore_visibility(self):
94117
if self._mesh is not None and self._part is not None:
95118
if self._meshVisible:
96119
self._mesh.ViewObject.show()
@@ -101,21 +124,30 @@ def _restoreVisibility(self):
101124
else:
102125
self._part.ViewObject.hide()
103126

104-
def _initParamWidget(self):
105-
self._paramWidget.bodyheatQSB.setProperty(
106-
'value', self._obj.HeatSource)
107-
self._paramWidget.bodyheatQSB.setProperty("unit", "W/kg")
108-
FreeCADGui.ExpressionBinding(self._paramWidget.bodyheatQSB).bind(self._obj, "HeatSource")
109-
110-
def _applyWidgetChanges(self):
111-
bodyheat = None
112-
try:
113-
bodyheat = self._paramWidget.bodyheatQSB.property('value').getValueAs("W/kg")
114-
except ValueError:
115-
FreeCAD.Console.PrintMessage(
116-
"Wrong input. Not recognised input: '{}' "
117-
"Body heat has not been set.\n"
118-
.format(self._paramWidget.bodyheatQSB.text())
119-
)
120-
if bodyheat is not None:
121-
self._obj.HeatSource = float(bodyheat)
127+
128+
def init_parameter_widget(self):
129+
self.dissipation_rate = self.obj.DissipationRate
130+
self.total_power = self.obj.TotalPower
131+
FreeCADGui.ExpressionBinding(self.parameterWidget.qsb_dissipation_rate)\
132+
.bind(self.obj, "DissipationRate")
133+
self.parameterWidget.qsb_dissipation_rate.setProperty("value", self.dissipation_rate)
134+
135+
FreeCADGui.ExpressionBinding(self.parameterWidget.qsb_total_power)\
136+
.bind(self.obj, "TotalPower")
137+
self.parameterWidget.qsb_total_power.setProperty("value", self.total_power)
138+
139+
self.mode = self.obj.Mode
140+
self.mode_enum = self.obj.getEnumerationsOfProperty("Mode")
141+
self.parameterWidget.cb_mode.addItems(self.mode_enum)
142+
index = self.mode_enum.index(self.mode)
143+
self.parameterWidget.cb_mode.setCurrentIndex(index)
144+
145+
146+
def dissipation_rate_changed(self, base_quantity_value):
147+
self.dissipation_rate = base_quantity_value
148+
149+
def total_power_changed(self, base_quantity_value):
150+
self.total_power = base_quantity_value
151+
152+
def mode_changed(self, index):
153+
self.mode = self.mode_enum[index]

0 commit comments

Comments
 (0)