Optimize enums by moving them to data.py

This commit is contained in:
Andrej730
2024-11-01 14:24:40 +05:00
parent 9c0256165e
commit caeabe2cd5
4 changed files with 44 additions and 22 deletions
@@ -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 = {}
@@ -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):
@@ -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 = {}
+6 -18
View File
@@ -17,7 +17,6 @@
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
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):