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