From 5d39df88ee02be8bcb1ca63b92d6df38bc7b707c Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Thu, 22 Aug 2013 19:50:50 +0200 Subject: [PATCH] Prevent user from selecting a sketch plane that is not in the active body --- src/Mod/PartDesign/Gui/Command.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 47cbfecd9..8361bfd16 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -767,9 +767,10 @@ void CmdPartDesignNewSketch::activated(int iMsg) else if (FaceFilter.match() || PlaneFilter.match()) { // get the selected object std::string supportString; + Part::Feature* feat; if (FaceFilter.match()) { - Part::Feature *part = static_cast(FaceFilter.Result[0][0].getObject()); + feat = static_cast(FaceFilter.Result[0][0].getObject()); // FIXME: Reject or warn about feature that is outside of active body, and feature // that comes after the current insert point (Tip) const std::vector &sub = FaceFilter.Result[0][0].getSubNames(); @@ -780,7 +781,7 @@ void CmdPartDesignNewSketch::activated(int iMsg) return; } // get the selected sub shape (a Face) - const Part::TopoShape &shape = part->Shape.getValue(); + const Part::TopoShape &shape = feat->Shape.getValue(); TopoDS_Shape sh = shape.getSubShape(sub[0].c_str()); const TopoDS_Face& face = TopoDS::Face(sh); if (face.IsNull()){ @@ -799,9 +800,19 @@ void CmdPartDesignNewSketch::activated(int iMsg) supportString = FaceFilter.Result[0][0].getAsPropertyLinkSubString(); } else { - Part::Feature *plane = static_cast(PlaneFilter.Result[0][0].getObject()); + feat = static_cast(PlaneFilter.Result[0][0].getObject()); // TODO: Find out whether the user picked front or back of this plane - supportString = std::string("(App.activeDocument().") + plane->getNameInDocument() + ", ['front'])"; + supportString = std::string("(App.activeDocument().") + feat->getNameInDocument() + ", ['front'])"; + } + + if (!pcActiveBody->hasFeature(feat)) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from other body"), + QObject::tr("You have to select a face or plane from the active body!")); + return; + } else if (pcActiveBody->isAfterTip(feat)) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Selection from inactive feature"), + QObject::tr("You have to select a face or plane before the current insert point, or move the insert point")); + return; } // create Sketch on Face or Plane @@ -842,12 +853,11 @@ void CmdPartDesignNewSketch::activated(int iMsg) if (base) continue; // Check whether this plane belongs to the active body - PartDesign::Body* body = PartDesignGui::getBody(); - if (!body->hasFeature(*p)) { + if (!pcActiveBody->hasFeature(*p)) { status.push_back(PartDesignGui::FeaturePickDialog::otherBody); continue; } else { - if (body->isAfterTip(*p)) + if (pcActiveBody->isAfterTip(*p)) status.push_back(PartDesignGui::FeaturePickDialog::afterTip); continue; }