From 5e25e4670ddbf6a499b751cbfd97bbaa5ab79806 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Fri, 18 Aug 2023 09:43:46 +0200 Subject: [PATCH] Active profil users count is now dynamically fetched when the profile is clicked in the UI list --- .../blenderbim/bim/module/profile/data.py | 15 ++++++--------- .../blenderbim/bim/module/profile/operator.py | 7 +++++-- .../blenderbim/bim/module/profile/prop.py | 6 +++++- .../blenderbim/bim/module/profile/ui.py | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/profile/data.py b/src/blenderbim/blenderbim/bim/module/profile/data.py index 81aabcad30..89103cc0a4 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/data.py +++ b/src/blenderbim/blenderbim/bim/module/profile/data.py @@ -36,7 +36,7 @@ class ProfileData: def load(cls): cls.data = { "total_profiles": cls.total_profiles(), - "profiles_users": cls.profiles_users(), + "active_profile_users": cls.active_profile_users(), "profile_classes": cls.profile_classes(), "is_arbitrary_profile": cls.is_arbitrary_profile(), "is_editing_arbitrary_profile": cls.is_editing_arbitrary_profile(), @@ -48,14 +48,11 @@ class ProfileData: 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 + def active_profile_users(cls): + profiles_props = bpy.context.scene.BIMProfileProperties + profile_prop = profiles_props.profiles[profiles_props.active_profile_index] + profile_ifc = tool.Ifc.get().by_id(profile_prop.ifc_definition_id) + return tool.Ifc.get().get_total_inverses(profile_ifc) @classmethod def profile_classes(cls): diff --git a/src/blenderbim/blenderbim/bim/module/profile/operator.py b/src/blenderbim/blenderbim/bim/module/profile/operator.py index 9194c895ff..03ecf10c6c 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/operator.py +++ b/src/blenderbim/blenderbim/bim/module/profile/operator.py @@ -222,6 +222,9 @@ class PurgeOrphanProfiles(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} def _execute(self, context): - profiles_ids = [profile_prop.ifc_definition_id for profile_prop in context.scene.BIMProfileProperties.profiles] + props = context.scene.BIMProfileProperties + profiles_ids = [profile_prop.ifc_definition_id for profile_prop in props.profiles] core.purge_orphan_profiles(tool.Ifc, profiles_ids=profiles_ids) - bpy.ops.bim.load_profiles() + if props.is_editing: + refresh() + bpy.ops.bim.load_profiles() diff --git a/src/blenderbim/blenderbim/bim/module/profile/prop.py b/src/blenderbim/blenderbim/bim/module/profile/prop.py index 3ea2d2a047..2939173ffe 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/prop.py +++ b/src/blenderbim/blenderbim/bim/module/profile/prop.py @@ -49,10 +49,14 @@ class Profile(PropertyGroup): ifc_definition_id: IntProperty(name="IFC Definition ID") +def update_active_profile_index(self, context): + ProfileData.data["active_profile_users"] = ProfileData.active_profile_users() + + class BIMProfileProperties(PropertyGroup): is_editing: BoolProperty(name="Is Editing") profiles: CollectionProperty(name="Profiles", type=Profile) - active_profile_index: IntProperty(name="Active Profile Index") + active_profile_index: IntProperty(name="Active Profile Index", update=update_active_profile_index) active_profile_id: IntProperty(name="Active Profile Id") active_arbitrary_profile_id: IntProperty(name="Active Arbitrary Profile Id") profile_attributes: CollectionProperty(name="Profile Attributes", type=Attribute) diff --git a/src/blenderbim/blenderbim/bim/module/profile/ui.py b/src/blenderbim/blenderbim/bim/module/profile/ui.py index 3061ad0d15..dc6ba88717 100644 --- a/src/blenderbim/blenderbim/bim/module/profile/ui.py +++ b/src/blenderbim/blenderbim/bim/module/profile/ui.py @@ -94,7 +94,7 @@ class BIM_PT_profiles(Panel): "bim.enable_editing_arbitrary_profile", text="Edit Arbitrary Profile", icon="GREASEPENCIL" ) - users_of_profile = ProfileData.data["profiles_users"][active_profile.ifc_definition_id] + users_of_profile = ProfileData.data["active_profile_users"] self.layout.label(icon="INFO", text=f"Profile has {users_of_profile} inverse relationship(s) in project") if self.props.active_profile_id: