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