Skip to content

Commit

Permalink
Attacher: Py: implement Attacher attribute of AttachableObject
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSOIC committed May 13, 2016
1 parent 7000d55 commit dcc8926
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mod/Part/App/AttachableObject.h
Expand Up @@ -78,7 +78,7 @@ class PartExport AttachableObject : public Part::Feature
*/
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;
Expand Down
7 changes: 7 additions & 0 deletions src/Mod/Part/App/AttachableObjectPy.xml
Expand Up @@ -30,5 +30,12 @@ typename: string. The following are accepted so far:
'Attacher::AttachEnginePoint'</UserDocu>
</Documentation>
</Methode>

<Attribute Name="Attacher" ReadOnly="true">
<Documentation>
<UserDocu>AttachEngine object driving this AttachableObject. Returns a copy.</UserDocu>
</Documentation>
<Parameter Name="Attacher" Type="Object" />
</Attribute>
</PythonExport>
</GenerateModel>
20 changes: 20 additions & 0 deletions src/Mod/Part/App/AttachableObjectPyImp.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit dcc8926

Please sign in to comment.