Start new Unit and Quantity system

This commit is contained in:
jriegel 2013-08-11 23:03:34 +02:00
parent 1446ee0b69
commit e23febcf32
14 changed files with 4190 additions and 0 deletions

View File

@ -63,6 +63,8 @@ generate_from_xml(MatrixPy)
generate_from_xml(RotationPy)
generate_from_xml(PlacementPy)
generate_from_xml(AxisPy)
generate_from_xml(UnitPy)
generate_from_xml(QuantityPy)
if(SWIG_FOUND)
execute_process(COMMAND ${SWIG_EXECUTABLE} -python -external-runtime ${CMAKE_CURRENT_BINARY_DIR}/swigpyrun.h)
@ -136,6 +138,8 @@ SET(FreeCADBase_XML_SRCS
PlacementPy.xml
RotationPy.xml
VectorPy.xml
QuantityPy.xml
UnitPy.xml
)
SOURCE_GROUP("XML" FILES ${FreeCADBase_XML_SRCS})
@ -159,6 +163,15 @@ SET(FreeCADBase_UNITAPI_SRCS
UnitsSchemaImperial1.cpp
UnitsApi.y
UnitsApi.l
Quantity.h
Quantity.cpp
QuantityPyImp.cpp
QuantityParser.l
QuantityParser.y
Unit.h
Unit.cpp
UnitPyImp.cpp
)
SOURCE_GROUP("Units" FILES ${FreeCADBase_UNITAPI_SRCS})

2
src/Base/Parser.bat Normal file
View File

@ -0,0 +1,2 @@
C:\Tools\GnuWin32\bin\flex.exe -oQuantityLexer.c QuantityParser.l
C:\Tools\GnuWin32\bin\bison -oQuantityParser.c QuantityParser.y

156
src/Base/Quantity.cpp Normal file
View File

@ -0,0 +1,156 @@
/***************************************************************************
* Copyright (c) 2013 Juergen Riegel *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "Quantity.h"
#include "Exception.h"
using namespace Base;
Quantity::Quantity()
{
this->_Value = 0.0;
}
Quantity::Quantity(const Quantity& that)
{
*this = that ;
}
Quantity::Quantity(double Value, const Unit& unit)
{
this->_Unit = unit;
this->_Value = Value;
}
bool Quantity::operator ==(const Quantity& that) const
{
return (this->_Value == that._Value) && (this->_Unit == that._Unit) ;
}
Quantity Quantity::operator *(const Quantity &p) const
{
return Quantity(this->_Value * p._Value,this->_Unit * p._Unit);
}
Quantity Quantity::operator /(const Quantity &p) const
{
return Quantity(this->_Value / p._Value,this->_Unit / p._Unit);
}
Quantity Quantity::pow(const Quantity &p) const
{
if(!p._Unit.isEmpty())
throw Base::Exception("Quantity::pow(): exponent must not have a unit");
return Quantity(
std::pow(this->_Value, p._Value),
this->_Unit.pow((short)p._Value)
);
}
Quantity Quantity::operator +(const Quantity &p) const
{
if(this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +(): Unit missmatch in plus operation");
return Quantity(this->_Value + p._Value,this->_Unit);
}
Quantity Quantity::operator -(const Quantity &p) const
{
if(this->_Unit != p._Unit)
throw Base::Exception("Quantity::operator +(): Unit missmatch in plus operation");
return Quantity(this->_Value - p._Value,this->_Unit);
}
Quantity Quantity::operator -(void) const
{
return Quantity(-(this->_Value),this->_Unit);
}
Quantity& Quantity::operator = (const Quantity &New)
{
this->_Value = New._Value;
this->_Unit = New._Unit;
return *this;
}
// === Parser & Scanner stuff ===============================================
// include the Scanner and the Parser for the Quantitys
Quantity ScanResult;
#ifndef DOUBLE_MAX
# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/
#endif
#ifndef DOUBLE_MIN
# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/
#endif
// error func
void Quantity_yyerror(char *errorinfo)
{
throw Base::Exception(errorinfo);
}
// for VC9 (isatty and fileno not supported anymore)
//#ifdef _MSC_VER
//int isatty (int i) {return _isatty(i);}
//int fileno(FILE *stream) {return _fileno(stream);}
//#endif
namespace QuantityParser {
// show the parser the lexer method
#define yylex QuantityLexer
int QuantityLexer(void);
// Parser, defined in QuantityParser.y
#include "QuantityParser.c"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// Scanner, defined in QuantityParser.l
#include "QuantityLexer.c"
#endif // DOXYGEN_SHOULD_SKIP_THIS
}
Quantity Quantity::parse(const char* buffer)
{
// parse from buffer
QuantityParser::YY_BUFFER_STATE my_string_buffer = QuantityParser::yy_scan_string (buffer);
// set the global return variables
ScanResult = Quantity(DOUBLE_MIN);
// run the parser
QuantityParser::yyparse ();
// free the scan buffer
QuantityParser::yy_delete_buffer (my_string_buffer);
if (ScanResult == Quantity(DOUBLE_MIN))
throw Base::Exception("Unknown error in Quantity expression");
return ScanResult;
}

65
src/Base/Quantity.h Normal file
View File

@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (c) 2013 Juergen Riegel *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_Quantity_H
#define BASE_Quantity_H
#include "Unit.h"
namespace Base {
/**
* The Quantity class.
*/
class BaseExport Quantity
{
public:
/// default constructor
Quantity(void);
Quantity(const Quantity&);
Quantity(double Value, const Unit& unit=Unit());
/// Destruction
~Quantity () {};
/** Operators. */
//@{
Quantity operator *(const Quantity &p) const;
Quantity operator +(const Quantity &p) const;
Quantity operator -(const Quantity &p) const;
Quantity operator -(void) const;
Quantity operator /(const Quantity &p) const;
bool operator ==(const Quantity&) const;
Quantity& operator =(const Quantity&);
Quantity pow(const Quantity&)const;
//@}
protected:
double _Value;
Unit _Unit;
static Quantity parse(const char* buffer);
};
} // namespace Base
#endif // BASE_Quantity_H

