Skip to content

Commit

Permalink
PartDesign: fixes for new body creation
Browse files Browse the repository at this point in the history
Upon creation, new bodies used to steal bits from other parts and
bodies, if they were accidentally selected. Extra checks have been added
to make that much less likely.
  • Loading branch information
DeepSOIC committed May 20, 2016
1 parent 0f75ad6 commit c344e83
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/Mod/PartDesign/Gui/CommandBody.cpp
Expand Up @@ -133,10 +133,14 @@ void CmdPartDesignBody::activated(int iMsg)
{
if ( !PartDesignGui::assureModernWorkflow( getDocument() ) )
return;
App::Part *actPart = PartDesignGui::getActivePart ();
App::Part* partOfBaseFeature = nullptr;

std::vector<App::DocumentObject*> features =
getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
App::DocumentObject* baseFeature = nullptr;


if (!features.empty()) {
if (features.size() == 1) {
baseFeature = features[0];
Expand All @@ -146,15 +150,28 @@ void CmdPartDesignBody::activated(int iMsg)
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Bad base feature"),
QObject::tr("Body can't be based on a PartDesign feature."));
baseFeature = nullptr;

}

if ( baseFeature->isDerivedFrom ( Part::BodyBase::getClassTypeId() ) ) {
else if (PartDesign::Body::findBodyOf ( baseFeature )){
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Bad base feature"),
QObject::tr("%1 already belongs to a body, can't use it as base feature for another body.")
.arg(QString::fromUtf8(baseFeature->Label.getValue())));
baseFeature = nullptr;
}
else if ( baseFeature->isDerivedFrom ( Part::BodyBase::getClassTypeId() ) ) {
// Prevent creating bodies based on bodies
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Bad base feature"),
QObject::tr("Body can't be based on annother body."));
baseFeature = nullptr;
} else {

partOfBaseFeature = App::Part::getPartOfObject(baseFeature);
if (partOfBaseFeature != 0 && partOfBaseFeature != actPart){
//prevent cross-part mess
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Bad base feature"),
QObject::tr("Base feature (%1) belongs to other part.")
.arg(QString::fromUtf8(baseFeature->Label.getValue())));
baseFeature = nullptr;
};
}

} else {
Expand All @@ -164,8 +181,6 @@ void CmdPartDesignBody::activated(int iMsg)
}
}

// first check if Part is already created:
App::Part *actPart = PartDesignGui::getActivePart ();

openCommand("Add a Body");

Expand All @@ -174,6 +189,11 @@ void CmdPartDesignBody::activated(int iMsg)
// add the Body feature itself, and make it active
doCommand(Doc,"App.activeDocument().addObject('PartDesign::Body','%s')", bodyName.c_str());
if (baseFeature) {
if (partOfBaseFeature){
//withdraw base feature from Part, otherwise visibility mandess results
doCommand(Doc,"App.activeDocument().%s.removeObject(App.activeDocument().%s)",
partOfBaseFeature->getNameInDocument(), baseFeature->getNameInDocument());
}
doCommand(Doc,"App.activeDocument().%s.BaseFeature = App.activeDocument().%s",
bodyName.c_str(), baseFeature->getNameInDocument());
}
Expand Down

0 comments on commit c344e83

Please sign in to comment.