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