Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add the following units:
- mmol
- ml
- bar
- mbar
- kJ
- kWh
- eV
- C
- T
- F (p, n, u, m)
- H (n, u, m)
  • Loading branch information
donovaly authored and wwmayer committed Dec 19, 2019
1 parent ba688b0 commit 82dc8e8
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 18 deletions.
31 changes: 29 additions & 2 deletions src/App/ExpressionParser.l
Expand Up @@ -168,6 +168,7 @@ EXPO [eE][-+]?[0-9]+
"km" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloMetre; yylval.quantity.unitStr = yytext; return UNIT; // kilo meter

"l" COUNTCHARS; yylval.quantity.scaler = Quantity::Liter; yylval.quantity.unitStr = yytext; return UNIT; // Liter dm^3
"ml" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliLiter; yylval.quantity.unitStr = yytext; return UNIT; // milli Liter

"ug" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram
"\xC2\xB5g" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroGram; yylval.quantity.unitStr = yytext; return UNIT; // micro gram
Expand All @@ -191,6 +192,7 @@ EXPO [eE][-+]?[0-9]+
"uK" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroKelvin; yylval.quantity.unitStr = yytext; return UNIT; // Kelvin

"mol" COUNTCHARS; yylval.quantity.scaler = Quantity::Mole; yylval.quantity.unitStr = yytext; return UNIT; // Mole (internal standard amount of substance)
"mmol" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliMole; yylval.quantity.unitStr = yytext; return UNIT; // milli Mole

"cd" COUNTCHARS; yylval.quantity.scaler = Quantity::Candela; yylval.quantity.unitStr = yytext; return UNIT; // Candela (internal standard luminous intensity)

Expand All @@ -203,8 +205,6 @@ EXPO [eE][-+]?[0-9]+
"yd" COUNTCHARS; yylval.quantity.scaler = Quantity::Yard; yylval.quantity.unitStr = yytext; return UNIT; // yard
"mi" COUNTCHARS; yylval.quantity.scaler = Quantity::Mile; yylval.quantity.unitStr = yytext; return UNIT; // mile



"lb" COUNTCHARS; yylval.quantity.scaler = Quantity::Pound; yylval.quantity.unitStr = yytext; return UNIT; // pound
"lbm" COUNTCHARS; yylval.quantity.scaler = Quantity::Pound; yylval.quantity.unitStr = yytext; return UNIT; // pound
"oz" COUNTCHARS; yylval.quantity.scaler = Quantity::Ounce; yylval.quantity.unitStr = yytext; return UNIT; // ounce
Expand All @@ -223,6 +223,9 @@ EXPO [eE][-+]?[0-9]+
"MPa" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaPascal; yylval.quantity.unitStr = yytext; return UNIT; // Pascal
"GPa" COUNTCHARS; yylval.quantity.scaler = Quantity::GigaPascal; yylval.quantity.unitStr = yytext; return UNIT; // Pascal

"bar" COUNTCHARS; yylval.quantity.scaler = Quantity::Bar; yylval.quantity.unitStr = yytext; return UNIT; // Bar
"mbar" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliBar; yylval.quantity.unitStr = yytext; return UNIT; // milli Bar

"Torr" COUNTCHARS; yylval.quantity.scaler = Quantity::Torr; yylval.quantity.unitStr = yytext; return UNIT; // portion of Pascal ( 101325/760 )
"mTorr" COUNTCHARS; yylval.quantity.scaler = Quantity::mTorr; yylval.quantity.unitStr = yytext; return UNIT; //
"uTorr" COUNTCHARS; yylval.quantity.scaler = Quantity::yTorr; yylval.quantity.unitStr = yytext; return UNIT; //
Expand All @@ -234,11 +237,35 @@ EXPO [eE][-+]?[0-9]+
"W" COUNTCHARS; yylval.quantity.scaler = Quantity::Watt; yylval.quantity.unitStr = yytext; return UNIT; // Watt (kg*m^2/s^3)
"VA" COUNTCHARS; yylval.quantity.scaler = Quantity::VoltAmpere; yylval.quantity.unitStr = yytext; return UNIT; // VoltAmpere (kg*m^2/s^3)

