Some fixes in unit system

This commit is contained in:
jriegel 2013-12-08 19:48:02 +01:00
parent b6025019df
commit cfa7045408
10 changed files with 275 additions and 203 deletions

View File

@ -136,6 +136,7 @@ FreeCAD.EndingAdd("FreeCAD document (*.FCStd)","FreeCAD")
App.GuiUp = 0
# fill up unit definitions
App.Units.NanoMetre = App.Units.Quantity('nm')
App.Units.MicroMetre = App.Units.Quantity('ym')
App.Units.MilliMetre = App.Units.Quantity('mm')
@ -170,9 +171,9 @@ App.Units.Mole = App.Units.Quantity('mol')
App.Units.Candela = App.Units.Quantity('cd')
App.Units.Inch = App.Units.Quantity('in')
App.Units.Foot = App.Units.Quantity('fo')
App.Units.Thou = App.Units.Quantity('th')
App.Units.Yard = App.Units.Quantity('yr')
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.Pound = App.Units.Quantity('lb')
@ -195,7 +196,7 @@ App.Units.PSI = App.Units.Quantity('psi')
App.Units.Watt = App.Units.Quantity('W')
App.Units.VoltAmpere = App.Units.Quantity('VA')
App.Units.Joul = App.Units.Quantity('J')
App.Units.Joule = App.Units.Quantity('J')
App.Units.NewtonMeter = App.Units.Quantity('Nm')
App.Units.VoltAmpereSecond = App.Units.Quantity('VAs')
App.Units.WattSecond = App.Units.Quantity('Ws')

View File

@ -1,2 +1,2 @@
flex -oQuantityLexer.c QuantityParser.l
bison -oQuantityParser.c QuantityParser.y
flex -oQuantityLexer.c < QuantityParser.l
bison -oQuantityParser.c QuantityParser.y

View File

