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

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