From 014a4e671af5d5866dd301959bed9d7820299446 Mon Sep 17 00:00:00 2001 From: Florian Foinant-Willig Date: Wed, 31 May 2023 22:34:03 +0200 Subject: [PATCH] Sketcher: Add command to switch arc helper --- src/Mod/Sketcher/Gui/AppSketcherGui.cpp | 2 + src/Mod/Sketcher/Gui/CMakeLists.txt | 1 + .../Sketcher/Gui/CommandSketcherBSpline.cpp | 321 --------------- .../Sketcher/Gui/CommandSketcherOverlay.cpp | 389 ++++++++++++++++++ src/Mod/Sketcher/Gui/Utils.cpp | 20 + src/Mod/Sketcher/Gui/Utils.h | 3 + src/Mod/Sketcher/Gui/Workbench.cpp | 11 +- 7 files changed, 422 insertions(+), 325 deletions(-) create mode 100644 src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp diff --git a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp index eb389779bd..b53b551e91 100644 --- a/src/Mod/Sketcher/Gui/AppSketcherGui.cpp +++ b/src/Mod/Sketcher/Gui/AppSketcherGui.cpp @@ -47,6 +47,7 @@ void CreateSketcherCommandsConstraints(); void CreateSketcherCommandsConstraintAccel(); void CreateSketcherCommandsAlterGeo(); void CreateSketcherCommandsBSpline(); +void CreateSketcherCommandsOverlay(); void CreateSketcherCommandsVirtualSpace(); void loadSketcherResource() @@ -116,6 +117,7 @@ PyMOD_INIT_FUNC(SketcherGui) CreateSketcherCommandsAlterGeo(); CreateSketcherCommandsConstraintAccel(); CreateSketcherCommandsBSpline(); + CreateSketcherCommandsOverlay(); CreateSketcherCommandsVirtualSpace(); SketcherGui::Workbench::init(); diff --git a/src/Mod/Sketcher/Gui/CMakeLists.txt b/src/Mod/Sketcher/Gui/CMakeLists.txt index d669e70f06..08772bda5a 100644 --- a/src/Mod/Sketcher/Gui/CMakeLists.txt +++ b/src/Mod/Sketcher/Gui/CMakeLists.txt @@ -84,6 +84,7 @@ SET(SketcherGui_SRCS CommandConstraints.cpp CommandSketcherTools.cpp CommandSketcherBSpline.cpp + CommandSketcherOverlay.cpp CommandSketcherVirtualSpace.cpp CommandAlterGeometry.cpp Resources/Sketcher.qrc diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index 57a3a61caf..50fd6eb2a4 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -49,26 +49,6 @@ 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) { std::unique_ptr ptr(handler); @@ -83,14 +63,6 @@ void ActivateBSplineHandler(Gui::Document* doc, DrawSketchHandler* handler) } } -void ShowRestoreInformationLayer(const char* visibleelementname) -{ - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( - "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - bool status = hGrp->GetBool(visibleelementname, true); - hGrp->SetBool(visibleelementname, !status); -} - /// For a knot given by (GeoId, PosId) finds the B-Spline and the knot's /// index within it (by OCC numbering). /// Returns true if the entities are found, false otherwise. @@ -129,293 +101,6 @@ bool findBSplineAndKnotIndex(Sketcher::SketchObject* Obj, int knotGeoId, return false; } -// Show/Hide B-spline degree -DEF_STD_CMD_A(CmdSketcherBSplineDegree) - -CmdSketcherBSplineDegree::CmdSketcherBSplineDegree() - : Command("Sketcher_BSplineDegree") -{ - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide B-spline degree"); - sToolTipText = QT_TR_NOOP("Switches between showing and hiding the degree for all B-splines"); - sWhatsThis = "Sketcher_BSplineDegree"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_BSplineDegree"; - sAccel = ""; - eType = ForEdit; -} - -void CmdSketcherBSplineDegree::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - ShowRestoreInformationLayer("BSplineDegreeVisible"); -} - -bool CmdSketcherBSplineDegree::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} - -// Show/Hide B-spline polygon -DEF_STD_CMD_A(CmdSketcherBSplinePolygon) - -CmdSketcherBSplinePolygon::CmdSketcherBSplinePolygon() - : Command("Sketcher_BSplinePolygon") -{ - sAppModule = "Sketcher"; - sGroup = "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; - sPixmap = "Sketcher_BSplinePolygon"; - sAccel = ""; - eType = ForEdit; -} - -void CmdSketcherBSplinePolygon::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - ShowRestoreInformationLayer("BSplineControlPolygonVisible"); -} - -bool CmdSketcherBSplinePolygon::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} - -// Show/Hide B-spline comb -DEF_STD_CMD_A(CmdSketcherBSplineComb) - -CmdSketcherBSplineComb::CmdSketcherBSplineComb() - : Command("Sketcher_BSplineComb") -{ - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide B-spline curvature comb"); - sToolTipText = - QT_TR_NOOP("Switches between showing and hiding the curvature comb for all B-splines"); - sWhatsThis = "Sketcher_BSplineComb"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_BSplineComb"; - sAccel = ""; - eType = ForEdit; -} - -void CmdSketcherBSplineComb::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - ShowRestoreInformationLayer("BSplineCombVisible"); -} - -bool CmdSketcherBSplineComb::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} - -// -DEF_STD_CMD_A(CmdSketcherBSplineKnotMultiplicity) - -CmdSketcherBSplineKnotMultiplicity::CmdSketcherBSplineKnotMultiplicity() - : Command("Sketcher_BSplineKnotMultiplicity") -{ - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide B-spline knot multiplicity"); - sToolTipText = - QT_TR_NOOP("Switches between showing and hiding the knot multiplicity for all B-splines"); - sWhatsThis = "Sketcher_BSplineKnotMultiplicity"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_BSplineKnotMultiplicity"; - sAccel = ""; - eType = ForEdit; -} - -void CmdSketcherBSplineKnotMultiplicity::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - ShowRestoreInformationLayer("BSplineKnotMultiplicityVisible"); -} - -bool CmdSketcherBSplineKnotMultiplicity::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} - -// -DEF_STD_CMD_A(CmdSketcherBSplinePoleWeight) - -CmdSketcherBSplinePoleWeight::CmdSketcherBSplinePoleWeight() - : Command("Sketcher_BSplinePoleWeight") -{ - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide B-spline control point weight"); - sToolTipText = QT_TR_NOOP( - "Switches between showing and hiding the control point weight for all B-splines"); - sWhatsThis = "Sketcher_BSplinePoleWeight"; - sStatusTip = sToolTipText; - sPixmap = "Sketcher_BSplinePoleWeight"; - sAccel = ""; - eType = ForEdit; -} - -void CmdSketcherBSplinePoleWeight::activated(int iMsg) -{ - Q_UNUSED(iMsg); - - ShowRestoreInformationLayer("BSplinePoleWeightVisible"); -} - -bool CmdSketcherBSplinePoleWeight::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} - -// Composite drop down menu for show/hide geometry information layer -DEF_STD_CMD_ACLU(CmdSketcherCompBSplineShowHideGeometryInformation) - -CmdSketcherCompBSplineShowHideGeometryInformation:: - CmdSketcherCompBSplineShowHideGeometryInformation() - : Command("Sketcher_CompBSplineShowHideGeometryInformation") -{ - sAppModule = "Sketcher"; - sGroup = "Sketcher"; - sMenuText = QT_TR_NOOP("Show/hide B-spline information layer"); - sToolTipText = sMenuText; - sWhatsThis = "Sketcher_CompBSplineShowHideGeometryInformation"; - sStatusTip = sToolTipText; - eType = ForEdit; -} - -void CmdSketcherCompBSplineShowHideGeometryInformation::activated(int iMsg) -{ - Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); - Gui::Command* cmd; - - if (iMsg == 0) - cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineDegree"); - else if (iMsg == 1) - cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePolygon"); - else if (iMsg == 2) - cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineComb"); - else if (iMsg == 3) - cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineKnotMultiplicity"); - else if (iMsg == 4) - cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePoleWeight"); - else - return; - - cmd->invoke(0); - - // Since the default icon is reset when enabling/disabling the command we have - // to explicitly set the icon of the used command. - Gui::ActionGroup* pcAction = qobject_cast(_pcAction); - QList a = pcAction->actions(); - - assert(iMsg < a.size()); - pcAction->setIcon(a[iMsg]->icon()); - // we must also set the tooltip of the used command - pcAction->setToolTip(a[iMsg]->toolTip()); -} - -Gui::Action* CmdSketcherCompBSplineShowHideGeometryInformation::createAction() -{ - Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); - pcAction->setDropDownMenu(true); - applyCommandData(this->className(), pcAction); - - QAction* c1 = pcAction->addAction(QString()); - c1->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineDegree")); - QAction* c2 = pcAction->addAction(QString()); - c2->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplinePolygon")); - QAction* c3 = pcAction->addAction(QString()); - c3->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineComb")); - QAction* c4 = pcAction->addAction(QString()); - c4->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineKnotMultiplicity")); - QAction* c5 = pcAction->addAction(QString()); - c5->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplinePoleWeight")); - - _pcAction = pcAction; - languageChange(); - - pcAction->setIcon(c2->icon()); - int defaultId = 1; - pcAction->setProperty("defaultAction", QVariant(defaultId)); - - return pcAction; -} - -void CmdSketcherCompBSplineShowHideGeometryInformation::languageChange() -{ - Command::languageChange(); - - if (!_pcAction) - return; - Gui::ActionGroup* pcAction = qobject_cast(_pcAction); - QList a = pcAction->actions(); - - QAction* c1 = a[0]; - c1->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", - "Show/hide B-spline degree")); - c1->setToolTip(QApplication::translate( - "Sketcher_BSplineDegree", - "Switches between showing and hiding the degree for all B-splines")); - c1->setStatusTip(QApplication::translate( - "Sketcher_BSplineDegree", - "Switches between showing and hiding the degree for all B-splines")); - QAction* c2 = a[1]; - c2->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", - "Show/hide B-spline control polygon")); - c2->setToolTip(QApplication::translate( - "Sketcher_BSplinePolygon", - "Switches between showing and hiding the control polygons for all B-splines")); - c2->setStatusTip(QApplication::translate( - "Sketcher_BSplinePolygon", - "Switches between showing and hiding the control polygons for all B-splines")); - QAction* c3 = a[2]; - c3->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", - "Show/hide B-spline curvature comb")); - c3->setToolTip(QApplication::translate( - "Sketcher_BSplineComb", - "Switches between showing and hiding the curvature comb for all B-splines")); - c3->setStatusTip(QApplication::translate( - "Sketcher_BSplineComb", - "Switches between showing and hiding the curvature comb for all B-splines")); - QAction* c4 = a[3]; - c4->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", - "Show/hide B-spline knot multiplicity")); - c4->setToolTip(QApplication::translate( - "Sketcher_BSplineKnotMultiplicity", - "Switches between showing and hiding the knot multiplicity for all B-splines")); - c4->setStatusTip(QApplication::translate( - "Sketcher_BSplineKnotMultiplicity", - "Switches between showing and hiding the knot multiplicity for all B-splines")); - - QAction* c5 = a[4]; - c5->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", - "Show/hide B-spline control point weight")); - c5->setToolTip(QApplication::translate( - "Sketcher_BSplinePoleWeight", - "Switches between showing and hiding the control point weight for all B-splines")); - c5->setStatusTip(QApplication::translate( - "Sketcher_BSplinePoleWeight", - "Switches between showing and hiding the control point weight for all B-splines")); -} - -void CmdSketcherCompBSplineShowHideGeometryInformation::updateAction(int /*mode*/) -{} - -bool CmdSketcherCompBSplineShowHideGeometryInformation::isActive() -{ - return isSketcherBSplineActive(getActiveGuiDocument(), false); -} // Convert to NURBS DEF_STD_CMD_A(CmdSketcherConvertToNURBS) @@ -1385,12 +1070,6 @@ void CreateSketcherCommandsBSpline() { Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); - rcCmdMgr.addCommand(new CmdSketcherBSplineDegree()); - rcCmdMgr.addCommand(new CmdSketcherBSplinePolygon()); - rcCmdMgr.addCommand(new CmdSketcherBSplineComb()); - rcCmdMgr.addCommand(new CmdSketcherBSplineKnotMultiplicity()); - rcCmdMgr.addCommand(new CmdSketcherBSplinePoleWeight()); - rcCmdMgr.addCommand(new CmdSketcherCompBSplineShowHideGeometryInformation()); rcCmdMgr.addCommand(new CmdSketcherConvertToNURBS()); rcCmdMgr.addCommand(new CmdSketcherIncreaseDegree()); rcCmdMgr.addCommand(new CmdSketcherDecreaseDegree()); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp new file mode 100644 index 0000000000..5f2f90f6c6 --- /dev/null +++ b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp @@ -0,0 +1,389 @@ +/*************************************************************************** + * Copyright (c) 2023 Florian Foinant-Willig * + * * + * 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 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "DrawSketchHandler.h" +#include "Utils.h" +#include "ViewProviderSketch.h" + +using namespace std; +using namespace SketcherGui; +using namespace Sketcher; + + +void ShowRestoreInformationLayer(const char* visibleelementname) +{ + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); + bool status = hGrp->GetBool(visibleelementname, true); + hGrp->SetBool(visibleelementname, !status); +} + +// Show/Hide B-spline degree +DEF_STD_CMD_A(CmdSketcherBSplineDegree) + +CmdSketcherBSplineDegree::CmdSketcherBSplineDegree() + : Command("Sketcher_BSplineDegree") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide B-spline degree"); + sToolTipText = QT_TR_NOOP("Switches between showing and hiding the degree for all B-splines"); + sWhatsThis = "Sketcher_BSplineDegree"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_BSplineDegree"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplineDegree::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("BSplineDegreeVisible"); +} + +bool CmdSketcherBSplineDegree::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// Show/Hide B-spline polygon +DEF_STD_CMD_A(CmdSketcherBSplinePolygon) + +CmdSketcherBSplinePolygon::CmdSketcherBSplinePolygon() + : Command("Sketcher_BSplinePolygon") +{ + sAppModule = "Sketcher"; + sGroup = "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; + sPixmap = "Sketcher_BSplinePolygon"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplinePolygon::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("BSplineControlPolygonVisible"); +} + +bool CmdSketcherBSplinePolygon::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// Show/Hide B-spline comb +DEF_STD_CMD_A(CmdSketcherBSplineComb) + +CmdSketcherBSplineComb::CmdSketcherBSplineComb() + : Command("Sketcher_BSplineComb") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide B-spline curvature comb"); + sToolTipText = + QT_TR_NOOP("Switches between showing and hiding the curvature comb for all B-splines"); + sWhatsThis = "Sketcher_BSplineComb"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_BSplineComb"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplineComb::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("BSplineCombVisible"); +} + +bool CmdSketcherBSplineComb::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// +DEF_STD_CMD_A(CmdSketcherBSplineKnotMultiplicity) + +CmdSketcherBSplineKnotMultiplicity::CmdSketcherBSplineKnotMultiplicity() + : Command("Sketcher_BSplineKnotMultiplicity") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide B-spline knot multiplicity"); + sToolTipText = + QT_TR_NOOP("Switches between showing and hiding the knot multiplicity for all B-splines"); + sWhatsThis = "Sketcher_BSplineKnotMultiplicity"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_BSplineKnotMultiplicity"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplineKnotMultiplicity::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("BSplineKnotMultiplicityVisible"); +} + +bool CmdSketcherBSplineKnotMultiplicity::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// +DEF_STD_CMD_A(CmdSketcherBSplinePoleWeight) + +CmdSketcherBSplinePoleWeight::CmdSketcherBSplinePoleWeight() + : Command("Sketcher_BSplinePoleWeight") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide B-spline control point weight"); + sToolTipText = QT_TR_NOOP( + "Switches between showing and hiding the control point weight for all B-splines"); + sWhatsThis = "Sketcher_BSplinePoleWeight"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_BSplinePoleWeight"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherBSplinePoleWeight::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("BSplinePoleWeightVisible"); +} + +bool CmdSketcherBSplinePoleWeight::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// Composite drop down menu for show/hide BSpline information layer +DEF_STD_CMD_ACLU(CmdSketcherCompBSplineShowHideGeometryInformation) + +CmdSketcherCompBSplineShowHideGeometryInformation:: + CmdSketcherCompBSplineShowHideGeometryInformation() + : Command("Sketcher_CompBSplineShowHideGeometryInformation") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide B-spline information layer"); + sToolTipText = sMenuText; + sWhatsThis = "Sketcher_CompBSplineShowHideGeometryInformation"; + sStatusTip = sToolTipText; + eType = ForEdit; +} + +void CmdSketcherCompBSplineShowHideGeometryInformation::activated(int iMsg) +{ + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); + Gui::Command* cmd; + + if (iMsg == 0) + cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineDegree"); + else if (iMsg == 1) + cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePolygon"); + else if (iMsg == 2) + cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineComb"); + else if (iMsg == 3) + cmd = rcCmdMgr.getCommandByName("Sketcher_BSplineKnotMultiplicity"); + else if (iMsg == 4) + cmd = rcCmdMgr.getCommandByName("Sketcher_BSplinePoleWeight"); + else + return; + + cmd->invoke(0); + + // Since the default icon is reset when enabling/disabling the command we have + // to explicitly set the icon of the used command. + Gui::ActionGroup* pcAction = qobject_cast(_pcAction); + QList a = pcAction->actions(); + + assert(iMsg < a.size()); + pcAction->setIcon(a[iMsg]->icon()); + // we must also set the tooltip of the used command + pcAction->setToolTip(a[iMsg]->toolTip()); +} + +Gui::Action* CmdSketcherCompBSplineShowHideGeometryInformation::createAction() +{ + Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); + pcAction->setDropDownMenu(true); + applyCommandData(this->className(), pcAction); + + QAction* c1 = pcAction->addAction(QString()); + c1->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineDegree")); + QAction* c2 = pcAction->addAction(QString()); + c2->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplinePolygon")); + QAction* c3 = pcAction->addAction(QString()); + c3->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineComb")); + QAction* c4 = pcAction->addAction(QString()); + c4->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineKnotMultiplicity")); + QAction* c5 = pcAction->addAction(QString()); + c5->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplinePoleWeight")); + + _pcAction = pcAction; + languageChange(); + + pcAction->setIcon(c2->icon()); + int defaultId = 1; + pcAction->setProperty("defaultAction", QVariant(defaultId)); + + return pcAction; +} + +void CmdSketcherCompBSplineShowHideGeometryInformation::languageChange() +{ + Command::languageChange(); + + if (!_pcAction) + return; + Gui::ActionGroup* pcAction = qobject_cast(_pcAction); + QList a = pcAction->actions(); + + QAction* c1 = a[0]; + c1->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", + "Show/hide B-spline degree")); + c1->setToolTip(QApplication::translate( + "Sketcher_BSplineDegree", + "Switches between showing and hiding the degree for all B-splines")); + c1->setStatusTip(QApplication::translate( + "Sketcher_BSplineDegree", + "Switches between showing and hiding the degree for all B-splines")); + QAction* c2 = a[1]; + c2->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", + "Show/hide B-spline control polygon")); + c2->setToolTip(QApplication::translate( + "Sketcher_BSplinePolygon", + "Switches between showing and hiding the control polygons for all B-splines")); + c2->setStatusTip(QApplication::translate( + "Sketcher_BSplinePolygon", + "Switches between showing and hiding the control polygons for all B-splines")); + QAction* c3 = a[2]; + c3->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", + "Show/hide B-spline curvature comb")); + c3->setToolTip(QApplication::translate( + "Sketcher_BSplineComb", + "Switches between showing and hiding the curvature comb for all B-splines")); + c3->setStatusTip(QApplication::translate( + "Sketcher_BSplineComb", + "Switches between showing and hiding the curvature comb for all B-splines")); + QAction* c4 = a[3]; + c4->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", + "Show/hide B-spline knot multiplicity")); + c4->setToolTip(QApplication::translate( + "Sketcher_BSplineKnotMultiplicity", + "Switches between showing and hiding the knot multiplicity for all B-splines")); + c4->setStatusTip(QApplication::translate( + "Sketcher_BSplineKnotMultiplicity", + "Switches between showing and hiding the knot multiplicity for all B-splines")); + + QAction* c5 = a[4]; + c5->setText(QApplication::translate("CmdSketcherCompBSplineShowHideGeometryInformation", + "Show/hide B-spline control point weight")); + c5->setToolTip(QApplication::translate( + "Sketcher_BSplinePoleWeight", + "Switches between showing and hiding the control point weight for all B-splines")); + c5->setStatusTip(QApplication::translate( + "Sketcher_BSplinePoleWeight", + "Switches between showing and hiding the control point weight for all B-splines")); +} + +void CmdSketcherCompBSplineShowHideGeometryInformation::updateAction(int /*mode*/) +{} + +bool CmdSketcherCompBSplineShowHideGeometryInformation::isActive() +{ + return isSketcherBSplineActive(getActiveGuiDocument(), false); +} + +// +DEF_STD_CMD_A(CmdSketcherArcOverlay) + +CmdSketcherArcOverlay::CmdSketcherArcOverlay() + : Command("Sketcher_ArcOverlay") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Show/hide circular helper for arcs"); + sToolTipText = + QT_TR_NOOP("Switches between showing and hiding the circular helper for all arcs"); + sWhatsThis = "Sketcher_ArcOverlay"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_ArcOverlay"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherArcOverlay::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + ShowRestoreInformationLayer("ArcCircleHelperVisible"); +} + +bool CmdSketcherArcOverlay::isActive() +{ + return isSketchInEdit(getActiveGuiDocument()); +} + +void CreateSketcherCommandsOverlay() +{ + Gui::CommandManager& rcCmdMgr = Gui::Application::Instance->commandManager(); + + rcCmdMgr.addCommand(new CmdSketcherBSplineDegree()); + rcCmdMgr.addCommand(new CmdSketcherBSplinePolygon()); + rcCmdMgr.addCommand(new CmdSketcherBSplineComb()); + rcCmdMgr.addCommand(new CmdSketcherBSplineKnotMultiplicity()); + rcCmdMgr.addCommand(new CmdSketcherBSplinePoleWeight()); + rcCmdMgr.addCommand(new CmdSketcherCompBSplineShowHideGeometryInformation()); + rcCmdMgr.addCommand(new CmdSketcherArcOverlay()); +} diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index 17b48b0281..ebab5ccd39 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -414,6 +414,26 @@ bool SketcherGui::isCommandActive(Gui::Document* doc, bool actsOnSelection) return false; } +bool SketcherGui::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; +} + SketcherGui::ViewProviderSketch* SketcherGui::getInactiveHandlerEditModeSketchViewProvider(Gui::Document* doc) { diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index fecf4e1c3e..1ce611e270 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -145,6 +145,8 @@ bool isSketchInEdit(Gui::Document* doc); /// sketcher is no special state or a sketchHandler is active. bool isCommandActive(Gui::Document* doc, bool actsOnSelection = false); +bool isSketcherBSplineActive(Gui::Document* doc, bool actsOnSelection); + SketcherGui::ViewProviderSketch* getInactiveHandlerEditModeSketchViewProvider(Gui::Document* doc); SketcherGui::ViewProviderSketch* getInactiveHandlerEditModeSketchViewProvider(); @@ -162,6 +164,7 @@ bool showCursorCoords(); bool useSystemDecimals(); std::string lengthToDisplayFormat(double value, int digits); std::string angleToDisplayFormat(double value, int digits); + }// namespace SketcherGui /// converts a 2D vector into a 3D vector in the XY plane diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 2751b3410a..09dbdddf9f 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -517,8 +517,7 @@ inline void SketcherAddWorkbenchBSplines(Gui::MenuItem& bspline) template<> inline void SketcherAddWorkbenchBSplines(Gui::ToolBarItem& bspline) { - bspline << "Sketcher_CompBSplineShowHideGeometryInformation" - << "Sketcher_BSplineConvertToNURBS" + bspline << "Sketcher_BSplineConvertToNURBS" << "Sketcher_BSplineIncreaseDegree" << "Sketcher_BSplineDecreaseDegree" << "Sketcher_CompModifyKnotMultiplicity" @@ -532,13 +531,17 @@ inline void SketcherAddWorkbenchVirtualSpace(T& virtualspace); template<> inline void SketcherAddWorkbenchVirtualSpace(Gui::MenuItem& virtualspace) { - virtualspace << "Sketcher_SwitchVirtualSpace"; + virtualspace << "Sketcher_SwitchVirtualSpace" + << "Sketcher_CompBSplineShowHideGeometryInformation" + << "Sketcher_ArcOverlay"; } template<> inline void SketcherAddWorkbenchVirtualSpace(Gui::ToolBarItem& virtualspace) { - virtualspace << "Sketcher_SwitchVirtualSpace"; + virtualspace << "Sketcher_SwitchVirtualSpace" + << "Sketcher_CompBSplineShowHideGeometryInformation" + << "Sketcher_ArcOverlay"; } template