mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
Profiles UI - better handling for invalid profiles
Previously it would be just console errors possibly breaking UI, now there will be UI error message - https://imgur.com/1o9teJ0
This commit is contained in:
@@ -29,6 +29,7 @@ def refresh():
|
|||||||
|
|
||||||
class ProfileData:
|
class ProfileData:
|
||||||
data = {}
|
data = {}
|
||||||
|
failed_previews: set[int] = set()
|
||||||
preview_collection = bpy.utils.previews.new()
|
preview_collection = bpy.utils.previews.new()
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
|
|
||||||
|
|||||||
@@ -81,14 +81,24 @@ def generate_thumbnail_for_active_profile():
|
|||||||
if not props.profiles:
|
if not props.profiles:
|
||||||
bpy.ops.bim.load_profiles()
|
bpy.ops.bim.load_profiles()
|
||||||
|
|
||||||
profile_id = props.profiles[props.active_profile_index].ifc_definition_id
|
active_profile = tool.Profile.get_active_profile_ui()
|
||||||
|
assert active_profile
|
||||||
|
profile_id = active_profile.ifc_definition_id
|
||||||
profile = ifc_file.by_id(profile_id)
|
profile = ifc_file.by_id(profile_id)
|
||||||
|
|
||||||
# generate image
|
# generate image
|
||||||
size = 128
|
size = 128
|
||||||
img = Image.new("RGBA", (size, size))
|
img = Image.new("RGBA", (size, size))
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
tool.Profile.draw_image_for_ifc_profile(draw, profile, size)
|
|
||||||
|
try:
|
||||||
|
tool.Profile.draw_image_for_ifc_profile(draw, profile, size)
|
||||||
|
except RuntimeError as e:
|
||||||
|
print(f"Failed to generate preview image for profile '{profile}': '{e}'.")
|
||||||
|
ProfileData.failed_previews.add(profile_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
ProfileData.failed_previews.discard(profile_id)
|
||||||
pixels = [item for sublist in img.getdata() for item in sublist]
|
pixels = [item for sublist in img.getdata() for item in sublist]
|
||||||
|
|
||||||
# save generated image to preview collection
|
# save generated image to preview collection
|
||||||
|
|||||||
@@ -43,19 +43,22 @@ class BIM_PT_profiles(Panel):
|
|||||||
self.props = context.scene.BIMProfileProperties
|
self.props = context.scene.BIMProfileProperties
|
||||||
|
|
||||||
active_profile = None
|
active_profile = None
|
||||||
if self.props.is_editing and self.props.profiles and self.props.active_profile_index < len(self.props.profiles):
|
if self.props.is_editing and (active_profile := tool.Profile.get_active_profile_ui()):
|
||||||
preview_collection = ProfileData.preview_collection
|
preview_collection = ProfileData.preview_collection
|
||||||
box = self.layout.box()
|
box = self.layout.box()
|
||||||
active_profile = self.props.profiles[self.props.active_profile_index]
|
|
||||||
profile_id = active_profile.ifc_definition_id
|
profile_id = active_profile.ifc_definition_id
|
||||||
profile_id_str = str(profile_id)
|
|
||||||
if profile_id_str in preview_collection:
|
|
||||||
preview_image = preview_collection[profile_id_str]
|
|
||||||
else:
|
|
||||||
preview_image = preview_collection.new(profile_id_str)
|
|
||||||
generate_thumbnail_for_active_profile()
|
|
||||||
|
|
||||||
box.template_icon(icon_value=preview_image.icon_id, scale=5)
|
if profile_id in ProfileData.failed_previews:
|
||||||
|
box.label(text="Failed to load preview (invalid profile).", icon="ERROR")
|
||||||
|
else:
|
||||||
|
profile_id_str = str(profile_id)
|
||||||
|
if profile_id_str in preview_collection:
|
||||||
|
preview_image = preview_collection[profile_id_str]
|
||||||
|
else:
|
||||||
|
preview_image = preview_collection.new(profile_id_str)
|
||||||
|
generate_thumbnail_for_active_profile()
|
||||||
|
|
||||||
|
box.template_icon(icon_value=preview_image.icon_id, scale=5)
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(text=f"{ProfileData.data['total_profiles']} Named Profiles", icon="ITALIC")
|
row.label(text=f"{ProfileData.data['total_profiles']} Named Profiles", icon="ITALIC")
|
||||||
|
|||||||
@@ -40,7 +40,11 @@ class Profile(bonsai.core.tool.Profile):
|
|||||||
settings = ifcopenshell.geom.settings()
|
settings = ifcopenshell.geom.settings()
|
||||||
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
|
settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS)
|
||||||
shape = ifcopenshell.geom.create_shape(settings, profile)
|
shape = ifcopenshell.geom.create_shape(settings, profile)
|
||||||
|
|
||||||
verts = shape.verts
|
verts = shape.verts
|
||||||
|
if not verts:
|
||||||
|
raise RuntimeError("Profile shape has no vertices, it probably is invalid.")
|
||||||
|
|
||||||
edges = shape.edges
|
edges = shape.edges
|
||||||
|
|
||||||
grouped_verts = [[verts[i], verts[i + 1]] for i in range(0, len(verts), 3)]
|
grouped_verts = [[verts[i], verts[i + 1]] for i in range(0, len(verts), 3)]
|
||||||
|
|||||||
Reference in New Issue
Block a user