Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Switching the UnitsApi to the new Quantity system
  • Loading branch information
jriegel committed Dec 3, 2013
1 parent a7e221f commit 3a3afa0
Show file tree
Hide file tree
Showing 23 changed files with 485 additions and 647 deletions.
3 changes: 0 additions & 3 deletions src/App/Application.cpp
Expand Up @@ -1133,9 +1133,6 @@ void Application::initConfig(int argc, char ** argv)

LoadParameters();

// set the default units
UnitsApi::setDefaults();

// capture python variables
SaveEnv("PYTHONPATH");
SaveEnv("PYTHONHOME");
Expand Down
7 changes: 7 additions & 0 deletions src/Base/Quantity.cpp
Expand Up @@ -59,6 +59,13 @@ Quantity::Quantity(double Value, const Unit& unit)
}


double Quantity::getValueAs(const Quantity &q)const
{
return _Value/q.getValue();
}



bool Quantity::operator ==(const Quantity& that) const
{
return (this->_Value == that._Value) && (this->_Unit == that._Unit) ;
Expand Down
9 changes: 9 additions & 0 deletions src/Base/Quantity.h
Expand Up @@ -68,10 +68,19 @@ class BaseExport Quantity

static Quantity parse(const char* buffer);

/// returns the unit of the quantity
const Unit & getUnit(void) const{return _Unit;}
/// set the unit of the quantity
void setUnit(const Unit &un){_Unit = un;}
/// get the Value of the quantity
double getValue(void) const{return _Value;}
/// set the value of the quantity
void setValue(double val){_Value = val;}
/** get the Value in a special unit given as quantity.
* One can use one of the predifeined quantity units in this class
*/
double getValueAs(const Quantity &)const;


/// true if it has a number without a unit
bool isDimensionless(void)const;
Expand Down
24 changes: 14 additions & 10 deletions src/Base/QuantityPy.xml
Expand Up @@ -40,6 +40,20 @@ Quantity(string) -- arbitrary mixture of numbers and chars defining a Quantity
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getValueAs">
<Documentation>
<UserDocu>
returns a floating point value as the provided unit

Following parameters are allowed:
getValueAs('m/s') # unit string to parse
getValueAs(2.45,1) # translatrion value and unit signatur
getValueAs(FreeCAD.Units.Pascal) # predefined standard units
getValueAs(Qantity('N/m^2')) # a quantity
getValueAs(Unit(0,1,0,0,0,0,0,0)) # a unit
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>Numeric Value of the Quantity (in internal system mm,kg,s)</UserDocu>
Expand All @@ -58,15 +72,5 @@ Quantity(string) -- arbitrary mixture of numbers and chars defining a Quantity
</Documentation>
<Parameter Name="UserString" Type="String" />
</Attribute>


<Attribute Name="NanoMeter" ReadOnly="true">
<Documentation>
<UserDocu>Definition of NanoMeter </UserDocu>
</Documentation>
<Parameter Name="NanoMeter" Type="Object" />
</Attribute>


</PythonExport>
</GenerateModel>

0 comments on commit 3a3afa0

Please sign in to comment.