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"}
+49 -45
View File
@@ -504,54 +504,58 @@ 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"]):
box = cls.layout.box() return
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 ui_context != "TOOL_HEADER": box = cls.layout.box()
row = box.row(align=True)
row.alignment = "CENTER"
row.operator(
"bim.launch_type_manager",
text=AuthoringData.data["relating_type_description"],
emboss=False,
)
if AuthoringData.data["type_thumbnail"]: row = box.row(align=True)
row1 = box.row() thumbnail: int = AuthoringData.data["type_thumbnail"]
row1.ui_units_y = 0.01 row.template_icon(icon_value=thumbnail)
row1.template_icon(icon_value=AuthoringData.data["type_thumbnail"], scale=4) row.operator("bim.launch_type_manager", text=AuthoringData.data["relating_type_name"], emboss=False)
row2 = box.column(align=True) row.operator(
row2.ui_units_y = 4 "bim.launch_type_manager",
for _ in range(4): icon=tool.Blender.TYPE_MANAGER_ICON,
row2.operator("bim.launch_type_manager", text="", emboss=False) text="",
else: emboss=False,
op = box.operator( )
"bim.load_type_thumbnails",
text="",
icon="FILE_REFRESH",
emboss=False,
)
op.ifc_class = ifc_class
row = box.row(align=True) if ui_context == "TOOL_HEADER":
row.alignment = "CENTER" return
row.operator( row = box.row(align=True)
"bim.launch_type_manager", row.alignment = "CENTER"
text=AuthoringData.data["predefined_type"], row.operator(
emboss=False, "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: class EditObjectUI: