diff --git a/src/bonsai/bonsai/bim/module/spatial/__init__.py b/src/bonsai/bonsai/bim/module/spatial/__init__.py index 4a30a1f2ab..97c49ab90f 100644 --- a/src/bonsai/bonsai/bim/module/spatial/__init__.py +++ b/src/bonsai/bonsai/bim/module/spatial/__init__.py @@ -40,6 +40,8 @@ classes = ( operator.SetContainerVisibility, operator.SetDefaultContainer, operator.ToggleContainerElement, + operator.ToggleGrids, + operator.ToggleSpatialElements, prop.Element, prop.BIMObjectSpatialProperties, prop.BIMContainer, diff --git a/src/bonsai/bonsai/bim/module/spatial/decorator.py b/src/bonsai/bonsai/bim/module/spatial/decorator.py index 5c48f87e8b..c6983e073c 100644 --- a/src/bonsai/bonsai/bim/module/spatial/decorator.py +++ b/src/bonsai/bonsai/bim/module/spatial/decorator.py @@ -65,7 +65,7 @@ class GridDecorator: blf.enable(font_id, blf.SHADOW) for axis in context.scene.BIMGridProperties.grid_axes: - if not (obj := axis.obj): + if not (obj := axis.obj) or obj.hide_get() == True: continue if obj.select_get() and context.mode != "OBJECT": continue @@ -112,11 +112,10 @@ class GridDecorator: selected_verts = [] selected_edges = [] - selected_tags = [] unselected_verts = [] unselected_edges = [] for axis in context.scene.BIMGridProperties.grid_axes: - if obj := axis.obj: + if (obj := axis.obj) and obj.hide_get() == False: if obj.select_get(): if context.mode != "OBJECT": continue @@ -132,8 +131,8 @@ class GridDecorator: v2 = matrix_world @ obj.data.vertices[1].co verts.extend([v1, v2]) - if selected_verts: - self.draw_batch("LINES", selected_verts, selected_elements_color, selected_edges) - if unselected_verts: self.draw_batch("LINES", unselected_verts, unselected_elements_color, unselected_edges) + + if selected_verts: + self.draw_batch("LINES", selected_verts, selected_elements_color, selected_edges) diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index 5ce3032555..5352ff144c 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -404,3 +404,33 @@ class SetContainerVisibility(bpy.types.Operator, tool.Ifc.Operator): collection.hide_viewport = should_hide if self.should_include_children: queue.extend(ifcopenshell.util.element.get_parts(container)) + + +class ToggleGrids(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.toggle_grids" + bl_label = "Toggle Grids" + bl_options = {"REGISTER", "UNDO"} + bl_description = "Show or hide grids and grid axes" + is_visible: bpy.props.BoolProperty(name="Is Visible", default=False, options={"SKIP_SAVE"}) + + def _execute(self, context): + for element in (tool.Ifc.get().by_type("IfcGrid") + tool.Ifc.get().by_type("IfcGridAxis")): + if obj := tool.Ifc.get_object(element): + obj.hide_set(not self.is_visible) + + +class ToggleSpatialElements(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.toggle_spatial_elements" + bl_label = "Toggle Spatial Elements" + bl_options = {"REGISTER", "UNDO"} + bl_description = "Show or hide spatial elements, such as buildings, sites, etc" + is_visible: bpy.props.BoolProperty(name="Is Visible", default=False, options={"SKIP_SAVE"}) + + def _execute(self, context): + if tool.Ifc.get().schema == "IFC2X3": + elements = tool.Ifc.get().by_type("IfcSpatialStructureElement") + else: + elements = tool.Ifc.get().by_type("IfcSpatialElement") + for element in elements: + if obj := tool.Ifc.get_object(element): + obj.hide_set(not self.is_visible) diff --git a/src/bonsai/bonsai/bim/module/spatial/ui.py b/src/bonsai/bonsai/bim/module/spatial/ui.py index ded210ce6d..39e810ed8d 100644 --- a/src/bonsai/bonsai/bim/module/spatial/ui.py +++ b/src/bonsai/bonsai/bim/module/spatial/ui.py @@ -105,6 +105,8 @@ class BIM_PT_spatial_decomposition(Panel): def draw_header(self, context): row = self.layout.row(align=True) row.label(text="") # empty text occupies the left of the row + row.operator("bim.toggle_spatial_elements", text="", icon="HIDE_OFF").is_visible = True + row.operator("bim.toggle_spatial_elements", text="", icon="HIDE_ON").is_visible = False icon = "VIEW_LOCKED" if context.scene.BIMSpatialDecompositionProperties.is_locked else "VIEW_UNLOCKED" row.prop(context.scene.BIMSpatialDecompositionProperties, "is_locked", text="", icon=icon) @@ -218,6 +220,8 @@ class BIM_PT_grids(Panel): def draw_header(self, context): row = self.layout.row(align=True) row.label(text="") # empty text occupies the left of the row + row.operator("bim.toggle_grids", text="", icon="HIDE_OFF").is_visible = True + row.operator("bim.toggle_grids", text="", icon="HIDE_ON").is_visible = False icon = "VIEW_LOCKED" if context.scene.BIMGridProperties.is_locked else "VIEW_UNLOCKED" row.prop(context.scene.BIMGridProperties, "is_locked", text="", icon=icon)