mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-10 06:00:51 +00:00
Bonsai: guard decorator draws against None and empty lists
Three crashes that surfaced when viewport decorators ran against
selected non-IFC blender objects or top-level objects with no
aggregate parent:
- WallAxisDecorator.draw_wall_axis: tool.Ifc.get_entity(obj) returns
None for a non-IFC selection (default cube, lamp, camera). The
subsequent element.is_a("IfcWall") raised AttributeError on every
redraw. Guard with `element and element.is_a(...)`.
- _ConnectedNetworkPathDecorator flow-segment loop: same shape;
iterates entries that may be None, calls .is_a("IfcFlowSegment")
unconditionally. Same guard.
- AggregateDecorator.draw_aggregate: indexes aggregates_list[-1]
unconditionally in the else branch; raises IndexError when the
selected element has no aggregate parent. Also leaves `aggregate`
unbound across loop iterations in the `in_aggregate_mode` branch
when `index <= 0`. Define `aggregate = None` per loop iteration
and guard the [-1] indexing with `elif aggregates_list:`.
Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -158,12 +158,13 @@ class AggregateDecorator(tool.Blender.ViewportDecorator):
|
|||||||
aggregates.append(obj)
|
aggregates.append(obj)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
aggregate = None
|
||||||
aggregates_list = tool.Aggregate.get_aggregates_recursively(element)
|
aggregates_list = tool.Aggregate.get_aggregates_recursively(element)
|
||||||
if props.in_aggregate_mode and props.editing_aggregate:
|
if props.in_aggregate_mode and props.editing_aggregate:
|
||||||
index = aggregates_list.index(tool.Ifc.get_entity(props.editing_aggregate))
|
index = aggregates_list.index(tool.Ifc.get_entity(props.editing_aggregate))
|
||||||
if index > 0:
|
if index > 0:
|
||||||
aggregate = aggregates_list[index - 1]
|
aggregate = aggregates_list[index - 1]
|
||||||
else:
|
elif aggregates_list:
|
||||||
aggregate = aggregates_list[-1]
|
aggregate = aggregates_list[-1]
|
||||||
if aggregate:
|
if aggregate:
|
||||||
aggregates.append(tool.Ifc.get_object(aggregate))
|
aggregates.append(tool.Ifc.get_object(aggregate))
|
||||||
|
|||||||
@@ -1597,7 +1597,7 @@ class WallAxisDecorator(tool.Blender.ViewportDecorator):
|
|||||||
self.line_shader.uniform_float("lineWidth", 2.0)
|
self.line_shader.uniform_float("lineWidth", 2.0)
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
if element.is_a("IfcWall"):
|
if element and element.is_a("IfcWall"):
|
||||||
layers = tool.Model.get_material_layer_parameters(element)
|
layers = tool.Model.get_material_layer_parameters(element)
|
||||||
axis = tool.Model.get_wall_axis(obj, layers)
|
axis = tool.Model.get_wall_axis(obj, layers)
|
||||||
side = [tuple(list(v) + [obj.location.z]) for v in axis["side"]]
|
side = [tuple(list(v) + [obj.location.z]) for v in axis["side"]]
|
||||||
@@ -2702,7 +2702,7 @@ class MEPSystemPathDecorator(_ConnectedNetworkPathDecorator):
|
|||||||
lines: list[tuple[tuple[float, float, float], tuple[float, float, float]]] = []
|
lines: list[tuple[tuple[float, float, float], tuple[float, float, float]]] = []
|
||||||
port_positions: list[tuple[float, float, float]] = []
|
port_positions: list[tuple[float, float, float]] = []
|
||||||
for element in connected:
|
for element in connected:
|
||||||
if element.is_a("IfcFlowSegment"):
|
if element and element.is_a("IfcFlowSegment"):
|
||||||
if not tool.Geometry.has_axis_representation(element):
|
if not tool.Geometry.has_axis_representation(element):
|
||||||
continue
|
continue
|
||||||
obj = tool.Ifc.get_object(element)
|
obj = tool.Ifc.get_object(element)
|
||||||
|
|||||||
Reference in New Issue
Block a user