mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Fix #5358. Easy way to toggle visibility of spatial elements and grids.
This commit is contained in:
@@ -40,6 +40,8 @@ classes = (
|
||||
operator.SetContainerVisibility,
|
||||
operator.SetDefaultContainer,
|
||||
operator.ToggleContainerElement,
|
||||
operator.ToggleGrids,
|
||||
operator.ToggleSpatialElements,
|
||||
prop.Element,
|
||||
prop.BIMObjectSpatialProperties,
|
||||
prop.BIMContainer,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user