From dcc8926236e1fab6165d3b43690082f22d307972 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Sat, 7 May 2016 14:14:25 +0300 Subject: [PATCH] Attacher: Py: implement Attacher attribute of AttachableObject --- src/Mod/Part/App/AttachableObject.h | 2 +- src/Mod/Part/App/AttachableObjectPy.xml | 7 +++++++ src/Mod/Part/App/AttachableObjectPyImp.cpp | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/App/AttachableObject.h b/src/Mod/Part/App/AttachableObject.h index 83bababa0..ed68a3958 100644 --- a/src/Mod/Part/App/AttachableObject.h +++ b/src/Mod/Part/App/AttachableObject.h @@ -78,7 +78,7 @@ public: */ bool changeAttacherType(const char* typeName); - Attacher::AttachEngine &attacher(void) const {return *_attacher;} + Attacher::AttachEngine &attacher(void) const {if(!_attacher) throw Base::Exception("AttachableObject: no attacher is set."); return *_attacher;} App::PropertyString AttacherType; diff --git a/src/Mod/Part/App/AttachableObjectPy.xml b/src/Mod/Part/App/AttachableObjectPy.xml index 664fbf7a7..89a75d45e 100644 --- a/src/Mod/Part/App/AttachableObjectPy.xml +++ b/src/Mod/Part/App/AttachableObjectPy.xml @@ -30,5 +30,12 @@ typename: string. The following are accepted so far: 'Attacher::AttachEnginePoint' + + + + AttachEngine object driving this AttachableObject. Returns a copy. + + + diff --git a/src/Mod/Part/App/AttachableObjectPyImp.cpp b/src/Mod/Part/App/AttachableObjectPyImp.cpp index 82ed1d6ea..aa45e065b 100644 --- a/src/Mod/Part/App/AttachableObjectPyImp.cpp +++ b/src/Mod/Part/App/AttachableObjectPyImp.cpp @@ -4,6 +4,8 @@ #include "Mod/Part/App/AttachableObject.h" #include "OCCError.h" +#include "AttachEnginePy.h" + // inclusion of the generated files (generated out of AttachableObjectPy.xml) #include "AttachableObjectPy.h" #include "AttachableObjectPy.cpp" @@ -53,6 +55,24 @@ PyObject* AttachableObjectPy::changeAttacherType(PyObject *args) return Py::new_reference_to(Py::Boolean(ret)); } +Py::Object AttachableObjectPy::getAttacher(void) const +{ + try { + this->getAttachableObjectPtr()->attacher(); //throws if attacher is not set + } catch (Base::Exception) { + return Py::None(); + } + + try { + return Py::Object( new Attacher::AttachEnginePy(this->getAttachableObjectPtr()->attacher().copy()), true); + } catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + throw Py::Exception(Part::PartExceptionOCCError, e->GetMessageString()); + } catch (Base::Exception &e) { + throw Py::Exception(Base::BaseExceptionFreeCADError, e.what()); + } + +} PyObject *AttachableObjectPy::getCustomAttributes(const char* /*attr*/) const {