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