PartDesign: fix a couple of crashes

The first crash was reported here:
http://forum.freecadweb.org/viewtopic.php?f=20&t=11205&start=50#p91052

The second one accures then moving a feature from a body without solid
features.
This commit is contained in:
Alexander Golubev 2015-06-28 04:16:21 +03:00 committed by Stefan Tröger
parent 08e4151ea1
commit b9f4e10fa5

View File

@ -374,12 +374,17 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
for (std::vector<App::DocumentObject*>::const_iterator f = features.begin(); f != features.end(); f++) {
// Find body of this feature
Part::BodyBase* source = PartDesign::Body::findBodyOf(*f);
if (source == target) continue;
bool featureIsTip = (source->Tip.getValue() == *f);
bool featureIsTip = false;
// Remove from source body
doCommand(Doc,"App.activeDocument().%s.removeFeature(App.activeDocument().%s)",
if (source == target) continue;
// Remove from the source body if the feature belonged to a body
if (source) {
featureIsTip = (source->Tip.getValue() == *f);
doCommand(Doc,"App.activeDocument().%s.removeFeature(App.activeDocument().%s)",
source->getNameInDocument(), (*f)->getNameInDocument());
}
// Add to target body (always at the Tip)
doCommand(Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)",
target->getNameInDocument(), (*f)->getNameInDocument());
@ -391,7 +396,9 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
// If we removed the tip of the source body, make the new tip visible
if (featureIsTip) {
App::DocumentObject* prevSolidFeature = source->getPrevSolidFeature();
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", prevSolidFeature->getNameInDocument());
if (prevSolidFeature) {
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", prevSolidFeature->getNameInDocument());
}
}
// Hide old tip and show new tip (the moved feature) of the target body
@ -399,6 +406,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")", prevSolidFeature->getNameInDocument());
doCommand(Gui,"Gui.activeDocument().show(\"%s\")", (*f)->getNameInDocument());
}
// TODO: if we are inserting a sketch which wasn't part of any body try to set right support for it
}
}