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