From 0da05071a5b5609a183c2b838012aa8e981aa7d1 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Tue, 6 May 2025 20:47:07 +0200 Subject: [PATCH] BIM: Do not hide children of Building if Building has been isolated --- src/Mod/BIM/bimcommands/BimViews.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Mod/BIM/bimcommands/BimViews.py b/src/Mod/BIM/bimcommands/BimViews.py index e6eaa5e536..b62f99a13a 100644 --- a/src/Mod/BIM/bimcommands/BimViews.py +++ b/src/Mod/BIM/bimcommands/BimViews.py @@ -454,7 +454,16 @@ class BIM_Views: obj.ViewObject.Visibility = not (obj.ViewObject.Visibility) FreeCAD.ActiveDocument.recompute() + def _isAncestor(self, ancestor_item, child_item): + current = child_item.parent() + while current is not None: + if current == ancestor_item: + return True + current = current.parent() + return False + def isolate(self): + import Draft """ Isolate the currently selected items in the tree view. @@ -476,11 +485,22 @@ class BIM_Views: vm = findWidget() if vm: selectedItems = vm.tree.selectedItems() + checkAncestors = False + # We can get a scenario where user has just selected only Building + # so we don't want to hide any of it's children, so just check if that's + # the case so we will know whether we should process items further or not + if len(selectedItems) == 1: + toolTip = selectedItems[0].toolTip(0) + obj = FreeCAD.ActiveDocument.getObject(toolTip) + t = Draft.getType(obj) + if obj and getattr(obj, "IfcType", "") == "Building": + checkAncestors = True + for item in self.allItemsInTree: toolTip = item.toolTip(0) obj = FreeCAD.ActiveDocument.getObject(toolTip) if obj: - if item not in selectedItems: + if item not in selectedItems and not (checkAncestors and self._isAncestor(selectedItems[0], item)): obj.ViewObject.Visibility = False else: obj.ViewObject.Visibility = True