diff --git a/src/Mod/PartDesign/App/AppPartDesign.cpp b/src/Mod/PartDesign/App/AppPartDesign.cpp index e9ef3b7f64..33e18f65c4 100644 --- a/src/Mod/PartDesign/App/AppPartDesign.cpp +++ b/src/Mod/PartDesign/App/AppPartDesign.cpp @@ -84,65 +84,68 @@ PyMOD_INIT_FUNC(_PartDesign) // call PyType_Ready, otherwise we run into a segmentation fault, later on. // This function is responsible for adding inherited slots from a type's base class. - PartDesign::Feature ::init(); - PartDesign::FeaturePython ::init(); - PartDesign::Solid ::init(); - PartDesign::DressUp ::init(); - PartDesign::FeatureAddSub ::init(); - PartDesign::ProfileBased ::init(); - PartDesign::Transformed ::init(); - PartDesign::Mirrored ::init(); - PartDesign::LinearPattern ::init(); - PartDesign::PolarPattern ::init(); - PartDesign::Scaled ::init(); - PartDesign::MultiTransform ::init(); - PartDesign::Hole ::init(); - PartDesign::Body ::init(); - PartDesign::Pad ::init(); - PartDesign::Pocket ::init(); - PartDesign::Fillet ::init(); - PartDesign::Revolution ::init(); - PartDesign::Groove ::init(); - PartDesign::Chamfer ::init(); - PartDesign::Draft ::init(); - PartDesign::Thickness ::init(); - PartDesign::Pipe ::init(); - PartDesign::AdditivePipe ::init(); - PartDesign::SubtractivePipe ::init(); - PartDesign::Loft ::init(); - PartDesign::AdditiveLoft ::init(); - PartDesign::SubtractiveLoft ::init(); - PartDesign::ShapeBinder ::init(); - PartDesign::Plane ::init(); - PartDesign::Line ::init(); - PartDesign::Point ::init(); - PartDesign::CoordinateSystem ::init(); - PartDesign::Boolean ::init(); - PartDesign::FeaturePrimitive ::init(); - PartDesign::Box ::init(); - PartDesign::AdditiveBox ::init(); - PartDesign::SubtractiveBox ::init(); - PartDesign::Cylinder ::init(); - PartDesign::AdditiveCylinder ::init(); - PartDesign::SubtractiveCylinder::init(); - PartDesign::Sphere ::init(); - PartDesign::AdditiveSphere ::init(); - PartDesign::SubtractiveSphere ::init(); - PartDesign::Cone ::init(); - PartDesign::AdditiveCone ::init(); - PartDesign::SubtractiveCone ::init(); - PartDesign::Ellipsoid ::init(); - PartDesign::AdditiveEllipsoid ::init(); - PartDesign::SubtractiveEllipsoid ::init(); - PartDesign::Torus ::init(); - PartDesign::AdditiveTorus ::init(); - PartDesign::SubtractiveTorus ::init(); - PartDesign::Prism ::init(); - PartDesign::AdditivePrism ::init(); - PartDesign::SubtractivePrism ::init(); - PartDesign::Wedge ::init(); - PartDesign::AdditiveWedge ::init(); - PartDesign::SubtractiveWedge ::init(); + PartDesign::Feature ::init(); + PartDesign::FeaturePython ::init(); + PartDesign::Solid ::init(); + PartDesign::DressUp ::init(); + PartDesign::FeatureAddSub ::init(); + PartDesign::FeatureAddSubPython ::init(); + PartDesign::FeatureAdditivePython ::init(); + PartDesign::FeatureSubtractivePython ::init(); + PartDesign::ProfileBased ::init(); + PartDesign::Transformed ::init(); + PartDesign::Mirrored ::init(); + PartDesign::LinearPattern ::init(); + PartDesign::PolarPattern ::init(); + PartDesign::Scaled ::init(); + PartDesign::MultiTransform ::init(); + PartDesign::Hole ::init(); + PartDesign::Body ::init(); + PartDesign::Pad ::init(); + PartDesign::Pocket ::init(); + PartDesign::Fillet ::init(); + PartDesign::Revolution ::init(); + PartDesign::Groove ::init(); + PartDesign::Chamfer ::init(); + PartDesign::Draft ::init(); + PartDesign::Thickness ::init(); + PartDesign::Pipe ::init(); + PartDesign::AdditivePipe ::init(); + PartDesign::SubtractivePipe ::init(); + PartDesign::Loft ::init(); + PartDesign::AdditiveLoft ::init(); + PartDesign::SubtractiveLoft ::init(); + PartDesign::ShapeBinder ::init(); + PartDesign::Plane ::init(); + PartDesign::Line ::init(); + PartDesign::Point ::init(); + PartDesign::CoordinateSystem ::init(); + PartDesign::Boolean ::init(); + PartDesign::FeaturePrimitive ::init(); + PartDesign::Box ::init(); + PartDesign::AdditiveBox ::init(); + PartDesign::SubtractiveBox ::init(); + PartDesign::Cylinder ::init(); + PartDesign::AdditiveCylinder ::init(); + PartDesign::SubtractiveCylinder ::init(); + PartDesign::Sphere ::init(); + PartDesign::AdditiveSphere ::init(); + PartDesign::SubtractiveSphere ::init(); + PartDesign::Cone ::init(); + PartDesign::AdditiveCone ::init(); + PartDesign::SubtractiveCone ::init(); + PartDesign::Ellipsoid ::init(); + PartDesign::AdditiveEllipsoid ::init(); + PartDesign::SubtractiveEllipsoid ::init(); + PartDesign::Torus ::init(); + PartDesign::AdditiveTorus ::init(); + PartDesign::SubtractiveTorus ::init(); + PartDesign::Prism ::init(); + PartDesign::AdditivePrism ::init(); + PartDesign::SubtractivePrism ::init(); + PartDesign::Wedge ::init(); + PartDesign::AdditiveWedge ::init(); + PartDesign::SubtractiveWedge ::init(); PyMOD_Return(mod); } diff --git a/src/Mod/PartDesign/App/FeatureAddSub.cpp b/src/Mod/PartDesign/App/FeatureAddSub.cpp index c845bb3743..fc2aadefdd 100644 --- a/src/Mod/PartDesign/App/FeatureAddSub.cpp +++ b/src/Mod/PartDesign/App/FeatureAddSub.cpp @@ -26,7 +26,9 @@ #endif +#include #include "FeatureAddSub.h" +#include "FeaturePy.h" using namespace PartDesign; @@ -48,3 +50,50 @@ FeatureAddSub::Type FeatureAddSub::getAddSubType() } } + +namespace App { +/// @cond DOXERR +PROPERTY_SOURCE_TEMPLATE(PartDesign::FeatureAddSubPython, PartDesign::FeatureAddSub) +template<> const char* PartDesign::FeatureAddSubPython::getViewProviderName(void) const { + return "PartDesignGui::ViewProviderPython"; +} +template<> PyObject* PartDesign::FeatureAddSubPython::getPyObject(void) { + if (PythonObject.is(Py::_None())) { + // ref counter is set to 1 + PythonObject = Py::Object(new FeaturePythonPyT(this),true); + } + return Py::new_reference_to(PythonObject); +} +/// @endcond + +// explicit template instantiation +template class PartDesignExport FeaturePythonT; +} + + +namespace PartDesign { + +PROPERTY_SOURCE(PartDesign::FeatureAdditivePython, PartDesign::FeatureAddSubPython) + +FeatureAdditivePython::FeatureAdditivePython() +{ + addSubType = Additive; +} + +FeatureAdditivePython::~FeatureAdditivePython() +{ +} + + +PROPERTY_SOURCE(PartDesign::FeatureSubtractivePython, PartDesign::FeatureAddSubPython) + +FeatureSubtractivePython::FeatureSubtractivePython() +{ + addSubType = Subtractive; +} + +FeatureSubtractivePython::~FeatureSubtractivePython() +{ +} + +} diff --git a/src/Mod/PartDesign/App/FeatureAddSub.h b/src/Mod/PartDesign/App/FeatureAddSub.h index 62933f4f07..6e09055b6b 100644 --- a/src/Mod/PartDesign/App/FeatureAddSub.h +++ b/src/Mod/PartDesign/App/FeatureAddSub.h @@ -53,6 +53,26 @@ protected: Type addSubType; }; +typedef App::FeaturePythonT FeatureAddSubPython; + +class FeatureAdditivePython : public FeatureAddSubPython +{ + PROPERTY_HEADER(PartDesign::FeatureAdditivePython); + +public: + FeatureAdditivePython(); + ~FeatureAdditivePython(); +}; + +class FeatureSubtractivePython : public FeatureAddSubPython +{ + PROPERTY_HEADER(PartDesign::FeatureSubtractivePython); + +public: + FeatureSubtractivePython(); + ~FeatureSubtractivePython(); +}; + } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/FeaturePyImp.cpp b/src/Mod/PartDesign/App/FeaturePyImp.cpp index c2705499b1..3ae11c06ff 100644 --- a/src/Mod/PartDesign/App/FeaturePyImp.cpp +++ b/src/Mod/PartDesign/App/FeaturePyImp.cpp @@ -34,7 +34,10 @@ using namespace PartDesign; // returns a string which represent the object e.g. when printed in python std::string FeaturePy::representation(void) const { - return std::string(""); + App::DocumentObject* object = this->getFeaturePtr(); + std::stringstream str; + str << "<" << object->getTypeId().getName() << ">"; + return str.str(); } PyObject *FeaturePy::getCustomAttributes(const char* ) const