Merge pull request #25555 from furgo16/assembly-exploded-points-equal-fix

Assembly: exploded points equal fix
This commit is contained in:
Chris Hennes
2025-11-24 11:52:51 -06:00
committed by GitHub
2 changed files with 24 additions and 4 deletions

View File

@@ -2092,6 +2092,16 @@ bool Document::afterRestore(const std::vector<DocumentObject*>& objArray, bool c
FC_ERR("Failed to restore " << obj->getFullName() << ": " << e.what());
}
catch (...) {
// If a Python exception occurred, it must be cleared immediately.
// Otherwise, the interpreter remains in a dirty state, causing
// Segfaults later when FreeCAD interacts with Python.
if (PyErr_Occurred()) {
Base::Console().error("Python error during object restore:\n");
PyErr_Print(); // Print the traceback to stderr/Console
PyErr_Clear(); // Reset the interpreter state
}
d->addRecomputeLog("Unknown exception on restore", obj);
FC_ERR("Failed to restore " << obj->getFullName() << ": " << "unknown exception");
}

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)