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