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

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