diff --git a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp index d3efd648c9..46c0fea99a 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp @@ -50,6 +50,7 @@ void CreateSketcherCommandsConstraints(void); void CreateSketcherCommandsConstraintAccel(void); void CreateSketcherCommandsAlterGeo(void); void CreateSketcherCommandsBSpline(void); +void CreateSketcherCommandsVirtualSpace(void); void loadSketcherResource() { @@ -106,6 +107,7 @@ PyMOD_INIT_FUNC(SketcherGui) CreateSketcherCommandsAlterGeo(); CreateSketcherCommandsConstraintAccel(); CreateSketcherCommandsBSpline(); + CreateSketcherCommandsVirtualSpace(); SketcherGui::Workbench::init(); diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index 505caff974..e26afcf7ec 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -83,6 +83,7 @@ SET(SketcherGui_SRCS CommandConstraints.cpp CommandSketcherTools.cpp CommandSketcherBSpline.cpp + CommandSketcherVirtualSpace.cpp CommandAlterGeometry.cpp Resources/Sketcher.qrc PreCompiled.cpp diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp new file mode 100644 index 0000000000..60e2e8a1fb --- /dev/null +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -0,0 +1,130 @@ +/*************************************************************************** + * Copyright (c) 2017 Abdullah Tahiri * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +# include +#endif + +# include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ViewProviderSketch.h" +#include "DrawSketchHandler.h" + +#include +#include + +#include "CommandConstraints.h" + +using namespace std; +using namespace SketcherGui; +using namespace Sketcher; + +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 (!actsOnSelection) + return true; + else if (Gui::Selection().countObjectsOfType(Sketcher::SketchObject::getClassTypeId()) > 0) + return true; + } + } + } + + return false; +} + +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()); + vp->purgeHandler(); + vp->activateHandler(handler); + } + } +} + +// Show/Hide B-spline degree +DEF_STD_CMD_A(CmdSketcherSwitchVirtualSpace); + +CmdSketcherSwitchVirtualSpace::CmdSketcherSwitchVirtualSpace() +:Command("Sketcher_SwitchVirtualSpace") +{ + sAppModule = "Sketcher"; + sGroup = QT_TR_NOOP("Sketcher"); + sMenuText = QT_TR_NOOP("Switch virtual space"); + sToolTipText = QT_TR_NOOP("Switches between the two virtual spaces"); + sWhatsThis = "Sketcher_SwitchVirtualSpace"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_SwitchVirtualSpace"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherSwitchVirtualSpace::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::Document * doc= getActiveGuiDocument(); + + SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); + + vp->setIsShownVirtualSpace(!vp->getIsShownVirtualSpace()); + +} + +bool CmdSketcherSwitchVirtualSpace::isActive(void) +{ + return isSketcherVirtualSpaceActive( getActiveGuiDocument(), false ); +} + + +void CreateSketcherCommandsVirtualSpace(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdSketcherSwitchVirtualSpace()); +} diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 4acb53db21..5b6830f273 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -83,12 +83,17 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* bsplines = new Gui::MenuItem(); bsplines->setCommand("Sketcher B-spline tools"); addSketcherWorkbenchBSplines(*bsplines); + + Gui::MenuItem* virtualspace = new Gui::MenuItem(); + virtualspace->setCommand("Sketcher Virtual Space"); + addSketcherWorkbenchVirtualSpace(*virtualspace); addSketcherWorkbenchSketchActions( *sketch ); *sketch << geom << cons << consaccel - << bsplines; + << bsplines + << virtualspace; return root; } @@ -116,6 +121,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* bspline = new Gui::ToolBarItem(root); bspline->setCommand("Sketcher B-spline tools"); addSketcherWorkbenchBSplines( *bspline ); + + Gui::ToolBarItem* virtualspace = new Gui::ToolBarItem(root); + bspline->setCommand("Sketcher Virtual Space tools"); + addSketcherWorkbenchVirtualSpace( *virtualspace ); return root; } @@ -306,6 +315,19 @@ inline void SketcherAddWorkbenchBSplines(Gui::ToolBarItem& bsp << "Sketcher_CompModifyKnotMultiplicity"; } +template +inline void SketcherAddWorkbenchVirtualSpace(T& virtualspace); + +template <> +inline void SketcherAddWorkbenchVirtualSpace(Gui::MenuItem& virtualspace){ + virtualspace << "Sketcher_SwitchVirtualSpace"; +} + +template <> +inline void SketcherAddWorkbenchVirtualSpace(Gui::ToolBarItem& virtualspace){ + virtualspace << "Sketcher_SwitchVirtualSpace"; +} + template inline void SketcherAddWorkspaceSketchExtra(T& /*sketch*/){ } @@ -342,6 +364,10 @@ void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline ){ SketcherAddWorkbenchBSplines( bspline ); } +void addSketcherWorkbenchVirtualSpace( Gui::MenuItem& virtualspace ){ + SketcherAddWorkbenchVirtualSpace( virtualspace ); +} + void addSketcherWorkbenchSketchActions( Gui::MenuItem& sketch ){ Sketcher_addWorkbenchSketchActions( sketch ); } @@ -363,6 +389,11 @@ void addSketcherWorkbenchBSplines( Gui::ToolBarItem& bspline ) SketcherAddWorkbenchBSplines( bspline ); } +void addSketcherWorkbenchVirtualSpace( Gui::ToolBarItem& virtualspace ) +{ + SketcherAddWorkbenchVirtualSpace( virtualspace ); +} + void addSketcherWorkbenchSketchActions( Gui::ToolBarItem& sketch ){ Sketcher_addWorkbenchSketchActions( sketch ); } diff --git a/src/Mod/Sketcher/Gui/Workbench.h b/src/Mod/Sketcher/Gui/Workbench.h index bec7a4011f..459b91f86b 100644 --- a/src/Mod/Sketcher/Gui/Workbench.h +++ b/src/Mod/Sketcher/Gui/Workbench.h @@ -53,12 +53,14 @@ protected: SketcherGuiExport void addSketcherWorkbenchConstraints( Gui::MenuItem& cons ); SketcherGuiExport void addSketcherWorkbenchTools( Gui::MenuItem& consaccel ); SketcherGuiExport void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline ); +SketcherGuiExport void addSketcherWorkbenchVirtualSpace( Gui::MenuItem& virtualspace ); SketcherGuiExport void addSketcherWorkbenchSketchActions( Gui::MenuItem& sketch ); SketcherGuiExport void addSketcherWorkbenchGeometries( Gui::MenuItem& geom ); SketcherGuiExport void addSketcherWorkbenchConstraints( Gui::ToolBarItem& cons ); SketcherGuiExport void addSketcherWorkbenchTools( Gui::ToolBarItem& consaccel ); SketcherGuiExport void addSketcherWorkbenchBSplines( Gui::ToolBarItem& bspline ); +SketcherGuiExport void addSketcherWorkbenchVirtualSpace( Gui::ToolBarItem& virtualspace ); SketcherGuiExport void addSketcherWorkbenchSketchActions( Gui::ToolBarItem& sketch ); SketcherGuiExport void addSketcherWorkbenchGeometries( Gui::ToolBarItem& geom );