From e4bb7a98e2172bdf07a1af7e5df6f668efdaf48b Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 5 Feb 2024 11:00:38 +0000 Subject: [PATCH] [Arch] [Draft] Add guard for RootNode specific child --- src/Mod/Arch/ArchProject.py | 11 ++--- src/Mod/Arch/ArchSite.py | 41 ++++++++++--------- .../Draft/draftguitools/gui_subelements.py | 7 ++-- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/Mod/Arch/ArchProject.py b/src/Mod/Arch/ArchProject.py index b364ed0ac2..78b247a9e0 100644 --- a/src/Mod/Arch/ArchProject.py +++ b/src/Mod/Arch/ArchProject.py @@ -210,11 +210,12 @@ class _ViewProviderProject(ArchIFCView.IfcContextView): """ if not hasattr(self, "displaymodes_cleaned"): - main_switch = vobj.RootNode.getChild(2) # The display mode switch. - if main_switch is not None and main_switch.getNumChildren() == 4: # Check if all display modes are available. - for node in tuple(main_switch.getChildren()): - node.removeAllChildren() - self.displaymodes_cleaned = True + if vobj.RootNode.getNumChildren() > 2: + main_switch = vobj.RootNode.getChild(2) # The display mode switch. + if main_switch is not None and main_switch.getNumChildren() == 4: # Check if all display modes are available. + for node in tuple(main_switch.getChildren()): + node.removeAllChildren() + self.displaymodes_cleaned = True def onChanged(self,vobj,prop): self.removeDisplaymodeChildNodes(vobj) diff --git a/src/Mod/Arch/ArchSite.py b/src/Mod/Arch/ArchSite.py index dc211e69f0..241c855df9 100644 --- a/src/Mod/Arch/ArchSite.py +++ b/src/Mod/Arch/ArchSite.py @@ -1038,26 +1038,27 @@ class _ViewProviderSite: """ if not hasattr(self, "terrain_switches"): - main_switch = vobj.RootNode.getChild(2) # The display mode switch. - if main_switch.getNumChildren() == 4: # Check if all display modes are available. - from pivy import coin - self.terrain_switches = [] - for node in tuple(main_switch.getChildren()): - new_switch = coin.SoSwitch() - sep1 = coin.SoSeparator() - sep1.setName("NoTerrain") - sep2 = coin.SoSeparator() - sep2.setName("Terrain") - child_list = list(node.getChildren()) - for child in child_list: - sep2.addChild(child) - new_switch.addChild(sep1) - new_switch.addChild(sep2) - new_switch.whichChild = 0 - node.addChild(new_switch) - for i in range(len(child_list)): - node.removeChild(0) # Remove the original children. - self.terrain_switches.append(new_switch) + if vobj.RootNode.getNumChildren() > 2: + main_switch = vobj.RootNode.getChild(2) # The display mode switch. + if main_switch.getNumChildren() == 4: # Check if all display modes are available. + from pivy import coin + self.terrain_switches = [] + for node in tuple(main_switch.getChildren()): + new_switch = coin.SoSwitch() + sep1 = coin.SoSeparator() + sep1.setName("NoTerrain") + sep2 = coin.SoSeparator() + sep2.setName("Terrain") + child_list = list(node.getChildren()) + for child in child_list: + sep2.addChild(child) + new_switch.addChild(sep1) + new_switch.addChild(sep2) + new_switch.whichChild = 0 + node.addChild(new_switch) + for i in range(len(child_list)): + node.removeChild(0) # Remove the original children. + self.terrain_switches.append(new_switch) def updateDisplaymodeTerrainSwitches(self,vobj): """Updates the 'terrain' switches.""" diff --git a/src/Mod/Draft/draftguitools/gui_subelements.py b/src/Mod/Draft/draftguitools/gui_subelements.py index d1a32f3d5d..6a217fb5fc 100644 --- a/src/Mod/Draft/draftguitools/gui_subelements.py +++ b/src/Mod/Draft/draftguitools/gui_subelements.py @@ -138,9 +138,10 @@ class SubelementHighlight(gui_base_original.Modifier): obj.ViewObject.PointColor = (1.0, 0.0, 0.0) obj.ViewObject.LineColor = (1.0, 0.0, 0.0) xray = coin.SoAnnotation() - xray.addChild(obj.ViewObject.RootNode.getChild(2).getChild(0)) - xray.setName("xray") - obj.ViewObject.RootNode.addChild(xray) + if obj.ViewObject.RootNode.getNumChildren() > 2: + xray.addChild(obj.ViewObject.RootNode.getChild(2).getChild(0)) + xray.setName("xray") + obj.ViewObject.RootNode.addChild(xray) def restore_editable_objects_graphics(self): """Restore the editable objects' appearance."""