@ -210,6 +210,8 @@ Quantity Quantity::Ounce (0.0283495231 ,Unit(0,1));
Quantity Quantity::Stone (6.35029318 ,Unit(0,1));
Quantity Quantity::Hundredweights (50.80234544 ,Unit(0,1));
Quantity Quantity::PoundForce (224.81 ,Unit(1,1,-2)); // Newton are ~= 0.22481 lbF
Quantity Quantity::Newton (1000.0 ,Unit(1,1,-2)); // Newton (kg*m/s^2)
Quantity Quantity::KiloNewton (1e+6 ,Unit(1,1,-2));
Quantity Quantity::MegaNewton (1e+9 ,Unit(1,1,-2));
@ -220,13 +222,17 @@ 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::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)
Quantity Quantity::PSI (0.145038 ,Unit(-1,1,-2)); // pounds/in^2
Quantity Quantity::KSI (145.038 ,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::VoltAmpere (1e+6 ,Unit(2,1,-3)); // VoltAmpere (kg*m^2/s^3)
Quantity Quantity::Joul (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::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)

View File

@ -145,6 +145,8 @@ public:
static Quantity Hundredweights;
static Quantity Mile;
static Quantity PoundForce;
static Quantity Newton;
static Quantity KiloNewton;
static Quantity MegaNewton;
@ -155,13 +157,17 @@ public:
static Quantity MegaPascal;
static Quantity GigaPascal;
static Quantity Torr;
static Quantity mTorr;
static Quantity yTorr;
static Quantity PSI;
static Quantity KSI;
static Quantity Watt;
static Quantity VoltAmpere;
static Quantity Joul;
static Quantity Joule;
static Quantity NewtonMeter;
static Quantity VoltAmpereSecond;
static Quantity WattSecond;

View File

@ -361,8 +361,8 @@ static void yy_fatal_error (yyconst char msg[] );
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 83
#define YY_END_OF_BUFFER 84
#define YY_NUM_RULES 90
#define YY_END_OF_BUFFER 91
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -370,23 +370,25 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[136] =
static yyconst flex_int16_t yy_accept[156] =
{ 0,
0, 0, 0, 0, 84, 83, 4, 5, 33, 35,
6, 64, 23, 83, 83, 54, 27, 83, 43, 83,
83, 52, 1, 83, 83, 83, 66, 83, 17, 22,
83, 83, 14, 12, 83, 83, 83, 83, 20, 19,
83, 3, 2, 5, 63, 64, 57, 0, 26, 45,
0, 55, 47, 53, 58, 0, 0, 0, 0, 31,
10, 0, 0, 0, 11, 0, 34, 0, 32, 25,
44, 0, 18, 13, 39, 0, 24, 28, 46, 16,
38, 9, 0, 7, 40, 65, 0, 0, 0, 0,
0, 41, 0, 36, 29, 15, 8, 37, 63, 0,
0, 0, 0, 0, 91, 90, 4, 5, 33, 35,
6, 70, 71, 23, 90, 90, 61, 27, 90, 46,
90, 90, 90, 59, 1, 90, 90, 90, 73, 90,
17, 22, 90, 90, 14, 12, 90, 90, 90, 90,
20, 19, 90, 3, 2, 5, 70, 0, 70, 71,
64, 0, 26, 48, 0, 62, 50, 0, 60, 65,
0, 0, 0, 0, 31, 10, 0, 0, 0, 11,
0, 34, 0, 32, 25, 47, 0, 18, 13, 0,
40, 0, 24, 28, 49, 0, 16, 39, 9, 0,
7, 42, 72, 0, 0, 0, 0, 0, 43, 0,
50, 49, 56, 73, 0, 0, 0, 71, 42, 59,
72, 61, 48, 75, 21, 74, 30, 77, 51, 60,
78, 0, 80, 0, 62, 67, 68, 69, 0, 79,
82, 81, 70, 76, 0
0, 29, 0, 38, 15, 8, 0, 69, 53, 52,
0, 63, 80, 0, 0, 0, 78, 44, 66, 79,
68, 51, 58, 45, 41, 82, 0, 37, 21, 81,
30, 84, 57, 67, 85, 0, 87, 0, 0, 54,
74, 75, 76, 0, 0, 86, 89, 88, 36, 0,
77, 83, 55, 56, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -399,12 +401,12 @@ static yyconst flex_int32_t yy_ec[256] =
12, 12, 12, 12, 12, 12, 12, 1, 1, 1,
6, 1, 1, 1, 13, 1, 14, 1, 15, 1,
16, 1, 1, 17, 18, 1, 19, 20, 1, 21,
1, 1, 1, 1, 1, 22, 23, 1, 1, 1,
24, 1, 25, 6, 1, 1, 26, 27, 28, 29,
1, 1, 1, 22, 1, 23, 24, 1, 1, 1,
25, 1, 26, 6, 1, 1, 27, 28, 29, 30,
30, 31, 32, 33, 34, 1, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 1, 1, 45, 46,
47, 48, 1, 1, 1, 1, 1, 1, 1, 1,
31, 32, 33, 34, 35, 1, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 1, 47, 48,
49, 50, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -421,109 +423,119 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[49] =
static yyconst flex_int32_t yy_meta[51] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
} ;
static yyconst flex_int16_t yy_base[137] =
static yyconst flex_int16_t yy_base[157] =
{ 0,
0, 0, 46, 47, 177, 178, 178, 173, 178, 178,
178, 47, 178, 153, 153, 178, 178, 40, 136, 146,
158, 127, 178, 35, 36, 37, 123, 129, 128, 178,
128, 56, 25, 67, 128, 116, 52, 137, 48, 57,
66, 178, 178, 159, 100, 109, 178, 135, 178, 178,
134, 178, 178, 116, 178, 115, 118, 122, 129, 178,
178, 111, 109, 120, 178, 111, 178, 112, 178, 178,
178, 123, 178, 178, 178, 116, 178, 178, 178, 178,
109, 178, 71, 178, 178, 178, 101, 111, 115, 89,
84, 178, 78, 178, 178, 178, 178, 178, 113, 122,
0, 0, 48, 49, 209, 210, 210, 205, 45, 210,
210, 52, 61, 210, 184, 185, 210, 210, 64, 167,
177, 163, 189, 157, 210, 50, 50, 28, 152, 154,
158, 210, 158, 78, 53, 110, 158, 145, 52, 167,
65, 55, 87, 210, 210, 190, 103, 126, 142, 151,
210, 165, 210, 210, 164, 210, 210, 147, 145, 210,
144, 147, 151, 158, 210, 210, 140, 138, 149, 210,
140, 210, 141, 210, 210, 210, 152, 210, 210, 143,
70, 144, 210, 210, 210, 136, 210, 64, 210, 89,
210, 210, 210, 128, 139, 142, 132, 127, 210, 130,
178, 178, 178, 178, 71, 67, 64, 178, 178, 178,
178, 178, 178, 87, 178, 178, 178, 178, 178, 178,
63, 50, 37, 126, 130, 178, 178, 57, 57, 178,
178, 178, 178, 178, 178, 53
128, 210, 118, 210, 210, 210, 130, 155, 210, 210,
113, 210, 210, 105, 108, 107, 210, 210, 210, 210,
210, 210, 210, 210, 210, 134, 88, 210, 210, 210,
210, 210, 210, 210, 95, 82, 90, 75, 63, 210,
210, 210, 93, 77, 25, 210, 210, 210, 210, 15,
210, 210, 210, 210, 210, 52
} ;
static yyconst flex_int16_t yy_def[137] =
static yyconst flex_int16_t yy_def[157] =
{ 0,
135, 1, 136, 136, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
155, 1, 156, 156, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 0, 135
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 0, 155
} ;
static yyconst flex_int16_t yy_nxt[227] =
static yyconst flex_int16_t yy_nxt[261] =
{ 0,
6, 7, 8, 9, 10, 11, 11, 6, 12, 12,
12, 12, 13, 14, 6, 15, 16, 17, 18, 19,
20, 21, 22, 23, 6, 24, 6, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
6, 38, 39, 40, 6, 6, 41, 6, 6, 6,
45, 75, 49, 42, 45, 46, 46, 46, 46, 50,
51, 56, 57, 76, 60, 134, 64, 133, 70, 132,
43, 43, 61, 65, 62, 71, 72, 58, 59, 77,
63, 90, 93, 95, 78, 86, 79, 73, 91, 94,
87, 92, 74, 131, 88, 130, 129, 96, 80, 116,
6, 7, 8, 9, 10, 11, 11, 12, 13, 13,
13, 13, 14, 15, 6, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 6, 26, 6, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 6, 40, 41, 42, 6, 6, 6, 43, 6,
6, 6, 44, 47, 47, 47, 47, 154, 69, 48,
47, 47, 47, 47, 49, 70, 48, 153, 49, 50,
50, 50, 50, 45, 45, 48, 53, 61, 62, 65,
81, 100, 48, 54, 55, 152, 93, 66, 101, 67,
75, 94, 82, 63, 64, 95, 68, 76, 77, 97,
81, 128, 97, 82, 127, 83, 117, 98, 99, 99,
99, 99, 45, 126, 100, 123, 45, 46, 46, 46,
46, 99, 99, 99, 99, 122, 121, 100, 124, 100,
125, 125, 125, 125, 125, 125, 125, 125, 125, 125,
125, 125, 100, 120, 119, 118, 115, 114, 113, 112,
111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
101, 44, 89, 85, 84, 69, 68, 67, 66, 55,
54, 53, 52, 48, 47, 44, 135, 5, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
128, 124, 129, 151, 102, 150, 98, 125, 103, 99,
78, 47, 47, 47, 47, 79, 104, 48, 130, 105,
149, 80, 83, 148, 106, 131, 147, 84, 146, 85,
145, 86, 107, 48, 108, 108, 108, 108, 108, 108,
108, 108, 87, 144, 88, 143, 142, 89, 141, 90,
47, 47, 47, 47, 49, 140, 48, 139, 49, 50,
50, 50, 50, 108, 108, 108, 108, 138, 137, 136,
135, 134, 48, 133, 132, 127, 126, 123, 122, 121,
120, 119, 118, 117, 116, 115, 114, 113, 112, 111,
110, 109, 46, 96, 92, 91, 74, 73, 72, 71,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135
60, 59, 58, 57, 56, 52, 51, 46, 155, 5,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155
} ;
static yyconst flex_int16_t yy_chk[227] =
static yyconst flex_int16_t yy_chk[261] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 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, 33, 18, 136, 12, 12, 12, 12, 12, 18,
18, 24, 24, 33, 25, 129, 26, 128, 32, 123,
3, 4, 25, 26, 25, 32, 32, 24, 24, 34,
25, 39, 40, 41, 34, 37, 34, 32, 39, 40,
37, 39, 32, 122, 37, 121, 114, 41, 34, 83,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 4, 156, 9, 9, 9, 9, 150, 28, 9,
12, 12, 12, 12, 13, 28, 12, 145, 13, 13,
13, 13, 13, 3, 4, 9, 19, 26, 26, 27,
35, 42, 12, 19, 19, 144, 39, 27, 42, 27,
34, 39, 35, 26, 26, 39, 27, 34, 34, 41,
34, 107, 41, 34, 106, 34, 83, 41, 45, 45,
45, 45, 46, 105, 45, 93, 46, 46, 46, 46,
46, 99, 99, 99, 99, 91, 90, 99, 100, 45,
100, 100, 100, 100, 124, 124, 124, 124, 125, 125,
125, 125, 99, 89, 88, 87, 81, 76, 72, 68,
66, 64, 63, 62, 59, 58, 57, 56, 54, 51,
48, 44, 38, 36, 35, 31, 29, 28, 27, 22,
21, 20, 19, 15, 14, 8, 5, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
88, 81, 88, 143, 43, 139, 41, 81, 43, 41,
34, 47, 47, 47, 47, 34, 43, 47, 90, 43,
138, 34, 36, 137, 43, 90, 136, 36, 135, 36,
127, 36, 48, 47, 48, 48, 48, 48, 107, 107,
107, 107, 36, 126, 36, 116, 115, 36, 114, 36,
49, 49, 49, 49, 50, 111, 49, 103, 50, 50,
50, 50, 50, 108, 108, 108, 108, 101, 100, 98,
97, 96, 49, 95, 94, 86, 82, 80, 77, 73,
71, 69, 68, 67, 64, 63, 62, 61, 59, 58,
55, 52, 46, 40, 38, 37, 33, 31, 30, 29,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135, 135, 135, 135, 135,
135, 135, 135, 135, 135, 135
24, 23, 22, 21, 20, 16, 15, 8, 5, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
155, 155, 155, 155, 155, 155, 155, 155, 155, 155
} ;
static yy_state_type yy_last_accepting_state;
@ -554,7 +566,7 @@ char *yytext;
/* the manual says "somewhat more optimized" */
/* no support for include files is planned */
#line 558 "QuantityLexer.c"
#line 570 "QuantityLexer.c"
#define INITIAL 0
#define C_COMMENT 1
@ -738,7 +750,7 @@ YY_DECL
#line 28 "QuantityParser.l"
#line 742 "QuantityLexer.c"
#line 754 "QuantityLexer.c"
if ( !(yy_init) )
{
@ -791,13 +803,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 >= 136 )
if ( yy_current_state >= 156 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_current_state != 135 );
while ( yy_current_state != 155 );
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
@ -996,244 +1008,279 @@ yylval = Quantity::Foot; return UNIT; // foot
case 36:
YY_RULE_SETUP
#line 77 "QuantityParser.l"
yylval = Quantity::Thou; return UNIT; // thou
yylval = Quantity::Thou; return UNIT; // thou (in/1000)
YY_BREAK
case 37:
YY_RULE_SETUP
#line 78 "QuantityParser.l"
yylval = Quantity::Yard; return UNIT; // yard
yylval = Quantity::Thou; return UNIT; // mil (the thou in US)
YY_BREAK
case 38:
YY_RULE_SETUP
#line 79 "QuantityParser.l"
yylval = Quantity::Mile; return UNIT; // mile
yylval = Quantity::Yard; return UNIT; // yard
YY_BREAK
case 39:
YY_RULE_SETUP
#line 83 "QuantityParser.l"
yylval = Quantity::Pound; return UNIT; // pound
#line 80 "QuantityParser.l"
yylval = Quantity::Mile; return UNIT; // mile
YY_BREAK
case 40:
YY_RULE_SETUP
#line 84 "QuantityParser.l"
yylval = Quantity::Ounce; return UNIT; // ounce
yylval = Quantity::Pound; return UNIT; // pound
YY_BREAK
case 41:
YY_RULE_SETUP
#line 85 "QuantityParser.l"
yylval = Quantity::Stone; return UNIT; // Stone
yylval = Quantity::Pound; return UNIT; // pound
YY_BREAK
case 42:
YY_RULE_SETUP
#line 86 "QuantityParser.l"
yylval = Quantity::Hundredweights; return UNIT; // hundredweights
yylval = Quantity::Ounce; return UNIT; // ounce
YY_BREAK
case 43:
YY_RULE_SETUP
#line 88 "QuantityParser.l"
yylval = Quantity::Newton; return UNIT; // Newton (kg*m/s^2)
#line 87 "QuantityParser.l"
yylval = Quantity::Stone; return UNIT; // Stone
YY_BREAK
case 44:
YY_RULE_SETUP
#line 89 "QuantityParser.l"
yylval = Quantity::KiloNewton; return UNIT; // Newton
#line 88 "QuantityParser.l"
yylval = Quantity::Hundredweights; return UNIT; // hundredweights
YY_BREAK
case 45:
YY_RULE_SETUP
#line 90 "QuantityParser.l"
yylval = Quantity::MegaNewton; return UNIT; // Newton
yylval = Quantity::PoundForce; return UNIT; // pound
YY_BREAK
case 46:
YY_RULE_SETUP
#line 91 "QuantityParser.l"
yylval = Quantity::MilliNewton; return UNIT; // Newton
#line 92 "QuantityParser.l"
yylval = Quantity::Newton; return UNIT; // Newton (kg*m/s^2)
YY_BREAK
case 47:
YY_RULE_SETUP
#line 93 "QuantityParser.l"
yylval = Quantity::Pascal; return UNIT; // Pascal (kg/m*s^2 or N/m^2)
yylval = Quantity::KiloNewton; return UNIT; // Newton
YY_BREAK
case 48:
YY_RULE_SETUP
#line 94 "QuantityParser.l"
yylval = Quantity::KiloPascal; return UNIT; // Pascal
yylval = Quantity::MegaNewton; return UNIT; // Newton
YY_BREAK
case 49:
YY_RULE_SETUP
#line 95 "QuantityParser.l"
yylval = Quantity::MegaPascal; return UNIT; // Pascal
yylval = Quantity::MilliNewton; return UNIT; // Newton
YY_BREAK
case 50:
YY_RULE_SETUP
#line 96 "QuantityParser.l"
yylval = Quantity::GigaPascal; return UNIT; // Pascal
#line 97 "QuantityParser.l"
yylval = Quantity::Pascal; return UNIT; // Pascal (kg/m*s^2 or N/m^2)
YY_BREAK
case 51:
YY_RULE_SETUP
#line 98 "QuantityParser.l"
yylval = Quantity::PSI; return UNIT; // pounds/in^2
yylval = Quantity::KiloPascal; return UNIT; // Pascal
YY_BREAK
case 52:
YY_RULE_SETUP
#line 100 "QuantityParser.l"
yylval = Quantity::Watt; return UNIT; // Watt (kg*m^2/s^3)
#line 99 "QuantityParser.l"
yylval = Quantity::MegaPascal; return UNIT; // Pascal
YY_BREAK
case 53:
YY_RULE_SETUP
#line 101 "QuantityParser.l"
yylval = Quantity::VoltAmpere; return UNIT; // VoltAmpere (kg*m^2/s^3)
#line 100 "QuantityParser.l"
yylval = Quantity::GigaPascal; return UNIT; // Pascal
YY_BREAK
case 54:
YY_RULE_SETUP
#line 103 "QuantityParser.l"
yylval = Quantity::Joul; return UNIT; // Joule (kg*m^2/s^2)
#line 102 "QuantityParser.l"
yylval = Quantity::Torr; return UNIT; // portion of Pascal ( 101325/760 )
YY_BREAK
case 55:
YY_RULE_SETUP
#line 104 "QuantityParser.l"
yylval = Quantity::NewtonMeter; return UNIT; // Joule (kg*m^2/s^2)
#line 103 "QuantityParser.l"
yylval = Quantity::mTorr; return UNIT; //
YY_BREAK
case 56:
YY_RULE_SETUP
#line 105 "QuantityParser.l"
yylval = Quantity::VoltAmpereSecond; return UNIT; // Joule (kg*m^2/s^2)
#line 104 "QuantityParser.l"
yylval = Quantity::yTorr; return UNIT; //
YY_BREAK
case 57:
YY_RULE_SETUP
#line 106 "QuantityParser.l"
yylval = Quantity::WattSecond; return UNIT; // Joule (kg*m^2/s^2)
yylval = Quantity::PSI; return UNIT; // pounds/in^2
YY_BREAK
case 58:
YY_RULE_SETUP
#line 107 "QuantityParser.l"
yylval = Quantity::WattSecond; return UNIT; // Joule (kg*m^2/s^2)
yylval = Quantity::KSI; return UNIT; // 1000 x pounds/in^2
YY_BREAK
case 59:
YY_RULE_SETUP
#line 109 "QuantityParser.l"
yylval = Quantity::Degree; return UNIT; // degree (internal standard angle)
yylval = Quantity::Watt; return UNIT; // Watt (kg*m^2/s^3)
YY_BREAK
case 60:
YY_RULE_SETUP
#line 110 "QuantityParser.l"
yylval = Quantity::Radian; return UNIT; // radian
yylval = Quantity::VoltAmpere; return UNIT; // VoltAmpere (kg*m^2/s^3)
YY_BREAK
case 61:
YY_RULE_SETUP
#line 111 "QuantityParser.l"
yylval = Quantity::Gon; return UNIT; // gon
#line 112 "QuantityParser.l"
yylval = Quantity::Joule; return UNIT; // Joule (kg*m^2/s^2)
YY_BREAK
case 62:
YY_RULE_SETUP
#line 113 "QuantityParser.l"
{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
yylval = Quantity::NewtonMeter; return UNIT; // N*m = Joule
YY_BREAK
case 63:
YY_RULE_SETUP
#line 114 "QuantityParser.l"
{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
yylval = Quantity::VoltAmpereSecond; return UNIT; // V*A*s = Joule
YY_BREAK
case 64:
YY_RULE_SETUP
#line 115 "QuantityParser.l"
{yylval = atof( yytext ); return NUM;}
yylval = Quantity::WattSecond; return UNIT; //
YY_BREAK
case 65:
YY_RULE_SETUP
#line 117 "QuantityParser.l"
{yylval = M_PI ; return NUM;} // constant pi
#line 116 "QuantityParser.l"
yylval = Quantity::WattSecond; return UNIT; // W*s = Joule
YY_BREAK
case 66:
YY_RULE_SETUP
#line 118 "QuantityParser.l"
{yylval = M_E ; return NUM;} // constant e
yylval = Quantity::Degree; return UNIT; // degree (internal standard angle)
YY_BREAK
case 67:
YY_RULE_SETUP
#line 120 "QuantityParser.l"
return ACOS;
#line 119 "QuantityParser.l"
yylval = Quantity::Radian; return UNIT; // radian
YY_BREAK
case 68:
YY_RULE_SETUP
#line 121 "QuantityParser.l"
return ASIN;
#line 120 "QuantityParser.l"
yylval = Quantity::Gon; return UNIT; // gon
YY_BREAK
case 69:
YY_RULE_SETUP
#line 122 "QuantityParser.l"
return ATAN;
{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
YY_BREAK
case 70:
YY_RULE_SETUP
#line 123 "QuantityParser.l"
return ATAN2;
{for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
YY_BREAK
case 71:
YY_RULE_SETUP
#line 124 "QuantityParser.l"
return COS;
{yylval = atof( yytext ); return NUM;}
YY_BREAK
case 72:
YY_RULE_SETUP
#line 125 "QuantityParser.l"
return EXP;
#line 126 "QuantityParser.l"
{yylval = M_PI ; return NUM;} // constant pi
YY_BREAK
case 73:
YY_RULE_SETUP
#line 126 "QuantityParser.l"
return ABS;
#line 127 "QuantityParser.l"
{yylval = M_E ; return NUM;} // constant e
YY_BREAK
case 74:
YY_RULE_SETUP
#line 127 "QuantityParser.l"
return MOD;
#line 129 "QuantityParser.l"
return ACOS;
YY_BREAK
case 75:
YY_RULE_SETUP
#line 128 "QuantityParser.l"
return LOG;
#line 130 "QuantityParser.l"
return ASIN;
YY_BREAK
case 76:
YY_RULE_SETUP
#line 129 "QuantityParser.l"
return LOG10;
#line 131 "QuantityParser.l"
return ATAN;
YY_BREAK
case 77:
YY_RULE_SETUP
#line 130 "QuantityParser.l"
return POW;
#line 132 "QuantityParser.l"
return ATAN2;
YY_BREAK
case 78:
YY_RULE_SETUP
#line 131 "QuantityParser.l"
return SIN;
#line 133 "QuantityParser.l"
return COS;
YY_BREAK
case 79:
YY_RULE_SETUP
#line 132 "QuantityParser.l"
return SINH;
#line 134 "QuantityParser.l"
return EXP;
YY_BREAK
case 80:
YY_RULE_SETUP
#line 133 "QuantityParser.l"
return TAN;
#line 135 "QuantityParser.l"
return ABS;
YY_BREAK
case 81:
YY_RULE_SETUP
#line 134 "QuantityParser.l"
return TANH;
#line 136 "QuantityParser.l"
return MOD;
YY_BREAK
case 82:
YY_RULE_SETUP
#line 135 "QuantityParser.l"
return SQRT;
#line 137 "QuantityParser.l"
return LOG;
YY_BREAK
case 83:
YY_RULE_SETUP
#line 137 "QuantityParser.l"
#line 138 "QuantityParser.l"
return LOG10;
YY_BREAK
case 84:
YY_RULE_SETUP
#line 139 "QuantityParser.l"
return POW;
YY_BREAK
case 85:
YY_RULE_SETUP
#line 140 "QuantityParser.l"
return SIN;
YY_BREAK
case 86:
YY_RULE_SETUP
#line 141 "QuantityParser.l"
return SINH;
YY_BREAK
case 87:
YY_RULE_SETUP
#line 142 "QuantityParser.l"
return TAN;
YY_BREAK
case 88:
YY_RULE_SETUP
#line 143 "QuantityParser.l"
return TANH;
YY_BREAK
case 89:
YY_RULE_SETUP
#line 144 "QuantityParser.l"
return SQRT;
YY_BREAK
case 90:
YY_RULE_SETUP
#line 146 "QuantityParser.l"
ECHO;
YY_BREAK
#line 1237 "QuantityLexer.c"
#line 1284 "QuantityLexer.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(C_COMMENT):
yyterminate();
@ -1527,7 +1574,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 >= 136 )
if ( yy_current_state >= 156 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1555,11 +1602,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 >= 136 )
if ( yy_current_state >= 156 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 135);
yy_is_jam = (yy_current_state == 155);
return yy_is_jam ? 0 : yy_current_state;
}
@ -2192,4 +2239,4 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 137 "QuantityParser.l"
#line 146 "QuantityParser.l"

View File

@ -72,7 +72,7 @@ ID [a-z][a-z0-9]*
"in" yylval = Quantity::Inch; return UNIT; // inch
"\"" yylval = Quantity::Inch; return UNIT; // inch
"fo" yylval = Quantity::Foot; return UNIT; // foot
"ft" yylval = Quantity::Foot; return UNIT; // foot
"'" yylval = Quantity::Foot; return UNIT; // foot
"thou" yylval = Quantity::Thou; return UNIT; // thou (in/1000)
"mil" yylval = Quantity::Thou; return UNIT; // mil (the thou in US)
@ -82,10 +82,13 @@ ID [a-z][a-z0-9]*
"lb" yylval = Quantity::Pound; return UNIT; // pound
"lbm" yylval = Quantity::Pound; return UNIT; // pound
"oz" yylval = Quantity::Ounce; return UNIT; // ounce
"st" yylval = Quantity::Stone; return UNIT; // Stone
"cwt" yylval = Quantity::Hundredweights; return UNIT; // hundredweights
"lbf" yylval = Quantity::PoundForce; return UNIT; // pound
"N" yylval = Quantity::Newton; return UNIT; // Newton (kg*m/s^2)
"kN" yylval = Quantity::KiloNewton; return UNIT; // Newton
"MN" yylval = Quantity::MegaNewton; return UNIT; // Newton
@ -95,6 +98,10 @@ ID [a-z][a-z0-9]*
"kPa" yylval = Quantity::KiloPascal; return UNIT; // Pascal
"MPa" yylval = Quantity::MegaPascal; return UNIT; // Pascal
"GPa" yylval = Quantity::GigaPascal; return UNIT; // Pascal
"Torr" yylval = Quantity::Torr; return UNIT; // portion of Pascal ( 101325/760 )
"mTorr" yylval = Quantity::mTorr; return UNIT; //
"yTorr" yylval = Quantity::yTorr; return UNIT; //
"psi" yylval = Quantity::PSI; return UNIT; // pounds/in^2
"ksi" yylval = Quantity::KSI; return UNIT; // 1000 x pounds/in^2
@ -102,18 +109,18 @@ ID [a-z][a-z0-9]*
"W" yylval = Quantity::Watt; return UNIT; // Watt (kg*m^2/s^3)
"VA" yylval = Quantity::VoltAmpere; return UNIT; // VoltAmpere (kg*m^2/s^3)
"J" yylval = Quantity::Joul; return UNIT; // Joule (kg*m^2/s^2)
"Nm" yylval = Quantity::NewtonMeter; return UNIT; // Joule (kg*m^2/s^2)
"VAs" yylval = Quantity::VoltAmpereSecond; return UNIT; // Joule (kg*m^2/s^2)
"CV" yylval = Quantity::WattSecond; return UNIT; // Joule (kg*m^2/s^2)
"Ws" yylval = Quantity::WattSecond; return UNIT; // Joule (kg*m^2/s^2)
"J" yylval = Quantity::Joule; return UNIT; // Joule (kg*m^2/s^2)
"Nm" yylval = Quantity::NewtonMeter; return UNIT; // N*m = Joule
"VAs" yylval = Quantity::VoltAmpereSecond; return UNIT; // V*A*s = Joule
"CV" yylval = Quantity::WattSecond; return UNIT; //
"Ws" yylval = Quantity::WattSecond; return UNIT; // W*s = Joule
"deg" yylval = Quantity::Degree; return UNIT; // degree (internal standard angle)
"rad" yylval = Quantity::Radian; return UNIT; // radian
"gon" yylval = Quantity::Gon; return UNIT; // gon
{DIGIT}+["."","]{DIGIT}*[eE][-+]?[0-9]+ {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
{DIGIT}+["."","]{DIGIT}* {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
{DIGIT}*["."","]{DIGIT}*[eE][-+]?[0-9]+ {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
{DIGIT}*["."","]{DIGIT}* {for(char* c=yytext;*c!='\0';c++)if(*c==',')*c='.'; yylval = atof( yytext ); return NUM;}
{DIGIT}+ {yylval = atof( yytext ); return NUM;}
"pi" {yylval = M_PI ; return NUM;} // constant pi

View File

@ -64,8 +64,13 @@ int QuantityPy::PyInit(PyObject* args, PyObject* kwd)
PyErr_Clear(); // set by PyArg_ParseTuple()
const char* string;
if (PyArg_ParseTuple(args,"s", &string)) {
*self = Quantity::parse(string);
try {
*self = Quantity::parse(string);
}catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return-1;
}
return 0;
}

View File

@ -60,7 +60,7 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
// for imperial user/programmer mind; UnitValue is in internal system, that means
// mm/kg/s. And all combined units have to be calculated from there!
// now do special treatment on all cases seams nececarry:
// now do special treatment on all cases seems necessary:
if(unit == Unit::Length){ // Length handling ============================
if(UnitValue < 0.00000254){// smaller then 0.001 thou -> inch and scientific notation
unitString = QString::fromLatin1("in");
@ -75,7 +75,7 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
unitString = QString::fromLatin1("ft");
factor = 304.8;
}else if(UnitValue < 1609344.0){
unitString = QString::fromLatin1("yr");
unitString = QString::fromLatin1("yd");
factor = 914.4;
}else if(UnitValue < 1609344000.0 ){
unitString = QString::fromLatin1("mi");
@ -93,7 +93,7 @@ QString UnitsSchemaImperial1::schemaTranslate(Base::Quantity quant,double &facto
// TODO Cascade for the Volume
// default action for all cases without special treatment:
unitString = QString::fromLatin1("in^3");
factor = 16387.1;
factor = 16387.064;
}else if (unit == Unit::Mass){
// TODO Cascade for the wights
// default action for all cases without special treatment:

View File

@ -58,7 +58,7 @@ QString UnitsSchemaInternal::schemaTranslate(Base::Quantity quant,double &factor
factor = 1000.0;
}else if(UnitValue < 100000000000.0 ){
unitString = QString::fromLatin1("km");
factor = 10000000.0;
factor = 1000000.0;
}else{ // bigger then 1000 km -> scientific notation
unitString = QString::fromLatin1("mm");
factor = 1.0;

View File

@ -58,7 +58,7 @@ QString UnitsSchemaMKS::schemaTranslate(Base::Quantity quant,double &factor,QStr
factor = 1000.0;
}else if(UnitValue < 100000000000.0 ){
unitString = QString::fromLatin1("km");
factor = 10000000.0;
factor = 1000000.0;
}else{ // bigger then 1000 km -> scientific notation
unitString = QString::fromLatin1("mm");
factor = 1.0;