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 CirclePy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Part.GeomCircle",
00024 sizeof(CirclePy),
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 "Describes a circle in 3D space\n"
00046 "To create a circle there are several ways:\n"
00047 "Part.Circle()\n"
00048 " Creates a default circle with center (0,0,0) and radius 1\n"
00049 "\n"
00050 "Part.Circle(Circle)\n"
00051 " Creates a copy of the given circle\n"
00052 "\n"
00053 "Part.Circle(Circle, Distance)\n"
00054 " Creates a circle parallel to given circle at a certain distance\n"
00055 "\n"
00056 "Part.Circle(Center,Normal,Radius)\n"
00057 " Creates a circle defined by center, normal direction and radius\n"
00058 "\n"
00059 "Part.Circle(Point1,Point2,Point3)\n"
00060 " Creates a circle defined by three non-linear points\n"
00061 " ",
00062 0,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 Part::CirclePy::Methods,
00069 0,
00070 Part::CirclePy::GetterSetter,
00071 &Part::GeometryCurvePy::Type,
00072 0,
00073 0,
00074 0,
00075 0,
00076 __PyInit,
00077 0,
00078 Part::CirclePy::PyMake,
00079 0,
00080 0,
00081 0,
00082 0,
00083 0,
00084 0,
00085 0,
00086 0
00087 };
00088
00090 PyMethodDef CirclePy::Methods[] = {
00091 {NULL, NULL, 0, NULL}
00092 };
00093
00094
00095
00097 PyGetSetDef CirclePy::GetterSetter[] = {
00098 {"Radius",
00099 (getter) staticCallback_getRadius,
00100 (setter) staticCallback_setRadius,
00101 "The radius of the circle.",
00102 NULL
00103 },
00104 {"Center",
00105 (getter) staticCallback_getCenter,
00106 (setter) staticCallback_setCenter,
00107 "Center of the circle.",
00108 NULL
00109 },
00110 {"Axis",
00111 (getter) staticCallback_getAxis,
00112 (setter) staticCallback_setAxis,
00113 "The axis direction of the circle",
00114 NULL
00115 },
00116 {NULL, NULL, NULL, NULL, NULL}
00117 };
00118
00119
00120
00121
00122 PyObject * CirclePy::staticCallback_getRadius (PyObject *self, void * )
00123 {
00124 if (!((PyObjectBase*) self)->isValid()){
00125 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00126 return NULL;
00127 }
00128
00129 try {
00130 return Py::new_reference_to(((CirclePy*)self)->getRadius());
00131 } catch (const Py::Exception&) {
00132
00133 return NULL;
00134 } catch (...) {
00135 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Radius' of object 'GeomCircle'");
00136 return NULL;
00137 }
00138 }
00139
00140 int CirclePy::staticCallback_setRadius (PyObject *self, PyObject *value, void * )
00141 {
00142 if (!((PyObjectBase*) self)->isValid()){
00143 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00144 return -1;
00145 }
00146 if (((PyObjectBase*) self)->isConst()){
00147 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00148 return -1;
00149 }
00150
00151 try {
00152 ((CirclePy*)self)->setRadius(Py::Float(value,false));
00153 return 0;
00154 } catch (const Py::Exception&) {
00155
00156 return -1;
00157 } catch (...) {
00158 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Radius' of object 'GeomCircle'");
00159 return -1;
00160 }
00161 }
00162
00163
00164
00165
00166 PyObject * CirclePy::staticCallback_getCenter (PyObject *self, void * )
00167 {
00168 if (!((PyObjectBase*) self)->isValid()){
00169 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00170 return NULL;
00171 }
00172
00173 try {
00174 return Py::new_reference_to(((CirclePy*)self)->getCenter());
00175 } catch (const Py::Exception&) {
00176
00177 return NULL;
00178 } catch (...) {
00179 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Center' of object 'GeomCircle'");
00180 return NULL;
00181 }
00182 }
00183
00184 int CirclePy::staticCallback_setCenter (PyObject *self, PyObject *value, void * )
00185 {
00186 if (!((PyObjectBase*) self)->isValid()){
00187 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00188 return -1;
00189 }
00190 if (((PyObjectBase*) self)->isConst()){
00191 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00192 return -1;
00193 }
00194
00195 try {
00196 ((CirclePy*)self)->setCenter(Py::Object(value,false));
00197 return 0;
00198 } catch (const Py::Exception&) {
00199
00200 return -1;
00201 } catch (...) {
00202 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Center' of object 'GeomCircle'");
00203 return -1;
00204 }
00205 }
00206
00207
00208
00209
00210 PyObject * CirclePy::staticCallback_getAxis (PyObject *self, void * )
00211 {
00212 if (!((PyObjectBase*) self)->isValid()){
00213 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00214 return NULL;
00215 }
00216
00217 try {
00218 return Py::new_reference_to(((CirclePy*)self)->getAxis());
00219 } catch (const Py::Exception&) {
00220
00221 return NULL;
00222 } catch (...) {
00223 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'GeomCircle'");
00224 return NULL;
00225 }
00226 }
00227
00228 int CirclePy::staticCallback_setAxis (PyObject *self, PyObject *value, void * )
00229 {
00230 if (!((PyObjectBase*) self)->isValid()){
00231 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00232 return -1;
00233 }
00234 if (((PyObjectBase*) self)->isConst()){
00235 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00236 return -1;
00237 }
00238
00239 try {
00240 ((CirclePy*)self)->setAxis(Py::Object(value,false));
00241 return 0;
00242 } catch (const Py::Exception&) {
00243
00244 return -1;
00245 } catch (...) {
00246 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Axis' of object 'GeomCircle'");
00247 return -1;
00248 }
00249 }
00250
00251
00252
00253
00254
00255
00256 PyParentObject CirclePy::Parents[] = { PARENTSPartCirclePy };
00257
00258
00259
00260
00261 CirclePy::CirclePy(GeomCircle *pcObject, PyTypeObject *T)
00262 : GeometryCurvePy(reinterpret_cast<GeometryCurvePy::PointerType>(pcObject), T)
00263 {
00264 }
00265
00266
00267
00268
00269
00270 CirclePy::~CirclePy()
00271 {
00272 }
00273
00274
00275
00276
00277 PyObject *CirclePy::_repr(void)
00278 {
00279 return Py_BuildValue("s", representation().c_str());
00280 }
00281
00282
00283
00284
00285 PyObject *CirclePy::_getattr(char *attr)
00286 {
00287 try {
00288
00289 PyObject *r = getCustomAttributes(attr);
00290 if(r) return r;
00291 }
00292 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00293 catch(const Base::Exception& e)
00294 {
00295 std::string str;
00296 str += "FreeCAD exception thrown (";
00297 str += e.what();
00298 str += ")";
00299 e.ReportException();
00300 PyErr_SetString(PyExc_Exception,str.c_str());
00301 return NULL;
00302 }
00303 catch(const std::exception& e)
00304 {
00305 std::string str;
00306 str += "FC++ exception thrown (";
00307 str += e.what();
00308 str += ")";
00309 Base::Console().Error(str.c_str());
00310 PyErr_SetString(PyExc_Exception,str.c_str());
00311 return NULL;
00312 }
00313 catch(const Py::Exception&)
00314 {
00315
00316 return NULL;
00317 }
00318 catch(...)
00319 {
00320 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00321 return NULL;
00322 }
00323 #else // DONT_CATCH_CXX_EXCEPTIONS
00324 catch(const Base::Exception& e)
00325 {
00326 std::string str;
00327 str += "FreeCAD exception thrown (";
00328 str += e.what();
00329 str += ")";
00330 e.ReportException();
00331 PyErr_SetString(PyExc_Exception,str.c_str());
00332 return NULL;
00333 }
00334 catch(const Py::Exception&)
00335 {
00336
00337 return NULL;
00338 }
00339 #endif // DONT_CATCH_CXX_EXCEPTIONS
00340
00341 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00342 if (rvalue == NULL)
00343 {
00344 PyErr_Clear();
00345 return GeometryCurvePy::_getattr(attr);
00346 }
00347 else
00348 {
00349 return rvalue;
00350 }
00351 }
00352
00353 int CirclePy::_setattr(char *attr, PyObject *value)
00354 {
00355 try {
00356
00357 int r = setCustomAttributes(attr, value);
00358 if(r==1) return 0;
00359 }
00360 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00361 catch(const Base::Exception& e)
00362 {
00363 std::string str;
00364 str += "FreeCAD exception thrown (";
00365 str += e.what();
00366 str += ")";
00367 e.ReportException();
00368 PyErr_SetString(PyExc_Exception,str.c_str());
00369 return -1;
00370 }
00371 catch(const std::exception& e)
00372 {
00373 std::string str;
00374 str += "FC++ exception thrown (";
00375 str += e.what();
00376 str += ")";
00377 Base::Console().Error(str.c_str());
00378 PyErr_SetString(PyExc_Exception,str.c_str());
00379 return -1;
00380 }
00381 catch(const Py::Exception&)
00382 {
00383
00384 return -1;
00385 }
00386 catch(...)
00387 {
00388 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00389 return -1;
00390 }
00391 #else // DONT_CATCH_CXX_EXCEPTIONS
00392 catch(const Base::Exception& e)
00393 {
00394 std::string str;
00395 str += "FreeCAD exception thrown (";
00396 str += e.what();
00397 str += ")";
00398 e.ReportException();
00399 PyErr_SetString(PyExc_Exception,str.c_str());
00400 return -1;
00401 }
00402 catch(const Py::Exception&)
00403 {
00404
00405 return -1;
00406 }
00407 #endif // DONT_CATCH_CXX_EXCEPTIONS
00408
00409 return GeometryCurvePy::_setattr(attr, value);
00410 }
00411
00412 GeomCircle *CirclePy::getGeomCirclePtr(void) const
00413 {
00414 return static_cast<GeomCircle *>(_pcTwinPointer);
00415 }
00416
00417 #if 0
00418
00419
00420
00421
00422 PyObject *CirclePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00423 {
00424
00425 return new CirclePy(new GeomCircle);
00426 }
00427
00428
00429 int CirclePy::PyInit(PyObject* , PyObject* )
00430 {
00431 return 0;
00432 }
00433
00434
00435 std::string CirclePy::representation(void) const
00436 {
00437 return std::string("<GeomCircle object>");
00438 }
00439
00440
00441
00442 Py::Float CirclePy::getRadius(void) const
00443 {
00444
00445 throw Py::AttributeError("Not yet implemented");
00446 }
00447
00448 void CirclePy::setRadius(Py::Float arg)
00449 {
00450 throw Py::AttributeError("Not yet implemented");
00451 }
00452
00453 Py::Object CirclePy::getCenter(void) const
00454 {
00455
00456 throw Py::AttributeError("Not yet implemented");
00457 }
00458
00459 void CirclePy::setCenter(Py::Object arg)
00460 {
00461 throw Py::AttributeError("Not yet implemented");
00462 }
00463
00464 Py::Object CirclePy::getAxis(void) const
00465 {
00466
00467 throw Py::AttributeError("Not yet implemented");
00468 }
00469
00470 void CirclePy::setAxis(Py::Object arg)
00471 {
00472 throw Py::AttributeError("Not yet implemented");
00473 }
00474
00475 PyObject *CirclePy::getCustomAttributes(const char* attr) const
00476 {
00477 return 0;
00478 }
00479
00480 int CirclePy::setCustomAttributes(const char* attr, PyObject *obj)
00481 {
00482 return 0;
00483 }
00484 #endif
00485
00486
00487