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 Mesh;
00018
00020 PyTypeObject FacetPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Mesh.Facet",
00024 sizeof(FacetPy),
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 "Facet in mesh\n"
00046 "This is a facet in a MeshObject. You can get it by e.g. iterating a\n"
00047 "mesh. The facet has a connection to its mesh and allows therefore\n"
00048 "topological operations. It is also possible to create an unbounded facet e.g. to create\n"
00049 "a mesh. In this case the topological operations will fail. The same is\n"
00050 "when you cut the bound to the mesh by calling unbound().\n"
00051 " ",
00052 0,
00053 0,
00054 0,
00055 0,
00056 0,
00057 0,
00058 Mesh::FacetPy::Methods,
00059 0,
00060 Mesh::FacetPy::GetterSetter,
00061 &Base::PyObjectBase::Type,
00062 0,
00063 0,
00064 0,
00065 0,
00066 __PyInit,
00067 0,
00068 Mesh::FacetPy::PyMake,
00069 0,
00070 0,
00071 0,
00072 0,
00073 0,
00074 0,
00075 0,
00076 0
00077 };
00078
00080 PyMethodDef FacetPy::Methods[] = {
00081 {"unbound",
00082 (PyCFunction) staticCallback_unbound,
00083 METH_VARARGS,
00084 "method unbound()\nCut the connection to a MeshObject. The facet becomes\nfree and is more or less a simple facet.\nAfter calling unbound() no topological operation will\nwork!\n "
00085 },
00086 {"intersect",
00087 (PyCFunction) staticCallback_intersect,
00088 METH_VARARGS,
00089 "intersect(Facet) -> list \nGet a list of intersection points with another triangle.\n "
00090 },
00091 {NULL, NULL, 0, NULL}
00092 };
00093
00094
00095
00097 PyGetSetDef FacetPy::GetterSetter[] = {
00098 {"Index",
00099 (getter) staticCallback_getIndex,
00100 (setter) staticCallback_setIndex,
00101 "The index of this facet in the MeshObject",
00102 NULL
00103 },
00104 {"Bound",
00105 (getter) staticCallback_getBound,
00106 (setter) staticCallback_setBound,
00107 "Bound state of the facet",
00108 NULL
00109 },
00110 {"Normal",
00111 (getter) staticCallback_getNormal,
00112 (setter) staticCallback_setNormal,
00113 "Normal vector of the facet.",
00114 NULL
00115 },
00116 {"Points",
00117 (getter) staticCallback_getPoints,
00118 (setter) staticCallback_setPoints,
00119 "A list of points of the facet",
00120 NULL
00121 },
00122 {NULL, NULL, NULL, NULL, NULL}
00123 };
00124
00125
00126
00127
00128 PyObject * FacetPy::staticCallback_unbound (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 = ((FacetPy*)self)->unbound(args);
00144 if (ret != 0)
00145 ((FacetPy*)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 * FacetPy::staticCallback_intersect (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 = ((FacetPy*)self)->intersect(args);
00220 if (ret != 0)
00221 ((FacetPy*)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 * FacetPy::staticCallback_getIndex (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(((FacetPy*)self)->getIndex());
00289 } catch (const Py::Exception&) {
00290
00291 return NULL;
00292 } catch (...) {
00293 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Index' of object 'Facet'");
00294 return NULL;
00295 }
00296 }
00297
00298 int FacetPy::staticCallback_setIndex (PyObject *self, PyObject * , 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
00305 PyErr_SetString(PyExc_AttributeError, "Attribute 'Index' of object 'Facet' is read-only");
00306 return -1;
00307 }
00308
00309
00310
00311
00312 PyObject * FacetPy::staticCallback_getBound (PyObject *self, void * )
00313 {
00314 if (!((PyObjectBase*) self)->isValid()){
00315 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00316 return NULL;
00317 }
00318
00319 try {
00320 return Py::new_reference_to(((FacetPy*)self)->getBound());
00321 } catch (const Py::Exception&) {
00322
00323 return NULL;
00324 } catch (...) {
00325 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Bound' of object 'Facet'");
00326 return NULL;
00327 }
00328 }
00329
00330 int FacetPy::staticCallback_setBound (PyObject *self, PyObject * , void * )
00331 {
00332 if (!((PyObjectBase*) self)->isValid()){
00333 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00334 return -1;
00335 }
00336
00337 PyErr_SetString(PyExc_AttributeError, "Attribute 'Bound' of object 'Facet' is read-only");
00338 return -1;
00339 }
00340
00341
00342
00343
00344 PyObject * FacetPy::staticCallback_getNormal (PyObject *self, void * )
00345 {
00346 if (!((PyObjectBase*) self)->isValid()){
00347 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00348 return NULL;
00349 }
00350
00351 try {
00352 return Py::new_reference_to(((FacetPy*)self)->getNormal());
00353 } catch (const Py::Exception&) {
00354
00355 return NULL;
00356 } catch (...) {
00357 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Normal' of object 'Facet'");
00358 return NULL;
00359 }
00360 }
00361
00362 int FacetPy::staticCallback_setNormal (PyObject *self, PyObject * , void * )
00363 {
00364 if (!((PyObjectBase*) self)->isValid()){
00365 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00366 return -1;
00367 }
00368
00369 PyErr_SetString(PyExc_AttributeError, "Attribute 'Normal' of object 'Facet' is read-only");
00370 return -1;
00371 }
00372
00373
00374
00375
00376 PyObject * FacetPy::staticCallback_getPoints (PyObject *self, void * )
00377 {
00378 if (!((PyObjectBase*) self)->isValid()){
00379 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00380 return NULL;
00381 }
00382
00383 try {
00384 return Py::new_reference_to(((FacetPy*)self)->getPoints());
00385 } catch (const Py::Exception&) {
00386
00387 return NULL;
00388 } catch (...) {
00389 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Points' of object 'Facet'");
00390 return NULL;
00391 }
00392 }
00393
00394 int FacetPy::staticCallback_setPoints (PyObject *self, PyObject * , void * )
00395 {
00396 if (!((PyObjectBase*) self)->isValid()){
00397 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00398 return -1;
00399 }
00400
00401 PyErr_SetString(PyExc_AttributeError, "Attribute 'Points' of object 'Facet' is read-only");
00402 return -1;
00403 }
00404
00405
00406
00407
00408
00409
00410 PyParentObject FacetPy::Parents[] = { PARENTSMeshFacetPy };
00411
00412
00413
00414
00415 FacetPy::FacetPy(Facet *pcObject, PyTypeObject *T)
00416 : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00417 {
00418 }
00419
00420
00421
00422
00423
00424 FacetPy::~FacetPy()
00425 {
00426
00427 FacetPy::PointerType ptr = reinterpret_cast<FacetPy::PointerType>(_pcTwinPointer);
00428 delete ptr;
00429 }
00430
00431
00432
00433
00434 PyObject *FacetPy::_repr(void)
00435 {
00436 return Py_BuildValue("s", representation().c_str());
00437 }
00438
00439
00440
00441
00442 PyObject *FacetPy::_getattr(char *attr)
00443 {
00444 try {
00445
00446 PyObject *r = getCustomAttributes(attr);
00447 if(r) return r;
00448 }
00449 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00450 catch(const Base::Exception& e)
00451 {
00452 std::string str;
00453 str += "FreeCAD exception thrown (";
00454 str += e.what();
00455 str += ")";
00456 e.ReportException();
00457 PyErr_SetString(PyExc_Exception,str.c_str());
00458 return NULL;
00459 }
00460 catch(const std::exception& e)
00461 {
00462 std::string str;
00463 str += "FC++ exception thrown (";
00464 str += e.what();
00465 str += ")";
00466 Base::Console().Error(str.c_str());
00467 PyErr_SetString(PyExc_Exception,str.c_str());
00468 return NULL;
00469 }
00470 catch(const Py::Exception&)
00471 {
00472
00473 return NULL;
00474 }
00475 catch(...)
00476 {
00477 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00478 return NULL;
00479 }
00480 #else // DONT_CATCH_CXX_EXCEPTIONS
00481 catch(const Base::Exception& e)
00482 {
00483 std::string str;
00484 str += "FreeCAD exception thrown (";
00485 str += e.what();
00486 str += ")";
00487 e.ReportException();
00488 PyErr_SetString(PyExc_Exception,str.c_str());
00489 return NULL;
00490 }
00491 catch(const Py::Exception&)
00492 {
00493
00494 return NULL;
00495 }
00496 #endif // DONT_CATCH_CXX_EXCEPTIONS
00497
00498 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00499 if (rvalue == NULL)
00500 {
00501 PyErr_Clear();
00502 return PyObjectBase::_getattr(attr);
00503 }
00504 else
00505 {
00506 return rvalue;
00507 }
00508 }
00509
00510 int FacetPy::_setattr(char *attr, PyObject *value)
00511 {
00512 try {
00513
00514 int r = setCustomAttributes(attr, value);
00515 if(r==1) return 0;
00516 }
00517 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00518 catch(const Base::Exception& e)
00519 {
00520 std::string str;
00521 str += "FreeCAD exception thrown (";
00522 str += e.what();
00523 str += ")";
00524 e.ReportException();
00525 PyErr_SetString(PyExc_Exception,str.c_str());
00526 return -1;
00527 }
00528 catch(const std::exception& e)
00529 {
00530 std::string str;
00531 str += "FC++ exception thrown (";
00532 str += e.what();
00533 str += ")";
00534 Base::Console().Error(str.c_str());
00535 PyErr_SetString(PyExc_Exception,str.c_str());
00536 return -1;
00537 }
00538 catch(const Py::Exception&)
00539 {
00540
00541 return -1;
00542 }
00543 catch(...)
00544 {
00545 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00546 return -1;
00547 }
00548 #else // DONT_CATCH_CXX_EXCEPTIONS
00549 catch(const Base::Exception& e)
00550 {
00551 std::string str;
00552 str += "FreeCAD exception thrown (";
00553 str += e.what();
00554 str += ")";
00555 e.ReportException();
00556 PyErr_SetString(PyExc_Exception,str.c_str());
00557 return -1;
00558 }
00559 catch(const Py::Exception&)
00560 {
00561
00562 return -1;
00563 }
00564 #endif // DONT_CATCH_CXX_EXCEPTIONS
00565
00566 return PyObjectBase::_setattr(attr, value);
00567 }
00568
00569 Facet *FacetPy::getFacetPtr(void) const
00570 {
00571 return static_cast<Facet *>(_pcTwinPointer);
00572 }
00573
00574 #if 0
00575
00576
00577
00578
00579 PyObject *FacetPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00580 {
00581
00582 return new FacetPy(new Facet);
00583 }
00584
00585
00586 int FacetPy::PyInit(PyObject* , PyObject* )
00587 {
00588 return 0;
00589 }
00590
00591
00592 std::string FacetPy::representation(void) const
00593 {
00594 return std::string("<Facet object>");
00595 }
00596
00597 PyObject* FacetPy::unbound(PyObject *args)
00598 {
00599 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00600 return 0;
00601 }
00602
00603 PyObject* FacetPy::intersect(PyObject *args)
00604 {
00605 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00606 return 0;
00607 }
00608
00609
00610
00611 Py::Int FacetPy::getIndex(void) const
00612 {
00613
00614 throw Py::AttributeError("Not yet implemented");
00615 }
00616
00617 Py::Boolean FacetPy::getBound(void) const
00618 {
00619
00620 throw Py::AttributeError("Not yet implemented");
00621 }
00622
00623 Py::Object FacetPy::getNormal(void) const
00624 {
00625
00626 throw Py::AttributeError("Not yet implemented");
00627 }
00628
00629 Py::List FacetPy::getPoints(void) const
00630 {
00631
00632 throw Py::AttributeError("Not yet implemented");
00633 }
00634
00635 PyObject *FacetPy::getCustomAttributes(const char* attr) const
00636 {
00637 return 0;
00638 }
00639
00640 int FacetPy::setCustomAttributes(const char* attr, PyObject *obj)
00641 {
00642 return 0;
00643 }
00644 #endif
00645
00646
00647