From de4f18e2af4142aeba0535f031a26aef175992e1 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 18 Dec 2020 22:12:13 +1100 Subject: [PATCH] New UI to show BCF comments in the BCF panel as a subpanel --- .../blenderbim/bim/__init__.py | 3 + .../blenderbim/bim/operator.py | 31 ++++++++++- src/ifcblenderexport/blenderbim/bim/prop.py | 20 +++++-- src/ifcblenderexport/blenderbim/bim/ui.py | 55 +++++++++++++++++-- 4 files changed, 98 insertions(+), 11 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 0a0c216529..075f00d236 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -28,6 +28,7 @@ if bpy is not None: operator.NewBcfProject, operator.LoadBcfProject, operator.LoadBcfTopics, + operator.LoadBcfComments, operator.SaveBcfProject, operator.AddBcfTopic, operator.ViewBcfTopic, @@ -260,6 +261,7 @@ if bpy is not None: prop.Sheet, prop.BcfBimSnippet, prop.BcfDocumentReference, + prop.BcfComment, prop.BcfTopic, prop.Subcontext, prop.PresentationLayer, @@ -295,6 +297,7 @@ if bpy is not None: ui.BIM_PT_ifccsv, ui.BIM_PT_ifcclash, ui.BIM_PT_bcf, + ui.BIM_PT_bcf_comments, ui.BIM_PT_owner, ui.BIM_PT_people, ui.BIM_PT_organisations, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 5c2b750aa1..aa2ccc7d77 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -550,8 +550,8 @@ class LoadBcfTopics(bpy.types.Operator): for topic in bcfxml.topics.values(): new = bpy.context.scene.BCFProperties.topics.add() data_map = { - "name": topic.title, - "guid": topic.guid, + "name": topic.guid, + "title": topic.title, "type": topic.topic_type, "status": topic.topic_status, "priority": topic.priority, @@ -597,6 +597,33 @@ class LoadBcfTopics(bpy.types.Operator): for related_topic in topic.related_topics: new2 = new.related_topics.add() new2.name = related_topic.guid + bpy.ops.bim.load_bcf_comments(topic_guid = topic.guid) + return {"FINISHED"} + + +class LoadBcfComments(bpy.types.Operator): + bl_idname = "bim.load_bcf_comments" + bl_label = "Load BCF Comments" + topic_guid: bpy.props.StringProperty() + + def execute(self, context): + bcfxml = bcfstore.BcfStore.get_bcfxml() + bcfxml.get_comments(self.topic_guid) + blender_topic = bpy.context.scene.BCFProperties.topics.get(self.topic_guid) + for comment in bcfxml.topics[self.topic_guid].comments.values(): + new = blender_topic.comments.add() + data_map = { + "name": comment.guid, + "comment": comment.comment, + "viewpoint": comment.viewpoint.guid if comment.viewpoint else None, + "date": comment.date, + "author": comment.author, + "modified_date": comment.modified_date, + "modified_author": comment.modified_author, + } + for key, value in data_map.items(): + if value is not None: + setattr(new, key, str(value)) return {"FINISHED"} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index b7d167f6aa..1d3f421664 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -917,7 +917,7 @@ def getBcfViewpoints(self, context): props = bpy.context.scene.BCFProperties bcfxml = bcfstore.BcfStore.get_bcfxml() topic = props.topics[props.active_topic_index] - viewpoints = bcfxml.get_viewpoints(topic.guid) + viewpoints = bcfxml.get_viewpoints(topic.name) bcfviewpoints_enum.extend([(v, f"Viewpoint {i+1}", "") for i, v in enumerate(viewpoints.keys())]) return bcfviewpoints_enum @@ -936,9 +936,19 @@ class BcfDocumentReference(PropertyGroup): is_external: BoolProperty(name="Is External") +class BcfComment(PropertyGroup): + name: StringProperty(name="GUID") + date: StringProperty(name="Date") + author: StringProperty(name="Author") + comment: StringProperty(name="Comment") + viewpoint: StringProperty(name="Viewpoint") + modified_date: StringProperty(name="Modified Date") + modified_author: StringProperty(name="Modified Author") + + class BcfTopic(PropertyGroup): - name: StringProperty(name="Name") - guid: StringProperty(default="", name="GUID") + name: StringProperty(name="GUID") + title: StringProperty(default="", name="Title") type: StringProperty(default="", name="Type") status: StringProperty(default="", name="Status") priority: StringProperty(default="", name="Priority") @@ -957,6 +967,7 @@ class BcfTopic(PropertyGroup): bim_snippet: PointerProperty(type=BcfBimSnippet) document_references: CollectionProperty(name="Document References", type=BcfDocumentReference) related_topics: CollectionProperty(name="Related Topics", type=StrProperty) + comments: CollectionProperty(name="Comments", type=BcfComment) def refreshBcfTopic(self, context): @@ -966,7 +977,7 @@ def refreshBcfTopic(self, context): props = bpy.context.scene.BCFProperties bcfxml = bcfstore.BcfStore.get_bcfxml() topic = props.topics[props.active_topic_index] - header = bcfxml.get_header(topic.guid) + header = bcfxml.get_header(topic.name) getBcfViewpoints(self, context) @@ -1478,6 +1489,7 @@ class BIMProperties(PropertyGroup): class BCFProperties(PropertyGroup): is_editable: BoolProperty(name="Is Editable", default=False) is_loaded: BoolProperty(name="Is Loaded", default=False) + comment_text_width: IntProperty(name="Comment Text Width", default=40) name: StringProperty(default="", name="Project Name") author: StringProperty(default="john@doe.com", name="Author Email") topics: CollectionProperty(name="BCF Topics", type=BcfTopic) diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index af4ba16f44..12c0ee2278 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -1708,7 +1708,7 @@ class BIM_PT_bcf(Panel): col.prop(topic, "modified_author") bcfxml = bcfstore.BcfStore.get_bcfxml() - bcf_topic = bcfxml.topics[topic.guid] + bcf_topic = bcfxml.topics[topic.name] if bcf_topic.header: layout.label(text="Header Files:") @@ -1720,7 +1720,7 @@ class BIM_PT_bcf(Panel): row.operator("bim.open_uri", icon="URL", text="").uri = f.reference else: op = row.operator("bim.open_uri", icon="FILE_FOLDER", text="") - op.uri = os.path.join(bcfxml.filepath, topic.guid, f.reference) + op.uri = os.path.join(bcfxml.filepath, topic.name, f.reference) box.label(text=f.date) #box.label(text=f.ifc_project) #box.label(text=f.ifc_spatial_structure_element) @@ -1751,7 +1751,7 @@ class BIM_PT_bcf(Panel): row.operator("bim.open_uri", icon="URL", text="").uri = topic.bim_snippet.reference else: op = row.operator("bim.open_uri", icon="FILE_FOLDER", text="") - op.uri = os.path.join(bcfxml.filepath, topic.guid, topic.bim_snippet.reference) + op.uri = os.path.join(bcfxml.filepath, topic.name, topic.bim_snippet.reference) if topic.document_references: layout.label(text="Document References:") @@ -1763,7 +1763,7 @@ class BIM_PT_bcf(Panel): row.operator("bim.open_uri", icon="URL", text="").uri = doc.reference else: op = row.operator("bim.open_uri", icon="FILE_FOLDER", text="") - op.uri = os.path.join(bcfxml.filepath, topic.guid, doc.reference) + op.uri = os.path.join(bcfxml.filepath, topic.name, doc.reference) row = box.row(align=True) row.prop(doc, "description") @@ -1774,6 +1774,51 @@ class BIM_PT_bcf(Panel): row.operator("bim.view_bcf_topic", text=related_topic.name).topic_guid = related_topic.name +class BIM_PT_bcf_comments(Panel): + bl_label = "BCF Comments" + bl_idname = "BIM_PT_bcf_comments" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_bcf" + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + + scene = context.scene + props = bpy.context.scene.BCFProperties + + if props.active_topic_index >= len(props.topics): + layout.label(text="No BCF project is loaded") + return + + row = layout.row() + row.prop(props, "comment_text_width") + + topic = props.topics[props.active_topic_index] + for comment in topic.comments: + box = self.layout.box() + box.separator() + author_text = "{} ({})".format(comment.author, comment.date) + if comment.modified_author: + author_text = "*{} ({})".format(comment.modified_author, comment.modified_date) + box.label(text=author_text, icon="WORDWRAP_ON") + box.separator() + box.scale_y = 0.5 + words = comment.comment.split() + while words: + total_line_chars = 0 + line_words = [] + while words and total_line_chars < props.comment_text_width: + word = words.pop(0) + line_words.append(word) + total_line_chars += len(word) + 1 # 1 is for the space + box.label(text=" ".join(line_words)) + box.separator() + + class BIM_PT_qa(Panel): bl_label = "BIMTester Quality Auditing" bl_idname = "BIM_PT_qa" @@ -2105,7 +2150,7 @@ class BIM_UL_topics(bpy.types.UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): ob = data if item: - layout.prop(item, "name", text="", emboss=False) + layout.prop(item, "title", text="", emboss=False) else: layout.label(text="", translate=False)