diff --git a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp index cb1e4a70d..e594307cf 100644 --- a/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp +++ b/src/Mod/Sketcher/Gui/CommandAlterGeometry.cpp @@ -44,13 +44,14 @@ using namespace Sketcher; bool isAlterGeoActive(Gui::Document *doc) { - if (doc) + if (doc) { // checks if a Sketch Viewprovider is in Edit and is in no special mode - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) - if (dynamic_cast(doc->getInEdit()) - ->getSketchMode() == ViewProviderSketch::STATUS_NONE) - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) - return true; + SketcherGui::ViewProviderSketch* edit = dynamic_cast(doc->getInEdit()); + if (edit && edit->getSketchMode() == ViewProviderSketch::STATUS_NONE) { + return Gui::Selection().isSelected(edit->getObject()); + } + } + return false; } @@ -88,12 +89,22 @@ void CmdSketcherToggleConstruction::activated(int iMsg) // get the needed lists and objects const std::vector &SubNames = selection[0].getSubNames(); + if (SubNames.empty()) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("Select edge(s) from the sketch.")); + return; + } + + // make sure the selected object is the sketch in edit mode + const App::DocumentObject* obj = selection[0].getObject(); + ViewProviderSketch* sketchView = static_cast + (Gui::Application::Instance->getViewProvider(obj)); // undo command open - openCommand("toggle draft from/to draft"); + openCommand("Toggle draft from/to draft"); // go through the selected subelements - for(std::vector::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ + for (std::vector::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ // only handle edges if (it->size() > 4 && it->substr(0,4) == "Edge") { int GeoId = std::atoi(it->substr(4,4000).c_str()) - 1;