implementing Quantity further
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "Base/Quantity.h"
|
||||
#include "Base/Vector3D.h"
|
||||
|
||||
// inclusion of the generated files (generated out of QuantityPy.xml)
|
||||
#include "QuantityPy.h"
|
||||
@@ -22,20 +23,101 @@ PyObject *QuantityPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // P
|
||||
}
|
||||
|
||||
// constructor method
|
||||
int QuantityPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
|
||||
int QuantityPy::PyInit(PyObject* args, PyObject* kwd)
|
||||
{
|
||||
return 0;
|
||||
Quantity *self = getQuantityPtr();
|
||||
|
||||
double f = DOUBLE_MAX;
|
||||
|
||||
if (PyArg_ParseTuple(args, "|d", &f)) {
|
||||
if(f!=DOUBLE_MAX)
|
||||
*self = Quantity(f);
|
||||
return 0;
|
||||
}
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
|
||||
PyObject *object;
|
||||
|
||||
if (PyArg_ParseTuple(args,"O!",&(Base::QuantityPy::Type), &object)) {
|
||||
// Note: must be static_cast, not reinterpret_cast
|
||||
*self = *(static_cast<Base::QuantityPy*>(object)->getQuantityPtr());
|
||||
return 0;
|
||||
}
|
||||
PyErr_Clear(); // set by PyArg_ParseTuple()
|
||||
const char* string;
|
||||
if (PyArg_ParseTuple(args,"s", &string)) {
|
||||
|
||||
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "Either three floats, tuple or Vector expected");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
PyObject* QuantityPy::multiply(PyObject * /*args*/)
|
||||
PyObject* QuantityPy::pow(PyObject * args)
|
||||
{
|
||||
PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PyObject* QuantityPy::number_add_handler(PyObject *self, PyObject *other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
if (!PyObject_TypeCheck(other, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "Second arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self)->getQuantityPtr();
|
||||
Base::Quantity *b = static_cast<QuantityPy*>(other)->getQuantityPtr();
|
||||
return new QuantityPy(new Quantity(*a+*b) );
|
||||
}
|
||||
|
||||
PyObject* QuantityPy::number_subtract_handler(PyObject *self, PyObject *other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
if (!PyObject_TypeCheck(other, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "Second arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self)->getQuantityPtr();
|
||||
Base::Quantity *b = static_cast<QuantityPy*>(other)->getQuantityPtr();
|
||||
return new QuantityPy(new Quantity(*a-*b) );
|
||||
}
|
||||
|
||||
PyObject* QuantityPy::number_multiply_handler(PyObject *self, PyObject *other)
|
||||
{
|
||||
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {
|
||||
PyErr_SetString(PyExc_TypeError, "First arg must be Quantity");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (PyObject_TypeCheck(other, &(QuantityPy::Type))) {
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
|
||||
Base::Quantity *b = static_cast<QuantityPy*>(other)->getQuantityPtr();
|
||||
|
||||
return new QuantityPy(new Quantity(*a * *b) );
|
||||
}
|
||||
else if (PyFloat_Check(other)) {
|
||||
Base::Quantity *a = static_cast<QuantityPy*>(self) ->getQuantityPtr();
|
||||
double b = PyFloat_AsDouble(other);
|
||||
return new QuantityPy(new Quantity(*a*b) );
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "A Quantity can only be multiplied by Quantity or number");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Py::Float QuantityPy::getValue(void) const
|
||||
|
||||
Reference in New Issue
Block a user