diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index c6c8d73cc8..7b6f869e6c 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -60,8 +60,7 @@ bool isSketcherVirtualSpaceActive(Gui::Document *doc, bool actsOnSelection ) 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 (static_cast(doc->getInEdit()) - ->getSketchMode() == ViewProviderSketch::STATUS_NONE) { + if (static_cast(doc->getInEdit())->getSketchMode() == ViewProviderSketch::STATUS_NONE) { if (!actsOnSelection) return true; else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) @@ -69,17 +68,14 @@ bool isSketcherVirtualSpaceActive(Gui::Document *doc, bool actsOnSelection ) } } } - return false; } -void ActivateVirtualSpaceHandler(Gui::Document *doc,DrawSketchHandler *handler) +void ActivateVirtualSpaceHandler(Gui::Document *doc, DrawSketchHandler *handler) { if (doc) { - if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom - (SketcherGui::ViewProviderSketch::getClassTypeId())) { - - SketcherGui::ViewProviderSketch* vp = static_cast (doc->getInEdit()); + if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(SketcherGui::ViewProviderSketch::getClassTypeId())) { + SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); vp->purgeHandler(); vp->activateHandler(handler); } @@ -90,7 +86,7 @@ void ActivateVirtualSpaceHandler(Gui::Document *doc,DrawSketchHandler *handler) DEF_STD_CMD_A(CmdSketcherSwitchVirtualSpace) CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace() -:Command("Sketcher_SwitchVirtualSpace") + : Command("Sketcher_SwitchVirtualSpace") { sAppModule = "Sketcher"; sGroup = QT_TR_NOOP("Sketcher"); @@ -106,14 +102,12 @@ CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace() void CmdSketcherSwitchVirtualSpace::activated(int iMsg) { Q_UNUSED(iMsg); - bool modeChange=true; + bool modeChange = true; std::vector selection; - if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0){ + if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) { // Now we check whether we have a constraint selected or not. - - // get the selection selection = getSelection().getSelectionEx(); // only one sketch with its subelements are allowed to be selected @@ -131,22 +125,21 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) return; } - for (std::vector::const_iterator it=SubNames.begin();it!=SubNames.end();++it){ + for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { // see if we have constraints, if we do it is not a mode change, but a toggle. - if (it->size() > 10 && it->substr(0,10) == "Constraint") - modeChange=false; + if (it->size() > 10 && it->substr(0, 10) == "Constraint") + modeChange = false; } } if (modeChange) { - Gui::Document * doc= getActiveGuiDocument(); + Gui::Document * doc = getActiveGuiDocument(); SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); - vp->setIsShownVirtualSpace(!vp->getIsShownVirtualSpace()); } - else // toggle the selected constraint(s) - { + // toggle the selected constraint(s) + else { // get the needed lists and objects const std::vector &SubNames = selection[0].getSubNames(); if (SubNames.empty()) { @@ -161,9 +154,9 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) // undo command open openCommand("Toggle constraints to the other virtual space"); - int successful=SubNames.size(); + int successful = SubNames.size(); // 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 constraints if (it->size() > 10 && it->substr(0,10) == "Constraint") { int ConstrId = Sketcher::PropertyConstraintList::getIndexFromConstraintName(*it); @@ -171,7 +164,7 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) try { Gui::cmdAppObjectArgs(Obj, "toggleVirtualSpace(%d)", ConstrId); } - catch(const Base::Exception&) { + catch (const Base::Exception&) { successful--; } } @@ -182,16 +175,15 @@ void CmdSketcherSwitchVirtualSpace::activated(int iMsg) else abortCommand(); + // recomputer and clear the selection (convenience) tryAutoRecompute(Obj); - - // clear the selection (convenience) getSelection().clearSelection(); } } bool CmdSketcherSwitchVirtualSpace::isActive(void) { - return isSketcherVirtualSpaceActive( getActiveGuiDocument(), false ); + return isSketcherVirtualSpaceActive(getActiveGuiDocument(), false); } void CreateSketcherCommandsVirtualSpace(void)