mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 23:02:39 +00:00
Merge pull request #7575 from falken10vdl/simplify-new-filter-mode-with-just-chained-filters-with-set-operations
Refactor filter mode handling to simplify chained filters with set operations
This commit is contained in:
@@ -511,14 +511,15 @@ def draw_filter(
|
|||||||
row.operator("bim.edit_element_filter", icon="CHECKMARK", text="").filter_mode = "EXCLUDE"
|
row.operator("bim.edit_element_filter", icon="CHECKMARK", text="").filter_mode = "EXCLUDE"
|
||||||
row.operator("bim.enable_editing_element_filter", icon="CANCEL", text="").filter_mode = "NONE"
|
row.operator("bim.enable_editing_element_filter", icon="CANCEL", text="").filter_mode = "NONE"
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
if not tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
|
if not preferences.chain_filter_with_set_operations:
|
||||||
row.operator("bim.add_filter_group", text="Add Search Group", icon="ADD").module = module
|
row.operator("bim.add_filter_group", text="Add Search Group", icon="ADD").module = module
|
||||||
else:
|
else:
|
||||||
if not filter_groups or not any(fg.filters for fg in filter_groups):
|
row.prop(sprops, "facet", text="")
|
||||||
op = row.operator("bim.add_filter", text="Add Filter", icon="ADD")
|
op = row.operator("bim.add_filter", text="Add Filter", icon="ADD")
|
||||||
op.type = "entity"
|
op.type = sprops.facet
|
||||||
op.index = 0
|
op.index = 0
|
||||||
op.module = module
|
op.module = module
|
||||||
op = row.operator("bim.edit_filter_query", text="", icon="FILTER")
|
op = row.operator("bim.edit_filter_query", text="", icon="FILTER")
|
||||||
if "module" in op.bl_rna.properties:
|
if "module" in op.bl_rna.properties:
|
||||||
op.module = module
|
op.module = module
|
||||||
@@ -526,26 +527,23 @@ def draw_filter(
|
|||||||
for i, filter_group in enumerate(filter_groups):
|
for i, filter_group in enumerate(filter_groups):
|
||||||
box = layout.box()
|
box = layout.box()
|
||||||
|
|
||||||
row = box.row(align=True)
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
row.prop(sprops, "facet", text="")
|
if not preferences.chain_filter_with_set_operations:
|
||||||
op = row.operator("bim.add_filter", text="Add Filter", icon="ADD")
|
row = box.row(align=True)
|
||||||
op.type = sprops.facet
|
row.prop(sprops, "facet", text="")
|
||||||
op.index = i
|
op = row.operator("bim.add_filter", text="Add Filter", icon="ADD")
|
||||||
op.module = module
|
op.type = sprops.facet
|
||||||
op = row.operator("bim.remove_filter_group", text="", icon="X")
|
op.index = i
|
||||||
op.index = i
|
op.module = module
|
||||||
op.module = module
|
op = row.operator("bim.remove_filter_group", text="", icon="X")
|
||||||
|
op.index = i
|
||||||
|
op.module = module
|
||||||
|
|
||||||
for j, ifc_filter in enumerate(filter_group.filters):
|
for j, ifc_filter in enumerate(filter_group.filters):
|
||||||
if ifc_filter.type == "entity":
|
if ifc_filter.type == "entity":
|
||||||
row = box.row(align=True)
|
row = box.row(align=True)
|
||||||
preferences = tool.Blender.get_addon_preferences()
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
if preferences.chain_filter_with_set_operations:
|
show_mode_toggle = preferences.chain_filter_with_set_operations and j > 0
|
||||||
show_mode_toggle = j > 0
|
|
||||||
else:
|
|
||||||
show_mode_toggle = (
|
|
||||||
preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0
|
|
||||||
) # PR 7315 mode
|
|
||||||
if show_mode_toggle:
|
if show_mode_toggle:
|
||||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||||
op = row.operator(
|
op = row.operator(
|
||||||
@@ -761,12 +759,7 @@ def draw_filter(
|
|||||||
elif ifc_filter.type == "instance":
|
elif ifc_filter.type == "instance":
|
||||||
row = box.row(align=True)
|
row = box.row(align=True)
|
||||||
preferences = tool.Blender.get_addon_preferences()
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
if preferences.chain_filter_with_set_operations:
|
show_mode_toggle = preferences.chain_filter_with_set_operations and j > 0
|
||||||
show_mode_toggle = j > 0
|
|
||||||
else:
|
|
||||||
show_mode_toggle = (
|
|
||||||
preferences.default_filter_with_set_operations_for_globalid_and_class and j > 0
|
|
||||||
) # PR 7315 mode
|
|
||||||
if show_mode_toggle:
|
if show_mode_toggle:
|
||||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||||
op = row.operator(
|
op = row.operator(
|
||||||
|
|||||||
@@ -765,10 +765,7 @@ class Search(Operator):
|
|||||||
preferences = tool.Blender.get_addon_preferences()
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
|
|
||||||
# Migrate old ! prefix filters to new filter_mode system when preferences are enabled
|
# Migrate old ! prefix filters to new filter_mode system when preferences are enabled
|
||||||
if (
|
if preferences.chain_filter_with_set_operations:
|
||||||
preferences.chain_filter_with_set_operations
|
|
||||||
or preferences.default_filter_with_set_operations_for_globalid_and_class
|
|
||||||
):
|
|
||||||
for filter_group in props.filter_groups:
|
for filter_group in props.filter_groups:
|
||||||
for ifc_filter in filter_group.filters:
|
for ifc_filter in filter_group.filters:
|
||||||
if ifc_filter.type not in ["entity", "instance"]:
|
if ifc_filter.type not in ["entity", "instance"]:
|
||||||
|
|||||||
@@ -724,15 +724,10 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
)
|
)
|
||||||
|
|
||||||
chain_filter_with_set_operations: BoolProperty(
|
chain_filter_with_set_operations: BoolProperty(
|
||||||
name="NEW filter mode: Enable chained filters with set operations",
|
name="NEW Filter mode: Enable chained filters with set operations",
|
||||||
description="Enable chaining search filters with set operations: ADD (union: combine sets), SUBTRACT (difference: remove from set), FILTER (intersection: only elements in both sets), with autocomplete suggestions for filter values",
|
description="Enable chaining search filters with set operations: ADD (union: combine sets), SUBTRACT (difference: remove from set), FILTER (intersection: only elements in both sets), with autocomplete suggestions for filter values",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
default_filter_with_set_operations_for_globalid_and_class: BoolProperty(
|
|
||||||
name="DEFAULT filter mode: Enable set operations for GlobalId/Class",
|
|
||||||
description="Enable ADD/SUBTRACT/FILTER toggle buttons on entity (Class) and instance (GlobalId) filters for the DEFAULT filter mode",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
save_metadata_blend_file: BoolProperty(
|
save_metadata_blend_file: BoolProperty(
|
||||||
name="Save non ifc data to metadata blend File",
|
name="Save non ifc data to metadata blend File",
|
||||||
@@ -783,7 +778,6 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
container_hide_show_isolate: bool
|
container_hide_show_isolate: bool
|
||||||
mass_time_units_in_wizard: bool
|
mass_time_units_in_wizard: bool
|
||||||
chain_filter_with_set_operations: bool
|
chain_filter_with_set_operations: bool
|
||||||
default_filter_with_set_operations_for_globalid_and_class: bool
|
|
||||||
save_metadata_blend_file: bool
|
save_metadata_blend_file: bool
|
||||||
|
|
||||||
def draw(self, context: bpy.types.Context) -> None:
|
def draw(self, context: bpy.types.Context) -> None:
|
||||||
@@ -979,14 +973,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
|||||||
def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
|
def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
|
||||||
layout.prop(self, "container_hide_show_isolate")
|
layout.prop(self, "container_hide_show_isolate")
|
||||||
layout.prop(self, "mass_time_units_in_wizard")
|
layout.prop(self, "mass_time_units_in_wizard")
|
||||||
layout.label(text="Filtering modes:")
|
row = layout.row(align=True)
|
||||||
box = layout.box()
|
|
||||||
row = box.row(align=True)
|
|
||||||
row.prop(self, "chain_filter_with_set_operations")
|
row.prop(self, "chain_filter_with_set_operations")
|
||||||
row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/3270"
|
row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/3270"
|
||||||
row = box.row(align=True)
|
|
||||||
row.prop(self, "default_filter_with_set_operations_for_globalid_and_class")
|
|
||||||
row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/comment/27030"
|
|
||||||
layout.prop(self, "save_metadata_blend_file")
|
layout.prop(self, "save_metadata_blend_file")
|
||||||
if self.save_metadata_blend_file:
|
if self.save_metadata_blend_file:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
|||||||
@@ -132,10 +132,7 @@ class Search(bonsai.core.tool.Search):
|
|||||||
else:
|
else:
|
||||||
value = ifc_filter.value
|
value = ifc_filter.value
|
||||||
|
|
||||||
if (
|
if preferences.chain_filter_with_set_operations:
|
||||||
preferences.chain_filter_with_set_operations
|
|
||||||
or preferences.default_filter_with_set_operations_for_globalid_and_class
|
|
||||||
):
|
|
||||||
value = value.lstrip("!")
|
value = value.lstrip("!")
|
||||||
if ifc_filter.filter_mode == "SUBTRACT":
|
if ifc_filter.filter_mode == "SUBTRACT":
|
||||||
value = f"!{value}"
|
value = f"!{value}"
|
||||||
@@ -144,10 +141,7 @@ class Search(bonsai.core.tool.Search):
|
|||||||
elif ifc_filter.type == "entity":
|
elif ifc_filter.type == "entity":
|
||||||
value = ifc_filter.value
|
value = ifc_filter.value
|
||||||
|
|
||||||
if (
|
if preferences.chain_filter_with_set_operations:
|
||||||
preferences.chain_filter_with_set_operations
|
|
||||||
or preferences.default_filter_with_set_operations_for_globalid_and_class
|
|
||||||
):
|
|
||||||
value = value.lstrip("!")
|
value = value.lstrip("!")
|
||||||
if ifc_filter.filter_mode == "SUBTRACT":
|
if ifc_filter.filter_mode == "SUBTRACT":
|
||||||
value = f"!{value}"
|
value = f"!{value}"
|
||||||
@@ -215,19 +209,10 @@ class Search(bonsai.core.tool.Search):
|
|||||||
if filter_index == 0:
|
if filter_index == 0:
|
||||||
mode = "ADD"
|
mode = "ADD"
|
||||||
else:
|
else:
|
||||||
if ifc_filter.type in ["entity", "instance"]:
|
if preferences.chain_filter_with_set_operations:
|
||||||
if (
|
mode = ifc_filter.filter_mode
|
||||||
preferences.chain_filter_with_set_operations
|
|
||||||
or preferences.default_filter_with_set_operations_for_globalid_and_class
|
|
||||||
):
|
|
||||||
mode = ifc_filter.filter_mode
|
|
||||||
else:
|
|
||||||
mode = "FILTER" if group_results else "ADD"
|
|
||||||
else:
|
else:
|
||||||
if preferences.chain_filter_with_set_operations:
|
mode = "FILTER" if group_results else "ADD"
|
||||||
mode = ifc_filter.filter_mode
|
|
||||||
else:
|
|
||||||
mode = "FILTER" if group_results else "ADD"
|
|
||||||
|
|
||||||
if mode == "ADD":
|
if mode == "ADD":
|
||||||
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
||||||
|
|||||||
Reference in New Issue
Block a user