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.SelectGlobalId,
operator.SelectIfcClass, operator.SelectIfcClass,
operator.SelectPset, operator.SelectPset,
operator.UnhideAllElements, operator.ShowAllIfcElements,
operator.FilterModelElements, operator.FilterModelElements,
operator.IfcSelector, operator.IfcSelector,
operator.SaveSelectorQuery, operator.SaveSelectorQuery,
@@ -25,6 +25,7 @@ import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.helper import close_operator_panel from blenderbim.bim.helper import close_operator_panel
from blenderbim.bim.module.group import ui from blenderbim.bim.module.group import ui
import blenderbim.core.search as core
from itertools import cycle from itertools import cycle
from bpy.types import PropertyGroup, Operator from bpy.types import PropertyGroup, Operator
from bpy.props import ( from bpy.props import (
@@ -451,17 +452,17 @@ class ActivateIfcBuildingStoreyFilter(Operator):
row.operator("bim.toggle_filter_selection", text="Deselect All").action = "DESELECT" row.operator("bim.toggle_filter_selection", text="Deselect All").action = "DESELECT"
class UnhideAllElements(Operator): class ShowAllIfcElements(Operator):
"""Filter model elements based on selection""" """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_idname = "bim.show_scene_elements"
bl_label = "Reset 3D View" bl_label = "Shows All Elements"
bl_idname = "bim.unhide_all_elements" bl_options = {"REGISTER", "UNDO"}
bl_label = "Unhide All Elements"
def execute(self, context): def execute(self, context):
for obj in bpy.data.scenes["Scene"].objects: core.show_scene_elements(tool.Spatial)
obj.hide_set(False)
return {"FINISHED"} return {"FINISHED"}
@@ -473,10 +474,12 @@ class FilterModelElements(Operator):
option: StringProperty("select|isolate|hide") option: StringProperty("select|isolate|hide")
def execute(self, context): def execute(self, context):
selector = context.scene.IfcSelectorProperties selection_props = context.scene.IfcSelectorProperties
selection = selector.selector_query_syntax if selector.manual_override else self.add_groups(selector) selection = selection_props.selector_query_syntax if selection_props.manual_override else self.add_groups(selection_props)
selector.selector_query_syntax = selection selection_props.selector_query_syntax = selection
self.update_model_view(context, selection) r = core.search(tool.Search, tool.Spatial, query=selection, action=self.option)
if isinstance(r, str):
self.report({"WARNING"}, r)
return {"FINISHED"} return {"FINISHED"}
def add_groups(self, selector:str) -> str: def add_groups(self, selector:str) -> str:
@@ -535,25 +538,6 @@ class FilterModelElements(Operator):
selection += "]" selection += "]"
return 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 # This needs to be moved into ui code, I know ;) - vulevukusej
class IfcSelector(Operator): class IfcSelector(Operator):
"""Select elements in model with IFC Selector""" """Select elements in model with IFC Selector"""
@@ -140,7 +140,8 @@ class IfcSelectorUI:
isolate.option = "isolate" isolate.option = "isolate"
hide = row.operator("bim.filter_model_elements", text="", icon="HIDE_ON") hide = row.operator("bim.filter_model_elements", text="", icon="HIDE_ON")
hide.option = "hide" 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 = layout.row(align=True)
row.alignment = "CENTER" row.alignment = "CENTER"
@@ -148,6 +149,9 @@ class IfcSelectorUI:
op = row.operator("bim.open_query_library", text="Load Query") op = row.operator("bim.open_query_library", text="Load Query")
row.operator("bim.add_to_ifc_group", text="Add to IFC Group") 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): def draw_query_group_ui(self, ifc_selector, layout):
for index, group in enumerate(ifc_selector.groups): for index, group in enumerate(ifc_selector.groups):
row = layout.row() 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() spatial.show_scene_objects()
def search(search, spatial, query, action): def search(search, spatial, query, action):