Base: [skip ci] add an enum for unit schemes in Python to avoid to work with numbers
This commit is contained in:
@@ -824,6 +824,27 @@ App.Units.DynamicViscosity = App.Units.Unit(-1,1,-1)
|
||||
App.Units.KinematicViscosity = App.Units.Unit(2,0,-1)
|
||||
App.Units.VacuumPermittivity = App.Units.Unit(-3,-1,4,2)
|
||||
|
||||
# Add an enum for the different unit schemes
|
||||
if sys.version_info.major < 3:
|
||||
IntEnum = object
|
||||
else:
|
||||
from enum import IntEnum
|
||||
|
||||
# The values must match with that of the
|
||||
# C++ enum class UnitSystem
|
||||
class Scheme(IntEnum):
|
||||
SI1 = 0
|
||||
SI2 = 1
|
||||
Imperial1 = 2
|
||||
ImperialDecimal = 3
|
||||
Centimeters = 4
|
||||
ImperialBuilding = 5
|
||||
MmMin = 6
|
||||
ImperialCivil = 7
|
||||
FemMilliMeterNewton = 8
|
||||
|
||||
App.Units.Scheme = Scheme
|
||||
|
||||
# clean up namespace
|
||||
del(InitApplications)
|
||||
del(test_ascii)
|
||||
|
||||
@@ -108,7 +108,7 @@ class Writer(object):
|
||||
# the units are consistent
|
||||
# TODO retrieve the seven base units from FreeCAD unit schema
|
||||
# instead of hard coding them here for a second once
|
||||
self.unit_schema = 0
|
||||
self.unit_schema = Units.Scheme.SI1
|
||||
self.unit_system = { # standard FreeCAD Base units = unit schema 0
|
||||
"L": "mm",
|
||||
"M": "kg",
|
||||
@@ -119,13 +119,13 @@ class Writer(object):
|
||||
"J": "cd",
|
||||
}
|
||||
param = ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
self.unit_schema = param.GetInt("UserSchema", 0)
|
||||
if self.unit_schema == 0:
|
||||
self.unit_schema = param.GetInt("UserSchema", Units.Scheme.SI1)
|
||||
if self.unit_schema == Units.Scheme.SI1:
|
||||
Console.PrintMessage(
|
||||
"The FreeCAD standard unit schema mm/kg/s is used. "
|
||||
"Elmer sif-file writing is done in Standard FreeCAD units.\n"
|
||||
)
|
||||
elif self.unit_schema == 1:
|
||||
elif self.unit_schema == Units.Scheme.SI2:
|
||||
Console.PrintMessage(
|
||||
"The SI unit schema m/kg/s is used. "
|
||||
"Elmer sif-file writing is done in SI-units.\n"
|
||||
@@ -139,7 +139,7 @@ class Writer(object):
|
||||
"N": "mol",
|
||||
"J": "cd",
|
||||
}
|
||||
elif self.unit_schema == 8:
|
||||
elif self.unit_schema == Units.Scheme.FemMilliMeterNewton:
|
||||
# see also unit comment in calculix writer
|
||||
Console.PrintMessage(
|
||||
"The FEM unit schema mm/N/s is used. "
|
||||
@@ -154,12 +154,12 @@ class Writer(object):
|
||||
"N": "mol",
|
||||
"J": "cd",
|
||||
}
|
||||
elif self.unit_schema > 1 and self.unit_schema != 8:
|
||||
elif self.unit_schema > Units.Scheme.SI2 and self.unit_schema != Units.Scheme.FemMilliMeterNewton:
|
||||
Console.PrintMessage(
|
||||
"Unit schema: {} not supported by Elmer writer. "
|
||||
"The FreeCAD standard unit schema mm/kg/s is used. "
|
||||
"Elmer sif-file writing is done in Standard FreeCAD units.\n"
|
||||
.format(self.unit_schema)
|
||||
.format(Units.listSchemas(self.unit_schema))
|
||||
)
|
||||
|
||||
def _getFromUi(self, value, unit, outputDim):
|
||||
@@ -277,7 +277,7 @@ class Writer(object):
|
||||
def _handleSimulation(self):
|
||||
self._simulation("Coordinate System", "Cartesian 3D")
|
||||
self._simulation("Coordinate Mapping", (1, 2, 3))
|
||||
if self.unit_schema == 1:
|
||||
if self.unit_schema == Units.Scheme.SI2:
|
||||
self._simulation("Coordinate Scaling", 0.001)
|
||||
Console.PrintMessage(
|
||||
"'Coordinate Scaling = Real 0.001' was inserted into the solver input file.\n"
|
||||
@@ -881,7 +881,7 @@ class Writer(object):
|
||||
s["Procedure"] = sifio.FileAttr("ResultOutputSolve/ResultOutputSolver")
|
||||
s["Output File Name"] = sifio.FileAttr("case")
|
||||
s["Vtu Format"] = True
|
||||
if self.unit_schema == 1:
|
||||
if self.unit_schema == Units.Scheme.SI2:
|
||||
s["Coordinate Scaling Revert"] = True
|
||||
Console.PrintMessage(
|
||||
"'Coordinate Scaling Revert = Logical True' was "
|
||||
|
||||
Reference in New Issue
Block a user