From e4ba633d94e5ce68d1d6937a6a75af194ceb56d8 Mon Sep 17 00:00:00 2001 From: falken10vdl Date: Fri, 8 Aug 2025 20:28:40 +0200 Subject: [PATCH] cleanup nomenclature and some redundant code --- src/bonsai/bonsai/bim/module/document/data.py | 3 +- .../bonsai/bim/module/document/operator.py | 12 ++--- src/bonsai/bonsai/bim/module/document/ui.py | 4 +- src/bonsai/bonsai/core/document.py | 54 +++++++++---------- src/bonsai/bonsai/tool/document.py | 47 +++++++--------- 5 files changed, 54 insertions(+), 66 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/document/data.py b/src/bonsai/bonsai/bim/module/document/data.py index 7f91247b87..7fc05ca3d1 100644 --- a/src/bonsai/bonsai/bim/module/document/data.py +++ b/src/bonsai/bonsai/bim/module/document/data.py @@ -125,7 +125,6 @@ class ObjectDocumentData: location = None identification = None - description = None if is_information: if tool.Ifc.get_schema() == "IFC2X3": @@ -134,7 +133,7 @@ class ObjectDocumentData: identification = relating_document.Identification location = getattr(relating_document, "Location", None) - + description = getattr(relating_document, "Description", "No description") else: description = relating_document.Description if tool.Ifc.get_schema() == "IFC2X3": diff --git a/src/bonsai/bonsai/bim/module/document/operator.py b/src/bonsai/bonsai/bim/module/document/operator.py index 10eab2f5ed..f63b5e1693 100644 --- a/src/bonsai/bonsai/bim/module/document/operator.py +++ b/src/bonsai/bonsai/bim/module/document/operator.py @@ -60,7 +60,7 @@ class EnableEditingDocument(bpy.types.Operator): document: bpy.props.IntProperty() def execute(self, context): - core.enable_editing_document(tool.Document, document=tool.Ifc.get().by_id(self.document)) + core.enable_editing_document(tool.Document, ifc_document=tool.Ifc.get().by_id(self.document)) return {"FINISHED"} @@ -154,7 +154,7 @@ class EditDocument(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): props = tool.Document.get_document_props() if props.active_document_id: - core.edit_document(tool.Ifc, tool.Document, document=tool.Ifc.get().by_id(props.active_document_id)) + core.edit_document(tool.Ifc, tool.Document, ifc_document=tool.Ifc.get().by_id(props.active_document_id)) props.active_document_id = 0 @@ -165,7 +165,7 @@ class RemoveDocument(bpy.types.Operator, tool.Ifc.Operator): document: bpy.props.IntProperty() def _execute(self, context): - core.remove_document(tool.Ifc, tool.Document, document=tool.Ifc.get().by_id(self.document)) + core.remove_document(tool.Ifc, tool.Document, ifc_document=tool.Ifc.get().by_id(self.document)) class AssignDocument(bpy.types.Operator, tool.Ifc.Operator): @@ -177,12 +177,11 @@ class AssignDocument(bpy.types.Operator, tool.Ifc.Operator): document: bpy.props.IntProperty() def _execute(self, context): - document = tool.Ifc.get().by_id(self.document) objs = [bpy.data.objects[self.obj]] if self.obj else tool.Blender.get_selected_objects() for obj in objs: element = tool.Ifc.get_entity(obj) if element: - core.assign_document(tool.Ifc, product=element, document=document) + core.assign_document(tool.Ifc, product=element, ifc_document=tool.Ifc.get().by_id(self.document)) tool.Document.update_document_objects(self.document) ObjectDocumentData.load() @@ -197,13 +196,12 @@ class UnassignDocument(bpy.types.Operator, tool.Ifc.Operator): document: bpy.props.IntProperty() def _execute(self, context): - document = tool.Ifc.get().by_id(self.document) objs = [bpy.data.objects.get(self.obj)] if self.obj else tool.Blender.get_selected_objects() for obj in objs: if obj: element = tool.Ifc.get_entity(obj) if element: - core.unassign_document(tool.Ifc, product=element, document=document) + core.unassign_document(tool.Ifc, product=element, ifc_document=tool.Ifc.get().by_id(self.document)) props = tool.Document.get_document_props() active_document_id = None diff --git a/src/bonsai/bonsai/bim/module/document/ui.py b/src/bonsai/bonsai/bim/module/document/ui.py index 60e83fdcbe..68a9c5adb2 100644 --- a/src/bonsai/bonsai/bim/module/document/ui.py +++ b/src/bonsai/bonsai/bim/module/document/ui.py @@ -234,10 +234,10 @@ class BIM_UL_documents(UIList): if item.document_type == "INFORMATION": row.label(text="", icon="FILE") - text = " - ".join([x for x in [item.name, item.location] if x]) + text = " - ".join([x for x in [item.location, item.description, item.name] if x]) else: row.label(text="", icon="FILE_HIDDEN") - text = " - ".join([x for x in [item.description, item.location] if x]) + text = " - ".join([x for x in [item.location, item.description] if x]) split1 = row.split(factor=0.1) split1.prop(item, "identification", text="", emboss=False) split2 = split1.split(factor=0.8) diff --git a/src/bonsai/bonsai/core/document.py b/src/bonsai/bonsai/core/document.py index 67680a7a55..7b42295500 100644 --- a/src/bonsai/bonsai/core/document.py +++ b/src/bonsai/bonsai/core/document.py @@ -39,9 +39,9 @@ def disable_object_document_editing_ui(document: tool.Document) -> None: document.disable_object_editing_ui() -def enable_editing_document(document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None: - document_tool.set_active_document(document) - document_tool.import_document_attributes(document) +def enable_editing_document(document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None: + document.set_active_document(ifc_document) + document.import_document_attributes(ifc_document) def disable_editing_document(document: tool.Document) -> None: @@ -49,19 +49,19 @@ def disable_editing_document(document: tool.Document) -> None: document.clear_document_attributes() -def add_information(ifc: tool.Ifc, document_tool: tool.Document, parent=None) -> ifcopenshell.entity_instance: - document_tool.clear_document_tree() +def add_information(ifc: tool.Ifc, document: tool.Document, parent=None) -> ifcopenshell.entity_instance: + document.clear_document_tree() if parent is None: - parent = document_tool.get_default_parent_for_information(ifc) + parent = document.get_default_parent_for_information(ifc) information = ifc.run("document.add_information", parent=parent) ifc.run("document.add_reference", information=information) - if document_tool.is_document_information(parent): - document_tool.expand_document(parent) + if document.is_document_information(parent): + document.expand_document(parent) - document_tool.import_project_documents() + document.import_project_documents() return information @@ -76,33 +76,33 @@ def add_reference(ifc: tool.Ifc, document: tool.Document) -> None: document.import_project_documents() -def edit_document(ifc: tool.Ifc, document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None: - attributes = document_tool.export_document_attributes() - if document_tool.is_document_information(document): - ifc.run("document.edit_information", information=document, attributes=attributes) +def edit_document(ifc: tool.Ifc, document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None: + attributes = document.export_document_attributes() + if document.is_document_information(ifc_document): + ifc.run("document.edit_information", information=ifc_document, attributes=attributes) else: - ifc.run("document.edit_reference", reference=document, attributes=attributes) - document_tool.disable_editing_document() - document_tool.clear_document_tree() - document_tool.import_project_documents() + ifc.run("document.edit_reference", reference=ifc_document, attributes=attributes) + document.disable_editing_document() + document.clear_document_tree() + document.import_project_documents() -def remove_document(ifc: tool.Ifc, document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None: - document_tool.clear_document_tree() - if document_tool.is_document_information(document): - ifc.run("document.remove_information", information=document) +def remove_document(ifc: tool.Ifc, document: tool.Document, ifc_document: ifcopenshell.entity_instance) -> None: + document.clear_document_tree() + if document.is_document_information(ifc_document): + ifc.run("document.remove_information", information=ifc_document) else: - ifc.run("document.remove_reference", reference=document) - document_tool.import_project_documents() + ifc.run("document.remove_reference", reference=ifc_document) + document.import_project_documents() def assign_document( - ifc: tool.Ifc, product: ifcopenshell.entity_instance, document: ifcopenshell.entity_instance + ifc: tool.Ifc, product: ifcopenshell.entity_instance, ifc_document: ifcopenshell.entity_instance ) -> None: - ifc.run("document.assign_document", products=[product], document=document) + ifc.run("document.assign_document", products=[product], document=ifc_document) def unassign_document( - ifc: tool.Ifc, product: ifcopenshell.entity_instance, document: ifcopenshell.entity_instance + ifc: tool.Ifc, product: ifcopenshell.entity_instance, ifc_document: ifcopenshell.entity_instance ) -> None: - ifc.run("document.unassign_document", products=[product], document=document) + ifc.run("document.unassign_document", products=[product], document=ifc_document) diff --git a/src/bonsai/bonsai/tool/document.py b/src/bonsai/bonsai/tool/document.py index 28edfe12e0..f8f45fffcf 100644 --- a/src/bonsai/bonsai/tool/document.py +++ b/src/bonsai/bonsai/tool/document.py @@ -172,30 +172,23 @@ class Document(bonsai.core.tool.Document): new.document_type = "INFORMATION" if document.is_a("IfcDocumentInformation") else "REFERENCE" new.tree_depth = depth - file = document.file + new.name = document.Name or "" + new.identification = cls.get_document_information_id(document) if new.document_type == "INFORMATION" else cls.get_external_reference_id(document) + new.identification = new.identification or "" + new.description = document.Description or "" + new.location = document.Location or "" + if new.document_type == "INFORMATION": new.name = document.Name or "Unnamed" - new.identification = cls.get_document_information_id(document) or "" - new.location = document.Location or "" - else: - new.name = document.Name or "" - new.identification = cls.get_external_reference_id(document) or "" - new.description = document.Description or "" - new.location = document.Location or "" - - if new.document_type == "REFERENCE": - if file.schema == "IFC2X3": - if document.ReferenceToDocument: - doc_info = document.ReferenceToDocument[0] - if not new.name: - new.name = doc_info.Name or "" - new.location = new.location or "" - else: - if document.ReferencedDocument: - doc_info = document.ReferencedDocument - if not new.name: - new.name = doc_info.Name or "" - new.location = new.location or "" + + elif new.document_type == "REFERENCE": + file = document.file + if file.schema == "IFC2X3": + if document.ReferenceToDocument and not new.name: + new.name = document.ReferenceToDocument[0].Name or "" + else: + if document.ReferencedDocument and not new.name: + new.name = document.ReferencedDocument.Name or "" doc_id = document.id() has_children = doc_id in document_children and bool(document_children[doc_id]) @@ -205,16 +198,14 @@ class Document(bonsai.core.tool.Document): if has_children and new.is_expanded: children = document_children[doc_id] - info_children = [d for d in children if d.is_a("IfcDocumentInformation")] - ref_children = [d for d in children if not d.is_a("IfcDocumentInformation")] - info_children = natsorted( - info_children, key=lambda doc: (cls.get_document_information_id(doc) or "", doc.Name or "") + [d for d in children if d.is_a("IfcDocumentInformation")], + key=lambda doc: (cls.get_document_information_id(doc) or "", doc.Name or "") ) ref_children = natsorted( - ref_children, - key=lambda doc: (cls.get_external_reference_id(doc) or "", doc.Description or doc.Name or ""), + [d for d in children if not d.is_a("IfcDocumentInformation")], + key=lambda doc: (cls.get_external_reference_id(doc) or "", doc.Description or doc.Name or "") ) for child in info_children + ref_children: