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