mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
Implement add BIM Snippet
This commit is contained in:
@@ -523,6 +523,20 @@ class BcfXml:
|
|||||||
topic.bim_snippet = None
|
topic.bim_snippet = None
|
||||||
self.edit_topic(topic)
|
self.edit_topic(topic)
|
||||||
|
|
||||||
|
def add_bim_snippet(self, topic, bim_snippet):
|
||||||
|
if topic.bim_snippet:
|
||||||
|
self.delete_bim_snippet(topic)
|
||||||
|
if os.path.exists(bim_snippet.reference):
|
||||||
|
topic_filepath = os.path.join(self.filepath, topic.guid)
|
||||||
|
filename = os.path.basename(bim_snippet.reference)
|
||||||
|
copyfile(bim_snippet.reference, os.path.join(topic_filepath, filename))
|
||||||
|
bim_snippet.reference = filename
|
||||||
|
bim_snippet.is_external = False
|
||||||
|
else:
|
||||||
|
bim_snippet.is_external = True
|
||||||
|
topic.bim_snippet = bim_snippet
|
||||||
|
self.edit_topic(topic)
|
||||||
|
|
||||||
def add_file(self, topic, header_file):
|
def add_file(self, topic, header_file):
|
||||||
if os.path.exists(header_file.reference):
|
if os.path.exists(header_file.reference):
|
||||||
topic_filepath = os.path.join(self.filepath, topic.guid)
|
topic_filepath = os.path.join(self.filepath, topic.guid)
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ if bpy is not None:
|
|||||||
operator.NewBcfProject,
|
operator.NewBcfProject,
|
||||||
operator.LoadBcfProject,
|
operator.LoadBcfProject,
|
||||||
operator.LoadBcfTopics,
|
operator.LoadBcfTopics,
|
||||||
|
operator.LoadBcfTopic,
|
||||||
operator.LoadBcfComments,
|
operator.LoadBcfComments,
|
||||||
operator.EditBcfProjectName,
|
operator.EditBcfProjectName,
|
||||||
operator.EditBcfAuthor,
|
operator.EditBcfAuthor,
|
||||||
@@ -36,6 +37,7 @@ if bpy is not None:
|
|||||||
operator.SaveBcfProject,
|
operator.SaveBcfProject,
|
||||||
operator.AddBcfTopic,
|
operator.AddBcfTopic,
|
||||||
operator.AddBcfHeaderFile,
|
operator.AddBcfHeaderFile,
|
||||||
|
operator.AddBcfBimSnippet,
|
||||||
operator.AddBcfReferenceLink,
|
operator.AddBcfReferenceLink,
|
||||||
operator.AddBcfLabel,
|
operator.AddBcfLabel,
|
||||||
operator.ViewBcfTopic,
|
operator.ViewBcfTopic,
|
||||||
@@ -54,6 +56,7 @@ if bpy is not None:
|
|||||||
operator.OpenUri,
|
operator.OpenUri,
|
||||||
operator.OpenBcfReferenceLink,
|
operator.OpenBcfReferenceLink,
|
||||||
operator.SelectBcfHeaderFile,
|
operator.SelectBcfHeaderFile,
|
||||||
|
operator.SelectBcfBimSnippetReference,
|
||||||
operator.SelectFeaturesDir,
|
operator.SelectFeaturesDir,
|
||||||
operator.SelectDiffJsonFile,
|
operator.SelectDiffJsonFile,
|
||||||
operator.SelectDiffNewFile,
|
operator.SelectDiffNewFile,
|
||||||
|
|||||||
@@ -561,57 +561,81 @@ class LoadBcfTopics(bpy.types.Operator):
|
|||||||
bcfxml.get_topics()
|
bcfxml.get_topics()
|
||||||
while len(bpy.context.scene.BCFProperties.topics) > 0:
|
while len(bpy.context.scene.BCFProperties.topics) > 0:
|
||||||
bpy.context.scene.BCFProperties.topics.remove(0)
|
bpy.context.scene.BCFProperties.topics.remove(0)
|
||||||
for topic in bcfxml.topics.values():
|
index = 0
|
||||||
|
for topic_guid in bcfxml.topics.keys():
|
||||||
new = bpy.context.scene.BCFProperties.topics.add()
|
new = bpy.context.scene.BCFProperties.topics.add()
|
||||||
|
bpy.ops.bim.load_bcf_topic(topic_guid = topic_guid, topic_index = index)
|
||||||
|
index += 1
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class LoadBcfTopic(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.load_bcf_topic"
|
||||||
|
bl_label = "Load BCF Topics"
|
||||||
|
topic_guid: bpy.props.StringProperty()
|
||||||
|
topic_index: bpy.props.IntProperty()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||||
|
topic = bcfxml.get_topic(self.topic_guid)
|
||||||
|
new = bpy.context.scene.BCFProperties.topics[self.topic_index]
|
||||||
|
data_map = {
|
||||||
|
"name": topic.guid,
|
||||||
|
"title": topic.title,
|
||||||
|
"type": topic.topic_type,
|
||||||
|
"status": topic.topic_status,
|
||||||
|
"priority": topic.priority,
|
||||||
|
"stage": topic.stage,
|
||||||
|
"creation_date": topic.creation_date,
|
||||||
|
"creation_author": topic.creation_author,
|
||||||
|
"modified_date": topic.modified_date,
|
||||||
|
"modified_author": topic.modified_author,
|
||||||
|
"assigned_to": topic.assigned_to,
|
||||||
|
"due_date": topic.due_date,
|
||||||
|
"description": topic.description
|
||||||
|
}
|
||||||
|
for key, value in data_map.items():
|
||||||
|
if value is not None:
|
||||||
|
setattr(new, key, str(value))
|
||||||
|
while len(new.reference_links) > 0:
|
||||||
|
new.reference_links.remove(0)
|
||||||
|
for reference_link in topic.reference_links:
|
||||||
|
new2 = new.reference_links.add()
|
||||||
|
new2.name = reference_link
|
||||||
|
while len(new.labels) > 0:
|
||||||
|
new.labels.remove(0)
|
||||||
|
for label in topic.labels:
|
||||||
|
new2 = new.labels.add()
|
||||||
|
new2.name = label
|
||||||
|
if topic.bim_snippet:
|
||||||
data_map = {
|
data_map = {
|
||||||
"name": topic.guid,
|
"type": topic.bim_snippet.snippet_type,
|
||||||
"title": topic.title,
|
"is_external": topic.bim_snippet.is_external,
|
||||||
"type": topic.topic_type,
|
"reference": topic.bim_snippet.reference,
|
||||||
"status": topic.topic_status,
|
"schema": topic.bim_snippet.reference_schema
|
||||||
"priority": topic.priority,
|
|
||||||
"stage": topic.stage,
|
|
||||||
"creation_date": topic.creation_date,
|
|
||||||
"creation_author": topic.creation_author,
|
|
||||||
"modified_date": topic.modified_date,
|
|
||||||
"modified_author": topic.modified_author,
|
|
||||||
"assigned_to": topic.assigned_to,
|
|
||||||
"due_date": topic.due_date,
|
|
||||||
"description": topic.description
|
|
||||||
}
|
}
|
||||||
for key, value in data_map.items():
|
for key, value in data_map.items():
|
||||||
if value is not None:
|
if value is not None:
|
||||||
setattr(new, key, str(value))
|
setattr(new.bim_snippet, key, value)
|
||||||
for reference_link in topic.reference_links:
|
while len(new.document_references) > 0:
|
||||||
new2 = new.reference_links.add()
|
new.document_references.remove(0)
|
||||||
new2.name = reference_link
|
for doc in topic.document_references:
|
||||||
for label in topic.labels:
|
new2 = new.document_references.add()
|
||||||
new2 = new.labels.add()
|
data_map = {
|
||||||
new2.name = label
|
"reference": doc.referenced_document,
|
||||||
if topic.bim_snippet:
|
"description": doc.description,
|
||||||
data_map = {
|
"guid": doc.guid,
|
||||||
"type": topic.bim_snippet.snippet_type,
|
"is_external": doc.is_external
|
||||||
"is_external": topic.bim_snippet.is_external,
|
}
|
||||||
"reference": topic.bim_snippet.reference,
|
for key, value in data_map.items():
|
||||||
"schema": topic.bim_snippet.reference_schema
|
if value is not None:
|
||||||
}
|
setattr(new2, key, value)
|
||||||
for key, value in data_map.items():
|
while len(new.related_topics) > 0:
|
||||||
if value is not None:
|
new.related_topics.remove(0)
|
||||||
setattr(new.bim_snippet, key, value)
|
for related_topic in topic.related_topics:
|
||||||
for doc in topic.document_references:
|
new2 = new.related_topics.add()
|
||||||
new2 = new.document_references.add()
|
new2.name = related_topic.guid
|
||||||
data_map = {
|
bpy.ops.bim.load_bcf_comments(topic_guid = topic.guid)
|
||||||
"reference": doc.referenced_document,
|
|
||||||
"description": doc.description,
|
|
||||||
"guid": doc.guid,
|
|
||||||
"is_external": doc.is_external
|
|
||||||
}
|
|
||||||
for key, value in data_map.items():
|
|
||||||
if value is not None:
|
|
||||||
setattr(new2, key, value)
|
|
||||||
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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
@@ -730,6 +754,24 @@ class AddBcfTopic(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AddBcfBimSnippet(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.add_bcf_bim_snippet"
|
||||||
|
bl_label = "Add BCF BIM Snippet"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
bcfxml = bcfstore.BcfStore.get_bcfxml()
|
||||||
|
props = bpy.context.scene.BCFProperties
|
||||||
|
blender_topic = props.topics[props.active_topic_index]
|
||||||
|
topic = bcfxml.topics[blender_topic.name]
|
||||||
|
bim_snippet = bcf.data.BimSnippet()
|
||||||
|
bim_snippet.reference = blender_topic.bim_snippet_reference
|
||||||
|
bim_snippet.reference_schema = blender_topic.bim_snippet_schema
|
||||||
|
bim_snippet.snippet_type = blender_topic.bim_snippet_type
|
||||||
|
bcfxml.add_bim_snippet(topic, bim_snippet)
|
||||||
|
bpy.ops.bim.load_bcf_topic(topic_guid = topic.guid, topic_index = props.active_topic_index)
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddBcfHeaderFile(bpy.types.Operator):
|
class AddBcfHeaderFile(bpy.types.Operator):
|
||||||
bl_idname = "bim.add_bcf_header_file"
|
bl_idname = "bim.add_bcf_header_file"
|
||||||
bl_label = "Add BCF Header File"
|
bl_label = "Add BCF Header File"
|
||||||
@@ -852,10 +894,9 @@ class AddBcfReferenceLink(bpy.types.Operator):
|
|||||||
topic = bcfxml.topics[blender_topic.name]
|
topic = bcfxml.topics[blender_topic.name]
|
||||||
if not blender_topic.reference_link:
|
if not blender_topic.reference_link:
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
new = blender_topic.reference_links.add()
|
|
||||||
new.name = blender_topic.reference_link
|
|
||||||
topic.reference_links.append(blender_topic.reference_link)
|
topic.reference_links.append(blender_topic.reference_link)
|
||||||
bcfxml.edit_topic(topic)
|
bcfxml.edit_topic(topic)
|
||||||
|
bpy.ops.bim.load_bcf_topic(topic_guid = topic.guid, topic_index = props.active_topic_index)
|
||||||
blender_topic.reference_link = ""
|
blender_topic.reference_link = ""
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
@@ -2454,7 +2495,6 @@ class SelectBcfHeaderFile(bpy.types.Operator):
|
|||||||
bl_idname = "bim.select_bcf_header_file"
|
bl_idname = "bim.select_bcf_header_file"
|
||||||
bl_label = "Select BCF Header File"
|
bl_label = "Select BCF Header File"
|
||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
target: bpy.props.StringProperty()
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
if self.filepath:
|
if self.filepath:
|
||||||
@@ -2468,6 +2508,23 @@ class SelectBcfHeaderFile(bpy.types.Operator):
|
|||||||
return {"RUNNING_MODAL"}
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
|
||||||
|
class SelectBcfBimSnippetReference(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.select_bcf_bim_snippet_reference"
|
||||||
|
bl_label = "Select BCF BIM Snippet Reference"
|
||||||
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
if self.filepath:
|
||||||
|
props = bpy.context.scene.BCFProperties
|
||||||
|
topic = props.topics[props.active_topic_index]
|
||||||
|
topic.bim_snippet_reference = self.filepath
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
context.window_manager.fileselect_add(self)
|
||||||
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
|
||||||
class SelectFeaturesDir(bpy.types.Operator):
|
class SelectFeaturesDir(bpy.types.Operator):
|
||||||
bl_idname = "bim.select_features_dir"
|
bl_idname = "bim.select_features_dir"
|
||||||
bl_label = "Select Features Directory"
|
bl_label = "Select Features Directory"
|
||||||
|
|||||||
@@ -1037,6 +1037,9 @@ class BcfTopic(PropertyGroup):
|
|||||||
labels: CollectionProperty(name="Labels", type=BcfLabel)
|
labels: CollectionProperty(name="Labels", type=BcfLabel)
|
||||||
label: StringProperty(default="", name="Label")
|
label: StringProperty(default="", name="Label")
|
||||||
bim_snippet: PointerProperty(type=BcfBimSnippet)
|
bim_snippet: PointerProperty(type=BcfBimSnippet)
|
||||||
|
bim_snippet_type: StringProperty(default="", name="Type")
|
||||||
|
bim_snippet_reference: StringProperty(default="", name="Reference")
|
||||||
|
bim_snippet_schema: StringProperty(default="", name="Schema")
|
||||||
document_references: CollectionProperty(name="Document References", type=BcfDocumentReference)
|
document_references: CollectionProperty(name="Document References", type=BcfDocumentReference)
|
||||||
related_topics: CollectionProperty(name="Related Topics", type=StrProperty)
|
related_topics: CollectionProperty(name="Related Topics", type=StrProperty)
|
||||||
comments: CollectionProperty(name="Comments", type=BcfComment)
|
comments: CollectionProperty(name="Comments", type=BcfComment)
|
||||||
|
|||||||
@@ -1827,6 +1827,17 @@ class BIM_PT_bcf_metadata(Panel):
|
|||||||
op = row.operator("bim.open_uri", icon="FILE_FOLDER", text="")
|
op = row.operator("bim.open_uri", icon="FILE_FOLDER", text="")
|
||||||
op.uri = os.path.join(bcfxml.filepath, topic.name, topic.bim_snippet.reference)
|
op.uri = os.path.join(bcfxml.filepath, topic.name, topic.bim_snippet.reference)
|
||||||
row.operator("bim.remove_bcf_bim_snippet", icon="X", text="")
|
row.operator("bim.remove_bcf_bim_snippet", icon="X", text="")
|
||||||
|
else:
|
||||||
|
row = layout.row(align=True)
|
||||||
|
row.prop(topic, "bim_snippet_reference")
|
||||||
|
row.operator("bim.select_bcf_bim_snippet_reference", icon="FILE_FOLDER", text="")
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(topic, "bim_snippet_type")
|
||||||
|
row = layout.row()
|
||||||
|
row.prop(topic, "bim_snippet_schema")
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.operator("bim.add_bcf_bim_snippet")
|
||||||
|
|
||||||
if topic.document_references:
|
if topic.document_references:
|
||||||
layout.label(text="Document References:")
|
layout.label(text="Document References:")
|
||||||
|
|||||||
Reference in New Issue
Block a user