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 Gui;
00018
00020 PyTypeObject ViewProviderPythonFeaturePy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Gui.ViewProviderPythonFeature",
00024 sizeof(ViewProviderPythonFeaturePy),
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 the view provider class for Python features",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Gui::ViewProviderPythonFeaturePy::Methods,
00053 0,
00054 Gui::ViewProviderPythonFeaturePy::GetterSetter,
00055 &Gui::ViewProviderDocumentObjectPy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Gui::ViewProviderPythonFeaturePy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef ViewProviderPythonFeaturePy::Methods[] = {
00075 {"addDisplayMode",
00076 (PyCFunction) staticCallback_addDisplayMode,
00077 METH_VARARGS,
00078 "Add a new display mode to the view provider"
00079 },
00080 {"addProperty",
00081 (PyCFunction) staticCallback_addProperty,
00082 METH_VARARGS,
00083 "\n addProperty(string, string) -- Add a generic property.\n The first argument specifies the type, the second the\n name of the property.\n "
00084 },
00085 {"supportedProperties",
00086 (PyCFunction) staticCallback_supportedProperties,
00087 METH_VARARGS,
00088 "A list of supported property types"
00089 },
00090 {NULL, NULL, 0, NULL}
00091 };
00092
00093
00094
00096 PyGetSetDef ViewProviderPythonFeaturePy::GetterSetter[] = {
00097 {NULL, NULL, NULL, NULL, NULL}
00098 };
00099
00100
00101
00102
00103 PyObject * ViewProviderPythonFeaturePy::staticCallback_addDisplayMode (PyObject *self, PyObject *args)
00104 {
00105
00106 if (!((PyObjectBase*) self)->isValid()){
00107 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00108 return NULL;
00109 }
00110
00111
00112 if (((PyObjectBase*) self)->isConst()){
00113 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00114 return NULL;
00115 }
00116
00117 try {
00118 PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->addDisplayMode(args);
00119 if (ret != 0)
00120 ((ViewProviderPythonFeaturePy*)self)->startNotify();
00121 return ret;
00122 }
00123 catch(const Base::Exception& e)
00124 {
00125 std::string str;
00126 str += "FreeCAD exception thrown (";
00127 str += e.what();
00128 str += ")";
00129 e.ReportException();
00130 PyErr_SetString(PyExc_Exception,str.c_str());
00131 return NULL;
00132 }
00133 catch(const boost::filesystem::filesystem_error& e)
00134 {
00135 std::string str;
00136 str += "File system exception thrown (";
00137
00138
00139 str += e.what();
00140 str += ")\n";
00141 Base::Console().Error(str.c_str());
00142 PyErr_SetString(PyExc_Exception,str.c_str());
00143 return NULL;
00144 }
00145 catch(const Py::Exception&)
00146 {
00147
00148 return NULL;
00149 }
00150 catch(const char* e)
00151 {
00152 Base::Console().Error(e);
00153 PyErr_SetString(PyExc_Exception,e);
00154 return NULL;
00155 }
00156
00157 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00158 catch(const std::exception& e)
00159 {
00160 std::string str;
00161 str += "FC++ exception thrown (";
00162 str += e.what();
00163 str += ")";
00164 Base::Console().Error(str.c_str());
00165 PyErr_SetString(PyExc_Exception,str.c_str());
00166 return NULL;
00167 }
00168 catch(...)
00169 {
00170 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00171 return NULL;
00172 }
00173 #endif
00174 }
00175
00176
00177
00178
00179 PyObject * ViewProviderPythonFeaturePy::staticCallback_addProperty (PyObject *self, PyObject *args)
00180 {
00181
00182 if (!((PyObjectBase*) self)->isValid()){
00183 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00184 return NULL;
00185 }
00186
00187
00188 if (((PyObjectBase*) self)->isConst()){
00189 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00190 return NULL;
00191 }
00192
00193 try {
00194 PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->addProperty(args);
00195 if (ret != 0)
00196 ((ViewProviderPythonFeaturePy*)self)->startNotify();
00197 return ret;
00198 }
00199 catch(const Base::Exception& e)
00200 {
00201 std::string str;
00202 str += "FreeCAD exception thrown (";
00203 str += e.what();
00204 str += ")";
00205 e.ReportException();
00206 PyErr_SetString(PyExc_Exception,str.c_str());
00207 return NULL;
00208 }
00209 catch(const boost::filesystem::filesystem_error& e)
00210 {
00211 std::string str;
00212 str += "File system exception thrown (";
00213
00214
00215 str += e.what();
00216 str += ")\n";
00217 Base::Console().Error(str.c_str());
00218 PyErr_SetString(PyExc_Exception,str.c_str());
00219 return NULL;
00220 }
00221 catch(const Py::Exception&)
00222 {
00223
00224 return NULL;
00225 }
00226 catch(const char* e)
00227 {
00228 Base::Console().Error(e);
00229 PyErr_SetString(PyExc_Exception,e);
00230 return NULL;
00231 }
00232
00233 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00234 catch(const std::exception& e)
00235 {
00236 std::string str;
00237 str += "FC++ exception thrown (";
00238 str += e.what();
00239 str += ")";
00240 Base::Console().Error(str.c_str());
00241 PyErr_SetString(PyExc_Exception,str.c_str());
00242 return NULL;
00243 }
00244 catch(...)
00245 {
00246 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00247 return NULL;
00248 }
00249 #endif
00250 }
00251
00252
00253
00254
00255 PyObject * ViewProviderPythonFeaturePy::staticCallback_supportedProperties (PyObject *self, PyObject *args)
00256 {
00257
00258 if (!((PyObjectBase*) self)->isValid()){
00259 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00260 return NULL;
00261 }
00262
00263
00264 if (((PyObjectBase*) self)->isConst()){
00265 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00266 return NULL;
00267 }
00268
00269 try {
00270 PyObject* ret = ((ViewProviderPythonFeaturePy*)self)->supportedProperties(args);
00271 if (ret != 0)
00272 ((ViewProviderPythonFeaturePy*)self)->startNotify();
00273 return ret;
00274 }
00275 catch(const Base::Exception& e)
00276 {
00277 std::string str;
00278 str += "FreeCAD exception thrown (";
00279 str += e.what();
00280 str += ")";
00281 e.ReportException();
00282 PyErr_SetString(PyExc_Exception,str.c_str());
00283 return NULL;
00284 }
00285 catch(const boost::filesystem::filesystem_error& e)
00286 {
00287 std::string str;
00288 str += "File system exception thrown (";
00289
00290
00291 str += e.what();
00292 str += ")\n";
00293 Base::Console().Error(str.c_str());
00294 PyErr_SetString(PyExc_Exception,str.c_str());
00295 return NULL;
00296 }
00297 catch(const Py::Exception&)
00298 {
00299
00300 return NULL;
00301 }
00302 catch(const char* e)
00303 {
00304 Base::Console().Error(e);
00305 PyErr_SetString(PyExc_Exception,e);
00306 return NULL;
00307 }
00308
00309 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00310 catch(const std::exception& e)
00311 {
00312 std::string str;
00313 str += "FC++ exception thrown (";
00314 str += e.what();
00315 str += ")";
00316 Base::Console().Error(str.c_str());
00317 PyErr_SetString(PyExc_Exception,str.c_str());
00318 return NULL;
00319 }
00320 catch(...)
00321 {
00322 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00323 return NULL;
00324 }
00325 #endif
00326 }
00327
00328
00329
00330
00331
00332
00333 PyParentObject ViewProviderPythonFeaturePy::Parents[] = { PARENTSGuiViewProviderPythonFeaturePy };
00334
00335
00336
00337
00338 ViewProviderPythonFeaturePy::ViewProviderPythonFeaturePy(ViewProviderDocumentObject *pcObject, PyTypeObject *T)
00339 : ViewProviderDocumentObjectPy(reinterpret_cast<ViewProviderDocumentObjectPy::PointerType>(pcObject), T)
00340 {
00341 }
00342
00343 PyObject *ViewProviderPythonFeaturePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00344 {
00345
00346 PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'ViewProviderPythonFeaturePy'.");
00347
00348 return 0;
00349 }
00350
00351 int ViewProviderPythonFeaturePy::PyInit(PyObject* , PyObject* )
00352 {
00353 return 0;
00354 }
00355
00356
00357
00358
00359 ViewProviderPythonFeaturePy::~ViewProviderPythonFeaturePy()
00360 {
00361 }
00362
00363
00364
00365
00366 PyObject *ViewProviderPythonFeaturePy::_repr(void)
00367 {
00368 return Py_BuildValue("s", representation().c_str());
00369 }
00370
00371
00372
00373
00374 PyObject *ViewProviderPythonFeaturePy::_getattr(char *attr)
00375 {
00376 try {
00377
00378 PyObject *r = getCustomAttributes(attr);
00379 if(r) return r;
00380 }
00381 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00382 catch(const Base::Exception& e)
00383 {
00384 std::string str;
00385 str += "FreeCAD exception thrown (";
00386 str += e.what();
00387 str += ")";
00388 e.ReportException();
00389 PyErr_SetString(PyExc_Exception,str.c_str());
00390 return NULL;
00391 }
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(const Py::Exception&)
00403 {
00404
00405 return NULL;
00406 }
00407 catch(...)
00408 {
00409 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00410 return NULL;
00411 }
00412 #else // DONT_CATCH_CXX_EXCEPTIONS
00413 catch(const Base::Exception& e)
00414 {
00415 std::string str;
00416 str += "FreeCAD exception thrown (";
00417 str += e.what();
00418 str += ")";
00419 e.ReportException();
00420 PyErr_SetString(PyExc_Exception,str.c_str());
00421 return NULL;
00422 }
00423 catch(const Py::Exception&)
00424 {
00425
00426 return NULL;
00427 }
00428 #endif // DONT_CATCH_CXX_EXCEPTIONS
00429
00430 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00431 if (rvalue == NULL)
00432 {
00433 PyErr_Clear();
00434 return ViewProviderDocumentObjectPy::_getattr(attr);
00435 }
00436 else
00437 {
00438 return rvalue;
00439 }
00440 }
00441
00442 int ViewProviderPythonFeaturePy::_setattr(char *attr, PyObject *value)
00443 {
00444 try {
00445
00446 int r = setCustomAttributes(attr, value);
00447 if(r==1) return 0;
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 -1;
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 -1;
00469 }
00470 catch(const Py::Exception&)
00471 {
00472
00473 return -1;
00474 }
00475 catch(...)
00476 {
00477 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00478 return -1;
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 -1;
00490 }
00491 catch(const Py::Exception&)
00492 {
00493
00494 return -1;
00495 }
00496 #endif // DONT_CATCH_CXX_EXCEPTIONS
00497
00498 return ViewProviderDocumentObjectPy::_setattr(attr, value);
00499 }
00500
00501 ViewProviderDocumentObject *ViewProviderPythonFeaturePy::getViewProviderPythonFeaturePtr(void) const
00502 {
00503 return static_cast<ViewProviderDocumentObject *>(_pcTwinPointer);
00504 }
00505
00506 #if 0
00507
00508
00509
00510
00511
00512
00513 std::string ViewProviderPythonFeaturePy::representation(void) const
00514 {
00515 return std::string("<ViewProviderPythonFeature object>");
00516 }
00517
00518 PyObject* ViewProviderPythonFeaturePy::addDisplayMode(PyObject *args)
00519 {
00520 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00521 return 0;
00522 }
00523
00524 PyObject* ViewProviderPythonFeaturePy::addProperty(PyObject *args)
00525 {
00526 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00527 return 0;
00528 }
00529
00530 PyObject* ViewProviderPythonFeaturePy::supportedProperties(PyObject *args)
00531 {
00532 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00533 return 0;
00534 }
00535
00536
00537
00538 PyObject *ViewProviderPythonFeaturePy::getCustomAttributes(const char* attr) const
00539 {
00540 return 0;
00541 }
00542
00543 int ViewProviderPythonFeaturePy::setCustomAttributes(const char* attr, PyObject *obj)
00544 {
00545 return 0;
00546 }
00547 #endif
00548
00549
00550