From d7c90d3f77c9929f599230efdfea9a4d20ca77b0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 14 May 2023 11:12:49 +0200 Subject: [PATCH] PD: fix out of scope warnings of Clone feature If the BaseFeature link of the Body of a Clone feature isn't set then do not update it. Forum thread: https://forum.freecad.org/viewtopic.php?p=675644#p675644 --- src/Mod/PartDesign/App/FeatureBase.cpp | 20 ++++++++++++-------- src/Mod/PartDesign/App/FeatureBase.h | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureBase.cpp b/src/Mod/PartDesign/App/FeatureBase.cpp index 06306141f6..d7fc21cb66 100644 --- a/src/Mod/PartDesign/App/FeatureBase.cpp +++ b/src/Mod/PartDesign/App/FeatureBase.cpp @@ -73,18 +73,22 @@ App::DocumentObjectExecReturn* FeatureBase::execute() { return StdReturn; } +void FeatureBase::trySetBaseFeatureOfBody() +{ + if (auto body = getFeatureBody()) { + if (BaseFeature.getValue() + && body->BaseFeature.getValue() + && body->BaseFeature.getValue() != BaseFeature.getValue()) { + body->BaseFeature.setValue(BaseFeature.getValue()); + } + } +} + void FeatureBase::onChanged(const App::Property* prop) { // the BaseFeature property should track the Body BaseFeature and vice-versa if (prop == &BaseFeature) { - - auto body = getFeatureBody(); - if(!body) - return; - - if (BaseFeature.getValue() && body->BaseFeature.getValue() != BaseFeature.getValue()) { - body->BaseFeature.setValue(BaseFeature.getValue()); - } + trySetBaseFeatureOfBody(); } Part::Feature::onChanged(prop); diff --git a/src/Mod/PartDesign/App/FeatureBase.h b/src/Mod/PartDesign/App/FeatureBase.h index 28812af885..4be140d44d 100644 --- a/src/Mod/PartDesign/App/FeatureBase.h +++ b/src/Mod/PartDesign/App/FeatureBase.h @@ -48,6 +48,9 @@ public: void onChanged(const App::Property* prop) override; App::DocumentObjectExecReturn* execute() override; void onDocumentRestored() override; + +private: + void trySetBaseFeatureOfBody(); }; } //namespace PartDesign