mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
bcf bonsai - create bcf v3 projects and display loaded bcf version
Example - https://imgur.com/a/3ZSGtw7
This commit is contained in:
@@ -46,7 +46,15 @@ class BcfStore:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def set(cls, bcfxml: Union[bcf.bcfxml.BcfXml, None], filepath: str) -> None:
|
def set(cls, bcfxml: Union[bcf.bcfxml.BcfXml, None], filepath: str) -> None:
|
||||||
cls.bcfxml = bcfxml
|
cls.bcfxml = bcfxml
|
||||||
bpy.context.scene.BCFProperties.bcf_file = filepath
|
props = bpy.context.scene.BCFProperties
|
||||||
|
props.bcf_file = filepath
|
||||||
|
|
||||||
|
# Set bcf_version prop on load.
|
||||||
|
if filepath or bcfxml:
|
||||||
|
bcfxml = cls.get_bcfxml()
|
||||||
|
assert bcfxml
|
||||||
|
bcf_v2 = (bcfxml.version.version_id or "").startswith("2")
|
||||||
|
props.bcf_version = "2" if bcf_v2 else "3"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_by_filepath(cls, filepath: str) -> None:
|
def set_by_filepath(cls, filepath: str) -> None:
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ class NewBcfProject(bpy.types.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
bcfxml = bcf.v2.bcfxml.BcfXml.create_new("New Project")
|
props = context.scene.BCFProperties
|
||||||
|
bcf_v2 = props.bcf_version == "2"
|
||||||
|
bcf_class = bcf.v2.bcfxml.BcfXml if bcf_v2 else bcf.v3.bcfxml.BcfXml
|
||||||
|
bcfxml = bcf_class.create_new("New Project")
|
||||||
bcfstore.BcfStore.set(bcfxml, "")
|
bcfstore.BcfStore.set(bcfxml, "")
|
||||||
bpy.ops.bim.load_bcf_project()
|
bpy.ops.bim.load_bcf_project()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
@@ -65,12 +68,14 @@ class LoadBcfProject(bpy.types.Operator):
|
|||||||
bl_idname = "bim.load_bcf_project"
|
bl_idname = "bim.load_bcf_project"
|
||||||
bl_label = "Load BCF Project"
|
bl_label = "Load BCF Project"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH", options={"SKIP_SAVE"})
|
||||||
filter_glob: bpy.props.StringProperty(default="*.bcf;*.bcfzip", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.bcf;*.bcfzip", options={"HIDDEN"})
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
# Operator is also used when new project is created by not yet saved.
|
||||||
if self.filepath:
|
if self.filepath:
|
||||||
bcfstore.BcfStore.set_by_filepath(self.filepath)
|
bcfstore.BcfStore.set_by_filepath(self.filepath)
|
||||||
|
|
||||||
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||||
assert bcfxml
|
assert bcfxml
|
||||||
bcf_v2 = (bcfxml.version.version_id or "").startswith("2")
|
bcf_v2 = (bcfxml.version.version_id or "").startswith("2")
|
||||||
|
|||||||
@@ -201,6 +201,12 @@ def get_related_topics(self: "BCFProperties", context: bpy.types.Context) -> lis
|
|||||||
|
|
||||||
class BCFProperties(PropertyGroup):
|
class BCFProperties(PropertyGroup):
|
||||||
bcf_file: StringProperty(name="BCF File")
|
bcf_file: StringProperty(name="BCF File")
|
||||||
|
bcf_version: EnumProperty(
|
||||||
|
name="BCF Version",
|
||||||
|
description="Currently loaded BCF project version / BCF version to use for created projects",
|
||||||
|
items=[("2", "v2.1", ""), ("3", "v3.0", "")],
|
||||||
|
default="3",
|
||||||
|
)
|
||||||
comment_text_width: IntProperty(name="Comment Text Width", default=40)
|
comment_text_width: IntProperty(name="Comment Text Width", default=40)
|
||||||
name: StringProperty(default="", name="Project Name", update=updateBcfProjectName)
|
name: StringProperty(default="", name="Project Name", update=updateBcfProjectName)
|
||||||
author: StringProperty(
|
author: StringProperty(
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class BIM_PT_bcf(Panel):
|
|||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator("bim.new_bcf_project", text="New Project")
|
row.operator("bim.new_bcf_project", text="New Project")
|
||||||
row.operator("bim.load_bcf_project", text="Load Project")
|
row.operator("bim.load_bcf_project", text="Load Project")
|
||||||
|
layout.prop(props, "bcf_version")
|
||||||
return
|
return
|
||||||
|
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
@@ -52,6 +53,10 @@ class BIM_PT_bcf(Panel):
|
|||||||
row.operator("bim.save_bcf_project", icon="EXPORT", text="Save Project As...")
|
row.operator("bim.save_bcf_project", icon="EXPORT", text="Save Project As...")
|
||||||
row.operator("bim.unload_bcf_project", text="", icon="CANCEL")
|
row.operator("bim.unload_bcf_project", text="", icon="CANCEL")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(props, "bcf_version", emboss=False)
|
||||||
|
row.enabled = False
|
||||||
|
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(props, "name")
|
row.prop(props, "name")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user