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 RobotObjectPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Robot.RobotObject",
00024 sizeof(RobotObjectPy),
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 "Robot document object",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Robot::RobotObjectPy::Methods,
00053 0,
00054 Robot::RobotObjectPy::GetterSetter,
00055 &App::DocumentObjectPy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Robot::RobotObjectPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef RobotObjectPy::Methods[] = {
00075 {"getRobot",
00076 (PyCFunction) staticCallback_getRobot,
00077 METH_VARARGS,
00078 "\n Returns a copy of the robot. Be aware, the robot behaves the same\n like the robot of the object but is a copy!\n "
00079 },
00080 {NULL, NULL, 0, NULL}
00081 };
00082
00083
00084
00086 PyGetSetDef RobotObjectPy::GetterSetter[] = {
00087 {NULL, NULL, NULL, NULL, NULL}
00088 };
00089
00090
00091
00092
00093 PyObject * RobotObjectPy::staticCallback_getRobot (PyObject *self, PyObject *args)
00094 {
00095
00096 if (!((PyObjectBase*) self)->isValid()){
00097 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00098 return NULL;
00099 }
00100
00101
00102 if (((PyObjectBase*) self)->isConst()){
00103 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00104 return NULL;
00105 }
00106
00107 try {
00108 PyObject* ret = ((RobotObjectPy*)self)->getRobot(args);
00109 if (ret != 0)
00110 ((RobotObjectPy*)self)->startNotify();
00111 return ret;
00112 }
00113 catch(const Base::Exception& e)
00114 {
00115 std::string str;
00116 str += "FreeCAD exception thrown (";
00117 str += e.what();
00118 str += ")";
00119 e.ReportException();
00120 PyErr_SetString(PyExc_Exception,str.c_str());
00121 return NULL;
00122 }
00123 catch(const boost::filesystem::filesystem_error& e)
00124 {
00125 std::string str;
00126 str += "File system exception thrown (";
00127
00128
00129 str += e.what();
00130 str += ")\n";
00131 Base::Console().Error(str.c_str());
00132 PyErr_SetString(PyExc_Exception,str.c_str());
00133 return NULL;
00134 }
00135 catch(const Py::Exception&)
00136 {
00137
00138 return NULL;
00139 }
00140 catch(const char* e)
00141 {
00142 Base::Console().Error(e);
00143 PyErr_SetString(PyExc_Exception,e);
00144 return NULL;
00145 }
00146
00147 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00148 catch(const std::exception& e)
00149 {
00150 std::string str;
00151 str += "FC++ exception thrown (";
00152 str += e.what();
00153 str += ")";
00154 Base::Console().Error(str.c_str());
00155 PyErr_SetString(PyExc_Exception,str.c_str());
00156 return NULL;
00157 }
00158 catch(...)
00159 {
00160 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00161 return NULL;
00162 }
00163 #endif
00164 }
00165
00166
00167
00168
00169
00170
00171 PyParentObject RobotObjectPy::Parents[] = { PARENTSRobotRobotObjectPy };
00172
00173
00174
00175
00176 RobotObjectPy::RobotObjectPy(RobotObject *pcObject, PyTypeObject *T)
00177 : DocumentObjectPy(reinterpret_cast<DocumentObjectPy::PointerType>(pcObject), T)
00178 {
00179 }
00180
00181 PyObject *RobotObjectPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00182 {
00183
00184 PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'RobotObjectPy'.");
00185
00186 return 0;
00187 }
00188
00189 int RobotObjectPy::PyInit(PyObject* , PyObject* )
00190 {
00191 return 0;
00192 }
00193
00194
00195
00196
00197 RobotObjectPy::~RobotObjectPy()
00198 {
00199 }
00200
00201
00202
00203
00204 PyObject *RobotObjectPy::_repr(void)
00205 {
00206 return Py_BuildValue("s", representation().c_str());
00207 }
00208
00209
00210
00211
00212 PyObject *RobotObjectPy::_getattr(char *attr)
00213 {
00214 try {
00215
00216 PyObject *r = getCustomAttributes(attr);
00217 if(r) return r;
00218 }
00219 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00220 catch(const Base::Exception& e)
00221 {
00222 std::string str;
00223 str += "FreeCAD exception thrown (";
00224 str += e.what();
00225 str += ")";
00226 e.ReportException();
00227 PyErr_SetString(PyExc_Exception,str.c_str());
00228 return NULL;
00229 }
00230 catch(const std::exception& e)
00231 {
00232 std::string str;
00233 str += "FC++ exception thrown (";
00234 str += e.what();
00235 str += ")";
00236 Base::Console().Error(str.c_str());
00237 PyErr_SetString(PyExc_Exception,str.c_str());
00238 return NULL;
00239 }
00240 catch(const Py::Exception&)
00241 {
00242
00243 return NULL;
00244 }
00245 catch(...)
00246 {
00247 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00248 return NULL;
00249 }
00250 #else // DONT_CATCH_CXX_EXCEPTIONS
00251 catch(const Base::Exception& e)
00252 {
00253 std::string str;
00254 str += "FreeCAD exception thrown (";
00255 str += e.what();
00256 str += ")";
00257 e.ReportException();
00258 PyErr_SetString(PyExc_Exception,str.c_str());
00259 return NULL;
00260 }
00261 catch(const Py::Exception&)
00262 {
00263
00264 return NULL;
00265 }
00266 #endif // DONT_CATCH_CXX_EXCEPTIONS
00267
00268 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00269 if (rvalue == NULL)
00270 {
00271 PyErr_Clear();
00272 return DocumentObjectPy::_getattr(attr);
00273 }
00274 else
00275 {
00276 return rvalue;
00277 }
00278 }
00279
00280 int RobotObjectPy::_setattr(char *attr, PyObject *value)
00281 {
00282 try {
00283
00284 int r = setCustomAttributes(attr, value);
00285 if(r==1) return 0;
00286 }
00287 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00288 catch(const Base::Exception& e)
00289 {
00290 std::string str;
00291 str += "FreeCAD exception thrown (";
00292 str += e.what();
00293 str += ")";
00294 e.ReportException();
00295 PyErr_SetString(PyExc_Exception,str.c_str());
00296 return -1;
00297 }
00298 catch(const std::exception& e)
00299 {
00300 std::string str;
00301 str += "FC++ exception thrown (";
00302 str += e.what();
00303 str += ")";
00304 Base::Console().Error(str.c_str());
00305 PyErr_SetString(PyExc_Exception,str.c_str());
00306 return -1;
00307 }
00308 catch(const Py::Exception&)
00309 {
00310
00311 return -1;
00312 }
00313 catch(...)
00314 {
00315 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00316 return -1;
00317 }
00318 #else // DONT_CATCH_CXX_EXCEPTIONS
00319 catch(const Base::Exception& e)
00320 {
00321 std::string str;
00322 str += "FreeCAD exception thrown (";
00323 str += e.what();
00324 str += ")";
00325 e.ReportException();
00326 PyErr_SetString(PyExc_Exception,str.c_str());
00327 return -1;
00328 }
00329 catch(const Py::Exception&)
00330 {
00331
00332 return -1;
00333 }
00334 #endif // DONT_CATCH_CXX_EXCEPTIONS
00335
00336 return DocumentObjectPy::_setattr(attr, value);
00337 }
00338
00339 RobotObject *RobotObjectPy::getRobotObjectPtr(void) const
00340 {
00341 return static_cast<RobotObject *>(_pcTwinPointer);
00342 }
00343
00344 #if 0
00345
00346
00347
00348
00349
00350
00351 std::string RobotObjectPy::representation(void) const
00352 {
00353 return std::string("<RobotObject object>");
00354 }
00355
00356 PyObject* RobotObjectPy::getRobot(PyObject *args)
00357 {
00358 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00359 return 0;
00360 }
00361
00362
00363
00364 PyObject *RobotObjectPy::getCustomAttributes(const char* attr) const
00365 {
00366 return 0;
00367 }
00368
00369 int RobotObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
00370 {
00371 return 0;
00372 }
00373 #endif
00374
00375
00376