[Base] fix issues with new units

- also sort units for better overview
This commit is contained in:
Uwe
2023-02-26 20:06:30 +01:00
parent 4714135880
commit 1032fe4468
3 changed files with 134 additions and 153 deletions

View File

@@ -534,68 +534,59 @@ QString Unit::getTypeString() const
return QString();
}
Unit Unit::Length(1);
Unit Unit::Area(2);
Unit Unit::Volume(3);
Unit Unit::Mass(0,1);
// SI base units
Unit Unit::AmountOfSubstance (0, 0, 0, 0, 0, 1);
Unit Unit::ElectricCurrent (0, 0, 0, 1);
Unit Unit::Length (1);
Unit Unit::LuminousIntensity (0, 0, 0, 0, 0, 0, 1);
Unit Unit::Mass (0, 1);
Unit Unit::Temperature (0, 0, 0, 0, 1);
Unit Unit::TimeSpan (0, 0, 1);
// Angle, deg
Unit Unit::Angle (0,0,0,0,0,0,0,1);
Unit Unit::AngleOfFriction (0,0,0,0,0,0,0,1);
Unit Unit::Density(-3,1);
Unit Unit::TimeSpan(0,0,1);
Unit Unit::Frequency(0,0,-1);
Unit Unit::Velocity(1,0,-1);
Unit Unit::Acceleration(1,0,-2);
Unit Unit::Temperature(0,0,0,0,1);
Unit Unit::CurrentDensity(-2,0,0,1);
Unit Unit::ElectricCurrent(0,0,0,1);
Unit Unit::ElectricPotential(2,1,-3,-1);
Unit Unit::ElectricCharge(0,0,1,1);
Unit Unit::MagneticFieldStrength(-1,0,0,1);
Unit Unit::MagneticFlux(2,1,-2,-1);
Unit Unit::MagneticFluxDensity(0,1,-2,-1);
Unit Unit::Magnetization(-1,0,0,1);
Unit Unit::ElectricalCapacitance(-2,-1,4,2);
Unit Unit::ElectricalInductance(2,1,-2,-2);
Unit Unit::ElectricalConductance(-2,-1,3,2);
Unit Unit::ElectricalResistance(2,1,-3,-2);
Unit Unit::ElectricalConductivity(-3,-1,3,2);
Unit Unit::AmountOfSubstance(0,0,0,0,0,1);
Unit Unit::LuminousIntensity(0,0,0,0,0,0,1);
// Pressure, kg/m*s^2 or N/m^2 or PSI or MPa
Unit Unit::CompressiveStrength (-1,1,-2);
Unit Unit::Pressure (-1,1,-2);
Unit Unit::ShearModulus (-1,1,-2);
Unit Unit::Stress (-1,1,-2);
Unit Unit::UltimateTensileStrength (-1,1,-2);
Unit Unit::YieldStrength (-1,1,-2);
Unit Unit::YoungsModulus (-1,1,-2);
// Stiffness [kg/s^-2]
Unit Unit::Stiffness (0,1,-2);
Unit Unit::Force (1,1,-2);
Unit Unit::Work (2,1,-2);
Unit Unit::Power (2,1,-3);
Unit Unit::SpecificEnergy (2,0,-2);
Unit Unit::ThermalConductivity (1,1,-3,0,-1);
Unit Unit::ThermalExpansionCoefficient (0,0,0,0,-1);
Unit Unit::VolumetricThermalExpansionCoefficient (0,0,0,0,-1);
Unit Unit::SpecificHeat (2,0,-2,0,-1);
Unit Unit::ThermalTransferCoefficient (0,1,-3,0,-1);
Unit Unit::HeatFlux (0,1,-3,0,0);
Unit Unit::DynamicViscosity (-1,1,-1); // SI unit: kg/m/s
Unit Unit::KinematicViscosity (2,0,-1); // SI unit: m^2/s, https://en.wikipedia.org/wiki/Viscosity#Kinematic_viscosity
Unit Unit::VacuumPermittivity (-3,-1,4,2); // SI unit: A²*s⁴/kg/m³ https://en.wikipedia.org/wiki/Permittivity#Vacuum_permittivity
Unit Unit::VolumeFlowRate (3,0,-1);
Unit Unit::DissipationRate (2,0,-3); // SI unit: m^2/s^3 https://cfd-online.com/Wiki/Turbulence_dissipation_rate
Unit Unit::InverseLength (-1,0,0);
Unit Unit::InverseArea (-2,0,0);
Unit Unit::InverseVolume (-3,0,0);
// all other units
Unit Unit::Acceleration (1, 0, -2);
Unit Unit::Angle (0, 0, 0, 0, 0, 0, 0, 1);
Unit Unit::AngleOfFriction (0, 0, 0, 0, 0, 0, 0, 1);
Unit Unit::Area (2);
Unit Unit::CompressiveStrength (-1, 1, -2);
Unit Unit::CurrentDensity (-2, 0, 0, 1);
Unit Unit::Density (-3, 1);
Unit Unit::DissipationRate (2, 0, -3); // https://cfd-online.com/Wiki/Turbulence_dissipation_rate
Unit Unit::DynamicViscosity (-1, 1, -1);
Unit Unit::ElectricalCapacitance (-2, -1, 4, 2);
Unit Unit::ElectricalConductance (-2, -1, 3, 2);
Unit Unit::ElectricalConductivity (-3, -1, 3, 2);
Unit Unit::ElectricalInductance (2, 1, -2, -2);
Unit Unit::ElectricalResistance (2, 1, -3, -2);
Unit Unit::ElectricCharge (0, 0, 1, 1);
Unit Unit::ElectricPotential (2, 1, -3, -1);
Unit Unit::Force (1, 1, -2);
Unit Unit::Frequency (0, 0, -1);
Unit Unit::HeatFlux (0, 1, -3, 0, 0);
Unit Unit::InverseArea (-2, 0, 0);
Unit Unit::InverseLength (-1, 0, 0);
Unit Unit::InverseVolume (-3, 0, 0);
Unit Unit::KinematicViscosity (2, 0, -1);
Unit Unit::MagneticFieldStrength (-1,0,0,1);
Unit Unit::MagneticFlux (2,1,-2,-1);
Unit Unit::MagneticFluxDensity (0,1,-2,-1);
Unit Unit::Magnetization (-1,0,0,1);
Unit Unit::Pressure (-1,1,-2);
Unit Unit::Power (2, 1, -3);
Unit Unit::ShearModulus (-1,1,-2);
Unit Unit::SpecificEnergy (2, 0, -2);
Unit Unit::SpecificHeat (2, 0, -2, 0, -1);
Unit Unit::Stiffness (0, 1, -2);
Unit Unit::Stress (-1,1,-2);
Unit Unit::ThermalConductivity (1, 1, -3, 0, -1);
Unit Unit::ThermalExpansionCoefficient(0, 0, 0, 0, -1);
Unit Unit::ThermalTransferCoefficient (0, 1, -3, 0, -1);
Unit Unit::UltimateTensileStrength (-1,1,-2);
Unit Unit::VacuumPermittivity (-3, -1, 4, 2);
Unit Unit::Velocity (1, 0, -1);
Unit Unit::Volume (3);
Unit Unit::VolumeFlowRate (3, 0, -1);
Unit Unit::VolumetricThermalExpansionCoefficient(0, 0, 0, 0, -1);
Unit Unit::Work (2, 1, -2);
Unit Unit::YieldStrength (-1,1,-2);
Unit Unit::YoungsModulus (-1,1,-2);

