mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix #4054. You can now select objects based on diff results.
This commit is contained in:
@@ -20,11 +20,12 @@ import bpy
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.SelectDiffJsonFile,
|
||||
operator.VisualiseDiff,
|
||||
operator.SelectDiffOldFile,
|
||||
operator.SelectDiffNewFile,
|
||||
operator.ExecuteIfcDiff,
|
||||
operator.SelectDiffJsonFile,
|
||||
operator.SelectDiffNewFile,
|
||||
operator.SelectDiffObjects,
|
||||
operator.SelectDiffOldFile,
|
||||
operator.VisualiseDiff,
|
||||
prop.Relationships,
|
||||
prop.DiffProperties,
|
||||
ui.BIM_PT_diff,
|
||||
|
||||
@@ -226,3 +226,59 @@ class ExecuteIfcDiff(bpy.types.Operator):
|
||||
for obj in objs:
|
||||
if isinstance(obj, bpy.types.Object):
|
||||
collection.objects.link(obj)
|
||||
|
||||
|
||||
class SelectDiffObjects(bpy.types.Operator):
|
||||
bl_idname = "bim.select_diff_objects"
|
||||
bl_label = "Select Diff Objects"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
mode: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifc_file = tool.Ifc.get()
|
||||
with open(context.scene.DiffProperties.diff_json_file, "r") as file:
|
||||
diff = json.load(file)
|
||||
for obj in context.visible_objects:
|
||||
obj.select_set(False)
|
||||
|
||||
if self.mode == "DELETED" and "IfcDiff Deleted Elements" in obj.users_collection[0].name:
|
||||
obj.select_set(True)
|
||||
continue
|
||||
elif self.mode == "ADDED" and "IfcDiff Added Elements" in obj.users_collection[0].name:
|
||||
obj.select_set(True)
|
||||
continue
|
||||
elif self.mode == "CHANGED" and "IfcDiff Changed Elements" in obj.users_collection[0].name:
|
||||
obj.select_set(True)
|
||||
continue
|
||||
|
||||
if not obj.BIMObjectProperties.ifc_definition_id:
|
||||
continue
|
||||
|
||||
ifc_file = ""
|
||||
for scene in obj.users_scene:
|
||||
if scene.BIMProperties.ifc_file:
|
||||
ifc_file = scene.BIMProperties.ifc_file
|
||||
if scene.library:
|
||||
break
|
||||
|
||||
if ifc_file:
|
||||
if ifc_file not in IfcStore.session_files:
|
||||
IfcStore.session_files[ifc_file] = ifcopenshell.open(ifc_file)
|
||||
element_file = IfcStore.session_files[ifc_file]
|
||||
else:
|
||||
element_file = ifc_file
|
||||
|
||||
try:
|
||||
element = element_file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||
except:
|
||||
continue
|
||||
global_id = getattr(element, "GlobalId", None)
|
||||
if not global_id:
|
||||
continue
|
||||
if self.mode == "DELETED" and global_id in diff["deleted"]:
|
||||
obj.select_set(True)
|
||||
elif self.mode == "ADDED" and global_id in diff["added"]:
|
||||
obj.select_set(True)
|
||||
elif self.mode == "CHANGED" and global_id in diff["changed"]:
|
||||
obj.select_set(True)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -107,10 +107,22 @@ class BIM_PT_diff(Panel):
|
||||
|
||||
if DiffData.data["diff_json"]:
|
||||
row = layout.row()
|
||||
row.alignment = "CENTER"
|
||||
row.label(text=f"{DiffData.data['total_added']} added")
|
||||
row.label(text=f"{DiffData.data['total_deleted']} deleted")
|
||||
row.label(text=f"{DiffData.data['total_changed']} changed")
|
||||
col = row.column(align=True)
|
||||
col.operator(
|
||||
"bim.select_diff_objects",
|
||||
icon="RESTRICT_SELECT_OFF",
|
||||
text=f"Select {DiffData.data['total_added']} Added",
|
||||
).mode = "ADDED"
|
||||
col.operator(
|
||||
"bim.select_diff_objects",
|
||||
icon="RESTRICT_SELECT_OFF",
|
||||
text=f"Select {DiffData.data['total_deleted']} Deleted",
|
||||
).mode = "DELETED"
|
||||
col.operator(
|
||||
"bim.select_diff_objects",
|
||||
icon="RESTRICT_SELECT_OFF",
|
||||
text=f"Select {DiffData.data['total_changed']} Changed",
|
||||
).mode = "CHANGED"
|
||||
|
||||
if DiffData.data["changes"]:
|
||||
box = layout.box()
|
||||
|
||||
Reference in New Issue
Block a user