From eaf49f82ee2d5440fdeeeaab3d531ee08f7eda8e Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 26 May 2025 16:33:45 +0100 Subject: [PATCH] [App] Use consistent unit schema names (#21355) * [Start] ensure user's preferred unit schema is retained after restart of application * [App] use consistent schema names throughout the application * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [Start] Revert commit 2eea421 in preference to PR #21466 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/App/FreeCADInit.py | 11 ++++++----- src/Mod/Fem/femsolver/elmer/writer.py | 17 +++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index f4ee025aef..f248c3efb4 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -928,15 +928,16 @@ 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 + Internal = 0 + MKS = 1 + Imperial = 2 ImperialDecimal = 3 - Centimeters = 4 + Centimeter = 4 ImperialBuilding = 5 MmMin = 6 ImperialCivil = 7 - FemMilliMeterNewton = 8 + FEM = 8 + MeterDecimal = 9 App.Units.Scheme = Scheme diff --git a/src/Mod/Fem/femsolver/elmer/writer.py b/src/Mod/Fem/femsolver/elmer/writer.py index 8e54b2b972..974729667f 100644 --- a/src/Mod/Fem/femsolver/elmer/writer.py +++ b/src/Mod/Fem/femsolver/elmer/writer.py @@ -138,7 +138,7 @@ class Writer: # 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 = Units.Scheme.SI1 + self.unit_schema = Units.Scheme.Internal self.unit_system = { # standard FreeCAD Base units = unit schema 0 "L": "m", "M": "kg", @@ -149,13 +149,13 @@ class Writer: "J": "cd", } param = ParamGet("User parameter:BaseApp/Preferences/Units") - self.unit_schema = param.GetInt("UserSchema", Units.Scheme.SI1) - if self.unit_schema == Units.Scheme.SI1: + self.unit_schema = param.GetInt("UserSchema", Units.Scheme.Internal) + if self.unit_schema == Units.Scheme.Internal: Console.PrintMessage( "The FreeCAD standard unit schema mm/kg/s is used. " "Elmer sif-file writing is however done in SI units.\n" ) - elif self.unit_schema == Units.Scheme.SI2: + elif self.unit_schema == Units.Scheme.MKS: Console.PrintMessage( "The SI unit schema m/kg/s is used. " "Elmer sif-file writing is done in SI-units.\n" @@ -169,7 +169,7 @@ class Writer: "N": "mol", "J": "cd", } - elif self.unit_schema == Units.Scheme.FemMilliMeterNewton: + elif self.unit_schema == Units.Scheme.FEM: # see also unit comment in calculix writer Console.PrintMessage( "The FEM unit schema mm/N/s is used. " @@ -184,10 +184,7 @@ class Writer: "N": "mol", "J": "cd", } - elif ( - self.unit_schema > Units.Scheme.SI2 - and self.unit_schema != Units.Scheme.FemMilliMeterNewton - ): + elif self.unit_schema > Units.Scheme.MKS and self.unit_schema != Units.Scheme.FEM: Console.PrintMessage( "Unit schema: {} not supported by Elmer writer. " "The FreeCAD standard unit schema mm/kg/s is used. " @@ -829,7 +826,7 @@ class Writer: s["Binary Output"] = self.solver.BinaryOutput s["Save Geometry Ids"] = self.solver.SaveGeometryIndex s["Vtu Time Collection"] = True - if self.unit_schema == Units.Scheme.SI2: + if self.unit_schema == Units.Scheme.MKS: s["Coordinate Scaling Revert"] = True Console.PrintMessage( "'Coordinate Scaling Revert = Logical True' was "