From cd8b63028c4ee1ffdbc47c5abf319ffc80919717 Mon Sep 17 00:00:00 2001 From: donovaly Date: Mon, 23 Dec 2019 22:32:47 +0100 Subject: [PATCH] missing parts from from commit d9d903faea - also add keV and MeV since these are the units used in practice --- src/App/ExpressionParser.l | 5 + src/App/FreeCADInit.py | 13 +- src/Base/Quantity.cpp | 2 + src/Base/Quantity.h | 2 + src/Base/QuantityLexer.c | 434 ++++++++++++++++--------------- src/Base/QuantityParser.l | 2 + src/Base/UnitsSchemaInternal.cpp | 8 + src/Base/UnitsSchemaMKS.cpp | 8 + 8 files changed, 259 insertions(+), 215 deletions(-) diff --git a/src/App/ExpressionParser.l b/src/App/ExpressionParser.l index 64c430ca65..56c21776f5 100644 --- a/src/App/ExpressionParser.l +++ b/src/App/ExpressionParser.l @@ -210,6 +210,9 @@ EXPO [eE][-+]?[0-9]+ "mil" COUNTCHARS; yylval.quantity.scaler = Quantity::Thou; yylval.quantity.unitStr = yytext; return UNIT; // mil (the thou in US) "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 +"mph" COUNTCHARS; yylval.quantity.scaler = Quantity::MilePerHour; yylval.quantity.unitStr = yytext; return UNIT; // mile per hour +"sqft" COUNTCHARS; yylval.quantity.scaler = Quantity::SquareFoot; yylval.quantity.unitStr = yytext; return UNIT; // square foot +"cft" COUNTCHARS; yylval.quantity.scaler = Quantity::CubicFoot; yylval.quantity.unitStr = yytext; return UNIT; // cubic foot "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 @@ -276,6 +279,8 @@ EXPO [eE][-+]?[0-9]+ "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 +"keV" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; +"MeV" COUNTCHARS; yylval.quantity.scaler = Quantity::MegaElectronVolt; yylval.quantity.unitStr = yytext; return UNIT; "cal" COUNTCHARS; yylval.quantity.scaler = Quantity::Calorie; yylval.quantity.unitStr = yytext; return UNIT; // 1 cal = 4.1868 J "kcal" COUNTCHARS; yylval.quantity.scaler = Quantity::KiloCalorie; yylval.quantity.unitStr = yytext; return UNIT; diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index 4eb51dd6ad..aa3606ca6e 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -676,6 +676,9 @@ App.Units.Foot = App.Units.Quantity('ft') App.Units.Thou = App.Units.Quantity('thou') App.Units.Yard = App.Units.Quantity('yd') App.Units.Mile = App.Units.Quantity('mi') +App.Units.MilePerHour = App.Units.Quantity('mph') +App.Units.SquareFoot = App.Units.Quantity('sqft') +App.Units.CubicFoot = App.Units.Quantity('cft') App.Units.Pound = App.Units.Quantity('lb') App.Units.Ounce = App.Units.Quantity('oz') @@ -695,10 +698,10 @@ 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 -App.Units.yTorr = App.Units.Quantity().yTorr +App.Units.PoundForce = App.Units.Quantity('lbf') +App.Units.Torr = App.Units.Quantity('Torr') +App.Units.mTorr = App.Units.Quantity('mTorr') +App.Units.yTorr = App.Units.Quantity('uTorr') App.Units.PSI = App.Units.Quantity('psi') App.Units.KSI = App.Units.Quantity('ksi') @@ -736,6 +739,8 @@ 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.KiloElectronVolt = App.Units.Quantity('keV') +App.Units.MegaElectronVolt = App.Units.Quantity('MeV') App.Units.Calorie = App.Units.Quantity('cal') App.Units.KiloCalorie = App.Units.Quantity('kcal') diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 9e1e846778..df8655654d 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -354,6 +354,8 @@ Quantity Quantity::VoltAmpereSecond (1e+6 ,Unit(2,1,-2)); // Joule ( 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::KiloElectronVolt (1.602176634e-10 ,Unit(2,1,-2)); +Quantity Quantity::MegaElectronVolt (1.602176634e-7 ,Unit(2,1,-2)); Quantity Quantity::Calorie (4.1868e+6 ,Unit(2,1,-2)); // 1 cal = 4.1868 J Quantity Quantity::KiloCalorie (4.1868e+9 ,Unit(2,1,-2)); diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index 56de3f486e..04b1df2dc6 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -291,6 +291,8 @@ public: static Quantity WattSecond; static Quantity KiloWattHour; static Quantity ElectronVolt; + static Quantity KiloElectronVolt; + static Quantity MegaElectronVolt; static Quantity Calorie; static Quantity KiloCalorie; diff --git a/src/Base/QuantityLexer.c b/src/Base/QuantityLexer.c index 5a581400af..8acef0aed8 100644 --- a/src/Base/QuantityLexer.c +++ b/src/Base/QuantityLexer.c @@ -1,6 +1,6 @@ -#line 2 "QuantityLexer.c" +#line 1 "QuantityLexer.c" -#line 4 "QuantityLexer.c" +#line 3 "QuantityLexer.c" #define YY_INT_ALIGNED short int @@ -353,8 +353,8 @@ static void yynoreturn yy_fatal_error ( const char* msg ); (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; -#define YY_NUM_RULES 141 -#define YY_END_OF_BUFFER 142 +#define YY_NUM_RULES 143 +#define YY_END_OF_BUFFER 144 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -362,35 +362,35 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static const flex_int16_t yy_accept[245] = +static const flex_int16_t yy_accept[249] = { 0, - 0, 0, 0, 0, 142, 140, 4, 5, 45, 47, - 6, 140, 7, 140, 118, 117, 33, 85, 87, 140, - 93, 98, 37, 113, 61, 140, 115, 86, 82, 78, - 1, 140, 140, 140, 140, 123, 140, 27, 32, 140, - 140, 17, 15, 140, 140, 140, 140, 30, 29, 140, - 140, 140, 140, 3, 141, 2, 5, 121, 119, 120, - 118, 118, 0, 103, 0, 0, 19, 36, 0, 64, - 0, 0, 101, 65, 0, 0, 81, 104, 0, 0, - 0, 0, 0, 0, 43, 0, 13, 0, 0, 0, - 14, 106, 0, 46, 0, 44, 35, 0, 100, 63, + 0, 0, 0, 0, 144, 142, 4, 5, 45, 47, + 6, 142, 7, 142, 120, 119, 33, 85, 87, 142, + 93, 98, 37, 115, 61, 142, 117, 86, 82, 78, + 1, 142, 142, 142, 142, 125, 142, 27, 32, 142, + 142, 17, 15, 142, 142, 142, 142, 30, 29, 142, + 142, 142, 142, 3, 143, 2, 5, 123, 121, 122, + 120, 120, 0, 103, 0, 0, 19, 36, 0, 64, + 0, 0, 0, 101, 65, 0, 0, 81, 104, 0, + 0, 0, 0, 0, 0, 43, 0, 13, 0, 0, + 0, 14, 106, 0, 46, 0, 44, 35, 0, 100, - 0, 83, 80, 0, 28, 16, 0, 55, 0, 34, - 88, 94, 99, 38, 62, 0, 84, 79, 0, 26, - 51, 18, 12, 0, 0, 91, 97, 9, 57, 92, - 122, 0, 0, 0, 0, 0, 58, 0, 0, 90, - 96, 40, 0, 24, 10, 50, 109, 0, 0, 0, - 0, 0, 120, 0, 118, 0, 0, 118, 22, 68, - 21, 67, 0, 23, 0, 102, 130, 0, 0, 0, - 69, 107, 54, 128, 59, 110, 129, 112, 20, 66, - 105, 0, 76, 60, 56, 132, 0, 0, 49, 31, - 0, 131, 41, 52, 134, 75, 111, 135, 0, 0, + 63, 0, 83, 80, 0, 0, 28, 16, 0, 55, + 0, 34, 88, 94, 99, 38, 62, 0, 84, 79, + 0, 26, 51, 18, 12, 0, 0, 91, 97, 9, + 57, 92, 124, 0, 0, 0, 0, 0, 58, 0, + 0, 90, 96, 40, 0, 24, 10, 50, 111, 0, + 0, 0, 0, 0, 122, 0, 120, 0, 0, 120, + 22, 68, 21, 67, 108, 0, 23, 0, 102, 132, + 0, 0, 0, 69, 109, 54, 130, 59, 112, 131, + 114, 20, 66, 105, 0, 107, 76, 60, 56, 134, + 0, 0, 49, 31, 0, 133, 41, 52, 136, 75, - 137, 0, 0, 89, 95, 39, 0, 25, 11, 114, - 116, 8, 0, 121, 0, 119, 0, 120, 0, 118, - 77, 71, 124, 125, 126, 108, 0, 0, 70, 42, - 136, 53, 139, 138, 48, 0, 0, 127, 133, 72, - 73, 0, 74, 0 + 113, 137, 0, 0, 139, 0, 0, 89, 95, 39, + 0, 25, 11, 116, 118, 8, 0, 123, 0, 121, + 0, 122, 0, 120, 77, 71, 126, 127, 128, 110, + 0, 0, 70, 42, 138, 53, 141, 140, 48, 0, + 0, 129, 135, 72, 73, 0, 74, 0 } ; static const YY_CHAR yy_ec[256] = @@ -436,69 +436,69 @@ static const YY_CHAR yy_meta[65] = 1, 1, 1, 1 } ; -static const flex_int16_t yy_base[246] = +static const flex_int16_t yy_base[250] = { 0, - 0, 0, 62, 63, 374, 375, 375, 370, 375, 375, - 375, 56, 375, 60, 67, 75, 375, 344, 375, 70, - 316, 375, 375, 76, 327, 337, 375, 62, 353, 318, - 375, 64, 334, 67, 72, 77, 315, 319, 375, 319, - 116, 73, 151, 103, 307, 98, 329, 77, 93, 163, - 325, 67, 77, 375, 375, 375, 356, 150, 191, 198, - 205, 218, 144, 375, 303, 325, 375, 375, 301, 375, - 323, 305, 375, 375, 298, 304, 302, 375, 301, 304, - 308, 315, 298, 303, 375, 294, 375, 294, 292, 303, - 375, 375, 294, 375, 295, 375, 375, 283, 375, 375, + 0, 0, 62, 63, 378, 379, 379, 374, 379, 379, + 379, 56, 379, 60, 67, 75, 379, 348, 379, 70, + 320, 379, 379, 76, 331, 341, 379, 62, 357, 322, + 379, 64, 338, 73, 63, 74, 319, 323, 379, 323, + 113, 76, 148, 97, 311, 86, 333, 89, 91, 160, + 329, 84, 63, 379, 379, 379, 360, 147, 188, 195, + 202, 215, 141, 379, 307, 329, 379, 379, 305, 379, + 327, 330, 308, 379, 379, 301, 307, 305, 379, 304, + 307, 311, 318, 301, 306, 379, 297, 379, 297, 295, + 306, 379, 379, 297, 379, 298, 379, 379, 286, 379, - 305, 375, 297, 303, 375, 375, 294, 105, 295, 375, - 375, 375, 375, 375, 375, 240, 375, 375, 251, 375, - 126, 375, 237, 93, 241, 375, 375, 375, 375, 375, - 375, 227, 230, 231, 208, 72, 375, 207, 205, 375, - 375, 375, 198, 375, 375, 375, 375, 218, 116, 181, - 235, 246, 251, 260, 264, 277, 281, 285, 375, 375, - 375, 375, 197, 375, 185, 375, 375, 176, 180, 179, - 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, - 375, 179, 375, 375, 375, 208, 166, 165, 375, 375, - 165, 375, 375, 375, 375, 375, 375, 161, 149, 148, + 379, 308, 379, 300, 306, 309, 379, 379, 296, 128, + 297, 379, 379, 379, 379, 379, 379, 289, 379, 379, + 301, 379, 153, 379, 287, 132, 292, 379, 379, 379, + 379, 379, 379, 278, 242, 245, 235, 136, 379, 233, + 231, 379, 379, 379, 222, 379, 379, 379, 379, 215, + 84, 205, 232, 243, 248, 257, 261, 274, 278, 282, + 379, 379, 379, 379, 379, 209, 379, 200, 379, 379, + 198, 196, 192, 379, 379, 379, 379, 379, 379, 379, + 379, 379, 379, 379, 192, 379, 379, 379, 379, 218, + 174, 173, 379, 379, 178, 379, 379, 379, 379, 379, - 156, 141, 140, 375, 375, 375, 142, 375, 375, 375, - 375, 375, 290, 294, 298, 302, 306, 310, 314, 318, - 375, 375, 375, 375, 169, 375, 163, 112, 375, 375, - 375, 375, 375, 375, 375, 104, 101, 375, 375, 375, - 375, 91, 375, 375, 75 + 379, 179, 167, 161, 171, 153, 148, 379, 379, 379, + 147, 379, 379, 379, 379, 379, 287, 291, 295, 299, + 303, 307, 311, 315, 379, 379, 379, 379, 176, 379, + 174, 131, 379, 379, 379, 379, 379, 379, 379, 109, + 84, 379, 379, 379, 379, 76, 379, 379, 75 } ; -static const flex_int16_t yy_def[246] = +static const flex_int16_t yy_def[250] = { 0, - 244, 1, 245, 245, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, + 248, 1, 249, 249, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 0, 244 + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 0, 248 } ; -static const flex_int16_t yy_nxt[440] = +static const flex_int16_t yy_nxt[444] = { 0, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 15, 15, 17, 18, 6, 19, 20, 21, @@ -508,49 +508,50 @@ static const flex_int16_t yy_nxt[440] = 50, 6, 6, 51, 6, 6, 6, 6, 6, 6, 6, 6, 52, 53, 55, 55, 58, 58, 58, 58, 59, 59, 59, 59, 60, 54, 61, 62, 62, 62, - 62, 75, 60, 63, 61, 62, 62, 62, 62, 65, - 68, 63, 56, 56, 66, 69, 79, 80, 84, 70, + 62, 76, 60, 63, 61, 62, 62, 62, 62, 65, + 68, 63, 56, 56, 66, 69, 80, 81, 91, 70, - 71, 85, 63, 86, 92, 108, 76, 90, 199, 87, - 63, 88, 81, 82, 91, 130, 135, 109, 89, 200, - 126, 72, 127, 136, 138, 147, 137, 192, 148, 93, - 97, 139, 149, 150, 193, 98, 99, 131, 243, 100, - 101, 184, 132, 102, 103, 128, 133, 185, 242, 104, - 157, 241, 157, 105, 158, 158, 158, 158, 106, 240, - 58, 58, 58, 58, 107, 110, 151, 189, 111, 190, - 112, 113, 114, 239, 115, 210, 211, 116, 117, 118, - 140, 238, 141, 119, 142, 151, 237, 236, 120, 143, - 121, 235, 122, 123, 234, 124, 125, 233, 232, 231, + 71, 93, 63, 132, 85, 92, 77, 86, 110, 87, + 63, 72, 82, 83, 128, 88, 129, 89, 151, 152, + 111, 73, 140, 247, 90, 133, 94, 98, 137, 141, + 134, 246, 99, 100, 135, 138, 101, 102, 139, 130, + 103, 104, 149, 214, 215, 150, 105, 159, 106, 159, + 107, 160, 160, 160, 160, 108, 245, 58, 58, 58, + 58, 109, 112, 153, 188, 113, 196, 114, 115, 116, + 189, 117, 203, 197, 118, 119, 120, 142, 244, 143, + 121, 144, 153, 204, 243, 122, 145, 123, 242, 124, + 125, 241, 126, 127, 193, 240, 194, 146, 59, 59, - 144, 59, 59, 59, 59, 145, 230, 152, 153, 153, - 153, 153, 229, 228, 154, 155, 155, 155, 155, 227, - 226, 156, 225, 224, 223, 60, 152, 61, 62, 62, - 62, 62, 222, 154, 63, 204, 221, 205, 212, 206, - 156, 213, 203, 213, 207, 214, 214, 214, 214, 202, - 201, 198, 215, 63, 215, 208, 216, 216, 216, 216, - 209, 153, 153, 153, 153, 197, 217, 154, 217, 196, - 218, 218, 218, 218, 155, 155, 155, 155, 195, 194, - 156, 191, 188, 219, 187, 219, 154, 220, 220, 220, - 220, 158, 158, 158, 158, 158, 158, 158, 158, 156, + 59, 59, 147, 239, 154, 155, 155, 155, 155, 238, + 237, 156, 157, 157, 157, 157, 236, 235, 158, 234, + 233, 232, 60, 154, 61, 62, 62, 62, 62, 231, + 156, 63, 208, 230, 209, 229, 210, 158, 217, 228, + 217, 211, 218, 218, 218, 218, 227, 226, 225, 219, + 63, 219, 212, 220, 220, 220, 220, 213, 155, 155, + 155, 155, 216, 221, 156, 221, 207, 222, 222, 222, + 222, 157, 157, 157, 157, 206, 205, 158, 202, 201, + 223, 200, 223, 156, 224, 224, 224, 224, 160, 160, + 160, 160, 160, 160, 160, 160, 158, 218, 218, 218, - 214, 214, 214, 214, 214, 214, 214, 214, 216, 216, - 216, 216, 216, 216, 216, 216, 218, 218, 218, 218, - 218, 218, 218, 218, 220, 220, 220, 220, 220, 220, - 220, 220, 186, 183, 182, 181, 180, 179, 178, 177, - 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, - 166, 165, 164, 163, 162, 161, 160, 159, 57, 146, - 134, 129, 96, 95, 94, 83, 78, 77, 74, 73, - 67, 64, 57, 244, 5, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, + 218, 218, 218, 218, 218, 220, 220, 220, 220, 220, + 220, 220, 220, 222, 222, 222, 222, 222, 222, 222, + 222, 224, 224, 224, 224, 224, 224, 224, 224, 199, + 198, 195, 192, 191, 190, 187, 186, 185, 184, 183, + 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, + 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, + 162, 161, 57, 148, 136, 131, 97, 96, 95, 84, + 79, 78, 75, 74, 67, 64, 57, 248, 5, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244 + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248 } ; -static const flex_int16_t yy_chk[440] = +static const flex_int16_t yy_chk[444] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -559,47 +560,48 @@ static const flex_int16_t yy_chk[440] = 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 12, 12, 12, 12, - 14, 14, 14, 14, 15, 245, 15, 15, 15, 15, + 14, 14, 14, 14, 15, 249, 15, 15, 15, 15, 15, 28, 16, 15, 16, 16, 16, 16, 16, 20, - 24, 16, 3, 4, 20, 24, 32, 32, 34, 24, + 24, 16, 3, 4, 20, 24, 32, 32, 35, 24, - 24, 34, 15, 34, 36, 42, 28, 35, 136, 34, - 16, 34, 32, 32, 35, 46, 48, 42, 34, 136, - 44, 24, 44, 48, 49, 52, 48, 124, 52, 36, - 41, 49, 53, 53, 124, 41, 41, 46, 242, 41, - 41, 108, 46, 41, 41, 44, 46, 108, 237, 41, - 63, 236, 63, 41, 63, 63, 63, 63, 41, 228, - 58, 58, 58, 58, 41, 43, 58, 121, 43, 121, - 43, 43, 43, 227, 43, 149, 149, 43, 43, 43, - 50, 225, 50, 43, 50, 58, 207, 203, 43, 50, - 43, 202, 43, 43, 201, 43, 43, 200, 199, 198, + 24, 36, 15, 46, 34, 35, 28, 34, 42, 34, + 16, 24, 32, 32, 44, 34, 44, 34, 53, 53, + 42, 24, 49, 246, 34, 46, 36, 41, 48, 49, + 46, 241, 41, 41, 46, 48, 41, 41, 48, 44, + 41, 41, 52, 151, 151, 52, 41, 63, 41, 63, + 41, 63, 63, 63, 63, 41, 240, 58, 58, 58, + 58, 41, 43, 58, 110, 43, 126, 43, 43, 43, + 110, 43, 138, 126, 43, 43, 43, 50, 232, 50, + 43, 50, 58, 138, 231, 43, 50, 43, 229, 43, + 43, 211, 43, 43, 123, 207, 123, 50, 59, 59, - 50, 59, 59, 59, 59, 50, 191, 59, 60, 60, - 60, 60, 188, 187, 60, 61, 61, 61, 61, 186, - 182, 61, 170, 169, 168, 62, 59, 62, 62, 62, - 62, 62, 165, 60, 62, 148, 163, 148, 150, 148, - 61, 151, 143, 151, 148, 151, 151, 151, 151, 139, - 138, 135, 152, 62, 152, 148, 152, 152, 152, 152, - 148, 153, 153, 153, 153, 134, 154, 153, 154, 133, - 154, 154, 154, 154, 155, 155, 155, 155, 132, 125, - 155, 123, 119, 156, 116, 156, 153, 156, 156, 156, - 156, 157, 157, 157, 157, 158, 158, 158, 158, 155, + 59, 59, 50, 206, 59, 60, 60, 60, 60, 205, + 204, 60, 61, 61, 61, 61, 203, 202, 61, 195, + 192, 191, 62, 59, 62, 62, 62, 62, 62, 190, + 60, 62, 150, 185, 150, 173, 150, 61, 153, 172, + 153, 150, 153, 153, 153, 153, 171, 168, 166, 154, + 62, 154, 150, 154, 154, 154, 154, 150, 155, 155, + 155, 155, 152, 156, 155, 156, 145, 156, 156, 156, + 156, 157, 157, 157, 157, 141, 140, 157, 137, 136, + 158, 135, 158, 155, 158, 158, 158, 158, 159, 159, + 159, 159, 160, 160, 160, 160, 157, 217, 217, 217, - 213, 213, 213, 213, 214, 214, 214, 214, 215, 215, - 215, 215, 216, 216, 216, 216, 217, 217, 217, 217, - 218, 218, 218, 218, 219, 219, 219, 219, 220, 220, - 220, 220, 109, 107, 104, 103, 101, 98, 95, 93, - 90, 89, 88, 86, 84, 83, 82, 81, 80, 79, - 77, 76, 75, 72, 71, 69, 66, 65, 57, 51, - 47, 45, 40, 38, 37, 33, 30, 29, 26, 25, - 21, 18, 8, 5, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, + 217, 218, 218, 218, 218, 219, 219, 219, 219, 220, + 220, 220, 220, 221, 221, 221, 221, 222, 222, 222, + 222, 223, 223, 223, 223, 224, 224, 224, 224, 134, + 127, 125, 121, 118, 111, 109, 106, 105, 104, 102, + 99, 96, 94, 91, 90, 89, 87, 85, 84, 83, + 82, 81, 80, 78, 77, 76, 73, 72, 71, 69, + 66, 65, 57, 51, 47, 45, 40, 38, 37, 33, + 30, 29, 26, 25, 21, 18, 8, 5, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, - 244, 244, 244, 244, 244, 244, 244, 244, 244 + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + 248, 248, 248 } ; static yy_state_type yy_last_accepting_state; @@ -632,12 +634,12 @@ char *yytext; * on Win32. The C++ scanner uses STL streams instead. */ #define YY_NO_UNISTD_H -#line 636 "QuantityLexer.c" +#line 637 "QuantityLexer.c" /*** Flex Declarations and Options ***/ /* the manual says "somewhat more optimized" */ /* no support for include files is planned */ -#line 641 "QuantityLexer.c" +#line 642 "QuantityLexer.c" #define INITIAL 0 #define C_COMMENT 1 @@ -649,7 +651,7 @@ char *yytext; */ #include #endif - + #ifndef YY_EXTRA_TYPE #define YY_EXTRA_TYPE void * #endif @@ -856,7 +858,7 @@ YY_DECL #line 37 "QuantityParser.l" -#line 860 "QuantityLexer.c" +#line 861 "QuantityLexer.c" while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ { @@ -883,13 +885,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 245 ) + if ( yy_current_state >= 249 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_current_state != 244 ); + while ( yy_current_state != 248 ); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); @@ -1443,179 +1445,189 @@ yylval = Quantity::ElectronVolt; return UNIT; // 1 eV = 1.602176634e-19 J case 107: YY_RULE_SETUP #line 173 "QuantityParser.l" -yylval = Quantity::Calorie; return UNIT; // 1 cal = 4.1868 J +yylval = Quantity::KiloElectronVolt; return UNIT; YY_BREAK case 108: YY_RULE_SETUP #line 174 "QuantityParser.l" -yylval = Quantity::KiloCalorie; return UNIT; +yylval = Quantity::MegaElectronVolt; return UNIT; YY_BREAK case 109: YY_RULE_SETUP -#line 176 "QuantityParser.l" -yylval = Quantity::Degree; return UNIT; // degree (internal standard angle) +#line 175 "QuantityParser.l" +yylval = Quantity::Calorie; return UNIT; // 1 cal = 4.1868 J YY_BREAK case 110: YY_RULE_SETUP -#line 177 "QuantityParser.l" -yylval = Quantity::Degree; return UNIT; // degree (internal standard angle) +#line 176 "QuantityParser.l" +yylval = Quantity::KiloCalorie; return UNIT; YY_BREAK case 111: YY_RULE_SETUP #line 178 "QuantityParser.l" -yylval = Quantity::Radian; return UNIT; // radian +yylval = Quantity::Degree; return UNIT; // degree (internal standard angle) YY_BREAK case 112: YY_RULE_SETUP #line 179 "QuantityParser.l" -yylval = Quantity::Gon; return UNIT; // gon +yylval = Quantity::Degree; return UNIT; // degree (internal standard angle) YY_BREAK case 113: YY_RULE_SETUP #line 180 "QuantityParser.l" -yylval = Quantity::AngMinute; return UNIT; // minute(Angular) +yylval = Quantity::Radian; return UNIT; // radian YY_BREAK case 114: YY_RULE_SETUP #line 181 "QuantityParser.l" -yylval = Quantity::AngMinute; return UNIT; // minute(Angular) +yylval = Quantity::Gon; return UNIT; // gon YY_BREAK case 115: YY_RULE_SETUP #line 182 "QuantityParser.l" -yylval = Quantity::AngSecond; return UNIT; // second(Angular) +yylval = Quantity::AngMinute; return UNIT; // minute(Angular) YY_BREAK case 116: YY_RULE_SETUP #line 183 "QuantityParser.l" -yylval = Quantity::AngSecond; return UNIT; // second(Angular) +yylval = Quantity::AngMinute; return UNIT; // minute(Angular) YY_BREAK case 117: YY_RULE_SETUP -#line 185 "QuantityParser.l" -yylval = Quantity(1.0); return ONE; +#line 184 "QuantityParser.l" +yylval = Quantity::AngSecond; return UNIT; // second(Angular) YY_BREAK case 118: YY_RULE_SETUP -#line 186 "QuantityParser.l" -{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } +#line 185 "QuantityParser.l" +yylval = Quantity::AngSecond; return UNIT; // second(Angular) YY_BREAK case 119: YY_RULE_SETUP #line 187 "QuantityParser.l" -{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } +yylval = Quantity(1.0); return ONE; YY_BREAK case 120: YY_RULE_SETUP #line 188 "QuantityParser.l" -{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } +{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } YY_BREAK case 121: YY_RULE_SETUP #line 189 "QuantityParser.l" -{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } +{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } YY_BREAK case 122: YY_RULE_SETUP -#line 192 "QuantityParser.l" -{yylval = Quantity(M_PI) ; return NUM;} // constant pi +#line 190 "QuantityParser.l" +{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } YY_BREAK case 123: YY_RULE_SETUP -#line 193 "QuantityParser.l" -{yylval = Quantity(M_E) ; return NUM;} // constant e +#line 191 "QuantityParser.l" +{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } YY_BREAK case 124: YY_RULE_SETUP -#line 195 "QuantityParser.l" -return ACOS; +#line 194 "QuantityParser.l" +{yylval = Quantity(M_PI) ; return NUM;} // constant pi YY_BREAK case 125: YY_RULE_SETUP -#line 196 "QuantityParser.l" -return ASIN; +#line 195 "QuantityParser.l" +{yylval = Quantity(M_E) ; return NUM;} // constant e YY_BREAK case 126: YY_RULE_SETUP #line 197 "QuantityParser.l" -return ATAN; +return ACOS; YY_BREAK case 127: YY_RULE_SETUP #line 198 "QuantityParser.l" -return ATAN2; +return ASIN; YY_BREAK case 128: YY_RULE_SETUP #line 199 "QuantityParser.l" -return COS; +return ATAN; YY_BREAK case 129: YY_RULE_SETUP #line 200 "QuantityParser.l" -return EXP; +return ATAN2; YY_BREAK case 130: YY_RULE_SETUP #line 201 "QuantityParser.l" -return ABS; +return COS; YY_BREAK case 131: YY_RULE_SETUP #line 202 "QuantityParser.l" -return MOD; +return EXP; YY_BREAK case 132: YY_RULE_SETUP #line 203 "QuantityParser.l" -return LOG; +return ABS; YY_BREAK case 133: YY_RULE_SETUP #line 204 "QuantityParser.l" -return LOG10; +return MOD; YY_BREAK case 134: YY_RULE_SETUP #line 205 "QuantityParser.l" -return POW; +return LOG; YY_BREAK case 135: YY_RULE_SETUP #line 206 "QuantityParser.l" -return SIN; +return LOG10; YY_BREAK case 136: YY_RULE_SETUP #line 207 "QuantityParser.l" -return SINH; +return POW; YY_BREAK case 137: YY_RULE_SETUP #line 208 "QuantityParser.l" -return TAN; +return SIN; YY_BREAK case 138: YY_RULE_SETUP #line 209 "QuantityParser.l" -return TANH; +return SINH; YY_BREAK case 139: YY_RULE_SETUP #line 210 "QuantityParser.l" -return SQRT; +return TAN; YY_BREAK case 140: YY_RULE_SETUP -#line 212 "QuantityParser.l" -return *yytext; +#line 211 "QuantityParser.l" +return TANH; YY_BREAK case 141: YY_RULE_SETUP -#line 213 "QuantityParser.l" +#line 212 "QuantityParser.l" +return SQRT; + YY_BREAK +case 142: +YY_RULE_SETUP +#line 214 "QuantityParser.l" +return *yytext; + YY_BREAK +case 143: +YY_RULE_SETUP +#line 215 "QuantityParser.l" ECHO; YY_BREAK -#line 1619 "QuantityLexer.c" +#line 1630 "QuantityLexer.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(C_COMMENT): yyterminate(); @@ -1914,7 +1926,7 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 245 ) + if ( yy_current_state >= 249 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; @@ -1942,11 +1954,11 @@ static int yy_get_next_buffer (void) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 245 ) + if ( yy_current_state >= 249 ) yy_c = yy_meta[yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - yy_is_jam = (yy_current_state == 244); + yy_is_jam = (yy_current_state == 248); return yy_is_jam ? 0 : yy_current_state; } @@ -2585,4 +2597,4 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 213 "QuantityParser.l" +#line 215 "QuantityParser.l" diff --git a/src/Base/QuantityParser.l b/src/Base/QuantityParser.l index bb0c995c1e..16b6d9d287 100644 --- a/src/Base/QuantityParser.l +++ b/src/Base/QuantityParser.l @@ -170,6 +170,8 @@ CGRP '\,'[0-9][0-9][0-9] "Ws" yylval = Quantity::WattSecond; return UNIT; // W*s = Joule "kWh" yylval = Quantity::KiloWattHour; return UNIT; // 1 kWh = 3.6e6 J "eV" yylval = Quantity::ElectronVolt; return UNIT; // 1 eV = 1.602176634e-19 J +"keV" yylval = Quantity::KiloElectronVolt; return UNIT; +"MeV" yylval = Quantity::MegaElectronVolt; return UNIT; "cal" yylval = Quantity::Calorie; return UNIT; // 1 cal = 4.1868 J "kcal" yylval = Quantity::KiloCalorie; return UNIT; diff --git a/src/Base/UnitsSchemaInternal.cpp b/src/Base/UnitsSchemaInternal.cpp index 0953ea2e56..c1884fb728 100644 --- a/src/Base/UnitsSchemaInternal.cpp +++ b/src/Base/UnitsSchemaInternal.cpp @@ -264,6 +264,14 @@ QString UnitsSchemaInternal::schemaTranslate(const Quantity &quant, double &fact unitString = QString::fromLatin1("eV"); factor = 1.602176634e-13; } + else if (UnitValue < 1.602176634e-7) { + unitString = QString::fromLatin1("keV"); + factor = 1.602176634e-10; + } + else if (UnitValue < 1.602176634e-4) { + unitString = QString::fromLatin1("MeV"); + factor = 1.602176634e-7; + } else if (UnitValue < 1e6) { unitString = QString::fromLatin1("mJ"); factor = 1e3; diff --git a/src/Base/UnitsSchemaMKS.cpp b/src/Base/UnitsSchemaMKS.cpp index b84cc0ee68..9fdbc7c3da 100644 --- a/src/Base/UnitsSchemaMKS.cpp +++ b/src/Base/UnitsSchemaMKS.cpp @@ -315,6 +315,14 @@ QString UnitsSchemaMKS::schemaTranslate(const Quantity &quant, double &factor, Q unitString = QString::fromLatin1("eV"); factor = 1.602176634e-13; } + else if (UnitValue < 1.602176634e-7) { + unitString = QString::fromLatin1("keV"); + factor = 1.602176634e-10; + } + else if (UnitValue < 1.602176634e-4) { + unitString = QString::fromLatin1("MeV"); + factor = 1.602176634e-7; + } else if (UnitValue < 1e6) { unitString = QString::fromLatin1("mJ"); factor = 1e3;