Skip to content

Commit

Permalink
spend own type for Python wrappers of FeaturePrimitive and BodyBase
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 20, 2017
1 parent ac7750f commit eeb7dd4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Mod/Part/App/BodyBase.cpp
Expand Up @@ -25,6 +25,7 @@
#ifndef _PreComp_
#endif

#include <Mod/Part/App/BodyBasePy.h>
#include <App/Application.h>
#include <App/Document.h>
#include <Base/Placement.h>
Expand Down Expand Up @@ -98,4 +99,13 @@ void BodyBase::onChanged (const App::Property* prop) {
Part::Feature::onChanged ( prop );
}

PyObject* BodyBase::getPyObject()
{
if (PythonObject.is(Py::_None())){
// ref counter is set to 1
PythonObject = Py::Object(new BodyBasePy(this),true);
}
return Py::new_reference_to(PythonObject);
}

} /* Part */
1 change: 1 addition & 0 deletions src/Mod/Part/App/BodyBase.h
Expand Up @@ -78,6 +78,7 @@ class PartExport BodyBase : public Part::Feature, public App::OriginGroupExtensi
* TODO introduce a findBodiesOf() if needed (2015-08-04, Fat-Zer)
*/
static BodyBase* findBodyOf(const App::DocumentObject* f);
virtual PyObject* getPyObject();

protected:
/// If BaseFeature is getting changed and Tip points to it resets the Tip
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/PartDesign/App/FeaturePrimitive.cpp
Expand Up @@ -30,10 +30,13 @@
#include "DatumPoint.h"
#include "DatumCS.h"
#include <Mod/Part/App/modelRefine.h>
#include <Mod/Part/App/PartFeaturePy.h>
#include <Base/Exception.h>
#include <Base/Tools.h>
#include <App/Document.h>
#include <App/Application.h>
#include <App/FeaturePythonPyImp.h>

#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepBuilderAPI_GTransform.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
Expand Down Expand Up @@ -152,6 +155,18 @@ void FeaturePrimitive::onChanged(const App::Property* prop)
FeatureAddSub::onChanged(prop);
}

PYTHON_TYPE_DEF(PrimitivePy, Part::PartFeaturePy)
PYTHON_TYPE_IMP(PrimitivePy, Part::PartFeaturePy)

PyObject* FeaturePrimitive::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);
}

PROPERTY_SOURCE(PartDesign::Box, PartDesign::FeaturePrimitive)

Box::Box()
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/PartDesign/App/FeaturePrimitive.h
Expand Up @@ -54,14 +54,15 @@ class PartDesignExport FeaturePrimitive : public PartDesign::FeatureAddSub, publ
virtual const char* getViewProviderName(void) const {
return "PartDesignGui::ViewProviderPrimitive";
}
Type getPrimitiveType() {return primitiveType;};
Type getPrimitiveType() {return primitiveType;}
TopoDS_Shape refineShapeIfActive(const TopoDS_Shape& oldShape) const;
virtual void onChanged(const App::Property* prop);
virtual PyObject* getPyObject();

/// Do nothing, just to suppress warning, must be redefined in derived classes
virtual App::DocumentObjectExecReturn* execute() {
return PartDesign::FeatureAddSub::execute();
};
}
protected:
//make the boolean ops with the primitives provided by the derived features
App::DocumentObjectExecReturn* execute(const TopoDS_Shape& primitiveShape);
Expand Down

0 comments on commit eeb7dd4

Please sign in to comment.