diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index eb8d9fa6e4..e76b512de3 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -55,7 +55,6 @@ def draw_attributes( layout: bpy.types.UILayout, copy_operator: Optional[str] = None, popup_active_attribute: Optional[bonsai.bim.prop.Attribute] = None, - filter_attributes: list[str] = None, callback: Optional[Callable[[bonsai.bim.prop.Attribute, bpy.types.UILayout], None]] = None, *, enable_search: Union[bool, EllipsisType] = ..., @@ -76,8 +75,6 @@ def draw_attributes( """ for attribute in props: - if attribute.name in (filter_attributes or []): - continue row = layout.row(align=True) if attribute == popup_active_attribute: row.activate_init = True diff --git a/src/bonsai/bonsai/bim/module/document/data.py b/src/bonsai/bonsai/bim/module/document/data.py index 0ba0106881..7f91247b87 100644 --- a/src/bonsai/bonsai/bim/module/document/data.py +++ b/src/bonsai/bonsai/bim/module/document/data.py @@ -24,6 +24,11 @@ import bonsai.tool as tool from natsort import natsorted +def refresh(): + DocumentData.is_loaded = False + ObjectDocumentData.is_loaded = False + + class DocumentData: data = {} is_loaded = False @@ -32,7 +37,6 @@ class DocumentData: def load(cls): cls.data = { "total_documents": cls.total_documents(), - "total_referenced_objects": cls.total_referenced_objects(), "document_objects": cls.document_objects(), } cls.is_loaded = True @@ -42,19 +46,6 @@ class DocumentData: file = tool.Ifc.get() return len(file.by_type("IfcDocumentInformation")) + len(file.by_type("IfcDocumentReference")) - @classmethod - def total_referenced_objects(cls): - file = tool.Ifc.get() - document_rels = file.by_type("IfcRelAssociatesDocument") - documented_objects = set() - for rel in document_rels: - for related_object in rel.RelatedObjects: - obj = tool.Ifc.get_object(related_object) - if obj: - documented_objects.add(related_object.id()) - - return len(documented_objects) - @classmethod def document_objects(cls): document_objects = {} diff --git a/src/bonsai/bonsai/bim/module/document/operator.py b/src/bonsai/bonsai/bim/module/document/operator.py index c2ccd5edc9..10eab2f5ed 100644 --- a/src/bonsai/bonsai/bim/module/document/operator.py +++ b/src/bonsai/bonsai/bim/module/document/operator.py @@ -21,8 +21,7 @@ import json import bonsai.bim.handler import bonsai.tool as tool import bonsai.core.document as core -from .data import DocumentData, ObjectDocumentData - +from bonsai.bim.module.document.data import DocumentData, ObjectDocumentData class LoadProjectDocuments(bpy.types.Operator): bl_idname = "bim.load_project_documents" @@ -186,7 +185,6 @@ class AssignDocument(bpy.types.Operator, tool.Ifc.Operator): core.assign_document(tool.Ifc, product=element, document=document) tool.Document.update_document_objects(self.document) - ObjectDocumentData.is_loaded = False ObjectDocumentData.load() return {"FINISHED"} @@ -217,7 +215,6 @@ class UnassignDocument(bpy.types.Operator, tool.Ifc.Operator): else: tool.Document.update_document_objects() - ObjectDocumentData.is_loaded = False ObjectDocumentData.load() return {"FINISHED"} @@ -255,7 +252,6 @@ class LoadObjectDocuments(bpy.types.Operator): props = tool.Document.get_document_props() props.is_object_editing = True - ObjectDocumentData.is_loaded = False ObjectDocumentData.load() return {"FINISHED"} @@ -276,27 +272,23 @@ class OpenIFCDocument(bpy.types.Operator): self.report({"ERROR"}, "Only local file:// URIs are supported") return {"CANCELLED"} - filepath = self.uri[7:] # Remove file:// prefix + filepath = self.uri[7:] if not os.path.exists(filepath): self.report({"ERROR"}, f"File not found: {filepath}") return {"CANCELLED"} - try: - blender_path = bpy.app.binary_path - args = [ - blender_path, - "--python-expr", - "import bpy; bpy.ops.bim.load_project(filepath='{}')".format(filepath), - ] - subprocess.Popen(args) - self.report({"INFO"}, f"Opening {filepath} in a new Blender instance") - except Exception as e: - self.report({"ERROR"}, f"Failed to open IFC file: {str(e)}") + blender_path = bpy.app.binary_path + args = [ + blender_path, + "--python-expr", + "import bpy; bpy.ops.bim.load_project(filepath='{}')".format(filepath), + ] + subprocess.Popen(args) + self.report({"INFO"}, f"Opening {filepath} in a new Blender instance") return {"FINISHED"} - class ToggleDocument(bpy.types.Operator): bl_idname = "bim.toggle_document" bl_label = "Toggle Document" diff --git a/src/bonsai/bonsai/bim/module/document/prop.py b/src/bonsai/bonsai/bim/module/document/prop.py index 5d9a978c69..93369b546d 100644 --- a/src/bonsai/bonsai/bim/module/document/prop.py +++ b/src/bonsai/bonsai/bim/module/document/prop.py @@ -1,24 +1,7 @@ -# Bonsai - OpenBIM Blender Add-on -# Copyright (C) 2020, 2021 Dion Moult -# -# This file is part of Bonsai. -# -# Bonsai is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Bonsai is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Bonsai. If not, see . - import bpy import bonsai.tool as tool from bonsai.bim.prop import StrProperty, Attribute +from bonsai.bim.module.document.data import refresh from bpy.types import PropertyGroup from bpy.props import ( PointerProperty, @@ -50,7 +33,8 @@ def update_document_identification(self: "Document", context: bpy.types.Context) tool.Document.set_external_reference_id(document, self.identification) -def update_active_document(self, context): +def update_active_document_index(self, context): + refresh() if document := self.active_document: if document.ifc_definition_id: DocumentData.load_document_objects_into_props(document.ifc_definition_id) @@ -100,7 +84,7 @@ class BIMDocumentProperties(PropertyGroup): document_attributes: CollectionProperty(name="Document Attributes", type=Attribute) active_document_id: IntProperty(name="Active Document Id") documents: CollectionProperty(name="Documents", type=Document) - active_document_index: IntProperty(name="Active Document Index", update=update_active_document) + active_document_index: IntProperty(name="Active Document Index", update=update_active_document_index) is_editing: BoolProperty(name="Is Editing", default=False) is_object_editing: BoolProperty(name="Is Object Editing", default=False) document_objects: CollectionProperty(name="Document Objects", type=DocumentObject) diff --git a/src/bonsai/bonsai/bim/module/document/ui.py b/src/bonsai/bonsai/bim/module/document/ui.py index 84f7d04632..60e83fdcbe 100644 --- a/src/bonsai/bonsai/bim/module/document/ui.py +++ b/src/bonsai/bonsai/bim/module/document/ui.py @@ -20,8 +20,7 @@ import bpy import bonsai.tool as tool from bpy.types import Panel, UIList from bonsai.bim.helper import draw_attributes -from .data import DocumentData, ObjectDocumentData - +from bonsai.bim.module.document.data import DocumentData, ObjectDocumentData class BIM_PT_documents(Panel): bl_label = "Documents" @@ -43,18 +42,12 @@ class BIM_PT_documents(Panel): self.props = tool.Document.get_document_props() row = self.layout.row(align=True) - split = row.split(factor=0.55) - - left_row = split.row(align=True) - left_row.label(text="{} Documents".format(DocumentData.data["total_documents"]), icon="FILE") - right_row = split.row(align=True) - right_row.label( - text="{} Objects Referenced".format(DocumentData.data["total_referenced_objects"]), icon="OBJECT_DATA" - ) + row.label(text="{} Documents found".format(DocumentData.data["total_documents"]), icon="FILE") + if self.props.is_editing: - right_row.operator("bim.disable_document_editing_ui", text="", icon="CANCEL") + row.operator("bim.disable_document_editing_ui", text="", icon="CANCEL") else: - right_row.operator("bim.load_project_documents", text="", icon="IMPORT") + row.operator("bim.load_project_documents", text="", icon="IMPORT") if not self.props.is_editing: return diff --git a/src/bonsai/bonsai/core/document.py b/src/bonsai/bonsai/core/document.py index 07a167c785..67680a7a55 100644 --- a/src/bonsai/bonsai/core/document.py +++ b/src/bonsai/bonsai/core/document.py @@ -36,18 +36,15 @@ def disable_document_editing_ui(document: tool.Document) -> None: def disable_object_document_editing_ui(document: tool.Document) -> None: - props = document.get_document_props() - props.is_object_editing = False + document.disable_object_editing_ui() def enable_editing_document(document_tool: tool.Document, document: ifcopenshell.entity_instance) -> None: - props = document_tool.get_document_props() document_tool.set_active_document(document) document_tool.import_document_attributes(document) def disable_editing_document(document: tool.Document) -> None: - props = document.get_document_props() document.clear_active_document() document.clear_document_attributes() diff --git a/src/bonsai/bonsai/tool/document.py b/src/bonsai/bonsai/tool/document.py index bbc20663dc..28edfe12e0 100644 --- a/src/bonsai/bonsai/tool/document.py +++ b/src/bonsai/bonsai/tool/document.py @@ -19,6 +19,7 @@ from __future__ import annotations import bpy import ifcopenshell.util.system +import bonsai.bim.helper import bonsai.core.tool import bonsai.tool as tool import json @@ -44,6 +45,11 @@ class Document(bonsai.core.tool.Document): props = cls.get_document_props() props.active_document_id = 0 + @classmethod + def disable_object_editing_ui(cls) -> None: + props = cls.get_document_props() + props.is_object_editing = False + @classmethod def disable_editing_ui(cls) -> None: props = cls.get_document_props()