1743
src/Base/QuantityLexer.c Normal file

File diff suppressed because it is too large Load Diff

1615
src/Base/QuantityParser.c Normal file

File diff suppressed because it is too large Load Diff

85
src/Base/QuantityParser.l Normal file
View File

@ -0,0 +1,85 @@
%{
/* Lexer for the FreeCAD Units language */
/* (c) 2013 Juergen Riegel LGPL */
/* This disables inclusion of unistd.h, which is not available under Visual C++
* on Win32. The C++ scanner uses STL streams instead. */
#define YY_NO_UNISTD_H
%}
/*** Flex Declarations and Options ***/
/* the manual says "somewhat more optimized" */
%option batch
%option never-interactive
/* no support for include files is planned */
%option noyywrap nounput
DIGIT [0-9]
ID [a-z][a-z0-9]*
%% /*** Filter language Part ***/
[ \t] ;
[\n]+ ;
[-+()=/*^] { return *yytext; }
"mm" yylval = 1.0; return UNIT; // millimeter (internal standard length)
"m" yylval = 1000.0; return UNIT; // meter
"cm" yylval = 10.0; return UNIT; // centimeter
"dm" yylval = 100.0; return UNIT; // decimeter
"km" yylval = 1000000.0; return UNIT; // kilometer
"in" yylval = 25.4; return UNIT; // inch
"\"" yylval = 25.4; return UNIT; // inch
"fo" yylval = 304.8; return UNIT; // foot
"'" yylval = 304.8; return UNIT; // foot
"th" yylval = 0.0254; return UNIT; // thou
"yr" yylval = 914.4; return UNIT; // yard
"kg" yylval = 1.0; return UNIT; // kilogram (internal standard mass)
"g" yylval = 0.001; return UNIT; // gram
"mg" yylval = 0.000001; return UNIT; // milligram
"t" yylval = 1000.0; return UNIT; // ton
"lb" yylval = 0.45359237; return UNIT; // pound
"oz" yylval = 0.45359237; return UNIT; // ounce
"st" yylval = 6.35029318; return UNIT; // Stone
"cwt" yylval = 50.80234544;return UNIT; // hundredweights
"deg" yylval = 1.0; return UNIT; // degree (internal standard angle)
"rad" yylval = 180/M_PI; return UNIT; // radian
"gon" yylval = 360.0/400.0;return UNIT; // gon
"s" yylval = 1.0; return UNIT; // second (internal standard time)
"min" yylval = 60.0; return UNIT; // minute
"h" yylval = 3600.0; return UNIT; // hour
"A" yylval = 1.0; return UNIT; // Ampere (internal standard electric current)
"K" yylval = 1.0; return UNIT; // Kelvin (internal standard thermodynamic temperature)
"cd" yylval = 1.0; return UNIT; // Candela (internal standard luminous intensity)
"mol" yylval = 1.0; return UNIT; // Mole (internal standard amount of substance)
"yl" yylval = 1.0; return UNIT; // microliter mm^3(derived standard volume)
"ml" yylval = 1000.0; return UNIT; // milliliter cm^3
"l" yylval = 1000000.0; return UNIT; // Liter dm^3
{DIGIT}+"."{DIGIT}* {yylval = atof( yytext ); return NUM;}
{DIGIT}+ {yylval = atof( yytext ); return NUM;}
"pi" {yylval = M_PI ; return NUM;} // constant pi
"e" {yylval = M_E ; return NUM;} // constant e

41
src/Base/QuantityParser.y Normal file
View File

@ -0,0 +1,41 @@
/* Parser for the FreeCAD Units language */
/* (c) 2013 Juergen Riegel LGPL */
/* Represents the many different ways we can access our data */
%{
#define YYSTYPE Quantity
#define yyparse Quantity_yyparse
#define yyerror Quantity_yyerror
%}
/* Bison declarations. */
%token UNIT NUM
%left '-' '+'
%left '*' '/'
%left NEG /* negation--unary minus */
%right '^' /* exponentiation */
%start input
%%
input: exp { ScanResult = $1 ; }
;
exp: NUM { $$ = $1; }
| UNIT { $$ = $1; }
| NUM UNIT { $$ = $1*$2; }
| exp '+' exp { $$ = $1 + $3; }
| exp '-' exp { $$ = $1 - $3; }
| exp '*' exp { $$ = $1 * $3; }
| exp '/' exp { $$ = $1 / $3; }
| '-' exp %prec NEG { $$ = -$2; }
| exp '^' NUM { $$ = $1.pow($3); }
| '(' exp ')' { $$ = $2; }
;
%%

48
src/Base/QuantityPy.xml Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="QuantityPy"
Twin="Quantity"
TwinPointer="Quantity"
Include="Base/Quantity.h"
FatherInclude="Base/PyObjectBase.h"
Namespace="Base"
Constructor="true"
Delete="true"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Quantity
defined by a value and a unit.
The following constructors are supported:
Quantity() -- empty constructor
Quantity(Value) -- empty constructor
Quantity(Value,Unit) -- empty constructor
Quantity(Quantity) -- copy constructor
Quantity(string) -- arbitrary mixture of numbers and chars defining a Quantity
</UserDocu>
<DeveloperDocu>Quantity</DeveloperDocu>
</Documentation>
<Methode Name="multiply">
<Documentation>
<UserDocu>
multiply two quantities
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>Vector to the Base position of the Quantity</UserDocu>
</Documentation>
<Parameter Name="Value" Type="Float" />
</Attribute>
<Attribute Name="Unit" ReadOnly="false">
<Documentation>
<UserDocu>Direction vector of the Quantity</UserDocu>
</Documentation>
<Parameter Name="Unit" Type="Object" />
</Attribute>
</PythonExport>
</GenerateModel>

View File

@ -0,0 +1,73 @@
#include "PreCompiled.h"
#include "Base/Quantity.h"
// inclusion of the generated files (generated out of QuantityPy.xml)
#include "QuantityPy.h"
#include "QuantityPy.cpp"
using namespace Base;
// returns a string which represents the object e.g. when printed in python
std::string QuantityPy::representation(void) const
{
return std::string("<Quantity object>");
}
PyObject *QuantityPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of QuantityPy and the Twin object
return new QuantityPy(new Quantity);
}
// constructor method
int QuantityPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
{
return 0;
}
PyObject* QuantityPy::multiply(PyObject * /*args*/)
{
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
return 0;
}
Py::Float QuantityPy::getValue(void) const
{
//return Py::Float();
throw Py::AttributeError("Not yet implemented");
}
void QuantityPy::setValue(Py::Float /*arg*/)
{
throw Py::AttributeError("Not yet implemented");
}
Py::Object QuantityPy::getUnit(void) const
{
//return Py::Object();
throw Py::AttributeError("Not yet implemented");
}
void QuantityPy::setUnit(Py::Object /*arg*/)
{
throw Py::AttributeError("Not yet implemented");
}
PyObject *QuantityPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int QuantityPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}

151
src/Base/Unit.cpp Normal file
View File

@ -0,0 +1,151 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include "Unit.h"
using namespace Base;
Unit::Unit(int8_t Length,
int8_t Mass,
int8_t Time,
int8_t ElectricCurrent,
int8_t ThermodynamicTemperature,
int8_t AmountOfSubstance,
int8_t LuminoseIntensity,
int8_t Angle)
{
Sig.Length = Length;
Sig.Mass = Mass;
Sig.Time = Time;
Sig.ElectricCurrent = ElectricCurrent;
Sig.ThermodynamicTemperature = ThermodynamicTemperature;
Sig.AmountOfSubstance = AmountOfSubstance;
Sig.LuminoseIntensity = LuminoseIntensity;
Sig.Angle = Angle;
}
Unit::Unit()
{
}
Unit::Unit(const Unit& that)
{
this->Sig = that.Sig;
}
Unit::Unit(const std::string& Pars)
{
}
Unit Unit::pow(char exp)const
{
Unit result;
result.Sig.Length = Sig.Length * exp;
result.Sig.Mass = Sig.Mass * exp;
result.Sig.Time = Sig.Time * exp;
result.Sig.ElectricCurrent = Sig.ElectricCurrent * exp;
result.Sig.ThermodynamicTemperature = Sig.ThermodynamicTemperature * exp;
result.Sig.AmountOfSubstance = Sig.AmountOfSubstance * exp;
result.Sig.LuminoseIntensity = Sig.LuminoseIntensity * exp;
result.Sig.Angle = Sig.Angle * exp;
return result;
}
bool Unit::isEmpty(void)const
{
return (this->Sig.Length == 0)
&& (this->Sig.Mass == 0)
&& (this->Sig.Time == 0)
&& (this->Sig.ElectricCurrent == 0)
&& (this->Sig.ThermodynamicTemperature == 0)
&& (this->Sig.AmountOfSubstance == 0)
&& (this->Sig.LuminoseIntensity == 0)
&& (this->Sig.Angle == 0);
}
bool Unit::operator ==(const Unit& that) const
{
return (this->Sig.Length == that.Sig.Length)
&& (this->Sig.Mass == that.Sig.Mass)
&& (this->Sig.Time == that.Sig.Time)
&& (this->Sig.ElectricCurrent == that.Sig.ElectricCurrent)
&& (this->Sig.ThermodynamicTemperature == that.Sig.ThermodynamicTemperature)
&& (this->Sig.AmountOfSubstance == that.Sig.AmountOfSubstance)
&& (this->Sig.LuminoseIntensity == that.Sig.LuminoseIntensity)
&& (this->Sig.Angle == that.Sig.Angle);
}
Unit Unit::operator *(const Unit &right) const
{
Unit result;
result.Sig.Length = Sig.Length + right.Sig.Length;
result.Sig.Mass = Sig.Mass + right.Sig.Mass;
result.Sig.Time = Sig.Time + right.Sig.Time;
result.Sig.ElectricCurrent = Sig.ElectricCurrent + right.Sig.ElectricCurrent;
result.Sig.ThermodynamicTemperature = Sig.ThermodynamicTemperature + right.Sig.ThermodynamicTemperature;
result.Sig.AmountOfSubstance = Sig.AmountOfSubstance + right.Sig.AmountOfSubstance;
result.Sig.LuminoseIntensity = Sig.LuminoseIntensity + right.Sig.LuminoseIntensity;
result.Sig.Angle = Sig.Angle + right.Sig.Angle;
return result;
}
Unit Unit::operator /(const Unit &right) const
{
Unit result;
result.Sig.Length = Sig.Length - right.Sig.Length;
result.Sig.Mass = Sig.Mass - right.Sig.Mass;
result.Sig.Time = Sig.Time - right.Sig.Time;
result.Sig.ElectricCurrent = Sig.ElectricCurrent - right.Sig.ElectricCurrent;
result.Sig.ThermodynamicTemperature = Sig.ThermodynamicTemperature - right.Sig.ThermodynamicTemperature;
result.Sig.AmountOfSubstance = Sig.AmountOfSubstance - right.Sig.AmountOfSubstance;
result.Sig.LuminoseIntensity = Sig.LuminoseIntensity - right.Sig.LuminoseIntensity;
result.Sig.Angle = Sig.Angle - right.Sig.Angle;
return result;
}
Unit& Unit::operator = (const Unit &New)
{
Sig.Length = New.Sig.Length;
Sig.Mass = New.Sig.Mass ;
Sig.Time = New.Sig.Time ;
Sig.ElectricCurrent = New.Sig.ElectricCurrent ;
Sig.ThermodynamicTemperature = New.Sig.ThermodynamicTemperature;
Sig.AmountOfSubstance = New.Sig.AmountOfSubstance ;
Sig.LuminoseIntensity = New.Sig.LuminoseIntensity ;
Sig.Angle = New.Sig.Angle ;
return *this;
}

