mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
updates based on core developer's feedback
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,24 +1,7 @@
|
||||
# Bonsai - OpenBIM Blender Add-on
|
||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user