Assembly: Sub-assembly: fix support for Part-wb objects (#25279)

* Assembly: Sub-assembly: fix support for Part-wb objects

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
PaddleStroke
2025-11-17 17:59:40 +01:00
committed by GitHub
parent 287ac6e9e9
commit e3311825d2

View File

@@ -252,8 +252,41 @@ void AssemblyLink::synchronizeComponents()
std::vector<App::DocumentObject*> assemblyGroup = assembly->Group.getValues();
std::vector<App::DocumentObject*> assemblyLinkGroup = Group.getValues();
// We check if a component needs to be added to the AssemblyLink
// Filter out child objects from Part-workbench features to get only top-level components.
// An object is considered a child if it's referenced by another object's 'Base', 'Tool',
// or 'Shapes' property within the same group.
std::set<App::DocumentObject*> children;
for (auto* obj : assemblyGroup) {
if (auto* partFeat = dynamic_cast<PartApp::Feature*>(obj)) {
if (auto* prop = dynamic_cast<App::PropertyLink*>(partFeat->getPropertyByName("Base"))) {
if (prop->getValue()) {
children.insert(prop->getValue());
}
}
if (auto* prop = dynamic_cast<App::PropertyLink*>(partFeat->getPropertyByName("Tool"))) {
if (prop->getValue()) {
children.insert(prop->getValue());
}
}
if (auto* prop
= dynamic_cast<App::PropertyLinkList*>(partFeat->getPropertyByName("Shapes"))) {
for (auto* shapeObj : prop->getValues()) {
children.insert(shapeObj);
}
}
}
}
std::vector<App::DocumentObject*> topLevelComponents;
std::copy_if(
assemblyGroup.begin(),
assemblyGroup.end(),
std::back_inserter(topLevelComponents),
[&children](App::DocumentObject* obj) { return children.find(obj) == children.end(); }
);
// We check if a component needs to be added to the AssemblyLink
for (auto* obj : topLevelComponents) {
if (!obj->isDerivedFrom<App::Part>() && !obj->isDerivedFrom<PartApp::Feature>()
&& !obj->isDerivedFrom<App::Link>()) {
continue;