"V" COUNTCHARS; yylval.quantity.scaler = Quantity::Volt; yylval.quantity.unitStr = yytext; return UNIT; // Volt (kg*m^2/A/s^3)
"kV" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloVolt; yylval.quantity.unitStr = yytext; return UNIT; // Kilo Volt
"mV" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliVolt; yylval.quantity.unitStr = yytext; return UNIT; // Milli Volt

"C" COUNTCHARS; yylval.quantity.scaler = Quantity::Coulomb; yylval.quantity.unitStr = yytext; return UNIT; // Coulomb (A*s)

"T" COUNTCHARS; yylval.quantity.scaler = Quantity::Tesla; yylval.quantity.unitStr = yytext; return UNIT; // Tesla (kg/s^2/A)

"F" COUNTCHARS; yylval.quantity.scaler = Quantity::Farad; yylval.quantity.unitStr = yytext; return UNIT; // Farad (s^4*A^2/m^2/kg)
"mF" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliFarad; yylval.quantity.unitStr = yytext; return UNIT; // Milli Farad
"\xC2\xB5F" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroFarad; yylval.quantity.unitStr = yytext; return UNIT; // Micro Farad
"uF" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroFarad; yylval.quantity.unitStr = yytext; return UNIT; // Micro Farad
"nF" COUNTCHARS; yylval.quantity.scaler = Quantity::NanoFarad; yylval.quantity.unitStr = yytext; return UNIT; // Nano Farad
"pF" COUNTCHARS; yylval.quantity.scaler = Quantity::PicoFarad; yylval.quantity.unitStr = yytext; return UNIT; // Pico Farad

"H" COUNTCHARS; yylval.quantity.scaler = Quantity::Henry; yylval.quantity.unitStr = yytext; return UNIT; // Henry (kg*m^2/s^2/A^2)
"mH" COUNTCHARS; yylval.quantity.scaler = Quantity::MilliHenry; yylval.quantity.unitStr = yytext; return UNIT; // Milli Henry
"\xC2\xB5H" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroHenry; yylval.quantity.unitStr = yytext; return UNIT; // Micro Henry
"uH" COUNTCHARS; yylval.quantity.scaler = Quantity::MicroHenry; yylval.quantity.unitStr = yytext; return UNIT; // Micro Henry)
"nH" COUNTCHARS; yylval.quantity.scaler = Quantity::NanoHenry; yylval.quantity.unitStr = yytext; return UNIT; // Nano Henry

"J" COUNTCHARS; yylval.quantity.scaler = Quantity::Joule; yylval.quantity.unitStr = yytext; return UNIT; // Joule (kg*m^2/s^2)
"kJ" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloJoule; yylval.quantity.unitStr = yytext; return UNIT; // kilo Joule
"Nm" COUNTCHARS; yylval.quantity.scaler = Quantity::NewtonMeter; yylval.quantity.unitStr = yytext; return UNIT; // N*m = Joule
"VAs" COUNTCHARS; yylval.quantity.scaler = Quantity::VoltAmpereSecond; yylval.quantity.unitStr = yytext; return UNIT; // V*A*s = Joule
"CV" COUNTCHARS; yylval.quantity.scaler = Quantity::WattSecond; yylval.quantity.unitStr = yytext; return UNIT; //
"Ws" COUNTCHARS; yylval.quantity.scaler = Quantity::WattSecond; yylval.quantity.unitStr = yytext; return UNIT; // W*s = Joule
"kWh" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloWattHour; yylval.quantity.unitStr = yytext; return UNIT; // 1 kWh = 3.6e6 J
"eV" COUNTCHARS; yylval.quantity.scaler = Quantity::ElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; // 1 eV = 1.602176634e-19 J

