SketchPy.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 SketchPyImp.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 Sketcher;
00018 
00020 PyTypeObject SketchPy::Type = {
00021     PyObject_HEAD_INIT(&PyType_Type)
00022     0,                                                /*ob_size*/
00023     "Sketcher.Sketch",     /*tp_name*/
00024     sizeof(SketchPy),                       /*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     "With this objects you can handle constraint sketches",           /*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     Sketcher::SketchPy::Methods,                     /*tp_methods */
00053     0,                                                /*tp_members */
00054     Sketcher::SketchPy::GetterSetter,                     /*tp_getset */
00055     &Base::PersistencePy::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     Sketcher::SketchPy::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 SketchPy::Methods[] = {
00075     {"solve",
00076         (PyCFunction) staticCallback_solve,
00077         METH_VARARGS,
00078         "solve the actuall set of geometry and constraints"
00079     },
00080     {"addGeometry",
00081         (PyCFunction) staticCallback_addGeometry,
00082         METH_VARARGS,
00083         "add a geometric object to the sketch"
00084     },
00085     {"addConstraint",
00086         (PyCFunction) staticCallback_addConstraint,
00087         METH_VARARGS,
00088         "add an constraint object to the sketch"
00089     },
00090     {"clear",
00091         (PyCFunction) staticCallback_clear,
00092         METH_VARARGS,
00093         "clear the sketch"
00094     },
00095     {"movePoint",
00096         (PyCFunction) staticCallback_movePoint,
00097         METH_VARARGS,
00098         "\n          movePoint(GeoIndex,PointPos,Vector,[relative]) - move a given point (or curve)\n          to another location.\n          It moves the specified point (or curve) to the given location by adding some\n          temporary weak constraints and solve the sketch.\n          This method is mostly used to allow the user to drag some portions of the sketch\n          in real time by e.g. the mouse and it works only for underconstrained portions of\n          the sketch.\n          The argument 'relative', if present, states if the new location is given\n          relatively to the current one.\n        "
00099     },
00100     {NULL, NULL, 0, NULL}               /* Sentinel */
00101 };
00102 
00103 
00104 
00106 PyGetSetDef SketchPy::GetterSetter[] = {
00107     {"Constraint",
00108         (getter) staticCallback_getConstraint,
00109         (setter) staticCallback_setConstraint, 
00110         "0: exactly constraint, -1 under-constraint, 1 over-constraint",
00111         NULL
00112     },
00113     {"Constraints",
00114         (getter) staticCallback_getConstraints,
00115         (setter) staticCallback_setConstraints, 
00116         "Tuple of all constrains in this sketch",
00117         NULL
00118     },
00119     {"Geometries",
00120         (getter) staticCallback_getGeometries,
00121         (setter) staticCallback_setGeometries, 
00122         "Tuple of all geometric elements in this sketch",
00123         NULL
00124     },
00125     {"Shape",
00126         (getter) staticCallback_getShape,
00127         (setter) staticCallback_setShape, 
00128         "Resulting shape from the sketch geometry",
00129         NULL
00130     },
00131     {NULL, NULL, NULL, NULL, NULL}              /* Sentinel */
00132 };
00133 
00134 // solve() callback and implementer
00135 // PyObject*  SketchPy::solve(PyObject *args){};
00136 // has to be implemented in SketchPyImp.cpp
00137 PyObject * SketchPy::staticCallback_solve (PyObject *self, PyObject *args)
00138 {
00139     // test if twin object not allready deleted
00140     if (!((PyObjectBase*) self)->isValid()){
00141         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00142         return NULL;
00143     }
00144 
00145     // test if object is set Const
00146     if (((PyObjectBase*) self)->isConst()){
00147         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00148         return NULL;
00149     }
00150 
00151     try { // catches all exceptions coming up from c++ and generate a python exception
00152         PyObject* ret = ((SketchPy*)self)->solve(args);
00153         if (ret != 0)
00154             ((SketchPy*)self)->startNotify();
00155         return ret;
00156     }
00157     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00158     {
00159         std::string str;
00160         str += "FreeCAD exception thrown (";
00161         str += e.what();
00162         str += ")";
00163         e.ReportException();
00164         PyErr_SetString(PyExc_Exception,str.c_str());
00165         return NULL;
00166     }
00167     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00168     {
00169         std::string str;
00170         str += "File system exception thrown (";
00171         //str += e.who();
00172         //str += ", ";
00173         str += e.what();
00174         str += ")\n";
00175         Base::Console().Error(str.c_str());
00176         PyErr_SetString(PyExc_Exception,str.c_str());
00177         return NULL;
00178     }
00179     catch(const Py::Exception&)
00180     {
00181         // The exception text is already set
00182         return NULL;
00183     }
00184     catch(const char* e) // catch simple string exceptions
00185     {
00186         Base::Console().Error(e);
00187         PyErr_SetString(PyExc_Exception,e);
00188         return NULL;
00189     }
00190     // in debug not all exceptions will be catched to get the attention of the developer!
00191 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00192     catch(const std::exception& e) // catch other c++ exceptions
00193     {
00194         std::string str;
00195         str += "FC++ exception thrown (";
00196         str += e.what();
00197         str += ")";
00198         Base::Console().Error(str.c_str());
00199         PyErr_SetString(PyExc_Exception,str.c_str());
00200         return NULL;
00201     }
00202     catch(...)  // catch the rest!
00203     {
00204         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00205         return NULL;
00206     }
00207 #endif
00208 }
00209 
00210 // addGeometry() callback and implementer
00211 // PyObject*  SketchPy::addGeometry(PyObject *args){};
00212 // has to be implemented in SketchPyImp.cpp
00213 PyObject * SketchPy::staticCallback_addGeometry (PyObject *self, PyObject *args)
00214 {
00215     // test if twin object not allready deleted
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 NULL;
00219     }
00220 
00221     // test if object is set Const
00222     if (((PyObjectBase*) self)->isConst()){
00223         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00224         return NULL;
00225     }
00226 
00227     try { // catches all exceptions coming up from c++ and generate a python exception
00228         PyObject* ret = ((SketchPy*)self)->addGeometry(args);
00229         if (ret != 0)
00230             ((SketchPy*)self)->startNotify();
00231         return ret;
00232     }
00233     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00234     {
00235         std::string str;
00236         str += "FreeCAD exception thrown (";
00237         str += e.what();
00238         str += ")";
00239         e.ReportException();
00240         PyErr_SetString(PyExc_Exception,str.c_str());
00241         return NULL;
00242     }
00243     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00244     {
00245         std::string str;
00246         str += "File system exception thrown (";
00247         //str += e.who();
00248         //str += ", ";
00249         str += e.what();
00250         str += ")\n";
00251         Base::Console().Error(str.c_str());
00252         PyErr_SetString(PyExc_Exception,str.c_str());
00253         return NULL;
00254     }
00255     catch(const Py::Exception&)
00256     {
00257         // The exception text is already set
00258         return NULL;
00259     }
00260     catch(const char* e) // catch simple string exceptions
00261     {
00262         Base::Console().Error(e);
00263         PyErr_SetString(PyExc_Exception,e);
00264         return NULL;
00265     }
00266     // in debug not all exceptions will be catched to get the attention of the developer!
00267 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00268     catch(const std::exception& e) // catch other c++ exceptions
00269     {
00270         std::string str;
00271         str += "FC++ exception thrown (";
00272         str += e.what();
00273         str += ")";
00274         Base::Console().Error(str.c_str());
00275         PyErr_SetString(PyExc_Exception,str.c_str());
00276         return NULL;
00277     }
00278     catch(...)  // catch the rest!
00279     {
00280         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00281         return NULL;
00282     }
00283 #endif
00284 }
00285 
00286 // addConstraint() callback and implementer
00287 // PyObject*  SketchPy::addConstraint(PyObject *args){};
00288 // has to be implemented in SketchPyImp.cpp
00289 PyObject * SketchPy::staticCallback_addConstraint (PyObject *self, PyObject *args)
00290 {
00291     // test if twin object not allready deleted
00292     if (!((PyObjectBase*) self)->isValid()){
00293         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00294         return NULL;
00295     }
00296 
00297     // test if object is set Const
00298     if (((PyObjectBase*) self)->isConst()){
00299         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00300         return NULL;
00301     }
00302 
00303     try { // catches all exceptions coming up from c++ and generate a python exception
00304         PyObject* ret = ((SketchPy*)self)->addConstraint(args);
00305         if (ret != 0)
00306             ((SketchPy*)self)->startNotify();
00307         return ret;
00308     }
00309     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00310     {
00311         std::string str;
00312         str += "FreeCAD exception thrown (";
00313         str += e.what();
00314         str += ")";
00315         e.ReportException();
00316         PyErr_SetString(PyExc_Exception,str.c_str());
00317         return NULL;
00318     }
00319     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00320     {
00321         std::string str;
00322         str += "File system exception thrown (";
00323         //str += e.who();
00324         //str += ", ";
00325         str += e.what();
00326         str += ")\n";
00327         Base::Console().Error(str.c_str());
00328         PyErr_SetString(PyExc_Exception,str.c_str());
00329         return NULL;
00330     }
00331     catch(const Py::Exception&)
00332     {
00333         // The exception text is already set
00334         return NULL;
00335     }
00336     catch(const char* e) // catch simple string exceptions
00337     {
00338         Base::Console().Error(e);
00339         PyErr_SetString(PyExc_Exception,e);
00340         return NULL;
00341     }
00342     // in debug not all exceptions will be catched to get the attention of the developer!
00343 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00344     catch(const std::exception& e) // catch other c++ exceptions
00345     {
00346         std::string str;
00347         str += "FC++ exception thrown (";
00348         str += e.what();
00349         str += ")";
00350         Base::Console().Error(str.c_str());
00351         PyErr_SetString(PyExc_Exception,str.c_str());
00352         return NULL;
00353     }
00354     catch(...)  // catch the rest!
00355     {
00356         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00357         return NULL;
00358     }
00359 #endif
00360 }
00361 
00362 // clear() callback and implementer
00363 // PyObject*  SketchPy::clear(PyObject *args){};
00364 // has to be implemented in SketchPyImp.cpp
00365 PyObject * SketchPy::staticCallback_clear (PyObject *self, PyObject *args)
00366 {
00367     // test if twin object not allready deleted
00368     if (!((PyObjectBase*) self)->isValid()){
00369         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00370         return NULL;
00371     }
00372 
00373     // test if object is set Const
00374     if (((PyObjectBase*) self)->isConst()){
00375         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00376         return NULL;
00377     }
00378 
00379     try { // catches all exceptions coming up from c++ and generate a python exception
00380         PyObject* ret = ((SketchPy*)self)->clear(args);
00381         if (ret != 0)
00382             ((SketchPy*)self)->startNotify();
00383         return ret;
00384     }
00385     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00386     {
00387         std::string str;
00388         str += "FreeCAD exception thrown (";
00389         str += e.what();
00390         str += ")";
00391         e.ReportException();
00392         PyErr_SetString(PyExc_Exception,str.c_str());
00393         return NULL;
00394     }
00395     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00396     {
00397         std::string str;
00398         str += "File system exception thrown (";
00399         //str += e.who();
00400         //str += ", ";
00401         str += e.what();
00402         str += ")\n";
00403         Base::Console().Error(str.c_str());
00404         PyErr_SetString(PyExc_Exception,str.c_str());
00405         return NULL;
00406     }
00407     catch(const Py::Exception&)
00408     {
00409         // The exception text is already set
00410         return NULL;
00411     }
00412     catch(const char* e) // catch simple string exceptions
00413     {
00414         Base::Console().Error(e);
00415         PyErr_SetString(PyExc_Exception,e);
00416         return NULL;
00417     }
00418     // in debug not all exceptions will be catched to get the attention of the developer!
00419 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00420     catch(const std::exception& e) // catch other c++ exceptions
00421     {
00422         std::string str;
00423         str += "FC++ exception thrown (";
00424         str += e.what();
00425         str += ")";
00426         Base::Console().Error(str.c_str());
00427         PyErr_SetString(PyExc_Exception,str.c_str());
00428         return NULL;
00429     }
00430     catch(...)  // catch the rest!
00431     {
00432         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00433         return NULL;
00434     }
00435 #endif
00436 }
00437 
00438 // movePoint() callback and implementer
00439 // PyObject*  SketchPy::movePoint(PyObject *args){};
00440 // has to be implemented in SketchPyImp.cpp
00441 PyObject * SketchPy::staticCallback_movePoint (PyObject *self, PyObject *args)
00442 {
00443     // test if twin object not allready deleted
00444     if (!((PyObjectBase*) self)->isValid()){
00445         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00446         return NULL;
00447     }
00448 
00449     // test if object is set Const
00450     if (((PyObjectBase*) self)->isConst()){
00451         PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00452         return NULL;
00453     }
00454 
00455     try { // catches all exceptions coming up from c++ and generate a python exception
00456         PyObject* ret = ((SketchPy*)self)->movePoint(args);
00457         if (ret != 0)
00458             ((SketchPy*)self)->startNotify();
00459         return ret;
00460     }
00461     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00462     {
00463         std::string str;
00464         str += "FreeCAD exception thrown (";
00465         str += e.what();
00466         str += ")";
00467         e.ReportException();
00468         PyErr_SetString(PyExc_Exception,str.c_str());
00469         return NULL;
00470     }
00471     catch(const boost::filesystem::filesystem_error& e) // catch boost filesystem exception
00472     {
00473         std::string str;
00474         str += "File system exception thrown (";
00475         //str += e.who();
00476         //str += ", ";
00477         str += e.what();
00478         str += ")\n";
00479         Base::Console().Error(str.c_str());
00480         PyErr_SetString(PyExc_Exception,str.c_str());
00481         return NULL;
00482     }
00483     catch(const Py::Exception&)
00484     {
00485         // The exception text is already set
00486         return NULL;
00487     }
00488     catch(const char* e) // catch simple string exceptions
00489     {
00490         Base::Console().Error(e);
00491         PyErr_SetString(PyExc_Exception,e);
00492         return NULL;
00493     }
00494     // in debug not all exceptions will be catched to get the attention of the developer!
00495 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00496     catch(const std::exception& e) // catch other c++ exceptions
00497     {
00498         std::string str;
00499         str += "FC++ exception thrown (";
00500         str += e.what();
00501         str += ")";
00502         Base::Console().Error(str.c_str());
00503         PyErr_SetString(PyExc_Exception,str.c_str());
00504         return NULL;
00505     }
00506     catch(...)  // catch the rest!
00507     {
00508         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00509         return NULL;
00510     }
00511 #endif
00512 }
00513 
00514 // Constraint() callback and implementer
00515 // PyObject*  SketchPy::Constraint(PyObject *args){};
00516 // has to be implemented in SketchPyImp.cpp
00517 PyObject * SketchPy::staticCallback_getConstraint (PyObject *self, void * /*closure*/)
00518 {
00519     if (!((PyObjectBase*) self)->isValid()){
00520         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00521         return NULL;
00522     }
00523 
00524     try {
00525         return Py::new_reference_to(((SketchPy*)self)->getConstraint());
00526     } catch (const Py::Exception&) {
00527         // The exception text is already set
00528         return NULL;
00529     } catch (...) {
00530         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Constraint' of object 'Sketch'");
00531         return NULL;
00532     }
00533 }
00534 
00535 int SketchPy::staticCallback_setConstraint (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00536 {
00537     if (!((PyObjectBase*) self)->isValid()){
00538         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00539         return -1;
00540     }
00541 
00542     PyErr_SetString(PyExc_AttributeError, "Attribute 'Constraint' of object 'Sketch' is read-only");
00543     return -1;
00544 }
00545 
00546 // Constraints() callback and implementer
00547 // PyObject*  SketchPy::Constraints(PyObject *args){};
00548 // has to be implemented in SketchPyImp.cpp
00549 PyObject * SketchPy::staticCallback_getConstraints (PyObject *self, void * /*closure*/)
00550 {
00551     if (!((PyObjectBase*) self)->isValid()){
00552         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00553         return NULL;
00554     }
00555 
00556     try {
00557         return Py::new_reference_to(((SketchPy*)self)->getConstraints());
00558     } catch (const Py::Exception&) {
00559         // The exception text is already set
00560         return NULL;
00561     } catch (...) {
00562         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Constraints' of object 'Sketch'");
00563         return NULL;
00564     }
00565 }
00566 
00567 int SketchPy::staticCallback_setConstraints (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00568 {
00569     if (!((PyObjectBase*) self)->isValid()){
00570         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00571         return -1;
00572     }
00573 
00574     PyErr_SetString(PyExc_AttributeError, "Attribute 'Constraints' of object 'Sketch' is read-only");
00575     return -1;
00576 }
00577 
00578 // Geometries() callback and implementer
00579 // PyObject*  SketchPy::Geometries(PyObject *args){};
00580 // has to be implemented in SketchPyImp.cpp
00581 PyObject * SketchPy::staticCallback_getGeometries (PyObject *self, void * /*closure*/)
00582 {
00583     if (!((PyObjectBase*) self)->isValid()){
00584         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00585         return NULL;
00586     }
00587 
00588     try {
00589         return Py::new_reference_to(((SketchPy*)self)->getGeometries());
00590     } catch (const Py::Exception&) {
00591         // The exception text is already set
00592         return NULL;
00593     } catch (...) {
00594         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Geometries' of object 'Sketch'");
00595         return NULL;
00596     }
00597 }
00598 
00599 int SketchPy::staticCallback_setGeometries (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00600 {
00601     if (!((PyObjectBase*) self)->isValid()){
00602         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00603         return -1;
00604     }
00605 
00606     PyErr_SetString(PyExc_AttributeError, "Attribute 'Geometries' of object 'Sketch' is read-only");
00607     return -1;
00608 }
00609 
00610 // Shape() callback and implementer
00611 // PyObject*  SketchPy::Shape(PyObject *args){};
00612 // has to be implemented in SketchPyImp.cpp
00613 PyObject * SketchPy::staticCallback_getShape (PyObject *self, void * /*closure*/)
00614 {
00615     if (!((PyObjectBase*) self)->isValid()){
00616         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00617         return NULL;
00618     }
00619 
00620     try {
00621         return Py::new_reference_to(((SketchPy*)self)->getShape());
00622     } catch (const Py::Exception&) {
00623         // The exception text is already set
00624         return NULL;
00625     } catch (...) {
00626         PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Shape' of object 'Sketch'");
00627         return NULL;
00628     }
00629 }
00630 
00631 int SketchPy::staticCallback_setShape (PyObject *self, PyObject * /*value*/, void * /*closure*/)
00632 {
00633     if (!((PyObjectBase*) self)->isValid()){
00634         PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00635         return -1;
00636     }
00637 
00638     PyErr_SetString(PyExc_AttributeError, "Attribute 'Shape' of object 'Sketch' is read-only");
00639     return -1;
00640 }
00641 
00642 
00643 
00644 //--------------------------------------------------------------------------
00645 // Parents structure
00646 //--------------------------------------------------------------------------
00647 PyParentObject SketchPy::Parents[] = { PARENTSSketcherSketchPy };
00648 
00649 //--------------------------------------------------------------------------
00650 // Constructor
00651 //--------------------------------------------------------------------------
00652 SketchPy::SketchPy(Sketch *pcObject, PyTypeObject *T)
00653     : PersistencePy(reinterpret_cast<PersistencePy::PointerType>(pcObject), T)
00654 {
00655 }
00656 
00657 
00658 //--------------------------------------------------------------------------
00659 // destructor
00660 //--------------------------------------------------------------------------
00661 SketchPy::~SketchPy()                                // Everything handled in parent
00662 {
00663 }
00664 
00665 //--------------------------------------------------------------------------
00666 // SketchPy representation
00667 //--------------------------------------------------------------------------
00668 PyObject *SketchPy::_repr(void)
00669 {
00670     return Py_BuildValue("s", representation().c_str());
00671 }
00672 
00673 //--------------------------------------------------------------------------
00674 // SketchPy Attributes
00675 //--------------------------------------------------------------------------
00676 PyObject *SketchPy::_getattr(char *attr)                                // __getattr__ function: note only need to handle new state
00677 {
00678     try {
00679         // getter method for special Attributes (e.g. dynamic ones)
00680         PyObject *r = getCustomAttributes(attr);
00681         if(r) return r;
00682     }
00683 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00684     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00685     {
00686         std::string str;
00687         str += "FreeCAD exception thrown (";
00688         str += e.what();
00689         str += ")";
00690         e.ReportException();
00691         PyErr_SetString(PyExc_Exception,str.c_str());
00692         return NULL;
00693     }
00694     catch(const std::exception& e) // catch other c++ exceptions
00695     {
00696         std::string str;
00697         str += "FC++ exception thrown (";
00698         str += e.what();
00699         str += ")";
00700         Base::Console().Error(str.c_str());
00701         PyErr_SetString(PyExc_Exception,str.c_str());
00702         return NULL;
00703     }
00704     catch(const Py::Exception&)
00705     {
00706         // The exception text is already set
00707         return NULL;
00708     }
00709     catch(...)  // catch the rest!
00710     {
00711         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00712         return NULL;
00713     }
00714 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00715     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00716     {
00717         std::string str;
00718         str += "FreeCAD exception thrown (";
00719         str += e.what();
00720         str += ")";
00721         e.ReportException();
00722         PyErr_SetString(PyExc_Exception,str.c_str());
00723         return NULL;
00724     }
00725     catch(const Py::Exception&)
00726     {
00727         // The exception text is already set
00728         return NULL;
00729     }
00730 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00731 
00732     PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00733     if (rvalue == NULL)
00734     {
00735         PyErr_Clear();
00736         return PersistencePy::_getattr(attr);
00737     }
00738     else
00739     {
00740         return rvalue;
00741     }
00742 }
00743 
00744 int SketchPy::_setattr(char *attr, PyObject *value)     // __setattr__ function: note only need to handle new state
00745 {
00746     try {
00747         // setter for  special Attributes (e.g. dynamic ones)
00748         int r = setCustomAttributes(attr, value);
00749         if(r==1) return 0;
00750     }
00751 #ifndef DONT_CATCH_CXX_EXCEPTIONS 
00752     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00753     {
00754         std::string str;
00755         str += "FreeCAD exception thrown (";
00756         str += e.what();
00757         str += ")";
00758         e.ReportException();
00759         PyErr_SetString(PyExc_Exception,str.c_str());
00760         return -1;
00761     }
00762     catch(const std::exception& e) // catch other c++ exceptions
00763     {
00764         std::string str;
00765         str += "FC++ exception thrown (";
00766         str += e.what();
00767         str += ")";
00768         Base::Console().Error(str.c_str());
00769         PyErr_SetString(PyExc_Exception,str.c_str());
00770         return -1;
00771     }
00772     catch(const Py::Exception&)
00773     {
00774         // The exception text is already set
00775         return -1;
00776     }
00777     catch(...)  // catch the rest!
00778     {
00779         PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00780         return -1;
00781     }
00782 #else  // DONT_CATCH_CXX_EXCEPTIONS  
00783     catch(const Base::Exception& e) // catch the FreeCAD exceptions
00784     {
00785         std::string str;
00786         str += "FreeCAD exception thrown (";
00787         str += e.what();
00788         str += ")";
00789         e.ReportException();
00790         PyErr_SetString(PyExc_Exception,str.c_str());
00791         return -1;
00792     }
00793     catch(const Py::Exception&)
00794     {
00795         // The exception text is already set
00796         return -1;
00797     }
00798 #endif  // DONT_CATCH_CXX_EXCEPTIONS
00799 
00800     return PersistencePy::_setattr(attr, value);
00801 }
00802 
00803 Sketch *SketchPy::getSketchPtr(void) const
00804 {
00805     return static_cast<Sketch *>(_pcTwinPointer);
00806 }
00807 
00808 #if 0
00809 /* From here on come the methods you have to implement, but NOT in this module. Implement in SketchPyImp.cpp! This prototypes 
00810  * are just for convenience when you add a new method.
00811  */
00812 
00813 PyObject *SketchPy::PyMake(struct _typeobject *, PyObject *, PyObject *)  // Python wrapper
00814 {
00815     // create a new instance of SketchPy and the Twin object 
00816     return new SketchPy(new Sketch);
00817 }
00818 
00819 // constructor method
00820 int SketchPy::PyInit(PyObject* /*args*/, PyObject* /*kwd*/)
00821 {
00822     return 0;
00823 }
00824 
00825 // returns a string which represents the object e.g. when printed in python
00826 std::string SketchPy::representation(void) const
00827 {
00828     return std::string("<Sketch object>");
00829 }
00830 
00831 PyObject* SketchPy::solve(PyObject *args)
00832 {
00833     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00834     return 0;
00835 }
00836 
00837 PyObject* SketchPy::addGeometry(PyObject *args)
00838 {
00839     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00840     return 0;
00841 }
00842 
00843 PyObject* SketchPy::addConstraint(PyObject *args)
00844 {
00845     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00846     return 0;
00847 }
00848 
00849 PyObject* SketchPy::clear(PyObject *args)
00850 {
00851     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00852     return 0;
00853 }
00854 
00855 PyObject* SketchPy::movePoint(PyObject *args)
00856 {
00857     PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00858     return 0;
00859 }
00860 
00861 
00862 
00863 Py::Int SketchPy::getConstraint(void) const
00864 {
00865     //return Py::Int();
00866     throw Py::AttributeError("Not yet implemented");
00867 }
00868 
00869 Py::Tuple SketchPy::getConstraints(void) const
00870 {
00871     //return Py::Tuple();
00872     throw Py::AttributeError("Not yet implemented");
00873 }
00874 
00875 Py::Tuple SketchPy::getGeometries(void) const
00876 {
00877     //return Py::Tuple();
00878     throw Py::AttributeError("Not yet implemented");
00879 }
00880 
00881 Py::Object SketchPy::getShape(void) const
00882 {
00883     //return Py::Object();
00884     throw Py::AttributeError("Not yet implemented");
00885 }
00886 
00887 PyObject *SketchPy::getCustomAttributes(const char* attr) const
00888 {
00889     return 0;
00890 }
00891 
00892 int SketchPy::setCustomAttributes(const char* attr, PyObject *obj)
00893 {
00894     return 0; 
00895 }
00896 #endif
00897 
00898 
00899 

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