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 PlanePy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Part.GeomPlane",
00024 sizeof(PlanePy),
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 an infinite plane\n"
00046 "To create a plane there are several ways:\n"
00047 "Part.Plane()\n"
00048 " Creates a default plane with base (0,0,0) and normal (0,0,1)\n"
00049 "\n"
00050 "Part.Plane(Plane)\n"
00051 " Creates a copy of the given plane\n"
00052 "\n"
00053 "Part.Plane(Plane, Distance)\n"
00054 " Creates a plane parallel to given plane at a certain distance\n"
00055 "\n"
00056 "Part.Plane(Location,Normal)\n"
00057 " Creates a plane with a given location and normal\n"
00058 "\n"
00059 "Part.Plane(Point1,Point2,Point3)\n"
00060 " Creates a plane defined by three non-linear points\n"
00061 "\n"
00062 "Part.Plane(A,B,C,D)\n"
00063 " Creates a plane from its cartesian equation\n"
00064 " Ax+By+Cz+D=0\n"
00065 "",
00066 0,
00067 0,
00068 0,
00069 0,
00070 0,
00071 0,
00072 Part::PlanePy::Methods,
00073 0,
00074 Part::PlanePy::GetterSetter,
00075 &Part::GeometrySurfacePy::Type,
00076 0,
00077 0,
00078 0,
00079 0,
00080 __PyInit,
00081 0,
00082 Part::PlanePy::PyMake,
00083 0,
00084 0,
00085 0,
00086 0,
00087 0,
00088 0,
00089 0,
00090 0
00091 };
00092
00094 PyMethodDef PlanePy::Methods[] = {
00095 {"uIso",
00096 (PyCFunction) staticCallback_uIso,
00097 METH_VARARGS,
00098 "Builds the U isoparametric line of this plane"
00099 },
00100 {"vIso",
00101 (PyCFunction) staticCallback_vIso,
00102 METH_VARARGS,
00103 "Builds the V isoparametric line of this plane"
00104 },
00105 {NULL, NULL, 0, NULL}
00106 };
00107
00108
00109
00111 PyGetSetDef PlanePy::GetterSetter[] = {
00112 {"Position",
00113 (getter) staticCallback_getPosition,
00114 (setter) staticCallback_setPosition,
00115 "Returns the position point of this plane.",
00116 NULL
00117 },
00118 {"Axis",
00119 (getter) staticCallback_getAxis,
00120 (setter) staticCallback_setAxis,
00121 "Returns the axis of this plane.",
00122 NULL
00123 },
00124 {NULL, NULL, NULL, NULL, NULL}
00125 };
00126
00127
00128
00129
00130 PyObject * PlanePy::staticCallback_uIso (PyObject *self, PyObject *args)
00131 {
00132
00133 if (!((PyObjectBase*) self)->isValid()){
00134 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00135 return NULL;
00136 }
00137
00138
00139 if (((PyObjectBase*) self)->isConst()){
00140 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00141 return NULL;
00142 }
00143
00144 try {
00145 PyObject* ret = ((PlanePy*)self)->uIso(args);
00146 if (ret != 0)
00147 ((PlanePy*)self)->startNotify();
00148 return ret;
00149 }
00150 catch(const Base::Exception& e)
00151 {
00152 std::string str;
00153 str += "FreeCAD exception thrown (";
00154 str += e.what();
00155 str += ")";
00156 e.ReportException();
00157 PyErr_SetString(PyExc_Exception,str.c_str());
00158 return NULL;
00159 }
00160 catch(const boost::filesystem::filesystem_error& e)
00161 {
00162 std::string str;
00163 str += "File system exception thrown (";
00164
00165
00166 str += e.what();
00167 str += ")\n";
00168 Base::Console().Error(str.c_str());
00169 PyErr_SetString(PyExc_Exception,str.c_str());
00170 return NULL;
00171 }
00172 catch(const Py::Exception&)
00173 {
00174
00175 return NULL;
00176 }
00177 catch(const char* e)
00178 {
00179 Base::Console().Error(e);
00180 PyErr_SetString(PyExc_Exception,e);
00181 return NULL;
00182 }
00183
00184 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00185 catch(const std::exception& e)
00186 {
00187 std::string str;
00188 str += "FC++ exception thrown (";
00189 str += e.what();
00190 str += ")";
00191 Base::Console().Error(str.c_str());
00192 PyErr_SetString(PyExc_Exception,str.c_str());
00193 return NULL;
00194 }
00195 catch(...)
00196 {
00197 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00198 return NULL;
00199 }
00200 #endif
00201 }
00202
00203
00204
00205
00206 PyObject * PlanePy::staticCallback_vIso (PyObject *self, PyObject *args)
00207 {
00208
00209 if (!((PyObjectBase*) self)->isValid()){
00210 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00211 return NULL;
00212 }
00213
00214
00215 if (((PyObjectBase*) self)->isConst()){
00216 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00217 return NULL;
00218 }
00219
00220 try {
00221 PyObject* ret = ((PlanePy*)self)->vIso(args);
00222 if (ret != 0)
00223 ((PlanePy*)self)->startNotify();
00224 return ret;
00225 }
00226 catch(const Base::Exception& e)
00227 {
00228 std::string str;
00229 str += "FreeCAD exception thrown (";
00230 str += e.what();
00231 str += ")";
00232 e.ReportException();
00233 PyErr_SetString(PyExc_Exception,str.c_str());
00234 return NULL;
00235 }
00236 catch(const boost::filesystem::filesystem_error& e)
00237 {
00238 std::string str;
00239 str += "File system exception thrown (";
00240
00241
00242 str += e.what();
00243 str += ")\n";
00244 Base::Console().Error(str.c_str());
00245 PyErr_SetString(PyExc_Exception,str.c_str());
00246 return NULL;
00247 }
00248 catch(const Py::Exception&)
00249 {
00250
00251 return NULL;
00252 }
00253 catch(const char* e)
00254 {
00255 Base::Console().Error(e);
00256 PyErr_SetString(PyExc_Exception,e);
00257 return NULL;
00258 }
00259
00260 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00261 catch(const std::exception& e)
00262 {
00263 std::string str;
00264 str += "FC++ exception thrown (";
00265 str += e.what();
00266 str += ")";
00267 Base::Console().Error(str.c_str());
00268 PyErr_SetString(PyExc_Exception,str.c_str());
00269 return NULL;
00270 }
00271 catch(...)
00272 {
00273 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00274 return NULL;
00275 }
00276 #endif
00277 }
00278
00279
00280
00281
00282 PyObject * PlanePy::staticCallback_getPosition (PyObject *self, void * )
00283 {
00284 if (!((PyObjectBase*) self)->isValid()){
00285 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00286 return NULL;
00287 }
00288
00289 try {
00290 return Py::new_reference_to(((PlanePy*)self)->getPosition());
00291 } catch (const Py::Exception&) {
00292
00293 return NULL;
00294 } catch (...) {
00295 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Position' of object 'GeomPlane'");
00296 return NULL;
00297 }
00298 }
00299
00300 int PlanePy::staticCallback_setPosition (PyObject *self, PyObject *value, void * )
00301 {
00302 if (!((PyObjectBase*) self)->isValid()){
00303 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00304 return -1;
00305 }
00306 if (((PyObjectBase*) self)->isConst()){
00307 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00308 return -1;
00309 }
00310
00311 try {
00312 ((PlanePy*)self)->setPosition(Py::Object(value,false));
00313 return 0;
00314 } catch (const Py::Exception&) {
00315
00316 return -1;
00317 } catch (...) {
00318 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Position' of object 'GeomPlane'");
00319 return -1;
00320 }
00321 }
00322
00323
00324
00325
00326 PyObject * PlanePy::staticCallback_getAxis (PyObject *self, void * )
00327 {
00328 if (!((PyObjectBase*) self)->isValid()){
00329 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00330 return NULL;
00331 }
00332
00333 try {
00334 return Py::new_reference_to(((PlanePy*)self)->getAxis());
00335 } catch (const Py::Exception&) {
00336
00337 return NULL;
00338 } catch (...) {
00339 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Axis' of object 'GeomPlane'");
00340 return NULL;
00341 }
00342 }
00343
00344 int PlanePy::staticCallback_setAxis (PyObject *self, PyObject *value, void * )
00345 {
00346 if (!((PyObjectBase*) self)->isValid()){
00347 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00348 return -1;
00349 }
00350 if (((PyObjectBase*) self)->isConst()){
00351 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00352 return -1;
00353 }
00354
00355 try {
00356 ((PlanePy*)self)->setAxis(Py::Object(value,false));
00357 return 0;
00358 } catch (const Py::Exception&) {
00359
00360 return -1;
00361 } catch (...) {
00362 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Axis' of object 'GeomPlane'");
00363 return -1;
00364 }
00365 }
00366
00367
00368
00369
00370
00371
00372 PyParentObject PlanePy::Parents[] = { PARENTSPartPlanePy };
00373
00374
00375
00376
00377 PlanePy::PlanePy(GeomPlane *pcObject, PyTypeObject *T)
00378 : GeometrySurfacePy(reinterpret_cast<GeometrySurfacePy::PointerType>(pcObject), T)
00379 {
00380 }
00381
00382
00383
00384
00385
00386 PlanePy::~PlanePy()
00387 {
00388 }
00389
00390
00391
00392
00393 PyObject *PlanePy::_repr(void)
00394 {
00395 return Py_BuildValue("s", representation().c_str());
00396 }
00397
00398
00399
00400
00401 PyObject *PlanePy::_getattr(char *attr)
00402 {
00403 try {
00404
00405 PyObject *r = getCustomAttributes(attr);
00406 if(r) return r;
00407 }
00408 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00409 catch(const Base::Exception& e)
00410 {
00411 std::string str;
00412 str += "FreeCAD exception thrown (";
00413 str += e.what();
00414 str += ")";
00415 e.ReportException();
00416 PyErr_SetString(PyExc_Exception,str.c_str());
00417 return NULL;
00418 }
00419 catch(const std::exception& e)
00420 {
00421 std::string str;
00422 str += "FC++ exception thrown (";
00423 str += e.what();
00424 str += ")";
00425 Base::Console().Error(str.c_str());
00426 PyErr_SetString(PyExc_Exception,str.c_str());
00427 return NULL;
00428 }
00429 catch(const Py::Exception&)
00430 {
00431
00432 return NULL;
00433 }
00434 catch(...)
00435 {
00436 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00437 return NULL;
00438 }
00439 #else // DONT_CATCH_CXX_EXCEPTIONS
00440 catch(const Base::Exception& e)
00441 {
00442 std::string str;
00443 str += "FreeCAD exception thrown (";
00444 str += e.what();
00445 str += ")";
00446 e.ReportException();
00447 PyErr_SetString(PyExc_Exception,str.c_str());
00448 return NULL;
00449 }
00450 catch(const Py::Exception&)
00451 {
00452
00453 return NULL;
00454 }
00455 #endif // DONT_CATCH_CXX_EXCEPTIONS
00456
00457 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00458 if (rvalue == NULL)
00459 {
00460 PyErr_Clear();
00461 return GeometrySurfacePy::_getattr(attr);
00462 }
00463 else
00464 {
00465 return rvalue;
00466 }
00467 }
00468
00469 int PlanePy::_setattr(char *attr, PyObject *value)
00470 {
00471 try {
00472
00473 int r = setCustomAttributes(attr, value);
00474 if(r==1) return 0;
00475 }
00476 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00477 catch(const Base::Exception& e)
00478 {
00479 std::string str;
00480 str += "FreeCAD exception thrown (";
00481 str += e.what();
00482 str += ")";
00483 e.ReportException();
00484 PyErr_SetString(PyExc_Exception,str.c_str());
00485 return -1;
00486 }
00487 catch(const std::exception& e)
00488 {
00489 std::string str;
00490 str += "FC++ exception thrown (";
00491 str += e.what();
00492 str += ")";
00493 Base::Console().Error(str.c_str());
00494 PyErr_SetString(PyExc_Exception,str.c_str());
00495 return -1;
00496 }
00497 catch(const Py::Exception&)
00498 {
00499
00500 return -1;
00501 }
00502 catch(...)
00503 {
00504 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00505 return -1;
00506 }
00507 #else // DONT_CATCH_CXX_EXCEPTIONS
00508 catch(const Base::Exception& e)
00509 {
00510 std::string str;
00511 str += "FreeCAD exception thrown (";
00512 str += e.what();
00513 str += ")";
00514 e.ReportException();
00515 PyErr_SetString(PyExc_Exception,str.c_str());
00516 return -1;
00517 }
00518 catch(const Py::Exception&)
00519 {
00520
00521 return -1;
00522 }
00523 #endif // DONT_CATCH_CXX_EXCEPTIONS
00524
00525 return GeometrySurfacePy::_setattr(attr, value);
00526 }
00527
00528 GeomPlane *PlanePy::getGeomPlanePtr(void) const
00529 {
00530 return static_cast<GeomPlane *>(_pcTwinPointer);
00531 }
00532
00533 #if 0
00534
00535
00536
00537
00538 PyObject *PlanePy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00539 {
00540
00541 return new PlanePy(new GeomPlane);
00542 }
00543
00544
00545 int PlanePy::PyInit(PyObject* , PyObject* )
00546 {
00547 return 0;
00548 }
00549
00550
00551 std::string PlanePy::representation(void) const
00552 {
00553 return std::string("<GeomPlane object>");
00554 }
00555
00556 PyObject* PlanePy::uIso(PyObject *args)
00557 {
00558 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00559 return 0;
00560 }
00561
00562 PyObject* PlanePy::vIso(PyObject *args)
00563 {
00564 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00565 return 0;
00566 }
00567
00568
00569
00570 Py::Object PlanePy::getPosition(void) const
00571 {
00572
00573 throw Py::AttributeError("Not yet implemented");
00574 }
00575
00576 void PlanePy::setPosition(Py::Object arg)
00577 {
00578 throw Py::AttributeError("Not yet implemented");
00579 }
00580
00581 Py::Object PlanePy::getAxis(void) const
00582 {
00583
00584 throw Py::AttributeError("Not yet implemented");
00585 }
00586
00587 void PlanePy::setAxis(Py::Object arg)
00588 {
00589 throw Py::AttributeError("Not yet implemented");
00590 }
00591
00592 PyObject *PlanePy::getCustomAttributes(const char* attr) const
00593 {
00594 return 0;
00595 }
00596
00597 int PlanePy::setCustomAttributes(const char* attr, PyObject *obj)
00598 {
00599 return 0;
00600 }
00601 #endif
00602
00603
00604