generate QuantityLexer.c

- also set proper unit conversions
- fix MilliWatt and MilliMole
This commit is contained in:
donovaly
2019-12-18 00:37:48 +01:00
committed by wmayer
parent 94bae36cee
commit 4b99ee28ce
6 changed files with 661 additions and 388 deletions

View File

@@ -312,6 +312,7 @@ Quantity Quantity::PSI (6.894744825494,Unit(-1,1,-2)); // pounds/in
Quantity Quantity::KSI (6894.744825494,Unit(-1,1,-2)); // 1000 x pounds/in^2
Quantity Quantity::Watt (1e+6 ,Unit(2,1,-3)); // Watt (kg*m^2/s^3)
Quantity Quantity::MilliWatt (1e+3 ,Unit(2,1,-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)

View File

@@ -252,6 +252,7 @@ public:
static Quantity KSI;
static Quantity Watt;
static Quantity MilliWatt;
static Quantity VoltAmpere;
static Quantity Volt;

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,12 @@
/* Lexer for the FreeCAD Units language */
/* (c) 2013 Juergen Riegel LGPL */
/* use this file to generate the file 'QuantityLexer.c' using the program flex
/* the command for this operation is:
/* flex --outfile=QuantityLexer.c QuantityParser.l */
/* (flex for Windows is available here: */
/* https://sourceforge.net/projects/winflexbison/ */
/* (you must then change 'flex' to 'win_flex' in the command)) */
/* This disables inclusion of unistd.h, which is not available under Visual C++
* on Win32. The C++ scanner uses STL streams instead. */
@@ -83,7 +88,7 @@ CGRP '\,'[0-9][0-9][0-9]
"uK" yylval = Quantity::MicroKelvin; return UNIT; // Kelvin
"mol" yylval = Quantity::Mole; return UNIT; // Mole (internal standard amount of substance)
"mmol" yylval = Quantity::Mole; return UNIT; // Milli Mole
"mmol" yylval = Quantity::MilliMole; return UNIT; // Milli Mole
"cd" yylval = Quantity::Candela; return UNIT; // Candela (internal standard luminous intensity)
@@ -126,7 +131,7 @@ CGRP '\,'[0-9][0-9][0-9]
"ksi" yylval = Quantity::KSI; return UNIT; // 1000 x pounds/in^2
"W" yylval = Quantity::Watt; return UNIT; // Watt (kg*m^2/s^3)
"mW" yylval = Quantity::Watt; return UNIT; // Milli Watt
"mW" yylval = Quantity::MilliWatt; return UNIT; // Milli Watt
"VA" yylval = Quantity::VoltAmpere; return UNIT; // VoltAmpere (kg*m^2/s^3)
"V" yylval = Quantity::Volt; return UNIT; // Volt (kg*m^2/A/s^3)

View File

@@ -82,10 +82,40 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
}
}
else if (unit == Unit::Area) {
// TODO Cascade for the Areas
// default action for all cases without special treatment:
unitString = quant.getUnit().getString();
factor = 1.0;
if (UnitValue < 100) {
unitString = QString::fromLatin1("mm^2");
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("cm^2");
factor = 100;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("m^2");
factor = 1e6;
}
else { // bigger than 1 square kilometer
unitString = QString::fromLatin1("km^2");
factor = 1e12;
}
}
else if (unit == Unit::Volume) {
if (UnitValue < 1e3) {// smaller than 1 ul
unitString = QString::fromLatin1("mm^3");
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml");
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l");
factor = 1e6;
}
else { // bigger than 1000 l
unitString = QString::fromLatin1("m^3");
factor = 1e9;
}
}
else if (unit == Unit::Angle) {
// TODO Cascade for the Areas
@@ -164,12 +194,50 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
}
}
else if (unit == Unit::Power) {
unitString = QString::fromLatin1("W");
factor = 1000000;
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mW");
factor = 1e3;
}
else {
unitString = QString::fromLatin1("W");
factor = 1e6;
}
}
else if (unit == Unit::ElectricPotential) {
unitString = QString::fromLatin1("V");
factor = 1000000;
if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mV");
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("V");
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kV");
factor = 1e9;
}
else { // > 1000 kV scientificc notation
unitString = QString::fromLatin1("V");
factor = 1.0;
}
}
else if (unit == Unit::Work) {
if (UnitValue < 1.602176634e-10) {
unitString = QString::fromLatin1("eV");
factor = 1.602176634e-13;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("J");
factor = 1e6;
}
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("kJ");
factor = 1e9;
}
else { // bigger than 1000 kJ -> scientific notation
unitString = QString::fromLatin1("J");
factor = 1.0;
}
}
else if (unit == Unit::SpecificEnergy) {
unitString = QString::fromLatin1("m^2/s^2");
@@ -179,6 +247,46 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact
unitString = QString::fromLatin1("W/m^2");
factor = 1.0;
}
else if (unit == Unit::ElectricalCapacitance) {
if (UnitValue < 1e-15) {
unitString = QString::fromLatin1("pF");
factor = 1e-18;
}
else if (UnitValue < 1e-12) {
unitString = QString::fromLatin1("nF");
factor = 1e-15;
}
else if (UnitValue < 1e-9) {
unitString = QString::fromUtf8("µF");
factor = 1e-12;
}
else if (UnitValue < 1e-6) {
unitString = QString::fromLatin1("mF");
factor = 1e-9;
}
else {
unitString = QString::fromLatin1("F");
factor = 1e-6;
}
}
else if (unit == Unit::ElectricalInductance) {
if (UnitValue < 1.0) {
unitString = QString::fromLatin1("nH");
factor = 1e-3;
}
else if (UnitValue < 1e3) {
unitString = QString::fromUtf8("µH");
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("mH");
factor = 1e3;
}
else {
unitString = QString::fromLatin1("H");
factor = 1e6;
}
}
else if (unit == Unit::Frequency) {
if (UnitValue < 1000.0) {
unitString = QString::fromLatin1("Hz");

View File

@@ -73,17 +73,39 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
}
}
else if (unit == Unit::Area) {
if (UnitValue < 100.0) {// smaller than 1 square cm
if (UnitValue < 100) {
unitString = QString::fromLatin1("mm^2");
factor = 1.0;
}
else if (UnitValue < 10000000000000.0) {
unitString = QString::fromLatin1("m^2");
factor = 1000000.0;
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("cm^2");
factor = 100;
}
else { // bigger then 1 square kilometer
else if (UnitValue < 1e12) {
unitString = QString::fromLatin1("m^2");
factor = 1e6;
}
else { // bigger than 1 square kilometer
unitString = QString::fromLatin1("km^2");
factor = 1000000000000.0;
factor = 1e12;
}
}
else if (unit == Unit::Volume) {
if (UnitValue < 1e3) {// smaller than 1 ul
unitString = QString::fromLatin1("mm^3");
factor = 1.0;
}
else if (UnitValue < 1e6) {
unitString = QString::fromLatin1("ml");
factor = 1e3;
}
else if (UnitValue < 1e9) {
unitString = QString::fromLatin1("l");
factor = 1e6;
}
else { // bigger than 1000 l
unitString = QString::fromLatin1("m^3");
factor = 1e9;
}
}
else if (unit == Unit::Mass) {
@@ -237,7 +259,11 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q
}
}
else if (unit == Unit::Work) {
if (UnitValue < 1e3) {
if (UnitValue < 1.602176634e-10) {
unitString = QString::fromLatin1("eV");
factor = 1.602176634e-13;
}
if (UnitValue < 1e9) {
unitString = QString::fromLatin1("J");
factor = 1e6;
}