From 5ddefe56fb6f736ed52b78b83474c41120ac6bdb Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 9 Dec 2021 12:33:09 +0100 Subject: [PATCH] PD: 0004699: ShapeBinder still touched after recompute --- src/Mod/PartDesign/App/ShapeBinder.cpp | 70 +++++++++++++++++--------- src/Mod/PartDesign/App/ShapeBinder.h | 6 ++- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/Mod/PartDesign/App/ShapeBinder.cpp b/src/Mod/PartDesign/App/ShapeBinder.cpp index 64d33f19e6..6153626f66 100644 --- a/src/Mod/PartDesign/App/ShapeBinder.cpp +++ b/src/Mod/PartDesign/App/ShapeBinder.cpp @@ -70,6 +70,11 @@ ShapeBinder::~ShapeBinder() this->connectDocumentChangedObject.disconnect(); } +void ShapeBinder::onChanged(const App::Property* prop) +{ + Feature::onChanged(prop); +} + short int ShapeBinder::mustExecute(void) const { if (Support.isTouched()) @@ -80,29 +85,45 @@ short int ShapeBinder::mustExecute(void) const { return Part::Feature::mustExecute(); } +Part::TopoShape ShapeBinder::updatedShape() const +{ + Part::TopoShape shape; + App::GeoFeature* obj = nullptr; + std::vector subs; + + ShapeBinder::getFilteredReferences(&Support, obj, subs); + + //if we have a link we rebuild the shape, but we change nothing if we are a simple copy + if (obj) { + shape = ShapeBinder::buildShapeFromReferences(obj, subs); + //now, shape is in object's CS, and includes local Placement of obj but nothing else. + + if (TraceSupport.getValue()) { + //compute the transform, and apply it to the shape. + Base::Placement sourceCS = //full placement of container of obj + obj->globalPlacement() * obj->Placement.getValue().inverse(); + Base::Placement targetCS = //full placement of container of this shapebinder + this->globalPlacement() * this->Placement.getValue().inverse(); + Base::Placement transform = targetCS.inverse() * sourceCS; + shape.setPlacement(transform * shape.getPlacement()); + } + } + + return shape; +} + +bool ShapeBinder::hasPlacementChanged() const +{ + Part::TopoShape shape(updatedShape()); + Base::Placement placement(shape.getTransform()); + return this->Placement.getValue() != placement; +} + App::DocumentObjectExecReturn* ShapeBinder::execute(void) { if (!this->isRestoring()) { - App::GeoFeature* obj = nullptr; - std::vector subs; - - ShapeBinder::getFilteredReferences(&Support, obj, subs); - - //if we have a link we rebuild the shape, but we change nothing if we are a simple copy - if (obj) { - Part::TopoShape shape(ShapeBinder::buildShapeFromReferences(obj, subs)); - //now, shape is in object's CS, and includes local Placement of obj but nothing else. - - if (TraceSupport.getValue()) { - //compute the transform, and apply it to the shape. - Base::Placement sourceCS = //full placement of container of obj - obj->globalPlacement() * obj->Placement.getValue().inverse(); - Base::Placement targetCS = //full placement of container of this shapebinder - this->globalPlacement() * this->Placement.getValue().inverse(); - Base::Placement transform = targetCS.inverse() * sourceCS; - shape.setPlacement(transform * shape.getPlacement()); - } - + Part::TopoShape shape(updatedShape()); + if (!shape.isNull()) { this->Placement.setValue(shape.getTransform()); this->Shape.setValue(shape); } @@ -111,7 +132,8 @@ App::DocumentObjectExecReturn* ShapeBinder::execute(void) { return Part::Feature::execute(); } -void ShapeBinder::getFilteredReferences(App::PropertyLinkSubList* prop, App::GeoFeature*& obj, +void ShapeBinder::getFilteredReferences(const App::PropertyLinkSubList* prop, + App::GeoFeature*& obj, std::vector< std::string >& subobjects) { obj = nullptr; @@ -256,7 +278,8 @@ void ShapeBinder::slotChangedObject(const App::DocumentObject& Obj, const App::P if (obj) { if (obj == &Obj) { // the directly referenced object has changed - enforceRecompute(); + if (hasPlacementChanged()) + enforceRecompute(); } else if (Obj.hasExtension(App::GroupExtension::getExtensionClassTypeId())) { // check if the changed property belongs to a group-like object @@ -269,7 +292,8 @@ void ShapeBinder::slotChangedObject(const App::DocumentObject& Obj, const App::P auto it = std::find(chain.begin(), chain.end(), &Obj); if (it != chain.end()) { - enforceRecompute(); + if (hasPlacementChanged()) + enforceRecompute(); } } } diff --git a/src/Mod/PartDesign/App/ShapeBinder.h b/src/Mod/PartDesign/App/ShapeBinder.h index ba7c548cd4..01500701fe 100644 --- a/src/Mod/PartDesign/App/ShapeBinder.h +++ b/src/Mod/PartDesign/App/ShapeBinder.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace PartDesign { @@ -51,7 +52,7 @@ public: App::PropertyLinkSubListGlobal Support; App::PropertyBool TraceSupport; - static void getFilteredReferences(App::PropertyLinkSubList* prop, App::GeoFeature*& object, std::vector< std::string >& subobjects); + static void getFilteredReferences(const App::PropertyLinkSubList* prop, App::GeoFeature*& object, std::vector< std::string >& subobjects); static Part::TopoShape buildShapeFromReferences(App::GeoFeature* obj, std::vector< std::string > subs); const char* getViewProviderName(void) const override { @@ -59,9 +60,12 @@ public: } protected: + Part::TopoShape updatedShape() const; + bool hasPlacementChanged() const; virtual void handleChangedPropertyType(Base::XMLReader &reader, const char * TypeName, App::Property * prop) override; virtual short int mustExecute(void) const override; virtual App::DocumentObjectExecReturn* execute(void) override; + virtual void onChanged(const App::Property* prop) override; private: void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop);