Assembly: Prevent zero-length line creation in ExplodedView

Safeguards the generation of explosion trail lines to avoid creating
invalid geometry.

Previously, if a part displacement was zero (or effectively zero),
`Part.LineSegment` would attempt to create a line with identical start
and end points, causing OpenCascade to throw a `Part.OCCError`. This
resulted in failures during document restoration and recomputes.

This commit introduces a `_createSafeLine` helper method that checks the
distance against a `1e-7` (near-zero) tolerance before attempting to
generate the shape.
This commit is contained in:
Furgo
2025-11-22 19:39:57 +01:00
parent b571889ab5
commit 2763bb962f

View File

@@ -132,6 +132,14 @@ class ExplodedView:
return obj
return None
def _createSafeLine(self, start, end):
"""Creates a LineSegment shape only if points are not coincident."""
from Part import Precision
if (start - end).Length > Precision.confusion():
return LineSegment(start, end).toShape()
return None
def saveAssemblyAndExplode(self, viewObj):
self.initialPlcs = UtilsAssembly.saveAssemblyPartsPlacements(self.getAssembly(viewObj))
@@ -140,8 +148,9 @@ class ExplodedView:
lines = []
for startPos, endPos in self.positions:
line = LineSegment(startPos, endPos).toShape()
lines.append(line)
line = self._createSafeLine(startPos, endPos)
if line:
lines.append(line)
if lines:
return Compound(lines)
@@ -244,8 +253,9 @@ class ExplodedView:
# Add shapes for the explosion lines
for start_pos, end_pos in line_positions:
line = LineSegment(start_pos, end_pos).toShape()
exploded_shapes.append(line)
line = self._createSafeLine(start_pos, end_pos)
if line:
exploded_shapes.append(line)
if exploded_shapes:
return Compound(exploded_shapes)