diff --git a/src/bonsai/bonsai/bim/module/constraint/data.py b/src/bonsai/bonsai/bim/module/constraint/data.py index e4ded98bdc..8a92de2c71 100644 --- a/src/bonsai/bonsai/bim/module/constraint/data.py +++ b/src/bonsai/bonsai/bim/module/constraint/data.py @@ -18,6 +18,7 @@ import bpy import bonsai.tool as tool +from ifcopenshell.util.doc import get_entity_doc def refresh(): @@ -31,13 +32,21 @@ class ConstraintsData: @classmethod def load(cls): - cls.data = {"total_objectives": cls.total_objectives()} + cls.data = { + "total_objectives": cls.total_objectives(), + "constraint_types_enum": cls.constraint_types_enum(), + } cls.is_loaded = True @classmethod def total_objectives(cls): return len(tool.Ifc.get().by_type("IfcObjective")) + @classmethod + def constraint_types_enum(cls) -> list[tuple[str, str, str]]: + version = tool.Ifc.get_schema() + return [(c, c, get_entity_doc(version, c).get("description", "")) for c in ["IfcObjective"]] + class ObjectConstraintsData: data = {} diff --git a/src/bonsai/bonsai/bim/module/constraint/prop.py b/src/bonsai/bonsai/bim/module/constraint/prop.py index 361e0a65c7..b773af506a 100644 --- a/src/bonsai/bonsai/bim/module/constraint/prop.py +++ b/src/bonsai/bonsai/bim/module/constraint/prop.py @@ -20,6 +20,7 @@ import bpy from ifcopenshell.util.doc import get_entity_doc import bonsai.tool as tool from bonsai.bim.prop import Attribute +from bonsai.bim.module.constraint.data import ConstraintsData from bpy.types import PropertyGroup from bpy.props import ( PointerProperty, @@ -33,10 +34,10 @@ from bpy.props import ( ) -# TODO: unsafe? def get_available_constraint_types(self, context): - version = tool.Ifc.get_schema() - return [(c, c, get_entity_doc(version, c).get("description", "")) for c in ["IfcObjective"]] + if not ConstraintsData.is_loaded: + ConstraintsData.load() + return ConstraintsData.data["constraint_types_enum"] class Constraint(PropertyGroup): diff --git a/src/bonsai/bonsai/bim/module/owner/data.py b/src/bonsai/bonsai/bim/module/owner/data.py index 01273e7f65..dec6cdd8a9 100644 --- a/src/bonsai/bonsai/bim/module/owner/data.py +++ b/src/bonsai/bonsai/bim/module/owner/data.py @@ -18,6 +18,7 @@ import bpy import bonsai.tool as tool +from ifcopenshell.util.doc import get_entity_doc def refresh(): @@ -219,6 +220,8 @@ class ActorData: cls.data = { "the_actor": cls.the_actor(), "actors": cls.actors(), + "actor_class_enum": cls.actor_class_enum(), + "get_actor_type_enum": cls.get_actor_type_enum(), } cls.is_loaded = True @@ -245,6 +248,27 @@ class ActorData: ) return actors + @classmethod + def actor_class_enum(cls) -> list[tuple[str, str, str]]: + version = tool.Ifc.get_schema() + return [ + ("IfcActor", "Actor", get_entity_doc(version, "IfcActor").get("description", "")), + ("IfcOccupant", "Occupant", get_entity_doc(version, "IfcOccupant").get("description", "")), + ] + + @classmethod + def get_actor_type_enum(cls) -> list[tuple[str, str, str]]: + version = tool.Ifc.get_schema() + return [ + ("IfcPerson", "Person", get_entity_doc(version, "IfcPerson").get("description", "")), + ("IfcOrganization", "Organisation", get_entity_doc(version, "IfcOrganization").get("description", "")), + ( + "IfcPersonAndOrganization", + "User", + get_entity_doc(version, "IfcPersonAndOrganization").get("description", ""), + ), + ] + class ObjectActorData: data = {} diff --git a/src/bonsai/bonsai/bim/module/owner/prop.py b/src/bonsai/bonsai/bim/module/owner/prop.py index e6fa190926..51e4d2871e 100644 --- a/src/bonsai/bonsai/bim/module/owner/prop.py +++ b/src/bonsai/bonsai/bim/module/owner/prop.py @@ -17,7 +17,6 @@ # along with Bonsai. If not, see . import bpy -from ifcopenshell.util.doc import get_entity_doc import bonsai.tool as tool from bonsai.bim.prop import StrProperty, Attribute from bonsai.bim.module.owner.data import OwnerData, ActorData, ObjectActorData @@ -66,27 +65,16 @@ def update_actor_class(self, context): ActorData.data["actors"] = ActorData.actors() -# TODO: unsafe? def get_actor_class_enum(self, context): - version = tool.Ifc.get_schema() - return [ - ("IfcActor", "Actor", get_entity_doc(version, "IfcActor").get("description", "")), - ("IfcOccupant", "Occupant", get_entity_doc(version, "IfcOccupant").get("description", "")), - ] + if not ActorData.is_loaded: + ActorData.load() + return ActorData.data["actor_class_enum"] -# TODO: unsafe? def get_actor_type_enum(self, context): - version = tool.Ifc.get_schema() - return [ - ("IfcPerson", "Person", get_entity_doc(version, "IfcPerson").get("description", "")), - ("IfcOrganization", "Organisation", get_entity_doc(version, "IfcOrganization").get("description", "")), - ( - "IfcPersonAndOrganization", - "User", - get_entity_doc(version, "IfcPersonAndOrganization").get("description", ""), - ), - ] + if not ActorData.is_loaded: + ActorData.load() + return ActorData.data["actor_type_enum"] class BIMOwnerProperties(PropertyGroup):