From 2d68d344bd49caa98c34feb69d7b883790af184b Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 10 Sep 2024 14:57:22 +0500 Subject: [PATCH] Profiles UI - update displayed psets when user is changing active profile previously it would get stuck until some other operator would refresh ui --- src/bonsai/bonsai/bim/module/pset/data.py | 15 ++++++++++++--- src/bonsai/bonsai/bim/module/pset/ui.py | 10 +++++++++- src/bonsai/bonsai/tool/profile.py | 8 ++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/pset/data.py b/src/bonsai/bonsai/bim/module/pset/data.py index c22ee88053..e9768ff0ab 100644 --- a/src/bonsai/bonsai/bim/module/pset/data.py +++ b/src/bonsai/bonsai/bim/module/pset/data.py @@ -290,9 +290,18 @@ class ProfilePsetsData(Data): @classmethod def load(cls): - pprops = bpy.context.scene.BIMProfileProperties - ifc_definition_id = pprops.profiles[pprops.active_profile_index].ifc_definition_id - cls.data = {"psets": cls.psetqtos(tool.Ifc.get().by_id(ifc_definition_id), psets_only=True)} + active_profile = tool.Profile.get_active_profile_ui() + if active_profile: + ifc_definition_id = active_profile.ifc_definition_id + psets_data = cls.psetqtos(tool.Ifc.get().by_id(ifc_definition_id), psets_only=True) + else: + ifc_definition_id = 0 + psets_data = [] + + cls.data = { + "ifc_definition_id": ifc_definition_id, + "psets": psets_data, + } cls.is_loaded = True diff --git a/src/bonsai/bonsai/bim/module/pset/ui.py b/src/bonsai/bonsai/bim/module/pset/ui.py index fd01a3b6af..3177a9ae31 100644 --- a/src/bonsai/bonsai/bim/module/pset/ui.py +++ b/src/bonsai/bonsai/bim/module/pset/ui.py @@ -664,7 +664,15 @@ class BIM_PT_profile_psets(Panel): return False def draw(self, context): - if not ProfilePsetsData.is_loaded: + active_profile = tool.Profile.get_active_profile_ui() + + if not active_profile: + return + + if ( + not ProfilePsetsData.is_loaded + or active_profile.ifc_definition_id != ProfilePsetsData.data["ifc_definition_id"] + ): ProfilePsetsData.load() props = context.scene.ProfilePsetProperties diff --git a/src/bonsai/bonsai/tool/profile.py b/src/bonsai/bonsai/tool/profile.py index 859f8e4a3b..cc7e91f0b3 100644 --- a/src/bonsai/bonsai/tool/profile.py +++ b/src/bonsai/bonsai/tool/profile.py @@ -16,6 +16,7 @@ # You should have received a copy of the GNU General Public License # along with Bonsai. If not, see . +import bpy import ifcopenshell import ifcopenshell.api.profile import ifcopenshell.geom @@ -104,3 +105,10 @@ class Profile(bonsai.core.tool.Profile): # In UI unnamed profiles are not available, so we don't handle them. new_profile.ProfileName = profile.ProfileName + "_copy" return new_profile + + @classmethod + def get_active_profile_ui(cls) -> Union[bpy.types.PropertyGroup, None]: + props = bpy.context.scene.BIMProfileProperties + index = props.active_profile_index + if len(props.profiles) > index >= 0: + return props.profiles[index]