Profiles UI - update displayed psets when user is changing active profile

previously it would get stuck until some other operator would refresh ui
This commit is contained in:
Andrej730
2024-09-10 14:57:22 +05:00
parent ddf92ab8fb
commit 2d68d344bd
3 changed files with 29 additions and 4 deletions
+12 -3
View File
@@ -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
+9 -1
View File
@@ -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
+8
View File
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
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]