From 805c27ca7baeb4f3d01bc11f894f48077ea2226e Mon Sep 17 00:00:00 2001 From: marioalexis Date: Thu, 27 Mar 2025 15:42:54 -0300 Subject: [PATCH] Base: Improve schema translation for electrical units --- src/Base/UnitsSchemaInternal.cpp | 34 +++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Base/UnitsSchemaInternal.cpp b/src/Base/UnitsSchemaInternal.cpp index c1bf33c321..f06286ff3e 100644 --- a/src/Base/UnitsSchemaInternal.cpp +++ b/src/Base/UnitsSchemaInternal.cpp @@ -370,18 +370,42 @@ UnitsSchemaInternal::schemaTranslate(const Quantity& quant, double& factor, std: factor = 1.0; } else if (unit == Unit::SurfaceChargeDensity) { - unitString = "C/mm^2"; - factor = 1.0; + if (UnitValue <= 1e-4) { + unitString = "C/m^2"; + factor = 1e-6; + } + else if (UnitValue <= 1e-2) { + unitString = "C/cm^2"; + factor = 1e-2; + } + else { + unitString = "C/mm^2"; + factor = 1; + } } else if (unit == Unit::VolumeChargeDensity) { - unitString = "C/mm^3"; - factor = 1.0; + if (UnitValue <= 1e-4) { + unitString = "C/m^3"; + factor = 1e-9; + } + else if (UnitValue <= 1e-2) { + unitString = "C/cm^3"; + factor = 1e-3; + } + else { + unitString = "C/mm^3"; + factor = 1; + } } else if (unit == Unit::CurrentDensity) { - if (UnitValue <= 1e3) { + if (UnitValue <= 1e-4) { unitString = "A/m^2"; factor = 1e-6; } + else if (UnitValue <= 1e-2) { + unitString = "A/cm^2"; + factor = 1e-2; + } else { unitString = "A/mm^2"; factor = 1;