mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
Migrate old filter prefixes to new filter_mode system and enhance filter handling based on user preferences
This commit is contained in:
@@ -761,7 +761,17 @@ class Search(Operator):
|
|||||||
assert_never(self.property_group)
|
assert_never(self.property_group)
|
||||||
|
|
||||||
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
|
||||||
if preferences.chain_filter_with_set_operations or preferences.default_filter_with_set_operations_for_globalid_and_class:
|
if 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 ifc_filter in filter_group.filters:
|
||||||
|
if ifc_filter.type not in ["entity", "instance"]:
|
||||||
|
continue
|
||||||
|
if ifc_filter.value.startswith("!"):
|
||||||
|
ifc_filter.value = ifc_filter.value[1:]
|
||||||
|
ifc_filter.filter_mode = "SUBTRACT"
|
||||||
|
|
||||||
results = tool.Search.execute_filter_groups(props.filter_groups)
|
results = tool.Search.execute_filter_groups(props.filter_groups)
|
||||||
else:
|
else:
|
||||||
results = ifcopenshell.util.selector.filter_elements(
|
results = ifcopenshell.util.selector.filter_elements(
|
||||||
|
|||||||
@@ -123,21 +123,28 @@ class Search(bonsai.core.tool.Search):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _export_single_filter(cls, ifc_filter: BIMFacet) -> str:
|
def _export_single_filter(cls, ifc_filter: BIMFacet) -> str:
|
||||||
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
|
|
||||||
if ifc_filter.type == "instance":
|
if ifc_filter.type == "instance":
|
||||||
if "bpy.data.texts" in ifc_filter.value:
|
if "bpy.data.texts" in ifc_filter.value:
|
||||||
data_name = ifc_filter.value.split("bpy.data.texts")[1][2:-2]
|
data_name = ifc_filter.value.split("bpy.data.texts")[1][2:-2]
|
||||||
value = bpy.data.texts[data_name].as_string()
|
value = bpy.data.texts[data_name].as_string()
|
||||||
else:
|
else:
|
||||||
value = ifc_filter.value
|
value = ifc_filter.value
|
||||||
value = value.lstrip("!")
|
|
||||||
if ifc_filter.filter_mode == "SUBTRACT":
|
if preferences.chain_filter_with_set_operations or preferences.default_filter_with_set_operations_for_globalid_and_class:
|
||||||
value = f"!{value}"
|
value = value.lstrip("!")
|
||||||
|
if ifc_filter.filter_mode == "SUBTRACT":
|
||||||
|
value = f"!{value}"
|
||||||
return value
|
return value
|
||||||
|
|
||||||
elif ifc_filter.type == "entity":
|
elif ifc_filter.type == "entity":
|
||||||
value = ifc_filter.value
|
value = ifc_filter.value
|
||||||
value = value.lstrip("!")
|
|
||||||
if ifc_filter.filter_mode == "SUBTRACT":
|
if preferences.chain_filter_with_set_operations or preferences.default_filter_with_set_operations_for_globalid_and_class:
|
||||||
value = f"!{value}"
|
value = value.lstrip("!")
|
||||||
|
if ifc_filter.filter_mode == "SUBTRACT":
|
||||||
|
value = f"!{value}"
|
||||||
return value
|
return value
|
||||||
elif ifc_filter.type == "attribute":
|
elif ifc_filter.type == "attribute":
|
||||||
if not ifc_filter.name:
|
if not ifc_filter.name:
|
||||||
@@ -185,63 +192,36 @@ class Search(bonsai.core.tool.Search):
|
|||||||
Groups are combined with union (same as original " + " behavior).
|
Groups are combined with union (same as original " + " behavior).
|
||||||
"""
|
"""
|
||||||
preferences = tool.Blender.get_addon_preferences()
|
preferences = tool.Blender.get_addon_preferences()
|
||||||
#print(f"\n{'='*80}")
|
|
||||||
#print(f"DEBUG: execute_filter_groups - Starting execution")
|
|
||||||
#print(f"DEBUG: Preferences - chain_filter_with_set_operations: {preferences.chain_filter_with_set_operations}")
|
|
||||||
#print(f"DEBUG: Preferences - default_filter_with_set_operations_for_globalid_and_class: {preferences.default_filter_with_set_operations_for_globalid_and_class}")
|
|
||||||
#print(f"DEBUG: Total filter groups: {len(filter_groups)}")
|
|
||||||
|
|
||||||
all_group_results = []
|
all_group_results = []
|
||||||
|
|
||||||
for group_idx, filter_group in enumerate(filter_groups):
|
for group_idx, filter_group in enumerate(filter_groups):
|
||||||
#print(f"\n--- Group {group_idx} ---")
|
|
||||||
group_results = set()
|
group_results = set()
|
||||||
|
|
||||||
for filter_index, ifc_filter in enumerate(filter_group.filters):
|
for filter_index, ifc_filter in enumerate(filter_group.filters):
|
||||||
#print(f"\n Filter {filter_index}:")
|
|
||||||
#print(f" Type: {ifc_filter.type}")
|
|
||||||
#print(f" Value: {ifc_filter.value}")
|
|
||||||
#print(f" filter_mode property: {ifc_filter.filter_mode}")
|
|
||||||
|
|
||||||
if not ifc_filter.value:
|
if not ifc_filter.value:
|
||||||
#print(f" SKIPPED: No value")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
query = cls._export_single_filter(ifc_filter)
|
query = cls._export_single_filter(ifc_filter)
|
||||||
if not query:
|
if not query:
|
||||||
#print(f" SKIPPED: No query generated")
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
#print(f" Generated query: {query}")
|
|
||||||
#print(f" Current group_results size before this filter: {len(group_results)}")
|
|
||||||
|
|
||||||
# Determine the mode for this filter
|
|
||||||
if filter_index == 0:
|
if filter_index == 0:
|
||||||
mode = "ADD" # First filter is always ADD
|
mode = "ADD"
|
||||||
#print(f" Mode decision: ADD (first filter)")
|
|
||||||
else:
|
else:
|
||||||
# For entity and instance filters, check if set operations are enabled
|
|
||||||
if ifc_filter.type in ["entity", "instance"]:
|
if ifc_filter.type in ["entity", "instance"]:
|
||||||
# Use filter_mode only if chain mode OR default mode preference is enabled
|
|
||||||
if preferences.chain_filter_with_set_operations or preferences.default_filter_with_set_operations_for_globalid_and_class:
|
if preferences.chain_filter_with_set_operations or preferences.default_filter_with_set_operations_for_globalid_and_class:
|
||||||
mode = ifc_filter.filter_mode
|
mode = ifc_filter.filter_mode
|
||||||
#print(f" Mode decision: {mode} (entity/instance with preference enabled)")
|
|
||||||
else:
|
else:
|
||||||
# Default behavior: sequential filtering (FILTER mode)
|
|
||||||
mode = "FILTER" if group_results else "ADD"
|
mode = "FILTER" if group_results else "ADD"
|
||||||
#print(f" Mode decision: {mode} (entity/instance default behavior)")
|
|
||||||
else:
|
else:
|
||||||
# For other filter types, use chain mode if enabled, otherwise FILTER
|
|
||||||
if preferences.chain_filter_with_set_operations:
|
if preferences.chain_filter_with_set_operations:
|
||||||
mode = ifc_filter.filter_mode
|
mode = ifc_filter.filter_mode
|
||||||
#print(f" Mode decision: {mode} (other type with chain mode)")
|
|
||||||
else:
|
else:
|
||||||
mode = "FILTER" if group_results else "ADD"
|
mode = "FILTER" if group_results else "ADD"
|
||||||
#print(f" Mode decision: {mode} (other type default behavior)")
|
|
||||||
|
|
||||||
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)
|
||||||
#print(f" ADD: Found {len(results)} elements, adding to group_results")
|
|
||||||
group_results.update(results)
|
group_results.update(results)
|
||||||
|
|
||||||
elif mode == "SUBTRACT":
|
elif mode == "SUBTRACT":
|
||||||
@@ -250,11 +230,9 @@ class Search(bonsai.core.tool.Search):
|
|||||||
elements_to_remove = ifcopenshell.util.selector.filter_elements(
|
elements_to_remove = ifcopenshell.util.selector.filter_elements(
|
||||||
tool.Ifc.get(), query_without_prefix, elements=group_results
|
tool.Ifc.get(), query_without_prefix, elements=group_results
|
||||||
)
|
)
|
||||||
#print(f" SUBTRACT: Removing {len(elements_to_remove)} elements from group_results")
|
|
||||||
group_results -= elements_to_remove
|
group_results -= elements_to_remove
|
||||||
else:
|
else:
|
||||||
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
||||||
#print(f" SUBTRACT: group_results empty, adding {len(results)} elements (fallback to ADD)")
|
|
||||||
group_results.update(results)
|
group_results.update(results)
|
||||||
|
|
||||||
elif mode == "FILTER":
|
elif mode == "FILTER":
|
||||||
@@ -262,16 +240,11 @@ class Search(bonsai.core.tool.Search):
|
|||||||
results = ifcopenshell.util.selector.filter_elements(
|
results = ifcopenshell.util.selector.filter_elements(
|
||||||
tool.Ifc.get(), query, elements=group_results
|
tool.Ifc.get(), query, elements=group_results
|
||||||
)
|
)
|
||||||
#print(f" FILTER: Filtering group_results, result: {len(results)} elements")
|
|
||||||
group_results = results
|
group_results = results
|
||||||
else:
|
else:
|
||||||
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
results = ifcopenshell.util.selector.filter_elements(tool.Ifc.get(), query)
|
||||||
#print(f" FILTER: group_results empty, found {len(results)} elements (fallback to ADD)")
|
|
||||||
group_results.update(results)
|
group_results.update(results)
|
||||||
|
|
||||||
#print(f" Group results size after this filter: {len(group_results)}")
|
|
||||||
|
|
||||||
#print(f"\n Group {group_idx} final size: {len(group_results)}")
|
|
||||||
if group_results:
|
if group_results:
|
||||||
all_group_results.append(group_results)
|
all_group_results.append(group_results)
|
||||||
|
|
||||||
@@ -279,10 +252,6 @@ class Search(bonsai.core.tool.Search):
|
|||||||
for group_results in all_group_results:
|
for group_results in all_group_results:
|
||||||
final_results.update(group_results)
|
final_results.update(group_results)
|
||||||
|
|
||||||
#print(f"\n{'='*80}")
|
|
||||||
#print(f"DEBUG: Final combined results: {len(final_results)} elements")
|
|
||||||
#print(f"{'='*80}\n")
|
|
||||||
|
|
||||||
return final_results
|
return final_results
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user