Mark thumbnails as outdated instead of updating them right away

As user may never open them in type manager
This commit is contained in:
Andrej730
2025-05-12 18:12:25 +05:00
parent 22b5db8a1e
commit be1836fa48
5 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -618,7 +618,7 @@ class FinishEditingDoor(bpy.types.Operator, tool.Ifc.Operator):
update_door_modifier_representation(obj)
element_type = ifcopenshell.util.element.get_type(element)
if element_type:
tool.Model.update_thumbnail_for_element(element_type, refresh=True)
tool.Model.mark_thumbnail_for_update(element_type)
pset = tool.Pset.get_element_pset(element, "BBIM_Door")
door_data = tool.Ifc.get().createIfcText(json.dumps(door_data, default=list))
@@ -608,8 +608,7 @@ class LoadTypeThumbnails(bpy.types.Operator):
while queue:
# if bpy.app.is_job_running("RENDER_PREVIEW") does not seem to reflect asset preview generation
element = queue.pop()
if tool.Model.update_thumbnail_for_element(element):
queue.append(element)
tool.Model.mark_thumbnail_for_update(element)
return {"FINISHED"}
@@ -212,7 +212,7 @@ class DumbProfileRegenerator:
# update related thumbnails
for element in self.get_element_types_using_profile(profile):
tool.Model.update_thumbnail_for_element(element, refresh=True)
tool.Model.mark_thumbnail_for_update(element)
def regenerate_from_profile(self, usecase_path, ifc_file, settings):
self.file = ifc_file
+1 -1
View File
@@ -531,7 +531,7 @@ class FinishEditingWindow(bpy.types.Operator, tool.Ifc.Operator):
update_window_modifier_representation(context)
element_type = ifcopenshell.util.element.get_type(element)
if element_type:
tool.Model.update_thumbnail_for_element(element_type, refresh=True)
tool.Model.mark_thumbnail_for_update(element_type)
pset = tool.Pset.get_element_pset(element, "BBIM_Window")
window_data = tool.Ifc.get().createIfcText(json.dumps(window_data, default=list))
+11
View File
@@ -1145,6 +1145,17 @@ class Model(bonsai.core.tool.Model):
AuthoringData.type_thumbnails[element.id()] = obj.preview.icon_id
@classmethod
def mark_thumbnail_for_update(cls, element: ifcopenshell.entity_instance) -> None:
"""Mark the thumbnail for the provided element as outdated.
Allows postponing the thumbnail update until it is actually needed by the user.
"""
element_id = element.id()
if element_id not in AuthoringData.type_thumbnails:
return
del AuthoringData.type_thumbnails[element_id]
@classmethod
def get_selected_ifc_objects(cls) -> list[bpy.types.Object]:
return [obj for obj in tool.Blender.get_selected_objects() if tool.Ifc.get_entity(obj)]