From 88c002703eec39777671fc1bca941bf53706a02b Mon Sep 17 00:00:00 2001 From: Gorgious Date: Thu, 17 Aug 2023 21:00:03 +0200 Subject: [PATCH] Move profile data and inverse check in data class --- .../blenderbim/bim/module/profile/data.py | 18 +++++++++++++++++- .../blenderbim/bim/module/profile/ui.py | 3 +-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/profile/data.py b/src/blenderbim/blenderbim/bim/module/profile/data.py index 698b0a1f5f..81aabcad30 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/data.py +++ b/src/blenderbim/blenderbim/bim/module/profile/data.py @@ -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" + ) diff --git a/src/blenderbim/blenderbim/bim/module/profile/ui.py b/src/blenderbim/blenderbim/bim/module/profile/ui.py index ca2ea03d68..3061ad0d15 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/ui.py +++ b/src/blenderbim/blenderbim/bim/module/profile/ui.py @@ -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: