From 1bac54e63e6b383abf9970192e176f5c7e766b47 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Wed, 8 Feb 2017 16:06:04 +0100 Subject: [PATCH] Sketcher: new BSpline toolbar / command to hide control polygon --- src/Mod/Sketcher/Gui/AppSketcherGui.cpp | 2 + src/Mod/Sketcher/Gui/CMakeLists.txt | 1 + .../Sketcher/Gui/CommandSketcherBSpline.cpp | 156 ++++++++++++++++++ src/Mod/Sketcher/Gui/Workbench.cpp | 38 ++++- src/Mod/Sketcher/Gui/Workbench.h | 2 + 5 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp diff --git a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp index 1d9bace66..8a2116844 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp @@ -49,6 +49,7 @@ void CreateSketcherCommandsCreateGeo(void); void CreateSketcherCommandsConstraints(void); void CreateSketcherCommandsConstraintAccel(void); void CreateSketcherCommandsAlterGeo(void); +void CreateSketcherCommandsBSpline(void); void loadSketcherResource() { @@ -98,6 +99,7 @@ PyMODINIT_FUNC initSketcherGui() CreateSketcherCommandsConstraints(); CreateSketcherCommandsAlterGeo(); CreateSketcherCommandsConstraintAccel(); + CreateSketcherCommandsBSpline(); SketcherGui::Workbench::init(); diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index fbe91a8dc..6f6c78817 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -79,6 +79,7 @@ SET(SketcherGui_SRCS CommandConstraints.h CommandConstraints.cpp CommandSketcherTools.cpp + CommandSketcherBSpline.cpp CommandAlterGeometry.cpp Resources/Sketcher.qrc PreCompiled.cpp diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp new file mode 100644 index 000000000..741677cdf --- /dev/null +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -0,0 +1,156 @@ +/*************************************************************************** + * 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 +#endif + +# include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ViewProviderSketch.h" +#include "DrawSketchHandler.h" + +#include +#include + +#include "ViewProviderSketch.h" + +using namespace std; +using namespace SketcherGui; +using namespace Sketcher; + +bool isSketcherBSplineActive(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 ActivateBSplineHandler(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); + } + } +} + +extern bool isPolygonShown; + +// Show/Hide BSpline polygon +DEF_STD_CMD_A(CmdSketcherBSplinePolygon); + +CmdSketcherBSplinePolygon::CmdSketcherBSplinePolygon() + :Command("Sketcher_BSplinePolygon") +{ + sAppModule = "Sketcher"; + sGroup = QT_TR_NOOP("Sketcher"); + sMenuText = QT_TR_NOOP("Show/Hide B-Spline control polygon"); + sToolTipText = QT_TR_NOOP("Switches between showing and hiding the control polygons for all B-Splines"); + sWhatsThis = "Sketcher_BSplinePolygon"; + sStatusTip = sToolTipText; + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General"); + if(hGrp->GetBool("BSplinePolygonVisible", true)) + sPixmap = "Sketcher_BSplinePolygon_on"; + else + sPixmap = "Sketcher_BSplinePolygon_off"; + + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplinePolygon::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + Gui::Document * doc= getActiveGuiDocument(); + + SketcherGui::ViewProviderSketch* vp = static_cast(doc->getInEdit()); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General"); + + bool status = hGrp->GetBool("BSplineControlPolygonVisible", true); + + hGrp->SetBool("BSplineControlPolygonVisible", !status); + + vp->showRestoreInformationLayer(); + + if(status) { + if (getAction()) { + getAction()->setIcon(Gui::BitmapFactory().pixmap("Sketcher_BSplinePolygon_on")); + } + } + else { + if (getAction()) { + getAction()->setIcon(Gui::BitmapFactory().pixmap("Sketcher_BSplinePolygon_off")); + } + } +} + +bool CmdSketcherBSplinePolygon::isActive(void) +{ + return isSketcherBSplineActive( getActiveGuiDocument(), false ); +} + + + + +void CreateSketcherCommandsBSpline(void) +{ + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdSketcherBSplinePolygon()); + +} diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 76ae0c4ec..283a5964b 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -79,11 +79,16 @@ Gui::MenuItem* Workbench::setupMenuBar() const Gui::MenuItem* consaccel = new Gui::MenuItem(); consaccel->setCommand("Sketcher tools"); addSketcherWorkbenchTools(*consaccel); + + Gui::MenuItem* bsplines = new Gui::MenuItem(); + bsplines->setCommand("Sketcher B-Spline tools"); + addSketcherWorkbenchBSplines(*bsplines); addSketcherWorkbenchSketchActions( *sketch ); *sketch << geom << cons - << consaccel; + << consaccel + << bsplines; return root; } @@ -107,6 +112,11 @@ Gui::ToolBarItem* Workbench::setupToolBars() const Gui::ToolBarItem* consaccel = new Gui::ToolBarItem(root); consaccel->setCommand("Sketcher tools"); addSketcherWorkbenchTools( *consaccel ); + + Gui::ToolBarItem* bspline = new Gui::ToolBarItem(root); + bspline->setCommand("Sketcher B-Spline tools"); + addSketcherWorkbenchBSplines( *bspline ); + return root; } @@ -233,7 +243,7 @@ inline void SketcherAddWorkbenchConstraints(Gui::ToolBarItem& << "Sketcher_ConstrainAngle" << "Sketcher_ConstrainSnellsLaw" << "Separator" - << "Sketcher_ToggleDrivingConstraint"; + << "Sketcher_ToggleDrivingConstraint"; } template @@ -268,6 +278,19 @@ inline void SketcherAddWorkbenchTools(Gui::ToolBarItem& consac << "Sketcher_RectangularArray"; } +template +inline void SketcherAddWorkbenchBSplines(T& bspline); + +template <> +inline void SketcherAddWorkbenchBSplines(Gui::MenuItem& bspline){ + bspline << "Sketcher_BSplinePolygon"; +} + +template <> +inline void SketcherAddWorkbenchBSplines(Gui::ToolBarItem& bspline){ + bspline << "Sketcher_BSplinePolygon"; +} + template inline void SketcherAddWorkspaceSketchExtra(T& /*sketch*/){ } @@ -298,6 +321,10 @@ void addSketcherWorkbenchConstraints( Gui::MenuItem& cons ){ void addSketcherWorkbenchTools( Gui::MenuItem& consaccel ){ SketcherAddWorkbenchTools( consaccel ); } +void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline ){ + SketcherAddWorkbenchBSplines( bspline ); +} + void addSketcherWorkbenchSketchActions( Gui::MenuItem& sketch ){ Sketcher_addWorkbenchSketchActions( sketch ); } @@ -308,10 +335,17 @@ void addSketcherWorkbenchGeometries( Gui::MenuItem& geom ){ void addSketcherWorkbenchConstraints( Gui::ToolBarItem& cons ){ SketcherAddWorkbenchConstraints( cons ); } + void addSketcherWorkbenchTools( Gui::ToolBarItem& consaccel ) { SketcherAddWorkbenchTools( consaccel ); } + +void addSketcherWorkbenchBSplines( Gui::ToolBarItem& bspline ) +{ + SketcherAddWorkbenchBSplines( bspline ); +} + 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 d9ead5842..bec7a4011 100644 --- a/src/Mod/Sketcher/Gui/Workbench.h +++ b/src/Mod/Sketcher/Gui/Workbench.h @@ -52,11 +52,13 @@ protected: SketcherGuiExport void addSketcherWorkbenchConstraints( Gui::MenuItem& cons ); SketcherGuiExport void addSketcherWorkbenchTools( Gui::MenuItem& consaccel ); +SketcherGuiExport void addSketcherWorkbenchBSplines( Gui::MenuItem& bspline ); 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 addSketcherWorkbenchSketchActions( Gui::ToolBarItem& sketch ); SketcherGuiExport void addSketcherWorkbenchGeometries( Gui::ToolBarItem& geom );