"\xC2\xB0" COUNTCHARS; yylval.quantity.scaler = Quantity::Degree; yylval.quantity.unitStr = yytext; return UNIT; // degree (internal standard angle)
"deg" COUNTCHARS; yylval.quantity.scaler = Quantity::Degree; yylval.quantity.unitStr = yytext; return UNIT; // degree (internal standard angle)
Expand Down
34 changes: 31 additions & 3 deletions src/App/FreeCADInit.py
Expand Up @@ -638,6 +638,7 @@ def report(self,msg,func,*args,**kargs):
App.Units.Metre = App.Units.Quantity('m')
App.Units.KiloMetre = App.Units.Quantity('km')

App.Units.MilliLiter = App.Units.Quantity('ml')
App.Units.Liter = App.Units.Quantity('l')

App.Units.MicroGram = App.Units.Quantity('ug')
Expand All @@ -659,6 +660,7 @@ def report(self,msg,func,*args,**kargs):
App.Units.MilliKelvin = App.Units.Quantity('mK')
App.Units.MicroKelvin = App.Units.Quantity('uK')

App.Units.MilliMole = App.Units.Quantity('mmol')
App.Units.Mole = App.Units.Quantity('mol')

App.Units.Candela = App.Units.Quantity('cd')
Expand All @@ -684,6 +686,9 @@ def report(self,msg,func,*args,**kargs):
App.Units.MegaPascal = App.Units.Quantity('MPa')
App.Units.GigaPascal = App.Units.Quantity('GPa')

App.Units.MilliBar = App.Units.Quantity('mbar')
App.Units.Bar = App.Units.Quantity('bar')

App.Units.PoundForce = App.Units.Quantity().PoundForce
App.Units.Torr = App.Units.Quantity().Torr
App.Units.mTorr = App.Units.Quantity().mTorr
Expand All @@ -696,16 +701,35 @@ def report(self,msg,func,*args,**kargs):
App.Units.VoltAmpere = App.Units.Quantity('VA')

App.Units.Volt = App.Units.Quantity('V')
App.Units.MilliVolt = App.Units.Quantity('mV')
App.Units.KiloVolt = App.Units.Quantity('kV')

App.Units.Coulomb = App.Units.Quantity('C')

App.Units.Tesla = App.Units.Quantity('T')

App.Units.PicoFarad = App.Units.Quantity('pF')
App.Units.NanoFarad = App.Units.Quantity('nF')
App.Units.MicroFarad = App.Units.Quantity('uF')
App.Units.MilliFarad = App.Units.Quantity('mF')
App.Units.Farad = App.Units.Quantity('F')

App.Units.NanoHenry = App.Units.Quantity('nH')
App.Units.MicroHenry = App.Units.Quantity('uH')
App.Units.MilliHenry = App.Units.Quantity('mH')
App.Units.Henry = App.Units.Quantity('H')

App.Units.Joule = App.Units.Quantity('J')
App.Units.KiloJoule = App.Units.Quantity('kJ')
App.Units.NewtonMeter = App.Units.Quantity('Nm')
App.Units.VoltAmpereSecond = App.Units.Quantity('VAs')
App.Units.WattSecond = App.Units.Quantity('Ws')
App.Units.KiloWattHour = App.Units.Quantity('kWh')
App.Units.ElectronVolt = App.Units.Quantity('eV')

App.Units.MPH = App.Units.Quantity('mi/h')
App.Units.KMH = App.Units.Quantity('km/h')


App.Units.Degree = App.Units.Quantity('deg')
App.Units.Radian = App.Units.Quantity('rad')
App.Units.Gon = App.Units.Quantity('gon')
Expand All @@ -730,8 +754,12 @@ def report(self,msg,func,*args,**kargs):
App.Units.Acceleration = App.Units.Unit(1,0,-2)
App.Units.Temperature = App.Units.Unit(0,0,0,0,1)

