mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
Project libraries UI - use cached project library data
instead of accessing IFC directly on every draw call
This commit is contained in:
@@ -23,7 +23,7 @@ import ifcopenshell.util.file
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
from pathlib import Path
|
||||
from collections import defaultdict
|
||||
from typing import Union
|
||||
from typing import Union, Any
|
||||
|
||||
|
||||
def refresh():
|
||||
@@ -108,6 +108,28 @@ class ProjectData:
|
||||
return 0
|
||||
|
||||
|
||||
class ProjectLibraryData:
|
||||
data: dict[str, Any] = {}
|
||||
is_loaded: bool = False
|
||||
|
||||
@classmethod
|
||||
def load(cls):
|
||||
cls.data = {}
|
||||
cls.data["project_libraries"] = cls.project_libraries()
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def project_libraries(cls) -> dict[int, dict[str, Any]]:
|
||||
results = {}
|
||||
library_file = IfcStore.library_file
|
||||
if library_file is None or library_file.schema == "IFC2X3":
|
||||
return results
|
||||
KEEP_ATTRS = set(("id", "Name", "Description"))
|
||||
for l in library_file.by_type("IfcProjectLibrary"):
|
||||
results[l.id()] = {k: v for k, v in l.get_info().items() if k in KEEP_ATTRS}
|
||||
return results
|
||||
|
||||
|
||||
class LinksData:
|
||||
linked_data = {}
|
||||
enable_culling = False
|
||||
|
||||
@@ -24,7 +24,7 @@ import bonsai.tool as tool
|
||||
from bonsai.bim.helper import prop_with_search
|
||||
from bpy.types import Panel, Menu, UIList
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
from bonsai.bim.module.project.data import ProjectData, LinksData
|
||||
from bonsai.bim.module.project.data import ProjectData, LinksData, ProjectLibraryData
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -463,11 +463,9 @@ class BIM_UL_library(UIList):
|
||||
op = row.operator("bim.change_library_element", text="", icon="DISCLOSURE_TRI_RIGHT", emboss=False)
|
||||
op.element_name = item.name
|
||||
row.label(text=item.name)
|
||||
if (
|
||||
item.ifc_definition_id
|
||||
and IfcStore.library_file.schema != "IFC2X3"
|
||||
and IfcStore.library_file.by_type("IfcProjectLibrary")
|
||||
):
|
||||
if not ProjectLibraryData.is_loaded:
|
||||
ProjectLibraryData.load()
|
||||
if item.ifc_definition_id and ProjectLibraryData.data["project_libraries"]:
|
||||
if item.is_declared:
|
||||
op = row.operator("bim.unassign_library_declaration", text="", icon="KEYFRAME_HLT", emboss=False)
|
||||
op.definition = item.ifc_definition_id
|
||||
|
||||
Reference in New Issue
Block a user