Assembly: Fix #12889 : deleting a part does not delete joint and later crashes freecad.

This commit is contained in:
PaddleStroke
2024-03-12 18:22:40 +01:00
committed by Yorik van Havre
parent ef010e6f7c
commit 5349d08abe
2 changed files with 13 additions and 4 deletions

View File

@@ -235,7 +235,7 @@ void AssemblyObject::undoSolve()
previousPositions.clear();
// update joint placements:
getJoints();
getJoints(/*updateJCS*/ true, /*delBadJoints*/ false);
}
void AssemblyObject::clearUndo()
@@ -398,7 +398,7 @@ JointGroup* AssemblyObject::getJointGroup()
return nullptr;
}
std::vector<App::DocumentObject*> AssemblyObject::getJoints(bool updateJCS)
std::vector<App::DocumentObject*> AssemblyObject::getJoints(bool updateJCS, bool delBadJoints)
{
std::vector<App::DocumentObject*> joints = {};
@@ -414,7 +414,16 @@ std::vector<App::DocumentObject*> AssemblyObject::getJoints(bool updateJCS)
}
auto* prop = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Activated"));
if (prop && !prop->getValue()) {
if (!prop || !prop->getValue()) {
// Filter grounded joints and deactivated joints.
continue;
}
if (!getLinkObjFromProp(joint, "Part1") || !getLinkObjFromProp(joint, "Part2")) {
// Remove incomplete joints. Left-over when the user delets a part.
if (delBadJoints) {
getDocument()->removeObject(joint->getNameInDocument());
}
continue;
}