PlanePy.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 PlanePyImp.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 PlanePy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Part.GeomPlane",     /*tp_name*/
00024     sizeof(PlanePy),                       /*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 an infinite plane\n"
00046     "To create a plane there are several ways:\n"
00047     "Part.Plane()\n"
00048     "    Creates a default plane with base (0,0,0) and normal (0,0,1)\n"
00049     "\n"
00050     "Part.Plane(Plane)\n"
00051     "    Creates a copy of the given plane\n"
00052     "\n"
00053     "Part.Plane(Plane, Distance)\n"
00054     "    Creates a plane parallel to given plane at a certain distance\n"
00055     "\n"
00056     "Part.Plane(Location,Normal)\n"
00057     "    Creates a plane with a given location and normal\n"
00058     "\n"
00059     "Part.Plane(Point1,Point2,Point3)\n"
00060     "    Creates a plane defined by three non-linear points\n"
00061     "\n"
00062     "Part.Plane(A,B,C,D)\n"
00063     "    Creates a plane from its cartesian equation\n"
00064     "    Ax+By+Cz+D=0\n"
00065     "",           /*tp_doc */
00066     0,                                                /*tp_traverse */
00067     0,                                                /*tp_clear */
00068     0,                                                /*tp_richcompare */
00069     0,                                                /*tp_weaklistoffset */
00070     0,                                                /*tp_iter */
00071     0,                                                /*tp_iternext */
00072     Part::PlanePy::Methods,                     /*tp_methods */
00073     0,                                                /*tp_members */
00074     Part::PlanePy::GetterSetter,                     /*tp_getset */
00075     &Part::GeometrySurfacePy::Type,                        /*tp_base */
00076     0,                                                /*tp_dict */
00077     0,                                                /*tp_descr_get */
00078     0,                                                /*tp_descr_set */
00079     0,                                                /*tp_dictoffset */
00080     __PyInit,                                         /*tp_init */
00081     0,                                                /*tp_alloc */
00082     Part::PlanePy::PyMake,/*tp_new */
00083     0,                                                /*tp_free   Low-level free-memory routine */
00084     0,                                                /*tp_is_gc  For PyObject_IS_GC */
00085     0,                                                /*tp_bases */
00086     0,                                                /*tp_mro    method resolution order */
00087     0,                                                /*tp_cache */
00088     0,                                                /*tp_subclasses */
00089     0,                                                /*tp_weaklist */
00090     0                                                 /*tp_del */
00091 };
00092 
00094 PyMethodDef PlanePy::Methods[] = {
00095     {"uIso",
00096         (PyCFunction) staticCallback_uIso,
00097         METH_VARARGS,
00098         "Builds the U isoparametric line of this plane"
00099     },
00100     {"vIso",
00101         (PyCFunction) staticCallback_vIso,
00102         METH_VARARGS,
00103         "Builds the V isoparametric line of this plane"
00104     },
00105     {NULL, NULL, 0, NULL}               /* Sentinel */
00106 };
00107 
00108 
00109 
00111 PyGetSetDef PlanePy::GetterSetter[] = {
00112     {"Position",
00113         (getter) staticCallback_getPosition,
00114         (setter) staticCallback_setPosition, 
00115         "Returns the position point of this plane.",
00116         NULL
00117     },
00118     {"Axis",
00119         (getter) staticCallback_getAxis,
00120         (setter) staticCallback_setAxis, 
00121         "Returns the axis of this plane.",
00122         NULL
00123     },
00124     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00125 };
00126 
00127 // uIso() callback and implementer
00128 // PyObject*  PlanePy::uIso(PyObject *args){};
00129 // has to be implemented in PlanePyImp.cpp
00130 PyObject * PlanePy::staticCallback_uIso (PyObject *self, PyObject *args)
00131 {
00132     // test if twin object not allready deleted
00133     if (!((PyObjectBase*) self)->isValid()){
00134         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00135         return NULL;
00136     }
00137 
00138     // test if object is set Const
00139     if (((PyObjectBase*) self)->isConst()){
00140         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00141         return NULL;
00142     }
00143 
00144     try { // catches all exceptions coming up from c++ and generate a python exception
00145         PyObject* ret = ((PlanePy*)self)->uIso(args);
00146         if (ret != 0)
00147             ((PlanePy*)self)->startNotify();
00148         return ret;
00149     }
00150     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00151     {
00152         std::string str;
00153         str += "FreeCAD exception thrown (";
00154         str += e.what();
00155         str += ")";
00156         e.ReportException();
00157         PyErr_SetString(PyExc_Exception,str.c_str());
00158         return NULL;
00159     }
00160     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00161     {
00162         std::string str;
00163         str += "File system exception thrown (";
00164         //str += e.who();
00165         //str += ", ";
00166         str += e.what();
00167         str += ")\n";
00168         Base::Console().Error(str.c_str());
00169         PyErr_SetString(PyExc_Exception,str.c_str());
00170         return NULL;
00171     }
00172     catch(const Py::Exception&)
00173     {
00174         // The exception text is already set
00175         return NULL;
00176     }
00177     catch(const char* e) // catch simple string exceptions
00178     {
00179         Base::Console().Error(e);
00180         PyErr_SetString(PyExc_Exception,e);
00181         return NULL;
00182     }
00183     // in debug not all exceptions will be catched to get the attention of the developer!
00184 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00185     catch(const std::exception& e) // catch other c++ exceptions
00186     {
00187         std::string str;
00188         str += "FC++ exception thrown (";
00189         str += e.what();
00190         str += ")";
00191         Base::Console().Error(str.c_str());
00192         PyErr_SetString(PyExc_Exception,str.c_str());
00193         return NULL;
00194     }
00195     catch(...)  // catch the rest!
00196     {
00197         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00198         return NULL;
00199     }
00200 #endif
00201 }
00202 
00203 // vIso() callback and implementer
00204 // PyObject*  PlanePy::vIso(PyObject *args){};
00205 // has to be implemented in PlanePyImp.cpp
00206 PyObject * PlanePy::staticCallback_vIso (PyObject *self, PyObject *args)
00207 {
00208     // test if twin object not allready deleted
00209     if (!((PyObjectBase*) self)->isValid()){
00210         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00211         return NULL;
00212     }
00213 
00214     // test if object is set Const
00215     if (((PyObjectBase*) self)->isConst()){
00216         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00217         return NULL;
00218     }
00219 
00220     try { // catches all exceptions coming up from c++ and generate a python exception
00221         PyObject* ret = ((PlanePy*)self)->vIso(args);
00222         if (ret != 0)
00223             ((PlanePy*)self)->startNotify();
00224         return ret;
00225     }
00226     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00227     {
00228         std::string str;
00229         str += "FreeCAD exception thrown (";
00230         str += e.what();
00231         str += ")";
00232         e.ReportException();
00233         PyErr_SetString(PyExc_Exception,str.c_str());
00234         return NULL;
00235     }
00236     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00237     {
00238         std::string str;
00239         str += "File system exception thrown (";
00240         //str += e.who();
00241         //str += ", ";
00242         str += e.what();
00243         str += ")\n";
00244         Base::Console().Error(str.c_str());
00245         PyErr_SetString(PyExc_Exception,str.c_str());
00246         return NULL;
00247     }
00248     catch(const Py::Exception&)
00249     {
00250         // The exception text is already set
00251         return NULL;
00252     }
00253     catch(const char* e) // catch simple string exceptions
00254     {
00255         Base::Console().Error(e);
00256         PyErr_SetString(PyExc_Exception,e);
00257         return NULL;
00258     }
00259     // in debug not all exceptions will be catched to get the attention of the developer!
00260 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00261     catch(const std::exception& e) // catch other c++ exceptions
00262     {
00263         std::string str;
00264         str += "FC++ exception thrown (";
00265         str += e.what();
00266         str += ")";
00267         Base::Console().Error(str.c_str());
00268         PyErr_SetString(PyExc_Exception,str.c_str());
00269         return NULL;
00270     }
00271     catch(...)  // catch the rest!
00272     {
00273         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00274         return NULL;
00275     }
00276 #endif
00277 }
00278 
00279 // Position() callback and implementer
00280 // PyObject*  PlanePy::Position(PyObject *args){};
00281 // has to be implemented in PlanePyImp.cpp
00282 PyObject * PlanePy::staticCallback_getPosition (PyObject *self, void * /*closure*/)
00283 {
00284     if (!((PyObjectBase*) self)->isValid()){
00285         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00286         return NULL;
00287     }
00288 
00289     try {
00290         return Py::new_reference_to(((PlanePy*)self)->getPosition());
00291     } catch (const Py::Exception&) {
00292         // The exception text is already set
00293         return NULL;
00294     } catch (...) {
00295         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Position' of object 'GeomPlane'");
00296         return NULL;
00297     }
00298 }
00299 
00300 int PlanePy::staticCallback_setPosition (PyObject *self, PyObject *value, void * /*closure*/)
00301 {    
00302     if (!((PyObjectBase*) self)->isValid()){
00303         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00304         return -1;
00305     }
00306     if (((PyObjectBase*) self)->isConst()){
00307         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00308         return -1;
00309     }
00310 
00311     try {
00312         ((PlanePy*)self)->setPosition(Py::Object(value,false));
00313         return 0;
00314     } catch (const Py::Exception&) {
00315         // The exception text is already set
00316         return -1;
00317     } catch (...) {
00318         PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Position' of object 'GeomPlane'");
00319         return -1;
00320     }
00321 }
00322 
00323 // Axis() callback and implementer
00324 // PyObject*  PlanePy::Axis(PyObject *args){};
00325 // has to be implemented in PlanePyImp.cpp
00326 PyObject * PlanePy::staticCallback_getAxis (PyObject *self, void * /*closure*/)
00327 {
00328     if (!((PyObjectBase*) self)->isValid()){
00329         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00330         return NULL;
00331     }
00332 
00333     try {
00334         return Py::new_reference_to(((PlanePy*)self)->getAxis());
00335     } catch (const Py::Exception&) {
00336         // The exception text is already set
00337         return NULL;
00338     } catch (...) {
00339         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'GeomPlane'");
00340         return NULL;
00341     }
00342 }
00343 
00344 int PlanePy::staticCallback_setAxis (PyObject *self, PyObject *value, 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 -1;
00349     }
00350     if (((PyObjectBase*) self)->isConst()){
00351         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00352         return -1;
00353     }
00354 
00355     try {
00356         ((PlanePy*)self)->setAxis(Py::Object(value,false));
00357         return 0;
00358     } catch (const Py::Exception&) {
00359         // The exception text is already set
00360         return -1;
00361     } catch (...) {
00362         PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Axis' of object 'GeomPlane'");
00363         return -1;
00364     }
00365 }
00366 
00367 
00368 
00369 //--------------------------------------------------------------------------
00370 // Parents structure
00371 //--------------------------------------------------------------------------
00372 PyParentObject PlanePy::Parents[] = { PARENTSPartPlanePy };
00373 
00374 //--------------------------------------------------------------------------
00375 // Constructor
00376 //--------------------------------------------------------------------------
00377 PlanePy::PlanePy(GeomPlane *pcObject, PyTypeObject *T)
00378     : GeometrySurfacePy(reinterpret_cast<GeometrySurfacePy::PointerType>(pcObject), T)
00379 {
00380 }
00381 
00382 
00383 //--------------------------------------------------------------------------
00384 // destructor
00385 //--------------------------------------------------------------------------
00386 PlanePy::~PlanePy()                                // Everything handled in parent
00387 {
00388 }
00389 
00390 //--------------------------------------------------------------------------
00391 // PlanePy representation
00392 //--------------------------------------------------------------------------
00393 PyObject *PlanePy::_repr(void)
00394 {
00395     return Py_BuildValue("s", representation().c_str());
00396 }
00397 
00398 //--------------------------------------------------------------------------
00399 // PlanePy Attributes
00400 //--------------------------------------------------------------------------
00401 PyObject *PlanePy::_getattr(char *attr)                         // __getattr__ function: note only need to handle new state
00402 {
00403     try {
00404         // getter method for special Attributes (e.g. dynamic ones)
00405         PyObject *r = getCustomAttributes(attr);
00406         if(r) return r;
00407     }
00408 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00409     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00410     {
00411         std::string str;
00412         str += "FreeCAD exception thrown (";
00413         str += e.what();
00414         str += ")";
00415         e.ReportException();
00416         PyErr_SetString(PyExc_Exception,str.c_str());
00417         return NULL;
00418     }
00419     catch(const std::exception& e) // catch other c++ exceptions
00420     {
00421         std::string str;
00422         str += "FC++ exception thrown (";
00423         str += e.what();
00424         str += ")";
00425         Base::Console().Error(str.c_str());
00426         PyErr_SetString(PyExc_Exception,str.c_str());
00427         return NULL;
00428     }
00429     catch(const Py::Exception&)
00430     {
00431         // The exception text is already set
00432         return NULL;
00433     }
00434     catch(...)  // catch the rest!
00435     {
00436         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00437         return NULL;
00438     }
00439 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00440     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00441     {
00442         std::string str;
00443         str += "FreeCAD exception thrown (";
00444         str += e.what();
00445         str += ")";
00446         e.ReportException();
00447         PyErr_SetString(PyExc_Exception,str.c_str());
00448         return NULL;
00449     }
00450     catch(const Py::Exception&)
00451     {
00452         // The exception text is already set
00453         return NULL;
00454     }
00455 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00456 
00457     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00458     if (rvalue == NULL)
00459     {
00460         PyErr_Clear();
00461         return GeometrySurfacePy::_getattr(attr);
00462     }
00463     else
00464     {
00465         return rvalue;
00466     }
00467 }
00468 
00469 int PlanePy::_setattr(char *attr, PyObject *value)      // __setattr__ function: note only need to handle new state
00470 {
00471     try {
00472         // setter for  special Attributes (e.g. dynamic ones)
00473         int r = setCustomAttributes(attr, value);
00474         if(r==1) return 0;
00475     }
00476 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00477     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00478     {
00479         std::string str;
00480         str += "FreeCAD exception thrown (";
00481         str += e.what();
00482         str += ")";
00483         e.ReportException();
00484         PyErr_SetString(PyExc_Exception,str.c_str());
00485         return -1;
00486     }
00487     catch(const std::exception& e) // catch other c++ exceptions
00488     {
00489         std::string str;
00490         str += "FC++ exception thrown (";
00491         str += e.what();
00492         str += ")";
00493         Base::Console().Error(str.c_str());
00494         PyErr_SetString(PyExc_Exception,str.c_str());
00495         return -1;
00496     }
00497     catch(const Py::Exception&)
00498     {
00499         // The exception text is already set
00500         return -1;
00501     }
00502     catch(...)  // catch the rest!
00503     {
00504         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00505         return -1;
00506     }
00507 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00508     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00509     {
00510         std::string str;
00511         str += "FreeCAD exception thrown (";
00512         str += e.what();
00513         str += ")";
00514         e.ReportException();
00515         PyErr_SetString(PyExc_Exception,str.c_str());
00516         return -1;
00517     }
00518     catch(const Py::Exception&)
00519     {
00520         // The exception text is already set
00521         return -1;
00522     }
00523 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00524 
00525     return GeometrySurfacePy::_setattr(attr, value);
00526 }
00527 
00528 GeomPlane *PlanePy::getGeomPlanePtr(void) const
00529 {
00530     return static_cast<GeomPlane *>(_pcTwinPointer);
00531 }
00532 
00533 #if 0
00534 /* From here on come the methods you have to implement, but NOT in this module. Implement in PlanePyImp.cpp! This prototypes 
00535  * are just for convenience when you add a new method.
00536  */
00537 
00538 PyObject *PlanePy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00539 {
00540     // create a new instance of PlanePy and the Twin object 
00541     return new PlanePy(new GeomPlane);
00542 }
00543 
00544 // constructor method
00545 int PlanePy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00546 {
00547     return 0;
00548 }
00549 
00550 // returns a string which represents the object e.g. when printed in python
00551 std::string PlanePy::representation(void) const
00552 {
00553     return std::string("<GeomPlane object>");
00554 }
00555 
00556 PyObject* PlanePy::uIso(PyObject *args)
00557 {
00558     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00559     return 0;
00560 }
00561 
00562 PyObject* PlanePy::vIso(PyObject *args)
00563 {
00564     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00565     return 0;
00566 }
00567 
00568 
00569 
00570 Py::Object PlanePy::getPosition(void) const
00571 {
00572     //return Py::Object();
00573     throw Py::AttributeError("Not yet implemented");
00574 }
00575 
00576 void  PlanePy::setPosition(Py::Object arg)
00577 {
00578     throw Py::AttributeError("Not yet implemented");
00579 }
00580 
00581 Py::Object PlanePy::getAxis(void) const
00582 {
00583     //return Py::Object();
00584     throw Py::AttributeError("Not yet implemented");
00585 }
00586 
00587 void  PlanePy::setAxis(Py::Object arg)
00588 {
00589     throw Py::AttributeError("Not yet implemented");
00590 }
00591 
00592 PyObject *PlanePy::getCustomAttributes(const char* attr) const
00593 {
00594     return 0;
00595 }
00596 
00597 int PlanePy::setCustomAttributes(const char* attr, PyObject *obj)
00598 {
00599     return 0; 
00600 }
00601 #endif
00602 
00603 
00604 

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