ViewProviderPythonFeaturePy.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 ViewProviderPythonFeaturePyImp.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 ViewProviderPythonFeaturePy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Gui.ViewProviderPythonFeature",     /*tp_name*/
00024     sizeof(ViewProviderPythonFeaturePy),                       /*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 view provider class for Python features",           /*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::ViewProviderPythonFeaturePy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Gui::ViewProviderPythonFeaturePy::GetterSetter,                     /*tp_getset */
00055     &Gui::ViewProviderDocumentObjectPy::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::ViewProviderPythonFeaturePy::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 ViewProviderPythonFeaturePy::Methods[] = {
00075     {"addDisplayMode",
00076         (PyCFunction) staticCallback_addDisplayMode,
00077         METH_VARARGS,
00078         "Add a new display mode to the view provider"
00079     },
00080     {"addProperty",
00081         (PyCFunction) staticCallback_addProperty,
00082         METH_VARARGS,
00083         "\n                                     addProperty(string, string) -- Add a generic property.\n                                        The first argument specifies the type, the second the\n                                 name of the property.\n                         "
00084     },
00085     {"supportedProperties",
00086         (PyCFunction) staticCallback_supportedProperties,
00087         METH_VARARGS,
00088         "A list of supported property types"
00089     },
00090     {NULL, NULL, 0, NULL}               /* Sentinel */
00091 };
00092 
00093 
00094 
00096 PyGetSetDef ViewProviderPythonFeaturePy::GetterSetter[] = {
00097     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00098 };
00099 
00100 // addDisplayMode() callback and implementer
00101 // PyObject*  ViewProviderPythonFeaturePy::addDisplayMode(PyObject *args){};
00102 // has to be implemented in ViewProviderPythonFeaturePyImp.cpp
00103 PyObject * ViewProviderPythonFeaturePy::staticCallback_addDisplayMode (PyObject *self, PyObject *args)
00104 {
00105     // test if twin object not allready deleted
00106     if (!((PyObjectBase*) self)->isValid()){
00107         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00108         return NULL;
00109     }
00110 
00111     // test if object is set Const
00112     if (((PyObjectBase*) self)->isConst()){
00113         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00114         return NULL;
00115     }
00116 
00117     try { // catches all exceptions coming up from c++ and generate a python exception
00118         PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->addDisplayMode(args);
00119         if (ret != 0)
00120             ((ViewProviderPythonFeaturePy*)self)->startNotify();
00121         return ret;
00122     }
00123     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00124     {
00125         std::string str;
00126         str += "FreeCAD exception thrown (";
00127         str += e.what();
00128         str += ")";
00129         e.ReportException();
00130         PyErr_SetString(PyExc_Exception,str.c_str());
00131         return NULL;
00132     }
00133     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00134     {
00135         std::string str;
00136         str += "File system exception thrown (";
00137         //str += e.who();
00138         //str += ", ";
00139         str += e.what();
00140         str += ")\n";
00141         Base::Console().Error(str.c_str());
00142         PyErr_SetString(PyExc_Exception,str.c_str());
00143         return NULL;
00144     }
00145     catch(const Py::Exception&)
00146     {
00147         // The exception text is already set
00148         return NULL;
00149     }
00150     catch(const char* e) // catch simple string exceptions
00151     {
00152         Base::Console().Error(e);
00153         PyErr_SetString(PyExc_Exception,e);
00154         return NULL;
00155     }
00156     // in debug not all exceptions will be catched to get the attention of the developer!
00157 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00158     catch(const std::exception& e) // catch other c++ exceptions
00159     {
00160         std::string str;
00161         str += "FC++ exception thrown (";
00162         str += e.what();
00163         str += ")";
00164         Base::Console().Error(str.c_str());
00165         PyErr_SetString(PyExc_Exception,str.c_str());
00166         return NULL;
00167     }
00168     catch(...)  // catch the rest!
00169     {
00170         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00171         return NULL;
00172     }
00173 #endif
00174 }
00175 
00176 // addProperty() callback and implementer
00177 // PyObject*  ViewProviderPythonFeaturePy::addProperty(PyObject *args){};
00178 // has to be implemented in ViewProviderPythonFeaturePyImp.cpp
00179 PyObject * ViewProviderPythonFeaturePy::staticCallback_addProperty (PyObject *self, PyObject *args)
00180 {
00181     // test if twin object not allready deleted
00182     if (!((PyObjectBase*) self)->isValid()){
00183         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00184         return NULL;
00185     }
00186 
00187     // test if object is set Const
00188     if (((PyObjectBase*) self)->isConst()){
00189         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00190         return NULL;
00191     }
00192 
00193     try { // catches all exceptions coming up from c++ and generate a python exception
00194         PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->addProperty(args);
00195         if (ret != 0)
00196             ((ViewProviderPythonFeaturePy*)self)->startNotify();
00197         return ret;
00198     }
00199     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00200     {
00201         std::string str;
00202         str += "FreeCAD exception thrown (";
00203         str += e.what();
00204         str += ")";
00205         e.ReportException();
00206         PyErr_SetString(PyExc_Exception,str.c_str());
00207         return NULL;
00208     }
00209     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00210     {
00211         std::string str;
00212         str += "File system exception thrown (";
00213         //str += e.who();
00214         //str += ", ";
00215         str += e.what();
00216         str += ")\n";
00217         Base::Console().Error(str.c_str());
00218         PyErr_SetString(PyExc_Exception,str.c_str());
00219         return NULL;
00220     }
00221     catch(const Py::Exception&)
00222     {
00223         // The exception text is already set
00224         return NULL;
00225     }
00226     catch(const char* e) // catch simple string exceptions
00227     {
00228         Base::Console().Error(e);
00229         PyErr_SetString(PyExc_Exception,e);
00230         return NULL;
00231     }
00232     // in debug not all exceptions will be catched to get the attention of the developer!
00233 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00234     catch(const std::exception& e) // catch other c++ exceptions
00235     {
00236         std::string str;
00237         str += "FC++ exception thrown (";
00238         str += e.what();
00239         str += ")";
00240         Base::Console().Error(str.c_str());
00241         PyErr_SetString(PyExc_Exception,str.c_str());
00242         return NULL;
00243     }
00244     catch(...)  // catch the rest!
00245     {
00246         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00247         return NULL;
00248     }
00249 #endif
00250 }
00251 
00252 // supportedProperties() callback and implementer
00253 // PyObject*  ViewProviderPythonFeaturePy::supportedProperties(PyObject *args){};
00254 // has to be implemented in ViewProviderPythonFeaturePyImp.cpp
00255 PyObject * ViewProviderPythonFeaturePy::staticCallback_supportedProperties (PyObject *self, PyObject *args)
00256 {
00257     // test if twin object not allready deleted
00258     if (!((PyObjectBase*) self)->isValid()){
00259         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00260         return NULL;
00261     }
00262 
00263     // test if object is set Const
00264     if (((PyObjectBase*) self)->isConst()){
00265         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00266         return NULL;
00267     }
00268 
00269     try { // catches all exceptions coming up from c++ and generate a python exception
00270         PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->supportedProperties(args);
00271         if (ret != 0)
00272             ((ViewProviderPythonFeaturePy*)self)->startNotify();
00273         return ret;
00274     }
00275     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00276     {
00277         std::string str;
00278         str += "FreeCAD exception thrown (";
00279         str += e.what();
00280         str += ")";
00281         e.ReportException();
00282         PyErr_SetString(PyExc_Exception,str.c_str());
00283         return NULL;
00284     }
00285     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00286     {
00287         std::string str;
00288         str += "File system exception thrown (";
00289         //str += e.who();
00290         //str += ", ";
00291         str += e.what();
00292         str += ")\n";
00293         Base::Console().Error(str.c_str());
00294         PyErr_SetString(PyExc_Exception,str.c_str());
00295         return NULL;
00296     }
00297     catch(const Py::Exception&)
00298     {
00299         // The exception text is already set
00300         return NULL;
00301     }
00302     catch(const char* e) // catch simple string exceptions
00303     {
00304         Base::Console().Error(e);
00305         PyErr_SetString(PyExc_Exception,e);
00306         return NULL;
00307     }
00308     // in debug not all exceptions will be catched to get the attention of the developer!
00309 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00310     catch(const std::exception& e) // catch other c++ exceptions
00311     {
00312         std::string str;
00313         str += "FC++ exception thrown (";
00314         str += e.what();
00315         str += ")";
00316         Base::Console().Error(str.c_str());
00317         PyErr_SetString(PyExc_Exception,str.c_str());
00318         return NULL;
00319     }
00320     catch(...)  // catch the rest!
00321     {
00322         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00323         return NULL;
00324     }
00325 #endif
00326 }
00327 
00328 
00329 
00330 //--------------------------------------------------------------------------
00331 // Parents structure
00332 //--------------------------------------------------------------------------
00333 PyParentObject ViewProviderPythonFeaturePy::Parents[] = { PARENTSGuiViewProviderPythonFeaturePy };
00334 
00335 //--------------------------------------------------------------------------
00336 // Constructor
00337 //--------------------------------------------------------------------------
00338 ViewProviderPythonFeaturePy::ViewProviderPythonFeaturePy(ViewProviderDocumentObject *pcObject, PyTypeObject *T)
00339     : ViewProviderDocumentObjectPy(reinterpret_cast<ViewProviderDocumentObjectPy::PointerType>(pcObject), T)
00340 {
00341 }
00342 
00343 PyObject *ViewProviderPythonFeaturePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00344 {
00345     // never create such objects with the constructor
00346     PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'ViewProviderPythonFeaturePy'.");
00347  
00348     return 0;
00349 }
00350 
00351 int ViewProviderPythonFeaturePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00352 {
00353     return 0;
00354 }
00355 
00356 //--------------------------------------------------------------------------
00357 // destructor
00358 //--------------------------------------------------------------------------
00359 ViewProviderPythonFeaturePy::~ViewProviderPythonFeaturePy()                                // Everything handled in parent
00360 {
00361 }
00362 
00363 //--------------------------------------------------------------------------
00364 // ViewProviderPythonFeaturePy representation
00365 //--------------------------------------------------------------------------
00366 PyObject *ViewProviderPythonFeaturePy::_repr(void)
00367 {
00368     return Py_BuildValue("s", representation().c_str());
00369 }
00370 
00371 //--------------------------------------------------------------------------
00372 // ViewProviderPythonFeaturePy Attributes
00373 //--------------------------------------------------------------------------
00374 PyObject *ViewProviderPythonFeaturePy::_getattr(char *attr)                             // __getattr__ function: note only need to handle new state
00375 {
00376     try {
00377         // getter method for special Attributes (e.g. dynamic ones)
00378         PyObject *r = getCustomAttributes(attr);
00379         if(r) return r;
00380     }
00381 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00382     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00383     {
00384         std::string str;
00385         str += "FreeCAD exception thrown (";
00386         str += e.what();
00387         str += ")";
00388         e.ReportException();
00389         PyErr_SetString(PyExc_Exception,str.c_str());
00390         return NULL;
00391     }
00392     catch(const std::exception& e) // catch other c++ exceptions
00393     {
00394         std::string str;
00395         str += "FC++ exception thrown (";
00396         str += e.what();
00397         str += ")";
00398         Base::Console().Error(str.c_str());
00399         PyErr_SetString(PyExc_Exception,str.c_str());
00400         return NULL;
00401     }
00402     catch(const Py::Exception&)
00403     {
00404         // The exception text is already set
00405         return NULL;
00406     }
00407     catch(...)  // catch the rest!
00408     {
00409         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00410         return NULL;
00411     }
00412 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00413     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00414     {
00415         std::string str;
00416         str += "FreeCAD exception thrown (";
00417         str += e.what();
00418         str += ")";
00419         e.ReportException();
00420         PyErr_SetString(PyExc_Exception,str.c_str());
00421         return NULL;
00422     }
00423     catch(const Py::Exception&)
00424     {
00425         // The exception text is already set
00426         return NULL;
00427     }
00428 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00429 
00430     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00431     if (rvalue == NULL)
00432     {
00433         PyErr_Clear();
00434         return ViewProviderDocumentObjectPy::_getattr(attr);
00435     }
00436     else
00437     {
00438         return rvalue;
00439     }
00440 }
00441 
00442 int ViewProviderPythonFeaturePy::_setattr(char *attr, PyObject *value)  // __setattr__ function: note only need to handle new state
00443 {
00444     try {
00445         // setter for  special Attributes (e.g. dynamic ones)
00446         int r = setCustomAttributes(attr, value);
00447         if(r==1) return 0;
00448     }
00449 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00450     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00451     {
00452         std::string str;
00453         str += "FreeCAD exception thrown (";
00454         str += e.what();
00455         str += ")";
00456         e.ReportException();
00457         PyErr_SetString(PyExc_Exception,str.c_str());
00458         return -1;
00459     }
00460     catch(const std::exception& e) // catch other c++ exceptions
00461     {
00462         std::string str;
00463         str += "FC++ exception thrown (";
00464         str += e.what();
00465         str += ")";
00466         Base::Console().Error(str.c_str());
00467         PyErr_SetString(PyExc_Exception,str.c_str());
00468         return -1;
00469     }
00470     catch(const Py::Exception&)
00471     {
00472         // The exception text is already set
00473         return -1;
00474     }
00475     catch(...)  // catch the rest!
00476     {
00477         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00478         return -1;
00479     }
00480 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00481     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00482     {
00483         std::string str;
00484         str += "FreeCAD exception thrown (";
00485         str += e.what();
00486         str += ")";
00487         e.ReportException();
00488         PyErr_SetString(PyExc_Exception,str.c_str());
00489         return -1;
00490     }
00491     catch(const Py::Exception&)
00492     {
00493         // The exception text is already set
00494         return -1;
00495     }
00496 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00497 
00498     return ViewProviderDocumentObjectPy::_setattr(attr, value);
00499 }
00500 
00501 ViewProviderDocumentObject *ViewProviderPythonFeaturePy::getViewProviderPythonFeaturePtr(void) const
00502 {
00503     return static_cast<ViewProviderDocumentObject *>(_pcTwinPointer);
00504 }
00505 
00506 #if 0
00507 /* From here on come the methods you have to implement, but NOT in this module. Implement in ViewProviderPythonFeaturePyImp.cpp! This prototypes 
00508  * are just for convenience when you add a new method.
00509  */
00510 
00511 
00512 // returns a string which represents the object e.g. when printed in python
00513 std::string ViewProviderPythonFeaturePy::representation(void) const
00514 {
00515     return std::string("<ViewProviderPythonFeature object>");
00516 }
00517 
00518 PyObject* ViewProviderPythonFeaturePy::addDisplayMode(PyObject *args)
00519 {
00520     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00521     return 0;
00522 }
00523 
00524 PyObject* ViewProviderPythonFeaturePy::addProperty(PyObject *args)
00525 {
00526     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00527     return 0;
00528 }
00529 
00530 PyObject* ViewProviderPythonFeaturePy::supportedProperties(PyObject *args)
00531 {
00532     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00533     return 0;
00534 }
00535 
00536 
00537 
00538 PyObject *ViewProviderPythonFeaturePy::getCustomAttributes(const char* attr) const
00539 {
00540     return 0;
00541 }
00542 
00543 int ViewProviderPythonFeaturePy::setCustomAttributes(const char* attr, PyObject *obj)
00544 {
00545     return 0; 
00546 }
00547 #endif
00548 
00549 
00550 

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