mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 14:23:53 +00:00
bbim bcf - fix issues setting visibility exceptions
1) bpy.ops.object.hide_view_set doesn't actually work with context provided selected objects - it's checking whether they're actually selected 2) bpy.ops.object.hide_view_clear wasn't using select=False, selecting revealed objects which might get in the way later. 3) used new api for getting visibility settings
This commit is contained in:
@@ -998,43 +998,46 @@ class ActivateBcfViewpoint(bpy.types.Operator):
|
|||||||
self.set_colours(viewpoint)
|
self.set_colours(viewpoint)
|
||||||
|
|
||||||
def set_exceptions(self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler, context: bpy.types.Context) -> None:
|
def set_exceptions(self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler, context: bpy.types.Context) -> None:
|
||||||
if not hasattr(viewpoint.visualization_info.components, "visibility") or not hasattr(
|
visibility_settings = viewpoint.get_elements_visibility()
|
||||||
viewpoint.visualization_info.components.visibility.exceptions, "component"
|
if visibility_settings is None:
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
exception_global_ids = {
|
default_visibility, exception_global_ids = visibility_settings
|
||||||
v.ifc_guid for v in viewpoint.visualization_info.components.visibility.exceptions.component or []
|
|
||||||
}
|
|
||||||
|
|
||||||
if viewpoint.visualization_info.components.visibility.default_visibility:
|
objs: list[bpy.types.Object] = []
|
||||||
|
for global_id in exception_global_ids:
|
||||||
|
obj = IfcStore.get_element(global_id)
|
||||||
|
if obj and context.view_layer.objects.get(obj.name):
|
||||||
|
assert isinstance(obj, bpy.types.Object)
|
||||||
|
objs.append(obj)
|
||||||
|
|
||||||
|
context_override = tool.Blender.get_viewport_context()
|
||||||
|
if default_visibility:
|
||||||
# default_visibility is True: show all objs, hide the exceptions
|
# default_visibility is True: show all objs, hide the exceptions
|
||||||
old = context.area.type
|
with context.temp_override(**context_override):
|
||||||
context.area.type = "VIEW_3D"
|
bpy.ops.object.hide_view_clear(select=False)
|
||||||
bpy.ops.object.hide_view_clear()
|
for obj in objs:
|
||||||
context.area.type = old
|
|
||||||
for global_id in exception_global_ids:
|
|
||||||
obj = IfcStore.get_element(global_id)
|
|
||||||
if obj and bpy.context.view_layer.objects.get(obj.name):
|
|
||||||
obj.hide_set(True)
|
obj.hide_set(True)
|
||||||
else:
|
else:
|
||||||
# default_visibility is False: hide all objs, show the exceptions
|
# default_visibility is False: hide all objs, show the exceptions
|
||||||
objs = []
|
with context.temp_override(**context_override):
|
||||||
for global_id in exception_global_ids:
|
bpy.ops.object.hide_view_clear(select=False)
|
||||||
obj = IfcStore.get_element(global_id)
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
if obj:
|
|
||||||
objs.append(obj)
|
# We need to store unselectable objects and toggle unselectibility for them.
|
||||||
if objs:
|
# As hide_view_set requires them to be selected to work.
|
||||||
old = context.area.type
|
unselectable = []
|
||||||
context.area.type = "VIEW_3D"
|
for obj in objs:
|
||||||
bpy.ops.object.hide_view_clear()
|
if obj.hide_select:
|
||||||
context_override = {}
|
unselectable.append(obj)
|
||||||
context_override["object"] = context_override["active_object"] = objs[0]
|
obj.hide_select = False
|
||||||
context_override["selected_objects"] = context_override["selected_editable_objects"] = objs
|
obj.select_set(True)
|
||||||
with context.temp_override(**context_override):
|
|
||||||
bpy.ops.object.hide_view_set(unselected=True)
|
# hide_view_set is checking actually selected objects, not context.selected objects.
|
||||||
bpy.data.objects["Viewpoint"].hide_set(False)
|
bpy.ops.object.hide_view_set(unselected=True)
|
||||||
context.area.type = old
|
bpy.data.objects["Viewpoint"].hide_set(False)
|
||||||
|
for obj in unselectable:
|
||||||
|
obj.hide_select = True
|
||||||
|
|
||||||
def set_view_setup_hints(
|
def set_view_setup_hints(
|
||||||
self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler, context: bpy.types.Context
|
self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler, context: bpy.types.Context
|
||||||
@@ -1062,9 +1065,9 @@ class ActivateBcfViewpoint(bpy.types.Operator):
|
|||||||
pass # We no longer have an openings collection
|
pass # We no longer have an openings collection
|
||||||
|
|
||||||
def set_selection(self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler) -> None:
|
def set_selection(self, viewpoint: bcf.v2.visinfo.VisualizationInfoHandler) -> None:
|
||||||
if not viewpoint.visualization_info.components or not viewpoint.visualization_info.components.selection:
|
selected_global_ids = viewpoint.get_selected_guids()
|
||||||
|
if selected_global_ids is None:
|
||||||
return
|
return
|
||||||
selected_global_ids = [s.ifc_guid for s in viewpoint.visualization_info.components.selection.component or []]
|
|
||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
for global_id in selected_global_ids:
|
for global_id in selected_global_ids:
|
||||||
obj = IfcStore.get_element(global_id)
|
obj = IfcStore.get_element(global_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user