Move profile data and inverse check in data class

This commit is contained in:
Gorgious
2023-08-17 21:00:03 +02:00
parent 51c78a89bd
commit 88c002703e
2 changed files with 18 additions and 3 deletions
@@ -36,6 +36,7 @@ class ProfileData:
def load(cls):
cls.data = {
"total_profiles": cls.total_profiles(),
"profiles_users": cls.profiles_users(),
"profile_classes": cls.profile_classes(),
"is_arbitrary_profile": cls.is_arbitrary_profile(),
"is_editing_arbitrary_profile": cls.is_editing_arbitrary_profile(),
@@ -46,6 +47,16 @@ class ProfileData:
def total_profiles(cls):
return len([p for p in tool.Ifc.get().by_type("IfcProfileDef") if p.ProfileName])
@classmethod
def profiles_users(cls):
profile_id_to_users = {}
for profile_prop in bpy.context.scene.BIMProfileProperties.profiles:
profile_id = profile_prop.ifc_definition_id
profile_ifc = tool.Ifc.get().by_id(profile_id)
profile_users = tool.Ifc.get().get_total_inverses(profile_ifc)
profile_id_to_users[profile_id] = profile_users
return profile_id_to_users
@classmethod
def profile_classes(cls):
classes = ["IfcArbitraryClosedProfileDef"]
@@ -72,4 +83,9 @@ class ProfileData:
@classmethod
def is_editing_arbitrary_profile(cls):
obj = bpy.context.active_object
return obj and obj.data and hasattr(obj.data, "BIMMeshProperties") and obj.data.BIMMeshProperties.subshape_type == "PROFILE"
return (
obj
and obj.data
and hasattr(obj.data, "BIMMeshProperties")
and obj.data.BIMMeshProperties.subshape_type == "PROFILE"
)
@@ -94,8 +94,7 @@ class BIM_PT_profiles(Panel):
"bim.enable_editing_arbitrary_profile", text="Edit Arbitrary Profile", icon="GREASEPENCIL"
)
profile_entity = tool.Ifc.get().by_id(active_profile.ifc_definition_id)
users_of_profile = tool.Ifc.get().get_total_inverses(profile_entity)
users_of_profile = ProfileData.data["profiles_users"][active_profile.ifc_definition_id]
self.layout.label(icon="INFO", text=f"Profile has {users_of_profile} inverse relationship(s) in project")
if self.props.active_profile_id: