implement setting custom attributes for RotationPy to assign matrix or pair of vectors
This commit is contained in:
@@ -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<Base::MatrixPy*>(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<MatrixPy*>(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<VectorPy*>(vec1)->getVectorPtr(),
|
||||
*static_cast<VectorPy*>(vec2)->getVectorPtr());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user