Skip to content

Commit

Permalink
Attacher: Py: introduce Py interface of AttachableObject
Browse files Browse the repository at this point in the history
Small - just the introduction.
Support for Py features based on AttachableObject.
Redirect Part2DObjectPython's father to be AttachableObjectPython.
  • Loading branch information
DeepSOIC committed May 13, 2016
1 parent 897a66c commit fe295b7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -229,6 +229,7 @@ PyMODINIT_FUNC initPart()
Part::Feature ::init();
Part::FeatureExt ::init();
Part::AttachableObject ::init();
Part::AttachableObjectPython::init();
Part::BodyBase ::init();
Part::FeaturePython ::init();
Part::FeatureGeometrySet ::init();
Expand Down
20 changes: 20 additions & 0 deletions src/Mod/Part/App/AttachableObject.cpp
Expand Up @@ -30,6 +30,8 @@
#include <Base/Console.h>
#include <App/Application.h>

#include <App/FeaturePythonPyImp.h>
#include "AttachableObjectPy.h"


using namespace Part;
Expand Down Expand Up @@ -151,4 +153,22 @@ void AttachableObject::updateAttacherVals()
this->superPlacement.getValue());
}

namespace App {
/// @cond DOXERR
PROPERTY_SOURCE_TEMPLATE(Part::AttachableObjectPython, Part::AttachableObject)
template<> const char* Part::AttachableObjectPython::getViewProviderName(void) const {
return "PartGui::ViewProviderPython";
}
template<> PyObject* Part::AttachableObjectPython::getPyObject(void) {
if (PythonObject.is(Py::_None())) {
// ref counter is set to 1
PythonObject = Py::Object(new FeaturePythonPyT<Part::AttachableObjectPy>(this),true);
}
return Py::new_reference_to(PythonObject);
}
/// @endcond

// explicit template instantiation
template class PartExport FeaturePythonT<Part::AttachableObject>;
}

2 changes: 2 additions & 0 deletions src/Mod/Part/App/AttachableObject.h
Expand Up @@ -104,6 +104,8 @@ class PartExport AttachableObject : public Part::Feature
};


typedef App::FeaturePythonT<AttachableObject> AttachableObjectPython;

} // namespace Part

#endif // PARTATTACHABLEOBJECT_H
24 changes: 24 additions & 0 deletions src/Mod/Part/App/AttachableObjectPy.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PartFeaturePy"
Name="AttachableObjectPy"
Twin="AttachableObject"
TwinPointer="AttachableObject"
Include="Mod/Part/App/AttachableObject.h"
Namespace="Part"
FatherInclude="Mod/Part/App/PartFeaturePy.h"
FatherNamespace="Part">
<Documentation>
<Author Licence="LGPL" Name="DeepSOIC" EMail="vv.titov@gmail.com" />
<UserDocu>This object represents an attachable object with OCC shape.</UserDocu>
</Documentation>
<Methode Name="positionBySupport">
<Documentation>
<UserDocu>positionBySupport(): Reposition object based on Support, MapMode and MapPathParameter properties.
Returns True if attachment calculation was successful, false if object is not attached and Placement wasn't updated,
and raises an exception if attachment calculation fails.</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>
48 changes: 48 additions & 0 deletions src/Mod/Part/App/AttachableObjectPyImp.cpp
@@ -0,0 +1,48 @@

#include "PreCompiled.h"

#include "Mod/Part/App/AttachableObject.h"
#include "OCCError.h"

// inclusion of the generated files (generated out of AttachableObjectPy.xml)
#include "AttachableObjectPy.h"
#include "AttachableObjectPy.cpp"

using namespace Part;

// returns a string which represents the object e.g. when printed in python
std::string AttachableObjectPy::representation(void) const
{
return std::string("<Part::AttachableObject>");
}

PyObject* AttachableObjectPy::positionBySupport(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return 0;
bool bAttached = false;
try{
bAttached = this->getAttachableObjectPtr()->positionBySupport();
} catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
PyErr_SetString(PartExceptionOCCError, e->GetMessageString());
return NULL;
} catch (Base::Exception &e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return NULL;
}
return Py::new_reference_to(Py::Boolean(bAttached));
}


PyObject *AttachableObjectPy::getCustomAttributes(const char* /*attr*/) const
{
return 0;
}

int AttachableObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
{
return 0;
}


3 changes: 3 additions & 0 deletions src/Mod/Part/App/CMakeLists.txt
Expand Up @@ -69,6 +69,7 @@ generate_from_xml(RectangularTrimmedSurfacePy)
generate_from_xml(SurfaceOfExtrusionPy)
generate_from_xml(SurfaceOfRevolutionPy)
generate_from_xml(PartFeaturePy)
generate_from_xml(AttachableObjectPy)
generate_from_xml(Part2DObjectPy)
generate_from_xml(TopoShapePy)
generate_from_xml(TopoShapeCompoundPy)
Expand Down Expand Up @@ -216,6 +217,8 @@ SET(Python_SRCS
SurfaceOfRevolutionPyImp.cpp
PartFeaturePy.xml
PartFeaturePyImp.cpp
AttachableObjectPy.xml
AttachableObjectPyImp.cpp
Part2DObjectPy.xml
Part2DObjectPyImp.cpp
TopoShapePy.xml
Expand Down
4 changes: 2 additions & 2 deletions src/Mod/Part/App/Part2DObjectPy.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="PartFeaturePy"
Father="AttachableObjectPy"
Name="Part2DObjectPy"
Twin="Part2DObject"
TwinPointer="Part2DObject"
Include="Mod/Part/App/Part2DObject.h"
Namespace="Part"
FatherInclude="Mod/Part/App/PartFeaturePy.h"
FatherInclude="Mod/Part/App/AttachableObjectPy.h"
FatherNamespace="Part">
<Documentation>
<Author Licence="LGPL" Name="Juergen Riegel" EMail="FreeCAD@juergen-riegel.net" />
Expand Down

0 comments on commit fe295b7

Please sign in to comment.