MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / setCustomAttributes

Method setCustomAttributes

src/Base/RotationPyImp.cpp:562–626  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560}
561
562int RotationPy::setCustomAttributes(const char* attr, PyObject* obj)
563{
564 if (strcmp(attr, "Matrix") == 0) {
565 if (PyObject_TypeCheck(obj, &(MatrixPy::Type))) {
566 try {
567 this->getRotationPtr()->setValue(*static_cast<MatrixPy*>(obj)->getMatrixPtr());
568 return 1;
569 }
570 catch (const Exception& e) {
571 PyErr_SetString(e.getPyExceptionType(), e.what());
572 return -1;
573 }
574 }
575 }
576 else if (strcmp(attr, "Axes") == 0) {
577 if (PySequence_Check(obj)) {
578 Py::Sequence sequence(obj);
579 if (sequence.size() == 2) {
580 Py::Object vec1 = sequence.getItem(0);
581 Py::Object vec2 = sequence.getItem(1);
582 if (PyObject_TypeCheck(vec1.ptr(), &(VectorPy::Type))
583 && PyObject_TypeCheck(vec2.ptr(), &(VectorPy::Type))) {
584 Vector3d* pt1 = static_cast<VectorPy*>(vec1.ptr())->getVectorPtr();
585 Vector3d* pt2 = static_cast<VectorPy*>(vec2.ptr())->getVectorPtr();
586 this->getRotationPtr()->setValue(*pt1, *pt2);
587 return 1;
588 }
589 }
590 }
591 }
592 else if (strcmp(attr, "Yaw") == 0) {
593 if (PyNumber_Check(obj)) {
594 double V = PyFloat_AsDouble(obj);
595 double A {};
596 double B {};
597 double C {};
598 this->getRotationPtr()->getYawPitchRoll(A, B, C);
599 this->getRotationPtr()->setYawPitchRoll(V, B, C);
600 return 1;
601 }
602 }
603 else if (strcmp(attr, "Pitch") == 0) {
604 if (PyNumber_Check(obj)) {
605 double V = PyFloat_AsDouble(obj);
606 double A {};
607 double B {};
608 double C {};
609 this->getRotationPtr()->getYawPitchRoll(A, B, C);
610 this->getRotationPtr()->setYawPitchRoll(A, V, C);
611 return 1;
612 }
613 }
614 else if (strcmp(attr, "Roll") == 0) {
615 if (PyNumber_Check(obj)) {
616 double V = PyFloat_AsDouble(obj);
617 double A {};
618 double B {};
619 double C {};

Callers

nothing calls this directly

Calls 8

getPyExceptionTypeMethod · 0.80
setValueMethod · 0.45
whatMethod · 0.45
sizeMethod · 0.45
getItemMethod · 0.45
ptrMethod · 0.45
getYawPitchRollMethod · 0.45
setYawPitchRollMethod · 0.45

Tested by

no test coverage detected