CirclePy.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 CirclePyImp.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 CirclePy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Part.GeomCircle",     /*tp_name*/
00024     sizeof(CirclePy),                       /*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     "Describes a circle in 3D space\n"
00046     "To create a circle there are several ways:\n"
00047     "Part.Circle()\n"
00048     "    Creates a default circle with center (0,0,0) and radius 1\n"
00049     "\n"
00050     "Part.Circle(Circle)\n"
00051     "    Creates a copy of the given circle\n"
00052     "\n"
00053     "Part.Circle(Circle, Distance)\n"
00054     "    Creates a circle parallel to given circle at a certain distance\n"
00055     "\n"
00056     "Part.Circle(Center,Normal,Radius)\n"
00057     "    Creates a circle defined by center, normal direction and radius\n"
00058     "\n"
00059     "Part.Circle(Point1,Point2,Point3)\n"
00060     "    Creates a circle defined by three non-linear points\n"
00061     "   ",           /*tp_doc */
00062     0,                                                /*tp_traverse */
00063     0,                                                /*tp_clear */
00064     0,                                                /*tp_richcompare */
00065     0,                                                /*tp_weaklistoffset */
00066     0,                                                /*tp_iter */
00067     0,                                                /*tp_iternext */
00068     Part::CirclePy::Methods,                     /*tp_methods */
00069     0,                                                /*tp_members */
00070     Part::CirclePy::GetterSetter,                     /*tp_getset */
00071     &Part::GeometryCurvePy::Type,                        /*tp_base */
00072     0,                                                /*tp_dict */
00073     0,                                                /*tp_descr_get */
00074     0,                                                /*tp_descr_set */
00075     0,                                                /*tp_dictoffset */
00076     __PyInit,                                         /*tp_init */
00077     0,                                                /*tp_alloc */
00078     Part::CirclePy::PyMake,/*tp_new */
00079     0,                                                /*tp_free   Low-level free-memory routine */
00080     0,                                                /*tp_is_gc  For PyObject_IS_GC */
00081     0,                                                /*tp_bases */
00082     0,                                                /*tp_mro    method resolution order */
00083     0,                                                /*tp_cache */
00084     0,                                                /*tp_subclasses */
00085     0,                                                /*tp_weaklist */
00086     0                                                 /*tp_del */
00087 };
00088 
00090 PyMethodDef CirclePy::Methods[] = {
00091     {NULL, NULL, 0, NULL}               /* Sentinel */
00092 };
00093 
00094 
00095 
00097 PyGetSetDef CirclePy::GetterSetter[] = {
00098     {"Radius",
00099         (getter) staticCallback_getRadius,
00100         (setter) staticCallback_setRadius, 
00101         "The radius of the circle.",
00102         NULL
00103     },
00104     {"Center",
00105         (getter) staticCallback_getCenter,
00106         (setter) staticCallback_setCenter, 
00107         "Center of the circle.",
00108         NULL
00109     },
00110     {"Axis",
00111         (getter) staticCallback_getAxis,
00112         (setter) staticCallback_setAxis, 
00113         "The axis direction of the circle",
00114         NULL
00115     },
00116     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00117 };
00118 
00119 // Radius() callback and implementer
00120 // PyObject*  CirclePy::Radius(PyObject *args){};
00121 // has to be implemented in CirclePyImp.cpp
00122 PyObject * CirclePy::staticCallback_getRadius (PyObject *self, void * /*closure*/)
00123 {
00124     if (!((PyObjectBase*) self)->isValid()){
00125         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00126         return NULL;
00127     }
00128 
00129     try {
00130         return Py::new_reference_to(((CirclePy*)self)->getRadius());
00131     } catch (const Py::Exception&) {
00132         // The exception text is already set
00133         return NULL;
00134     } catch (...) {
00135         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Radius' of object 'GeomCircle'");
00136         return NULL;
00137     }
00138 }
00139 
00140 int CirclePy::staticCallback_setRadius (PyObject *self, PyObject *value, void * /*closure*/)
00141 {    
00142     if (!((PyObjectBase*) self)->isValid()){
00143         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00144         return -1;
00145     }
00146     if (((PyObjectBase*) self)->isConst()){
00147         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00148         return -1;
00149     }
00150 
00151     try {
00152         ((CirclePy*)self)->setRadius(Py::Float(value,false));
00153         return 0;
00154     } catch (const Py::Exception&) {
00155         // The exception text is already set
00156         return -1;
00157     } catch (...) {
00158         PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Radius' of object 'GeomCircle'");
00159         return -1;
00160     }
00161 }
00162 
00163 // Center() callback and implementer
00164 // PyObject*  CirclePy::Center(PyObject *args){};
00165 // has to be implemented in CirclePyImp.cpp
00166 PyObject * CirclePy::staticCallback_getCenter (PyObject *self, void * /*closure*/)
00167 {
00168     if (!((PyObjectBase*) self)->isValid()){
00169         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00170         return NULL;
00171     }
00172 
00173     try {
00174         return Py::new_reference_to(((CirclePy*)self)->getCenter());
00175     } catch (const Py::Exception&) {
00176         // The exception text is already set
00177         return NULL;
00178     } catch (...) {
00179         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Center' of object 'GeomCircle'");
00180         return NULL;
00181     }
00182 }
00183 
00184 int CirclePy::staticCallback_setCenter (PyObject *self, PyObject *value, void * /*closure*/)
00185 {    
00186     if (!((PyObjectBase*) self)->isValid()){
00187         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00188         return -1;
00189     }
00190     if (((PyObjectBase*) self)->isConst()){
00191         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00192         return -1;
00193     }
00194 
00195     try {
00196         ((CirclePy*)self)->setCenter(Py::Object(value,false));
00197         return 0;
00198     } catch (const Py::Exception&) {
00199         // The exception text is already set
00200         return -1;
00201     } catch (...) {
00202         PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Center' of object 'GeomCircle'");
00203         return -1;
00204     }
00205 }
00206 
00207 // Axis() callback and implementer
00208 // PyObject*  CirclePy::Axis(PyObject *args){};
00209 // has to be implemented in CirclePyImp.cpp
00210 PyObject * CirclePy::staticCallback_getAxis (PyObject *self, void * /*closure*/)
00211 {
00212     if (!((PyObjectBase*) self)->isValid()){
00213         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00214         return NULL;
00215     }
00216 
00217     try {
00218         return Py::new_reference_to(((CirclePy*)self)->getAxis());
00219     } catch (const Py::Exception&) {
00220         // The exception text is already set
00221         return NULL;
00222     } catch (...) {
00223         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'GeomCircle'");
00224         return NULL;
00225     }
00226 }
00227 
00228 int CirclePy::staticCallback_setAxis (PyObject *self, PyObject *value, void * /*closure*/)
00229 {    
00230     if (!((PyObjectBase*) self)->isValid()){
00231         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00232         return -1;
00233     }
00234     if (((PyObjectBase*) self)->isConst()){
00235         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00236         return -1;
00237     }
00238 
00239     try {
00240         ((CirclePy*)self)->setAxis(Py::Object(value,false));
00241         return 0;
00242     } catch (const Py::Exception&) {
00243         // The exception text is already set
00244         return -1;
00245     } catch (...) {
00246         PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Axis' of object 'GeomCircle'");
00247         return -1;
00248     }
00249 }
00250 
00251 
00252 
00253 //--------------------------------------------------------------------------
00254 // Parents structure
00255 //--------------------------------------------------------------------------
00256 PyParentObject CirclePy::Parents[] = { PARENTSPartCirclePy };
00257 
00258 //--------------------------------------------------------------------------
00259 // Constructor
00260 //--------------------------------------------------------------------------
00261 CirclePy::CirclePy(GeomCircle *pcObject, PyTypeObject *T)
00262     : GeometryCurvePy(reinterpret_cast<GeometryCurvePy::PointerType>(pcObject), T)
00263 {
00264 }
00265 
00266 
00267 //--------------------------------------------------------------------------
00268 // destructor
00269 //--------------------------------------------------------------------------
00270 CirclePy::~CirclePy()                                // Everything handled in parent
00271 {
00272 }
00273 
00274 //--------------------------------------------------------------------------
00275 // CirclePy representation
00276 //--------------------------------------------------------------------------
00277 PyObject *CirclePy::_repr(void)
00278 {
00279     return Py_BuildValue("s", representation().c_str());
00280 }
00281 
00282 //--------------------------------------------------------------------------
00283 // CirclePy Attributes
00284 //--------------------------------------------------------------------------
00285 PyObject *CirclePy::_getattr(char *attr)                                // __getattr__ function: note only need to handle new state
00286 {
00287     try {
00288         // getter method for special Attributes (e.g. dynamic ones)
00289         PyObject *r = getCustomAttributes(attr);
00290         if(r) return r;
00291     }
00292 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00293     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00294     {
00295         std::string str;
00296         str += "FreeCAD exception thrown (";
00297         str += e.what();
00298         str += ")";
00299         e.ReportException();
00300         PyErr_SetString(PyExc_Exception,str.c_str());
00301         return NULL;
00302     }
00303     catch(const std::exception& e) // catch other c++ exceptions
00304     {
00305         std::string str;
00306         str += "FC++ exception thrown (";
00307         str += e.what();
00308         str += ")";
00309         Base::Console().Error(str.c_str());
00310         PyErr_SetString(PyExc_Exception,str.c_str());
00311         return NULL;
00312     }
00313     catch(const Py::Exception&)
00314     {
00315         // The exception text is already set
00316         return NULL;
00317     }
00318     catch(...)  // catch the rest!
00319     {
00320         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00321         return NULL;
00322     }
00323 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00324     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00325     {
00326         std::string str;
00327         str += "FreeCAD exception thrown (";
00328         str += e.what();
00329         str += ")";
00330         e.ReportException();
00331         PyErr_SetString(PyExc_Exception,str.c_str());
00332         return NULL;
00333     }
00334     catch(const Py::Exception&)
00335     {
00336         // The exception text is already set
00337         return NULL;
00338     }
00339 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00340 
00341     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00342     if (rvalue == NULL)
00343     {
00344         PyErr_Clear();
00345         return GeometryCurvePy::_getattr(attr);
00346     }
00347     else
00348     {
00349         return rvalue;
00350     }
00351 }
00352 
00353 int CirclePy::_setattr(char *attr, PyObject *value)     // __setattr__ function: note only need to handle new state
00354 {
00355     try {
00356         // setter for  special Attributes (e.g. dynamic ones)
00357         int r = setCustomAttributes(attr, value);
00358         if(r==1) return 0;
00359     }
00360 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00361     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00362     {
00363         std::string str;
00364         str += "FreeCAD exception thrown (";
00365         str += e.what();
00366         str += ")";
00367         e.ReportException();
00368         PyErr_SetString(PyExc_Exception,str.c_str());
00369         return -1;
00370     }
00371     catch(const std::exception& e) // catch other c++ exceptions
00372     {
00373         std::string str;
00374         str += "FC++ exception thrown (";
00375         str += e.what();
00376         str += ")";
00377         Base::Console().Error(str.c_str());
00378         PyErr_SetString(PyExc_Exception,str.c_str());
00379         return -1;
00380     }
00381     catch(const Py::Exception&)
00382     {
00383         // The exception text is already set
00384         return -1;
00385     }
00386     catch(...)  // catch the rest!
00387     {
00388         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00389         return -1;
00390     }
00391 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00392     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00393     {
00394         std::string str;
00395         str += "FreeCAD exception thrown (";
00396         str += e.what();
00397         str += ")";
00398         e.ReportException();
00399         PyErr_SetString(PyExc_Exception,str.c_str());
00400         return -1;
00401     }
00402     catch(const Py::Exception&)
00403     {
00404         // The exception text is already set
00405         return -1;
00406     }
00407 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00408 
00409     return GeometryCurvePy::_setattr(attr, value);
00410 }
00411 
00412 GeomCircle *CirclePy::getGeomCirclePtr(void) const
00413 {
00414     return static_cast<GeomCircle *>(_pcTwinPointer);
00415 }
00416 
00417 #if 0
00418 /* From here on come the methods you have to implement, but NOT in this module. Implement in CirclePyImp.cpp! This prototypes 
00419  * are just for convenience when you add a new method.
00420  */
00421 
00422 PyObject *CirclePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00423 {
00424     // create a new instance of CirclePy and the Twin object 
00425     return new CirclePy(new GeomCircle);
00426 }
00427 
00428 // constructor method
00429 int CirclePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00430 {
00431     return 0;
00432 }
00433 
00434 // returns a string which represents the object e.g. when printed in python
00435 std::string CirclePy::representation(void) const
00436 {
00437     return std::string("<GeomCircle object>");
00438 }
00439 
00440 
00441 
00442 Py::Float CirclePy::getRadius(void) const
00443 {
00444     //return Py::Float();
00445     throw Py::AttributeError("Not yet implemented");
00446 }
00447 
00448 void  CirclePy::setRadius(Py::Float arg)
00449 {
00450     throw Py::AttributeError("Not yet implemented");
00451 }
00452 
00453 Py::Object CirclePy::getCenter(void) const
00454 {
00455     //return Py::Object();
00456     throw Py::AttributeError("Not yet implemented");
00457 }
00458 
00459 void  CirclePy::setCenter(Py::Object arg)
00460 {
00461     throw Py::AttributeError("Not yet implemented");
00462 }
00463 
00464 Py::Object CirclePy::getAxis(void) const
00465 {
00466     //return Py::Object();
00467     throw Py::AttributeError("Not yet implemented");
00468 }
00469 
00470 void  CirclePy::setAxis(Py::Object arg)
00471 {
00472     throw Py::AttributeError("Not yet implemented");
00473 }
00474 
00475 PyObject *CirclePy::getCustomAttributes(const char* attr) const
00476 {
00477     return 0;
00478 }
00479 
00480 int CirclePy::setCustomAttributes(const char* attr, PyObject *obj)
00481 {
00482     return 0; 
00483 }
00484 #endif
00485 
00486 
00487 

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