TopoShapeSolidPy.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 TopoShapeSolidPyImp.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 TopoShapeSolidPy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Part.TopoShape",     /*tp_name*/
00024     sizeof(TopoShapeSolidPy),                       /*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 solid out of the shells of a shape",           /*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::TopoShapeSolidPy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Part::TopoShapeSolidPy::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::TopoShapeSolidPy::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 TopoShapeSolidPy::Methods[] = {
00075     {NULL, NULL, 0, NULL}               /* Sentinel */
00076 };
00077 
00078 
00079 
00081 PyGetSetDef TopoShapeSolidPy::GetterSetter[] = {
00082     {"CenterOfMass",
00083         (getter) staticCallback_getCenterOfMass,
00084         (setter) staticCallback_setCenterOfMass, 
00085         "Returns the center of mass of the current system.\nIf the gravitational field is uniform, it is the center of gravity.\nThe coordinates returned for the center of mass are expressed in the\nabsolute Cartesian coordinate system.",
00086         NULL
00087     },
00088     {"OuterShell",
00089         (getter) staticCallback_getOuterShell,
00090         (setter) staticCallback_setOuterShell, 
00091         "\nReturns the outer most shell of this solid or an null\nshape if the solid has no shells",
00092         NULL
00093     },
00094     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00095 };
00096 
00097 // CenterOfMass() callback and implementer
00098 // PyObject*  TopoShapeSolidPy::CenterOfMass(PyObject *args){};
00099 // has to be implemented in TopoShapeSolidPyImp.cpp
00100 PyObject * TopoShapeSolidPy::staticCallback_getCenterOfMass (PyObject *self, void * /*closure*/)
00101 {
00102     if (!((PyObjectBase*) self)->isValid()){
00103         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00104         return NULL;
00105     }
00106 
00107     try {
00108         return Py::new_reference_to(((TopoShapeSolidPy*)self)->getCenterOfMass());
00109     } catch (const Py::Exception&) {
00110         // The exception text is already set
00111         return NULL;
00112     } catch (...) {
00113         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'CenterOfMass' of object 'TopoShape'");
00114         return NULL;
00115     }
00116 }
00117 
00118 int TopoShapeSolidPy::staticCallback_setCenterOfMass (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00119 {
00120     if (!((PyObjectBase*) self)->isValid()){
00121         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00122         return -1;
00123     }
00124 
00125     PyErr_SetString(PyExc_AttributeError, "Attribute 'CenterOfMass' of object 'TopoShape' is read-only");
00126     return -1;
00127 }
00128 
00129 // OuterShell() callback and implementer
00130 // PyObject*  TopoShapeSolidPy::OuterShell(PyObject *args){};
00131 // has to be implemented in TopoShapeSolidPyImp.cpp
00132 PyObject * TopoShapeSolidPy::staticCallback_getOuterShell (PyObject *self, void * /*closure*/)
00133 {
00134     if (!((PyObjectBase*) self)->isValid()){
00135         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00136         return NULL;
00137     }
00138 
00139     try {
00140         return Py::new_reference_to(((TopoShapeSolidPy*)self)->getOuterShell());
00141     } catch (const Py::Exception&) {
00142         // The exception text is already set
00143         return NULL;
00144     } catch (...) {
00145         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'OuterShell' of object 'TopoShape'");
00146         return NULL;
00147     }
00148 }
00149 
00150 int TopoShapeSolidPy::staticCallback_setOuterShell (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00151 {
00152     if (!((PyObjectBase*) self)->isValid()){
00153         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00154         return -1;
00155     }
00156 
00157     PyErr_SetString(PyExc_AttributeError, "Attribute 'OuterShell' of object 'TopoShape' is read-only");
00158     return -1;
00159 }
00160 
00161 
00162 
00163 //--------------------------------------------------------------------------
00164 // Parents structure
00165 //--------------------------------------------------------------------------
00166 PyParentObject TopoShapeSolidPy::Parents[] = { PARENTSPartTopoShapeSolidPy };
00167 
00168 //--------------------------------------------------------------------------
00169 // Constructor
00170 //--------------------------------------------------------------------------
00171 TopoShapeSolidPy::TopoShapeSolidPy(TopoShape *pcObject, PyTypeObject *T)
00172     : TopoShapePy(reinterpret_cast<TopoShapePy::PointerType>(pcObject), T)
00173 {
00174 }
00175 
00176 
00177 //--------------------------------------------------------------------------
00178 // destructor
00179 //--------------------------------------------------------------------------
00180 TopoShapeSolidPy::~TopoShapeSolidPy()                                // Everything handled in parent
00181 {
00182 }
00183 
00184 //--------------------------------------------------------------------------
00185 // TopoShapeSolidPy representation
00186 //--------------------------------------------------------------------------
00187 PyObject *TopoShapeSolidPy::_repr(void)
00188 {
00189     return Py_BuildValue("s", representation().c_str());
00190 }
00191 
00192 //--------------------------------------------------------------------------
00193 // TopoShapeSolidPy Attributes
00194 //--------------------------------------------------------------------------
00195 PyObject *TopoShapeSolidPy::_getattr(char *attr)                                // __getattr__ function: note only need to handle new state
00196 {
00197     try {
00198         // getter method for special Attributes (e.g. dynamic ones)
00199         PyObject *r = getCustomAttributes(attr);
00200         if(r) return r;
00201     }
00202 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00203     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00204     {
00205         std::string str;
00206         str += "FreeCAD exception thrown (";
00207         str += e.what();
00208         str += ")";
00209         e.ReportException();
00210         PyErr_SetString(PyExc_Exception,str.c_str());
00211         return NULL;
00212     }
00213     catch(const std::exception& e) // catch other c++ exceptions
00214     {
00215         std::string str;
00216         str += "FC++ exception thrown (";
00217         str += e.what();
00218         str += ")";
00219         Base::Console().Error(str.c_str());
00220         PyErr_SetString(PyExc_Exception,str.c_str());
00221         return NULL;
00222     }
00223     catch(const Py::Exception&)
00224     {
00225         // The exception text is already set
00226         return NULL;
00227     }
00228     catch(...)  // catch the rest!
00229     {
00230         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00231         return NULL;
00232     }
00233 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00234     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00235     {
00236         std::string str;
00237         str += "FreeCAD exception thrown (";
00238         str += e.what();
00239         str += ")";
00240         e.ReportException();
00241         PyErr_SetString(PyExc_Exception,str.c_str());
00242         return NULL;
00243     }
00244     catch(const Py::Exception&)
00245     {
00246         // The exception text is already set
00247         return NULL;
00248     }
00249 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00250 
00251     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00252     if (rvalue == NULL)
00253     {
00254         PyErr_Clear();
00255         return TopoShapePy::_getattr(attr);
00256     }
00257     else
00258     {
00259         return rvalue;
00260     }
00261 }
00262 
00263 int TopoShapeSolidPy::_setattr(char *attr, PyObject *value)     // __setattr__ function: note only need to handle new state
00264 {
00265     try {
00266         // setter for  special Attributes (e.g. dynamic ones)
00267         int r = setCustomAttributes(attr, value);
00268         if(r==1) return 0;
00269     }
00270 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00271     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00272     {
00273         std::string str;
00274         str += "FreeCAD exception thrown (";
00275         str += e.what();
00276         str += ")";
00277         e.ReportException();
00278         PyErr_SetString(PyExc_Exception,str.c_str());
00279         return -1;
00280     }
00281     catch(const std::exception& e) // catch other c++ exceptions
00282     {
00283         std::string str;
00284         str += "FC++ exception thrown (";
00285         str += e.what();
00286         str += ")";
00287         Base::Console().Error(str.c_str());
00288         PyErr_SetString(PyExc_Exception,str.c_str());
00289         return -1;
00290     }
00291     catch(const Py::Exception&)
00292     {
00293         // The exception text is already set
00294         return -1;
00295     }
00296     catch(...)  // catch the rest!
00297     {
00298         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00299         return -1;
00300     }
00301 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00302     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00303     {
00304         std::string str;
00305         str += "FreeCAD exception thrown (";
00306         str += e.what();
00307         str += ")";
00308         e.ReportException();
00309         PyErr_SetString(PyExc_Exception,str.c_str());
00310         return -1;
00311     }
00312     catch(const Py::Exception&)
00313     {
00314         // The exception text is already set
00315         return -1;
00316     }
00317 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00318 
00319     return TopoShapePy::_setattr(attr, value);
00320 }
00321 
00322 TopoShape *TopoShapeSolidPy::getTopoShapePtr(void) const
00323 {
00324     return static_cast<TopoShape *>(_pcTwinPointer);
00325 }
00326 
00327 #if 0
00328 /* From here on come the methods you have to implement, but NOT in this module. Implement in TopoShapeSolidPyImp.cpp! This prototypes 
00329  * are just for convenience when you add a new method.
00330  */
00331 
00332 PyObject *TopoShapeSolidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00333 {
00334     // create a new instance of TopoShapeSolidPy and the Twin object 
00335     return new TopoShapeSolidPy(new TopoShape);
00336 }
00337 
00338 // constructor method
00339 int TopoShapeSolidPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00340 {
00341     return 0;
00342 }
00343 
00344 // returns a string which represents the object e.g. when printed in python
00345 std::string TopoShapeSolidPy::representation(void) const
00346 {
00347     return std::string("<TopoShape object>");
00348 }
00349 
00350 
00351 
00352 Py::Object TopoShapeSolidPy::getCenterOfMass(void) const
00353 {
00354     //return Py::Object();
00355     throw Py::AttributeError("Not yet implemented");
00356 }
00357 
00358 Py::Object TopoShapeSolidPy::getOuterShell(void) const
00359 {
00360     //return Py::Object();
00361     throw Py::AttributeError("Not yet implemented");
00362 }
00363 
00364 PyObject *TopoShapeSolidPy::getCustomAttributes(const char* attr) const
00365 {
00366     return 0;
00367 }
00368 
00369 int TopoShapeSolidPy::setCustomAttributes(const char* attr, PyObject *obj)
00370 {
00371     return 0; 
00372 }
00373 #endif
00374 
00375 
00376 

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