diff --git a/src/ifcblenderexport/blenderbim/__init__.py b/src/ifcblenderexport/blenderbim/__init__.py index c440e16728..a17958e582 100644 --- a/src/ifcblenderexport/blenderbim/__init__.py +++ b/src/ifcblenderexport/blenderbim/__init__.py @@ -36,6 +36,8 @@ if bpy is not None: operator.SelectType, operator.SelectFeaturesDir, operator.SelectDiffJsonFile, + operator.SelectDiffNewFile, + operator.SelectDiffOldFile, operator.SelectDataDir, operator.SelectSchemaDir, operator.ExportIFC, @@ -82,6 +84,7 @@ if bpy is not None: operator.GenerateDigitalTwin, operator.CreateView, operator.ActivateView, + operator.ExecuteIfcDiff, prop.Subcontext, prop.BIMProperties, prop.DocProperties, diff --git a/src/ifcblenderexport/blenderbim/operator.py b/src/ifcblenderexport/blenderbim/operator.py index d23d149043..45fa32f228 100644 --- a/src/ifcblenderexport/blenderbim/operator.py +++ b/src/ifcblenderexport/blenderbim/operator.py @@ -519,6 +519,51 @@ class SelectDiffJsonFile(bpy.types.Operator): context.window_manager.fileselect_add(self) return {'RUNNING_MODAL'} + +class SelectDiffOldFile(bpy.types.Operator): + bl_idname = "bim.select_diff_old_file" + bl_label = "Select Diff Old File" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + bpy.context.scene.BIMProperties.diff_old_file = self.filepath + return {'FINISHED'} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {'RUNNING_MODAL'} + + +class SelectDiffNewFile(bpy.types.Operator): + bl_idname = "bim.select_diff_new_file" + bl_label = "Select Diff New File" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + bpy.context.scene.BIMProperties.diff_new_file = self.filepath + return {'FINISHED'} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {'RUNNING_MODAL'} + + +class ExecuteIfcDiff(bpy.types.Operator): + bl_idname = 'bim.execute_ifc_diff' + bl_label = 'Execute IFC Diff' + + def execute(self, context): + import ifcdiff + ifc_diff = ifcdiff.IfcDiff( + bpy.context.scene.BIMProperties.diff_old_file, + bpy.context.scene.BIMProperties.diff_new_file, + bpy.context.scene.BIMProperties.diff_json_file + ) + ifc_diff.diff() + ifc_diff.export() + return {'FINISHED'} + + class SelectFeaturesDir(bpy.types.Operator): bl_idname = "bim.select_features_dir" bl_label = "Select Features Directory" diff --git a/src/ifcblenderexport/blenderbim/prop.py b/src/ifcblenderexport/blenderbim/prop.py index 9ef6b22c69..31dfa69ca0 100644 --- a/src/ifcblenderexport/blenderbim/prop.py +++ b/src/ifcblenderexport/blenderbim/prop.py @@ -266,6 +266,8 @@ class BIMProperties(PropertyGroup): global_id: StringProperty(name="GlobalId") features_dir: StringProperty(default='', name="Features Directory") diff_json_file: StringProperty(default='', name="Diff JSON File") + diff_old_file: StringProperty(default='', name="Diff Old IFC File") + diff_new_file: StringProperty(default='', name="Diff New IFC File") aggregate_class: EnumProperty(items=getIfcClasses, name="Aggregate Class") aggregate_name: StringProperty(name="Aggregate Name") classification: EnumProperty(items=getClassifications, name="Classification", update=refreshReferences) diff --git a/src/ifcblenderexport/blenderbim/ui.py b/src/ifcblenderexport/blenderbim/ui.py index 5c10b94331..4c9eff6fc4 100644 --- a/src/ifcblenderexport/blenderbim/ui.py +++ b/src/ifcblenderexport/blenderbim/ui.py @@ -456,6 +456,17 @@ class BIM_PT_diff(Panel): row.prop(bim_properties, "diff_json_file") row.operator("bim.select_diff_json_file", icon="FILE_FOLDER", text="") + row = layout.row(align=True) + row.prop(bim_properties, "diff_old_file") + row.operator("bim.select_diff_old_file", icon="FILE_FOLDER", text="") + + row = layout.row(align=True) + row.prop(bim_properties, "diff_new_file") + row.operator("bim.select_diff_new_file", icon="FILE_FOLDER", text="") + + row = layout.row() + row.operator('bim.execute_ifc_diff') + class BIM_PT_mvd(Panel): bl_label = "Model View Definitions" diff --git a/src/ifcdiff/diff.py b/src/ifcdiff/ifcdiff.py old mode 100755 new mode 100644 similarity index 80% rename from src/ifcdiff/diff.py rename to src/ifcdiff/ifcdiff.py index eed469f06f..06e3fdcc96 --- a/src/ifcdiff/diff.py +++ b/src/ifcdiff/ifcdiff.py @@ -9,9 +9,10 @@ import argparse class IfcDiff(): - def __init__(self, old_file, new_file): + def __init__(self, old_file, new_file, output_file): self.old_file = old_file self.new_file = new_file + self.output_file = output_file self.change_register = {} self.representation_ids = [] @@ -51,6 +52,17 @@ class IfcDiff(): len(self.change_register.keys()))) print('# Diff finished in {:.2f} seconds'.format(time.time() - start)) + def export(self): + with open(self.output_file, 'w', encoding='utf-8') as diff_file: + json.dump({ + 'added': list(self.added_elements), + 'deleted': list(self.deleted_elements), + 'changed': self.change_register, + }, + diff_file, + indent=4, + cls=DiffEncoder) + def load(self): print('Loading old file ...') self.old = ifcopenshell.open(self.old_file) @@ -104,26 +116,18 @@ class DiffEncoder(json.JSONEncoder): except: return str(obj) -parser = argparse.ArgumentParser(description='Show the difference between two IFC files') -parser.add_argument('old', type=str, help='The old IFC file') -parser.add_argument('new', type=str, help='The new IFC file') -parser.add_argument( - '-o', - '--output', - type=str, - help='The JSON diff file to output. Defaults to diff.json', - default='diff.json') -args = parser.parse_args() - -ifc_diff = IfcDiff(args.old, args.new) -ifc_diff.diff() - -with open(args.output, 'w', encoding='utf-8') as diff_file: - json.dump({ - 'added': list(ifc_diff.added_elements), - 'deleted': list(ifc_diff.deleted_elements), - 'changed': ifc_diff.change_register, - }, - diff_file, - indent=4, - cls=DiffEncoder) +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Show the difference between two IFC files') + parser.add_argument('old', type=str, help='The old IFC file') + parser.add_argument('new', type=str, help='The new IFC file') + parser.add_argument( + '-o', + '--output', + type=str, + help='The JSON diff file to output. Defaults to diff.json', + default='diff.json') + args = parser.parse_args() + + ifc_diff = IfcDiff(args.old, args.new, args.output) + ifc_diff.diff() + ifc_diff.export()