mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 18:16:40 +00:00
Fix regression where type thumbnails don't refresh properly from ae76d3253
The fix in ae76d3253 removed the refresh_ui_data call, so we need to
handle it a bit better. I also heavily simplified the thumbnail loading.
This commit is contained in:
@@ -544,8 +544,8 @@ class ChangeTypePage(bpy.types.Operator, tool.Ifc.Operator):
|
||||
|
||||
def _execute(self, context):
|
||||
props = tool.Model.get_model_props()
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=props.ifc_class, offset=9 * (self.page - 1), limit=9)
|
||||
props.type_page = self.page
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -623,29 +623,18 @@ class LoadTypeThumbnails(bpy.types.Operator):
|
||||
bl_idname = "bim.load_type_thumbnails"
|
||||
bl_label = "Load Type Thumbnails"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
ifc_class: bpy.props.StringProperty()
|
||||
limit: bpy.props.IntProperty()
|
||||
offset: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
if bpy.app.background:
|
||||
return {"FINISHED"}
|
||||
|
||||
props = tool.Model.get_model_props()
|
||||
# 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:
|
||||
AuthoringData.load()
|
||||
queue = AuthoringData.data["type_elements_filtered"]
|
||||
if self.limit:
|
||||
queue = queue[self.offset : self.offset + self.limit]
|
||||
else:
|
||||
offset = 9 * (props.type_page - 1)
|
||||
if offset < 0:
|
||||
offset = 0
|
||||
queue = queue[offset : offset + 9]
|
||||
queue = [tool.Ifc.get().by_id(t["id"]) for t in AuthoringData.data["paginated_relating_types"]]
|
||||
|
||||
# The active type may be in another page than the active one :
|
||||
# The active type may be in another page than the active one:
|
||||
if relating_type_id_current := AuthoringData.data["relating_type_data"].get("id"):
|
||||
active_element = tool.Ifc.get_entity_by_id(relating_type_id_current)
|
||||
if active_element and active_element not in queue:
|
||||
|
||||
@@ -58,7 +58,7 @@ def get_materials(
|
||||
|
||||
|
||||
def update_ifc_class(self: "BIMModelProperties", context: bpy.types.Context) -> None:
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=self.ifc_class)
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
AuthoringData.data["ifc_class_current"] = self.ifc_class
|
||||
AuthoringData.data["type_elements"] = AuthoringData.type_elements()
|
||||
AuthoringData.data["type_elements_filtered"] = AuthoringData.type_elements_filtered()
|
||||
@@ -82,7 +82,7 @@ def update_relating_type_id(self: "BIMModelProperties", context: bpy.types.Conte
|
||||
|
||||
def update_type_page(self: "BIMModelProperties", context: bpy.types.Context) -> None:
|
||||
AuthoringData.data["paginated_relating_types"] = AuthoringData.paginated_relating_types()
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=self.ifc_class, offset=9 * (self.type_page - 1), limit=9)
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
self["type_page"] = min(self["type_page"], AuthoringData.data["total_pages"])
|
||||
self["type_page"] = max(self["type_page"], 1)
|
||||
|
||||
@@ -118,7 +118,7 @@ def update_search_name(self: "BIMModelProperties", context: bpy.types.Context) -
|
||||
# Total number of pages may decrease when using the search bar :
|
||||
if self.type_page > AuthoringData.data["total_pages"]:
|
||||
self.type_page = max(1, AuthoringData.data["total_pages"])
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=self.ifc_class)
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
|
||||
|
||||
def update_x_angle(self: "BIMModelProperties", context: bpy.types.Context) -> None:
|
||||
|
||||
@@ -31,7 +31,6 @@ from bonsai.bim.module.model.data import (
|
||||
RailingData,
|
||||
RoofData,
|
||||
)
|
||||
from bonsai.bim.module.model.prop import get_ifc_class
|
||||
from bonsai.bim.module.model.stair import regenerate_stair_mesh
|
||||
from bonsai.bim.module.model.railing import update_railing_modifier_bmesh
|
||||
from bonsai.bim.module.model.roof import update_roof_modifier_bmesh
|
||||
@@ -90,14 +89,7 @@ class LaunchTypeManager(bpy.types.Operator):
|
||||
def invoke(self, context, event):
|
||||
props = tool.Model.get_model_props()
|
||||
props.type_page = 1
|
||||
if get_ifc_class(None, context):
|
||||
ifc_class = AuthoringData.data["ifc_class_current"] or AuthoringData.data["ifc_element_type"]
|
||||
else:
|
||||
ifc_class = AuthoringData.data["ifc_element_type"]
|
||||
|
||||
# will be None if project has no types
|
||||
if ifc_class is not None:
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=ifc_class, offset=0, limit=9)
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
return context.window_manager.invoke_props_dialog(self, width=550, title="Type Manager", confirm_text="Close")
|
||||
|
||||
def draw(self, context):
|
||||
@@ -157,11 +149,11 @@ class LaunchTypeManager(bpy.types.Operator):
|
||||
op = row.operator("bim.set_active_type", text=relating_type["description"], emboss=False)
|
||||
op.relating_type = relating_type["id"]
|
||||
|
||||
if relating_type["icon_id"]:
|
||||
if icon_id := AuthoringData.type_thumbnails.get(relating_type["id"], 0):
|
||||
# Yep, that's EXACTLY how it's done. And I'm proud of it.
|
||||
row1 = box.row()
|
||||
row1.ui_units_y = 0.01
|
||||
row1.template_icon(icon_value=relating_type["icon_id"], scale=4)
|
||||
row1.template_icon(icon_value=icon_id, scale=4)
|
||||
row2 = box.column(align=True)
|
||||
row2.operator("bim.set_active_type", text="", emboss=False).relating_type = relating_type["id"]
|
||||
row2.operator("bim.set_active_type", text="", emboss=False).relating_type = relating_type["id"]
|
||||
@@ -175,8 +167,7 @@ class LaunchTypeManager(bpy.types.Operator):
|
||||
row2.operator("bim.set_active_type", text="", emboss=False).relating_type = relating_type["id"]
|
||||
else:
|
||||
row = box.row()
|
||||
op = box.operator("bim.load_type_thumbnails", text="", icon="FILE_REFRESH", emboss=False)
|
||||
op.ifc_class = AuthoringData.data["ifc_class_current"]
|
||||
box.operator("bim.load_type_thumbnails", text="", icon="FILE_REFRESH")
|
||||
|
||||
row = box.row()
|
||||
row.alignment = "CENTER"
|
||||
|
||||
@@ -646,7 +646,7 @@ class CreateObjectUI:
|
||||
box = cls.layout.box()
|
||||
|
||||
row = box.row(align=True)
|
||||
thumbnail: int = relating_type_data["icon_id"]
|
||||
thumbnail: int = AuthoringData.type_thumbnails.get(relating_type_data["id"], 0)
|
||||
row.template_icon(icon_value=thumbnail)
|
||||
row.operator("bim.launch_type_manager", text=relating_type_data["name"], emboss=False)
|
||||
row.operator(
|
||||
|
||||
@@ -325,7 +325,7 @@ class DuplicateType(bpy.types.Operator, tool.Ifc.Operator):
|
||||
new_obj.data = obj.data.copy()
|
||||
new = bonsai.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=new_obj)
|
||||
new.Name += " Copy"
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=new.is_a())
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
if obj in context.selectable_objects:
|
||||
tool.Blender.select_and_activate_single_object(context, new_obj)
|
||||
else:
|
||||
|
||||
@@ -35,7 +35,7 @@ from collections import defaultdict
|
||||
from bonsai.bim.ifc import IfcStore
|
||||
from ifcopenshell.api.project.append_asset import APPENDABLE_ASSET_TYPES
|
||||
from pathlib import Path
|
||||
from typing import Optional, Union, TYPE_CHECKING, Generator, Callable
|
||||
from typing import Optional, Union, TYPE_CHECKING, Generator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from bonsai.bim.module.project.prop import BIMProjectProperties
|
||||
@@ -65,8 +65,7 @@ class Project(bonsai.core.tool.Project):
|
||||
@classmethod
|
||||
def load_default_thumbnails(cls):
|
||||
if tool.Ifc.get().by_type("IfcElementType"):
|
||||
ifc_class = sorted(tool.Ifc.get().by_type("IfcElementType"), key=lambda e: e.is_a())[0].is_a()
|
||||
bpy.ops.bim.load_type_thumbnails(ifc_class=ifc_class, offset=0, limit=9)
|
||||
bpy.ops.bim.load_type_thumbnails()
|
||||
|
||||
@classmethod
|
||||
def load_pset_templates(cls):
|
||||
|
||||
Reference in New Issue
Block a user