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