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

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