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 GeometryPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Part.Geometry",
00024 sizeof(GeometryPy),
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 "The abstract class Geometry for 3D space is the root class of all geometric objects.\n"
00046 "It describes the common behavior of these objects when:\n"
00047 "- applying geometric transformations to objects, and\n"
00048 "- constructing objects by geometric transformation (including copying).",
00049 0,
00050 0,
00051 0,
00052 0,
00053 0,
00054 0,
00055 Part::GeometryPy::Methods,
00056 0,
00057 Part::GeometryPy::GetterSetter,
00058 &Base::PyObjectBase::Type,
00059 0,
00060 0,
00061 0,
00062 0,
00063 __PyInit,
00064 0,
00065 Part::GeometryPy::PyMake,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0,
00071 0,
00072 0,
00073 0
00074 };
00075
00077 PyMethodDef GeometryPy::Methods[] = {
00078 {"mirror",
00079 (PyCFunction) staticCallback_mirror,
00080 METH_VARARGS,
00081 "Performs the symmetrical transformation of this geometric object"
00082 },
00083 {"rotate",
00084 (PyCFunction) staticCallback_rotate,
00085 METH_VARARGS,
00086 "Rotates this geometric object at angle Ang (in radians) about axis"
00087 },
00088 {"scale",
00089 (PyCFunction) staticCallback_scale,
00090 METH_VARARGS,
00091 "Applies a scaling transformation on this geometric object with a center and scaling factor"
00092 },
00093 {"transform",
00094 (PyCFunction) staticCallback_transform,
00095 METH_VARARGS,
00096 "Applies a transformation to this geometric object"
00097 },
00098 {"translate",
00099 (PyCFunction) staticCallback_translate,
00100 METH_VARARGS,
00101 "Translates this geometric object"
00102 },
00103 {NULL, NULL, 0, NULL}
00104 };
00105
00106
00107
00109 PyGetSetDef GeometryPy::GetterSetter[] = {
00110 {"Construction",
00111 (getter) staticCallback_getConstruction,
00112 (setter) staticCallback_setConstruction,
00113 "Defines this geometry as a construction one which\nmeans that it is not part of a later built shape.",
00114 NULL
00115 },
00116 {NULL, NULL, NULL, NULL, NULL}
00117 };
00118
00119
00120
00121
00122 PyObject * GeometryPy::staticCallback_mirror (PyObject *self, PyObject *args)
00123 {
00124
00125 if (!((PyObjectBase*) self)->isValid()){
00126 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00127 return NULL;
00128 }
00129
00130
00131 if (((PyObjectBase*) self)->isConst()){
00132 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00133 return NULL;
00134 }
00135
00136 try {
00137 PyObject* ret = ((GeometryPy*)self)->mirror(args);
00138 if (ret != 0)
00139 ((GeometryPy*)self)->startNotify();
00140 return ret;
00141 }
00142 catch(const Base::Exception& e)
00143 {
00144 std::string str;
00145 str += "FreeCAD exception thrown (";
00146 str += e.what();
00147 str += ")";
00148 e.ReportException();
00149 PyErr_SetString(PyExc_Exception,str.c_str());
00150 return NULL;
00151 }
00152 catch(const boost::filesystem::filesystem_error& e)
00153 {
00154 std::string str;
00155 str += "File system exception thrown (";
00156
00157
00158 str += e.what();
00159 str += ")\n";
00160 Base::Console().Error(str.c_str());
00161 PyErr_SetString(PyExc_Exception,str.c_str());
00162 return NULL;
00163 }
00164 catch(const Py::Exception&)
00165 {
00166
00167 return NULL;
00168 }
00169 catch(const char* e)
00170 {
00171 Base::Console().Error(e);
00172 PyErr_SetString(PyExc_Exception,e);
00173 return NULL;
00174 }
00175
00176 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00177 catch(const std::exception& e)
00178 {
00179 std::string str;
00180 str += "FC++ exception thrown (";
00181 str += e.what();
00182 str += ")";
00183 Base::Console().Error(str.c_str());
00184 PyErr_SetString(PyExc_Exception,str.c_str());
00185 return NULL;
00186 }
00187 catch(...)
00188 {
00189 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00190 return NULL;
00191 }
00192 #endif
00193 }
00194
00195
00196
00197
00198 PyObject * GeometryPy::staticCallback_rotate (PyObject *self, PyObject *args)
00199 {
00200
00201 if (!((PyObjectBase*) self)->isValid()){
00202 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00203 return NULL;
00204 }
00205
00206
00207 if (((PyObjectBase*) self)->isConst()){
00208 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00209 return NULL;
00210 }
00211
00212 try {
00213 PyObject* ret = ((GeometryPy*)self)->rotate(args);
00214 if (ret != 0)
00215 ((GeometryPy*)self)->startNotify();
00216 return ret;
00217 }
00218 catch(const Base::Exception& e)
00219 {
00220 std::string str;
00221 str += "FreeCAD exception thrown (";
00222 str += e.what();
00223 str += ")";
00224 e.ReportException();
00225 PyErr_SetString(PyExc_Exception,str.c_str());
00226 return NULL;
00227 }
00228 catch(const boost::filesystem::filesystem_error& e)
00229 {
00230 std::string str;
00231 str += "File system exception thrown (";
00232
00233
00234 str += e.what();
00235 str += ")\n";
00236 Base::Console().Error(str.c_str());
00237 PyErr_SetString(PyExc_Exception,str.c_str());
00238 return NULL;
00239 }
00240 catch(const Py::Exception&)
00241 {
00242
00243 return NULL;
00244 }
00245 catch(const char* e)
00246 {
00247 Base::Console().Error(e);
00248 PyErr_SetString(PyExc_Exception,e);
00249 return NULL;
00250 }
00251
00252 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00253 catch(const std::exception& e)
00254 {
00255 std::string str;
00256 str += "FC++ exception thrown (";
00257 str += e.what();
00258 str += ")";
00259 Base::Console().Error(str.c_str());
00260 PyErr_SetString(PyExc_Exception,str.c_str());
00261 return NULL;
00262 }
00263 catch(...)
00264 {
00265 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00266 return NULL;
00267 }
00268 #endif
00269 }
00270
00271
00272
00273
00274 PyObject * GeometryPy::staticCallback_scale (PyObject *self, PyObject *args)
00275 {
00276
00277 if (!((PyObjectBase*) self)->isValid()){
00278 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00279 return NULL;
00280 }
00281
00282
00283 if (((PyObjectBase*) self)->isConst()){
00284 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00285 return NULL;
00286 }
00287
00288 try {
00289 PyObject* ret = ((GeometryPy*)self)->scale(args);
00290 if (ret != 0)
00291 ((GeometryPy*)self)->startNotify();
00292 return ret;
00293 }
00294 catch(const Base::Exception& e)
00295 {
00296 std::string str;
00297 str += "FreeCAD exception thrown (";
00298 str += e.what();
00299 str += ")";
00300 e.ReportException();
00301 PyErr_SetString(PyExc_Exception,str.c_str());
00302 return NULL;
00303 }
00304 catch(const boost::filesystem::filesystem_error& e)
00305 {
00306 std::string str;
00307 str += "File system exception thrown (";
00308
00309
00310 str += e.what();
00311 str += ")\n";
00312 Base::Console().Error(str.c_str());
00313 PyErr_SetString(PyExc_Exception,str.c_str());
00314 return NULL;
00315 }
00316 catch(const Py::Exception&)
00317 {
00318
00319 return NULL;
00320 }
00321 catch(const char* e)
00322 {
00323 Base::Console().Error(e);
00324 PyErr_SetString(PyExc_Exception,e);
00325 return NULL;
00326 }
00327
00328 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00329 catch(const std::exception& e)
00330 {
00331 std::string str;
00332 str += "FC++ exception thrown (";
00333 str += e.what();
00334 str += ")";
00335 Base::Console().Error(str.c_str());
00336 PyErr_SetString(PyExc_Exception,str.c_str());
00337 return NULL;
00338 }
00339 catch(...)
00340 {
00341 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00342 return NULL;
00343 }
00344 #endif
00345 }
00346
00347
00348
00349
00350 PyObject * GeometryPy::staticCallback_transform (PyObject *self, PyObject *args)
00351 {
00352
00353 if (!((PyObjectBase*) self)->isValid()){
00354 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00355 return NULL;
00356 }
00357
00358
00359 if (((PyObjectBase*) self)->isConst()){
00360 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00361 return NULL;
00362 }
00363
00364 try {
00365 PyObject* ret = ((GeometryPy*)self)->transform(args);
00366 if (ret != 0)
00367 ((GeometryPy*)self)->startNotify();
00368 return ret;
00369 }
00370 catch(const Base::Exception& e)
00371 {
00372 std::string str;
00373 str += "FreeCAD exception thrown (";
00374 str += e.what();
00375 str += ")";
00376 e.ReportException();
00377 PyErr_SetString(PyExc_Exception,str.c_str());
00378 return NULL;
00379 }
00380 catch(const boost::filesystem::filesystem_error& e)
00381 {
00382 std::string str;
00383 str += "File system exception thrown (";
00384
00385
00386 str += e.what();
00387 str += ")\n";
00388 Base::Console().Error(str.c_str());
00389 PyErr_SetString(PyExc_Exception,str.c_str());
00390 return NULL;
00391 }
00392 catch(const Py::Exception&)
00393 {
00394
00395 return NULL;
00396 }
00397 catch(const char* e)
00398 {
00399 Base::Console().Error(e);
00400 PyErr_SetString(PyExc_Exception,e);
00401 return NULL;
00402 }
00403
00404 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00405 catch(const std::exception& e)
00406 {
00407 std::string str;
00408 str += "FC++ exception thrown (";
00409 str += e.what();
00410 str += ")";
00411 Base::Console().Error(str.c_str());
00412 PyErr_SetString(PyExc_Exception,str.c_str());
00413 return NULL;
00414 }
00415 catch(...)
00416 {
00417 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00418 return NULL;
00419 }
00420 #endif
00421 }
00422
00423
00424
00425
00426 PyObject * GeometryPy::staticCallback_translate (PyObject *self, PyObject *args)
00427 {
00428
00429 if (!((PyObjectBase*) self)->isValid()){
00430 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00431 return NULL;
00432 }
00433
00434
00435 if (((PyObjectBase*) self)->isConst()){
00436 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00437 return NULL;
00438 }
00439
00440 try {
00441 PyObject* ret = ((GeometryPy*)self)->translate(args);
00442 if (ret != 0)
00443 ((GeometryPy*)self)->startNotify();
00444 return ret;
00445 }
00446 catch(const Base::Exception& e)
00447 {
00448 std::string str;
00449 str += "FreeCAD exception thrown (";
00450 str += e.what();
00451 str += ")";
00452 e.ReportException();
00453 PyErr_SetString(PyExc_Exception,str.c_str());
00454 return NULL;
00455 }
00456 catch(const boost::filesystem::filesystem_error& e)
00457 {
00458 std::string str;
00459 str += "File system exception thrown (";
00460
00461
00462 str += e.what();
00463 str += ")\n";
00464 Base::Console().Error(str.c_str());
00465 PyErr_SetString(PyExc_Exception,str.c_str());
00466 return NULL;
00467 }
00468 catch(const Py::Exception&)
00469 {
00470
00471 return NULL;
00472 }
00473 catch(const char* e)
00474 {
00475 Base::Console().Error(e);
00476 PyErr_SetString(PyExc_Exception,e);
00477 return NULL;
00478 }
00479
00480 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00481 catch(const std::exception& e)
00482 {
00483 std::string str;
00484 str += "FC++ exception thrown (";
00485 str += e.what();
00486 str += ")";
00487 Base::Console().Error(str.c_str());
00488 PyErr_SetString(PyExc_Exception,str.c_str());
00489 return NULL;
00490 }
00491 catch(...)
00492 {
00493 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00494 return NULL;
00495 }
00496 #endif
00497 }
00498
00499
00500
00501
00502 PyObject * GeometryPy::staticCallback_getConstruction (PyObject *self, void * )
00503 {
00504 if (!((PyObjectBase*) self)->isValid()){
00505 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00506 return NULL;
00507 }
00508
00509 try {
00510 return Py::new_reference_to(((GeometryPy*)self)->getConstruction());
00511 } catch (const Py::Exception&) {
00512
00513 return NULL;
00514 } catch (...) {
00515 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Construction' of object 'Geometry'");
00516 return NULL;
00517 }
00518 }
00519
00520 int GeometryPy::staticCallback_setConstruction (PyObject *self, PyObject *value, void * )
00521 {
00522 if (!((PyObjectBase*) self)->isValid()){
00523 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00524 return -1;
00525 }
00526 if (((PyObjectBase*) self)->isConst()){
00527 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
00528 return -1;
00529 }
00530
00531 try {
00532 ((GeometryPy*)self)->setConstruction(Py::Boolean(value,false));
00533 return 0;
00534 } catch (const Py::Exception&) {
00535
00536 return -1;
00537 } catch (...) {
00538 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Construction' of object 'Geometry'");
00539 return -1;
00540 }
00541 }
00542
00543
00544
00545
00546
00547
00548 PyParentObject GeometryPy::Parents[] = { PARENTSPartGeometryPy };
00549
00550
00551
00552
00553 GeometryPy::GeometryPy(Geometry *pcObject, PyTypeObject *T)
00554 : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
00555 {
00556 }
00557
00558
00559
00560
00561
00562 GeometryPy::~GeometryPy()
00563 {
00564
00565 GeometryPy::PointerType ptr = reinterpret_cast<GeometryPy::PointerType>(_pcTwinPointer);
00566 delete ptr;
00567 }
00568
00569
00570
00571
00572 PyObject *GeometryPy::_repr(void)
00573 {
00574 return Py_BuildValue("s", representation().c_str());
00575 }
00576
00577
00578
00579
00580 PyObject *GeometryPy::_getattr(char *attr)
00581 {
00582 try {
00583
00584 PyObject *r = getCustomAttributes(attr);
00585 if(r) return r;
00586 }
00587 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00588 catch(const Base::Exception& e)
00589 {
00590 std::string str;
00591 str += "FreeCAD exception thrown (";
00592 str += e.what();
00593 str += ")";
00594 e.ReportException();
00595 PyErr_SetString(PyExc_Exception,str.c_str());
00596 return NULL;
00597 }
00598 catch(const std::exception& e)
00599 {
00600 std::string str;
00601 str += "FC++ exception thrown (";
00602 str += e.what();
00603 str += ")";
00604 Base::Console().Error(str.c_str());
00605 PyErr_SetString(PyExc_Exception,str.c_str());
00606 return NULL;
00607 }
00608 catch(const Py::Exception&)
00609 {
00610
00611 return NULL;
00612 }
00613 catch(...)
00614 {
00615 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00616 return NULL;
00617 }
00618 #else // DONT_CATCH_CXX_EXCEPTIONS
00619 catch(const Base::Exception& e)
00620 {
00621 std::string str;
00622 str += "FreeCAD exception thrown (";
00623 str += e.what();
00624 str += ")";
00625 e.ReportException();
00626 PyErr_SetString(PyExc_Exception,str.c_str());
00627 return NULL;
00628 }
00629 catch(const Py::Exception&)
00630 {
00631
00632 return NULL;
00633 }
00634 #endif // DONT_CATCH_CXX_EXCEPTIONS
00635
00636 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
00637 if (rvalue == NULL)
00638 {
00639 PyErr_Clear();
00640 return PyObjectBase::_getattr(attr);
00641 }
00642 else
00643 {
00644 return rvalue;
00645 }
00646 }
00647
00648 int GeometryPy::_setattr(char *attr, PyObject *value)
00649 {
00650 try {
00651
00652 int r = setCustomAttributes(attr, value);
00653 if(r==1) return 0;
00654 }
00655 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00656 catch(const Base::Exception& e)
00657 {
00658 std::string str;
00659 str += "FreeCAD exception thrown (";
00660 str += e.what();
00661 str += ")";
00662 e.ReportException();
00663 PyErr_SetString(PyExc_Exception,str.c_str());
00664 return -1;
00665 }
00666 catch(const std::exception& e)
00667 {
00668 std::string str;
00669 str += "FC++ exception thrown (";
00670 str += e.what();
00671 str += ")";
00672 Base::Console().Error(str.c_str());
00673 PyErr_SetString(PyExc_Exception,str.c_str());
00674 return -1;
00675 }
00676 catch(const Py::Exception&)
00677 {
00678
00679 return -1;
00680 }
00681 catch(...)
00682 {
00683 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00684 return -1;
00685 }
00686 #else // DONT_CATCH_CXX_EXCEPTIONS
00687 catch(const Base::Exception& e)
00688 {
00689 std::string str;
00690 str += "FreeCAD exception thrown (";
00691 str += e.what();
00692 str += ")";
00693 e.ReportException();
00694 PyErr_SetString(PyExc_Exception,str.c_str());
00695 return -1;
00696 }
00697 catch(const Py::Exception&)
00698 {
00699
00700 return -1;
00701 }
00702 #endif // DONT_CATCH_CXX_EXCEPTIONS
00703
00704 return PyObjectBase::_setattr(attr, value);
00705 }
00706
00707 Geometry *GeometryPy::getGeometryPtr(void) const
00708 {
00709 return static_cast<Geometry *>(_pcTwinPointer);
00710 }
00711
00712 #if 0
00713
00714
00715
00716
00717 PyObject *GeometryPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
00718 {
00719
00720 return new GeometryPy(new Geometry);
00721 }
00722
00723
00724 int GeometryPy::PyInit(PyObject* , PyObject* )
00725 {
00726 return 0;
00727 }
00728
00729
00730 std::string GeometryPy::representation(void) const
00731 {
00732 return std::string("<Geometry object>");
00733 }
00734
00735 PyObject* GeometryPy::mirror(PyObject *args)
00736 {
00737 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00738 return 0;
00739 }
00740
00741 PyObject* GeometryPy::rotate(PyObject *args)
00742 {
00743 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00744 return 0;
00745 }
00746
00747 PyObject* GeometryPy::scale(PyObject *args)
00748 {
00749 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00750 return 0;
00751 }
00752
00753 PyObject* GeometryPy::transform(PyObject *args)
00754 {
00755 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00756 return 0;
00757 }
00758
00759 PyObject* GeometryPy::translate(PyObject *args)
00760 {
00761 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
00762 return 0;
00763 }
00764
00765
00766
00767 Py::Boolean GeometryPy::getConstruction(void) const
00768 {
00769
00770 throw Py::AttributeError("Not yet implemented");
00771 }
00772
00773 void GeometryPy::setConstruction(Py::Boolean arg)
00774 {
00775 throw Py::AttributeError("Not yet implemented");
00776 }
00777
00778 PyObject *GeometryPy::getCustomAttributes(const char* attr) const
00779 {
00780 return 0;
00781 }
00782
00783 int GeometryPy::setCustomAttributes(const char* attr, PyObject *obj)
00784 {
00785 return 0;
00786 }
00787 #endif
00788
00789
00790