From c344e83f05b46121b7c1913ef1136756ad871983 Mon Sep 17 00:00:00 2001 From: DeepSOIC Date: Fri, 20 May 2016 01:52:07 +0300 Subject: [PATCH] PartDesign: fixes for new body creation 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. --- src/Mod/PartDesign/Gui/CommandBody.cpp | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index a759f4f9e1..c6bac0b2d8 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -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 features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); App::DocumentObject* baseFeature = nullptr; + if (!features.empty()) { if (features.size() == 1) { baseFeature = features[0]; @@ -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 { @@ -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"); @@ -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()); }