From f9521eca54c9737bd8198b5a715588ce4a71d6e8 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 24 Jan 2021 19:57:22 +1100 Subject: [PATCH] WIP Refactor patch module. See #1222. --- .../blenderbim/bim/__init__.py | 5 +- .../blenderbim/bim/module/patch/__init__.py | 18 +++++++ .../blenderbim/bim/module/patch/operator.py | 52 +++++++++++++++++++ .../blenderbim/bim/module/patch/prop.py | 38 ++++++++++++++ .../blenderbim/bim/module/patch/ui.py | 32 ++++++++++++ .../blenderbim/bim/operator.py | 48 ----------------- src/ifcblenderexport/blenderbim/bim/prop.py | 17 ------ src/ifcblenderexport/blenderbim/bim/ui.py | 30 ----------- 8 files changed, 141 insertions(+), 99 deletions(-) create mode 100644 src/ifcblenderexport/blenderbim/bim/module/patch/__init__.py create mode 100644 src/ifcblenderexport/blenderbim/bim/module/patch/operator.py create mode 100644 src/ifcblenderexport/blenderbim/bim/module/patch/prop.py create mode 100644 src/ifcblenderexport/blenderbim/bim/module/patch/ui.py diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index b8d9c5172c..6e493f893b 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -28,6 +28,7 @@ if bpy is not None: "material": None, "model": None, "owner": None, + "patch": None, "project": None, "pset": None, "pset_template": None, @@ -110,9 +111,6 @@ if bpy is not None: operator.AddVariable, operator.RemoveVariable, operator.PropagateTextData, - operator.SelectIfcPatchInput, - operator.SelectIfcPatchOutput, - operator.ExecuteIfcPatch, operator.SetOverrideColour, operator.AddDrawing, operator.RemoveDrawing, @@ -179,7 +177,6 @@ if bpy is not None: ui.BIM_PT_ifcclash, ui.BIM_PT_library, ui.BIM_PT_presentation_layers, - ui.BIM_PT_patch, ui.BIM_PT_presentation_layer_data, ui.BIM_PT_object_structural, ui.BIM_PT_camera, diff --git a/src/ifcblenderexport/blenderbim/bim/module/patch/__init__.py b/src/ifcblenderexport/blenderbim/bim/module/patch/__init__.py new file mode 100644 index 0000000000..d8a39535d2 --- /dev/null +++ b/src/ifcblenderexport/blenderbim/bim/module/patch/__init__.py @@ -0,0 +1,18 @@ +import bpy +from . import ui, prop, operator + +classes = ( + operator.SelectIfcPatchInput, + operator.SelectIfcPatchOutput, + operator.ExecuteIfcPatch, + prop.BIMPatchProperties, + ui.BIM_PT_patch, +) + + +def register(): + bpy.types.Scene.BIMPatchProperties = bpy.props.PointerProperty(type=prop.BIMPatchProperties) + + +def unregister(): + del bpy.types.Scene.BIMPatchProperties diff --git a/src/ifcblenderexport/blenderbim/bim/module/patch/operator.py b/src/ifcblenderexport/blenderbim/bim/module/patch/operator.py new file mode 100644 index 0000000000..4566891401 --- /dev/null +++ b/src/ifcblenderexport/blenderbim/bim/module/patch/operator.py @@ -0,0 +1,52 @@ +import bpy +import json + + +class SelectIfcPatchInput(bpy.types.Operator): + bl_idname = "bim.select_ifc_patch_input" + bl_label = "Select IFC Patch Input" + filter_glob: bpy.props.StringProperty(default="*.ifc", options={"HIDDEN"}) + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + context.scene.BIMPatchProperties.ifc_patch_input = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} + + +class SelectIfcPatchOutput(bpy.types.Operator): + bl_idname = "bim.select_ifc_patch_output" + bl_label = "Select IFC Patch Output" + filename_ext = ".ifc" + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + + def execute(self, context): + context.scene.BIMPatchProperties.ifc_patch_output = self.filepath + return {"FINISHED"} + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} + + +class ExecuteIfcPatch(bpy.types.Operator): + bl_idname = "bim.execute_ifc_patch" + bl_label = "Execute IFCPatch" + file_format: bpy.props.StringProperty() + + def execute(self, context): + import ifcpatch + + ifcpatch.execute( + { + "input": context.scene.BIMPatchProperties.ifc_patch_input, + "output": context.scene.BIMPatchProperties.ifc_patch_output, + "recipe": context.scene.BIMPatchProperties.ifc_patch_recipes, + "arguments": json.loads(context.scene.BIMPatchProperties.ifc_patch_args), + "log": context.scene.BIMProperties.data_dir + "process.log", + } + ) + return {"FINISHED"} diff --git a/src/ifcblenderexport/blenderbim/bim/module/patch/prop.py b/src/ifcblenderexport/blenderbim/bim/module/patch/prop.py new file mode 100644 index 0000000000..b2d4315878 --- /dev/null +++ b/src/ifcblenderexport/blenderbim/bim/module/patch/prop.py @@ -0,0 +1,38 @@ +import bpy +import importlib +from pathlib import Path +from blenderbim.bim.prop import StrProperty, Attribute +from bpy.types import PropertyGroup +from bpy.props import ( + PointerProperty, + StringProperty, + EnumProperty, + BoolProperty, + IntProperty, + FloatProperty, + FloatVectorProperty, + CollectionProperty, +) + + +ifcpatchrecipes_enum = [] + + +def getIfcPatchRecipes(self, context): + global ifcpatchrecipes_enum + if len(ifcpatchrecipes_enum) < 1: + ifcpatchrecipes_enum.clear() + ifcpatch_path = Path(importlib.util.find_spec("ifcpatch").submodule_search_locations[0]) + for filename in ifcpatch_path.joinpath("recipes").glob("*.py"): + f = str(filename.stem) + if f == "__init__": + continue + ifcpatchrecipes_enum.append((f, f, "")) + return ifcpatchrecipes_enum + + +class BIMPatchProperties(PropertyGroup): + ifc_patch_recipes: EnumProperty(items=getIfcPatchRecipes, name="Recipes") + ifc_patch_input: StringProperty(default="", name="IFC Patch Input IFC") + ifc_patch_output: StringProperty(default="", name="IFC Patch Output IFC") + ifc_patch_args: StringProperty(default="", name="Arguments") diff --git a/src/ifcblenderexport/blenderbim/bim/module/patch/ui.py b/src/ifcblenderexport/blenderbim/bim/module/patch/ui.py new file mode 100644 index 0000000000..49600d2d1c --- /dev/null +++ b/src/ifcblenderexport/blenderbim/bim/module/patch/ui.py @@ -0,0 +1,32 @@ +import bpy +from bpy.types import Panel + + +class BIM_PT_patch(Panel): + bl_label = "IFC Patch" + bl_idname = "BIM_PT_patch" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + + scene = context.scene + props = scene.BIMPatchProperties + + row = layout.row() + row.prop(props, "ifc_patch_recipes") + row = layout.row(align=True) + row.prop(props, "ifc_patch_input") + row.operator("bim.select_ifc_patch_input", icon="FILE_FOLDER", text="") + row = layout.row(align=True) + row.prop(props, "ifc_patch_output") + row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="") + row = layout.row() + row.prop(props, "ifc_patch_args") + + row = layout.row() + op = row.operator("bim.execute_ifc_patch") diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 5daa1c0888..4304c9e3cc 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -413,24 +413,6 @@ class SelectExternalMaterialDir(bpy.types.Operator): return {"RUNNING_MODAL"} -class ExecuteIfcPatch(bpy.types.Operator): - bl_idname = "bim.execute_ifc_patch" - bl_label = "Execute IFCPatch" - file_format: bpy.props.StringProperty() - - def execute(self, context): - import ifcpatch - - ifcpatch.execute( - { - "input": bpy.context.scene.BIMProperties.ifc_patch_input, - "output": bpy.context.scene.BIMProperties.ifc_patch_output, - "recipe": bpy.context.scene.BIMProperties.ifc_patch_recipes, - "arguments": json.loads("[" + bpy.context.scene.BIMProperties.ifc_patch_args + "]"), - "log": bpy.context.scene.BIMProperties.data_dir + "process.log", - } - ) - return {"FINISHED"} class ExportClashSets(bpy.types.Operator): @@ -1732,36 +1714,6 @@ class PropagateTextData(bpy.types.Operator): return {"FINISHED"} -class SelectIfcPatchInput(bpy.types.Operator): - bl_idname = "bim.select_ifc_patch_input" - bl_label = "Select IFC Patch Input" - filter_glob: bpy.props.StringProperty(default="*.ifc", options={"HIDDEN"}) - filepath: bpy.props.StringProperty(subtype="FILE_PATH") - - def execute(self, context): - bpy.context.scene.BIMProperties.ifc_patch_input = self.filepath - return {"FINISHED"} - - def invoke(self, context, event): - context.window_manager.fileselect_add(self) - return {"RUNNING_MODAL"} - - -class SelectIfcPatchOutput(bpy.types.Operator): - bl_idname = "bim.select_ifc_patch_output" - bl_label = "Select IFC Patch Output" - filename_ext = ".ifc" - filepath: bpy.props.StringProperty(subtype="FILE_PATH") - - def execute(self, context): - bpy.context.scene.BIMProperties.ifc_patch_output = self.filepath - return {"FINISHED"} - - def invoke(self, context, event): - context.window_manager.fileselect_add(self) - return {"RUNNING_MODAL"} - - class SetOverrideColour(bpy.types.Operator): bl_idname = "bim.set_override_colour" bl_label = "Set Override Colour" diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index b2f51af130..96c4eed206 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -28,7 +28,6 @@ cwd = os.path.dirname(os.path.realpath(__file__)) diagram_scales_enum = [] profiledef_enum = [] availablematerialpsets_enum = [] -ifcpatchrecipes_enum = [] titleblocks_enum = [] materialpsetnames_enum = [] attributes_enum = [] @@ -211,18 +210,6 @@ def getAttributeEnumValues(self, context): return [(e, e, "") for e in json.loads(self.enum_items)] -def getIfcPatchRecipes(self, context): - global ifcpatchrecipes_enum - if len(ifcpatchrecipes_enum) < 1: - ifcpatchrecipes_enum.clear() - ifcpatch_path = Path(importlib.util.find_spec("ifcpatch").submodule_search_locations[0]) - for filename in ifcpatch_path.joinpath("recipes").glob("*.py"): - f = str(filename.stem) - if f == "__init__": - continue - ifcpatchrecipes_enum.append((f, f, "")) - return ifcpatchrecipes_enum - def getTitleblocks(self, context): global titleblocks_enum if len(titleblocks_enum) < 1: @@ -503,10 +490,6 @@ class BIMProperties(PropertyGroup): smart_clash_groups: CollectionProperty(name="Smart Clash Groups", type=SmartClashGroup) active_smart_group_index: IntProperty(name="Active Smart Group Index") smart_clash_grouping_max_distance: IntProperty(name="Smart Clash Grouping Max Distance", default=3, soft_min=1, soft_max=10) - ifc_patch_recipes: EnumProperty(items=getIfcPatchRecipes, name="Recipes") - ifc_patch_input: StringProperty(default="", name="IFC Patch Input IFC") - ifc_patch_output: StringProperty(default="", name="IFC Patch Output IFC") - ifc_patch_args: StringProperty(default="", name="Arguments") area_unit: EnumProperty( default="SQUARE_METRE", items=[ diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index dc231e365b..3895645afd 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -403,36 +403,6 @@ class BIM_PT_library(Panel): layout.row().prop(scene.BIMLibrary, "description") -class BIM_PT_patch(Panel): - bl_label = "IFC Patch" - bl_idname = "BIM_PT_patch" - bl_options = {"DEFAULT_CLOSED"} - bl_space_type = "PROPERTIES" - bl_region_type = "WINDOW" - bl_context = "scene" - - def draw(self, context): - layout = self.layout - layout.use_property_split = True - - scene = context.scene - props = scene.BIMProperties - - row = layout.row() - row.prop(props, "ifc_patch_recipes") - row = layout.row(align=True) - row.prop(props, "ifc_patch_input") - row.operator("bim.select_ifc_patch_input", icon="FILE_FOLDER", text="") - row = layout.row(align=True) - row.prop(props, "ifc_patch_output") - row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="") - row = layout.row() - row.prop(props, "ifc_patch_args") - - row = layout.row() - op = row.operator("bim.execute_ifc_patch") - - class BIM_UL_generic(bpy.types.UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): if item: