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 PartFeaturePy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Part.Feature",
00024 sizeof(PartFeaturePy),
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 father of all shape object classes",
00046 0,
00047 0,
00048 0,
00049 0,
00050 0,
00051 0,
00052 Part::PartFeaturePy::Methods,
00053 0,
00054 Part::PartFeaturePy::GetterSetter,
00055 &App::DocumentObjectPy::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Part::PartFeaturePy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef PartFeaturePy::Methods[] = {
00075 {NULL, NULL, 0, NULL}
00076 };
00077
00078
00079
00081 PyGetSetDef PartFeaturePy::GetterSetter[] = {
00082 {NULL, NULL, NULL, NULL, NULL}
00083 };
00084
00085
00086
00087
00088
00089
00090 PyParentObject PartFeaturePy::Parents[] = { PARENTSPartPartFeaturePy };
00091
00092
00093
00094
00095 PartFeaturePy::PartFeaturePy(Feature *pcObject, PyTypeObject *T)
00096 : DocumentObjectPy(reinterpret_cast<DocumentObjectPy::PointerType>(pcObject), T)
00097 {
00098 }
00099
00100 PyObject *PartFeaturePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00101 {
00102
00103 PyErr_SetString(PyExc_RuntimeError, "You cannot create directly an instance of 'PartFeaturePy'.");
00104
00105 return 0;
00106 }
00107
00108 int PartFeaturePy::PyInit(PyObject* , PyObject* )
00109 {
00110 return 0;
00111 }
00112
00113
00114
00115
00116 PartFeaturePy::~PartFeaturePy()
00117 {
00118 }
00119
00120
00121
00122
00123 PyObject *PartFeaturePy::_repr(void)
00124 {
00125 return Py_BuildValue("s", representation().c_str());
00126 }
00127
00128
00129
00130
00131 PyObject *PartFeaturePy::_getattr(char *attr)
00132 {
00133 try {
00134
00135 PyObject *r = getCustomAttributes(attr);
00136 if(r) return r;
00137 }
00138 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00139 catch(const Base::Exception& e)
00140 {
00141 std::string str;
00142 str += "FreeCAD exception thrown (";
00143 str += e.what();
00144 str += ")";
00145 e.ReportException();
00146 PyErr_SetString(PyExc_Exception,str.c_str());
00147 return NULL;
00148 }
00149 catch(const std::exception& e)
00150 {
00151 std::string str;
00152 str += "FC++ exception thrown (";
00153 str += e.what();
00154 str += ")";
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(...)
00165 {
00166 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00167 return NULL;
00168 }
00169 #else // DONT_CATCH_CXX_EXCEPTIONS
00170 catch(const Base::Exception& e)
00171 {
00172 std::string str;
00173 str += "FreeCAD exception thrown (";
00174 str += e.what();
00175 str += ")";
00176 e.ReportException();
00177 PyErr_SetString(PyExc_Exception,str.c_str());
00178 return NULL;
00179 }
00180 catch(const Py::Exception&)
00181 {
00182
00183 return NULL;
00184 }
00185 #endif // DONT_CATCH_CXX_EXCEPTIONS
00186
00187 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00188 if (rvalue == NULL)
00189 {
00190 PyErr_Clear();
00191 return DocumentObjectPy::_getattr(attr);
00192 }
00193 else
00194 {
00195 return rvalue;
00196 }
00197 }
00198
00199 int PartFeaturePy::_setattr(char *attr, PyObject *value)
00200 {
00201 try {
00202
00203 int r = setCustomAttributes(attr, value);
00204 if(r==1) return 0;
00205 }
00206 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00207 catch(const Base::Exception& e)
00208 {
00209 std::string str;
00210 str += "FreeCAD exception thrown (";
00211 str += e.what();
00212 str += ")";
00213 e.ReportException();
00214 PyErr_SetString(PyExc_Exception,str.c_str());
00215 return -1;
00216 }
00217 catch(const std::exception& e)
00218 {
00219 std::string str;
00220 str += "FC++ exception thrown (";
00221 str += e.what();
00222 str += ")";
00223 Base::Console().Error(str.c_str());
00224 PyErr_SetString(PyExc_Exception,str.c_str());
00225 return -1;
00226 }
00227 catch(const Py::Exception&)
00228 {
00229
00230 return -1;
00231 }
00232 catch(...)
00233 {
00234 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00235 return -1;
00236 }
00237 #else // DONT_CATCH_CXX_EXCEPTIONS
00238 catch(const Base::Exception& e)
00239 {
00240 std::string str;
00241 str += "FreeCAD exception thrown (";
00242 str += e.what();
00243 str += ")";
00244 e.ReportException();
00245 PyErr_SetString(PyExc_Exception,str.c_str());
00246 return -1;
00247 }
00248 catch(const Py::Exception&)
00249 {
00250
00251 return -1;
00252 }
00253 #endif // DONT_CATCH_CXX_EXCEPTIONS
00254
00255 return DocumentObjectPy::_setattr(attr, value);
00256 }
00257
00258 Feature *PartFeaturePy::getFeaturePtr(void) const
00259 {
00260 return static_cast<Feature *>(_pcTwinPointer);
00261 }
00262
00263 #if 0
00264
00265
00266
00267
00268
00269
00270 std::string PartFeaturePy::representation(void) const
00271 {
00272 return std::string("<Feature object>");
00273 }
00274
00275
00276
00277 PyObject *PartFeaturePy::getCustomAttributes(const char* attr) const
00278 {
00279 return 0;
00280 }
00281
00282 int PartFeaturePy::setCustomAttributes(const char* attr, PyObject *obj)
00283 {
00284 return 0;
00285 }
00286 #endif
00287
00288
00289