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 Robot;
00018
00020 PyTypeObject TrajectoryPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Robot.Trajectory",
00024 sizeof(TrajectoryPy),
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 "Trajectory class",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Robot::TrajectoryPy::Methods,
00053 0,
00054 Robot::TrajectoryPy::GetterSetter,
00055 &Base::PersistencePy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Robot::TrajectoryPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef TrajectoryPy::Methods[] = {
00075 {"insertWaypoints",
00076 (PyCFunction) staticCallback_insertWaypoints,
00077 METH_VARARGS,
00078 "\n adds one or a list of waypoint to the end of the trajectory\n "
00079 },
00080 {"position",
00081 (PyCFunction) staticCallback_position,
00082 METH_VARARGS,
00083 "\n returns a Frame to a given time in the trajectory\n "
00084 },
00085 {"velocity",
00086 (PyCFunction) staticCallback_velocity,
00087 METH_VARARGS,
00088 "\n returns the velocity to a given time in the trajectory\n "
00089 },
00090 {"deleteLast",
00091 (PyCFunction) staticCallback_deleteLast,
00092 METH_VARARGS,
00093 "\n deleteLast(n) - delete n waypoints at the end\n deleteLast() - delete the last waypoint\n "
00094 },
00095 {NULL, NULL, 0, NULL}
00096 };
00097
00098
00099
00101 PyGetSetDef TrajectoryPy::GetterSetter[] = {
00102 {"Duration",
00103 (getter) staticCallback_getDuration,
00104 (setter) staticCallback_setDuration,
00105 "duration of the trajectory",
00106 NULL
00107 },
00108 {"Length",
00109 (getter) staticCallback_getLength,
00110 (setter) staticCallback_setLength,
00111 "length of the trajectory",
00112 NULL
00113 },
00114 {"Waypoints",
00115 (getter) staticCallback_getWaypoints,
00116 (setter) staticCallback_setWaypoints,
00117 "waypoints of this trajectory",
00118 NULL
00119 },
00120 {NULL, NULL, NULL, NULL, NULL}
00121 };
00122
00123
00124
00125
00126 PyObject * TrajectoryPy::staticCallback_insertWaypoints (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 = ((TrajectoryPy*)self)->insertWaypoints(args);
00142 if (ret != 0)
00143 ((TrajectoryPy*)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 * TrajectoryPy::staticCallback_position (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 = ((TrajectoryPy*)self)->position(args);
00218 if (ret != 0)
00219 ((TrajectoryPy*)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 * TrajectoryPy::staticCallback_velocity (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 = ((TrajectoryPy*)self)->velocity(args);
00294 if (ret != 0)
00295 ((TrajectoryPy*)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 * TrajectoryPy::staticCallback_deleteLast (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 = ((TrajectoryPy*)self)->deleteLast(args);
00370 if (ret != 0)
00371 ((TrajectoryPy*)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 * TrajectoryPy::staticCallback_getDuration (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(((TrajectoryPy*)self)->getDuration());
00439 } catch (const Py::Exception&) {
00440
00441 return NULL;
00442 } catch (...) {
00443 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Duration' of object 'Trajectory'");
00444 return NULL;
00445 }
00446 }
00447
00448 int TrajectoryPy::staticCallback_setDuration (PyObject *self, PyObject * , 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
00455 PyErr_SetString(PyExc_AttributeError, "Attribute 'Duration' of object 'Trajectory' is read-only");
00456 return -1;
00457 }
00458
00459
00460
00461
00462 PyObject * TrajectoryPy::staticCallback_getLength (PyObject *self, void * )
00463 {
00464 if (!((PyObjectBase*) self)->isValid()){
00465 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00466 return NULL;
00467 }
00468
00469 try {
00470 return Py::new_reference_to(((TrajectoryPy*)self)->getLength());
00471 } catch (const Py::Exception&) {
00472
00473 return NULL;
00474 } catch (...) {
00475 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Length' of object 'Trajectory'");
00476 return NULL;
00477 }
00478 }
00479
00480 int TrajectoryPy::staticCallback_setLength (PyObject *self, PyObject * , void * )
00481 {
00482 if (!((PyObjectBase*) self)->isValid()){
00483 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00484 return -1;
00485 }
00486
00487 PyErr_SetString(PyExc_AttributeError, "Attribute 'Length' of object 'Trajectory' is read-only");
00488 return -1;
00489 }
00490
00491
00492
00493
00494 PyObject * TrajectoryPy::staticCallback_getWaypoints (PyObject *self, void * )
00495 {
00496 if (!((PyObjectBase*) self)->isValid()){
00497 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00498 return NULL;
00499 }
00500
00501 try {
00502 return Py::new_reference_to(((TrajectoryPy*)self)->getWaypoints());
00503 } catch (const Py::Exception&) {
00504
00505 return NULL;
00506 } catch (...) {
00507 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Waypoints' of object 'Trajectory'");
00508 return NULL;
00509 }
00510 }
00511
00512 int TrajectoryPy::staticCallback_setWaypoints (PyObject *self, PyObject *value, void * )
00513 {
00514 if (!((PyObjectBase*) self)->isValid()){
00515 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00516 return -1;
00517 }
00518 if (((PyObjectBase*) self)->isConst()){
00519 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00520 return -1;
00521 }
00522
00523 try {
00524 ((TrajectoryPy*)self)->setWaypoints(Py::List(value,false));
00525 return 0;
00526 } catch (const Py::Exception&) {
00527
00528 return -1;
00529 } catch (...) {
00530 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Waypoints' of object 'Trajectory'");
00531 return -1;
00532 }
00533 }
00534
00535
00536
00537
00538
00539
00540 PyParentObject TrajectoryPy::Parents[] = { PARENTSRobotTrajectoryPy };
00541
00542
00543
00544
00545 TrajectoryPy::TrajectoryPy(Trajectory *pcObject, PyTypeObject *T)
00546 : PersistencePy(reinterpret_cast<PersistencePy::PointerType>(pcObject), T)
00547 {
00548 }
00549
00550
00551
00552
00553
00554 TrajectoryPy::~TrajectoryPy()
00555 {
00556
00557 TrajectoryPy::PointerType ptr = reinterpret_cast<TrajectoryPy::PointerType>(_pcTwinPointer);
00558 delete ptr;
00559 }
00560
00561
00562
00563
00564 PyObject *TrajectoryPy::_repr(void)
00565 {
00566 return Py_BuildValue("s", representation().c_str());
00567 }
00568
00569
00570
00571
00572 PyObject *TrajectoryPy::_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 PersistencePy::_getattr(attr);
00633 }
00634 else
00635 {
00636 return rvalue;
00637 }
00638 }
00639
00640 int TrajectoryPy::_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 PersistencePy::_setattr(attr, value);
00697 }
00698
00699 Trajectory *TrajectoryPy::getTrajectoryPtr(void) const
00700 {
00701 return static_cast<Trajectory *>(_pcTwinPointer);
00702 }
00703
00704 #if 0
00705
00706
00707
00708
00709 PyObject *TrajectoryPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00710 {
00711
00712 return new TrajectoryPy(new Trajectory);
00713 }
00714
00715
00716 int TrajectoryPy::PyInit(PyObject* , PyObject* )
00717 {
00718 return 0;
00719 }
00720
00721
00722 std::string TrajectoryPy::representation(void) const
00723 {
00724 return std::string("<Trajectory object>");
00725 }
00726
00727 PyObject* TrajectoryPy::insertWaypoints(PyObject *args)
00728 {
00729 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00730 return 0;
00731 }
00732
00733 PyObject* TrajectoryPy::position(PyObject *args)
00734 {
00735 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00736 return 0;
00737 }
00738
00739 PyObject* TrajectoryPy::velocity(PyObject *args)
00740 {
00741 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00742 return 0;
00743 }
00744
00745 PyObject* TrajectoryPy::deleteLast(PyObject *args)
00746 {
00747 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00748 return 0;
00749 }
00750
00751
00752
00753 Py::Float TrajectoryPy::getDuration(void) const
00754 {
00755
00756 throw Py::AttributeError("Not yet implemented");
00757 }
00758
00759 Py::Float TrajectoryPy::getLength(void) const
00760 {
00761
00762 throw Py::AttributeError("Not yet implemented");
00763 }
00764
00765 Py::List TrajectoryPy::getWaypoints(void) const
00766 {
00767
00768 throw Py::AttributeError("Not yet implemented");
00769 }
00770
00771 void TrajectoryPy::setWaypoints(Py::List arg)
00772 {
00773 throw Py::AttributeError("Not yet implemented");
00774 }
00775
00776 PyObject *TrajectoryPy::getCustomAttributes(const char* attr) const
00777 {
00778 return 0;
00779 }
00780
00781 int TrajectoryPy::setCustomAttributes(const char* attr, PyObject *obj)
00782 {
00783 return 0;
00784 }
00785 #endif
00786
00787
00788