diff --git a/src/App/FeaturePythonPyImp.h b/src/App/FeaturePythonPyImp.h
index 4e72f013df..3926bfff7a 100644
--- a/src/App/FeaturePythonPyImp.h
+++ b/src/App/FeaturePythonPyImp.h
@@ -26,6 +26,37 @@
#include
#include
+#define PYTHON_TYPE_DEF(_class_, _subclass_) \
+ class _class_ : public _subclass_ \
+ { \
+ public: \
+ static PyTypeObject Type; \
+ public: \
+ _class_(Base::BaseClass *pcObject, PyTypeObject *T = &Type); \
+ virtual ~_class_(); \
+ };
+
+#define PYTHON_TYPE_IMP(_class_, _subclass_) \
+ PyTypeObject _class_::Type = { \
+ PyObject_HEAD_INIT(&PyType_Type) \
+ 0, \
+ ""#_class_"", \
+ sizeof(_class_), \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_CLASS, \
+ ""#_class_"", \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ &_subclass_::Type, \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
+ }; \
+ _class_::_class_(Base::BaseClass *pcObject, PyTypeObject *T) \
+ : _subclass_(reinterpret_cast<_subclass_::PointerType>(pcObject), T) \
+ { \
+ } \
+ _class_::~_class_() \
+ { \
+ }
+
namespace App
{
diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp
index fef056f72c..fda1787017 100644
--- a/src/Mod/Part/App/PrimitiveFeature.cpp
+++ b/src/Mod/Part/App/PrimitiveFeature.cpp
@@ -63,6 +63,8 @@
#include "PrimitiveFeature.h"
+#include
+#include
#include
#include
#include
@@ -105,6 +107,19 @@ App::DocumentObjectExecReturn* Primitive::execute(void) {
return Part::Feature::execute();
}
+namespace Part {
+ PYTHON_TYPE_DEF(PrimitivePy, PartFeaturePy)
+ PYTHON_TYPE_IMP(PrimitivePy, PartFeaturePy)
+}
+
+PyObject* Primitive::getPyObject()
+{
+ if (PythonObject.is(Py::_None())){
+ // ref counter is set to 1
+ PythonObject = Py::Object(new PrimitivePy(this),true);
+ }
+ return Py::new_reference_to(PythonObject);
+}
void Primitive::Restore(Base::XMLReader &reader)
{
diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h
index f430b1d623..f73f8c41d2 100644
--- a/src/Mod/Part/App/PrimitiveFeature.h
+++ b/src/Mod/Part/App/PrimitiveFeature.h
@@ -44,6 +44,7 @@ public:
/// recalculate the feature
App::DocumentObjectExecReturn *execute(void);
short mustExecute() const;
+ PyObject* getPyObject();
//@}
protected: