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