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
def type_thumbnail(cls):
if not cls.data["relating_type_id"]:
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
return cls.type_thumbnails.get(int(cls.data["relating_type_id_current"] or 0), 0)
@classmethod
def total_types(cls):
@@ -563,7 +563,6 @@ class LoadTypeThumbnails(bpy.types.Operator, tool.Ifc.Operator):
return
props = bpy.context.scene.BIMModelProperties
processing = set()
# Only process at most one paginated class at a time.
# Large projects have hundreds of types which can lead to unnecessary lag.
if not AuthoringData.is_loaded:
@@ -577,6 +576,12 @@ class LoadTypeThumbnails(bpy.types.Operator, tool.Ifc.Operator):
offset = 0
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:
# if bpy.app.is_job_running("RENDER_PREVIEW") does not seem to reflect asset preview generation
element = queue.pop()
+1 -1
View File
@@ -84,7 +84,7 @@ class LaunchTypeManager(bpy.types.Operator):
bl_idname = "bim.launch_type_manager"
bl_label = "Launch Type Manager"
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):
return {"FINISHED"}
+49 -45
View File
@@ -504,54 +504,58 @@ class CreateObjectUI:
row = cls.layout.row(align=True)
if not AuthoringData.data["ifc_element_type"]:
prop_with_search(row, cls.props, "ifc_class", text="Type Class" if ui_context != "TOOL_HEADER" else "")
if AuthoringData.data["ifc_classes"]:
ifc_class = AuthoringData.data["ifc_class_current"]
if ifc_class:
box = cls.layout.box()
row = box.row(align=True)
if ui_context == "TOOL_HEADER":
row.template_icon(icon_value=AuthoringData.data.get("type_thumbnail", 0))
row.operator("bim.launch_type_manager", text=AuthoringData.data["relating_type_name"], emboss=False)
row.operator(
"bim.launch_type_manager",
icon=tool.Blender.TYPE_MANAGER_ICON,
text="",
emboss=False,
)
if not AuthoringData.data["ifc_classes"]:
return
if not (ifc_class := AuthoringData.data["ifc_class_current"]):
return
if ui_context != "TOOL_HEADER":
row = box.row(align=True)
row.alignment = "CENTER"
row.operator(
"bim.launch_type_manager",
text=AuthoringData.data["relating_type_description"],
emboss=False,
)
box = cls.layout.box()
if AuthoringData.data["type_thumbnail"]:
row1 = box.row()
row1.ui_units_y = 0.01
row1.template_icon(icon_value=AuthoringData.data["type_thumbnail"], scale=4)
row2 = box.column(align=True)
row2.ui_units_y = 4
for _ in range(4):
row2.operator("bim.launch_type_manager", text="", emboss=False)
else:
op = box.operator(
"bim.load_type_thumbnails",
text="",
icon="FILE_REFRESH",
emboss=False,
)
op.ifc_class = ifc_class
row = box.row(align=True)
thumbnail: int = AuthoringData.data["type_thumbnail"]
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",
icon=tool.Blender.TYPE_MANAGER_ICON,
text="",
emboss=False,
)
row = box.row(align=True)
row.alignment = "CENTER"
row.operator(
"bim.launch_type_manager",
text=AuthoringData.data["predefined_type"],
emboss=False,
)
if ui_context == "TOOL_HEADER":
return
row = box.row(align=True)
row.alignment = "CENTER"
row.operator(
"bim.launch_type_manager",
text=AuthoringData.data["relating_type_description"],
emboss=False,
)
if thumbnail != 0:
row1 = box.row()
row1.ui_units_y = 0.01
row1.template_icon(icon_value=thumbnail, scale=4)
row2 = box.column(align=True)
row2.ui_units_y = 4
for _ in range(4):
row2.operator("bim.launch_type_manager", text="", emboss=False)
else:
op = box.operator(
"bim.load_type_thumbnails",
text="",
icon="FILE_REFRESH",
emboss=False,
)
op.ifc_class = ifc_class
row = box.row(align=True)
row.alignment = "CENTER"
row.operator(
"bim.launch_type_manager",
text=AuthoringData.data["predefined_type"],
emboss=False,
)
class EditObjectUI: