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