ViewProviderDocumentObjectPy.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 ViewProviderDocumentObjectPyImp.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 Gui;
00018 
00020 PyTypeObject ViewProviderDocumentObjectPy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Gui.ViewProviderDocumentObject",     /*tp_name*/
00024     sizeof(ViewProviderDocumentObjectPy),                       /*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     "This is the ViewProvider base class",           /*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     Gui::ViewProviderDocumentObjectPy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Gui::ViewProviderDocumentObjectPy::GetterSetter,                     /*tp_getset */
00055     &Gui::ViewProviderPy::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     Gui::ViewProviderDocumentObjectPy::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 ViewProviderDocumentObjectPy::Methods[] = {
00075     {"update",
00076         (PyCFunction) staticCallback_update,
00077         METH_VARARGS,
00078         "Update the view representation of the object"
00079     },
00080     {NULL, NULL, 0, NULL}               /* Sentinel */
00081 };
00082 
00083 
00084 
00086 PyGetSetDef ViewProviderDocumentObjectPy::GetterSetter[] = {
00087     {"Object",
00088         (getter) staticCallback_getObject,
00089         (setter) staticCallback_setObject, 
00090         "Return the associated data object",
00091         NULL
00092     },
00093     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00094 };
00095 
00096 // update() callback and implementer
00097 // PyObject*  ViewProviderDocumentObjectPy::update(PyObject *args){};
00098 // has to be implemented in ViewProviderDocumentObjectPyImp.cpp
00099 PyObject * ViewProviderDocumentObjectPy::staticCallback_update (PyObject *self, PyObject *args)
00100 {
00101     // test if twin object not allready deleted
00102     if (!((PyObjectBase*) self)->isValid()){
00103         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00104         return NULL;
00105     }
00106 
00107     // test if object is set Const
00108     if (((PyObjectBase*) self)->isConst()){
00109         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00110         return NULL;
00111     }
00112 
00113     try { // catches all exceptions coming up from c++ and generate a python exception
00114         PyObject* ret = ((ViewProviderDocumentObjectPy*)self)->update(args);
00115         if (ret != 0)
00116             ((ViewProviderDocumentObjectPy*)self)->startNotify();
00117         return ret;
00118     }
00119     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00120     {
00121         std::string str;
00122         str += "FreeCAD exception thrown (";
00123         str += e.what();
00124         str += ")";
00125         e.ReportException();
00126         PyErr_SetString(PyExc_Exception,str.c_str());
00127         return NULL;
00128     }
00129     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00130     {
00131         std::string str;
00132         str += "File system exception thrown (";
00133         //str += e.who();
00134         //str += ", ";
00135         str += e.what();
00136         str += ")\n";
00137         Base::Console().Error(str.c_str());
00138         PyErr_SetString(PyExc_Exception,str.c_str());
00139         return NULL;
00140     }
00141     catch(const Py::Exception&)
00142     {
00143         // The exception text is already set
00144         return NULL;
00145     }
00146     catch(const char* e) // catch simple string exceptions
00147     {
00148         Base::Console().Error(e);
00149         PyErr_SetString(PyExc_Exception,e);
00150         return NULL;
00151     }
00152     // in debug not all exceptions will be catched to get the attention of the developer!
00153 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00154     catch(const std::exception& e) // catch other c++ exceptions
00155     {
00156         std::string str;
00157         str += "FC++ exception thrown (";
00158         str += e.what();
00159         str += ")";
00160         Base::Console().Error(str.c_str());
00161         PyErr_SetString(PyExc_Exception,str.c_str());
00162         return NULL;
00163     }
00164     catch(...)  // catch the rest!
00165     {
00166         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00167         return NULL;
00168     }
00169 #endif
00170 }
00171 
00172 // Object() callback and implementer
00173 // PyObject*  ViewProviderDocumentObjectPy::Object(PyObject *args){};
00174 // has to be implemented in ViewProviderDocumentObjectPyImp.cpp
00175 PyObject * ViewProviderDocumentObjectPy::staticCallback_getObject (PyObject *self, void * /*closure*/)
00176 {
00177     if (!((PyObjectBase*) self)->isValid()){
00178         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00179         return NULL;
00180     }
00181 
00182     try {
00183         return Py::new_reference_to(((ViewProviderDocumentObjectPy*)self)->getObject());
00184     } catch (const Py::Exception&) {
00185         // The exception text is already set
00186         return NULL;
00187     } catch (...) {
00188         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Object' of object 'ViewProviderDocumentObject'");
00189         return NULL;
00190     }
00191 }
00192 
00193 int ViewProviderDocumentObjectPy::staticCallback_setObject (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00194 {
00195     if (!((PyObjectBase*) self)->isValid()){
00196         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00197         return -1;
00198     }
00199 
00200     PyErr_SetString(PyExc_AttributeError, "Attribute 'Object' of object 'ViewProviderDocumentObject' is read-only");
00201     return -1;
00202 }
00203 
00204 
00205 
00206 //--------------------------------------------------------------------------
00207 // Parents structure
00208 //--------------------------------------------------------------------------
00209 PyParentObject ViewProviderDocumentObjectPy::Parents[] = { PARENTSGuiViewProviderDocumentObjectPy };
00210 
00211 //--------------------------------------------------------------------------
00212 // Constructor
00213 //--------------------------------------------------------------------------
00214 ViewProviderDocumentObjectPy::ViewProviderDocumentObjectPy(ViewProviderDocumentObject *pcObject, PyTypeObject *T)
00215     : ViewProviderPy(reinterpret_cast<ViewProviderPy::PointerType>(pcObject), T)
00216 {
00217 }
00218 
00219 PyObject *ViewProviderDocumentObjectPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00220 {
00221     // never create such objects with the constructor
00222     PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'ViewProviderDocumentObjectPy'.");
00223  
00224     return 0;
00225 }
00226 
00227 int ViewProviderDocumentObjectPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00228 {
00229     return 0;
00230 }
00231 
00232 //--------------------------------------------------------------------------
00233 // destructor
00234 //--------------------------------------------------------------------------
00235 ViewProviderDocumentObjectPy::~ViewProviderDocumentObjectPy()                                // Everything handled in parent
00236 {
00237 }
00238 
00239 //--------------------------------------------------------------------------
00240 // ViewProviderDocumentObjectPy representation
00241 //--------------------------------------------------------------------------
00242 PyObject *ViewProviderDocumentObjectPy::_repr(void)
00243 {
00244     return Py_BuildValue("s", representation().c_str());
00245 }
00246 
00247 //--------------------------------------------------------------------------
00248 // ViewProviderDocumentObjectPy Attributes
00249 //--------------------------------------------------------------------------
00250 PyObject *ViewProviderDocumentObjectPy::_getattr(char *attr)                            // __getattr__ function: note only need to handle new state
00251 {
00252     try {
00253         // getter method for special Attributes (e.g. dynamic ones)
00254         PyObject *r = getCustomAttributes(attr);
00255         if(r) return r;
00256     }
00257 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00258     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00259     {
00260         std::string str;
00261         str += "FreeCAD exception thrown (";
00262         str += e.what();
00263         str += ")";
00264         e.ReportException();
00265         PyErr_SetString(PyExc_Exception,str.c_str());
00266         return NULL;
00267     }
00268     catch(const std::exception& e) // catch other c++ exceptions
00269     {
00270         std::string str;
00271         str += "FC++ exception thrown (";
00272         str += e.what();
00273         str += ")";
00274         Base::Console().Error(str.c_str());
00275         PyErr_SetString(PyExc_Exception,str.c_str());
00276         return NULL;
00277     }
00278     catch(const Py::Exception&)
00279     {
00280         // The exception text is already set
00281         return NULL;
00282     }
00283     catch(...)  // catch the rest!
00284     {
00285         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00286         return NULL;
00287     }
00288 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00289     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00290     {
00291         std::string str;
00292         str += "FreeCAD exception thrown (";
00293         str += e.what();
00294         str += ")";
00295         e.ReportException();
00296         PyErr_SetString(PyExc_Exception,str.c_str());
00297         return NULL;
00298     }
00299     catch(const Py::Exception&)
00300     {
00301         // The exception text is already set
00302         return NULL;
00303     }
00304 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00305 
00306     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00307     if (rvalue == NULL)
00308     {
00309         PyErr_Clear();
00310         return ViewProviderPy::_getattr(attr);
00311     }
00312     else
00313     {
00314         return rvalue;
00315     }
00316 }
00317 
00318 int ViewProviderDocumentObjectPy::_setattr(char *attr, PyObject *value)         // __setattr__ function: note only need to handle new state
00319 {
00320     try {
00321         // setter for  special Attributes (e.g. dynamic ones)
00322         int r = setCustomAttributes(attr, value);
00323         if(r==1) return 0;
00324     }
00325 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00326     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00327     {
00328         std::string str;
00329         str += "FreeCAD exception thrown (";
00330         str += e.what();
00331         str += ")";
00332         e.ReportException();
00333         PyErr_SetString(PyExc_Exception,str.c_str());
00334         return -1;
00335     }
00336     catch(const std::exception& e) // catch other c++ exceptions
00337     {
00338         std::string str;
00339         str += "FC++ exception thrown (";
00340         str += e.what();
00341         str += ")";
00342         Base::Console().Error(str.c_str());
00343         PyErr_SetString(PyExc_Exception,str.c_str());
00344         return -1;
00345     }
00346     catch(const Py::Exception&)
00347     {
00348         // The exception text is already set
00349         return -1;
00350     }
00351     catch(...)  // catch the rest!
00352     {
00353         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00354         return -1;
00355     }
00356 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00357     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00358     {
00359         std::string str;
00360         str += "FreeCAD exception thrown (";
00361         str += e.what();
00362         str += ")";
00363         e.ReportException();
00364         PyErr_SetString(PyExc_Exception,str.c_str());
00365         return -1;
00366     }
00367     catch(const Py::Exception&)
00368     {
00369         // The exception text is already set
00370         return -1;
00371     }
00372 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00373 
00374     return ViewProviderPy::_setattr(attr, value);
00375 }
00376 
00377 ViewProviderDocumentObject *ViewProviderDocumentObjectPy::getViewProviderDocumentObjectPtr(void) const
00378 {
00379     return static_cast<ViewProviderDocumentObject *>(_pcTwinPointer);
00380 }
00381 
00382 #if 0
00383 /* From here on come the methods you have to implement, but NOT in this module. Implement in ViewProviderDocumentObjectPyImp.cpp! This prototypes 
00384  * are just for convenience when you add a new method.
00385  */
00386 
00387 
00388 // returns a string which represents the object e.g. when printed in python
00389 std::string ViewProviderDocumentObjectPy::representation(void) const
00390 {
00391     return std::string("<ViewProviderDocumentObject object>");
00392 }
00393 
00394 PyObject* ViewProviderDocumentObjectPy::update(PyObject *args)
00395 {
00396     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00397     return 0;
00398 }
00399 
00400 
00401 
00402 Py::Object ViewProviderDocumentObjectPy::getObject(void) const
00403 {
00404     //return Py::Object();
00405     throw Py::AttributeError("Not yet implemented");
00406 }
00407 
00408 PyObject *ViewProviderDocumentObjectPy::getCustomAttributes(const char* attr) const
00409 {
00410     return 0;
00411 }
00412 
00413 int ViewProviderDocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
00414 {
00415     return 0; 
00416 }
00417 #endif
00418 
00419 
00420 

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