mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
centralize docstring extraction in UI module
This commit is contained in:
@@ -2,7 +2,6 @@ import os
|
|||||||
import bpy
|
import bpy
|
||||||
import json
|
import json
|
||||||
import ifcpatch
|
import ifcpatch
|
||||||
from .helper import extract_docs
|
|
||||||
|
|
||||||
|
|
||||||
class SelectIfcPatchInput(bpy.types.Operator):
|
class SelectIfcPatchInput(bpy.types.Operator):
|
||||||
@@ -69,23 +68,21 @@ class ExecuteIfcPatch(bpy.types.Operator):
|
|||||||
class PopulatePatchArguments(bpy.types.Operator):
|
class PopulatePatchArguments(bpy.types.Operator):
|
||||||
bl_idname = "bim.populate_patch_arguments"
|
bl_idname = "bim.populate_patch_arguments"
|
||||||
bl_label = "Update IFC Patch arguments"
|
bl_label = "Update IFC Patch arguments"
|
||||||
recipe: bpy.props.StringProperty()
|
inputs: bpy.props.StringProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
patch_args = context.scene.BIMPatchProperties.ifc_patch_args_attr
|
patch_args = context.scene.BIMPatchProperties.ifc_patch_args_attr
|
||||||
patch_args.clear()
|
patch_args.clear()
|
||||||
docs = extract_docs(ifcpatch, self.recipe, "Patcher", "__init__", ("src", "file", "logger", "args"))
|
for name, _type, default, description in json.loads(self.inputs):
|
||||||
if "inputs" in docs:
|
new_attr = patch_args.add()
|
||||||
for arg_name in docs["inputs"]:
|
new_attr.data_type = {
|
||||||
arg_info = docs["inputs"][arg_name]
|
"str": "string",
|
||||||
new_attr = patch_args.add()
|
"float": "float",
|
||||||
new_attr.data_type = {
|
"int": "integer",
|
||||||
"str": "string",
|
"bool": "boolean",
|
||||||
"float": "float",
|
}[_type]
|
||||||
"int": "integer",
|
new_attr.name = name
|
||||||
"bool": "boolean",
|
if default is not None:
|
||||||
}[arg_info["type"]]
|
new_attr.set_value(default)
|
||||||
new_attr.name = arg_name
|
new_attr.description = description
|
||||||
new_attr.set_value(arg_info.get("default", new_attr.get_value_default()))
|
|
||||||
new_attr.description = arg_info.get("description", "")
|
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import importlib
|
|
||||||
import importlib.util
|
|
||||||
import ifcpatch
|
import ifcpatch
|
||||||
from blenderbim.bim.helper import draw_attributes
|
from blenderbim.bim.helper import draw_attributes
|
||||||
from .helper import extract_docs
|
from .helper import extract_docs
|
||||||
from .operator import PopulatePatchArguments
|
from .operator import PopulatePatchArguments
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class BIM_PT_patch(bpy.types.Panel):
|
class BIM_PT_patch(bpy.types.Panel):
|
||||||
@@ -23,7 +22,7 @@ class BIM_PT_patch(bpy.types.Panel):
|
|||||||
scene = context.scene
|
scene = context.scene
|
||||||
props = scene.BIMPatchProperties
|
props = scene.BIMPatchProperties
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(props, "ifc_patch_recipes")
|
row.prop(props, "ifc_patch_recipes")
|
||||||
|
|
||||||
recipe = props.ifc_patch_recipes
|
recipe = props.ifc_patch_recipes
|
||||||
|
|
||||||
@@ -41,9 +40,16 @@ class BIM_PT_patch(bpy.types.Panel):
|
|||||||
row.prop(props, "ifc_patch_output")
|
row.prop(props, "ifc_patch_output")
|
||||||
row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="")
|
row.operator("bim.select_ifc_patch_output", icon="FILE_FOLDER", text="")
|
||||||
|
|
||||||
op = layout.operator(PopulatePatchArguments.bl_idname)
|
update_args_op = layout.operator(PopulatePatchArguments.bl_idname)
|
||||||
op.recipe = recipe
|
update_args_op.inputs = json.dumps([
|
||||||
if props.ifc_patch_args_attr and bool(docs["inputs"]):
|
(
|
||||||
|
v["name"],
|
||||||
|
v["type"],
|
||||||
|
v.get("default", None),
|
||||||
|
v.get("description", "")
|
||||||
|
)
|
||||||
|
for v in docs.get("inputs", {}).values()])
|
||||||
|
if props.ifc_patch_args_attr and update_args_op.inputs:
|
||||||
draw_attributes(props.ifc_patch_args_attr, layout, show_description=True)
|
draw_attributes(props.ifc_patch_args_attr, layout, show_description=True)
|
||||||
else:
|
else:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@@ -51,4 +57,4 @@ class BIM_PT_patch(bpy.types.Panel):
|
|||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
op = row.operator("bim.execute_ifc_patch")
|
op = row.operator("bim.execute_ifc_patch")
|
||||||
op.use_json_for_args = not bool(docs["inputs"])
|
op.use_json_for_args = not update_args_op.inputs
|
||||||
|
|||||||
Reference in New Issue
Block a user