diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 0954d3b1b..e00e500ac 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -813,7 +813,7 @@ public: first = false; } - virtual Quantity getQuantity() const { return n; } + virtual Quantity getQuantity() const { return Quantity(n); } private: unsigned int n; @@ -886,7 +886,7 @@ Expression * FunctionExpression::evalAggregate() const if ((qp = freecad_dynamic_cast(p)) != 0) c->collect(qp->getQuantityValue()); else if ((fp = freecad_dynamic_cast(p)) != 0) - c->collect(fp->getValue()); + c->collect(Quantity(fp->getValue())); else throw Exception("Invalid property type for aggregate"); } while (range.next()); @@ -1358,27 +1358,27 @@ Expression * VariableExpression::eval() const else if (value.type() == typeid(double)) { double dvalue = boost::any_cast(value); - return new NumberExpression(owner, dvalue); + return new NumberExpression(owner, Quantity(dvalue)); } else if (value.type() == typeid(float)) { double fvalue = boost::any_cast(value); - return new NumberExpression(owner, fvalue); + return new NumberExpression(owner, Quantity(fvalue)); } else if (value.type() == typeid(int)) { int ivalue = boost::any_cast(value); - return new NumberExpression(owner, ivalue); + return new NumberExpression(owner, Quantity(ivalue)); } else if (value.type() == typeid(long)) { long lvalue = boost::any_cast(value); - return new NumberExpression(owner, lvalue); + return new NumberExpression(owner, Quantity(lvalue)); } else if (value.type() == typeid(bool)) { double bvalue = boost::any_cast(value) ? 1.0 : 0.0; - return new NumberExpression(owner, bvalue); + return new NumberExpression(owner, Quantity(bvalue)); } else if (value.type() == typeid(std::string)) { std::string svalue = boost::any_cast(value); @@ -1619,7 +1619,7 @@ int ConstantExpression::priority() const TYPESYSTEM_SOURCE_ABSTRACT(App::BooleanExpression, App::NumberExpression); BooleanExpression::BooleanExpression(const DocumentObject *_owner, bool _value) - : NumberExpression(_owner, _value ? 1.0 : 0.0) + : NumberExpression(_owner, Quantity(_value ? 1.0 : 0.0)) { } diff --git a/src/App/ExpressionParser.tab.c b/src/App/ExpressionParser.tab.c index c679081f0..feda2b2ad 100644 --- a/src/App/ExpressionParser.tab.c +++ b/src/App/ExpressionParser.tab.c @@ -1378,13 +1378,13 @@ yyreduce: case 8: #line 74 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::NEG, new NumberExpression(DocumentObject, -1)); } + { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1))); } #line 1383 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; case 9: #line 75 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::POS, new NumberExpression(DocumentObject, 1)); } + { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[0].expr), OperatorExpression::POS, new NumberExpression(DocumentObject, Quantity(1))); } #line 1389 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; @@ -1444,25 +1444,25 @@ yyreduce: case 19: #line 87 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new NumberExpression(DocumentObject, (yyvsp[0].fvalue)); } + { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((yyvsp[0].fvalue))); } #line 1449 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; case 20: #line 88 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new NumberExpression(DocumentObject, (yyvsp[0].fvalue)); } + { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((yyvsp[0].fvalue))); } #line 1455 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; case 21: #line 89 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new NumberExpression(DocumentObject, (double)(yyvsp[0].ivalue)); } + { (yyval.expr) = new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue))); } #line 1461 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; case 22: #line 90 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new ConstantExpression(DocumentObject, (yyvsp[0].constant).name, (yyvsp[0].constant).fvalue); } + { (yyval.expr) = new ConstantExpression(DocumentObject, (yyvsp[0].constant).name, Quantity((yyvsp[0].constant).fvalue)); } #line 1467 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; @@ -1582,13 +1582,13 @@ yyreduce: case 42: #line 117 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::POW, new NumberExpression(DocumentObject, (double)(yyvsp[0].ivalue))); } + { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-2].expr), OperatorExpression::POW, new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue)))); } #line 1587 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; case 43: #line 118 "ExpressionParser.y" /* yacc.c:1646 */ - { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-3].expr), OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, (double)(yyvsp[0].ivalue)), OperatorExpression::NEG, new NumberExpression(DocumentObject, -1))); } + { (yyval.expr) = new OperatorExpression(DocumentObject, (yyvsp[-3].expr), OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, Quantity((double)(yyvsp[0].ivalue))), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1)))); } #line 1593 "ExpressionParser.tab.c" /* yacc.c:1646 */ break; diff --git a/src/App/ExpressionParser.y b/src/App/ExpressionParser.y index 0d4d397e6..3982753c7 100644 --- a/src/App/ExpressionParser.y +++ b/src/App/ExpressionParser.y @@ -71,8 +71,8 @@ exp: num { $$ = $1; | num unit_exp %prec NUM_AND_UNIT { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::UNIT, $2); } | STRING { $$ = new StringExpression(DocumentObject, $1); } | identifier { $$ = new VariableExpression(DocumentObject, $1); } - | MINUSSIGN exp %prec NEG { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::NEG, new NumberExpression(DocumentObject, -1)); } - | '+' exp %prec POS { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::POS, new NumberExpression(DocumentObject, 1)); } + | MINUSSIGN exp %prec NEG { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1))); } + | '+' exp %prec POS { $$ = new OperatorExpression(DocumentObject, $2, OperatorExpression::POS, new NumberExpression(DocumentObject, Quantity(1))); } | exp '+' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::ADD, $3); } | exp MINUSSIGN exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::SUB, $3); } | exp '*' exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } @@ -84,10 +84,10 @@ exp: num { $$ = $1; | cond '?' exp ':' exp { $$ = new ConditionalExpression(DocumentObject, $1, $3, $5); } ; -num: ONE { $$ = new NumberExpression(DocumentObject, $1); } - | NUM { $$ = new NumberExpression(DocumentObject, $1); } - | INTEGER { $$ = new NumberExpression(DocumentObject, (double)$1); } - | CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, $1.fvalue); } +num: ONE { $$ = new NumberExpression(DocumentObject, Quantity($1)); } + | NUM { $$ = new NumberExpression(DocumentObject, Quantity($1)); } + | INTEGER { $$ = new NumberExpression(DocumentObject, Quantity((double)$1)); } + | CONSTANT { $$ = new ConstantExpression(DocumentObject, $1.name, Quantity($1.fvalue)); } args: exp { $$.push_back($1); } | range { $$.push_back($1); } @@ -114,8 +114,8 @@ cond: exp EQ exp { $$ = new OperatorExpression(Do unit_exp: UNIT { $$ = new UnitExpression(DocumentObject, $1.scaler, $1.unitStr ); } | unit_exp '/' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::DIV, $3); } | unit_exp '*' unit_exp { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::MUL, $3); } - | unit_exp '^' integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new NumberExpression(DocumentObject, (double)$3)); } - | unit_exp '^' MINUSSIGN integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, (double)$4), OperatorExpression::NEG, new NumberExpression(DocumentObject, -1))); } + | unit_exp '^' integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new NumberExpression(DocumentObject, Quantity((double)$3))); } + | unit_exp '^' MINUSSIGN integer { $$ = new OperatorExpression(DocumentObject, $1, OperatorExpression::POW, new OperatorExpression(DocumentObject, new NumberExpression(DocumentObject, Quantity((double)$4)), OperatorExpression::NEG, new NumberExpression(DocumentObject, Quantity(-1)))); } | '(' unit_exp ')' { $$ = $2; } ; diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index e770d181b..9c75f6762 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -92,16 +92,42 @@ bool Quantity::operator >(const Quantity& that) const return (this->_Value > that._Value) ; } +bool Quantity::operator <=(const Quantity& that) const +{ + if (this->_Unit != that._Unit) + throw Base::Exception("Quantity::operator <=(): quantities need to have same unit to compare"); + + return (this->_Value <= that._Value) ; +} + +bool Quantity::operator >=(const Quantity& that) const +{ + if (this->_Unit != that._Unit) + throw Base::Exception("Quantity::operator >=(): quantities need to have same unit to compare"); + + return (this->_Value >= that._Value) ; +} + Quantity Quantity::operator *(const Quantity &p) const { return Quantity(this->_Value * p._Value,this->_Unit * p._Unit); } +Quantity Quantity::operator *(double p) const +{ + return Quantity(this->_Value * p,this->_Unit); +} + Quantity Quantity::operator /(const Quantity &p) const { return Quantity(this->_Value / p._Value,this->_Unit / p._Unit); } +Quantity Quantity::operator /(double p) const +{ + return Quantity(this->_Value / p,this->_Unit); +} + Quantity Quantity::pow(const Quantity &p) const { if (!p._Unit.isEmpty()) @@ -112,6 +138,13 @@ Quantity Quantity::pow(const Quantity &p) const ); } +Quantity Quantity::pow(double p) const +{ + return Quantity( + std::pow(this->_Value, p), this->_Unit + ); +} + Quantity Quantity::operator +(const Quantity &p) const { if (this->_Unit != p._Unit) @@ -329,7 +362,6 @@ int QuantityLexer(void); Quantity Quantity::parse(const QString &string) { - // parse from buffer QuantityParser::YY_BUFFER_STATE my_string_buffer = QuantityParser::yy_scan_string (string.toUtf8().data()); // set the global return variables diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index 97befef90..6f0a4d15e 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -74,24 +74,29 @@ public: /// default constructor Quantity(void); Quantity(const Quantity&); - Quantity(double Value, const Unit& unit=Unit()); + explicit Quantity(double Value, const Unit& unit=Unit()); /// Destruction ~Quantity () {} /** Operators. */ //@{ Quantity operator *(const Quantity &p) const; + Quantity operator *(double p) const; Quantity operator +(const Quantity &p) const; Quantity& operator +=(const Quantity &p); Quantity operator -(const Quantity &p) const; Quantity& operator -=(const Quantity &p); Quantity operator -(void) const; Quantity operator /(const Quantity &p) const; + Quantity operator /(double p) const; bool operator ==(const Quantity&) const; bool operator < (const Quantity&) const; bool operator > (const Quantity&) const; + bool operator <= (const Quantity&) const; + bool operator >= (const Quantity&) const; Quantity& operator =(const Quantity&); Quantity pow(const Quantity&)const; + Quantity pow(double)const; //@} const QuantityFormat& getFormat() const { diff --git a/src/Base/QuantityLexer.c b/src/Base/QuantityLexer.c index 298e2faf5..fe0883079 100644 --- a/src/Base/QuantityLexer.c +++ b/src/Base/QuantityLexer.c @@ -1245,32 +1245,32 @@ yylval = Quantity::Gon; return UNIT; // gon case 76: YY_RULE_SETUP #line 133 "QuantityParser.l" -{ yylval = num_change(yytext,'.',',');return NUM; } +{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } YY_BREAK case 77: YY_RULE_SETUP #line 134 "QuantityParser.l" -{ yylval = num_change(yytext,'.',',');return NUM; } +{ yylval = Quantity(num_change(yytext,'.',','));return NUM; } YY_BREAK case 78: YY_RULE_SETUP #line 135 "QuantityParser.l" -{ yylval = num_change(yytext,',','.');return NUM; } +{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } YY_BREAK case 79: YY_RULE_SETUP #line 136 "QuantityParser.l" -{ yylval = num_change(yytext,',','.');return NUM; } +{ yylval = Quantity(num_change(yytext,',','.'));return NUM; } YY_BREAK case 80: YY_RULE_SETUP #line 139 "QuantityParser.l" -{yylval = M_PI ; return NUM;} // constant pi +{yylval = Quantity(M_PI) ; return NUM;} // constant pi YY_BREAK case 81: YY_RULE_SETUP #line 140 "QuantityParser.l" -{yylval = M_E ; return NUM;} // constant e +{yylval = Quantity(M_E) ; return NUM;} // constant e YY_BREAK case 82: YY_RULE_SETUP diff --git a/src/Base/QuantityParser.c b/src/Base/QuantityParser.c index fa454a332..cc241cfec 100644 --- a/src/Base/QuantityParser.c +++ b/src/Base/QuantityParser.c @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ +/* A Bison parser, made by GNU Bison 3.0.2. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "3.0.4" +#define YYBISON_VERSION "3.0.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -93,10 +93,7 @@ # define YYERROR_VERBOSE 0 #endif -/* In a future release of Bison, this section will be replaced - by #include "QuantityParser.h". */ -#ifndef YY_YY_QUANTITYPARSER_H_INCLUDED -# define YY_YY_QUANTITYPARSER_H_INCLUDED + /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -145,11 +142,11 @@ extern YYSTYPE yylval; int yyparse (void); -#endif /* !YY_YY_QUANTITYPARSER_H_INCLUDED */ + /* Copy the second part of user declarations. */ -#line 153 "QuantityParser.c" /* yacc.c:358 */ +#line 150 "QuantityParser.c" /* yacc.c:358 */ #ifdef short # undef short @@ -1293,197 +1290,197 @@ yyreduce: case 2: #line 33 "QuantityParser.y" /* yacc.c:1646 */ { QuantResult = Quantity(DOUBLE_MIN); /* empty input */ } -#line 1297 "QuantityParser.c" /* yacc.c:1646 */ +#line 1294 "QuantityParser.c" /* yacc.c:1646 */ break; case 3: #line 34 "QuantityParser.y" /* yacc.c:1646 */ { QuantResult = (yyvsp[0]) ; } -#line 1303 "QuantityParser.c" /* yacc.c:1646 */ +#line 1300 "QuantityParser.c" /* yacc.c:1646 */ break; case 4: #line 35 "QuantityParser.y" /* yacc.c:1646 */ { QuantResult = (yyvsp[0]) ; } -#line 1309 "QuantityParser.c" /* yacc.c:1646 */ +#line 1306 "QuantityParser.c" /* yacc.c:1646 */ break; case 5: #line 36 "QuantityParser.y" /* yacc.c:1646 */ { QuantResult = (yyvsp[0]) ; } -#line 1315 "QuantityParser.c" /* yacc.c:1646 */ +#line 1312 "QuantityParser.c" /* yacc.c:1646 */ break; case 6: #line 37 "QuantityParser.y" /* yacc.c:1646 */ { QuantResult = (yyvsp[-1]) + (yyvsp[0]); } -#line 1321 "QuantityParser.c" /* yacc.c:1646 */ +#line 1318 "QuantityParser.c" /* yacc.c:1646 */ break; case 7: #line 39 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[0]); } -#line 1327 "QuantityParser.c" /* yacc.c:1646 */ +#line 1324 "QuantityParser.c" /* yacc.c:1646 */ break; case 8: #line 40 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = (yyvsp[-2]).getValue() + (yyvsp[0]).getValue(); } -#line 1333 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity((yyvsp[-2]).getValue() + (yyvsp[0]).getValue()); } +#line 1330 "QuantityParser.c" /* yacc.c:1646 */ break; case 9: #line 41 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = (yyvsp[-2]).getValue() - (yyvsp[0]).getValue(); } -#line 1339 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity((yyvsp[-2]).getValue() - (yyvsp[0]).getValue()); } +#line 1336 "QuantityParser.c" /* yacc.c:1646 */ break; case 10: #line 42 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = (yyvsp[-2]).getValue() * (yyvsp[0]).getValue(); } -#line 1345 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity((yyvsp[-2]).getValue() * (yyvsp[0]).getValue()); } +#line 1342 "QuantityParser.c" /* yacc.c:1646 */ break; case 11: #line 43 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = (yyvsp[-2]).getValue() / (yyvsp[0]).getValue(); } -#line 1351 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity((yyvsp[-2]).getValue() / (yyvsp[0]).getValue()); } +#line 1348 "QuantityParser.c" /* yacc.c:1646 */ break; case 12: #line 44 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = -(yyvsp[0]).getValue(); } -#line 1357 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(-(yyvsp[0]).getValue()); } +#line 1354 "QuantityParser.c" /* yacc.c:1646 */ break; case 13: #line 45 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = pow ((yyvsp[-2]).getValue(), (yyvsp[0]).getValue());} -#line 1363 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(pow ((yyvsp[-2]).getValue(), (yyvsp[0]).getValue()));} +#line 1360 "QuantityParser.c" /* yacc.c:1646 */ break; case 14: #line 46 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-1]); } -#line 1369 "QuantityParser.c" /* yacc.c:1646 */ +#line 1366 "QuantityParser.c" /* yacc.c:1646 */ break; case 15: #line 47 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = acos((yyvsp[-1]).getValue()); } -#line 1375 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(acos((yyvsp[-1]).getValue())); } +#line 1372 "QuantityParser.c" /* yacc.c:1646 */ break; case 16: #line 48 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = asin((yyvsp[-1]).getValue()); } -#line 1381 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(asin((yyvsp[-1]).getValue())); } +#line 1378 "QuantityParser.c" /* yacc.c:1646 */ break; case 17: #line 49 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = atan((yyvsp[-1]).getValue()); } -#line 1387 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(atan((yyvsp[-1]).getValue())); } +#line 1384 "QuantityParser.c" /* yacc.c:1646 */ break; case 18: #line 50 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = fabs((yyvsp[-1]).getValue()); } -#line 1393 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(fabs((yyvsp[-1]).getValue())); } +#line 1390 "QuantityParser.c" /* yacc.c:1646 */ break; case 19: #line 51 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = exp((yyvsp[-1]).getValue()); } -#line 1399 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(exp((yyvsp[-1]).getValue())); } +#line 1396 "QuantityParser.c" /* yacc.c:1646 */ break; case 20: #line 52 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = log((yyvsp[-1]).getValue()); } -#line 1405 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(log((yyvsp[-1]).getValue())); } +#line 1402 "QuantityParser.c" /* yacc.c:1646 */ break; case 21: #line 53 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = log10((yyvsp[-1]).getValue()); } -#line 1411 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(log10((yyvsp[-1]).getValue())); } +#line 1408 "QuantityParser.c" /* yacc.c:1646 */ break; case 22: #line 54 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = sin((yyvsp[-1]).getValue()); } -#line 1417 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(sin((yyvsp[-1]).getValue())); } +#line 1414 "QuantityParser.c" /* yacc.c:1646 */ break; case 23: #line 55 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = sinh((yyvsp[-1]).getValue()); } -#line 1423 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(sinh((yyvsp[-1]).getValue())); } +#line 1420 "QuantityParser.c" /* yacc.c:1646 */ break; case 24: #line 56 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = tan((yyvsp[-1]).getValue()); } -#line 1429 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(tan((yyvsp[-1]).getValue())); } +#line 1426 "QuantityParser.c" /* yacc.c:1646 */ break; case 25: #line 57 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = tanh((yyvsp[-1]).getValue()); } -#line 1435 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(tanh((yyvsp[-1]).getValue())); } +#line 1432 "QuantityParser.c" /* yacc.c:1646 */ break; case 26: #line 58 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = sqrt((yyvsp[-1]).getValue()); } -#line 1441 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(sqrt((yyvsp[-1]).getValue())); } +#line 1438 "QuantityParser.c" /* yacc.c:1646 */ break; case 27: #line 59 "QuantityParser.y" /* yacc.c:1646 */ - { (yyval) = cos((yyvsp[-1]).getValue()); } -#line 1447 "QuantityParser.c" /* yacc.c:1646 */ + { (yyval) = Quantity(cos((yyvsp[-1]).getValue())); } +#line 1444 "QuantityParser.c" /* yacc.c:1646 */ break; case 28: #line 62 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[0]); } -#line 1453 "QuantityParser.c" /* yacc.c:1646 */ +#line 1450 "QuantityParser.c" /* yacc.c:1646 */ break; case 29: #line 63 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-2]) * (yyvsp[0]); } -#line 1459 "QuantityParser.c" /* yacc.c:1646 */ +#line 1456 "QuantityParser.c" /* yacc.c:1646 */ break; case 30: #line 64 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-2]) / (yyvsp[0]); } -#line 1465 "QuantityParser.c" /* yacc.c:1646 */ +#line 1462 "QuantityParser.c" /* yacc.c:1646 */ break; case 31: #line 65 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-2]).pow ((yyvsp[0])); } -#line 1471 "QuantityParser.c" /* yacc.c:1646 */ +#line 1468 "QuantityParser.c" /* yacc.c:1646 */ break; case 32: #line 66 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-1]); } -#line 1477 "QuantityParser.c" /* yacc.c:1646 */ +#line 1474 "QuantityParser.c" /* yacc.c:1646 */ break; case 33: #line 68 "QuantityParser.y" /* yacc.c:1646 */ { (yyval) = (yyvsp[-1])*(yyvsp[0]); } -#line 1483 "QuantityParser.c" /* yacc.c:1646 */ +#line 1480 "QuantityParser.c" /* yacc.c:1646 */ break; -#line 1487 "QuantityParser.c" /* yacc.c:1646 */ +#line 1484 "QuantityParser.c" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires diff --git a/src/Base/QuantityParser.l b/src/Base/QuantityParser.l index 8b47d1844..b57e1c5e6 100644 --- a/src/Base/QuantityParser.l +++ b/src/Base/QuantityParser.l @@ -130,14 +130,14 @@ CGRP '\,'[0-9][0-9][0-9] "rad" yylval = Quantity::Radian; return UNIT; // radian "gon" yylval = Quantity::Gon; return UNIT; // gon -{DIGIT}+"."?{DIGIT}*{EXPO}? { yylval = num_change(yytext,'.',',');return NUM; } -"."?{DIGIT}+{EXPO}? { yylval = num_change(yytext,'.',',');return NUM; } -{DIGIT}+","?{DIGIT}*{EXPO}? { yylval = num_change(yytext,',','.');return NUM; } -","?{DIGIT}+{EXPO}? { yylval = num_change(yytext,',','.');return NUM; } +{DIGIT}+"."?{DIGIT}*{EXPO}? { yylval = Quantity(num_change(yytext,'.',','));return NUM; } +"."?{DIGIT}+{EXPO}? { yylval = Quantity(num_change(yytext,'.',','));return NUM; } +{DIGIT}+","?{DIGIT}*{EXPO}? { yylval = Quantity(num_change(yytext,',','.'));return NUM; } +","?{DIGIT}+{EXPO}? { yylval = Quantity(num_change(yytext,',','.'));return NUM; } -"pi" {yylval = M_PI ; return NUM;} // constant pi -"e" {yylval = M_E ; return NUM;} // constant e +"pi" {yylval = Quantity(M_PI) ; return NUM;} // constant pi +"e" {yylval = Quantity(M_E) ; return NUM;} // constant e "acos" return ACOS; "asin" return ASIN; diff --git a/src/Base/QuantityParser.y b/src/Base/QuantityParser.y index b118bb265..90155dadd 100644 --- a/src/Base/QuantityParser.y +++ b/src/Base/QuantityParser.y @@ -37,26 +37,26 @@ | quantity quantity { QuantResult = $1 + $2; } ; num: NUM { $$ = $1; } - | num '+' num { $$ = $1.getValue() + $3.getValue(); } - | num MINUSSIGN num { $$ = $1.getValue() - $3.getValue(); } - | num '*' num { $$ = $1.getValue() * $3.getValue(); } - | num '/' num { $$ = $1.getValue() / $3.getValue(); } - | MINUSSIGN num %prec NEG { $$ = -$2.getValue(); } - | num '^' num { $$ = pow ($1.getValue(), $3.getValue());} + | num '+' num { $$ = Quantity($1.getValue() + $3.getValue()); } + | num MINUSSIGN num { $$ = Quantity($1.getValue() - $3.getValue()); } + | num '*' num { $$ = Quantity($1.getValue() * $3.getValue()); } + | num '/' num { $$ = Quantity($1.getValue() / $3.getValue()); } + | MINUSSIGN num %prec NEG { $$ = Quantity(-$2.getValue()); } + | num '^' num { $$ = Quantity(pow ($1.getValue(), $3.getValue()));} | '(' num ')' { $$ = $2; } - | ACOS '(' num ')' { $$ = acos($3.getValue()); } - | ASIN '(' num ')' { $$ = asin($3.getValue()); } - | ATAN '(' num ')' { $$ = atan($3.getValue()); } - | ABS '(' num ')' { $$ = fabs($3.getValue()); } - | EXP '(' num ')' { $$ = exp($3.getValue()); } - | LOG '(' num ')' { $$ = log($3.getValue()); } - | LOG10 '(' num ')' { $$ = log10($3.getValue()); } - | SIN '(' num ')' { $$ = sin($3.getValue()); } - | SINH '(' num ')' { $$ = sinh($3.getValue()); } - | TAN '(' num ')' { $$ = tan($3.getValue()); } - | TANH '(' num ')' { $$ = tanh($3.getValue()); } - | SQRT '(' num ')' { $$ = sqrt($3.getValue()); } - | COS '(' num ')' { $$ = cos($3.getValue()); } + | ACOS '(' num ')' { $$ = Quantity(acos($3.getValue())); } + | ASIN '(' num ')' { $$ = Quantity(asin($3.getValue())); } + | ATAN '(' num ')' { $$ = Quantity(atan($3.getValue())); } + | ABS '(' num ')' { $$ = Quantity(fabs($3.getValue())); } + | EXP '(' num ')' { $$ = Quantity(exp($3.getValue())); } + | LOG '(' num ')' { $$ = Quantity(log($3.getValue())); } + | LOG10 '(' num ')' { $$ = Quantity(log10($3.getValue())); } + | SIN '(' num ')' { $$ = Quantity(sin($3.getValue())); } + | SINH '(' num ')' { $$ = Quantity(sinh($3.getValue())); } + | TAN '(' num ')' { $$ = Quantity(tan($3.getValue())); } + | TANH '(' num ')' { $$ = Quantity(tanh($3.getValue())); } + | SQRT '(' num ')' { $$ = Quantity(sqrt($3.getValue())); } + | COS '(' num ')' { $$ = Quantity(cos($3.getValue())); } ; unit: UNIT { $$ = $1; } diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 4acf0243f..1eb95ea5e 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -198,7 +198,7 @@ PyObject* QuantityPy::getValueAs(PyObject *args) return 0; } - quant = getQuantityPtr()->getValueAs(quant); + quant = Quantity(getQuantityPtr()->getValueAs(quant)); return new QuantityPy(new Quantity(quant)); } diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 1c07539f5..5498560e4 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -106,7 +106,7 @@ void InputField::bind(const App::ObjectIdentifier &_path) PropertyQuantity * prop = freecad_dynamic_cast(getPath().getProperty()); if (prop) - actQuantity = prop->getValue(); + actQuantity = Base::Quantity(prop->getValue()); DocumentObject * docObj = getPath().getDocumentObject(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 309cf2542..f3c75aac8 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -1761,7 +1761,7 @@ Base::Quantity PropertyPlacementItem::getAngle() const { QVariant value = data(1, Qt::EditRole); if (!value.canConvert()) - return 0.0; + return Base::Quantity(0.0); const Base::Placement& val = value.value(); double angle; Base::Vector3d dir; diff --git a/src/Mod/Spreadsheet/App/Cell.cpp b/src/Mod/Spreadsheet/App/Cell.cpp index db7642969..9855c09f6 100644 --- a/src/Mod/Spreadsheet/App/Cell.cpp +++ b/src/Mod/Spreadsheet/App/Cell.cpp @@ -29,6 +29,7 @@ #include "Utils.h" #include #include +#include #include #include #include "Sheet.h" @@ -235,7 +236,7 @@ void Cell::setContent(const char * value) errno = 0; double float_value = strtod(value, &end); if (!*end && errno == 0) - expr = new App::NumberExpression(owner->sheet(), float_value); + expr = new App::NumberExpression(owner->sheet(), Quantity(float_value)); else { try { expr = ExpressionParser::parse(owner->sheet(), value);