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