Create UI to run IFCDiff tool from Blender

This commit is contained in:
Dion Moult
2020-01-07 14:27:34 +11:00
parent dfe8149b17
commit 6d6f7af3d7
5 changed files with 89 additions and 24 deletions
@@ -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,
@@ -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"
+2
View File
@@ -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)
+11
View File
@@ -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"
+28 -24
View File
@@ -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()