[FEM] Elecrostatic: use App::PropertyElectricPotential

This commit is contained in:
Uwe
2022-03-26 02:29:19 +01:00
parent f2def75852
commit a5b86128be
3 changed files with 8 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ __url__ = "https://www.freecadweb.org"
# \ingroup FEM
# \brief constraint electrostatic potential object
from FreeCAD import Units
from . import base_fempythonobject
@@ -47,10 +48,10 @@ class ConstraintElectrostaticPotential(base_fempythonobject.BaseFemPythonObject)
def add_properties(self, obj):
if not hasattr(obj, "Potential"):
obj.addProperty(
"App::PropertyFloat",
"App::PropertyElectricPotential",
"Potential",
"Parameter",
"Potential"
"Electric Potential"
),
obj.Potential = 0.0

View File

@@ -462,10 +462,9 @@ class Writer(object):
for obj in self._getMember("Fem::ConstraintElectrostaticPotential"):
if obj.References:
for name in obj.References[0][1]:
# https://forum.freecadweb.org/viewtopic.php?f=18&t=41488&start=10#p369454 ff
if obj.PotentialEnabled:
if hasattr(obj, "Potential"):
potential = self._getFromUi(obj.Potential, "V", "M*L^2/(T^3 * I)")
potential = float(obj.Potential.getValueAs("V"))
self._boundary(name, "Potential", potential)
if obj.PotentialConstant:
self._boundary(name, "Potential Constant", True)

View File

@@ -91,10 +91,8 @@ class _TaskPanel(object):
self._part.ViewObject.hide()
def _initParamWidget(self):
unit = "V"
quantity = Units.Quantity("{} {}".format(self._obj.Potential, unit))
self._paramWidget.potentialQSB.setProperty(
'value', quantity)
'value', self._obj.Potential)
self._paramWidget.potentialBox.setChecked(
not self._obj.PotentialEnabled)
self._paramWidget.potentialConstantBox.setChecked(
@@ -125,13 +123,12 @@ class _TaskPanel(object):
potential = Units.Quantity(self._paramWidget.potentialQSB.text())
except ValueError:
FreeCAD.Console.PrintMessage(
"Wrong input. OK has been triggered without a green hook "
"in the input field. Not recognised input: '{}' "
"Wrong input. Not recognised input: '{}' "
"Potential has not been set.\n"
.format(self._paramWidget.potentialTxt.text())
.format(self._paramWidget.potentialQSB.text())
)
if potential is not None:
self._obj.Potential = potential.getValueAs(unit).Value
self._obj.Potential = potential
self._obj.PotentialConstant = self._paramWidget.potentialConstantBox.isChecked()