mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
bonsai bcf - dropdown for related topics
Previously you had to type in exactly manually. Besides the dropdown it should also show now a topic description in the dropdown items tooltips. Removed "bim.add_bcf_related_topic" poll as it should be now covered by the enum. Example - https://imgur.com/a/xhgcGWI
This commit is contained in:
@@ -327,11 +327,16 @@ class EditBcfTopic(bpy.types.Operator):
|
||||
topic.topic_status = blender_topic.status or None
|
||||
topic.topic_type = blender_topic.type or None
|
||||
else:
|
||||
error_msg = None
|
||||
if not blender_topic.status:
|
||||
self.report({"INFO"}, "Topic Status field is not optional.")
|
||||
return {"CANCELLED"}
|
||||
error_msg = "Topic Status field is not optional."
|
||||
if not blender_topic.type:
|
||||
self.report({"INFO"}, "Topic Type field is not optional.")
|
||||
error_msg = "Topic Type field is not optional."
|
||||
if error_msg:
|
||||
# Use show_info_message as this operator is not called directly
|
||||
# but from prop callback and user won't see a popup from self.report.
|
||||
tool.Blender.show_info_message(error_msg, "ERROR")
|
||||
self.report({"INFO"}, error_msg)
|
||||
return {"CANCELLED"}
|
||||
topic.topic_status = blender_topic.status
|
||||
topic.topic_type = blender_topic.type
|
||||
@@ -433,33 +438,6 @@ class AddBcfRelatedTopic(bpy.types.Operator):
|
||||
bl_label = "Add BCF Related Topic"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||
assert bcfxml
|
||||
props = context.scene.BCFProperties
|
||||
blender_topic = props.active_topic
|
||||
if not props.related_topic:
|
||||
cls.poll_message_set("Related topic field is empty.")
|
||||
return False
|
||||
if props.related_topic == blender_topic.title:
|
||||
# Prevent adding self as related topic
|
||||
cls.poll_message_set("Cannot add current topic as related topic to itself.")
|
||||
return False
|
||||
related_topic_guid = None
|
||||
for topic in bcfxml.topics.values():
|
||||
if topic.topic.title == props.related_topic:
|
||||
related_topic_guid = topic.guid
|
||||
break
|
||||
if not related_topic_guid:
|
||||
cls.poll_message_set(f"Topic by name '{props.related_topic}' doesn't exist..")
|
||||
return False
|
||||
if str(related_topic_guid) in [t.name for t in blender_topic.related_topics]:
|
||||
cls.poll_message_set("This topic is already added as related")
|
||||
# Prevent adding the same related topic more than once
|
||||
return False
|
||||
return True
|
||||
|
||||
def execute(self, context):
|
||||
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||
assert bcfxml
|
||||
|
||||
@@ -189,6 +189,21 @@ class BcfTopic(PropertyGroup):
|
||||
is_editable: BoolProperty(name="Edit Topic Attributes", default=False, update=updateBcfTopicIsEditable)
|
||||
|
||||
|
||||
def get_related_topics(self: "BCFProperties", context: bpy.types.Context) -> list[tuple[str, str, str]]:
|
||||
props = self
|
||||
active_topic = props.active_topic
|
||||
active_related_topics = active_topic.related_topics.keys()
|
||||
enum_items = []
|
||||
i = 0
|
||||
for t in props.topics:
|
||||
if t.name == active_topic.name:
|
||||
continue
|
||||
if t.name in active_related_topics:
|
||||
continue
|
||||
enum_items.append((t.name, t.title, t.description))
|
||||
return enum_items
|
||||
|
||||
|
||||
class BCFProperties(PropertyGroup):
|
||||
bcf_file: StringProperty(name="BCF File")
|
||||
comment_text_width: IntProperty(name="Comment Text Width", default=40)
|
||||
@@ -211,7 +226,7 @@ class BCFProperties(PropertyGroup):
|
||||
document_reference: StringProperty(default="", name="Referenced Document")
|
||||
document_reference_description: StringProperty(default="", name="Description")
|
||||
document_description: StringProperty(default="", name="Document Description")
|
||||
related_topic: StringProperty(name="Related Topic")
|
||||
related_topic: EnumProperty(name="Related Topic", items=get_related_topics)
|
||||
comment: StringProperty(default="", name="Comment")
|
||||
has_related_viewpoint: BoolProperty(name="Has Related Viewpoint", default=False)
|
||||
|
||||
|
||||
@@ -267,10 +267,14 @@ class BIM_PT_bcf_metadata(Panel):
|
||||
row.operator("bim.remove_bcf_related_topic", icon="X", text="").index = index
|
||||
except KeyError:
|
||||
pass
|
||||
row = layout.row()
|
||||
row.prop(props, "related_topic")
|
||||
row = layout.row()
|
||||
row.operator("bim.add_bcf_related_topic")
|
||||
|
||||
if len(props.topics) == len(topic.related_topics) + 1:
|
||||
layout.label(text="No topics to add as related.")
|
||||
else:
|
||||
row = layout.row()
|
||||
row.prop(props, "related_topic")
|
||||
row = layout.row()
|
||||
row.operator("bim.add_bcf_related_topic")
|
||||
|
||||
|
||||
class BIM_PT_bcf_comments(Panel):
|
||||
|
||||
Reference in New Issue
Block a user