82
src/Base/Unit.h Normal file
View File

@ -0,0 +1,82 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_Unit_H
#define BASE_Unit_H
#ifdef _MSC_VER
# include <boost/cstdint.hpp>
#else
# include <stdint.h>
#endif
namespace Base {
struct UnitSignature{
int32_t Length:4;
int32_t Mass:4;
int32_t Time:4;
int32_t ElectricCurrent:4;
int32_t ThermodynamicTemperature:4;
int32_t AmountOfSubstance:4;
int32_t LuminoseIntensity:4;
int32_t Angle:4;
};
/**
* The Unit class.
*/
class BaseExport Unit
{
public:
/// default constructor
Unit(int8_t Length,int8_t Mass=0,int8_t Time=0,int8_t ElectricCurrent=0,int8_t ThermodynamicTemperature=0,int8_t AmountOfSubstance=0,int8_t LuminoseIntensity=0,int8_t Angle=0);
Unit(void);
Unit(const Unit&);
Unit(const std::string& Pars);
/// Destruction
~Unit () {};
/** Operators. */
//@{
Unit& operator *=(const Unit&that) const {return *this * that;}
Unit& operator /=(const Unit&that) const {return *this / that;}
Unit operator *(const Unit&) const;
Unit operator /(const Unit&) const;
bool operator ==(const Unit&) const;
bool operator !=(const Unit&that) const {return !(*this == that);}
Unit& operator =(const Unit&);
Unit pow(char exp)const;
//@}
bool isEmpty(void)const;
char getLengthDimension(void){return Sig.Length;}
protected:
UnitSignature Sig;
};
} // namespace Base
#endif // BASE_Unit_H

