00001
00002
00003
00004
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 ToroidPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Part.GeomToroid",
00024 sizeof(ToroidPy),
00025 0,
00026
00027 PyDestructor,
00028 0,
00029 __getattr,
00030 __setattr,
00031 0,
00032 __repr,
00033 0,
00034 0,
00035 0,
00036 0,
00037 0,
00038 0,
00039 0,
00040 0,
00041
00042 0,
00043
00044 Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS,
00045 "Describes a toroid in 3D space",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Part::ToroidPy::Methods,
00053 0,
00054 Part::ToroidPy::GetterSetter,
00055 &Part::GeometrySurfacePy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Part::ToroidPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef ToroidPy::Methods[] = {
00075 {"uIso",
00076 (PyCFunction) staticCallback_uIso,
00077 METH_VARARGS,
00078 "Builds the U isoparametric circle of this toroid"
00079 },
00080 {"vIso",
00081 (PyCFunction) staticCallback_vIso,
00082 METH_VARARGS,
00083 "Builds the V isoparametric circle of this toroid"
00084 },
00085 {NULL, NULL, 0, NULL}
00086 };
00087
00088
00089
00091 PyGetSetDef ToroidPy::GetterSetter[] = {
00092 {"MajorRadius",
00093 (getter) staticCallback_getMajorRadius,
00094 (setter) staticCallback_setMajorRadius,
00095 "The major radius of the toroid.",
00096 NULL
00097 },
00098 {"MinorRadius",
00099 (getter) staticCallback_getMinorRadius,
00100 (setter) staticCallback_setMinorRadius,
00101 "The minor radius of the toroid.",
00102 NULL
00103 },
00104 {"Center",
00105 (getter) staticCallback_getCenter,
00106 (setter) staticCallback_setCenter,
00107 "Center of the toroid.",
00108 NULL
00109 },
00110 {"Axis",
00111 (getter) staticCallback_getAxis,
00112 (setter) staticCallback_setAxis,
00113 "The axis direction of the toroid",
00114 NULL
00115 },
00116 {"Area",
00117 (getter) staticCallback_getArea,
00118 (setter) staticCallback_setArea,
00119 "Compute the area of the toroid.",
00120 NULL
00121 },
00122 {"Volume",
00123 (getter) staticCallback_getVolume,
00124 (setter) staticCallback_setVolume,
00125 "Compute the volume of the toroid.",
00126 NULL
00127 },
00128 {NULL, NULL, NULL, NULL, NULL}
00129 };
00130
00131
00132
00133
00134 PyObject * ToroidPy::staticCallback_uIso (PyObject *self, PyObject *args)
00135 {
00136
00137 if (!((PyObjectBase*) self)->isValid()){
00138 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00139 return NULL;
00140 }
00141
00142
00143 if (((PyObjectBase*) self)->isConst()){
00144 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00145 return NULL;
00146 }
00147
00148 try {
00149 PyObject* ret = ((ToroidPy*)self)->uIso(args);
00150 if (ret != 0)
00151 ((ToroidPy*)self)->startNotify();
00152 return ret;
00153 }
00154 catch(const Base::Exception& e)
00155 {
00156 std::string str;
00157 str += "FreeCAD exception thrown (";
00158 str += e.what();
00159 str += ")";
00160 e.ReportException();
00161 PyErr_SetString(PyExc_Exception,str.c_str());
00162 return NULL;
00163 }
00164 catch(const boost::filesystem::filesystem_error& e)
00165 {
00166 std::string str;
00167 str += "File system exception thrown (";
00168
00169
00170 str += e.what();
00171 str += ")\n";
00172 Base::Console().Error(str.c_str());
00173 PyErr_SetString(PyExc_Exception,str.c_str());
00174 return NULL;
00175 }
00176 catch(const Py::Exception&)
00177 {
00178
00179 return NULL;
00180 }
00181 catch(const char* e)
00182 {
00183 Base::Console().Error(e);
00184 PyErr_SetString(PyExc_Exception,e);
00185 return NULL;
00186 }
00187
00188 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00189 catch(const std::exception& e)
00190 {
00191 std::string str;
00192 str += "FC++ exception thrown (";
00193 str += e.what();
00194 str += ")";
00195 Base::Console().Error(str.c_str());
00196 PyErr_SetString(PyExc_Exception,str.c_str());
00197 return NULL;
00198 }
00199 catch(...)
00200 {
00201 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00202 return NULL;
00203 }
00204 #endif
00205 }
00206
00207
00208
00209
00210 PyObject * ToroidPy::staticCallback_vIso (PyObject *self, PyObject *args)
00211 {
00212
00213 if (!((PyObjectBase*) self)->isValid()){
00214 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00215 return NULL;
00216 }
00217
00218
00219 if (((PyObjectBase*) self)->isConst()){
00220 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00221 return NULL;
00222 }
00223
00224 try {
00225 PyObject* ret = ((ToroidPy*)self)->vIso(args);
00226 if (ret != 0)
00227 ((ToroidPy*)self)->startNotify();
00228 return ret;
00229 }
00230 catch(const Base::Exception& e)
00231 {
00232 std::string str;
00233 str += "FreeCAD exception thrown (";
00234 str += e.what();
00235 str += ")";
00236 e.ReportException();
00237 PyErr_SetString(PyExc_Exception,str.c_str());
00238 return NULL;
00239 }
00240 catch(const boost::filesystem::filesystem_error& e)
00241 {
00242 std::string str;
00243 str += "File system exception thrown (";
00244
00245
00246 str += e.what();
00247 str += ")\n";
00248 Base::Console().Error(str.c_str());
00249 PyErr_SetString(PyExc_Exception,str.c_str());
00250 return NULL;
00251 }
00252 catch(const Py::Exception&)
00253 {
00254
00255 return NULL;
00256 }
00257 catch(const char* e)
00258 {
00259 Base::Console().Error(e);
00260 PyErr_SetString(PyExc_Exception,e);
00261 return NULL;
00262 }
00263
00264 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00265 catch(const std::exception& e)
00266 {
00267 std::string str;
00268 str += "FC++ exception thrown (";
00269 str += e.what();
00270 str += ")";
00271 Base::Console().Error(str.c_str());
00272 PyErr_SetString(PyExc_Exception,str.c_str());
00273 return NULL;
00274 }
00275 catch(...)
00276 {
00277 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00278 return NULL;
00279 }
00280 #endif
00281 }
00282
00283
00284
00285
00286 PyObject * ToroidPy::staticCallback_getMajorRadius (PyObject *self, void * )
00287 {
00288 if (!((PyObjectBase*) self)->isValid()){
00289 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00290 return NULL;
00291 }
00292
00293 try {
00294 return Py::new_reference_to(((ToroidPy*)self)->getMajorRadius());
00295 } catch (const Py::Exception&) {
00296
00297 return NULL;
00298 } catch (...) {
00299 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'MajorRadius' of object 'GeomToroid'");
00300 return NULL;
00301 }
00302 }
00303
00304 int ToroidPy::staticCallback_setMajorRadius (PyObject *self, PyObject *value, void * )
00305 {
00306 if (!((PyObjectBase*) self)->isValid()){
00307 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00308 return -1;
00309 }
00310 if (((PyObjectBase*) self)->isConst()){
00311 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00312 return -1;
00313 }
00314
00315 try {
00316 ((ToroidPy*)self)->setMajorRadius(Py::Float(value,false));
00317 return 0;
00318 } catch (const Py::Exception&) {
00319
00320 return -1;
00321 } catch (...) {
00322 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'MajorRadius' of object 'GeomToroid'");
00323 return -1;
00324 }
00325 }
00326
00327
00328
00329
00330 PyObject * ToroidPy::staticCallback_getMinorRadius (PyObject *self, void * )
00331 {
00332 if (!((PyObjectBase*) self)->isValid()){
00333 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00334 return NULL;
00335 }
00336
00337 try {
00338 return Py::new_reference_to(((ToroidPy*)self)->getMinorRadius());
00339 } catch (const Py::Exception&) {
00340
00341 return NULL;
00342 } catch (...) {
00343 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'MinorRadius' of object 'GeomToroid'");
00344 return NULL;
00345 }
00346 }
00347
00348 int ToroidPy::staticCallback_setMinorRadius (PyObject *self, PyObject *value, void * )
00349 {
00350 if (!((PyObjectBase*) self)->isValid()){
00351 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00352 return -1;
00353 }
00354 if (((PyObjectBase*) self)->isConst()){
00355 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00356 return -1;
00357 }
00358
00359 try {
00360 ((ToroidPy*)self)->setMinorRadius(Py::Float(value,false));
00361 return 0;
00362 } catch (const Py::Exception&) {
00363
00364 return -1;
00365 } catch (...) {
00366 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'MinorRadius' of object 'GeomToroid'");
00367 return -1;
00368 }
00369 }
00370
00371
00372
00373
00374 PyObject * ToroidPy::staticCallback_getCenter (PyObject *self, void * )
00375 {
00376 if (!((PyObjectBase*) self)->isValid()){
00377 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00378 return NULL;
00379 }
00380
00381 try {
00382 return Py::new_reference_to(((ToroidPy*)self)->getCenter());
00383 } catch (const Py::Exception&) {
00384
00385 return NULL;
00386 } catch (...) {
00387 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Center' of object 'GeomToroid'");
00388 return NULL;
00389 }
00390 }
00391
00392 int ToroidPy::staticCallback_setCenter (PyObject *self, PyObject *value, void * )
00393 {
00394 if (!((PyObjectBase*) self)->isValid()){
00395 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00396 return -1;
00397 }
00398 if (((PyObjectBase*) self)->isConst()){
00399 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00400 return -1;
00401 }
00402
00403 try {
00404 ((ToroidPy*)self)->setCenter(Py::Object(value,false));
00405 return 0;
00406 } catch (const Py::Exception&) {
00407
00408 return -1;
00409 } catch (...) {
00410 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Center' of object 'GeomToroid'");
00411 return -1;
00412 }
00413 }
00414
00415
00416
00417
00418 PyObject * ToroidPy::staticCallback_getAxis (PyObject *self, void * )
00419 {
00420 if (!((PyObjectBase*) self)->isValid()){
00421 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00422 return NULL;
00423 }
00424
00425 try {
00426 return Py::new_reference_to(((ToroidPy*)self)->getAxis());
00427 } catch (const Py::Exception&) {
00428
00429 return NULL;
00430 } catch (...) {
00431 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'GeomToroid'");
00432 return NULL;
00433 }
00434 }
00435
00436 int ToroidPy::staticCallback_setAxis (PyObject *self, PyObject *value, void * )
00437 {
00438 if (!((PyObjectBase*) self)->isValid()){
00439 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00440 return -1;
00441 }
00442 if (((PyObjectBase*) self)->isConst()){
00443 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00444 return -1;
00445 }
00446
00447 try {
00448 ((ToroidPy*)self)->setAxis(Py::Object(value,false));
00449 return 0;
00450 } catch (const Py::Exception&) {
00451
00452 return -1;
00453 } catch (...) {
00454 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Axis' of object 'GeomToroid'");
00455 return -1;
00456 }
00457 }
00458
00459
00460
00461
00462 PyObject * ToroidPy::staticCallback_getArea (PyObject *self, void * )
00463 {
00464 if (!((PyObjectBase*) self)->isValid()){
00465 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00466 return NULL;
00467 }
00468
00469 try {
00470 return Py::new_reference_to(((ToroidPy*)self)->getArea());
00471 } catch (const Py::Exception&) {
00472
00473 return NULL;
00474 } catch (...) {
00475 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Area' of object 'GeomToroid'");
00476 return NULL;
00477 }
00478 }
00479
00480 int ToroidPy::staticCallback_setArea (PyObject *self, PyObject * , void * )
00481 {
00482 if (!((PyObjectBase*) self)->isValid()){
00483 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00484 return -1;
00485 }
00486
00487 PyErr_SetString(PyExc_AttributeError, "Attribute 'Area' of object 'GeomToroid' is read-only");
00488 return -1;
00489 }
00490
00491
00492
00493
00494 PyObject * ToroidPy::staticCallback_getVolume (PyObject *self, void * )
00495 {
00496 if (!((PyObjectBase*) self)->isValid()){
00497 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00498 return NULL;
00499 }
00500
00501 try {
00502 return Py::new_reference_to(((ToroidPy*)self)->getVolume());
00503 } catch (const Py::Exception&) {
00504
00505 return NULL;
00506 } catch (...) {
00507 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Volume' of object 'GeomToroid'");
00508 return NULL;
00509 }
00510 }
00511
00512 int ToroidPy::staticCallback_setVolume (PyObject *self, PyObject * , void * )
00513 {
00514 if (!((PyObjectBase*) self)->isValid()){
00515 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00516 return -1;
00517 }
00518
00519 PyErr_SetString(PyExc_AttributeError, "Attribute 'Volume' of object 'GeomToroid' is read-only");
00520 return -1;
00521 }
00522
00523
00524
00525
00526
00527
00528 PyParentObject ToroidPy::Parents[] = { PARENTSPartToroidPy };
00529
00530
00531
00532
00533 ToroidPy::ToroidPy(GeomToroid *pcObject, PyTypeObject *T)
00534 : GeometrySurfacePy(reinterpret_cast<GeometrySurfacePy::PointerType>(pcObject), T)
00535 {
00536 }
00537
00538
00539
00540
00541
00542 ToroidPy::~ToroidPy()
00543 {
00544 }
00545
00546
00547
00548
00549 PyObject *ToroidPy::_repr(void)
00550 {
00551 return Py_BuildValue("s", representation().c_str());
00552 }
00553
00554
00555
00556
00557 PyObject *ToroidPy::_getattr(char *attr)
00558 {
00559 try {
00560
00561 PyObject *r = getCustomAttributes(attr);
00562 if(r) return r;
00563 }
00564 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00565 catch(const Base::Exception& e)
00566 {
00567 std::string str;
00568 str += "FreeCAD exception thrown (";
00569 str += e.what();
00570 str += ")";
00571 e.ReportException();
00572 PyErr_SetString(PyExc_Exception,str.c_str());
00573 return NULL;
00574 }
00575 catch(const std::exception& e)
00576 {
00577 std::string str;
00578 str += "FC++ exception thrown (";
00579 str += e.what();
00580 str += ")";
00581 Base::Console().Error(str.c_str());
00582 PyErr_SetString(PyExc_Exception,str.c_str());
00583 return NULL;
00584 }
00585 catch(const Py::Exception&)
00586 {
00587
00588 return NULL;
00589 }
00590 catch(...)
00591 {
00592 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00593 return NULL;
00594 }
00595 #else // DONT_CATCH_CXX_EXCEPTIONS
00596 catch(const Base::Exception& e)
00597 {
00598 std::string str;
00599 str += "FreeCAD exception thrown (";
00600 str += e.what();
00601 str += ")";
00602 e.ReportException();
00603 PyErr_SetString(PyExc_Exception,str.c_str());
00604 return NULL;
00605 }
00606 catch(const Py::Exception&)
00607 {
00608
00609 return NULL;
00610 }
00611 #endif // DONT_CATCH_CXX_EXCEPTIONS
00612
00613 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00614 if (rvalue == NULL)
00615 {
00616 PyErr_Clear();
00617 return GeometrySurfacePy::_getattr(attr);
00618 }
00619 else
00620 {
00621 return rvalue;
00622 }
00623 }
00624
00625 int ToroidPy::_setattr(char *attr, PyObject *value)
00626 {
00627 try {
00628
00629 int r = setCustomAttributes(attr, value);
00630 if(r==1) return 0;
00631 }
00632 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00633 catch(const Base::Exception& e)
00634 {
00635 std::string str;
00636 str += "FreeCAD exception thrown (";
00637 str += e.what();
00638 str += ")";
00639 e.ReportException();
00640 PyErr_SetString(PyExc_Exception,str.c_str());
00641 return -1;
00642 }
00643 catch(const std::exception& e)
00644 {
00645 std::string str;
00646 str += "FC++ exception thrown (";
00647 str += e.what();
00648 str += ")";
00649 Base::Console().Error(str.c_str());
00650 PyErr_SetString(PyExc_Exception,str.c_str());
00651 return -1;
00652 }
00653 catch(const Py::Exception&)
00654 {
00655
00656 return -1;
00657 }
00658 catch(...)
00659 {
00660 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00661 return -1;
00662 }
00663 #else // DONT_CATCH_CXX_EXCEPTIONS
00664 catch(const Base::Exception& e)
00665 {
00666 std::string str;
00667 str += "FreeCAD exception thrown (";
00668 str += e.what();
00669 str += ")";
00670 e.ReportException();
00671 PyErr_SetString(PyExc_Exception,str.c_str());
00672 return -1;
00673 }
00674 catch(const Py::Exception&)
00675 {
00676
00677 return -1;
00678 }
00679 #endif // DONT_CATCH_CXX_EXCEPTIONS
00680
00681 return GeometrySurfacePy::_setattr(attr, value);
00682 }
00683
00684 GeomToroid *ToroidPy::getGeomToroidPtr(void) const
00685 {
00686 return static_cast<GeomToroid *>(_pcTwinPointer);
00687 }
00688
00689 #if 0
00690
00691
00692
00693
00694 PyObject *ToroidPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00695 {
00696
00697 return new ToroidPy(new GeomToroid);
00698 }
00699
00700
00701 int ToroidPy::PyInit(PyObject* , PyObject* )
00702 {
00703 return 0;
00704 }
00705
00706
00707 std::string ToroidPy::representation(void) const
00708 {
00709 return std::string("<GeomToroid object>");
00710 }
00711
00712 PyObject* ToroidPy::uIso(PyObject *args)
00713 {
00714 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00715 return 0;
00716 }
00717
00718 PyObject* ToroidPy::vIso(PyObject *args)
00719 {
00720 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00721 return 0;
00722 }
00723
00724
00725
00726 Py::Float ToroidPy::getMajorRadius(void) const
00727 {
00728
00729 throw Py::AttributeError("Not yet implemented");
00730 }
00731
00732 void ToroidPy::setMajorRadius(Py::Float arg)
00733 {
00734 throw Py::AttributeError("Not yet implemented");
00735 }
00736
00737 Py::Float ToroidPy::getMinorRadius(void) const
00738 {
00739
00740 throw Py::AttributeError("Not yet implemented");
00741 }
00742
00743 void ToroidPy::setMinorRadius(Py::Float arg)
00744 {
00745 throw Py::AttributeError("Not yet implemented");
00746 }
00747
00748 Py::Object ToroidPy::getCenter(void) const
00749 {
00750
00751 throw Py::AttributeError("Not yet implemented");
00752 }
00753
00754 void ToroidPy::setCenter(Py::Object arg)
00755 {
00756 throw Py::AttributeError("Not yet implemented");
00757 }
00758
00759 Py::Object ToroidPy::getAxis(void) const
00760 {
00761
00762 throw Py::AttributeError("Not yet implemented");
00763 }
00764
00765 void ToroidPy::setAxis(Py::Object arg)
00766 {
00767 throw Py::AttributeError("Not yet implemented");
00768 }
00769
00770 Py::Float ToroidPy::getArea(void) const
00771 {
00772
00773 throw Py::AttributeError("Not yet implemented");
00774 }
00775
00776 Py::Float ToroidPy::getVolume(void) const
00777 {
00778
00779 throw Py::AttributeError("Not yet implemented");
00780 }
00781
00782 PyObject *ToroidPy::getCustomAttributes(const char* attr) const
00783 {
00784 return 0;
00785 }
00786
00787 int ToroidPy::setCustomAttributes(const char* attr, PyObject *obj)
00788 {
00789 return 0;
00790 }
00791 #endif
00792
00793
00794