From 4f2bf3a36f2a260f0ffcf7a4991f19b1e3f6db79 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 14 Dec 2020 13:29:52 +1100 Subject: [PATCH] You can now add new BCF topics to a BCF project --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/operator.py | 20 +++++++++++++++++-- src/ifcblenderexport/blenderbim/bim/prop.py | 12 ++++++++--- src/ifcblenderexport/blenderbim/bim/ui.py | 5 ++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 6c908b6078..07e5b318ce 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -27,6 +27,7 @@ if bpy is not None: operator.SelectType, operator.LoadBcfProject, operator.SaveBcfProject, + operator.AddBcfTopic, operator.ViewBcfTopic, operator.ActivateBcfViewpoint, operator.OpenBcfFileReference, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 81da0e7dba..016c9e1a31 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -517,13 +517,14 @@ class LoadBcfProject(bpy.types.Operator): bcfplugin.openProject(self.filepath) bcf.BcfStore.topics = bcfplugin.getTopics() + bpy.context.scene.BCFProperties.is_editable = False + bpy.context.scene.BCFProperties.name = bcfplugin.getProjectName() while len(bpy.context.scene.BCFProperties.topics) > 0: bpy.context.scene.BCFProperties.topics.remove(0) for topic in bcf.BcfStore.topics: new = bpy.context.scene.BCFProperties.topics.add() new.name = topic[0] - # Note: set this last, as we use it to check whether or not the project has been loaded - bpy.context.scene.BCFProperties.name = bcfplugin.getProjectName() + bpy.context.scene.BCFProperties.is_editable = True return {"FINISHED"} def invoke(self, context, event): @@ -546,6 +547,21 @@ class SaveBcfProject(bpy.types.Operator): return {"RUNNING_MODAL"} +class AddBcfTopic(bpy.types.Operator): + bl_idname = "bim.add_bcf_topic" + bl_label = "Add BCF Topic" + + def execute(self, context): + import bcfplugin + bcfplugin.addTopic("New Topic", bpy.context.scene.BCFProperties.author) + bpy.context.scene.BCFProperties.is_editable = False + new = bpy.context.scene.BCFProperties.topics.add() + new.name = "New Topic" + bcf.BcfStore.topics = bcfplugin.getTopics() + bpy.context.scene.BCFProperties.is_editable = True + return {"FINISHED"} + + class ViewBcfTopic(bpy.types.Operator): bl_idname = "bim.view_bcf_topic" bl_label = "Get BCF Topic" diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index ee4659832b..15500500bb 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -916,6 +916,8 @@ def updateBcfProjectName(self, context): def updateBcfTopicAttribute(context, name, value): + if not bpy.context.scene.BCFProperties.is_editable: + return import bcfplugin props = bpy.context.scene.BCFProperties topic = bcf.BcfStore.topics[props.active_topic_index][1] @@ -925,8 +927,7 @@ def updateBcfTopicAttribute(context, name, value): def updateBcfTopicName(self, context): - if bpy.context.scene.BCFProperties.name: - updateBcfTopicAttribute(context, "title", self.name) + updateBcfTopicAttribute(context, "title", self.name) def updateBcfTopicType(self, context): @@ -945,6 +946,10 @@ def updateBcfTopicStage(self, context): updateBcfTopicAttribute(context, "stage", self.topic_stage) +def updateBcfTopicDescription(self, context): + updateBcfTopicAttribute(context, "description", self.topic_description) + + class BcfTopic(PropertyGroup): name: StringProperty(name="Name", update=updateBcfTopicName) @@ -1634,6 +1639,7 @@ class BIMProperties(PropertyGroup): class BCFProperties(PropertyGroup): + is_editable: BoolProperty(name="Is Editable", default=False) name: StringProperty(default="", name="Project Name", update=updateBcfProjectName) author: StringProperty(default="john@doe.com", name="Author Email") topics: CollectionProperty(name="BCF Topics", type=BcfTopic) @@ -1650,7 +1656,7 @@ class BCFProperties(PropertyGroup): topic_modified_author: StringProperty(default="", name="Topic Modified By") topic_assigned_to: StringProperty(default="", name="Topic Assigned To") topic_due_date: StringProperty(default="", name="Topic Due Date") - topic_description: StringProperty(default="", name="Topic Description") + topic_description: StringProperty(default="", name="Topic Description", update=updateBcfTopicDescription) topic_labels: CollectionProperty(name="BCF Topic Labels", type=BcfTopicLabel) topic_files: CollectionProperty(name="BCF Topic Files", type=BcfTopicFile) topic_links: CollectionProperty(name="BCF Topic Links", type=BcfTopicLink) diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 6e0eed1fd4..67ede77508 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -1678,7 +1678,10 @@ class BIM_PT_bcf(Panel): return props = bpy.context.scene.BCFProperties - layout.template_list("BIM_UL_topics", "", props, "topics", props, "active_topic_index") + row = layout.row() + row.template_list("BIM_UL_topics", "", props, "topics", props, "active_topic_index") + col = row.column(align=True) + col.operator("bim.add_bcf_topic", icon="ADD", text="") row = layout.row() row.prop(props, "topic_description", text="")