mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Optimize enums by moving them to data.py
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
from ifcopenshell.util.doc import get_entity_doc
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -31,13 +32,21 @@ class ConstraintsData:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load(cls):
|
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
|
cls.is_loaded = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def total_objectives(cls):
|
def total_objectives(cls):
|
||||||
return len(tool.Ifc.get().by_type("IfcObjective"))
|
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:
|
class ObjectConstraintsData:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import bpy
|
|||||||
from ifcopenshell.util.doc import get_entity_doc
|
from ifcopenshell.util.doc import get_entity_doc
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.prop import Attribute
|
from bonsai.bim.prop import Attribute
|
||||||
|
from bonsai.bim.module.constraint.data import ConstraintsData
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup
|
||||||
from bpy.props import (
|
from bpy.props import (
|
||||||
PointerProperty,
|
PointerProperty,
|
||||||
@@ -33,10 +34,10 @@ from bpy.props import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: unsafe?
|
|
||||||
def get_available_constraint_types(self, context):
|
def get_available_constraint_types(self, context):
|
||||||
version = tool.Ifc.get_schema()
|
if not ConstraintsData.is_loaded:
|
||||||
return [(c, c, get_entity_doc(version, c).get("description", "")) for c in ["IfcObjective"]]
|
ConstraintsData.load()
|
||||||
|
return ConstraintsData.data["constraint_types_enum"]
|
||||||
|
|
||||||
|
|
||||||
class Constraint(PropertyGroup):
|
class Constraint(PropertyGroup):
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
|
from ifcopenshell.util.doc import get_entity_doc
|
||||||
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
@@ -219,6 +220,8 @@ class ActorData:
|
|||||||
cls.data = {
|
cls.data = {
|
||||||
"the_actor": cls.the_actor(),
|
"the_actor": cls.the_actor(),
|
||||||
"actors": cls.actors(),
|
"actors": cls.actors(),
|
||||||
|
"actor_class_enum": cls.actor_class_enum(),
|
||||||
|
"get_actor_type_enum": cls.get_actor_type_enum(),
|
||||||
}
|
}
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
@@ -245,6 +248,27 @@ class ActorData:
|
|||||||
)
|
)
|
||||||
return actors
|
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:
|
class ObjectActorData:
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from ifcopenshell.util.doc import get_entity_doc
|
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.prop import StrProperty, Attribute
|
from bonsai.bim.prop import StrProperty, Attribute
|
||||||
from bonsai.bim.module.owner.data import OwnerData, ActorData, ObjectActorData
|
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()
|
ActorData.data["actors"] = ActorData.actors()
|
||||||
|
|
||||||
|
|
||||||
# TODO: unsafe?
|
|
||||||
def get_actor_class_enum(self, context):
|
def get_actor_class_enum(self, context):
|
||||||
version = tool.Ifc.get_schema()
|
if not ActorData.is_loaded:
|
||||||
return [
|
ActorData.load()
|
||||||
("IfcActor", "Actor", get_entity_doc(version, "IfcActor").get("description", "")),
|
return ActorData.data["actor_class_enum"]
|
||||||
("IfcOccupant", "Occupant", get_entity_doc(version, "IfcOccupant").get("description", "")),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: unsafe?
|
|
||||||
def get_actor_type_enum(self, context):
|
def get_actor_type_enum(self, context):
|
||||||
version = tool.Ifc.get_schema()
|
if not ActorData.is_loaded:
|
||||||
return [
|
ActorData.load()
|
||||||
("IfcPerson", "Person", get_entity_doc(version, "IfcPerson").get("description", "")),
|
return ActorData.data["actor_type_enum"]
|
||||||
("IfcOrganization", "Organisation", get_entity_doc(version, "IfcOrganization").get("description", "")),
|
|
||||||
(
|
|
||||||
"IfcPersonAndOrganization",
|
|
||||||
"User",
|
|
||||||
get_entity_doc(version, "IfcPersonAndOrganization").get("description", ""),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class BIMOwnerProperties(PropertyGroup):
|
class BIMOwnerProperties(PropertyGroup):
|
||||||
|
|||||||
Reference in New Issue
Block a user