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