From bbde4e75222d6a7e94ef17c5f316b74370d60459 Mon Sep 17 00:00:00 2001 From: Vincent Cadoret Date: Sat, 21 Nov 2020 16:29:55 -0500 Subject: [PATCH] Added a ui to select input and output files to clash smart grouper. --- .../blenderbim/bim/__init__.py | 2 + .../blenderbim/bim/operator.py | 44 +++++++++++++++---- src/ifcblenderexport/blenderbim/bim/prop.py | 2 + src/ifcblenderexport/blenderbim/bim/ui.py | 14 ++++++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 690f693251..d30c889884 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -143,6 +143,8 @@ if bpy is not None: operator.SelectClashSource, operator.ExecuteIfcClash, operator.SelectIfcClashResults, + operator.SelectClashResults, + operator.SelectSmartGroupedClashesPath, operator.SmartClashGroup, operator.IsolateSmartGroup, operator.SwitchContext, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 527650ada2..42f71af404 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1801,6 +1801,31 @@ class SelectClashSource(bpy.types.Operator): context.window_manager.fileselect_add(self) return {"RUNNING_MODAL"} +class SelectClashResults(bpy.types.Operator): + bl_idname = "bim.select_clash_results" + bl_label = "Select Clash Results" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + bpy.context.scene.BIMProperties.clash_results_path = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} + +class SelectSmartGroupedClashesPath(bpy.types.Operator): + bl_idname = "bim.select_smart_grouped_clashes_path" + bl_label = "Select Smart-Grouped Clashes Path" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + bpy.context.scene.BIMProperties.smart_grouped_clashes_path = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} class ExecuteIfcClash(bpy.types.Operator): bl_idname = "bim.execute_ifc_clash" @@ -1879,20 +1904,21 @@ class SelectIfcClashResults(bpy.types.Operator): class SmartClashGroup(bpy.types.Operator): bl_idname = "bim.smart_clash_group" bl_label = "Smart Clash Group" - filename_ext = ".json" + # filename_ext = ".json" filepath: bpy.props.StringProperty(subtype="FILE_PATH") - def invoke(self, context, event): - self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".json") - WindowManager = context.window_manager - WindowManager.fileselect_add(self) - return {"RUNNING_MODAL"} + #def invoke(self, context, event): + #self.filepath = bpy.path.ensure_ext(bpy.data.filepath, ".json") + #WindowManager = context.window_manager + #WindowManager.fileselect_add(self) + #return {"RUNNING_MODAL"} def execute(self, context): import ifcclash settings = ifcclash.IfcClashSettings() - self.filepath = bpy.path.ensure_ext(self.filepath, ".json") + # self.filepath = bpy.path.ensure_ext(self.filepath, ".json") + self.filepath = bpy.path.ensure_ext(bpy.context.scene.BIMProperties.clash_results_path, ".json") settings.output = self.filepath settings.logger = logging.getLogger("Clash") settings.logger.setLevel(logging.DEBUG) @@ -1901,8 +1927,8 @@ class SmartClashGroup(bpy.types.Operator): with open(self.filepath) as f: clash_sets = json.load(f) - # execute the smart grouping here (but put the heavy lifting code somewhere else in a class) - save_path = r"C:\Users\vince\Desktop\SmartGrouping Demo\smart-groups.json" + # execute the smart grouping + save_path = bpy.path.ensure_ext(bpy.context.scene.BIMProperties.smart_grouped_clashes_path, ".json") smart_grouped_clashes = ifc_clasher.smart_group_clashes(clash_sets) # save smart_groups to json diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 19e6f2ea2b..62d8baf7ff 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -1522,6 +1522,8 @@ class BIMProperties(PropertyGroup): blender_clash_set_a: CollectionProperty(name="Blender Clash Set A", type=StrProperty) blender_clash_set_b: CollectionProperty(name="Blender Clash Set B", type=StrProperty) clash_sets: CollectionProperty(name="Clash Sets", type=ClashSet) + clash_results_path: StringProperty(name="Clash Results Path") + smart_grouped_clashes_path: StringProperty(name="Smart Grouped Clashes Path") active_clash_set_index: IntProperty(name="Active Clash Set Index") smart_clash_groups: CollectionProperty(name="Smart Clash Groups", type=SmartClashGroup) active_smart_group_index: IntProperty(name="Active Smart Group Index") diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 78950996a9..e111921458 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -2376,6 +2376,20 @@ class BIM_PT_clash_manager(Panel): layout = self.layout props = context.scene.BIMProperties + row = layout.row() + layout.label(text="Select clash results to group:") + + row = layout.row(align=True) + row.prop(props, "clash_results_path", text="") + op = row.operator("bim.select_clash_results", icon="FILE_FOLDER", text="") + + row = layout.row() + layout.label(text="Select output path for smart-grouped clashes:") + + row = layout.row(align=True) + row.prop(props, "smart_grouped_clashes_path", text="") + op = row.operator("bim.select_smart_grouped_clashes_path", icon="FILE_FOLDER", text="") + row = layout.row(align=True) row.operator("bim.smart_clash_group")