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
This commit is contained in:
tetektoza
2025-12-30 18:22:37 +01:00
committed by GitHub
parent e9ea3d0d25
commit df25bd3cdb

View File

@@ -26,6 +26,7 @@
#include <TopExp.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <QMessageBox>
#include <algorithm>
#include <App/Document.h>
#include <Gui/Application.h>
@@ -94,7 +95,23 @@ bool ViewProviderCompound::onDelete(const std::vector<std::string>& subNames)
}
for (auto pLink : pLinks) {
if (pLink) {
if (!pLink) {
continue;
}
bool hasOtherParent = false;
for (auto parent : pLink->getInList()) {
if (parent && parent != pComp && parent->isDerivedFrom<Part::Compound>()) {
auto otherCompound = static_cast<Part::Compound*>(parent);
auto otherLinks = otherCompound->Links.getValues();
if (std::ranges::find(otherLinks, pLink) != otherLinks.end()) {
hasOtherParent = true;
break;
}
}
}
if (!hasOtherParent) {
Gui::Application::Instance->showViewProvider(pLink);
}
}