mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
Refactor filter suggestion handling to streamline preference access and improve code clarity
This commit is contained in:
@@ -489,8 +489,6 @@ def draw_filter(
|
||||
data.load()
|
||||
|
||||
sprops = tool.Search.get_search_props()
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if tool.Ifc.get():
|
||||
row = layout.row(align=True)
|
||||
@@ -500,7 +498,7 @@ def draw_filter(
|
||||
if data.data["saved_searches"]:
|
||||
row.operator("bim.load_search", text="", icon="IMPORT").module = module
|
||||
row.operator("bim.save_search", text="", icon="EXPORT").module = module
|
||||
if data.data["saved_searches"] and enable_suggestions:
|
||||
if data.data["saved_searches"]:
|
||||
row.operator("bim.remove_search", text="", icon="REMOVE").module = module
|
||||
if module != "search":
|
||||
if module == "drawing_include":
|
||||
@@ -509,7 +507,7 @@ def draw_filter(
|
||||
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 = layout.row(align=True)
|
||||
if not enable_suggestions:
|
||||
if not tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
||||
row.operator("bim.add_filter_group", text="Add Search Group", icon="ADD").module = module
|
||||
else:
|
||||
if not filter_groups or not any(fg.filters for fg in filter_groups):
|
||||
@@ -537,7 +535,7 @@ def draw_filter(
|
||||
for j, ifc_filter in enumerate(filter_group.filters):
|
||||
if ifc_filter.type == "entity":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -549,15 +547,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="FILE_3D")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "attribute":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -569,15 +566,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "name", text="", icon="COPY_ID")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op.suggestion_type = "attribute_name"
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op.suggestion_type = "attribute_name"
|
||||
row.prop(ifc_filter, "value", text="")
|
||||
if enable_suggestions and ifc_filter.name:
|
||||
if ifc_filter.name:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
@@ -586,7 +582,7 @@ def draw_filter(
|
||||
op.suggestion_type = "attribute_value"
|
||||
elif ifc_filter.type == "type":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -598,15 +594,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="FILE_VOLUME")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "material":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -618,15 +613,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="MATERIAL")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "property":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -638,15 +632,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "pset", text="", icon="PROPERTIES")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op.suggestion_type = "pset"
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op.suggestion_type = "pset"
|
||||
row.prop(ifc_filter, "name", text="")
|
||||
if enable_suggestions and ifc_filter.pset:
|
||||
if ifc_filter.pset:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
@@ -655,7 +648,7 @@ def draw_filter(
|
||||
op.suggestion_type = "property_name"
|
||||
row.prop(ifc_filter, "comparison", text="")
|
||||
row.prop(ifc_filter, "value", text="")
|
||||
if enable_suggestions and ifc_filter.pset and ifc_filter.name:
|
||||
if ifc_filter.pset and ifc_filter.name:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
@@ -664,7 +657,7 @@ def draw_filter(
|
||||
op.suggestion_type = "property_value"
|
||||
elif ifc_filter.type == "classification":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -676,15 +669,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="OUTLINER")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "location":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -696,15 +688,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="PACKAGE")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "group":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -716,15 +707,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="OUTLINER_COLLECTION")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "parent":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -736,15 +726,14 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="FILE_PARENT")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
elif ifc_filter.type == "query":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -760,7 +749,7 @@ def draw_filter(
|
||||
row.prop(ifc_filter, "value", text="")
|
||||
elif ifc_filter.type == "instance":
|
||||
row = box.row(align=True)
|
||||
if enable_suggestions and j > 0:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and j > 0:
|
||||
mode_icons = {"ADD": "ADD", "SUBTRACT": "REMOVE", "FILTER": "FILTER"}
|
||||
op = row.operator(
|
||||
"bim.toggle_filter_inclusion",
|
||||
@@ -772,12 +761,11 @@ def draw_filter(
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
row.prop(ifc_filter, "value", text="", icon="GRIP")
|
||||
if enable_suggestions:
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.filter_value_suggestions", text="", icon="VIEWZOOM")
|
||||
op.group_index = i
|
||||
op.filter_index = j
|
||||
op.module = module
|
||||
op.filter_type = ifc_filter.type
|
||||
op = row.operator("bim.select_filter_elements", text="", icon="EYEDROPPER")
|
||||
op.group_index = i
|
||||
op.index = j
|
||||
|
||||
@@ -3687,9 +3687,6 @@ class EditElementFilter(bpy.types.Operator, tool.Ifc.Operator):
|
||||
pset = tool.Pset.get_element_pset(element, "EPset_Drawing")
|
||||
assert pset
|
||||
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if self.filter_mode == "INCLUDE":
|
||||
filter_groups = props.include_filter_groups
|
||||
elif self.filter_mode == "EXCLUDE":
|
||||
@@ -3699,7 +3696,7 @@ class EditElementFilter(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
query = tool.Search.export_filter_query(filter_groups) or None
|
||||
|
||||
if enable_suggestions and query:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations and query:
|
||||
filter_structure = []
|
||||
for filter_group in filter_groups:
|
||||
group_data = []
|
||||
|
||||
@@ -662,10 +662,8 @@ class EditFilterQuery(Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
module = getattr(self, "module", "search")
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if not enable_suggestions:
|
||||
if not tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
||||
if self.query == self.old_query:
|
||||
return
|
||||
|
||||
@@ -676,20 +674,16 @@ class EditFilterQuery(Operator, tool.Ifc.Operator):
|
||||
return
|
||||
|
||||
def draw(self, context):
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if not enable_suggestions:
|
||||
if not tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
||||
row = self.layout.row()
|
||||
row.prop(self, "query", text="")
|
||||
|
||||
def invoke(self, context, event):
|
||||
module = getattr(self, "module", "search")
|
||||
filter_groups = tool.Search.get_filter_groups(module)
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if enable_suggestions:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
||||
filter_structure = []
|
||||
for filter_group in filter_groups:
|
||||
group_data = []
|
||||
@@ -766,10 +760,8 @@ class Search(Operator):
|
||||
else:
|
||||
assert_never(self.property_group)
|
||||
|
||||
preferences = tool.Blender.get_addon_preferences()
|
||||
enable_suggestions = getattr(preferences, "chain_filter_with_set_operations", False)
|
||||
|
||||
if enable_suggestions:
|
||||
if tool.Blender.get_addon_preferences().chain_filter_with_set_operations:
|
||||
results = tool.Search.execute_filter_groups(props.filter_groups)
|
||||
else:
|
||||
results = ifcopenshell.util.selector.filter_elements(
|
||||
|
||||
@@ -916,7 +916,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences):
|
||||
def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None:
|
||||
layout.prop(self, "container_hide_show_isolate")
|
||||
layout.prop(self, "mass_time_units_in_wizard")
|
||||
layout.prop(self, "chain_filter_with_set_operations")
|
||||
row = layout.row(align=True)
|
||||
row.prop(self, "chain_filter_with_set_operations")
|
||||
row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/3270"
|
||||
|
||||
|
||||
# Scene panel groups
|
||||
|
||||
Reference in New Issue
Block a user