From d0d4d6bc07a9b95f6813da3e60616c87021622e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Wed, 30 Nov 2016 17:25:26 +0100 Subject: [PATCH] Port Attacher codde to the extension framework AttachableObjects are desired in multiple occasions, and the current AttachableObject is not flexible enough to handle all cases. Hence the code is portet to an extension, which gives the needed flexibility. --- src/App/DocumentObject.cpp | 7 +-- src/App/Extension.h | 9 ++- src/App/ExtensionContainer.h | 12 ++-- src/Mod/Part/App/AppPart.cpp | 7 ++- src/Mod/Part/App/AttachEnginePyImp.cpp | 18 +++--- ...tachableObject.cpp => AttachExtension.cpp} | 40 +++++++------ .../{AttachableObject.h => AttachExtension.h} | 6 +- ...ableObjectPy.xml => AttachExtensionPy.xml} | 15 +++-- ...jectPyImp.cpp => AttachExtensionPyImp.cpp} | 28 +++++----- src/Mod/Part/App/CMakeLists.txt | 10 ++-- src/Mod/Part/App/DatumFeature.cpp | 5 +- src/Mod/Part/App/DatumFeature.h | 6 +- src/Mod/Part/App/Part2DObject.cpp | 5 +- src/Mod/Part/App/Part2DObject.h | 6 +- src/Mod/Part/App/Part2DObjectPy.xml | 4 +- src/Mod/Part/App/PartFeature.cpp | 2 +- src/Mod/Part/App/PrimitiveFeature.cpp | 56 ++++++++++--------- src/Mod/Part/App/PrimitiveFeature.h | 8 +-- src/Mod/PartDesign/Gui/Command.cpp | 2 +- src/Mod/PartDesign/Gui/Utils.cpp | 8 +-- 20 files changed, 136 insertions(+), 118 deletions(-) rename src/Mod/Part/App/{AttachableObject.cpp => AttachExtension.cpp} (89%) rename src/Mod/Part/App/{AttachableObject.h => AttachExtension.h} (94%) rename src/Mod/Part/App/{AttachableObjectPy.xml => AttachExtensionPy.xml} (83%) rename src/Mod/Part/App/{AttachableObjectPyImp.cpp => AttachExtensionPyImp.cpp} (65%) diff --git a/src/App/DocumentObject.cpp b/src/App/DocumentObject.cpp index daac1f756..476d87412 100644 --- a/src/App/DocumentObject.cpp +++ b/src/App/DocumentObject.cpp @@ -82,10 +82,9 @@ DocumentObjectExecReturn *DocumentObject::execute(void) { //call all extensions auto vector = getExtensionsDerivedFromType(); - for(auto ext : vector) { - if(ext->extensionMustExecute()) - ext->extensionExecute(); - } + for(auto ext : vector) + ext->extensionExecute(); + return StdReturn; } diff --git a/src/App/Extension.h b/src/App/Extension.h index 65583ef83..c164a721b 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -53,6 +53,13 @@ void * _class_::create(void){\ return new _class_ ();\ } +/// define to implement a subclass of Base::BaseClass +#define EXTENSION_TYPESYSTEM_SOURCE_ABSTRACT_P(_class_) \ +Base::Type _class_::getExtensionClassTypeId(void) { return _class_::classTypeId; } \ +Base::Type _class_::getExtensionTypeId(void) const { return _class_::classTypeId; } \ +Base::Type _class_::classTypeId = Base::Type::badType(); \ +void * _class_::create(void){return 0;} + /// define to implement a subclass of Base::BaseClass #define EXTENSION_TYPESYSTEM_SOURCE(_class_, _parentclass_) \ EXTENSION_TYPESYSTEM_SOURCE_P(_class_);\ @@ -248,7 +255,7 @@ public: /** @name TypeHandling */ //@{ - bool isDerivedFrom(const Base::Type type) const {return getExtensionTypeId().isDerivedFrom(type);} + bool extensionIsDerivedFrom(const Base::Type type) const {return getExtensionTypeId().isDerivedFrom(type);} protected: static void initExtensionSubclass(Base::Type &toInit,const char* ClassName, const char *ParentName, Base::Type::instantiationMethod method=0); diff --git a/src/App/ExtensionContainer.h b/src/App/ExtensionContainer.h index dc6e42b88..ca13f5b34 100644 --- a/src/App/ExtensionContainer.h +++ b/src/App/ExtensionContainer.h @@ -186,14 +186,10 @@ private: /// We make sur that the PropertyData of the container is not connected to the one of the extension #define PROPERTY_SOURCE_WITH_EXTENSIONS(_class_, _parentclass_) \ -TYPESYSTEM_SOURCE_P(_class_);\ -const App::PropertyData * _class_::getPropertyDataPtr(void){return &propertyData;} \ -const App::PropertyData & _class_::getPropertyData(void) const{return propertyData;} \ -App::PropertyData _class_::propertyData; \ -void _class_::init(void){\ - initSubclass(_class_::classTypeId, #_class_ , #_parentclass_, &(_class_::create) ); \ - _class_::propertyData.parentPropertyData = _parentclass_::getPropertyDataPtr();\ -} + PROPERTY_SOURCE(_class_, _parentclass_) + +#define PROPERTY_SOURCE_ABSTRACT_WITH_EXTENSIONS(_class_, _parentclass_) \ + PROPERTY_SOURCE_ABSTRACT(_class_, _parentclass_) } //App diff --git a/src/Mod/Part/App/AppPart.cpp b/src/Mod/Part/App/AppPart.cpp index af49edf33..bc4c86d7b 100644 --- a/src/Mod/Part/App/AppPart.cpp +++ b/src/Mod/Part/App/AppPart.cpp @@ -118,7 +118,7 @@ #include "PropertyGeometryList.h" #include "DatumFeature.h" #include "Attacher.h" -#include "AttachableObject.h" +#include "AttachExtension.h" #include "FaceMaker.h" #include "FaceMakerCheese.h" #include "FaceMakerBullseye.h" @@ -397,11 +397,12 @@ PyMODINIT_FUNC initPart() Attacher::AttachEnginePlane ::init(); Attacher::AttachEngineLine ::init(); Attacher::AttachEnginePoint ::init(); + + Part::AttachExtension ::init(); + Part::AttachExtensionPython ::init(); Part::Feature ::init(); Part::FeatureExt ::init(); - Part::AttachableObject ::init(); - Part::AttachableObjectPython::init(); Part::BodyBase ::init(); Part::FeaturePython ::init(); Part::FeatureGeometrySet ::init(); diff --git a/src/Mod/Part/App/AttachEnginePyImp.cpp b/src/Mod/Part/App/AttachEnginePyImp.cpp index 259f1e76f..fe2abd3c7 100644 --- a/src/Mod/Part/App/AttachEnginePyImp.cpp +++ b/src/Mod/Part/App/AttachEnginePyImp.cpp @@ -6,7 +6,7 @@ #include "Mod/Part/App/Attacher.h" #include #include -#include "AttachableObjectPy.h" +#include "AttachExtensionPy.h" #include "TopoShapePy.h" #include "OCCError.h" @@ -493,12 +493,12 @@ PyObject* AttachEnginePy::readParametersFromFeature(PyObject* args) return NULL; // NULL triggers exception try{ - const App::DocumentObjectPy* dobjpy = static_cast(obj); - const App::DocumentObject* dobj = dobjpy->getDocumentObjectPtr(); - if (! dobj->isDerivedFrom(Part::AttachableObject::getClassTypeId())){ - throw Py::TypeError("Supplied object isn't Part::AttachableObject"); + App::DocumentObjectPy* dobjpy = static_cast(obj); + App::DocumentObject* dobj = dobjpy->getDocumentObjectPtr(); + if (! dobj->hasExtension(Part::AttachExtension::getExtensionClassTypeId())){ + throw Py::TypeError("Supplied object has no Part::AttachExtension"); } - const Part::AttachableObject* feat = static_cast(dobj); + Part::AttachExtension* feat = dobj->getExtensionByType(); AttachEngine &attacher = *(this->getAttachEnginePtr()); attacher.setUp(feat->Support, eMapMode(feat->MapMode.getValue()), @@ -519,10 +519,10 @@ PyObject* AttachEnginePy::writeParametersToFeature(PyObject* args) try{ App::DocumentObjectPy* dobjpy = static_cast(obj); App::DocumentObject* dobj = dobjpy->getDocumentObjectPtr(); - if (! dobj->isDerivedFrom(Part::AttachableObject::getClassTypeId())){ - throw Py::TypeError("Supplied object isn't Part::AttachableObject"); + if (! dobj->hasExtension(Part::AttachExtension::getExtensionClassTypeId())){ + throw Py::TypeError("Supplied object has no Part::AttachExtension"); } - Part::AttachableObject* feat = static_cast(dobj); + Part::AttachExtension* feat = dobj->getExtensionByType(); const AttachEngine &attacher = *(this->getAttachEnginePtr()); AttachEngine::verifyReferencesAreSafe(attacher.references); feat->Support.Paste(attacher.references); diff --git a/src/Mod/Part/App/AttachableObject.cpp b/src/Mod/Part/App/AttachExtension.cpp similarity index 89% rename from src/Mod/Part/App/AttachableObject.cpp rename to src/Mod/Part/App/AttachExtension.cpp index 30629db3c..f7b9cb542 100644 --- a/src/Mod/Part/App/AttachableObject.cpp +++ b/src/Mod/Part/App/AttachExtension.cpp @@ -25,19 +25,19 @@ #ifndef _PreComp_ #endif -#include "AttachableObject.h" +#include "AttachExtension.h" #include #include #include -#include "AttachableObjecty.h" +#include "AttachExtensionPy.h" using namespace Part; using namespace Attacher; -EXTENSION_PROPERTY_SOURCE(Part::AttachExtension, Part::Feature); +EXTENSION_PROPERTY_SOURCE(Part::AttachExtension, App::DocumentObjectExtension); AttachExtension::AttachExtension() : _attacher(0) @@ -126,10 +126,17 @@ bool AttachExtension::positionBySupport() }; } -App::DocumentObjectExecReturn *AttachExtension::exttensionExecute() +short int AttachExtension::extensionMustExecute(void) { + return DocumentObjectExtension::extensionMustExecute(); +} + + +App::DocumentObjectExecReturn *AttachExtension::extensionExecute() { + Base::Console().Message("Execute Extension"); if(this->isTouched_Mapping()) { try{ + Base::Console().Message("Call position by support"); positionBySupport(); } catch (Base::Exception &e) { return new App::DocumentObjectExecReturn(e.what()); @@ -153,11 +160,11 @@ void AttachExtension::extensionOnChanged(const App::Property* prop) try{ bAttached = positionBySupport(); } catch (Base::Exception &e) { - this->setError(); + getExtendedObject()->setStatus(App::Error, true); Base::Console().Error("PositionBySupport: %s",e.what()); //set error message - how? } catch (Standard_Failure &e){ - this->setError(); + getExtendedObject()->setStatus(App::Error, true); Base::Console().Error("PositionBySupport: %s",e.GetMessageString()); } @@ -195,23 +202,22 @@ App::PropertyPlacement& AttachExtension::getPlacement() { return static_cast(getExtendedObject())->Placement; } +PyObject* AttachExtension::getExtensionPyObject(void) { + + if (ExtensionPythonObject.is(Py::_None())){ + // ref counter is set to 1 + ExtensionPythonObject = Py::Object(new AttachExtensionPy(this),true); + } + return Py::new_reference_to(ExtensionPythonObject); +} + namespace App { /// @cond DOXERR EXTENSION_PROPERTY_SOURCE_TEMPLATE(Part::AttachExtensionPython, Part::AttachExtension) - template<> const char* Part::AttachExtensionPython::getViewProviderName(void) const { - return "PartGui::ViewProviderPython"; - } - template<> PyObject* Part::AttachExtensionPython::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 PartExport FeaturePythonT; + template class PartExport ExtensionPythonT; } diff --git a/src/Mod/Part/App/AttachableObject.h b/src/Mod/Part/App/AttachExtension.h similarity index 94% rename from src/Mod/Part/App/AttachableObject.h rename to src/Mod/Part/App/AttachExtension.h index 3f883134a..c340c8f7a 100644 --- a/src/Mod/Part/App/AttachableObject.h +++ b/src/Mod/Part/App/AttachExtension.h @@ -21,7 +21,7 @@ * * ***************************************************************************/ /** - * AttachableObject.h, .cpp contain a class to derive other features from, to make + * AttachExtensionh, .cpp contain a extension class to derive other features from, to make * them attachable. */ @@ -100,7 +100,9 @@ public: virtual bool isTouched_Mapping() {return true; /*support.isTouched isn't true when linked objects are changed... why?..*/}; - App::DocumentObjectExecReturn *extensionExecute(void); + virtual short int extensionMustExecute(void); + virtual App::DocumentObjectExecReturn *extensionExecute(void); + virtual PyObject* getExtensionPyObject(void); protected: virtual void extensionOnChanged(const App::Property* /*prop*/); diff --git a/src/Mod/Part/App/AttachableObjectPy.xml b/src/Mod/Part/App/AttachExtensionPy.xml similarity index 83% rename from src/Mod/Part/App/AttachableObjectPy.xml rename to src/Mod/Part/App/AttachExtensionPy.xml index d9514a901..df5f91dd3 100644 --- a/src/Mod/Part/App/AttachableObjectPy.xml +++ b/src/Mod/Part/App/AttachExtensionPy.xml @@ -1,15 +1,14 @@  + FatherInclude="App/DocumentObjectExtensionPy.h" + FatherNamespace="App"> This object represents an attachable object with OCC shape. diff --git a/src/Mod/Part/App/AttachableObjectPyImp.cpp b/src/Mod/Part/App/AttachExtensionPyImp.cpp similarity index 65% rename from src/Mod/Part/App/AttachableObjectPyImp.cpp rename to src/Mod/Part/App/AttachExtensionPyImp.cpp index aa45e065b..3740c5991 100644 --- a/src/Mod/Part/App/AttachableObjectPyImp.cpp +++ b/src/Mod/Part/App/AttachExtensionPyImp.cpp @@ -1,30 +1,30 @@ #include "PreCompiled.h" -#include "Mod/Part/App/AttachableObject.h" +#include "Mod/Part/App/AttachExtension.h" #include "OCCError.h" #include "AttachEnginePy.h" -// inclusion of the generated files (generated out of AttachableObjectPy.xml) -#include "AttachableObjectPy.h" -#include "AttachableObjectPy.cpp" +// inclusion of the generated files (generated out of AttachExtensionPy.xml) +#include "AttachExtensionPy.h" +#include "AttachExtensionPy.cpp" using namespace Part; // returns a string which represents the object e.g. when printed in python -std::string AttachableObjectPy::representation(void) const +std::string AttachExtensionPy::representation(void) const { return std::string(""); } -PyObject* AttachableObjectPy::positionBySupport(PyObject *args) +PyObject* AttachExtensionPy::positionBySupport(PyObject *args) { if (!PyArg_ParseTuple(args, "")) return 0; bool bAttached = false; try{ - bAttached = this->getAttachableObjectPtr()->positionBySupport(); + bAttached = this->getAttachExtensionPtr()->positionBySupport(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); @@ -36,14 +36,14 @@ PyObject* AttachableObjectPy::positionBySupport(PyObject *args) return Py::new_reference_to(Py::Boolean(bAttached)); } -PyObject* AttachableObjectPy::changeAttacherType(PyObject *args) +PyObject* AttachExtensionPy::changeAttacherType(PyObject *args) { const char* typeName; if (!PyArg_ParseTuple(args, "s", &typeName)) return 0; bool ret; try{ - ret = this->getAttachableObjectPtr()->changeAttacherType(typeName); + ret = this->getAttachExtensionPtr()->changeAttacherType(typeName); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); PyErr_SetString(PartExceptionOCCError, e->GetMessageString()); @@ -55,16 +55,16 @@ PyObject* AttachableObjectPy::changeAttacherType(PyObject *args) return Py::new_reference_to(Py::Boolean(ret)); } -Py::Object AttachableObjectPy::getAttacher(void) const +Py::Object AttachExtensionPy::getAttacher(void) const { try { - this->getAttachableObjectPtr()->attacher(); //throws if attacher is not set + this->getAttachExtensionPtr()->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); + return Py::Object( new Attacher::AttachEnginePy(this->getAttachExtensionPtr()->attacher().copy()), true); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); throw Py::Exception(Part::PartExceptionOCCError, e->GetMessageString()); @@ -74,12 +74,12 @@ Py::Object AttachableObjectPy::getAttacher(void) const } -PyObject *AttachableObjectPy::getCustomAttributes(const char* /*attr*/) const +PyObject *AttachExtensionPy::getCustomAttributes(const char* /*attr*/) const { return 0; } -int AttachableObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) +int AttachExtensionPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) { return 0; } diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 7623c2b91..6d9217e7e 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -73,7 +73,7 @@ generate_from_xml(RectangularTrimmedSurfacePy) generate_from_xml(SurfaceOfExtrusionPy) generate_from_xml(SurfaceOfRevolutionPy) generate_from_xml(PartFeaturePy) -generate_from_xml(AttachableObjectPy) +generate_from_xml(AttachExtensionPy) generate_from_xml(Part2DObjectPy) generate_from_xml(AttachEnginePy) generate_from_xml(TopoShapePy) @@ -169,8 +169,8 @@ SET(Features_SRCS BodyBase.cpp DatumFeature.cpp DatumFeature.h - AttachableObject.h - AttachableObject.cpp + AttachExtension.h + AttachExtension.cpp ) SOURCE_GROUP("Features" FILES ${Features_SRCS}) @@ -251,8 +251,8 @@ SET(Python_SRCS SurfaceOfRevolutionPyImp.cpp PartFeaturePy.xml PartFeaturePyImp.cpp - AttachableObjectPy.xml - AttachableObjectPyImp.cpp + AttachExtensionPy.xml + AttachExtensionPyImp.cpp Part2DObjectPy.xml Part2DObjectPyImp.cpp AttachEnginePy.xml diff --git a/src/Mod/Part/App/DatumFeature.cpp b/src/Mod/Part/App/DatumFeature.cpp index e907ae8d7..bdb62317c 100644 --- a/src/Mod/Part/App/DatumFeature.cpp +++ b/src/Mod/Part/App/DatumFeature.cpp @@ -32,10 +32,11 @@ using namespace Part; using namespace Attacher; -PROPERTY_SOURCE_ABSTRACT(Part::Datum, Part::AttachableObject) +PROPERTY_SOURCE_ABSTRACT_WITH_EXTENSIONS(Part::Datum, Part::Feature) Datum::Datum(void) { + AttachExtension::initExtension(this); touch(); } @@ -47,7 +48,7 @@ void Datum::onDocumentRestored() { // This seems to be the only way to make the ViewProvider display the datum feature Support.touch(); - AttachableObject::onDocumentRestored(); + Part::Feature::onDocumentRestored(); } TopoDS_Shape Datum::getShape() const diff --git a/src/Mod/Part/App/DatumFeature.h b/src/Mod/Part/App/DatumFeature.h index 916d23f4c..30f5162cf 100644 --- a/src/Mod/Part/App/DatumFeature.h +++ b/src/Mod/Part/App/DatumFeature.h @@ -28,7 +28,7 @@ #include #include "PartFeature.h" -#include "AttachableObject.h" +#include "AttachExtension.h" namespace Part { @@ -36,9 +36,9 @@ namespace Part // This generic class is defined here so that the Sketcher module can access datum features // without creating a dependency on PartDesign -class PartExport Datum : public Part::AttachableObject +class PartExport Datum : public Part::Feature, public Part::AttachExtension { - PROPERTY_HEADER(Part::Datum); + PROPERTY_HEADER_WITH_EXTENSIONS(Part::Datum); public: Datum(); diff --git a/src/Mod/Part/App/Part2DObject.cpp b/src/Mod/Part/App/Part2DObject.cpp index e5858a253..2df617c1f 100644 --- a/src/Mod/Part/App/Part2DObject.cpp +++ b/src/Mod/Part/App/Part2DObject.cpp @@ -62,18 +62,19 @@ const int Part2DObject::H_Axis = -1; const int Part2DObject::V_Axis = -2; const int Part2DObject::N_Axis = -3; -PROPERTY_SOURCE(Part::Part2DObject, Part::AttachableObject) +PROPERTY_SOURCE_WITH_EXTENSIONS(Part::Part2DObject, Part::Feature) Part2DObject::Part2DObject() { + AttachExtension::initExtension(this); this->setAttacher(new Attacher::AttachEnginePlane); } App::DocumentObjectExecReturn *Part2DObject::execute(void) { - return AttachableObject::execute(); + return Feature::execute(); } void Part2DObject::transformPlacement(const Base::Placement &transform) diff --git a/src/Mod/Part/App/Part2DObject.h b/src/Mod/Part/App/Part2DObject.h index 9041ebb97..c4d19dacf 100644 --- a/src/Mod/Part/App/Part2DObject.h +++ b/src/Mod/Part/App/Part2DObject.h @@ -29,7 +29,7 @@ #include #include "PartFeature.h" -#include "AttachableObject.h" +#include "AttachExtension.h" class TopoDS_Face; @@ -50,9 +50,9 @@ class Geometry; * geometry as its descend Sketcher::SketchObject . */ -class PartExport Part2DObject : public Part::AttachableObject +class PartExport Part2DObject : public Part::Feature, public Part::AttachExtension { - PROPERTY_HEADER(Part::Part2DObject); + PROPERTY_HEADER_WITH_EXTENSIONS(Part::Part2DObject); public: Part2DObject(); diff --git a/src/Mod/Part/App/Part2DObjectPy.xml b/src/Mod/Part/App/Part2DObjectPy.xml index 299bcd84d..231276087 100644 --- a/src/Mod/Part/App/Part2DObjectPy.xml +++ b/src/Mod/Part/App/Part2DObjectPy.xml @@ -1,13 +1,13 @@  diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index 2485dcaaf..203493582 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -93,7 +93,7 @@ App::DocumentObjectExecReturn *Feature::recompute(void) App::DocumentObjectExecReturn *Feature::execute(void) { this->Shape.touch(); - return App::DocumentObject::StdReturn; + return GeoFeature::execute(); } PyObject *Feature::getPyObject(void) diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 9170e4c3b..fef056f72 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -84,10 +84,11 @@ namespace Part { using namespace Part; -PROPERTY_SOURCE_ABSTRACT(Part::Primitive, Part::AttachableObject) +PROPERTY_SOURCE_ABSTRACT_WITH_EXTENSIONS(Part::Primitive, Part::Feature) Primitive::Primitive(void) { + AttachExtension::initExtension(this); touch(); } @@ -100,6 +101,11 @@ short Primitive::mustExecute(void) const return Feature::mustExecute(); } +App::DocumentObjectExecReturn* Primitive::execute(void) { + return Part::Feature::execute(); +} + + void Primitive::Restore(Base::XMLReader &reader) { reader.readElement("Properties"); @@ -169,7 +175,7 @@ void Primitive::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Feature::onChanged(prop); } PROPERTY_SOURCE(Part::Vertex, Part::Primitive) @@ -191,7 +197,7 @@ short Vertex::mustExecute() const Y.isTouched() || Z.isTouched()) return 1; - return Part::AttachableObject::mustExecute(); + return Part::Primitive::mustExecute(); } App::DocumentObjectExecReturn *Vertex::execute(void) @@ -205,7 +211,7 @@ App::DocumentObjectExecReturn *Vertex::execute(void) const TopoDS_Vertex& vertex = MakeVertex.Vertex(); this->Shape.setValue(vertex); - return AttachableObject::execute(); + return Primitive::execute(); } @@ -221,7 +227,7 @@ void Vertex::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Primitive::onChanged(prop); } PROPERTY_SOURCE(Part::Line, Part::Primitive) @@ -249,7 +255,7 @@ short Line::mustExecute() const Y2.isTouched() || Z2.isTouched()) return 1; - return Part::AttachableObject::mustExecute(); + return Part::Primitive::mustExecute(); } App::DocumentObjectExecReturn *Line::execute(void) @@ -270,7 +276,7 @@ App::DocumentObjectExecReturn *Line::execute(void) const TopoDS_Edge& edge = mkEdge.Edge(); this->Shape.setValue(edge); - return AttachableObject::execute(); + return Primitive::execute(); } void Line::onChanged(const App::Property* prop) @@ -285,7 +291,7 @@ void Line::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Primitive::onChanged(prop); } PROPERTY_SOURCE(Part::Plane, Part::Primitive) @@ -356,7 +362,7 @@ App::DocumentObjectExecReturn *Plane::execute(void) TopoDS_Shape ResultShape = mkFace.Shape(); this->Shape.setValue(ResultShape); - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Sphere, Part::Primitive) @@ -404,7 +410,7 @@ App::DocumentObjectExecReturn *Sphere::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Ellipsoid, Part::Primitive) @@ -486,7 +492,7 @@ App::DocumentObjectExecReturn *Ellipsoid::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Cylinder, Part::Primitive) @@ -529,7 +535,7 @@ App::DocumentObjectExecReturn *Cylinder::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } App::PropertyIntegerConstraint::Constraints Prism::polygonRange = {3,INT_MAX,1}; @@ -587,7 +593,7 @@ App::DocumentObjectExecReturn *Prism::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } App::PropertyIntegerConstraint::Constraints RegularPolygon::polygon = {3,INT_MAX,1}; @@ -639,7 +645,7 @@ App::DocumentObjectExecReturn *RegularPolygon::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } @@ -689,7 +695,7 @@ App::DocumentObjectExecReturn *Cone::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Torus, Part::Primitive) @@ -761,7 +767,7 @@ App::DocumentObjectExecReturn *Torus::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Helix, Part::Primitive) @@ -798,7 +804,7 @@ void Helix::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Primitive::onChanged(prop); } short Helix::mustExecute() const @@ -842,7 +848,7 @@ App::DocumentObjectExecReturn *Helix::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Spiral, Part::Primitive) @@ -869,7 +875,7 @@ void Spiral::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Primitive::onChanged(prop); } short Spiral::mustExecute() const @@ -933,7 +939,7 @@ App::DocumentObjectExecReturn *Spiral::execute(void) BRepProj_Projection proj(wire, mkFace.Face(), gp::DZ()); this->Shape.setValue(proj.Shape()); - AttachableObject::execute(); + Primitive::execute(); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); @@ -942,7 +948,7 @@ App::DocumentObjectExecReturn *Spiral::execute(void) - return AttachableObject::execute(); + return Primitive::execute(); } PROPERTY_SOURCE(Part::Wedge, Part::Primitive) @@ -1027,7 +1033,7 @@ App::DocumentObjectExecReturn *Wedge::execute(void) return new App::DocumentObjectExecReturn(e->GetMessageString()); } - return AttachableObject::execute(); + return Primitive::execute(); } void Wedge::onChanged(const App::Property* prop) @@ -1070,7 +1076,7 @@ short Ellipse::mustExecute() const MajorRadius.isTouched() || MinorRadius.isTouched()) return 1; - return Part::AttachableObject::mustExecute(); + return Part::Primitive::mustExecute(); } App::DocumentObjectExecReturn *Ellipse::execute(void) @@ -1084,7 +1090,7 @@ App::DocumentObjectExecReturn *Ellipse::execute(void) const TopoDS_Edge& edge = clMakeEdge.Edge(); this->Shape.setValue(edge); - return AttachableObject::execute(); + return Primitive::execute(); } void Ellipse::onChanged(const App::Property* prop) @@ -1099,5 +1105,5 @@ void Ellipse::onChanged(const App::Property* prop) } } } - Part::AttachableObject::onChanged(prop); + Part::Primitive::onChanged(prop); } diff --git a/src/Mod/Part/App/PrimitiveFeature.h b/src/Mod/Part/App/PrimitiveFeature.h index 6a7848373..f430b1d62 100644 --- a/src/Mod/Part/App/PrimitiveFeature.h +++ b/src/Mod/Part/App/PrimitiveFeature.h @@ -26,14 +26,14 @@ #include #include "PartFeature.h" -#include "AttachableObject.h" +#include "AttachExtension.h" namespace Part { -class PartExport Primitive : public Part::AttachableObject +class PartExport Primitive : public Part::Feature, public Part::AttachExtension { - PROPERTY_HEADER(Part::Primitive); + PROPERTY_HEADER_WITH_EXTENSIONS(Part::Primitive); public: Primitive(); @@ -42,7 +42,7 @@ public: /** @name methods override feature */ //@{ /// recalculate the feature - App::DocumentObjectExecReturn *execute(void) = 0; + App::DocumentObjectExecReturn *execute(void); short mustExecute() const; //@} diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index b3aceeb28..5cf7f4af6 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -112,7 +112,7 @@ void UnifiedDatumCommand(Gui::Command &cmd, Base::Type type, std::string name) //test if current selection fits a mode. if (support.getSize() > 0) { - Part::AttachableObject* pcDatum = static_cast(cmd.getDocument()->getObject(FeatName.c_str())); + Part::AttachExtension* pcDatum = cmd.getDocument()->getObject(FeatName.c_str())->getExtensionByType(); pcDatum->attacher().references.Paste(support); SuggestResult sugr; pcDatum->attacher().suggestMapModes(sugr); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index ee97e0811..c65861c4c 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -394,8 +394,8 @@ bool isFeatureMovable(App::DocumentObject* const feat) } - if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { - auto attachable = static_cast(feat); + if (feat->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) { + auto attachable = feat->getExtensionByType(); App::DocumentObject* support = attachable->Support.getValue(); if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) return false; @@ -460,8 +460,8 @@ std::vector collectMovableDependencies(std::vectorgetTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { - auto attachable = static_cast(feat); + if (feat->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) { + auto attachable = feat->getExtensionByType(); App::DocumentObject* support = attachable->Support.getValue(); if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) { auto originfeat = static_cast(support);