App.Units.ElectricCurrent = App.Units.Unit(0,0,0,1)
App.Units.ElectricPotential = App.Units.Unit(2,1,-3,-1)
App.Units.ElectricCurrent = App.Units.Unit(0,0,0,1)
App.Units.ElectricPotential = App.Units.Unit(2,1,-3,-1)
App.Units.ElectricCharge = App.Units.Unit(0,0,1,1)
App.Units.MagneticFluxDensity = App.Units.Unit(0,1,-2,-1)
App.Units.ElectricalCapacitance = App.Units.Unit(-2,-1,4,2)
App.Units.ElectricalInductance = App.Units.Unit(2,1,-2,-2)
App.Units.AmountOfSubstance = App.Units.Unit(0,0,0,0,0,1)
App.Units.LuminousIntensity = App.Units.Unit(0,0,0,0,0,0,1)

Expand Down
37 changes: 31 additions & 6 deletions src/Base/Quantity.cpp
Expand Up @@ -246,7 +246,8 @@ Quantity Quantity::DeciMetre (100.0 ,Unit(1));
Quantity Quantity::Metre (1.0e3 ,Unit(1));
Quantity Quantity::KiloMetre (1.0e6 ,Unit(1));

Quantity Quantity::Liter (1000000.0 ,Unit(3));
Quantity Quantity::MilliLiter (1000.0 ,Unit(3));
Quantity Quantity::Liter (1.0e6 ,Unit(3));

Quantity Quantity::Hertz (1.0 ,Unit(0,0,-1));
Quantity Quantity::KiloHertz (1.0e3 ,Unit(0,0,-1));
Expand All @@ -272,6 +273,7 @@ Quantity Quantity::Kelvin (1.0 ,Unit(0,0,0,0,1));
Quantity Quantity::MilliKelvin (0.001 ,Unit(0,0,0,0,1));
Quantity Quantity::MicroKelvin (0.000001 ,Unit(0,0,0,0,1));

Quantity Quantity::MilliMole (0.001 ,Unit(0,0,0,0,0,1));
Quantity Quantity::Mole (1.0 ,Unit(0,0,0,0,0,1));

Quantity Quantity::Candela (1.0 ,Unit(0,0,0,0,0,0,1));
Expand Down Expand Up @@ -299,6 +301,9 @@ Quantity Quantity::KiloPascal (1.00 ,Unit(-1,1,-2));
Quantity Quantity::MegaPascal (1000.0 ,Unit(-1,1,-2));
Quantity Quantity::GigaPascal (1e+6 ,Unit(-1,1,-2));

Quantity Quantity::MilliBar (0.1 ,Unit(-1,1,-2));
Quantity Quantity::Bar (100.0 ,Unit(-1,1,-2)); // 1 bar = 100 kPa

Quantity Quantity::Torr (101.325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m/s^2 or N/m^2)
Quantity Quantity::mTorr (0.101325/760.0,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m/s^2 or N/m^2)
Quantity Quantity::yTorr (0.000101325/760.0 ,Unit(-1,1,-2)); // Torr is a defined fraction of Pascal (kg/m/s^2 or N/m^2)
Expand All @@ -309,12 +314,32 @@ Quantity Quantity::KSI (6894.744825494,Unit(-1,1,-2)); // 1000 x po
Quantity Quantity::Watt (1e+6 ,Unit(2,1,-3)); // Watt (kg*m^2/s^3)
Quantity Quantity::VoltAmpere (1e+6 ,Unit(2,1,-3)); // VoltAmpere (kg*m^2/s^3)

Quantity Quantity::Volt (1e+6 ,Unit(2,1,-3,-1)); // Volt (kg*m^2/A/s^3)
Quantity Quantity::Volt (1e+6 ,Unit(2,1,-3,-1)); // Volt (kg*m^2/A/s^3)
Quantity Quantity::MilliVolt (1e+3 ,Unit(2,1,-3,-1));
Quantity Quantity::KiloVolt (1e+9 ,Unit(2,1,-3,-1));

