FacetPy.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 FacetPyImp.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 Mesh;
00018 
00020 PyTypeObject FacetPy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Mesh.Facet",     /*tp_name*/
00024     sizeof(FacetPy),                       /*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     "Facet in mesh\n"
00046     "This is a facet in a MeshObject. You can get it by e.g. iterating a\n"
00047     "mesh. The facet has a connection to its mesh and allows therefore\n"
00048     "topological operations. It is also possible to create an unbounded facet e.g. to create\n"
00049     "a mesh. In this case the topological operations will fail. The same is\n"
00050     "when you cut the bound to the mesh by calling unbound().\n"
00051     "           ",           /*tp_doc */
00052     0,                                                /*tp_traverse */
00053     0,                                                /*tp_clear */
00054     0,                                                /*tp_richcompare */
00055     0,                                                /*tp_weaklistoffset */
00056     0,                                                /*tp_iter */
00057     0,                                                /*tp_iternext */
00058     Mesh::FacetPy::Methods,                     /*tp_methods */
00059     0,                                                /*tp_members */
00060     Mesh::FacetPy::GetterSetter,                     /*tp_getset */
00061     &Base::PyObjectBase::Type,                        /*tp_base */
00062     0,                                                /*tp_dict */
00063     0,                                                /*tp_descr_get */
00064     0,                                                /*tp_descr_set */
00065     0,                                                /*tp_dictoffset */
00066     __PyInit,                                         /*tp_init */
00067     0,                                                /*tp_alloc */
00068     Mesh::FacetPy::PyMake,/*tp_new */
00069     0,                                                /*tp_free   Low-level free-memory routine */
00070     0,                                                /*tp_is_gc  For PyObject_IS_GC */
00071     0,                                                /*tp_bases */
00072     0,                                                /*tp_mro    method resolution order */
00073     0,                                                /*tp_cache */
00074     0,                                                /*tp_subclasses */
00075     0,                                                /*tp_weaklist */
00076     0                                                 /*tp_del */
00077 };
00078 
00080 PyMethodDef FacetPy::Methods[] = {
00081     {"unbound",
00082         (PyCFunction) staticCallback_unbound,
00083         METH_VARARGS,
00084         "method unbound()\nCut the connection to a MeshObject. The facet becomes\nfree and is more or less a simple facet.\nAfter calling unbound() no topological operation will\nwork!\n                        "
00085     },
00086     {"intersect",
00087         (PyCFunction) staticCallback_intersect,
00088         METH_VARARGS,
00089         "intersect(Facet) -> list \nGet a list of intersection points with another triangle.\n                    "
00090     },
00091     {NULL, NULL, 0, NULL}               /* Sentinel */
00092 };
00093 
00094 
00095 
00097 PyGetSetDef FacetPy::GetterSetter[] = {
00098     {"Index",
00099         (getter) staticCallback_getIndex,
00100         (setter) staticCallback_setIndex, 
00101         "The index of this facet in the MeshObject",
00102         NULL
00103     },
00104     {"Bound",
00105         (getter) staticCallback_getBound,
00106         (setter) staticCallback_setBound, 
00107         "Bound state of the facet",
00108         NULL
00109     },
00110     {"Normal",
00111         (getter) staticCallback_getNormal,
00112         (setter) staticCallback_setNormal, 
00113         "Normal vector of the facet.",
00114         NULL
00115     },
00116     {"Points",
00117         (getter) staticCallback_getPoints,
00118         (setter) staticCallback_setPoints, 
00119         "A list of points of the facet",
00120         NULL
00121     },
00122     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00123 };
00124 
00125 // unbound() callback and implementer
00126 // PyObject*  FacetPy::unbound(PyObject *args){};
00127 // has to be implemented in FacetPyImp.cpp
00128 PyObject * FacetPy::staticCallback_unbound (PyObject *self, PyObject *args)
00129 {
00130     // test if twin object not allready deleted
00131     if (!((PyObjectBase*) self)->isValid()){
00132         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00133         return NULL;
00134     }
00135 
00136     // test if object is set Const
00137     if (((PyObjectBase*) self)->isConst()){
00138         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00139         return NULL;
00140     }
00141 
00142     try { // catches all exceptions coming up from c++ and generate a python exception
00143         PyObject* ret = ((FacetPy*)self)->unbound(args);
00144         if (ret != 0)
00145             ((FacetPy*)self)->startNotify();
00146         return ret;
00147     }
00148     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00149     {
00150         std::string str;
00151         str += "FreeCAD exception thrown (";
00152         str += e.what();
00153         str += ")";
00154         e.ReportException();
00155         PyErr_SetString(PyExc_Exception,str.c_str());
00156         return NULL;
00157     }
00158     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00159     {
00160         std::string str;
00161         str += "File system exception thrown (";
00162         //str += e.who();
00163         //str += ", ";
00164         str += e.what();
00165         str += ")\n";
00166         Base::Console().Error(str.c_str());
00167         PyErr_SetString(PyExc_Exception,str.c_str());
00168         return NULL;
00169     }
00170     catch(const Py::Exception&)
00171     {
00172         // The exception text is already set
00173         return NULL;
00174     }
00175     catch(const char* e) // catch simple string exceptions
00176     {
00177         Base::Console().Error(e);
00178         PyErr_SetString(PyExc_Exception,e);
00179         return NULL;
00180     }
00181     // in debug not all exceptions will be catched to get the attention of the developer!
00182 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00183     catch(const std::exception& e) // catch other c++ exceptions
00184     {
00185         std::string str;
00186         str += "FC++ exception thrown (";
00187         str += e.what();
00188         str += ")";
00189         Base::Console().Error(str.c_str());
00190         PyErr_SetString(PyExc_Exception,str.c_str());
00191         return NULL;
00192     }
00193     catch(...)  // catch the rest!
00194     {
00195         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00196         return NULL;
00197     }
00198 #endif
00199 }
00200 
00201 // intersect() callback and implementer
00202 // PyObject*  FacetPy::intersect(PyObject *args){};
00203 // has to be implemented in FacetPyImp.cpp
00204 PyObject * FacetPy::staticCallback_intersect (PyObject *self, PyObject *args)
00205 {
00206     // test if twin object not allready deleted
00207     if (!((PyObjectBase*) self)->isValid()){
00208         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00209         return NULL;
00210     }
00211 
00212     // test if object is set Const
00213     if (((PyObjectBase*) self)->isConst()){
00214         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00215         return NULL;
00216     }
00217 
00218     try { // catches all exceptions coming up from c++ and generate a python exception
00219         PyObject* ret = ((FacetPy*)self)->intersect(args);
00220         if (ret != 0)
00221             ((FacetPy*)self)->startNotify();
00222         return ret;
00223     }
00224     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00225     {
00226         std::string str;
00227         str += "FreeCAD exception thrown (";
00228         str += e.what();
00229         str += ")";
00230         e.ReportException();
00231         PyErr_SetString(PyExc_Exception,str.c_str());
00232         return NULL;
00233     }
00234     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00235     {
00236         std::string str;
00237         str += "File system exception thrown (";
00238         //str += e.who();
00239         //str += ", ";
00240         str += e.what();
00241         str += ")\n";
00242         Base::Console().Error(str.c_str());
00243         PyErr_SetString(PyExc_Exception,str.c_str());
00244         return NULL;
00245     }
00246     catch(const Py::Exception&)
00247     {
00248         // The exception text is already set
00249         return NULL;
00250     }
00251     catch(const char* e) // catch simple string exceptions
00252     {
00253         Base::Console().Error(e);
00254         PyErr_SetString(PyExc_Exception,e);
00255         return NULL;
00256     }
00257     // in debug not all exceptions will be catched to get the attention of the developer!
00258 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00259     catch(const std::exception& e) // catch other c++ exceptions
00260     {
00261         std::string str;
00262         str += "FC++ exception thrown (";
00263         str += e.what();
00264         str += ")";
00265         Base::Console().Error(str.c_str());
00266         PyErr_SetString(PyExc_Exception,str.c_str());
00267         return NULL;
00268     }
00269     catch(...)  // catch the rest!
00270     {
00271         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00272         return NULL;
00273     }
00274 #endif
00275 }
00276 
00277 // Index() callback and implementer
00278 // PyObject*  FacetPy::Index(PyObject *args){};
00279 // has to be implemented in FacetPyImp.cpp
00280 PyObject * FacetPy::staticCallback_getIndex (PyObject *self, void * /*closure*/)
00281 {
00282     if (!((PyObjectBase*) self)->isValid()){
00283         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00284         return NULL;
00285     }
00286 
00287     try {
00288         return Py::new_reference_to(((FacetPy*)self)->getIndex());
00289     } catch (const Py::Exception&) {
00290         // The exception text is already set
00291         return NULL;
00292     } catch (...) {
00293         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Index' of object 'Facet'");
00294         return NULL;
00295     }
00296 }
00297 
00298 int FacetPy::staticCallback_setIndex (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00299 {
00300     if (!((PyObjectBase*) self)->isValid()){
00301         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00302         return -1;
00303     }
00304 
00305     PyErr_SetString(PyExc_AttributeError, "Attribute 'Index' of object 'Facet' is read-only");
00306     return -1;
00307 }
00308 
00309 // Bound() callback and implementer
00310 // PyObject*  FacetPy::Bound(PyObject *args){};
00311 // has to be implemented in FacetPyImp.cpp
00312 PyObject * FacetPy::staticCallback_getBound (PyObject *self, void * /*closure*/)
00313 {
00314     if (!((PyObjectBase*) self)->isValid()){
00315         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00316         return NULL;
00317     }
00318 
00319     try {
00320         return Py::new_reference_to(((FacetPy*)self)->getBound());
00321     } catch (const Py::Exception&) {
00322         // The exception text is already set
00323         return NULL;
00324     } catch (...) {
00325         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Bound' of object 'Facet'");
00326         return NULL;
00327     }
00328 }
00329 
00330 int FacetPy::staticCallback_setBound (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00331 {
00332     if (!((PyObjectBase*) self)->isValid()){
00333         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00334         return -1;
00335     }
00336 
00337     PyErr_SetString(PyExc_AttributeError, "Attribute 'Bound' of object 'Facet' is read-only");
00338     return -1;
00339 }
00340 
00341 // Normal() callback and implementer
00342 // PyObject*  FacetPy::Normal(PyObject *args){};
00343 // has to be implemented in FacetPyImp.cpp
00344 PyObject * FacetPy::staticCallback_getNormal (PyObject *self, void * /*closure*/)
00345 {
00346     if (!((PyObjectBase*) self)->isValid()){
00347         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00348         return NULL;
00349     }
00350 
00351     try {
00352         return Py::new_reference_to(((FacetPy*)self)->getNormal());
00353     } catch (const Py::Exception&) {
00354         // The exception text is already set
00355         return NULL;
00356     } catch (...) {
00357         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Normal' of object 'Facet'");
00358         return NULL;
00359     }
00360 }
00361 
00362 int FacetPy::staticCallback_setNormal (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00363 {
00364     if (!((PyObjectBase*) self)->isValid()){
00365         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00366         return -1;
00367     }
00368 
00369     PyErr_SetString(PyExc_AttributeError, "Attribute 'Normal' of object 'Facet' is read-only");
00370     return -1;
00371 }
00372 
00373 // Points() callback and implementer
00374 // PyObject*  FacetPy::Points(PyObject *args){};
00375 // has to be implemented in FacetPyImp.cpp
00376 PyObject * FacetPy::staticCallback_getPoints (PyObject *self, void * /*closure*/)
00377 {
00378     if (!((PyObjectBase*) self)->isValid()){
00379         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00380         return NULL;
00381     }
00382 
00383     try {
00384         return Py::new_reference_to(((FacetPy*)self)->getPoints());
00385     } catch (const Py::Exception&) {
00386         // The exception text is already set
00387         return NULL;
00388     } catch (...) {
00389         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Points' of object 'Facet'");
00390         return NULL;
00391     }
00392 }
00393 
00394 int FacetPy::staticCallback_setPoints (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00395 {
00396     if (!((PyObjectBase*) self)->isValid()){
00397         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00398         return -1;
00399     }
00400 
00401     PyErr_SetString(PyExc_AttributeError, "Attribute 'Points' of object 'Facet' is read-only");
00402     return -1;
00403 }
00404 
00405 
00406 
00407 //--------------------------------------------------------------------------
00408 // Parents structure
00409 //--------------------------------------------------------------------------
00410 PyParentObject FacetPy::Parents[] = { PARENTSMeshFacetPy };
00411 
00412 //--------------------------------------------------------------------------
00413 // Constructor
00414 //--------------------------------------------------------------------------
00415 FacetPy::FacetPy(Facet *pcObject, PyTypeObject *T)
00416     : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00417 {
00418 }
00419 
00420 
00421 //--------------------------------------------------------------------------
00422 // destructor
00423 //--------------------------------------------------------------------------
00424 FacetPy::~FacetPy()                                // Everything handled in parent
00425 {
00426     // delete the handled object when the PyObject dies
00427     FacetPy::PointerType ptr = reinterpret_cast<FacetPy::PointerType>(_pcTwinPointer);
00428     delete ptr;
00429 }
00430 
00431 //--------------------------------------------------------------------------
00432 // FacetPy representation
00433 //--------------------------------------------------------------------------
00434 PyObject *FacetPy::_repr(void)
00435 {
00436     return Py_BuildValue("s", representation().c_str());
00437 }
00438 
00439 //--------------------------------------------------------------------------
00440 // FacetPy Attributes
00441 //--------------------------------------------------------------------------
00442 PyObject *FacetPy::_getattr(char *attr)                         // __getattr__ function: note only need to handle new state
00443 {
00444     try {
00445         // getter method for special Attributes (e.g. dynamic ones)
00446         PyObject *r = getCustomAttributes(attr);
00447         if(r) return r;
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 NULL;
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 NULL;
00469     }
00470     catch(const Py::Exception&)
00471     {
00472         // The exception text is already set
00473         return NULL;
00474     }
00475     catch(...)  // catch the rest!
00476     {
00477         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00478         return NULL;
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 NULL;
00490     }
00491     catch(const Py::Exception&)
00492     {
00493         // The exception text is already set
00494         return NULL;
00495     }
00496 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00497 
00498     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00499     if (rvalue == NULL)
00500     {
00501         PyErr_Clear();
00502         return PyObjectBase::_getattr(attr);
00503     }
00504     else
00505     {
00506         return rvalue;
00507     }
00508 }
00509 
00510 int FacetPy::_setattr(char *attr, PyObject *value)      // __setattr__ function: note only need to handle new state
00511 {
00512     try {
00513         // setter for  special Attributes (e.g. dynamic ones)
00514         int r = setCustomAttributes(attr, value);
00515         if(r==1) return 0;
00516     }
00517 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00518     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00519     {
00520         std::string str;
00521         str += "FreeCAD exception thrown (";
00522         str += e.what();
00523         str += ")";
00524         e.ReportException();
00525         PyErr_SetString(PyExc_Exception,str.c_str());
00526         return -1;
00527     }
00528     catch(const std::exception& e) // catch other c++ exceptions
00529     {
00530         std::string str;
00531         str += "FC++ exception thrown (";
00532         str += e.what();
00533         str += ")";
00534         Base::Console().Error(str.c_str());
00535         PyErr_SetString(PyExc_Exception,str.c_str());
00536         return -1;
00537     }
00538     catch(const Py::Exception&)
00539     {
00540         // The exception text is already set
00541         return -1;
00542     }
00543     catch(...)  // catch the rest!
00544     {
00545         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00546         return -1;
00547     }
00548 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00549     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00550     {
00551         std::string str;
00552         str += "FreeCAD exception thrown (";
00553         str += e.what();
00554         str += ")";
00555         e.ReportException();
00556         PyErr_SetString(PyExc_Exception,str.c_str());
00557         return -1;
00558     }
00559     catch(const Py::Exception&)
00560     {
00561         // The exception text is already set
00562         return -1;
00563     }
00564 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00565 
00566     return PyObjectBase::_setattr(attr, value);
00567 }
00568 
00569 Facet *FacetPy::getFacetPtr(void) const
00570 {
00571     return static_cast<Facet *>(_pcTwinPointer);
00572 }
00573 
00574 #if 0
00575 /* From here on come the methods you have to implement, but NOT in this module. Implement in FacetPyImp.cpp! This prototypes 
00576  * are just for convenience when you add a new method.
00577  */
00578 
00579 PyObject *FacetPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00580 {
00581     // create a new instance of FacetPy and the Twin object 
00582     return new FacetPy(new Facet);
00583 }
00584 
00585 // constructor method
00586 int FacetPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00587 {
00588     return 0;
00589 }
00590 
00591 // returns a string which represents the object e.g. when printed in python
00592 std::string FacetPy::representation(void) const
00593 {
00594     return std::string("<Facet object>");
00595 }
00596 
00597 PyObject* FacetPy::unbound(PyObject *args)
00598 {
00599     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00600     return 0;
00601 }
00602 
00603 PyObject* FacetPy::intersect(PyObject *args)
00604 {
00605     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00606     return 0;
00607 }
00608 
00609 
00610 
00611 Py::Int FacetPy::getIndex(void) const
00612 {
00613     //return Py::Int();
00614     throw Py::AttributeError("Not yet implemented");
00615 }
00616 
00617 Py::Boolean FacetPy::getBound(void) const
00618 {
00619     //return Py::Boolean();
00620     throw Py::AttributeError("Not yet implemented");
00621 }
00622 
00623 Py::Object FacetPy::getNormal(void) const
00624 {
00625     //return Py::Object();
00626     throw Py::AttributeError("Not yet implemented");
00627 }
00628 
00629 Py::List FacetPy::getPoints(void) const
00630 {
00631     //return Py::List();
00632     throw Py::AttributeError("Not yet implemented");
00633 }
00634 
00635 PyObject *FacetPy::getCustomAttributes(const char* attr) const
00636 {
00637     return 0;
00638 }
00639 
00640 int FacetPy::setCustomAttributes(const char* attr, PyObject *obj)
00641 {
00642     return 0; 
00643 }
00644 #endif
00645 
00646 
00647 

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