diff --git a/src/Base/PlacementPy.xml b/src/Base/PlacementPy.xml index cfdc208c1..9916fc482 100644 --- a/src/Base/PlacementPy.xml +++ b/src/Base/PlacementPy.xml @@ -9,7 +9,8 @@ FatherInclude="Base/PyObjectBase.h" Namespace="Base" Constructor="true" - Delete="true" + Delete="true" + RichCompare="true" FatherNamespace="Base"> @@ -75,7 +76,7 @@ Placement(Base, Axis, Angle) -- define position and rotation - + isNull() -> Bool @@ -83,7 +84,7 @@ Placement(Base, Axis, Angle) -- define position and rotation - + Vector to the Base Position of the Placement diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index cd959cc54..3f1096513 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -118,6 +118,37 @@ int PlacementPy::PyInit(PyObject* args, PyObject* /*kwd*/) return -1; } +PyObject* PlacementPy::richCompare(PyObject *v, PyObject *w, int op) +{ + if (PyObject_TypeCheck(v, &(PlacementPy::Type)) && + PyObject_TypeCheck(w, &(PlacementPy::Type))) { + Base::Placement p1 = *static_cast(v)->getPlacementPtr(); + Base::Placement p2 = *static_cast(w)->getPlacementPtr(); + + PyObject *res=0; + if (op != Py_EQ && op != Py_NE) { + PyErr_SetString(PyExc_TypeError, + "no ordering relation is defined for Placement"); + return 0; + } + else if (op == Py_EQ) { + res = (p1 == p2) ? Py_True : Py_False; + Py_INCREF(res); + return res; + } + else { + res = (p1 != p2) ? Py_True : Py_False; + Py_INCREF(res); + return res; + } + } + else { + // This always returns False + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } +} + PyObject* PlacementPy::move(PyObject * args) { PyObject *vec; diff --git a/src/Base/RotationPy.xml b/src/Base/RotationPy.xml index e510c39b9..f7ab91cea 100644 --- a/src/Base/RotationPy.xml +++ b/src/Base/RotationPy.xml @@ -10,6 +10,7 @@ Namespace="Base" Constructor="true" Delete="true" + RichCompare="true" FatherNamespace="Base"> @@ -59,7 +60,7 @@ - + isNull() -> Bool @@ -67,7 +68,7 @@ - + The rotation elements (as quaternion) diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index d5d9687f9..7f9a1fe1c 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -77,14 +77,14 @@ int RotationPy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_Clear(); double angle; if (PyArg_ParseTuple(args, "O!d", &(Base::VectorPy::Type), &o, &angle)) { - // NOTE: The last parameter defines the rotation angle in degree. + // NOTE: The last parameter defines the rotation angle in degree. getRotationPtr()->setValue(static_cast(o)->value(), Base::toRadians(angle)); return 0; } PyErr_Clear(); if (PyArg_ParseTuple(args, "O!d", &(Base::MatrixPy::Type), &o, &angle)) { - // NOTE: The last parameter defines the rotation angle in degree. + // NOTE: The last parameter defines the rotation angle in degree. getRotationPtr()->setValue(static_cast(o)->value()); return 0; } @@ -164,6 +164,37 @@ int RotationPy::PyInit(PyObject* args, PyObject* /*kwd*/) return -1; } +PyObject* RotationPy::richCompare(PyObject *v, PyObject *w, int op) +{ + if (PyObject_TypeCheck(v, &(RotationPy::Type)) && + PyObject_TypeCheck(w, &(RotationPy::Type))) { + Base::Rotation r1 = *static_cast(v)->getRotationPtr(); + Base::Rotation r2 = *static_cast(w)->getRotationPtr(); + + PyObject *res=0; + if (op != Py_EQ && op != Py_NE) { + PyErr_SetString(PyExc_TypeError, + "no ordering relation is defined for Rotation"); + return 0; + } + else if (op == Py_EQ) { + res = (r1 == r2) ? Py_True : Py_False; + Py_INCREF(res); + return res; + } + else { + res = (r1 != r2) ? Py_True : Py_False; + Py_INCREF(res); + return res; + } + } + else { + // This always returns False + Py_INCREF(Py_NotImplemented); + return Py_NotImplemented; + } +} + PyObject* RotationPy::invert(PyObject * args) { if (!PyArg_ParseTuple(args, "")) @@ -205,16 +236,16 @@ PyObject* RotationPy::toEuler(PyObject * args) return Py::new_reference_to(tuple); } -PyObject* RotationPy::isNull(PyObject *args) -{ - if (!PyArg_ParseTuple(args, "")) - return NULL; - Base::Rotation rot = * getRotationPtr(); - Base::Rotation nullrot(0,0,0,1); - Base::Rotation nullrotinv(0,0,0,-1); - bool null = (rot == nullrot) | (rot == nullrotinv); - return Py_BuildValue("O", (null ? Py_True : Py_False)); -} +PyObject* RotationPy::isNull(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + Base::Rotation rot = * getRotationPtr(); + Base::Rotation nullrot(0,0,0,1); + Base::Rotation nullrotinv(0,0,0,-1); + bool null = (rot == nullrot) | (rot == nullrotinv); + return Py_BuildValue("O", (null ? Py_True : Py_False)); +} Py::Tuple RotationPy::getQ(void) const {