View File

@@ -49,34 +49,34 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
// = 10e6 * kg*mm/s^3/K
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 0.000000001) {// smaller than 0.001 nm -> scientific notation
if (unit == Unit::Length) {// Length handling ============================
if (UnitValue < 1e-6) {// smaller than 0.001 nm -> scientific notation
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if(UnitValue < 0.001) {
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("nm");
factor = 1e-6;
}
else if (UnitValue < 0.1) {
unitString = QString::fromUtf8("\xC2\xB5m");
factor = 0.001;
factor = 1e-3;
}
else if (UnitValue < 10000.0) {
else if (UnitValue < 1e4) {
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if (UnitValue < 10000000.0) {
else if (UnitValue < 1e7) {
unitString = QString::fromLatin1("m");
factor = 1000.0;
factor = 1e3;
}
else if (UnitValue < 100000000000.0) {
else if (UnitValue < 1e10) {
unitString = QString::fromLatin1("km");
factor = 1e6;
}
else { // bigger than 1000 km -> scientific notation
unitString = QString::fromLatin1("mm");
factor = 1.0;
else {// bigger than 1000 km -> scientific notation
unitString = QString::fromLatin1("m");
factor = 1e3;
}
}
else if (unit == Unit::Area) {
@@ -419,7 +419,8 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
factor = 1e-15;
}
else if (UnitValue < 1e-9) {
unitString = QString::fromUtf8("\xC2\xB5""F"); // \x reads everything to the end, therefore split
// \x reads everything to the end, therefore split
unitString = QString::fromUtf8("\xC2\xB5""F");
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
@@ -516,77 +517,73 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
factor = 1e6;
}
else if (unit == Unit::InverseLength) {
if (UnitValue < 1e-6) { // smaller than 0.001 1/km -> scientific notation
unitString = QString::fromLatin1("1/mm");
factor = 1;
if (UnitValue < 1e-6) {// smaller than 0.001 1/km -> scientific notation
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/km");
factor = 1e-6;
}
else if (UnitValue < 1) {
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("1/mm");
factor = 1;
factor = 1.0;
}
else if(UnitValue < 1e6) {
unitString = QString::fromUtf8("\xC2\xB5m");
else if (UnitValue < 1e6) {
unitString = QString::fromUtf8("1/\xC2\xB5m");
factor = 1e3;
}
else if(UnitValue < 1e9) {
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("1/nm");
factor = 1e6;
}
else { // bigger than 1000 1/nm -> scientific notation
unitString = QString::fromLatin1("1/mm");
factor = 1;
else {// larger -> scientific notation
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
}
else if (unit == Unit::InverseArea) {
if (UnitValue < 1e-15) { // smaller than 0.001 1/km^2 -> scientific notation
unitString = QString::fromLatin1("1/mm^2");
factor = 1;
}
else if (UnitValue < 1e-9) {
unitString = QString::fromLatin1("1/km^2");
factor = 1e-12;
}
else if (UnitValue < 1e-3) {
if (UnitValue < 1e-12) {// smaller than 0.001 1/km^2 -> scientific notation
unitString = QString::fromLatin1("1/m^2");
factor = 1e-6;
}
else if (UnitValue < 1e-1) {
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/km^2");
factor = 1e-12;
}
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m^2");
factor = 1e-6;
}
else if (UnitValue < 1e2) {
unitString = QString::fromLatin1("1/cm^2");
factor = 1e-2;
}
else {
unitString = QString::fromLatin1("1/mm^2");
factor = 1;
factor = 1.0;
}
}
else if (unit == Unit::InverseVolume) {
if (UnitValue < 1e-9) { // smaller than 0.001 1/m^3 -> scientific notation
unitString = QString::fromLatin1("1/mm^3");
factor = 1;
}
else if (UnitValue < 1e-6) {
if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/m^3");
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/l^3");
unitString = QString::fromLatin1("1/l");
factor = 1e-6;
}
else if (UnitValue < 1) {
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/ml");
factor = 1e-3;
}
else {
unitString = QString::fromLatin1("1/mm^3");
factor = 1;
factor = 1.0;
}
}
else {

View File

@@ -41,34 +41,34 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
Unit unit = quant.getUnit();
// now do special treatment on all cases seems necessary:
if (unit == Unit::Length) { // Length handling ============================
if (UnitValue < 0.000000001) {// smaller then 0.001 nm -> scientific notation
unitString = QString::fromLatin1("m");
factor = 1000.0;
}
else if(UnitValue < 0.001) {
unitString = QString::fromLatin1("nm");
factor = 0.000001;
}
else if(UnitValue < 0.1) {
unitString = QString::fromUtf8("\xC2\xB5m");
factor = 0.001;
}
else if(UnitValue < 100.0) {
if (unit == Unit::Length) {// Length handling ============================
if (UnitValue < 1e-6) {// smaller than 0.001 nm -> scientific notation
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if(UnitValue < 10000000.0) {
unitString = QString::fromLatin1("m");
factor = 1000.0;
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("nm");
factor = 1e-6;
}
else if(UnitValue < 100000000000.0 ) {
else if (UnitValue < 0.1) {
unitString = QString::fromUtf8("\xC2\xB5m");
factor = 1e-3;
}
else if (UnitValue < 1e4) {
unitString = QString::fromLatin1("mm");
factor = 1.0;
}
else if (UnitValue < 1e7) {
unitString = QString::fromLatin1("m");
factor = 1e3;
}
else if (UnitValue < 1e10) {
unitString = QString::fromLatin1("km");
factor = 1000000.0;
factor = 1e6;
}
else { // bigger then 1000 km -> scientific notation
else {// bigger than 1000 km -> scientific notation
unitString = QString::fromLatin1("m");
factor = 1000.0;
factor = 1e3;
}
}
else if (unit == Unit::Area) {
@@ -367,7 +367,8 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
factor = 1e-15;
}
else if (UnitValue < 1e-9) {
unitString = QString::fromUtf8("\xC2\xB5""F"); // \x reads everything to the end, therefore split
// \x reads everything to the end, therefore split
unitString = QString::fromUtf8("\xC2\xB5""F");
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
@@ -504,7 +505,7 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
factor = 1e6;
}
else if (unit == Unit::InverseLength) {
if (UnitValue < 1e-6) { // smaller than 0.001 1/km -> scientific notation
if (UnitValue < 1e-6) {// smaller than 0.001 1/km -> scientific notation
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
@@ -512,51 +513,47 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
unitString = QString::fromLatin1("1/km");
factor = 1e-6;
}
else if (UnitValue < 1) {
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromLatin1("1/mm");
factor = 1;
factor = 1.0;
}
else if(UnitValue < 1e6) {
unitString = QString::fromUtf8("\xC2\xB5m");
else if (UnitValue < 1e6) {
unitString = QString::fromUtf8("1/\xC2\xB5m");
factor = 1e3;
}
else if(UnitValue < 1e9) {
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("1/nm");
factor = 1e6;
}
else { // bigger than 1000 1/nm -> scientific notation
else {// larger -> scientific notation
unitString = QString::fromLatin1("1/m");
factor = 1e-3;
}
}
else if (unit == Unit::InverseArea) {
if (UnitValue < 1e-15) { // smaller than 0.001 1/km^2 -> scientific notation
if (UnitValue < 1e-12) {// smaller than 0.001 1/km^2 -> scientific notation
unitString = QString::fromLatin1("1/m^2");
factor = 1e-6;
}
else if (UnitValue < 1e-9) {
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("1/km^2");
factor = 1e-12;
}
else if (UnitValue < 1e-3) {
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/m^2");
factor = 1e-6;
}
else if (UnitValue < 1e-1) {
else if (UnitValue < 1e2) {
unitString = QString::fromLatin1("1/cm^2");
factor = 1e-2;
}
else if (UnitValue < 1e3) {
else {
unitString = QString::fromLatin1("1/mm^2");
factor = 1;
}
else { // bigger than 1000 1/mm^2 -> scientific notation
unitString = QString::fromLatin1("1/m^2");
factor = 1e-6;
factor = 1.0;
}
}
else if (unit == Unit::InverseVolume) {
@@ -565,20 +562,16 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
factor = 1e-9;
}
else if (UnitValue < 1e-3) {
unitString = QString::fromLatin1("1/l^3");
unitString = QString::fromLatin1("1/l");
factor = 1e-6;
}
else if (UnitValue < 1) {
else if (UnitValue < 1.0) {
unitString = QString::fromLatin1("1/ml");
factor = 1e-3;
}
else if (UnitValue < 1e3) {
else {
unitString = QString::fromLatin1("1/mm^3");
factor = 1;
}
else { // bigger than 1000 1/mm^3 -> scientific notation
unitString = QString::fromLatin1("1/m^3");
factor = 1e-9;
factor = 1.0;
}
}
else {