diff --git a/src/Base/RotationPyImp.cpp b/src/Base/RotationPyImp.cpp index 6b7f642d57..06c358507a 100644 --- a/src/Base/RotationPyImp.cpp +++ b/src/Base/RotationPyImp.cpp @@ -83,8 +83,7 @@ int RotationPy::PyInit(PyObject* args, PyObject* /*kwd*/) } PyErr_Clear(); - if (PyArg_ParseTuple(args, "O!d", &(Base::MatrixPy::Type), &o, &angle)) { - // NOTE: The last parameter defines the rotation angle in degree. + if (PyArg_ParseTuple(args, "O!", &(Base::MatrixPy::Type), &o)) { getRotationPtr()->setValue(static_cast(o)->value()); return 0; } @@ -154,9 +153,9 @@ int RotationPy::PyInit(PyObject* args, PyObject* /*kwd*/) PyObject *v3; char *priority = nullptr; if (PyArg_ParseTuple(args, "O!O!O!|s", &(Base::VectorPy::Type), &v1, - &(Base::VectorPy::Type), &v2, - &(Base::VectorPy::Type), &v3, - &priority )) { + &(Base::VectorPy::Type), &v2, + &(Base::VectorPy::Type), &v3, + &priority)) { Py::Vector xdir(v1, false); Py::Vector ydir(v2, false); Py::Vector zdir(v3, false); @@ -350,13 +349,37 @@ void RotationPy::setAngle(Py::Float arg) this->getRotationPtr()->setValue(axis, angle); } -PyObject *RotationPy::getCustomAttributes(const char* /*attr*/) const +PyObject *RotationPy::getCustomAttributes(const char* attr) const { + if (strcmp(attr, "Matrix") == 0) { + Matrix4D mat; + this->getRotationPtr()->getValue(mat); + return new MatrixPy(mat); + } return 0; } -int RotationPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +int RotationPy::setCustomAttributes(const char* attr, PyObject* obj) { + if (strcmp(attr, "Matrix") == 0) { + if (PyObject_TypeCheck(obj, &(MatrixPy::Type))) { + this->getRotationPtr()->setValue(*static_cast(obj)->getMatrixPtr()); + return 1; + } + } + else if (strcmp(attr, "Axes") == 0) { + if (PySequence_Check(obj) && PySequence_Size(obj) == 2) { + PyObject* vec1 = PySequence_GetItem(obj, 0); + PyObject* vec2 = PySequence_GetItem(obj, 1); + if (PyObject_TypeCheck(vec1, &(VectorPy::Type)) && + PyObject_TypeCheck(vec2, &(VectorPy::Type))) { + this->getRotationPtr()->setValue( + *static_cast(vec1)->getVectorPtr(), + *static_cast(vec2)->getVectorPtr()); + return 1; + } + } + } return 0; }