Quantity Quantity::Coulomb (1.0 ,Unit(0,0,1,1)); // Coulomb (A*s)

Quantity Quantity::Tesla (1.0 ,Unit(0,1,-2,-1)); // Tesla (kg/s^2/A)

Quantity Quantity::PicoFarad (1e-18 ,Unit(-2,-1,4,2));
Quantity Quantity::NanoFarad (1e-15 ,Unit(-2,-1,4,2));
Quantity Quantity::MicroFarad (1e-12 ,Unit(-2,-1,4,2));
Quantity Quantity::MilliFarad (1e-9 ,Unit(-2,-1,4,2));
Quantity Quantity::Farad (1e-6 ,Unit(-2,-1,4,2)); // Farad (s^4*A^2/m^2/kg)

Quantity Quantity::NanoHenry (1e-3 ,Unit(2,1,-2,-2));
Quantity Quantity::MicroHenry (1.0 ,Unit(2,1,-2,-2));
Quantity Quantity::MilliHenry (1e+3 ,Unit(2,1,-2,-2));
Quantity Quantity::Henry (1e+6 ,Unit(2,1,-2,-2)); // Henry (kg*m^2/s^2/A^2)

Quantity Quantity::Joule (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::NewtonMeter (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::VoltAmpereSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::WattSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::Joule (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::KiloJoule (1e+9 ,Unit(2,1,-2));
Quantity Quantity::NewtonMeter (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::VoltAmpereSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::WattSecond (1e+6 ,Unit(2,1,-2)); // Joule (kg*m^2/s^2)
Quantity Quantity::KiloWattHour (3.6e+12 ,Unit(2,1,-2)); // 1 kWh = 3.6e6 J
Quantity Quantity::ElectronVolt (1.602176634e-13 ,Unit(2,1,-2)); // 1 eV = 1.602176634e-19 J

Quantity Quantity::KMH (277.778 ,Unit(1,0,-1)); // km/h
Quantity Quantity::MPH (447.04 ,Unit(1,0,-1)); // Mile/h
Expand Down
25 changes: 25 additions & 0 deletions src/Base/Quantity.h
Expand Up @@ -187,6 +187,7 @@ class BaseExport Quantity
static Quantity KiloMetre;

static Quantity Liter;
static Quantity MilliLiter;

static Quantity Hertz;
static Quantity KiloHertz;
Expand All @@ -212,6 +213,7 @@ class BaseExport Quantity
static Quantity MilliKelvin;
static Quantity MicroKelvin;

static Quantity MilliMole;
static Quantity Mole;

static Quantity Candela;
Expand Down Expand Up @@ -239,6 +241,9 @@ class BaseExport Quantity
static Quantity MegaPascal;
static Quantity GigaPascal;

static Quantity Bar;
static Quantity MilliBar;

static Quantity Torr;
static Quantity mTorr;
static Quantity yTorr;
Expand All @@ -250,11 +255,31 @@ class BaseExport Quantity
static Quantity VoltAmpere;

static Quantity Volt;
static Quantity MilliVolt;
static Quantity KiloVolt;

static Quantity Coulomb;

static Quantity Tesla;

static Quantity Farad;
static Quantity MilliFarad;
static Quantity MicroFarad;
static Quantity NanoFarad;
static Quantity PicoFarad;

static Quantity Henry;
static Quantity MilliHenry;
static Quantity MicroHenry;
static Quantity NanoHenry;

static Quantity Joule;
static Quantity KiloJoule;
static Quantity NewtonMeter;
static Quantity VoltAmpereSecond;
static Quantity WattSecond;
static Quantity KiloWattHour;
static Quantity ElectronVolt;

static Quantity KMH;
static Quantity MPH;
Expand Down

0 comments on commit 82dc8e8

Please sign in to comment.