WIP Refactor patch module. See #1222.

This commit is contained in:
Dion Moult
2021-01-24 19:57:22 +11:00
parent af3ed303d8
commit f9521eca54
8 changed files with 141 additions and 99 deletions
@@ -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
@@ -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"}
@@ -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")
@@ -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")