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