| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/************************************************************************ |
| 4 |
* * |
| 5 |
* This file is part of the FreeCAD CAx development system. * |
| 6 |
* * |
| 7 |
* This library is free software; you can redistribute it and/or * |
| 8 |
* modify it under the terms of the GNU Library General Public * |
| 9 |
* License as published by the Free Software Foundation; either * |
| 10 |
* version 2 of the License, or (at your option) any later version. * |
| 11 |
* * |
| 12 |
* This library is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 19 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 20 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 21 |
* * |
| 22 |
************************************************************************/ |
| 23 |
|
| 24 |
#ifndef BASE_UNITSSCHEMASDATA_H |
| 25 |
#define BASE_UNITSSCHEMASDATA_H |
| 26 |
|
| 27 |
#include <map> |
| 28 |
#include <vector> |
| 29 |
|
| 30 |
#include <QtGlobal> |
| 31 |
|
| 32 |
#include "fmt/format.h" |
| 33 |
#include "fmt/ranges.h" |
| 34 |
|
| 35 |
#include "UnitsConvData.h" |
| 36 |
#include "UnitsSchemasSpecs.h" |
| 37 |
|
| 38 |
/** |
| 39 |
* UnitSchemas raw data |
| 40 |
*/ |
| 41 |
|
| 42 |
namespace Base::UnitsSchemasData |
| 43 |
{ |
| 44 |
|
| 45 |
constexpr std::size_t defDecimals {2}; |
| 46 |
constexpr std::size_t defDenominator {8}; |
| 47 |
|
| 48 |
using namespace Base::UnitsConvData; |
| 49 |
|
| 50 |
// NOLINTBEGIN |
| 51 |
// clang-format off |
| 52 |
inline const UnitsSchemaSpec s0 |
| 53 |
{ 6, "MmMin", "mm" , false, false , QT_TRANSLATE_NOOP("UnitsApi", "Metric small parts & CNC (mm, mm/min)"), false, |
| 54 |
{ |
| 55 |
{ "Length", {{ 0 , "mm" , 1.0 }}}, |
| 56 |
{ "Angle", {{ 0 , "°" , 1.0 }}}, |
| 57 |
{ "Velocity", {{ 0 , "mm/min" , 1.0 / 60.0 }}} |
| 58 |
} |
| 59 |
}; |
| 60 |
|
| 61 |
inline const UnitsSchemaSpec s1 |
| 62 |
{ 9, "MeterDecimal", "m", false, false, QT_TRANSLATE_NOOP("UnitsApi", "Meter decimal (m, m², m³)"), false, |
| 63 |
{ |
| 64 |
{ "Length", {{ 0 , "m" , 1e3 }}}, |
| 65 |
{ "Area", {{ 0 , "m^2" , 1e6 }}}, |
| 66 |
{ "Volume", {{ 0 , "m^3" , 1e9 }}}, |
| 67 |
{ "Power", {{ 0 , "W" , 1e6 }}}, |
| 68 |
{ "ElectricPotential", {{ 0 , "V" , 1e6 }}}, |
| 69 |
{ "HeatFlux", {{ 0 , "W/m^2", 1.0 }}}, |
| 70 |
{ "Velocity", {{ 0 , "m/s" , 1e3 }}} |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
inline const UnitsSchemaSpec s2 |
| 75 |
{ 3, "ImperialDecimal", "in", false, false, QT_TRANSLATE_NOOP("UnitsApi", "Imperial decimal (in, lb)"), false, |
| 76 |
{ |
| 77 |
{ "Length", {{ 0 , "in" , in }}}, |
| 78 |
{ "Angle", {{ 0 , "°" , 1.0 }}}, |
| 79 |
{ "Area", {{ 0 , "in^2" , in * in }}}, |
| 80 |
{ "Volume", {{ 0 , "in^3" , in * in * in }}}, |
| 81 |
{ "Mass", {{ 0 , "lb" , lb }}}, |
| 82 |
{ "Pressure", {{ 0 , "psi" , psi }}}, |
| 83 |
{ "Stiffness", {{ 0 , "lbf/in" , lbf / in * 1000 }}}, |
| 84 |
{ "Velocity", {{ 0 , "in/min" , in / 60 }}}, |
| 85 |
{ "Acceleration", {{ 0 , "in/min^2", in / 3600 }}} |
| 86 |
} |
| 87 |
}; |
| 88 |
|
| 89 |
inline const UnitsSchemaSpec s3 |
| 90 |
{ 0, "Internal", "mm", false, false, QT_TRANSLATE_NOOP("UnitsApi", "Standard (mm, kg, s, °)"), true, |
| 91 |
{ |
| 92 |
{ "Length", { |
| 93 |
{ 1e-6 , "mm" , 1.0 }, |
| 94 |
{ 1e-3 , "nm" , 1e-6 }, |
| 95 |
{ 1e-1 , "\xC2\xB5m" , 1e-3 }, |
| 96 |
{ 1e4 , "mm" , 1.0 }, |
| 97 |
{ 1e7 , "m" , 1e3 }, |
| 98 |
{ 1e10 , "km" , 1e6 }, |
| 99 |
{ 0 , "m" , 1e3 }} |
| 100 |
}, |
| 101 |
{ "Area", { |
| 102 |
{ 1e2 , "mm^2" , 1.0 }, |
| 103 |
{ 1e6 , "cm^2" , 1e2 }, |
| 104 |
{ 1e12 , "m^2" , 1e6 }, |
| 105 |
{ 0 , "km^2" , 1e12 }} |
| 106 |
}, |
| 107 |
{ "Volume", { |
| 108 |
{ 1e3 , "mm^3" , 1.0 }, |
| 109 |
{ 1e6 , "ml" , 1e3 }, |
| 110 |
{ 1e9 , "l" , 1e6 }, |
| 111 |
{ 0 , "m^3" , 1e9 }} |
| 112 |
}, |
| 113 |
{ "Angle", { |
| 114 |
{ 0 , "°" , 1.0 }} |
| 115 |
}, |
| 116 |
{ "Mass", { |
| 117 |
{ 1e-6 , "\xC2\xB5g" , 1e-9 }, |
| 118 |
{ 1e-3 , "mg" , 1e-6 }, |
| 119 |
{ 1.0 , "g" , 1e-3 }, |
| 120 |
{ 1e3 , "kg" , 1.0 }, |
| 121 |
{ 0 , "t" , 1e3 }} |
| 122 |
}, |
| 123 |
{ "Density", { |
| 124 |
{ 1e-4 , "kg/m^3" , 1e-9 }, |
| 125 |
{ 1.0 , "kg/cm^3" , 1e-3 }, |
| 126 |
{ 0 , "kg/mm^3" , 1.0 }} |
| 127 |
}, |
| 128 |
{ "ThermalConductivity", { |
| 129 |
{ 1e6 , "W/m/K" , 1e3 }, |
| 130 |
{ 0 , "W/mm/K" , 1e6 }} |
| 131 |
}, |
| 132 |
{ "ThermalExpansionCoefficient", { |
| 133 |
{ 1e-3 , "\xC2\xB5m/m/K" , 1e-6 }, |
| 134 |
{ 0 , "mm/mm/K" , 1.0 }} |
| 135 |
}, |
| 136 |
{ "VolumetricThermalExpansionCoefficient", { |
| 137 |
{ 1e-3 , "mm^3/m^3/K" , 1e-9 }, |
| 138 |
{ 0 , "m^3/m^3/K" , 1.0 }} |
| 139 |
}, |
| 140 |
{ "SpecificHeat", { |
| 141 |
{ 0 , "J/kg/K" , 1e6 }} |
| 142 |
}, |
| 143 |
{ "ThermalTransferCoefficient", { |
| 144 |
{ 0 , "W/m^2/K" , 1.0 }} |
| 145 |
}, |
| 146 |
{ "Pressure", { |
| 147 |
{ 10.0 , "Pa" , 1e-3 }, |
| 148 |
{ 1e4 , "kPa" , 1.0 }, |
| 149 |
{ 1e7 , "MPa" , 1e3 }, |
| 150 |
{ 1e10 , "GPa" , 1e6 }, |
| 151 |
{ 0 , "Pa" , 1e-3 }} |
| 152 |
}, |
| 153 |
{ "Stress", { |
| 154 |
{ 10.0 , "Pa" , 1e-3 }, |
| 155 |
{ 1e4 , "kPa" , 1.0 }, |
| 156 |
{ 1e7 , "MPa" , 1e3 }, |
| 157 |
{ 1e10 , "GPa" , 1e6 }, |
| 158 |
{ 0 , "Pa" , 1e-3 }} |
| 159 |
}, |
| 160 |
{ "Stiffness", { |
| 161 |
{ 1 , "mN/m" , 1e-3 }, |
| 162 |
{ 1e3 , "N/m" , 1.0 }, |
| 163 |
{ 1e6 , "kN/m" , 1e3 }, |
| 164 |
{ 0 , "MN/m" , 1e6 }} |
| 165 |
}, |
| 166 |
{ "StiffnessDensity", { |
| 167 |
{ 1e-3 , "Pa/m" , 1e-6 }, |
| 168 |
{ 1 , "kPa/m" , 1e-3 }, |
| 169 |
{ 1e3 , "MPa/m" , 1.0 }, |
| 170 |
{ 0 , "GPa/m" , 1e3 }} |
| 171 |
}, |
| 172 |
{ "Force", { |
| 173 |
{ 1e3 , "mN" , 1.0 }, |
| 174 |
{ 1e6 , "N" , 1e3 }, |
| 175 |
{ 1e9 , "kN" , 1e6 }, |
| 176 |
{ 0 , "MN" , 1e9 }} |
| 177 |
}, |
| 178 |
{ "Power", { |
| 179 |
{ 1e6 , "mW" , 1e3 }, |
| 180 |
{ 1e9 , "W" , 1e6 }, |
| 181 |
{ 0 , "kW" , 1e9 }} |
| 182 |
}, |
| 183 |
{ "ElectricPotential", { |
| 184 |
{ 1e6 , "mV" , 1e3 }, |
| 185 |
{ 1e9 , "V" , 1e6 }, |
| 186 |
{ 1e12 , "kV" , 1e9 }, |
| 187 |
{ 0 , "V" , 1e6 }} |
| 188 |
}, |
| 189 |
{ "Work", { |
| 190 |
{ 1.602176634e-10 , "eV" , 1.602176634e-13 }, |
| 191 |
{ 1.602176634e-7 , "keV" , 1.602176634e-10 }, |
| 192 |
{ 1.602176634e-4 , "MeV" , 1.602176634e-7 }, |
| 193 |
{ 1e6 , "mJ" , 1e3 }, |
| 194 |
{ 1e9 , "J" , 1e6 }, |
| 195 |
{ 1e12 , "kJ" , 1e9 }, |
| 196 |
{ 3.6e+15 , "kWh" , 3.6e+12 }, |
| 197 |
{ 0 , "J" , 1e6 }} |
| 198 |
}, |
| 199 |
{ "Moment", { |
| 200 |
{ 0 , "Nm" , 1e6 }} |
| 201 |
}, |
| 202 |
{ "SpecificEnergy", { |
| 203 |
{ 0 , "m^2/s^2" , 1e6 }} |
| 204 |
}, |
| 205 |
{ "HeatFlux", { |
| 206 |
{ 0 , "W/m^2" , 1.0 }} |
| 207 |
}, |
| 208 |
{ "ElectricCharge", { |
| 209 |
{ 0 , "C" , 1.0 }} |
| 210 |
}, |
| 211 |
{ "SurfaceChargeDensity", { |
| 212 |
{ 1e-2 , "C/m^2" , 1e-6 }, |
| 213 |
{ 1.0 , "C/cm^2" , 1e-2 }, |
| 214 |
{ 0 , "C/mm^2" , 1.0 }} |
| 215 |
}, |
| 216 |
{ "VolumeChargeDensity", { |
| 217 |
{ 1e-3 , "C/m^3" , 1e-9 }, |
| 218 |
{ 1.0 , "C/cm^3" , 1e-3 }, |
| 219 |
{ 0 , "C/mm^3" , 1.0 }} |
| 220 |
}, |
| 221 |
{ "CurrentDensity", { |
| 222 |
{ 1e-2 , "A/m^2" , 1e-6 }, |
| 223 |
{ 1.0 , "A/cm^2" , 1e-2 }, |
| 224 |
{ 0 , "A/mm^2" , 1 }} |
| 225 |
}, |
| 226 |
{ "MagneticFluxDensity", { |
| 227 |
{ 1e-3 , "G" , 1e-4 }, |
| 228 |
{ 0 , "T" , 1.0 }} |
| 229 |
}, |
| 230 |
{ "MagneticFieldStrength", { |
| 231 |
{ 0 , "A/m" , 1e-3 }} |
| 232 |
}, |
| 233 |
{ "MagneticFlux", { |
| 234 |
{ 0 , "Wb" , 1e6 }} |
| 235 |
}, |
| 236 |
{ "Magnetization", { |
| 237 |
{ 0 , "A/m" , 1e-3 }} |
| 238 |
}, |
| 239 |
{ "ElectromagneticPotential", { |
| 240 |
{ 0 , "Wb/m" , 1e3 }} |
| 241 |
}, |
| 242 |
{ "ElectricalConductance", { |
| 243 |
{ 1e-9 , "\xC2\xB5S" , 1e-12 }, |
| 244 |
{ 1e-6 , "mS" , 1e-9 }, |
| 245 |
{ 0 , "S" , 1e-6 }} |
| 246 |
}, |
| 247 |
{ "ElectricalResistance", { |
| 248 |
{ 1e9 , "Ohm" , 1e6 }, |
| 249 |
{ 1e12 , "kOhm" , 1e9 }, |
| 250 |
{ 0 , "MOhm" , 1e12 }} |
| 251 |
}, |
| 252 |
{ "ElectricalConductivity", { |
| 253 |
{ 1e-9 , "mS/m" , 1e-12 }, |
| 254 |
{ 1e-6 , "S/m" , 1e-9 }, |
| 255 |
{ 1e-3 , "kS/m" , 1e-6 }, |
| 256 |
{ 0 , "MS/m" , 1e-3 }} |
| 257 |
}, |
| 258 |
{ "ElectricalCapacitance", { |
| 259 |
{ 1e-15 , "pF" , 1e-18 }, |
| 260 |
{ 1e-12 , "nF" , 1e-15 }, |
| 261 |
{ 1e-9 , "\xC2\xB5""F", 1e-12 }, |
| 262 |
{ 1e-6 , "mF" , 1e-9 }, |
| 263 |
{ 0 , "F" , 1e-6 }} |
| 264 |
}, |
| 265 |
{ "ElectricalInductance", { |
| 266 |
{ 1.0 , "nH" , 1e-3 }, |
| 267 |
{ 1e3 , "\xC2\xB5H" , 1.0 }, |
| 268 |
{ 1e6 , "mH" , 1e3 }, |
| 269 |
{ 0 , "H" , 1e6 }} |
| 270 |
}, |
| 271 |
{ "VacuumPermittivity", { |
| 272 |
{ 0 , "F/m" , 1e-9 }} |
| 273 |
}, |
| 274 |
{ "Frequency", { |
| 275 |
{ 1e3 , "Hz" , 1.0 }, |
| 276 |
{ 1e6 , "kHz" , 1e3 }, |
| 277 |
{ 1e9 , "MHz" , 1e6 }, |
| 278 |
{ 1e12 , "GHz" , 1e9 }, |
| 279 |
{ 0 , "THz" , 1e12 }} |
| 280 |
}, |
| 281 |
{ "Velocity", { |
| 282 |
{ 0 , "mm/s" , 1.0 }} |
| 283 |
}, |
| 284 |
{ "DynamicViscosity", { |
| 285 |
{ 0 , "Pa*s" , 1e-3 }} |
| 286 |
}, |
| 287 |
{ "KinematicViscosity", { |
| 288 |
{ 1e3 , "mm^2/s" , 1.0 }, |
| 289 |
{ 0 , "m^2/s" , 1e6 }} |
| 290 |
}, |
| 291 |
{ "VolumeFlowRate", { |
| 292 |
{ 1e3 , "mm^3/s" , 1.0 }, |
| 293 |
{ 1e6 , "ml/s" , 1e3 }, |
| 294 |
{ 1e9 , "l/s" , 1e6 }, |
| 295 |
{ 0 , "m^3/s" , 1e9 }} |
| 296 |
}, |
| 297 |
{ "DissipationRate", { |
| 298 |
{ 0 , "W/kg" , 1e6 }} |
| 299 |
}, |
| 300 |
{ "InverseLength", { |
| 301 |
{ 1e-6 , "1/m" , 1e-3 }, |
| 302 |
{ 1e-3 , "1/km" , 1e-6 }, |
| 303 |
{ 1.0 , "1/m" , 1e-3 }, |
| 304 |
{ 1e3 , "1/mm" , 1.0 }, |
| 305 |
{ 1e6 , "1/\xC2\xB5m", 1e3 }, |
| 306 |
{ 1e9 , "1/nm" , 1e6 }, |
| 307 |
{ 0 , "1/m" , 1e-3 }} |
| 308 |
}, |
| 309 |
{ "InverseArea", { |
| 310 |
{ 1e-12 , "1/m^2" , 1e-6 }, |
| 311 |
{ 1e-6 , "1/km^2" , 1e-12 }, |
| 312 |
{ 1.0 , "1/m^2" , 1e-6 }, |
| 313 |
{ 1e2 , "1/cm^2" , 1e-2 }, |
| 314 |
{ 0 , "1/mm^2" , 1.0 }} |
| 315 |
}, |
| 316 |
{ "InverseVolume", { |
| 317 |
{ 1e-6 , "1/m^3" , 1e-9 }, |
| 318 |
{ 1e-3 , "1/l" , 1e-6 }, |
| 319 |
{ 1.0 , "1/ml" , 1e-3 }, |
| 320 |
{ 0 , "1/mm^3" , 1.0 }} |
| 321 |
} |
| 322 |
} |
| 323 |
}; |
| 324 |
|
| 325 |
inline const UnitsSchemaSpec s4 |
| 326 |
{ 1, "MKS", "m", false, false, QT_TRANSLATE_NOOP("UnitsApi", "MKS (m, kg, s, °)") , false, |
| 327 |
{ |
| 328 |
{ "Length", { |
| 329 |
{ 1e-6 , "mm" , 1.0 }, |
| 330 |
{ 1e-3 , "nm" , 1e-6 }, |
| 331 |
{ 0.1 , "\xC2\xB5m" , 1e-3 }, |
| 332 |
{ 1e4 , "mm" , 1.0 }, |
| 333 |
{ 1e7 , "m" , 1e3 }, |
| 334 |
{ 1e10 , "km" , 1e6 }, |
| 335 |
{ 0 , "m" , 1e3 }} |
| 336 |
}, |
| 337 |
{ "Area", { |
| 338 |
{ 100 , "mm^2" , 1.0 }, |
| 339 |
{ 1e6 , "cm^2" , 100 }, |
| 340 |
{ 1e12 , "m^2" , 1e6 }, |
| 341 |
{ 0 , "km^2" , 1e12 }} |
| 342 |
}, |
| 343 |
{ "Volume", { |
| 344 |
{ 1e3 , "mm^3" , 1.0 }, |
| 345 |
{ 1e6 , "ml" , 1e3 }, |
| 346 |
{ 1e9 , "l" , 1e6 }, |
| 347 |
{ 0 , "m^3" , 1e9 }} |
| 348 |
}, |
| 349 |
{ "Mass", { |
| 350 |
{ 1e-6 , "\xC2\xB5g" , 1e-9 }, |
| 351 |
{ 1e-3 , "mg" , 1e-6 }, |
| 352 |
{ 1.0 , "g" , 1e-3 }, |
| 353 |
{ 1e3 , "kg" , 1.0 }, |
| 354 |
{ 0 , "t" , 1e3 }} |
| 355 |
}, |
| 356 |
{ "Density", { |
| 357 |
{ 0.0001 , "kg/m^3" , 0.000000001 }, |
| 358 |
{ 1.0 , "kg/cm^3" , 0.001 }, |
| 359 |
{ 0 , "kg/mm^3" , 1.0 }} |
| 360 |
}, |
| 361 |
{ "Acceleration", { |
| 362 |
{ 0 , "m/s^2" , 1000.0 }} |
| 363 |
}, |
| 364 |
{ "Pressure", { |
| 365 |
{ 10.0 , "Pa" , 0.001 }, |
| 366 |
{ 10'000.0 , "kPa" , 1.0 }, |
| 367 |
{ 10'000'000.0 , "MPa" , 1'000.0 }, |
| 368 |
{ 10'000'000'000.0 , "GPa" , 1'000'000.0 }, |
| 369 |
{ 0 , "Pa" , 0.001 }} |
| 370 |
}, |
| 371 |
{ "Stress", { |
| 372 |
{ 10.0 , "Pa" , 0.001 }, |
| 373 |
{ 10'000.0 , "kPa" , 1.0 }, |
| 374 |
{ 10'000'000.0 , "MPa" , 1'000.0 }, |
| 375 |
{ 10'000'000'000.0 , "GPa" , 1'000'000.0 }, |
| 376 |
{ 0 , "Pa" , 0.001 }} |
| 377 |
}, |
| 378 |
{ "Stiffness", { |
| 379 |
{ 1 , "mN/m" , 1e-3 }, |
| 380 |
{ 1e3 , "N/m" , 1.0 }, |
| 381 |
{ 1e6 , "kN/m" , 1e3 }, |
| 382 |
{ 0 , "MN/m" , 1e6 }} |
| 383 |
}, |
| 384 |
{ "StiffnessDensity", { |
| 385 |
{ 1e-3 , "Pa/m" , 1e-6 }, |
| 386 |
{ 1 , "kPa/m" , 1e-3 }, |
| 387 |
{ 1e3 , "MPa/m" , 1.0 }, |
| 388 |
{ 0 , "GPa/m" , 1e3 }} |
| 389 |
}, |
| 390 |
{ "ThermalConductivity", { |
| 391 |
{ 1'000'000 , "W/m/K" , 1'000.0 }, |
| 392 |
{ 0 , "W/mm/K" , 1'000'000.0 }} |
| 393 |
}, |
| 394 |
{ "ThermalExpansionCoefficient", { |
| 395 |
{ 0.001 , "\xC2\xB5m/m/K" , 0.000001 }, |
| 396 |
{ 0 , "m/m/K" , 1.0 }} |
| 397 |
}, |
| 398 |
{ "VolumetricThermalExpansionCoefficient", { |
| 399 |
{ 0.001 , "mm^3/m^3/K" , 1e-9 }, |
| 400 |
{ 0 , "m^3/m^3/K" , 1.0 }} |
| 401 |
}, |
| 402 |
{ "SpecificHeat", { |
| 403 |
{ 0 , "J/kg/K" , 1'000'000.0 }} |
| 404 |
}, |
| 405 |
{ "ThermalTransferCoefficient", { |
| 406 |
{ 0 , "W/m^2/K" , 1.0 }} |
| 407 |
}, |
| 408 |
{ "Force", { |
| 409 |
{ 1e3 , "mN" , 1.0 }, |
| 410 |
{ 1e6 , "N" , 1e3 }, |
| 411 |
{ 1e9 , "kN" , 1e6 }, |
| 412 |
{ 0 , "MN" , 1e9 }} |
| 413 |
}, |
| 414 |
{ "Power", { |
| 415 |
{ 1e6 , "mW" , 1e3 }, |
| 416 |
{ 1e9 , "W" , 1e6 }, |
| 417 |
{ 0 , "kW" , 1e9 }} |
| 418 |
}, |
| 419 |
{ "ElectricPotential", { |
| 420 |
{ 1e6 , "mV" , 1e3 }, |
| 421 |
{ 1e9 , "V" , 1e6 }, |
| 422 |
{ 1e12 , "kV" , 1e9 }, |
| 423 |
{ 0 , "V" , 1e6 }} |
| 424 |
}, |
| 425 |
{ "ElectricCharge", { |
| 426 |
{ 0 , "C" , 1.0 }} |
| 427 |
}, |
| 428 |
{ "SurfaceChargeDensity", { |
| 429 |
{ 0 , "C/m^2" , 1e-6 }} |
| 430 |
}, |
| 431 |
{ "VolumeChargeDensity", { |
| 432 |
{ 0 , "C/m^3" , 1e-9 }} |
| 433 |
}, |
| 434 |
{ "CurrentDensity", { |
| 435 |
{ 1.0 , "A/m^2" , 1e-6 }, |
| 436 |
{ 0 , "A/mm^2" , 1.0 }} |
| 437 |
}, |
| 438 |
{ "MagneticFluxDensity", { |
| 439 |
{ 1e-3 , "G" , 1e-4 }, |
| 440 |
{ 0 , "T" , 1.0 }} |
| 441 |
}, |
| 442 |
{ "MagneticFieldStrength", { |
| 443 |
{ 0 , "A/m" , 1e-3 }} |
| 444 |
}, |
| 445 |
{ "MagneticFlux", { |
| 446 |
{ 0 , "Wb" , 1e6 }} |
| 447 |
}, |
| 448 |
{ "Magnetization", { |
| 449 |
{ 0 , "A/m" , 1e-3 }} |
| 450 |
}, |
| 451 |
{ "ElectromagneticPotential", { |
| 452 |
{ 0 , "Wb/m" , 1e3 }} |
| 453 |
}, |
| 454 |
{ "ElectricalConductance", { |
| 455 |
{ 1e-9 , "\xC2\xB5S" , 1e-12 }, |
| 456 |
{ 1e-6 , "mS" , 1e-9 }, |
| 457 |
{ 0 , "S" , 1e-6 }} |
| 458 |
}, |
| 459 |
{ "ElectricalResistance", { |
| 460 |
{ 1e9 , "Ohm" , 1e6 }, |
| 461 |
{ 1e12 , "kOhm" , 1e9 }, |
| 462 |
{ 0 , "MOhm" , 1e12 }} |
| 463 |
}, |
| 464 |
{ "ElectricalConductivity", { |
| 465 |
{ 1e-9 , "mS/m" , 1e-12 }, |
| 466 |
{ 1e-6 , "S/m" , 1e-9 }, |
| 467 |
{ 1e-3 , "kS/m" , 1e-6 }, |
| 468 |
{ 0 , "MS/m" , 1e-3 }} |
| 469 |
}, |
| 470 |
{ "ElectricalCapacitance", { |
| 471 |
{ 1e-15 , "pF" , 1e-18 }, |
| 472 |
{ 1e-12 , "nF" , 1e-15 }, |
| 473 |
{ 1e-9 , "\xC2\xB5""F", 1e-12 }, |
| 474 |
{ 1e-6 , "mF" , 1e-9 }, |
| 475 |
{ 0 , "F" , 1e-6 }} |
| 476 |
}, |
| 477 |
{ "ElectricalInductance", { |
| 478 |
{ 1.0 , "nH" , 1e-3 }, |
| 479 |
{ 1e3 , "\xC2\xB5H" , 1.0 }, |
| 480 |
{ 1e6 , "mH" , 1e3 }, |
| 481 |
{ 0 , "H" , 1e6 }} |
| 482 |
}, |
| 483 |
{ "VacuumPermittivity", { |
| 484 |
{ 0 , "F/m" , 1e-9 }} |
| 485 |
}, |
| 486 |
{ "Work", { |
| 487 |
{ 1.602176634e-10 , "eV" , 1.602176634e-13 }, |
| 488 |
{ 1.602176634e-7 , "keV" , 1.602176634e-10 }, |
| 489 |
{ 1.602176634e-4 , "MeV" , 1.602176634e-7 }, |
| 490 |
{ 1e6 , "mJ" , 1e3 }, |
| 491 |
{ 1e9 , "J" , 1e6 }, |
| 492 |
{ 1e12 , "kJ" , 1e9 }, |
| 493 |
{ 3.6e+15 , "kWh" , 3.6e+12 }, |
| 494 |
{ 0 , "J" , 1e6 }} |
| 495 |
}, |
| 496 |
{ "SpecificEnergy", { |
| 497 |
{ 0 , "m^2/s^2" , 1000000 }} |
| 498 |
}, |
| 499 |
{ "HeatFlux", { |
| 500 |
{ 0 , "W/m^2" , 1.0 }} |
| 501 |
}, |
| 502 |
{ "Frequency", { |
| 503 |
{ 1e3 , "Hz" , 1.0 }, |
| 504 |
{ 1e6 , "kHz" , 1e3 }, |
| 505 |
{ 1e9 , "MHz" , 1e6 }, |
| 506 |
{ 1e12 , "GHz" , 1e9 }, |
| 507 |
{ 0 , "THz" , 1e12 }} |
| 508 |
}, |
| 509 |
{ "Velocity", { |
| 510 |
{ 0 , "m/s" , 1000.0 }} |
| 511 |
}, |
| 512 |
{ "DynamicViscosity", { |
| 513 |
{ 0 , "Pa*s" , 0.001 }} |
| 514 |
}, |
| 515 |
{ "KinematicViscosity", { |
| 516 |
{ 0 , "m^2/s" , 1e6 }} |
| 517 |
}, |
| 518 |
{ "VolumeFlowRate", { |
| 519 |
{ 1e-3 , "m^3/s" , 1e9 }, |
| 520 |
{ 1e3 , "mm^3/s" , 1.0 }, |
| 521 |
{ 1e6 , "ml/s" , 1e3 }, |
| 522 |
{ 1e9 , "l/s" , 1e6 }, |
| 523 |
{ 0 , "m^3/s" , 1e9 }} |
| 524 |
}, |
| 525 |
{ "DissipationRate", { |
| 526 |
{ 0 , "W/kg" , 1e6 }} |
| 527 |
}, |
| 528 |
{ "InverseLength", { |
| 529 |
{ 1e-6 , "1/m" , 1e-3 }, |
| 530 |
{ 1e-3 , "1/km" , 1e-6 }, |
| 531 |
{ 1.0 , "1/m" , 1e-3 }, |
| 532 |
{ 1e3 , "1/mm" , 1.0 }, |
| 533 |
{ 1e6 , "1/\xC2\xB5m", 1e3 }, |
| 534 |
{ 1e9 , "1/nm" , 1e6 }, |
| 535 |
{ 0 , "1/m" , 1e-3 }} |
| 536 |
}, |
| 537 |
{ "InverseArea", { |
| 538 |
{ 1e-12 , "1/m^2" , 1e-6 }, |
| 539 |
{ 1e-6 , "1/km^2" , 1e-12 }, |
| 540 |
{ 1.0 , "1/m^2" , 1e-6 }, |
| 541 |
{ 1e2 , "1/cm^2" , 1e-2 }, |
| 542 |
{ 0 , "1/mm^2" , 1.0 }} |
| 543 |
}, |
| 544 |
{ "InverseVolume", { |
| 545 |
{ 1e-6 , "1/m^3" , 1e-9 }, |
| 546 |
{ 1e-3 , "1/l" , 1e-6 }, |
| 547 |
{ 1.0 , "1/ml" , 1e-3 }, |
| 548 |
{ 0 , "1/mm^3" , 1.0 }} |
| 549 |
} |
| 550 |
} |
| 551 |
}; |
| 552 |
|
| 553 |
inline const UnitsSchemaSpec s5 |
| 554 |
{ 4, "Centimeter", "cm", false, false, QT_TRANSLATE_NOOP("UnitsApi", "Building Euro (cm, m², m³)") , false, |
| 555 |
{ |
| 556 |
{ "Length", { |
| 557 |
{ 0 , "cm" , 10.0 }} |
| 558 |
}, |
| 559 |
{ "Area", { |
| 560 |
{ 0 , "m^2" , 1e6 }} |
| 561 |
}, |
| 562 |
{ "Volume", { |
| 563 |
{ 0 , "m^3" , 1e9 }} |
| 564 |
}, |
| 565 |
{ "Power", { |
| 566 |
{ 0 , "W" , 1e6 }} |
| 567 |
}, |
| 568 |
{ "ElectricPotential", { |
| 569 |
{ 0 , "V" , 1e6 }} |
| 570 |
}, |
| 571 |
{ "HeatFlux", { |
| 572 |
{ 0 , "W/m^2" , 1.0 }} |
| 573 |
}, |
| 574 |
{ "Velocity", { |
| 575 |
{ 0 , "mm/min" , 1.0 / 60 }} |
| 576 |
} |
| 577 |
} |
| 578 |
}; |
| 579 |
|
| 580 |
inline const UnitsSchemaSpec s6 |
| 581 |
{ 8, "FEM", "mm", false , false , QT_TRANSLATE_NOOP("UnitsApi", "FEM (mm, N, s)"), false, |
| 582 |
{ |
| 583 |
{ "Length", { |
| 584 |
{ 0 , "mm" , 1.0 }} |
| 585 |
}, |
| 586 |
{ "Mass", { |
| 587 |
{ 0 , "t" , 1e3 }} |
| 588 |
} |
| 589 |
} |
| 590 |
}; |
| 591 |
|
| 592 |
inline const UnitsSchemaSpec s7 |
| 593 |
{ 2, "Imperial", "in", false, false, QT_TRANSLATE_NOOP("UnitsApi", "US customary (in, lb)"), false, |
| 594 |
{ |
| 595 |
{ "Length", { |
| 596 |
{ 0.00000254 , "in" , in }, |
| 597 |
{ 2.54 , "thou" , in / 1000 }, |
| 598 |
{ 304.8 , "\"" , in }, |
| 599 |
{ 914.4 , "'" , ft }, |
| 600 |
{ 1'609'344.0 , "yd" , yd }, |
| 601 |
{ 1'609'344'000.0 , "mi" , mi }, |
| 602 |
{ 0 , "in" , in }} |
| 603 |
}, |
| 604 |
{ "Angle", { |
| 605 |
{ 0 , "°" , 1.0 }} |
| 606 |
}, |
| 607 |
{ "Area", { |
| 608 |
{ 0 , "in^2" , in * in }} |
| 609 |
}, |
| 610 |
{ "Volume", { |
| 611 |
{ 0 , "in^3" , in * in * in }} |
| 612 |
}, |
| 613 |
{ "Mass", { |
| 614 |
{ 0 , "lb" , lb }} |
| 615 |
}, |
| 616 |
{ "Pressure", { |
| 617 |
{ 1000 * psi , "psi" , psi }, |
| 618 |
{ 1000000 * psi , "ksi" , 1000 * psi }, |
| 619 |
{ 0 , "psi" , psi }} |
| 620 |
}, |
| 621 |
{ "Stiffness", { |
| 622 |
{ 0 , "lbf/in" , lbf / in * 1000 }} |
| 623 |
}, |
| 624 |
{ "Velocity", { |
| 625 |
{ 0 , "in/min" , in / 60 }} |
| 626 |
} |
| 627 |
} |
| 628 |
}; |
| 629 |
|
| 630 |
inline const UnitsSchemaSpec s8 |
| 631 |
{ 5, "ImperialBuilding", "ft", true, false , QT_TRANSLATE_NOOP("UnitsApi", "Building US (ft-in, sqft, cft)"), false, |
| 632 |
{ |
| 633 |
{ "Length" , {{ 0 , "toFractional" , 0 }}}, // <== ! |
| 634 |
{ "Angle" , {{ 0 , "°" , 1.0 }}}, |
| 635 |
{ "Area" , {{ 0 , "sqft" , ft * ft }}}, |
| 636 |
{ "Volume" , {{ 0 , "cft" , ft * ft * ft }}}, |
| 637 |
{ "Velocity" , {{ 0 , "in/min" , in / 60 }}} |
| 638 |
} |
| 639 |
}; |
| 640 |
|
| 641 |
inline const UnitsSchemaSpec s9 |
| 642 |
{ 7, "ImperialCivil", "ft", false, true, QT_TRANSLATE_NOOP("UnitsApi", "Imperial for Civil Eng (ft, lb, mph)"), false, |
| 643 |
{ |
| 644 |
{ "Length" , {{ 0 , "ft" , ft }}}, |
| 645 |
{ "Area" , {{ 0 , "ft^2" , ft * ft }}}, |
| 646 |
{ "Volume" , {{ 0 , "ft^3" , ft * ft * ft }}}, |
| 647 |
{ "Mass" , {{ 0 , "lb" , lb }}}, |
| 648 |
{ "Pressure" , {{ 0 , "psi" , psi }}}, |
| 649 |
{ "Stiffness", {{ 0 , "lbf/in", lbf / in * 1000 }}}, |
| 650 |
{ "Velocity" , {{ 0 , "mph" , mi / 3600 }}}, |
| 651 |
{ "Angle" , {{ 0 , "toDMS" , 0 }}} // <== ! |
| 652 |
} |
| 653 |
}; |
| 654 |
|
| 655 |
// clang-format on |
| 656 |
// NOLINTEND |
| 657 |
inline const std::vector schemaSpecs {s3, s4, s5, s6, s7, s8, s9, s0, s1, s2}; |
| 658 |
|
| 659 |
/** |
| 660 |
* Special functions |
| 661 |
* |
| 662 |
* A schema unit can have custom formatting via a special function |
| 663 |
* Such functions must be included here and also registered in special functions caller (below) |
| 664 |
*/ |
| 665 |
|
| 666 |
/** utility function for toFractional */ |
| 667 |
inline std::size_t greatestCommonDenominator(const std::size_t a, const std::size_t b) |
| 668 |
{ |
| 669 |
return b == 0 ? a : greatestCommonDenominator(b, a % b); // Euclid's algorithm |
| 670 |
} |
| 671 |
|
| 672 |
/** |
| 673 |
* double -> [feet'] [inches" [+ fraction]"], e.g.: 3' 4" + 3/8" |
| 674 |
*/ |
| 675 |
inline std::string toFractional(const double value, std::size_t denominator) |
| 676 |
{ |
| 677 |
constexpr auto inchPerFoot {12}; |
| 678 |
constexpr auto mmPerInch {25.4}; |
| 679 |
|
| 680 |
auto numFractUnits = static_cast<std::size_t>( |
| 681 |
std::round(std::abs(value) / mmPerInch * denominator) |
| 682 |
); |
| 683 |
if (numFractUnits == 0) { |
| 684 |
return "0"; |
| 685 |
} |
| 686 |
|
| 687 |
const auto feet = static_cast<std::size_t>(std::floor(numFractUnits / (inchPerFoot * denominator))); |
| 688 |
numFractUnits -= inchPerFoot * denominator * feet; |
| 689 |
|
| 690 |
const auto inches = static_cast<std::size_t>(std::floor(numFractUnits / denominator)); |
| 691 |
std::size_t numerator = numFractUnits - (denominator * inches); |
| 692 |
|
| 693 |
const std::size_t common_denom = greatestCommonDenominator(numerator, denominator); |
| 694 |
numerator /= common_denom; |
| 695 |
denominator /= common_denom; |
| 696 |
|
| 697 |
bool addSpace {false}; |
| 698 |
std::string result; |
| 699 |
|
| 700 |
if (value < 0) { |
| 701 |
result += "-"; |
| 702 |
} |
| 703 |
|
| 704 |
if (feet > 0) { |
| 705 |
result += fmt::format("{}'", feet); |
| 706 |
addSpace = true; |
| 707 |
} |
| 708 |
|
| 709 |
if (inches > 0) { |
| 710 |
result += fmt::format("{}{}\"", addSpace ? " " : "", inches); |
| 711 |
addSpace = false; |
| 712 |
} |
| 713 |
|
| 714 |
if (numerator > 0) { |
| 715 |
if (inches > 0) { |
| 716 |
result += fmt::format(" {} ", value < 0 ? "-" : "+"); |
| 717 |
addSpace = false; |
| 718 |
} |
| 719 |
result += fmt::format("{}{}/{}\"", addSpace ? " " : "", numerator, denominator); |
| 720 |
} |
| 721 |
|
| 722 |
return result; |
| 723 |
} |
| 724 |
|
| 725 |
/** |
| 726 |
* double -> degrees°[minutes′[seconds″]] |
| 727 |
*/ |
| 728 |
inline std::string toDms(const double value) |
| 729 |
{ |
| 730 |
constexpr auto dmsRatio {60.0}; |
| 731 |
|
| 732 |
auto calc = [&](const double total) -> std::pair<int, double> { |
| 733 |
const double whole = std::floor(total); |
| 734 |
return {static_cast<int>(whole), dmsRatio * (total - whole)}; |
| 735 |
}; |
| 736 |
|
| 737 |
auto [degrees, totalMinutes] = calc(value); |
| 738 |
std::string out = fmt::format("{}°", degrees); |
| 739 |
|
| 740 |
if (totalMinutes > 0) { |
| 741 |
auto [minutes, totalSeconds] = calc(totalMinutes); |
| 742 |
out += fmt::format("{}′", minutes); |
| 743 |
|
| 744 |
if (totalSeconds > 0) { |
| 745 |
out += fmt::format("{}″", std::round(totalSeconds)); |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
return out; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
/** |
| 754 |
* Special functions caller |
| 755 |
*/ |
| 756 |
|
| 757 |
// clang-format off |
| 758 |
inline const std::map<std::string, std::function<std::string(double, std::size_t, std::size_t, double&, std::string&)>> specials |
| 759 |
{ |
| 760 |
{ |
| 761 |
{ "toDMS" , [](const double val, [[maybe_unused]] const std::size_t precision, [[maybe_unused]] const std::size_t denominator, |
| 762 |
double& factor, std::string& unitString) { |
| 763 |
factor = 1.0; |
| 764 |
unitString = "deg"; |
| 765 |
return toDms(val); |
| 766 |
}}, |
| 767 |
{ "toFractional" , [](const double val, [[maybe_unused]] const std::size_t precision, const std::size_t denominator, |
| 768 |
double& factor, std::string& unitString) { |
| 769 |
factor = 25.4; |
| 770 |
unitString = "in"; |
| 771 |
return toFractional(val, denominator); |
| 772 |
}} |
| 773 |
} |
| 774 |
}; // clang-format on |
| 775 |
|
| 776 |
inline std::string runSpecial( |
| 777 |
const std::string& name, |
| 778 |
const double value, |
| 779 |
const std::size_t precision, |
| 780 |
const std::size_t denominator, |
| 781 |
double& factor, |
| 782 |
std::string& unitString |
| 783 |
) |
| 784 |
{ |
| 785 |
return specials.contains(name) |
| 786 |
? specials.at(name)(value, precision, denominator, factor, unitString) |
| 787 |
: ""; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
/** |
| 792 |
* Build data pack |
| 793 |
*/ |
| 794 |
inline const UnitsSchemasDataPack unitSchemasDataPack {schemaSpecs, defDecimals, defDenominator}; |
| 795 |
|
| 796 |
|
| 797 |
} // namespace Base::UnitsSchemasData |
| 798 |
#endif // BASE_UNITSSCHEMASDATA_H |