Fix bug where the thumbnail of the active class wasn't updated

This commit is contained in:
Gorgious56
2025-01-10 15:17:26 +01:00
parent 4f4c557f61
commit 7db0196791
4 changed files with 57 additions and 54 deletions
+1 -7
View File
@@ -107,13 +107,7 @@ class AuthoringData:
@classmethod @classmethod
def type_thumbnail(cls): def type_thumbnail(cls):
if not cls.data["relating_type_id"]: return cls.type_thumbnails.get(int(cls.data["relating_type_id_current"] or 0), 0)
return 0
relating_type_id = tool.Blender.get_enum_safe(cls.props, "relating_type_id")
if relating_type_id is None:
return 0
element = tool.Ifc.get().by_id(int(relating_type_id))
return cls.type_thumbnails.get(element.id(), None) or 0
@classmethod @classmethod
def total_types(cls): def total_types(cls):
@@ -563,7 +563,6 @@ class LoadTypeThumbnails(bpy.types.Operator, tool.Ifc.Operator):
return return
props = bpy.context.scene.BIMModelProperties props = bpy.context.scene.BIMModelProperties
processing = set()
# Only process at most one paginated class at a time. # Only process at most one paginated class at a time.
# Large projects have hundreds of types which can lead to unnecessary lag. # Large projects have hundreds of types which can lead to unnecessary lag.
if not AuthoringData.is_loaded: if not AuthoringData.is_loaded:
@@ -577,6 +576,12 @@ class LoadTypeThumbnails(bpy.types.Operator, tool.Ifc.Operator):
offset = 0 offset = 0
queue = queue[offset : offset + 9] queue = queue[offset : offset + 9]
# The active type may be in another page than the active one :
if relating_type_id_current := AuthoringData.data["relating_type_id_current"]:
active_element = tool.Ifc.get_entity_by_id(int(relating_type_id_current))
if active_element and active_element not in queue:
queue.append(active_element)
while queue: while queue:
# if bpy.app.is_job_running("RENDER_PREVIEW") does not seem to reflect asset preview generation # if bpy.app.is_job_running("RENDER_PREVIEW") does not seem to reflect asset preview generation
element = queue.pop() element = queue.pop()
+1 -1
View File
@@ -84,7 +84,7 @@ class LaunchTypeManager(bpy.types.Operator):
bl_idname = "bim.launch_type_manager" bl_idname = "bim.launch_type_manager"
bl_label = "Launch Type Manager" bl_label = "Launch Type Manager"
bl_options = {"REGISTER", "UNDO"} bl_options = {"REGISTER", "UNDO"}
bl_description = "Display all available Construction Types to add new occurrences" bl_description = "Browse, Edit and Manage Types"
def execute(self, context): def execute(self, context):
return {"FINISHED"} return {"FINISHED"}
@@ -504,13 +504,16 @@ class CreateObjectUI:
row = cls.layout.row(align=True) row = cls.layout.row(align=True)
if not AuthoringData.data["ifc_element_type"]: if not AuthoringData.data["ifc_element_type"]:
prop_with_search(row, cls.props, "ifc_class", text="Type Class" if ui_context != "TOOL_HEADER" else "") prop_with_search(row, cls.props, "ifc_class", text="Type Class" if ui_context != "TOOL_HEADER" else "")
if AuthoringData.data["ifc_classes"]: if not AuthoringData.data["ifc_classes"]:
ifc_class = AuthoringData.data["ifc_class_current"] return
if ifc_class: if not (ifc_class := AuthoringData.data["ifc_class_current"]):
return
box = cls.layout.box() box = cls.layout.box()
row = box.row(align=True) row = box.row(align=True)
if ui_context == "TOOL_HEADER": thumbnail: int = AuthoringData.data["type_thumbnail"]
row.template_icon(icon_value=AuthoringData.data.get("type_thumbnail", 0)) row.template_icon(icon_value=thumbnail)
row.operator("bim.launch_type_manager", text=AuthoringData.data["relating_type_name"], emboss=False) row.operator("bim.launch_type_manager", text=AuthoringData.data["relating_type_name"], emboss=False)
row.operator( row.operator(
"bim.launch_type_manager", "bim.launch_type_manager",
@@ -519,7 +522,8 @@ class CreateObjectUI:
emboss=False, emboss=False,
) )
if ui_context != "TOOL_HEADER": if ui_context == "TOOL_HEADER":
return
row = box.row(align=True) row = box.row(align=True)
row.alignment = "CENTER" row.alignment = "CENTER"
row.operator( row.operator(
@@ -528,10 +532,10 @@ class CreateObjectUI:
emboss=False, emboss=False,
) )
if AuthoringData.data["type_thumbnail"]: if thumbnail != 0:
row1 = box.row() row1 = box.row()
row1.ui_units_y = 0.01 row1.ui_units_y = 0.01
row1.template_icon(icon_value=AuthoringData.data["type_thumbnail"], scale=4) row1.template_icon(icon_value=thumbnail, scale=4)
row2 = box.column(align=True) row2 = box.column(align=True)
row2.ui_units_y = 4 row2.ui_units_y = 4
for _ in range(4): for _ in range(4):