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 ViewProviderDocumentObjectPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Gui.ViewProviderDocumentObject",
00024 sizeof(ViewProviderDocumentObjectPy),
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 ViewProvider base class",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Gui::ViewProviderDocumentObjectPy::Methods,
00053 0,
00054 Gui::ViewProviderDocumentObjectPy::GetterSetter,
00055 &Gui::ViewProviderPy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Gui::ViewProviderDocumentObjectPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef ViewProviderDocumentObjectPy::Methods[] = {
00075 {"update",
00076 (PyCFunction) staticCallback_update,
00077 METH_VARARGS,
00078 "Update the view representation of the object"
00079 },
00080 {NULL, NULL, 0, NULL}
00081 };
00082
00083
00084
00086 PyGetSetDef ViewProviderDocumentObjectPy::GetterSetter[] = {
00087 {"Object",
00088 (getter) staticCallback_getObject,
00089 (setter) staticCallback_setObject,
00090 "Return the associated data object",
00091 NULL
00092 },
00093 {NULL, NULL, NULL, NULL, NULL}
00094 };
00095
00096
00097
00098
00099 PyObject * ViewProviderDocumentObjectPy::staticCallback_update (PyObject *self, PyObject *args)
00100 {
00101
00102 if (!((PyObjectBase*) self)->isValid()){
00103 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00104 return NULL;
00105 }
00106
00107
00108 if (((PyObjectBase*) self)->isConst()){
00109 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00110 return NULL;
00111 }
00112
00113 try {
00114 PyObject* ret = ((ViewProviderDocumentObjectPy*)self)->update(args);
00115 if (ret != 0)
00116 ((ViewProviderDocumentObjectPy*)self)->startNotify();
00117 return ret;
00118 }
00119 catch(const Base::Exception& e)
00120 {
00121 std::string str;
00122 str += "FreeCAD exception thrown (";
00123 str += e.what();
00124 str += ")";
00125 e.ReportException();
00126 PyErr_SetString(PyExc_Exception,str.c_str());
00127 return NULL;
00128 }
00129 catch(const boost::filesystem::filesystem_error& e)
00130 {
00131 std::string str;
00132 str += "File system exception thrown (";
00133
00134
00135 str += e.what();
00136 str += ")\n";
00137 Base::Console().Error(str.c_str());
00138 PyErr_SetString(PyExc_Exception,str.c_str());
00139 return NULL;
00140 }
00141 catch(const Py::Exception&)
00142 {
00143
00144 return NULL;
00145 }
00146 catch(const char* e)
00147 {
00148 Base::Console().Error(e);
00149 PyErr_SetString(PyExc_Exception,e);
00150 return NULL;
00151 }
00152
00153 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00154 catch(const std::exception& e)
00155 {
00156 std::string str;
00157 str += "FC++ exception thrown (";
00158 str += e.what();
00159 str += ")";
00160 Base::Console().Error(str.c_str());
00161 PyErr_SetString(PyExc_Exception,str.c_str());
00162 return NULL;
00163 }
00164 catch(...)
00165 {
00166 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00167 return NULL;
00168 }
00169 #endif
00170 }
00171
00172
00173
00174
00175 PyObject * ViewProviderDocumentObjectPy::staticCallback_getObject (PyObject *self, void * )
00176 {
00177 if (!((PyObjectBase*) self)->isValid()){
00178 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00179 return NULL;
00180 }
00181
00182 try {
00183 return Py::new_reference_to(((ViewProviderDocumentObjectPy*)self)->getObject());
00184 } catch (const Py::Exception&) {
00185
00186 return NULL;
00187 } catch (...) {
00188 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Object' of object 'ViewProviderDocumentObject'");
00189 return NULL;
00190 }
00191 }
00192
00193 int ViewProviderDocumentObjectPy::staticCallback_setObject (PyObject *self, PyObject * , void * )
00194 {
00195 if (!((PyObjectBase*) self)->isValid()){
00196 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00197 return -1;
00198 }
00199
00200 PyErr_SetString(PyExc_AttributeError, "Attribute 'Object' of object 'ViewProviderDocumentObject' is read-only");
00201 return -1;
00202 }
00203
00204
00205
00206
00207
00208
00209 PyParentObject ViewProviderDocumentObjectPy::Parents[] = { PARENTSGuiViewProviderDocumentObjectPy };
00210
00211
00212
00213
00214 ViewProviderDocumentObjectPy::ViewProviderDocumentObjectPy(ViewProviderDocumentObject *pcObject, PyTypeObject *T)
00215 : ViewProviderPy(reinterpret_cast<ViewProviderPy::PointerType>(pcObject), T)
00216 {
00217 }
00218
00219 PyObject *ViewProviderDocumentObjectPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00220 {
00221
00222 PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'ViewProviderDocumentObjectPy'.");
00223
00224 return 0;
00225 }
00226
00227 int ViewProviderDocumentObjectPy::PyInit(PyObject* , PyObject* )
00228 {
00229 return 0;
00230 }
00231
00232
00233
00234
00235 ViewProviderDocumentObjectPy::~ViewProviderDocumentObjectPy()
00236 {
00237 }
00238
00239
00240
00241
00242 PyObject *ViewProviderDocumentObjectPy::_repr(void)
00243 {
00244 return Py_BuildValue("s", representation().c_str());
00245 }
00246
00247
00248
00249
00250 PyObject *ViewProviderDocumentObjectPy::_getattr(char *attr)
00251 {
00252 try {
00253
00254 PyObject *r = getCustomAttributes(attr);
00255 if(r) return r;
00256 }
00257 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00258 catch(const Base::Exception& e)
00259 {
00260 std::string str;
00261 str += "FreeCAD exception thrown (";
00262 str += e.what();
00263 str += ")";
00264 e.ReportException();
00265 PyErr_SetString(PyExc_Exception,str.c_str());
00266 return NULL;
00267 }
00268 catch(const std::exception& e)
00269 {
00270 std::string str;
00271 str += "FC++ exception thrown (";
00272 str += e.what();
00273 str += ")";
00274 Base::Console().Error(str.c_str());
00275 PyErr_SetString(PyExc_Exception,str.c_str());
00276 return NULL;
00277 }
00278 catch(const Py::Exception&)
00279 {
00280
00281 return NULL;
00282 }
00283 catch(...)
00284 {
00285 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00286 return NULL;
00287 }
00288 #else // DONT_CATCH_CXX_EXCEPTIONS
00289 catch(const Base::Exception& e)
00290 {
00291 std::string str;
00292 str += "FreeCAD exception thrown (";
00293 str += e.what();
00294 str += ")";
00295 e.ReportException();
00296 PyErr_SetString(PyExc_Exception,str.c_str());
00297 return NULL;
00298 }
00299 catch(const Py::Exception&)
00300 {
00301
00302 return NULL;
00303 }
00304 #endif // DONT_CATCH_CXX_EXCEPTIONS
00305
00306 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00307 if (rvalue == NULL)
00308 {
00309 PyErr_Clear();
00310 return ViewProviderPy::_getattr(attr);
00311 }
00312 else
00313 {
00314 return rvalue;
00315 }
00316 }
00317
00318 int ViewProviderDocumentObjectPy::_setattr(char *attr, PyObject *value)
00319 {
00320 try {
00321
00322 int r = setCustomAttributes(attr, value);
00323 if(r==1) return 0;
00324 }
00325 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00326 catch(const Base::Exception& e)
00327 {
00328 std::string str;
00329 str += "FreeCAD exception thrown (";
00330 str += e.what();
00331 str += ")";
00332 e.ReportException();
00333 PyErr_SetString(PyExc_Exception,str.c_str());
00334 return -1;
00335 }
00336 catch(const std::exception& e)
00337 {
00338 std::string str;
00339 str += "FC++ exception thrown (";
00340 str += e.what();
00341 str += ")";
00342 Base::Console().Error(str.c_str());
00343 PyErr_SetString(PyExc_Exception,str.c_str());
00344 return -1;
00345 }
00346 catch(const Py::Exception&)
00347 {
00348
00349 return -1;
00350 }
00351 catch(...)
00352 {
00353 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00354 return -1;
00355 }
00356 #else // DONT_CATCH_CXX_EXCEPTIONS
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 -1;
00366 }
00367 catch(const Py::Exception&)
00368 {
00369
00370 return -1;
00371 }
00372 #endif // DONT_CATCH_CXX_EXCEPTIONS
00373
00374 return ViewProviderPy::_setattr(attr, value);
00375 }
00376
00377 ViewProviderDocumentObject *ViewProviderDocumentObjectPy::getViewProviderDocumentObjectPtr(void) const
00378 {
00379 return static_cast<ViewProviderDocumentObject *>(_pcTwinPointer);
00380 }
00381
00382 #if 0
00383
00384
00385
00386
00387
00388
00389 std::string ViewProviderDocumentObjectPy::representation(void) const
00390 {
00391 return std::string("<ViewProviderDocumentObject object>");
00392 }
00393
00394 PyObject* ViewProviderDocumentObjectPy::update(PyObject *args)
00395 {
00396 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00397 return 0;
00398 }
00399
00400
00401
00402 Py::Object ViewProviderDocumentObjectPy::getObject(void) const
00403 {
00404
00405 throw Py::AttributeError("Not yet implemented");
00406 }
00407
00408 PyObject *ViewProviderDocumentObjectPy::getCustomAttributes(const char* attr) const
00409 {
00410 return 0;
00411 }
00412
00413 int ViewProviderDocumentObjectPy::setCustomAttributes(const char* attr, PyObject *obj)
00414 {
00415 return 0;
00416 }
00417 #endif
00418
00419
00420