48
src/Base/UnitPy.xml Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PyObjectBase"
Name="UnitPy"
Twin="Unit"
TwinPointer="Unit"
Include="Base/Unit.h"
FatherInclude="Base/PyObjectBase.h"
Namespace="Base"
Constructor="true"
Delete="true"
FatherNamespace="Base">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
<UserDocu>Unit
defines a unit type and calculate and compare.
The following constructors are supported:
Unit() -- empty constructor
Unit(Unit) -- copy constructor
Unit(string) -- parse the string for units
</UserDocu>
<DeveloperDocu>Unit</DeveloperDocu>
</Documentation>
<Methode Name="multiply">
<Documentation>
<UserDocu>
multiply(Placement)
Multiply this axis with a placement
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getType">
<Documentation>
<UserDocu>
get the type of the unit as string
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Dimensions" ReadOnly="false">
<Documentation>
<UserDocu>get the dimension as a vector with 8 fields</UserDocu>
</Documentation>
<Parameter Name="Direction" Type="Object" />
</Attribute>
</PythonExport>
</GenerateModel>

68
src/Base/UnitPyImp.cpp Normal file
View File

@ -0,0 +1,68 @@
#include "PreCompiled.h"
#include "Base/Unit.h"
// inclusion of the generated files (generated out of UnitPy.xml)
#include "UnitPy.h"
#include "UnitPy.cpp"
using namespace Base;
// returns a string which represents the object e.g. when printed in python
std::string UnitPy::representation(void) const
{
return std::string("<Unit object>");
}
PyObject *UnitPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
{
// create a new instance of UnitPy and the Twin object
return new UnitPy(new Unit);
}
// constructor method
int UnitPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
{
return 0;
}
PyObject* UnitPy::multiply(PyObject * /*args*/)
{
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
return 0;
}
PyObject* UnitPy::getType(PyObject * /*args*/)
{
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
return 0;
}
Py::Object UnitPy::getDimensions(void) const
{
//return Py::Object();
throw Py::AttributeError("Not yet implemented");
}
void UnitPy::setDimensions(Py::Object /*arg*/)
{
throw Py::AttributeError("Not yet implemented");
}
PyObject *UnitPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}
int UnitPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}