RobotObjectPy.cpp

Go to the documentation of this file.
00001 
00002 // This file is generated by src/Tools/generateTemaplates/templateClassPyExport.py out of the .XML file
00003 // Every change you make here get lost at the next full rebuild!
00004 // This File is normaly build as an include in RobotObjectPyImp.cpp! Its not intended to be in a project!
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,                                                /*ob_size*/
00023     "Robot.RobotObject",     /*tp_name*/
00024     sizeof(RobotObjectPy),                       /*tp_basicsize*/
00025     0,                                                /*tp_itemsize*/
00026     /* methods */
00027     PyDestructor,                                     /*tp_dealloc*/
00028     0,                                                /*tp_print*/
00029     __getattr,                                        /*tp_getattr*/
00030     __setattr,                                        /*tp_setattr*/
00031     0,                                                /*tp_compare*/
00032     __repr,                                           /*tp_repr*/
00033     0,                                                /*tp_as_number*/
00034     0,                                                /*tp_as_sequence*/
00035     0,                                                /*tp_as_mapping*/
00036     0,                                                /*tp_hash*/
00037     0,                                                /*tp_call */
00038     0,                                                /*tp_str  */
00039     0,                                                /*tp_getattro*/
00040     0,                                                /*tp_setattro*/
00041     /* --- Functions to access object as input/output buffer ---------*/
00042     0,                                                /* tp_as_buffer */
00043     /* --- Flags to define presence of optional/expanded features */
00044     Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS,        /*tp_flags */
00045     "Robot document object",           /*tp_doc */
00046     0,                                                /*tp_traverse */
00047     0,                                                /*tp_clear */
00048     0,                                                /*tp_richcompare */
00049     0,                                                /*tp_weaklistoffset */
00050     0,                                                /*tp_iter */
00051     0,                                                /*tp_iternext */
00052     Robot::RobotObjectPy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Robot::RobotObjectPy::GetterSetter,                     /*tp_getset */
00055     &App::DocumentObjectPy::Type,                        /*tp_base */
00056     0,                                                /*tp_dict */
00057     0,                                                /*tp_descr_get */
00058     0,                                                /*tp_descr_set */
00059     0,                                                /*tp_dictoffset */
00060     __PyInit,                                         /*tp_init */
00061     0,                                                /*tp_alloc */
00062     Robot::RobotObjectPy::PyMake,/*tp_new */
00063     0,                                                /*tp_free   Low-level free-memory routine */
00064     0,                                                /*tp_is_gc  For PyObject_IS_GC */
00065     0,                                                /*tp_bases */
00066     0,                                                /*tp_mro    method resolution order */
00067     0,                                                /*tp_cache */
00068     0,                                                /*tp_subclasses */
00069     0,                                                /*tp_weaklist */
00070     0                                                 /*tp_del */
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}               /* Sentinel */
00081 };
00082 
00083 
00084 
00086 PyGetSetDef RobotObjectPy::GetterSetter[] = {
00087     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00088 };
00089 
00090 // getRobot() callback and implementer
00091 // PyObject*  RobotObjectPy::getRobot(PyObject *args){};
00092 // has to be implemented in RobotObjectPyImp.cpp
00093 PyObject * RobotObjectPy::staticCallback_getRobot (PyObject *self, PyObject *args)
00094 {
00095     // test if twin object not allready deleted
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     // test if object is set Const
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 { // catches all exceptions coming up from c++ and generate a python exception
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) // catch the FreeCAD exceptions
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) // catch boost filesystem exception
00124     {
00125         std::string str;
00126         str += "File system exception thrown (";
00127         //str += e.who();
00128         //str += ", ";
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         // The exception text is already set
00138         return NULL;
00139     }
00140     catch(const char* e) // catch simple string exceptions
00141     {
00142         Base::Console().Error(e);
00143         PyErr_SetString(PyExc_Exception,e);
00144         return NULL;
00145     }
00146     // in debug not all exceptions will be catched to get the attention of the developer!
00147 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00148     catch(const std::exception& e) // catch other c++ exceptions
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(...)  // catch the rest!
00159     {
00160         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00161         return NULL;
00162     }
00163 #endif
00164 }
00165 
00166 
00167 
00168 //--------------------------------------------------------------------------
00169 // Parents structure
00170 //--------------------------------------------------------------------------
00171 PyParentObject RobotObjectPy::Parents[] = { PARENTSRobotRobotObjectPy };
00172 
00173 //--------------------------------------------------------------------------
00174 // Constructor
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 *)  // Python wrapper
00182 {
00183     // never create such objects with the constructor
00184     PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'RobotObjectPy'.");
00185  
00186     return 0;
00187 }
00188 
00189 int RobotObjectPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00190 {
00191     return 0;
00192 }
00193 
00194 //--------------------------------------------------------------------------
00195 // destructor
00196 //--------------------------------------------------------------------------
00197 RobotObjectPy::~RobotObjectPy()                                // Everything handled in parent
00198 {
00199 }
00200 
00201 //--------------------------------------------------------------------------
00202 // RobotObjectPy representation
00203 //--------------------------------------------------------------------------
00204 PyObject *RobotObjectPy::_repr(void)
00205 {
00206     return Py_BuildValue("s", representation().c_str());
00207 }
00208 
00209 //--------------------------------------------------------------------------
00210 // RobotObjectPy Attributes
00211 //--------------------------------------------------------------------------
00212 PyObject *RobotObjectPy::_getattr(char *attr)                           // __getattr__ function: note only need to handle new state
00213 {
00214     try {
00215         // getter method for special Attributes (e.g. dynamic ones)
00216         PyObject *r = getCustomAttributes(attr);
00217         if(r) return r;
00218     }
00219 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00220     catch(const Base::Exception& e) // catch the FreeCAD exceptions
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) // catch other c++ exceptions
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         // The exception text is already set
00243         return NULL;
00244     }
00245     catch(...)  // catch the rest!
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) // catch the FreeCAD exceptions
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         // The exception text is already set
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)        // __setattr__ function: note only need to handle new state
00281 {
00282     try {
00283         // setter for  special Attributes (e.g. dynamic ones)
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) // catch the FreeCAD exceptions
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) // catch other c++ exceptions
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         // The exception text is already set
00311         return -1;
00312     }
00313     catch(...)  // catch the rest!
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) // catch the FreeCAD exceptions
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         // The exception text is already set
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 /* From here on come the methods you have to implement, but NOT in this module. Implement in RobotObjectPyImp.cpp! This prototypes 
00346  * are just for convenience when you add a new method.
00347  */
00348 
00349 
00350 // returns a string which represents the object e.g. when printed in python
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 

Generated on Wed Nov 23 19:00:36 2011 for FreeCAD by  doxygen 1.6.1