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 Base;
00018
00020 PyTypeObject VectorPy::Type = {
00021 PyObject_HEAD_INIT(&PyType_Type)
00022 0,
00023 "Base.Vector",
00024 sizeof(VectorPy),
00025 0,
00026
00027 PyDestructor,
00028 0,
00029 __getattr,
00030 __setattr,
00031 0,
00032 __repr,
00033 Base::VectorPy::Number,
00034 Base::VectorPy::Sequence,
00035 0,
00036 0,
00037 0,
00038 0,
00039 0,
00040 0,
00041
00042 0,
00043
00044 Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS|Py_TPFLAGS_HAVE_RICHCOMPARE,
00045 "This class represents a 3D float vector",
00046 0,
00047 0,
00048 Base::VectorPy::richCompare,
00049 0,
00050 0,
00051 0,
00052 Base::VectorPy::Methods,
00053 0,
00054 Base::VectorPy::GetterSetter,
00055 &Base::PyObjectBase::Type,
00056 0,
00057 0,
00058 0,
00059 0,
00060 __PyInit,
00061 0,
00062 Base::VectorPy::PyMake,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 0,
00070 0
00071 };
00072
00074 PyMethodDef VectorPy::Methods[] = {
00075 {"add",
00076 (PyCFunction) staticCallback_add,
00077 METH_VARARGS,
00078 "add(Vector) - return the sum of the two vectors"
00079 },
00080 {"sub",
00081 (PyCFunction) staticCallback_sub,
00082 METH_VARARGS,
00083 "sub(Vector) - return the difference of the two vectors"
00084 },
00085 {"scale",
00086 (PyCFunction) staticCallback_scale,
00087 METH_VARARGS,
00088 "scale(Float,Float,Float) - scale (multiplies) this vector by a factor"
00089 },
00090 {"multiply",
00091 (PyCFunction) staticCallback_multiply,
00092 METH_VARARGS,
00093 "multiply(Float) - multiplies (scales) this vector by a single factor"
00094 },
00095 {"dot",
00096 (PyCFunction) staticCallback_dot,
00097 METH_VARARGS,
00098 "dot(Vector) - return the dot product of the two vectors"
00099 },
00100 {"cross",
00101 (PyCFunction) staticCallback_cross,
00102 METH_VARARGS,
00103 "cross(Vector) - return the cross product of the two vectors"
00104 },
00105 {"getAngle",
00106 (PyCFunction) staticCallback_getAngle,
00107 METH_VARARGS,
00108 "getAngle(Vector) - return the angle in radians between the two vectors"
00109 },
00110 {"normalize",
00111 (PyCFunction) staticCallback_normalize,
00112 METH_VARARGS,
00113 "Normalize the vector to the length of 1.0"
00114 },
00115 {"projectToLine",
00116 (PyCFunction) staticCallback_projectToLine,
00117 METH_VARARGS,
00118 "Deliver the projection point to a given line"
00119 },
00120 {"projectToPlane",
00121 (PyCFunction) staticCallback_projectToPlane,
00122 METH_VARARGS,
00123 "Deliver the projection point to a given plane"
00124 },
00125 {"distanceToLine",
00126 (PyCFunction) staticCallback_distanceToLine,
00127 METH_VARARGS,
00128 "Deliver the distance of the point to a given line"
00129 },
00130 {"distanceToPlane",
00131 (PyCFunction) staticCallback_distanceToPlane,
00132 METH_VARARGS,
00133 "Deliver the distance of the point to a given plane"
00134 },
00135 {NULL, NULL, 0, NULL}
00136 };
00137
00138 PyNumberMethods VectorPy::Number[] = { {
00139 number_add_handler,
00140 number_subtract_handler,
00141 number_multiply_handler,
00142 NULL
00143 } };
00144
00145 PySequenceMethods VectorPy::Sequence[] = { {
00146 sequence_length,
00147 0,
00148 0,
00149 sequence_item,
00150 0,
00151 sequence_ass_item,
00152 0,
00153 0,
00154 0,
00155 0
00156 } };
00157
00159 PyGetSetDef VectorPy::GetterSetter[] = {
00160 {"Length",
00161 (getter) staticCallback_getLength,
00162 (setter) staticCallback_setLength,
00163 "To read or modifiy the length of the vector",
00164 NULL
00165 },
00166 {"x",
00167 (getter) staticCallback_getx,
00168 (setter) staticCallback_setx,
00169 "The X component of the vector",
00170 NULL
00171 },
00172 {"y",
00173 (getter) staticCallback_gety,
00174 (setter) staticCallback_sety,
00175 "The Y component of the vector",
00176 NULL
00177 },
00178 {"z",
00179 (getter) staticCallback_getz,
00180 (setter) staticCallback_setz,
00181 "The Z component of the vector",
00182 NULL
00183 },
00184 {NULL, NULL, NULL, NULL, NULL}
00185 };
00186
00187
00188
00189
00190 PyObject * VectorPy::staticCallback_add (PyObject *self, PyObject *args)
00191 {
00192
00193 if (!((PyObjectBase*) self)->isValid()){
00194 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00195 return NULL;
00196 }
00197
00198
00199 try {
00200 PyObject* ret = ((VectorPy*)self)->add(args);
00201 return ret;
00202 }
00203 catch(const Base::Exception& e)
00204 {
00205 std::string str;
00206 str += "FreeCAD exception thrown (";
00207 str += e.what();
00208 str += ")";
00209 e.ReportException();
00210 PyErr_SetString(PyExc_Exception,str.c_str());
00211 return NULL;
00212 }
00213 catch(const boost::filesystem::filesystem_error& e)
00214 {
00215 std::string str;
00216 str += "File system exception thrown (";
00217
00218
00219 str += e.what();
00220 str += ")\n";
00221 Base::Console().Error(str.c_str());
00222 PyErr_SetString(PyExc_Exception,str.c_str());
00223 return NULL;
00224 }
00225 catch(const Py::Exception&)
00226 {
00227
00228 return NULL;
00229 }
00230 catch(const char* e)
00231 {
00232 Base::Console().Error(e);
00233 PyErr_SetString(PyExc_Exception,e);
00234 return NULL;
00235 }
00236
00237 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00238 catch(const std::exception& e)
00239 {
00240 std::string str;
00241 str += "FC++ exception thrown (";
00242 str += e.what();
00243 str += ")";
00244 Base::Console().Error(str.c_str());
00245 PyErr_SetString(PyExc_Exception,str.c_str());
00246 return NULL;
00247 }
00248 catch(...)
00249 {
00250 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00251 return NULL;
00252 }
00253 #endif
00254 }
00255
00256
00257
00258
00259 PyObject * VectorPy::staticCallback_sub (PyObject *self, PyObject *args)
00260 {
00261
00262 if (!((PyObjectBase*) self)->isValid()){
00263 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00264 return NULL;
00265 }
00266
00267
00268 try {
00269 PyObject* ret = ((VectorPy*)self)->sub(args);
00270 return ret;
00271 }
00272 catch(const Base::Exception& e)
00273 {
00274 std::string str;
00275 str += "FreeCAD exception thrown (";
00276 str += e.what();
00277 str += ")";
00278 e.ReportException();
00279 PyErr_SetString(PyExc_Exception,str.c_str());
00280 return NULL;
00281 }
00282 catch(const boost::filesystem::filesystem_error& e)
00283 {
00284 std::string str;
00285 str += "File system exception thrown (";
00286
00287
00288 str += e.what();
00289 str += ")\n";
00290 Base::Console().Error(str.c_str());
00291 PyErr_SetString(PyExc_Exception,str.c_str());
00292 return NULL;
00293 }
00294 catch(const Py::Exception&)
00295 {
00296
00297 return NULL;
00298 }
00299 catch(const char* e)
00300 {
00301 Base::Console().Error(e);
00302 PyErr_SetString(PyExc_Exception,e);
00303 return NULL;
00304 }
00305
00306 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00307 catch(const std::exception& e)
00308 {
00309 std::string str;
00310 str += "FC++ exception thrown (";
00311 str += e.what();
00312 str += ")";
00313 Base::Console().Error(str.c_str());
00314 PyErr_SetString(PyExc_Exception,str.c_str());
00315 return NULL;
00316 }
00317 catch(...)
00318 {
00319 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00320 return NULL;
00321 }
00322 #endif
00323 }
00324
00325
00326
00327
00328 PyObject * VectorPy::staticCallback_scale (PyObject *self, PyObject *args)
00329 {
00330
00331 if (!((PyObjectBase*) self)->isValid()){
00332 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00333 return NULL;
00334 }
00335
00336
00337 if (((PyObjectBase*) self)->isConst()){
00338 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00339 return NULL;
00340 }
00341
00342 try {
00343 PyObject* ret = ((VectorPy*)self)->scale(args);
00344 if (ret != 0)
00345 ((VectorPy*)self)->startNotify();
00346 return ret;
00347 }
00348 catch(const Base::Exception& e)
00349 {
00350 std::string str;
00351 str += "FreeCAD exception thrown (";
00352 str += e.what();
00353 str += ")";
00354 e.ReportException();
00355 PyErr_SetString(PyExc_Exception,str.c_str());
00356 return NULL;
00357 }
00358 catch(const boost::filesystem::filesystem_error& e)
00359 {
00360 std::string str;
00361 str += "File system exception thrown (";
00362
00363
00364 str += e.what();
00365 str += ")\n";
00366 Base::Console().Error(str.c_str());
00367 PyErr_SetString(PyExc_Exception,str.c_str());
00368 return NULL;
00369 }
00370 catch(const Py::Exception&)
00371 {
00372
00373 return NULL;
00374 }
00375 catch(const char* e)
00376 {
00377 Base::Console().Error(e);
00378 PyErr_SetString(PyExc_Exception,e);
00379 return NULL;
00380 }
00381
00382 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00383 catch(const std::exception& e)
00384 {
00385 std::string str;
00386 str += "FC++ exception thrown (";
00387 str += e.what();
00388 str += ")";
00389 Base::Console().Error(str.c_str());
00390 PyErr_SetString(PyExc_Exception,str.c_str());
00391 return NULL;
00392 }
00393 catch(...)
00394 {
00395 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00396 return NULL;
00397 }
00398 #endif
00399 }
00400
00401
00402
00403
00404 PyObject * VectorPy::staticCallback_multiply (PyObject *self, PyObject *args)
00405 {
00406
00407 if (!((PyObjectBase*) self)->isValid()){
00408 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00409 return NULL;
00410 }
00411
00412
00413 if (((PyObjectBase*) self)->isConst()){
00414 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00415 return NULL;
00416 }
00417
00418 try {
00419 PyObject* ret = ((VectorPy*)self)->multiply(args);
00420 if (ret != 0)
00421 ((VectorPy*)self)->startNotify();
00422 return ret;
00423 }
00424 catch(const Base::Exception& e)
00425 {
00426 std::string str;
00427 str += "FreeCAD exception thrown (";
00428 str += e.what();
00429 str += ")";
00430 e.ReportException();
00431 PyErr_SetString(PyExc_Exception,str.c_str());
00432 return NULL;
00433 }
00434 catch(const boost::filesystem::filesystem_error& e)
00435 {
00436 std::string str;
00437 str += "File system exception thrown (";
00438
00439
00440 str += e.what();
00441 str += ")\n";
00442 Base::Console().Error(str.c_str());
00443 PyErr_SetString(PyExc_Exception,str.c_str());
00444 return NULL;
00445 }
00446 catch(const Py::Exception&)
00447 {
00448
00449 return NULL;
00450 }
00451 catch(const char* e)
00452 {
00453 Base::Console().Error(e);
00454 PyErr_SetString(PyExc_Exception,e);
00455 return NULL;
00456 }
00457
00458 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00459 catch(const std::exception& e)
00460 {
00461 std::string str;
00462 str += "FC++ exception thrown (";
00463 str += e.what();
00464 str += ")";
00465 Base::Console().Error(str.c_str());
00466 PyErr_SetString(PyExc_Exception,str.c_str());
00467 return NULL;
00468 }
00469 catch(...)
00470 {
00471 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00472 return NULL;
00473 }
00474 #endif
00475 }
00476
00477
00478
00479
00480 PyObject * VectorPy::staticCallback_dot (PyObject *self, PyObject *args)
00481 {
00482
00483 if (!((PyObjectBase*) self)->isValid()){
00484 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00485 return NULL;
00486 }
00487
00488
00489 try {
00490 PyObject* ret = ((VectorPy*)self)->dot(args);
00491 return ret;
00492 }
00493 catch(const Base::Exception& e)
00494 {
00495 std::string str;
00496 str += "FreeCAD exception thrown (";
00497 str += e.what();
00498 str += ")";
00499 e.ReportException();
00500 PyErr_SetString(PyExc_Exception,str.c_str());
00501 return NULL;
00502 }
00503 catch(const boost::filesystem::filesystem_error& e)
00504 {
00505 std::string str;
00506 str += "File system exception thrown (";
00507
00508
00509 str += e.what();
00510 str += ")\n";
00511 Base::Console().Error(str.c_str());
00512 PyErr_SetString(PyExc_Exception,str.c_str());
00513 return NULL;
00514 }
00515 catch(const Py::Exception&)
00516 {
00517
00518 return NULL;
00519 }
00520 catch(const char* e)
00521 {
00522 Base::Console().Error(e);
00523 PyErr_SetString(PyExc_Exception,e);
00524 return NULL;
00525 }
00526
00527 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00528 catch(const std::exception& e)
00529 {
00530 std::string str;
00531 str += "FC++ exception thrown (";
00532 str += e.what();
00533 str += ")";
00534 Base::Console().Error(str.c_str());
00535 PyErr_SetString(PyExc_Exception,str.c_str());
00536 return NULL;
00537 }
00538 catch(...)
00539 {
00540 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00541 return NULL;
00542 }
00543 #endif
00544 }
00545
00546
00547
00548
00549 PyObject * VectorPy::staticCallback_cross (PyObject *self, PyObject *args)
00550 {
00551
00552 if (!((PyObjectBase*) self)->isValid()){
00553 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00554 return NULL;
00555 }
00556
00557
00558 try {
00559 PyObject* ret = ((VectorPy*)self)->cross(args);
00560 return ret;
00561 }
00562 catch(const Base::Exception& e)
00563 {
00564 std::string str;
00565 str += "FreeCAD exception thrown (";
00566 str += e.what();
00567 str += ")";
00568 e.ReportException();
00569 PyErr_SetString(PyExc_Exception,str.c_str());
00570 return NULL;
00571 }
00572 catch(const boost::filesystem::filesystem_error& e)
00573 {
00574 std::string str;
00575 str += "File system exception thrown (";
00576
00577
00578 str += e.what();
00579 str += ")\n";
00580 Base::Console().Error(str.c_str());
00581 PyErr_SetString(PyExc_Exception,str.c_str());
00582 return NULL;
00583 }
00584 catch(const Py::Exception&)
00585 {
00586
00587 return NULL;
00588 }
00589 catch(const char* e)
00590 {
00591 Base::Console().Error(e);
00592 PyErr_SetString(PyExc_Exception,e);
00593 return NULL;
00594 }
00595
00596 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00597 catch(const std::exception& e)
00598 {
00599 std::string str;
00600 str += "FC++ exception thrown (";
00601 str += e.what();
00602 str += ")";
00603 Base::Console().Error(str.c_str());
00604 PyErr_SetString(PyExc_Exception,str.c_str());
00605 return NULL;
00606 }
00607 catch(...)
00608 {
00609 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00610 return NULL;
00611 }
00612 #endif
00613 }
00614
00615
00616
00617
00618 PyObject * VectorPy::staticCallback_getAngle (PyObject *self, PyObject *args)
00619 {
00620
00621 if (!((PyObjectBase*) self)->isValid()){
00622 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00623 return NULL;
00624 }
00625
00626
00627 try {
00628 PyObject* ret = ((VectorPy*)self)->getAngle(args);
00629 return ret;
00630 }
00631 catch(const Base::Exception& e)
00632 {
00633 std::string str;
00634 str += "FreeCAD exception thrown (";
00635 str += e.what();
00636 str += ")";
00637 e.ReportException();
00638 PyErr_SetString(PyExc_Exception,str.c_str());
00639 return NULL;
00640 }
00641 catch(const boost::filesystem::filesystem_error& e)
00642 {
00643 std::string str;
00644 str += "File system exception thrown (";
00645
00646
00647 str += e.what();
00648 str += ")\n";
00649 Base::Console().Error(str.c_str());
00650 PyErr_SetString(PyExc_Exception,str.c_str());
00651 return NULL;
00652 }
00653 catch(const Py::Exception&)
00654 {
00655
00656 return NULL;
00657 }
00658 catch(const char* e)
00659 {
00660 Base::Console().Error(e);
00661 PyErr_SetString(PyExc_Exception,e);
00662 return NULL;
00663 }
00664
00665 #ifndef DONT_CATCH_CXX_EXCEPTIONS
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 NULL;
00675 }
00676 catch(...)
00677 {
00678 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00679 return NULL;
00680 }
00681 #endif
00682 }
00683
00684
00685
00686
00687 PyObject * VectorPy::staticCallback_normalize (PyObject *self, PyObject *args)
00688 {
00689
00690 if (!((PyObjectBase*) self)->isValid()){
00691 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00692 return NULL;
00693 }
00694
00695
00696 if (((PyObjectBase*) self)->isConst()){
00697 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00698 return NULL;
00699 }
00700
00701 try {
00702 PyObject* ret = ((VectorPy*)self)->normalize(args);
00703 if (ret != 0)
00704 ((VectorPy*)self)->startNotify();
00705 return ret;
00706 }
00707 catch(const Base::Exception& e)
00708 {
00709 std::string str;
00710 str += "FreeCAD exception thrown (";
00711 str += e.what();
00712 str += ")";
00713 e.ReportException();
00714 PyErr_SetString(PyExc_Exception,str.c_str());
00715 return NULL;
00716 }
00717 catch(const boost::filesystem::filesystem_error& e)
00718 {
00719 std::string str;
00720 str += "File system exception thrown (";
00721
00722
00723 str += e.what();
00724 str += ")\n";
00725 Base::Console().Error(str.c_str());
00726 PyErr_SetString(PyExc_Exception,str.c_str());
00727 return NULL;
00728 }
00729 catch(const Py::Exception&)
00730 {
00731
00732 return NULL;
00733 }
00734 catch(const char* e)
00735 {
00736 Base::Console().Error(e);
00737 PyErr_SetString(PyExc_Exception,e);
00738 return NULL;
00739 }
00740
00741 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00742 catch(const std::exception& e)
00743 {
00744 std::string str;
00745 str += "FC++ exception thrown (";
00746 str += e.what();
00747 str += ")";
00748 Base::Console().Error(str.c_str());
00749 PyErr_SetString(PyExc_Exception,str.c_str());
00750 return NULL;
00751 }
00752 catch(...)
00753 {
00754 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00755 return NULL;
00756 }
00757 #endif
00758 }
00759
00760
00761
00762
00763 PyObject * VectorPy::staticCallback_projectToLine (PyObject *self, PyObject *args)
00764 {
00765
00766 if (!((PyObjectBase*) self)->isValid()){
00767 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00768 return NULL;
00769 }
00770
00771
00772 if (((PyObjectBase*) self)->isConst()){
00773 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00774 return NULL;
00775 }
00776
00777 try {
00778 PyObject* ret = ((VectorPy*)self)->projectToLine(args);
00779 if (ret != 0)
00780 ((VectorPy*)self)->startNotify();
00781 return ret;
00782 }
00783 catch(const Base::Exception& e)
00784 {
00785 std::string str;
00786 str += "FreeCAD exception thrown (";
00787 str += e.what();
00788 str += ")";
00789 e.ReportException();
00790 PyErr_SetString(PyExc_Exception,str.c_str());
00791 return NULL;
00792 }
00793 catch(const boost::filesystem::filesystem_error& e)
00794 {
00795 std::string str;
00796 str += "File system exception thrown (";
00797
00798
00799 str += e.what();
00800 str += ")\n";
00801 Base::Console().Error(str.c_str());
00802 PyErr_SetString(PyExc_Exception,str.c_str());
00803 return NULL;
00804 }
00805 catch(const Py::Exception&)
00806 {
00807
00808 return NULL;
00809 }
00810 catch(const char* e)
00811 {
00812 Base::Console().Error(e);
00813 PyErr_SetString(PyExc_Exception,e);
00814 return NULL;
00815 }
00816
00817 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00818 catch(const std::exception& e)
00819 {
00820 std::string str;
00821 str += "FC++ exception thrown (";
00822 str += e.what();
00823 str += ")";
00824 Base::Console().Error(str.c_str());
00825 PyErr_SetString(PyExc_Exception,str.c_str());
00826 return NULL;
00827 }
00828 catch(...)
00829 {
00830 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00831 return NULL;
00832 }
00833 #endif
00834 }
00835
00836
00837
00838
00839 PyObject * VectorPy::staticCallback_projectToPlane (PyObject *self, PyObject *args)
00840 {
00841
00842 if (!((PyObjectBase*) self)->isValid()){
00843 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00844 return NULL;
00845 }
00846
00847
00848 if (((PyObjectBase*) self)->isConst()){
00849 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a non const method");
00850 return NULL;
00851 }
00852
00853 try {
00854 PyObject* ret = ((VectorPy*)self)->projectToPlane(args);
00855 if (ret != 0)
00856 ((VectorPy*)self)->startNotify();
00857 return ret;
00858 }
00859 catch(const Base::Exception& e)
00860 {
00861 std::string str;
00862 str += "FreeCAD exception thrown (";
00863 str += e.what();
00864 str += ")";
00865 e.ReportException();
00866 PyErr_SetString(PyExc_Exception,str.c_str());
00867 return NULL;
00868 }
00869 catch(const boost::filesystem::filesystem_error& e)
00870 {
00871 std::string str;
00872 str += "File system exception thrown (";
00873
00874
00875 str += e.what();
00876 str += ")\n";
00877 Base::Console().Error(str.c_str());
00878 PyErr_SetString(PyExc_Exception,str.c_str());
00879 return NULL;
00880 }
00881 catch(const Py::Exception&)
00882 {
00883
00884 return NULL;
00885 }
00886 catch(const char* e)
00887 {
00888 Base::Console().Error(e);
00889 PyErr_SetString(PyExc_Exception,e);
00890 return NULL;
00891 }
00892
00893 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00894 catch(const std::exception& e)
00895 {
00896 std::string str;
00897 str += "FC++ exception thrown (";
00898 str += e.what();
00899 str += ")";
00900 Base::Console().Error(str.c_str());
00901 PyErr_SetString(PyExc_Exception,str.c_str());
00902 return NULL;
00903 }
00904 catch(...)
00905 {
00906 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00907 return NULL;
00908 }
00909 #endif
00910 }
00911
00912
00913
00914
00915 PyObject * VectorPy::staticCallback_distanceToLine (PyObject *self, PyObject *args)
00916 {
00917
00918 if (!((PyObjectBase*) self)->isValid()){
00919 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00920 return NULL;
00921 }
00922
00923
00924 try {
00925 PyObject* ret = ((VectorPy*)self)->distanceToLine(args);
00926 return ret;
00927 }
00928 catch(const Base::Exception& e)
00929 {
00930 std::string str;
00931 str += "FreeCAD exception thrown (";
00932 str += e.what();
00933 str += ")";
00934 e.ReportException();
00935 PyErr_SetString(PyExc_Exception,str.c_str());
00936 return NULL;
00937 }
00938 catch(const boost::filesystem::filesystem_error& e)
00939 {
00940 std::string str;
00941 str += "File system exception thrown (";
00942
00943
00944 str += e.what();
00945 str += ")\n";
00946 Base::Console().Error(str.c_str());
00947 PyErr_SetString(PyExc_Exception,str.c_str());
00948 return NULL;
00949 }
00950 catch(const Py::Exception&)
00951 {
00952
00953 return NULL;
00954 }
00955 catch(const char* e)
00956 {
00957 Base::Console().Error(e);
00958 PyErr_SetString(PyExc_Exception,e);
00959 return NULL;
00960 }
00961
00962 #ifndef DONT_CATCH_CXX_EXCEPTIONS
00963 catch(const std::exception& e)
00964 {
00965 std::string str;
00966 str += "FC++ exception thrown (";
00967 str += e.what();
00968 str += ")";
00969 Base::Console().Error(str.c_str());
00970 PyErr_SetString(PyExc_Exception,str.c_str());
00971 return NULL;
00972 }
00973 catch(...)
00974 {
00975 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
00976 return NULL;
00977 }
00978 #endif
00979 }
00980
00981
00982
00983
00984 PyObject * VectorPy::staticCallback_distanceToPlane (PyObject *self, PyObject *args)
00985 {
00986
00987 if (!((PyObjectBase*) self)->isValid()){
00988 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
00989 return NULL;
00990 }
00991
00992
00993 try {
00994 PyObject* ret = ((VectorPy*)self)->distanceToPlane(args);
00995 return ret;
00996 }
00997 catch(const Base::Exception& e)
00998 {
00999 std::string str;
01000 str += "FreeCAD exception thrown (";
01001 str += e.what();
01002 str += ")";
01003 e.ReportException();
01004 PyErr_SetString(PyExc_Exception,str.c_str());
01005 return NULL;
01006 }
01007 catch(const boost::filesystem::filesystem_error& e)
01008 {
01009 std::string str;
01010 str += "File system exception thrown (";
01011
01012
01013 str += e.what();
01014 str += ")\n";
01015 Base::Console().Error(str.c_str());
01016 PyErr_SetString(PyExc_Exception,str.c_str());
01017 return NULL;
01018 }
01019 catch(const Py::Exception&)
01020 {
01021
01022 return NULL;
01023 }
01024 catch(const char* e)
01025 {
01026 Base::Console().Error(e);
01027 PyErr_SetString(PyExc_Exception,e);
01028 return NULL;
01029 }
01030
01031 #ifndef DONT_CATCH_CXX_EXCEPTIONS
01032 catch(const std::exception& e)
01033 {
01034 std::string str;
01035 str += "FC++ exception thrown (";
01036 str += e.what();
01037 str += ")";
01038 Base::Console().Error(str.c_str());
01039 PyErr_SetString(PyExc_Exception,str.c_str());
01040 return NULL;
01041 }
01042 catch(...)
01043 {
01044 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
01045 return NULL;
01046 }
01047 #endif
01048 }
01049
01050
01051
01052
01053 PyObject * VectorPy::staticCallback_getLength (PyObject *self, void * )
01054 {
01055 if (!((PyObjectBase*) self)->isValid()){
01056 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01057 return NULL;
01058 }
01059
01060 try {
01061 return Py::new_reference_to(((VectorPy*)self)->getLength());
01062 } catch (const Py::Exception&) {
01063
01064 return NULL;
01065 } catch (...) {
01066 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'Length' of object 'Vector'");
01067 return NULL;
01068 }
01069 }
01070
01071 int VectorPy::staticCallback_setLength (PyObject *self, PyObject *value, void * )
01072 {
01073 if (!((PyObjectBase*) self)->isValid()){
01074 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01075 return -1;
01076 }
01077 if (((PyObjectBase*) self)->isConst()){
01078 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
01079 return -1;
01080 }
01081
01082 try {
01083 ((VectorPy*)self)->setLength(Py::Float(value,false));
01084 return 0;
01085 } catch (const Py::Exception&) {
01086
01087 return -1;
01088 } catch (...) {
01089 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'Length' of object 'Vector'");
01090 return -1;
01091 }
01092 }
01093
01094
01095
01096
01097 PyObject * VectorPy::staticCallback_getx (PyObject *self, void * )
01098 {
01099 if (!((PyObjectBase*) self)->isValid()){
01100 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01101 return NULL;
01102 }
01103
01104 try {
01105 return Py::new_reference_to(((VectorPy*)self)->getx());
01106 } catch (const Py::Exception&) {
01107
01108 return NULL;
01109 } catch (...) {
01110 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'x' of object 'Vector'");
01111 return NULL;
01112 }
01113 }
01114
01115 int VectorPy::staticCallback_setx (PyObject *self, PyObject *value, void * )
01116 {
01117 if (!((PyObjectBase*) self)->isValid()){
01118 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01119 return -1;
01120 }
01121 if (((PyObjectBase*) self)->isConst()){
01122 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
01123 return -1;
01124 }
01125
01126 try {
01127 ((VectorPy*)self)->setx(Py::Float(value,false));
01128 return 0;
01129 } catch (const Py::Exception&) {
01130
01131 return -1;
01132 } catch (...) {
01133 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'x' of object 'Vector'");
01134 return -1;
01135 }
01136 }
01137
01138
01139
01140
01141 PyObject * VectorPy::staticCallback_gety (PyObject *self, void * )
01142 {
01143 if (!((PyObjectBase*) self)->isValid()){
01144 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01145 return NULL;
01146 }
01147
01148 try {
01149 return Py::new_reference_to(((VectorPy*)self)->gety());
01150 } catch (const Py::Exception&) {
01151
01152 return NULL;
01153 } catch (...) {
01154 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'y' of object 'Vector'");
01155 return NULL;
01156 }
01157 }
01158
01159 int VectorPy::staticCallback_sety (PyObject *self, PyObject *value, void * )
01160 {
01161 if (!((PyObjectBase*) self)->isValid()){
01162 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01163 return -1;
01164 }
01165 if (((PyObjectBase*) self)->isConst()){
01166 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
01167 return -1;
01168 }
01169
01170 try {
01171 ((VectorPy*)self)->sety(Py::Float(value,false));
01172 return 0;
01173 } catch (const Py::Exception&) {
01174
01175 return -1;
01176 } catch (...) {
01177 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'y' of object 'Vector'");
01178 return -1;
01179 }
01180 }
01181
01182
01183
01184
01185 PyObject * VectorPy::staticCallback_getz (PyObject *self, void * )
01186 {
01187 if (!((PyObjectBase*) self)->isValid()){
01188 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01189 return NULL;
01190 }
01191
01192 try {
01193 return Py::new_reference_to(((VectorPy*)self)->getz());
01194 } catch (const Py::Exception&) {
01195
01196 return NULL;
01197 } catch (...) {
01198 PyErr_SetString(PyExc_Exception, "Unknown exception while reading attribute 'z' of object 'Vector'");
01199 return NULL;
01200 }
01201 }
01202
01203 int VectorPy::staticCallback_setz (PyObject *self, PyObject *value, void * )
01204 {
01205 if (!((PyObjectBase*) self)->isValid()){
01206 PyErr_SetString(PyExc_ReferenceError, "This object is already deleted most likely through closing a document. This reference is no longer valid!");
01207 return -1;
01208 }
01209 if (((PyObjectBase*) self)->isConst()){
01210 PyErr_SetString(PyExc_ReferenceError, "This object is immutable, you can not set any attribute or call a method");
01211 return -1;
01212 }
01213
01214 try {
01215 ((VectorPy*)self)->setz(Py::Float(value,false));
01216 return 0;
01217 } catch (const Py::Exception&) {
01218
01219 return -1;
01220 } catch (...) {
01221 PyErr_SetString(PyExc_Exception, "Unknown exception while writing attribute 'z' of object 'Vector'");
01222 return -1;
01223 }
01224 }
01225
01226
01227
01228
01229
01230
01231 PyParentObject VectorPy::Parents[] = { PARENTSBaseVectorPy };
01232
01233
01234
01235
01236 VectorPy::VectorPy(Vector3d *pcObject, PyTypeObject *T)
01237 : PyObjectBase(reinterpret_cast<PyObjectBase::PointerType>(pcObject), T)
01238 {
01239 }
01240
01241
01242
01243
01244
01245 VectorPy::~VectorPy()
01246 {
01247
01248 VectorPy::PointerType ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
01249 delete ptr;
01250 }
01251
01252
01253
01254
01255 PyObject *VectorPy::_repr(void)
01256 {
01257 return Py_BuildValue("s", representation().c_str());
01258 }
01259
01260
01261
01262
01263 PyObject *VectorPy::_getattr(char *attr)
01264 {
01265 try {
01266
01267 PyObject *r = getCustomAttributes(attr);
01268 if(r) return r;
01269 }
01270 #ifndef DONT_CATCH_CXX_EXCEPTIONS
01271 catch(const Base::Exception& e)
01272 {
01273 std::string str;
01274 str += "FreeCAD exception thrown (";
01275 str += e.what();
01276 str += ")";
01277 e.ReportException();
01278 PyErr_SetString(PyExc_Exception,str.c_str());
01279 return NULL;
01280 }
01281 catch(const std::exception& e)
01282 {
01283 std::string str;
01284 str += "FC++ exception thrown (";
01285 str += e.what();
01286 str += ")";
01287 Base::Console().Error(str.c_str());
01288 PyErr_SetString(PyExc_Exception,str.c_str());
01289 return NULL;
01290 }
01291 catch(const Py::Exception&)
01292 {
01293
01294 return NULL;
01295 }
01296 catch(...)
01297 {
01298 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
01299 return NULL;
01300 }
01301 #else // DONT_CATCH_CXX_EXCEPTIONS
01302 catch(const Base::Exception& e)
01303 {
01304 std::string str;
01305 str += "FreeCAD exception thrown (";
01306 str += e.what();
01307 str += ")";
01308 e.ReportException();
01309 PyErr_SetString(PyExc_Exception,str.c_str());
01310 return NULL;
01311 }
01312 catch(const Py::Exception&)
01313 {
01314
01315 return NULL;
01316 }
01317 #endif // DONT_CATCH_CXX_EXCEPTIONS
01318
01319 PyObject *rvalue = Py_FindMethod(Methods, this, attr);
01320 if (rvalue == NULL)
01321 {
01322 PyErr_Clear();
01323 return PyObjectBase::_getattr(attr);
01324 }
01325 else
01326 {
01327 return rvalue;
01328 }
01329 }
01330
01331 int VectorPy::_setattr(char *attr, PyObject *value)
01332 {
01333 try {
01334
01335 int r = setCustomAttributes(attr, value);
01336 if(r==1) return 0;
01337 }
01338 #ifndef DONT_CATCH_CXX_EXCEPTIONS
01339 catch(const Base::Exception& e)
01340 {
01341 std::string str;
01342 str += "FreeCAD exception thrown (";
01343 str += e.what();
01344 str += ")";
01345 e.ReportException();
01346 PyErr_SetString(PyExc_Exception,str.c_str());
01347 return -1;
01348 }
01349 catch(const std::exception& e)
01350 {
01351 std::string str;
01352 str += "FC++ exception thrown (";
01353 str += e.what();
01354 str += ")";
01355 Base::Console().Error(str.c_str());
01356 PyErr_SetString(PyExc_Exception,str.c_str());
01357 return -1;
01358 }
01359 catch(const Py::Exception&)
01360 {
01361
01362 return -1;
01363 }
01364 catch(...)
01365 {
01366 PyErr_SetString(PyExc_Exception,"Unknown C++ exception");
01367 return -1;
01368 }
01369 #else // DONT_CATCH_CXX_EXCEPTIONS
01370 catch(const Base::Exception& e)
01371 {
01372 std::string str;
01373 str += "FreeCAD exception thrown (";
01374 str += e.what();
01375 str += ")";
01376 e.ReportException();
01377 PyErr_SetString(PyExc_Exception,str.c_str());
01378 return -1;
01379 }
01380 catch(const Py::Exception&)
01381 {
01382
01383 return -1;
01384 }
01385 #endif // DONT_CATCH_CXX_EXCEPTIONS
01386
01387 return PyObjectBase::_setattr(attr, value);
01388 }
01389
01390 Vector3d *VectorPy::getVectorPtr(void) const
01391 {
01392 return static_cast<Vector3d *>(_pcTwinPointer);
01393 }
01394
01395 #if 0
01396
01397
01398
01399
01400 PyObject *VectorPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
01401 {
01402
01403 return new VectorPy(new Vector3d);
01404 }
01405
01406
01407 int VectorPy::PyInit(PyObject* , PyObject* )
01408 {
01409 return 0;
01410 }
01411
01412
01413 std::string VectorPy::representation(void) const
01414 {
01415 return std::string("<Vector object>");
01416 }
01417
01418 PyObject* VectorPy::add(PyObject *args)
01419 {
01420 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01421 return 0;
01422 }
01423
01424 PyObject* VectorPy::sub(PyObject *args)
01425 {
01426 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01427 return 0;
01428 }
01429
01430 PyObject* VectorPy::scale(PyObject *args)
01431 {
01432 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01433 return 0;
01434 }
01435
01436 PyObject* VectorPy::multiply(PyObject *args)
01437 {
01438 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01439 return 0;
01440 }
01441
01442 PyObject* VectorPy::dot(PyObject *args)
01443 {
01444 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01445 return 0;
01446 }
01447
01448 PyObject* VectorPy::cross(PyObject *args)
01449 {
01450 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01451 return 0;
01452 }
01453
01454 PyObject* VectorPy::getAngle(PyObject *args)
01455 {
01456 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01457 return 0;
01458 }
01459
01460 PyObject* VectorPy::normalize(PyObject *args)
01461 {
01462 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01463 return 0;
01464 }
01465
01466 PyObject* VectorPy::projectToLine(PyObject *args)
01467 {
01468 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01469 return 0;
01470 }
01471
01472 PyObject* VectorPy::projectToPlane(PyObject *args)
01473 {
01474 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01475 return 0;
01476 }
01477
01478 PyObject* VectorPy::distanceToLine(PyObject *args)
01479 {
01480 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01481 return 0;
01482 }
01483
01484 PyObject* VectorPy::distanceToPlane(PyObject *args)
01485 {
01486 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01487 return 0;
01488 }
01489
01490 PyObject* VectorPy::number_add_handler(PyObject *self, PyObject *other)
01491 {
01492 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01493 return 0;
01494 }
01495
01496 PyObject* VectorPy::number_subtract_handler(PyObject *self, PyObject *other)
01497 {
01498 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01499 return 0;
01500 }
01501
01502 PyObject* VectorPy::number_multiply_handler(PyObject *self, PyObject *other)
01503 {
01504 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01505 return 0;
01506 }
01507
01508 Py_ssize_t VectorPy::sequence_length(PyObject *)
01509 {
01510 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01511 return -1;
01512 }
01513
01514 PyObject * VectorPy::sequence_item(PyObject *, Py_ssize_t)
01515 {
01516 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01517 return 0;
01518 }
01519
01520 int VectorPy::sequence_ass_item(PyObject *, Py_ssize_t, PyObject *)
01521 {
01522 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01523 return -1;
01524 }
01525
01526 PyObject* VectorPy::richCompare(PyObject *v, PyObject *w, int op)
01527 {
01528 PyErr_SetString(PyExc_NotImplementedError, "Not yet implemented");
01529 return 0;
01530 }
01531
01532 Py::Float VectorPy::getLength(void) const
01533 {
01534
01535 throw Py::AttributeError("Not yet implemented");
01536 }
01537
01538 void VectorPy::setLength(Py::Float arg)
01539 {
01540 throw Py::AttributeError("Not yet implemented");
01541 }
01542
01543 Py::Float VectorPy::getx(void) const
01544 {
01545
01546 throw Py::AttributeError("Not yet implemented");
01547 }
01548
01549 void VectorPy::setx(Py::Float arg)
01550 {
01551 throw Py::AttributeError("Not yet implemented");
01552 }
01553
01554 Py::Float VectorPy::gety(void) const
01555 {
01556
01557 throw Py::AttributeError("Not yet implemented");
01558 }
01559
01560 void VectorPy::sety(Py::Float arg)
01561 {
01562 throw Py::AttributeError("Not yet implemented");
01563 }
01564
01565 Py::Float VectorPy::getz(void) const
01566 {
01567
01568 throw Py::AttributeError("Not yet implemented");
01569 }
01570
01571 void VectorPy::setz(Py::Float arg)
01572 {
01573 throw Py::AttributeError("Not yet implemented");
01574 }
01575
01576 PyObject *VectorPy::getCustomAttributes(const char* attr) const
01577 {
01578 return 0;
01579 }
01580
01581 int VectorPy::setCustomAttributes(const char* attr, PyObject *obj)
01582 {
01583 return 0;
01584 }
01585 #endif
01586
01587
01588