Skip to content

Commit 7742e4d

Browse files
committed
IfcDiff now uses the new selector syntax with the new UI
1 parent e2102cd commit 7742e4d

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

src/blenderbim/blenderbim/bim/module/diff/data.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def load(cls):
3838
cls.data["total_deleted"] = cls.total_deleted()
3939
cls.data["total_changed"] = cls.total_changed()
4040
cls.data["changes"] = cls.changes()
41+
cls.data["saved_searches"] = cls.saved_searches()
4142
cls.is_loaded = True
4243

4344
@classmethod
@@ -84,3 +85,18 @@ def changes(cls):
8485
elif element.GlobalId in diff["deleted"]:
8586
changes["Deleted"] = True
8687
return changes
88+
89+
@classmethod
90+
def saved_searches(cls):
91+
if not tool.Ifc.get():
92+
return []
93+
groups = tool.Ifc.get().by_type("IfcGroup")
94+
results = []
95+
for group in groups:
96+
try:
97+
data = json.loads(group.Description)
98+
if isinstance(data, dict) and data.get("type", None) == "BBIM_Search" and data.get("query", None):
99+
results.append(group)
100+
except:
101+
pass
102+
return [(str(g.id()), g.Name or "Unnamed", "") for g in sorted(results, key=lambda x: x.Name or "Unnamed")]

src/blenderbim/blenderbim/bim/module/diff/operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class ExecuteIfcDiff(bpy.types.Operator):
135135
bl_label = "Execute IFC Diff"
136136
filename_ext = ".json"
137137
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
138+
filter_glob: bpy.props.StringProperty(default="*.json", options={"HIDDEN"})
138139

139140
def invoke(self, context, event):
140141
self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".json")
@@ -162,7 +163,7 @@ def execute(self, context):
162163
new = ifcopenshell.open(self.props.new_file)
163164

164165
relationships = [r.relationship for r in self.props.diff_relationships]
165-
query = self.props.diff_filter_elements
166+
query = tool.Search.export_filter_query(self.props.filter_groups) or None
166167

167168
ifc_diff = ifcdiff.IfcDiff(old, new, relationships=relationships, filter_elements=query)
168169
ifc_diff.diff()

src/blenderbim/blenderbim/bim/module/diff/prop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
1818

1919
import bpy
20-
from blenderbim.bim.prop import StrProperty
20+
from blenderbim.bim.prop import StrProperty, BIMFilterGroup
2121
from blenderbim.bim.module.diff.data import DiffData
2222
from bpy.types import PropertyGroup
2323
from bpy.props import (
@@ -48,7 +48,7 @@ class DiffProperties(PropertyGroup):
4848
old_file: StringProperty(default="", name="Old IFC File")
4949
new_file: StringProperty(default="", name="New IFC File")
5050
diff_relationships: CollectionProperty(type=Relationships, name="Relationships")
51-
diff_filter_elements: StringProperty(default="", name="Filter")
51+
filter_groups: CollectionProperty(type=BIMFilterGroup, name="Filter Groups")
5252
should_load_changed_elements: BoolProperty(name="Load Changed Elements", default=True)
5353
active_file: EnumProperty(
5454
items=[

src/blenderbim/blenderbim/bim/module/diff/ui.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from bpy.types import Panel
2020
from blenderbim.bim.ifc import IfcStore
2121
from blenderbim.bim.module.diff.data import DiffData
22+
import blenderbim.bim.helper
2223
import blenderbim.tool as tool
23-
import json
2424

2525

2626
class BIM_PT_diff(Panel):
@@ -93,8 +93,7 @@ def draw(self, context):
9393
remove.collection = "diff_relationships"
9494
remove.index = index
9595

96-
row = layout.row(align=True)
97-
row.prop(props, "diff_filter_elements")
96+
blenderbim.bim.helper.draw_filter(self.layout, props.filter_groups, DiffData, "diff")
9897

9998
row = layout.row()
10099
row.operator("bim.execute_ifc_diff")

src/blenderbim/blenderbim/tool/search.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def get_filter_groups(cls, module: str) -> bpy.types.bpy_prop_collection:
2020
return bpy.context.scene.BIMSearchProperties.filter_groups
2121
elif module == "csv":
2222
return bpy.context.scene.CsvProperties.filter_groups
23+
elif module == "diff":
24+
return bpy.context.scene.DiffProperties.filter_groups
2325
elif module == "drawing_include":
2426
return bpy.context.active_object.data.BIMCameraProperties.include_filter_groups
2527
elif module == "drawing_exclude":

src/ifcdiff/ifcdiff.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class IfcDiff:
5454
that comparisons will take longer.
5555
:type is_shallow: bool
5656
:param filter_elements: An IFC filter query if you only want to compare a
57-
subset of elements. For example: ``.IfcWall`` to only compare walls.
57+
subset of elements. For example: ``IfcWall`` to only compare walls.
5858
:type filter_elements: string
5959
6060
Example::
@@ -83,9 +83,12 @@ def diff(self):
8383
self.precision = self.get_precision()
8484

8585
if self.filter_elements:
86-
selector = ifcopenshell.util.selector.Selector()
87-
old_elements = set(e.GlobalId for e in selector.parse(self.old, self.filter_elements))
88-
new_elements = set(e.GlobalId for e in selector.parse(self.new, self.filter_elements))
86+
old_elements = set(
87+
e.GlobalId for e in ifcopenshell.util.selector.filter_elements(self.old, self.filter_elements)
88+
)
89+
new_elements = set(
90+
e.GlobalId for e in ifcopenshell.util.selector.filter_elements(self.new, self.filter_elements)
91+
)
8992
else:
9093
old_elements = self.old.by_type("IfcElement")
9194
if self.old.schema == "IFC2X3":

0 commit comments

Comments
 (0)