00001
00002
00003
00004
00005
00006 #include <boost/filesystem/path.hpp>
00007 #include <boost/filesystem/operations.hpp>
00008 #include <boost/filesystem/exception.hpp>
00009 #include <Base/PyObjectBase.h>
00010 #include <Base/Console.h>
00011 #include <Base/Exception.h>
00012 #include <CXX/Objects.hxx>
00013
00014 #define new DEBUG_CLIENTBLOCK
00015
00016 using Base::streq;
00017 using namespace Base;
00018
00020 PyTypeObject RotationPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Base.Rotation",
00024 sizeof(RotationPy),
00025 0,
00026
00027 PyDestructor,
00028 0,
00029 __getattr,
00030 __setattr,
00031 0,
00032 __repr,
00033 0,
00034 0,
00035 0,
00036 0,
00037 0,
00038 0,
00039 0,
00040 0,
00041
00042 0,
00043
00044 Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS,
00045 "A Rotation",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Base::RotationPy::Methods,
00053 0,
00054 Base::RotationPy::GetterSetter,
00055 &Base::PyObjectBase::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Base::RotationPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef RotationPy::Methods[] = {
00075 {"invert",
00076 (PyCFunction) staticCallback_invert,
00077 METH_VARARGS,
00078 "\n move(Vector)\n Move the matrix along the vector\n "
00079 },
00080 {"multiply",
00081 (PyCFunction) staticCallback_multiply,
00082 METH_VARARGS,
00083 "\n multiply(Rotation)\n Multiply this quaternion with another quaternion\n "
00084 },
00085 {"multVec",
00086 (PyCFunction) staticCallback_multVec,
00087 METH_VARARGS,
00088 "\n multVec(Vector) -> Vector\n Compute the transformed vector using the rotation\n "
00089 },
00090 {"toEuler",
00091 (PyCFunction) staticCallback_toEuler,
00092 METH_VARARGS,
00093 "\n toEuler(Vector) -> list\n Get the Euler angles of this rotation\n "
00094 },
00095 {NULL, NULL, 0, NULL}
00096 };
00097
00098
00099
00101 PyGetSetDef RotationPy::GetterSetter[] = {
00102 {"Q",
00103 (getter) staticCallback_getQ,
00104 (setter) staticCallback_setQ,
00105 "The rotation elements (as quaternion)",
00106 NULL
00107 },
00108 {"Axis",
00109 (getter) staticCallback_getAxis,
00110 (setter) staticCallback_setAxis,
00111 "The rotation axis of the quaternion",
00112 NULL
00113 },
00114 {"Angle",
00115 (getter) staticCallback_getAngle,
00116 (setter) staticCallback_setAngle,
00117 "The rotation angle of the quaternion",
00118 NULL
00119 },
00120 {NULL, NULL, NULL, NULL, NULL}
00121 };
00122
00123
00124
00125
00126 PyObject * RotationPy::staticCallback_invert (PyObject *self, PyObject *args)
00127 {
00128
00129 if (!((PyObjectBase*) self)->isValid()){
00130 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00131 return NULL;
00132 }
00133
00134
00135 if (((PyObjectBase*) self)->isConst()){
00136 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00137 return NULL;
00138 }
00139
00140 try {
00141 PyObject* ret = ((RotationPy*)self)->invert(args);
00142 if (ret != 0)
00143 ((RotationPy*)self)->startNotify();
00144 return ret;
00145 }
00146 catch(const Base::Exception& e)
00147 {
00148 std::string str;
00149 str += "FreeCAD exception thrown (";
00150 str += e.what();
00151 str += ")";
00152 e.ReportException();
00153 PyErr_SetString(PyExc_Exception,str.c_str());
00154 return NULL;
00155 }
00156 catch(const boost::filesystem::filesystem_error& e)
00157 {
00158 std::string str;
00159 str += "File system exception thrown (";
00160
00161
00162 str += e.what();
00163 str += ")\n";
00164 Base::Console().Error(str.c_str());
00165 PyErr_SetString(PyExc_Exception,str.c_str());
00166 return NULL;
00167 }
00168 catch(const Py::Exception&)
00169 {
00170
00171 return NULL;
00172 }
00173 catch(const char* e)
00174 {
00175 Base::Console().Error(e);
00176 PyErr_SetString(PyExc_Exception,e);
00177 return NULL;
00178 }
00179
00180 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00181 catch(const std::exception& e)
00182 {
00183 std::string str;
00184 str += "FC++ exception thrown (";
00185 str += e.what();
00186 str += ")";
00187 Base::Console().Error(str.c_str());
00188 PyErr_SetString(PyExc_Exception,str.c_str());
00189 return NULL;
00190 }
00191 catch(...)
00192 {
00193 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00194 return NULL;
00195 }
00196 #endif
00197 }
00198
00199
00200
00201
00202 PyObject * RotationPy::staticCallback_multiply (PyObject *self, PyObject *args)
00203 {
00204
00205 if (!((PyObjectBase*) self)->isValid()){
00206 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00207 return NULL;
00208 }
00209
00210
00211 if (((PyObjectBase*) self)->isConst()){
00212 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00213 return NULL;
00214 }
00215
00216 try {
00217 PyObject* ret = ((RotationPy*)self)->multiply(args);
00218 if (ret != 0)
00219 ((RotationPy*)self)->startNotify();
00220 return ret;
00221 }
00222 catch(const Base::Exception& e)
00223 {
00224 std::string str;
00225 str += "FreeCAD exception thrown (";
00226 str += e.what();
00227 str += ")";
00228 e.ReportException();
00229 PyErr_SetString(PyExc_Exception,str.c_str());
00230 return NULL;
00231 }
00232 catch(const boost::filesystem::filesystem_error& e)
00233 {
00234 std::string str;
00235 str += "File system exception thrown (";
00236
00237
00238 str += e.what();
00239 str += ")\n";
00240 Base::Console().Error(str.c_str());
00241 PyErr_SetString(PyExc_Exception,str.c_str());
00242 return NULL;
00243 }
00244 catch(const Py::Exception&)
00245 {
00246
00247 return NULL;
00248 }
00249 catch(const char* e)
00250 {
00251 Base::Console().Error(e);
00252 PyErr_SetString(PyExc_Exception,e);
00253 return NULL;
00254 }
00255
00256 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00257 catch(const std::exception& e)
00258 {
00259 std::string str;
00260 str += "FC++ exception thrown (";
00261 str += e.what();
00262 str += ")";
00263 Base::Console().Error(str.c_str());
00264 PyErr_SetString(PyExc_Exception,str.c_str());
00265 return NULL;
00266 }
00267 catch(...)
00268 {
00269 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00270 return NULL;
00271 }
00272 #endif
00273 }
00274
00275
00276
00277
00278 PyObject * RotationPy::staticCallback_multVec (PyObject *self, PyObject *args)
00279 {
00280
00281 if (!((PyObjectBase*) self)->isValid()){
00282 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00283 return NULL;
00284 }
00285
00286
00287 if (((PyObjectBase*) self)->isConst()){
00288 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00289 return NULL;
00290 }
00291
00292 try {
00293 PyObject* ret = ((RotationPy*)self)->multVec(args);
00294 if (ret != 0)
00295 ((RotationPy*)self)->startNotify();
00296 return ret;
00297 }
00298 catch(const Base::Exception& e)
00299 {
00300 std::string str;
00301 str += "FreeCAD exception thrown (";
00302 str += e.what();
00303 str += ")";
00304 e.ReportException();
00305 PyErr_SetString(PyExc_Exception,str.c_str());
00306 return NULL;
00307 }
00308 catch(const boost::filesystem::filesystem_error& e)
00309 {
00310 std::string str;
00311 str += "File system exception thrown (";
00312
00313
00314 str += e.what();
00315 str += ")\n";
00316 Base::Console().Error(str.c_str());
00317 PyErr_SetString(PyExc_Exception,str.c_str());
00318 return NULL;
00319 }
00320 catch(const Py::Exception&)
00321 {
00322
00323 return NULL;
00324 }
00325 catch(const char* e)
00326 {
00327 Base::Console().Error(e);
00328 PyErr_SetString(PyExc_Exception,e);
00329 return NULL;
00330 }
00331
00332 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00333 catch(const std::exception& e)
00334 {
00335 std::string str;
00336 str += "FC++ exception thrown (";
00337 str += e.what();
00338 str += ")";
00339 Base::Console().Error(str.c_str());
00340 PyErr_SetString(PyExc_Exception,str.c_str());
00341 return NULL;
00342 }
00343 catch(...)
00344 {
00345 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00346 return NULL;
00347 }
00348 #endif
00349 }
00350
00351
00352
00353
00354 PyObject * RotationPy::staticCallback_toEuler (PyObject *self, PyObject *args)
00355 {
00356
00357 if (!((PyObjectBase*) self)->isValid()){
00358 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00359 return NULL;
00360 }
00361
00362
00363 if (((PyObjectBase*) self)->isConst()){
00364 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00365 return NULL;
00366 }
00367
00368 try {
00369 PyObject* ret = ((RotationPy*)self)->toEuler(args);
00370 if (ret != 0)
00371 ((RotationPy*)self)->startNotify();
00372 return ret;
00373 }
00374 catch(const Base::Exception& e)
00375 {
00376 std::string str;
00377 str += "FreeCAD exception thrown (";
00378 str += e.what();
00379 str += ")";
00380 e.ReportException();
00381 PyErr_SetString(PyExc_Exception,str.c_str());
00382 return NULL;
00383 }
00384 catch(const boost::filesystem::filesystem_error& e)
00385 {
00386 std::string str;
00387 str += "File system exception thrown (";
00388
00389
00390 str += e.what();
00391 str += ")\n";
00392 Base::Console().Error(str.c_str());
00393 PyErr_SetString(PyExc_Exception,str.c_str());
00394 return NULL;
00395 }
00396 catch(const Py::Exception&)
00397 {
00398
00399 return NULL;
00400 }
00401 catch(const char* e)
00402 {
00403 Base::Console().Error(e);
00404 PyErr_SetString(PyExc_Exception,e);
00405 return NULL;
00406 }
00407
00408 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00409 catch(const std::exception& e)
00410 {
00411 std::string str;
00412 str += "FC++ exception thrown (";
00413 str += e.what();
00414 str += ")";
00415 Base::Console().Error(str.c_str());
00416 PyErr_SetString(PyExc_Exception,str.c_str());
00417 return NULL;
00418 }
00419 catch(...)
00420 {
00421 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00422 return NULL;
00423 }
00424 #endif
00425 }
00426
00427
00428
00429
00430 PyObject * RotationPy::staticCallback_getQ (PyObject *self, void * )
00431 {
00432 if (!((PyObjectBase*) self)->isValid()){
00433 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00434 return NULL;
00435 }
00436
00437 try {
00438 return Py::new_reference_to(((RotationPy*)self)->getQ());
00439 } catch (const Py::Exception&) {
00440
00441 return NULL;
00442 } catch (...) {
00443 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Q' of object 'Rotation'");
00444 return NULL;
00445 }
00446 }
00447
00448 int RotationPy::staticCallback_setQ (PyObject *self, PyObject *value, void * )
00449 {
00450 if (!((PyObjectBase*) self)->isValid()){
00451 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00452 return -1;
00453 }
00454 if (((PyObjectBase*) self)->isConst()){
00455 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00456 return -1;
00457 }
00458
00459 try {
00460 ((RotationPy*)self)->setQ(Py::Tuple(value,false));
00461 return 0;
00462 } catch (const Py::Exception&) {
00463
00464 return -1;
00465 } catch (...) {
00466 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Q' of object 'Rotation'");
00467 return -1;
00468 }
00469 }
00470
00471
00472
00473
00474 PyObject * RotationPy::staticCallback_getAxis (PyObject *self, void * )
00475 {
00476 if (!((PyObjectBase*) self)->isValid()){
00477 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00478 return NULL;
00479 }
00480
00481 try {
00482 return Py::new_reference_to(((RotationPy*)self)->getAxis());
00483 } catch (const Py::Exception&) {
00484
00485 return NULL;
00486 } catch (...) {
00487 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'Rotation'");
00488 return NULL;
00489 }
00490 }
00491
00492 int RotationPy::staticCallback_setAxis (PyObject *self, PyObject * , void * )
00493 {
00494 if (!((PyObjectBase*) self)->isValid()){
00495 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00496 return -1;
00497 }
00498
00499 PyErr_SetString(PyExc_AttributeError, "Attribute 'Axis' of object 'Rotation' is read-only");
00500 return -1;
00501 }
00502
00503
00504
00505
00506 PyObject * RotationPy::staticCallback_getAngle (PyObject *self, void * )
00507 {
00508 if (!((PyObjectBase*) self)->isValid()){
00509 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00510 return NULL;
00511 }
00512
00513 try {
00514 return Py::new_reference_to(((RotationPy*)self)->getAngle());
00515 } catch (const Py::Exception&) {
00516
00517 return NULL;
00518 } catch (...) {
00519 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Angle' of object 'Rotation'");
00520 return NULL;
00521 }
00522 }
00523
00524 int RotationPy::staticCallback_setAngle (PyObject *self, PyObject * , void * )
00525 {
00526 if (!((PyObjectBase*) self)->isValid()){
00527 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00528 return -1;
00529 }
00530
00531 PyErr_SetString(PyExc_AttributeError, "Attribute 'Angle' of object 'Rotation' is read-only");
00532 return -1;
00533 }
00534
00535
00536
00537
00538
00539
00540 PyParentObject RotationPy::Parents[] = { PARENTSBaseRotationPy };
00541
00542
00543
00544
00545 RotationPy::RotationPy(Rotation *pcObject, PyTypeObject *T)
00546 : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00547 {
00548 }
00549
00550
00551
00552
00553
00554 RotationPy::~RotationPy()
00555 {
00556
00557 RotationPy::PointerType ptr = reinterpret_cast<RotationPy::PointerType>(_pcTwinPointer);
00558 delete ptr;
00559 }
00560
00561
00562
00563
00564 PyObject *RotationPy::_repr(void)
00565 {
00566 return Py_BuildValue("s", representation().c_str());
00567 }
00568
00569
00570
00571
00572 PyObject *RotationPy::_getattr(char *attr)
00573 {
00574 try {
00575
00576 PyObject *r = getCustomAttributes(attr);
00577 if(r) return r;
00578 }
00579 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00580 catch(const Base::Exception& e)
00581 {
00582 std::string str;
00583 str += "FreeCAD exception thrown (";
00584 str += e.what();
00585 str += ")";
00586 e.ReportException();
00587 PyErr_SetString(PyExc_Exception,str.c_str());
00588 return NULL;
00589 }
00590 catch(const std::exception& e)
00591 {
00592 std::string str;
00593 str += "FC++ exception thrown (";
00594 str += e.what();
00595 str += ")";
00596 Base::Console().Error(str.c_str());
00597 PyErr_SetString(PyExc_Exception,str.c_str());
00598 return NULL;
00599 }
00600 catch(const Py::Exception&)
00601 {
00602
00603 return NULL;
00604 }
00605 catch(...)
00606 {
00607 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00608 return NULL;
00609 }
00610 #else // DONT_CATCH_CXX_EXCEPTIONS
00611 catch(const Base::Exception& e)
00612 {
00613 std::string str;
00614 str += "FreeCAD exception thrown (";
00615 str += e.what();
00616 str += ")";
00617 e.ReportException();
00618 PyErr_SetString(PyExc_Exception,str.c_str());
00619 return NULL;
00620 }
00621 catch(const Py::Exception&)
00622 {
00623
00624 return NULL;
00625 }
00626 #endif // DONT_CATCH_CXX_EXCEPTIONS
00627
00628 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00629 if (rvalue == NULL)
00630 {
00631 PyErr_Clear();
00632 return PyObjectBase::_getattr(attr);
00633 }
00634 else
00635 {
00636 return rvalue;
00637 }
00638 }
00639
00640 int RotationPy::_setattr(char *attr, PyObject *value)
00641 {
00642 try {
00643
00644 int r = setCustomAttributes(attr, value);
00645 if(r==1) return 0;
00646 }
00647 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00648 catch(const Base::Exception& e)
00649 {
00650 std::string str;
00651 str += "FreeCAD exception thrown (";
00652 str += e.what();
00653 str += ")";
00654 e.ReportException();
00655 PyErr_SetString(PyExc_Exception,str.c_str());
00656 return -1;
00657 }
00658 catch(const std::exception& e)
00659 {
00660 std::string str;
00661 str += "FC++ exception thrown (";
00662 str += e.what();
00663 str += ")";
00664 Base::Console().Error(str.c_str());
00665 PyErr_SetString(PyExc_Exception,str.c_str());
00666 return -1;
00667 }
00668 catch(const Py::Exception&)
00669 {
00670
00671 return -1;
00672 }
00673 catch(...)
00674 {
00675 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00676 return -1;
00677 }
00678 #else // DONT_CATCH_CXX_EXCEPTIONS
00679 catch(const Base::Exception& e)
00680 {
00681 std::string str;
00682 str += "FreeCAD exception thrown (";
00683 str += e.what();
00684 str += ")";
00685 e.ReportException();
00686 PyErr_SetString(PyExc_Exception,str.c_str());
00687 return -1;
00688 }
00689 catch(const Py::Exception&)
00690 {
00691
00692 return -1;
00693 }
00694 #endif // DONT_CATCH_CXX_EXCEPTIONS
00695
00696 return PyObjectBase::_setattr(attr, value);
00697 }
00698
00699 Rotation *RotationPy::getRotationPtr(void) const
00700 {
00701 return static_cast<Rotation *>(_pcTwinPointer);
00702 }
00703
00704 #if 0
00705
00706
00707
00708
00709 PyObject *RotationPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00710 {
00711
00712 return new RotationPy(new Rotation);
00713 }
00714
00715
00716 int RotationPy::PyInit(PyObject* , PyObject* )
00717 {
00718 return 0;
00719 }
00720
00721
00722 std::string RotationPy::representation(void) const
00723 {
00724 return std::string("<Rotation object>");
00725 }
00726
00727 PyObject* RotationPy::invert(PyObject *args)
00728 {
00729 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00730 return 0;
00731 }
00732
00733 PyObject* RotationPy::multiply(PyObject *args)
00734 {
00735 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00736 return 0;
00737 }
00738
00739 PyObject* RotationPy::multVec(PyObject *args)
00740 {
00741 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00742 return 0;
00743 }
00744
00745 PyObject* RotationPy::toEuler(PyObject *args)
00746 {
00747 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00748 return 0;
00749 }
00750
00751
00752
00753 Py::Tuple RotationPy::getQ(void) const
00754 {
00755
00756 throw Py::AttributeError("Not yet implemented");
00757 }
00758
00759 void RotationPy::setQ(Py::Tuple arg)
00760 {
00761 throw Py::AttributeError("Not yet implemented");
00762 }
00763
00764 Py::Object RotationPy::getAxis(void) const
00765 {
00766
00767 throw Py::AttributeError("Not yet implemented");
00768 }
00769
00770 Py::Float RotationPy::getAngle(void) const
00771 {
00772
00773 throw Py::AttributeError("Not yet implemented");
00774 }
00775
00776 PyObject *RotationPy::getCustomAttributes(const char* attr) const
00777 {
00778 return 0;
00779 }
00780
00781 int RotationPy::setCustomAttributes(const char* attr, PyObject *obj)
00782 {
00783 return 0;
00784 }
00785 #endif
00786
00787
00788