BBIM: rewrite Selector search filter to use core and tool functions

This commit is contained in:
Sigma Dimensions
2023-02-11 13:19:08 +01:00
parent d3b176e5eb
commit 5beea8640e
4 changed files with 22 additions and 34 deletions
@@ -31,7 +31,7 @@ classes = (
operator.SelectGlobalId,
operator.SelectIfcClass,
operator.SelectPset,
operator.UnhideAllElements,
operator.ShowAllIfcElements,
operator.FilterModelElements,
operator.IfcSelector,
operator.SaveSelectorQuery,
@@ -25,6 +25,7 @@ import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.helper import close_operator_panel
from blenderbim.bim.module.group import ui
import blenderbim.core.search as core
from itertools import cycle
from bpy.types import PropertyGroup, Operator
from bpy.props import (
@@ -451,17 +452,17 @@ class ActivateIfcBuildingStoreyFilter(Operator):
row.operator("bim.toggle_filter_selection", text="Deselect All").action = "DESELECT"
class UnhideAllElements(Operator):
"""Filter model elements based on selection"""
class ShowAllIfcElements(Operator):
"""Show all Physical objects in the 3D View.
Warning: Pressing this button will not work if collections are excluded in the outliner Panel.
"""
bl_idname = "bim.reset_3d_view"
bl_label = "Reset 3D View"
bl_idname = "bim.unhide_all_elements"
bl_label = "Unhide All Elements"
bl_idname = "bim.show_scene_elements"
bl_label = "Shows All Elements"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
for obj in bpy.data.scenes["Scene"].objects:
obj.hide_set(False)
core.show_scene_elements(tool.Spatial)
return {"FINISHED"}
@@ -473,10 +474,12 @@ class FilterModelElements(Operator):
option: StringProperty("select|isolate|hide")
def execute(self, context):
selector = context.scene.IfcSelectorProperties
selection = selector.selector_query_syntax if selector.manual_override else self.add_groups(selector)
selector.selector_query_syntax = selection
self.update_model_view(context, selection)
selection_props = context.scene.IfcSelectorProperties
selection = selection_props.selector_query_syntax if selection_props.manual_override else self.add_groups(selection_props)
selection_props.selector_query_syntax = selection
r = core.search(tool.Search, tool.Spatial, query=selection, action=self.option)
if isinstance(r, str):
self.report({"WARNING"}, r)
return {"FINISHED"}
def add_groups(self, selector:str) -> str:
@@ -535,25 +538,6 @@ class FilterModelElements(Operator):
selection += "]"
return selection
def update_model_view(self, context, selection: str) -> None:
query = Selector.parse(IfcStore.file, selection)
sel_element_ids = [e.id() for e in query]
bpy.ops.object.select_all(action="DESELECT")
for obj in bpy.data.scenes["Scene"].objects:
obj.hide_set(False) # reset 3d view
if self.option == "select":
if obj.BIMObjectProperties.ifc_definition_id in sel_element_ids:
obj.select_set(True)
elif self.option == "isolate":
if obj.BIMObjectProperties.ifc_definition_id not in sel_element_ids:
obj.hide_set(True)
elif self.option == "hide":
if obj.BIMObjectProperties.ifc_definition_id in sel_element_ids:
obj.hide_set(True)
# This needs to be moved into ui code, I know ;) - vulevukusej
class IfcSelector(Operator):
"""Select elements in model with IFC Selector"""
@@ -140,7 +140,8 @@ class IfcSelectorUI:
isolate.option = "isolate"
hide = row.operator("bim.filter_model_elements", text="", icon="HIDE_ON")
hide.option = "hide"
row.operator("bim.unhide_all_elements", text="", icon="HIDE_OFF")
unhide = row.operator("bim.filter_model_elements", text="", icon="HIDE_OFF")
unhide.option = "unhide"
row = layout.row(align=True)
row.alignment = "CENTER"
@@ -148,6 +149,9 @@ class IfcSelectorUI:
op = row.operator("bim.open_query_library", text="Load Query")
row.operator("bim.add_to_ifc_group", text="Add to IFC Group")
row = layout.row(align=True)
row.operator("bim.show_all_ifc_elements", text="Show All Elements", icon="HIDE_OFF")
def draw_query_group_ui(self, ifc_selector, layout):
for index, group in enumerate(ifc_selector.groups):
row = layout.row()
+1 -1
View File
@@ -1,4 +1,4 @@
def show_all_ifc_elements(spatial):
def show_scene_elements(spatial):
spatial.show_scene_objects()
def search(search, spatial, query, action):