From df25bd3cdbbf92c6ef43866bb7c1cd9a3dbf67e7 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Tue, 30 Dec 2025 18:22:37 +0100 Subject: [PATCH] Part: Preserve child visibility when deleting compound copies (#26509) * Part: Preserve child visibility when deleting compound copies Currently, if we have a FC document two compounds, when one of them is a copy of the other containing same children and we delete the copy compound to keep the children, their visibility state changes. The cause of that was a part of code in `onDelete()` method, which was unconditionally calling `showViewProvider()` on every child object, without checking if other compounds still claim those children or what the current visibility should be. So this patch adds parent-checking logic before changing visibility. The visibility is only updated if the child is truly orphaned. So in the scenario where we have the children referenced STILL by some compounds, the visibility remains unchanged. It only changes when child has truly no parents. * Part: Use std::ranges::find for finding parent --- src/Mod/Part/Gui/ViewProviderCompound.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Mod/Part/Gui/ViewProviderCompound.cpp b/src/Mod/Part/Gui/ViewProviderCompound.cpp index 3277fa6218..5008324949 100644 --- a/src/Mod/Part/Gui/ViewProviderCompound.cpp +++ b/src/Mod/Part/Gui/ViewProviderCompound.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -94,7 +95,23 @@ bool ViewProviderCompound::onDelete(const std::vector& subNames) } for (auto pLink : pLinks) { - if (pLink) { + if (!pLink) { + continue; + } + + bool hasOtherParent = false; + for (auto parent : pLink->getInList()) { + if (parent && parent != pComp && parent->isDerivedFrom()) { + auto otherCompound = static_cast(parent); + auto otherLinks = otherCompound->Links.getValues(); + if (std::ranges::find(otherLinks, pLink) != otherLinks.end()) { + hasOtherParent = true; + break; + } + } + } + + if (!hasOtherParent) { Gui::Application::Instance->showViewProvider(pLink); } }