From ab64e2251d5af740c8756ea2bf8bd7346a16132e Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Wed, 8 Mar 2023 13:46:36 +0530 Subject: [PATCH] [Sketcher] Add missing GUI elements for B-spline by knots Commented out the periodic version for now since they don't work completely well. This commit is part of a project funded by the Open Toolchain Foundation under the title "Open Toolchain Foundation - Curve drawing tool in Sketcher Workbench" --- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 84 +++++++++++++++++++++-- src/Mod/Sketcher/Gui/Workbench.cpp | 4 +- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index 20d9562df3..a1f5a7bb85 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -921,6 +921,66 @@ bool CmdSketcherCreatePeriodicBSpline::isActive() return isCommandActive(getActiveGuiDocument()); } +/// @brief Macro that declares a new sketcher command class 'CmdSketcherCreateBSplineByInterpolation' +DEF_STD_CMD_AU(CmdSketcherCreateBSplineByInterpolation) + +CmdSketcherCreateBSplineByInterpolation::CmdSketcherCreateBSplineByInterpolation() +: Command("Sketcher_CreateBSplineByInterpolation") +{ + sAppModule = "Sketcher"; + sGroup = "Sketcher"; + sMenuText = QT_TR_NOOP("Interpolate B-spline"); + sToolTipText = QT_TR_NOOP("Create a B-spline by interpolation, i.e. via knots in the sketch."); + sWhatsThis = "Sketcher_CreateBSplineByInterpolation"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_CreateBSplineByInterpolation"; + sAccel = "G, B, I"; // TODO: Finalize this. What about Periodic? + eType = ForEdit; +} + +CONSTRUCTION_UPDATE_ACTION(CmdSketcherCreateBSplineByInterpolation,"Sketcher_CreateBSplineByInterpolation") + +void CmdSketcherCreateBSplineByInterpolation::activated(int iMsg) +{ + Q_UNUSED(iMsg); + ActivateHandler(getActiveGuiDocument(),new DrawSketchHandlerBSplineByInterpolation(0) ); +} + +bool CmdSketcherCreateBSplineByInterpolation::isActive() +{ + return isCommandActive(getActiveGuiDocument()); +} + +// /// @brief Macro that declares a new sketcher command class 'CmdSketcherCreatePeriodicBSplineByInterpolation' +// DEF_STD_CMD_AU(CmdSketcherCreatePeriodicBSplineByInterpolation) + +// CmdSketcherCreatePeriodicBSplineByInterpolation::CmdSketcherCreatePeriodicBSplineByInterpolation() +// : Command("Sketcher_CreatePeriodicBSplineByInterpolation") +// { +// sAppModule = "Sketcher"; +// sGroup = "Sketcher"; +// sMenuText = QT_TR_NOOP("Interpolate periodic B-spline"); +// sToolTipText = QT_TR_NOOP("Create a periodic B-spline by interpolation, i.e. via knots in the sketch."); +// sWhatsThis = "Sketcher_Create_Periodic_BSplineByInterpolation"; +// sStatusTip = sToolTipText; +// sPixmap = "Sketcher_Create_Periodic_BSplineByInterpolation"; +// sAccel = "G, B, O"; // TODO: Finalize this. What about Periodic? +// eType = ForEdit; +// } + +// CONSTRUCTION_UPDATE_ACTION(CmdSketcherCreatePeriodicBSplineByInterpolation,"Sketcher_CreatePeriodicBSplineByInterpolation") + +// void CmdSketcherCreatePeriodicBSplineByInterpolation::activated(int iMsg) +// { +// Q_UNUSED(iMsg); +// ActivateHandler(getActiveGuiDocument(),new DrawSketchHandlerBSplineByInterpolation(1) ); +// } + +// bool CmdSketcherCreatePeriodicBSplineByInterpolation::isActive() +// { +// return isCommandActive(getActiveGuiDocument()); +// } + /// @brief Macro that declares a new sketcher command class 'CmdSketcherCompCreateBSpline' DEF_STD_CMD_ACLU(CmdSketcherCompCreateBSpline) @@ -955,9 +1015,9 @@ void CmdSketcherCompCreateBSpline::activated(int iMsg) else if (iMsg == 2) { ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerBSplineByInterpolation(0)); } - else if (iMsg == 3) { - ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerBSplineByInterpolation(1)); - } + // else if (iMsg == 3) { + // ActivateHandler(getActiveGuiDocument(), new DrawSketchHandlerBSplineByInterpolation(1)); + // } else { return; } @@ -986,8 +1046,8 @@ Gui::Action * CmdSketcherCompCreateBSpline::createAction() QAction* bsplinebyknot = pcAction->addAction(QString()); bsplinebyknot->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSplineByInterpolation")); - QAction* periodicbsplinebyknot = pcAction->addAction(QString()); - periodicbsplinebyknot->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSplineByInterpolation")); + // QAction* periodicbsplinebyknot = pcAction->addAction(QString()); + // periodicbsplinebyknot->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSplineByInterpolation")); _pcAction = pcAction; languageChange(); @@ -1012,11 +1072,15 @@ void CmdSketcherCompCreateBSpline::updateAction(int mode) case Normal: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSpline")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSpline")); + a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSplineByInterpolation")); + // a[3]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSplineByInterpolation")); getAction()->setIcon(a[index]->icon()); break; case Construction: a[0]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSpline_Constr")); a[1]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSpline_Constr")); + a[2]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_CreateBSplineByInterpolation_Constr")); + // a[3]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSplineByInterpolation_Constr")); getAction()->setIcon(a[index]->icon()); break; } @@ -1039,6 +1103,14 @@ void CmdSketcherCompCreateBSpline::languageChange() periodicbspline->setText(QApplication::translate("Sketcher_Create_Periodic_BSpline","Periodic B-spline by control points")); periodicbspline->setToolTip(QApplication::translate("Sketcher_Create_Periodic_BSpline","Create a periodic B-spline by control points")); periodicbspline->setStatusTip(QApplication::translate("Sketcher_Create_Periodic_BSpline","Create a periodic B-spline by control points")); + QAction* bsplinebyknot = a[2]; + bsplinebyknot->setText(QApplication::translate("Sketcher_CreateBSplineByInterpolation","B-spline by knots")); + bsplinebyknot->setToolTip(QApplication::translate("Sketcher_CreateBSplineByInterpolation","Create a B-spline by knots")); + bsplinebyknot->setStatusTip(QApplication::translate("Sketcher_CreateBSplineByInterpolation","Create a B-spline by knots")); + // QAction* periodicbsplinebyknot = a[3]; + // periodicbsplinebyknot->setText(QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation","Periodic B-spline by knots")); + // periodicbsplinebyknot->setToolTip(QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation","Create a periodic B-spline by knots")); + // periodicbsplinebyknot->setStatusTip(QApplication::translate("Sketcher_Create_Periodic_BSplineByInterpolation","Create a periodic B-spline by knots")); } bool CmdSketcherCompCreateBSpline::isActive() @@ -1938,6 +2010,8 @@ void CreateSketcherCommandsCreateGeo() rcCmdMgr.addCommand(new CmdSketcherCreateArcOfParabola()); rcCmdMgr.addCommand(new CmdSketcherCreateBSpline()); rcCmdMgr.addCommand(new CmdSketcherCreatePeriodicBSpline()); + rcCmdMgr.addCommand(new CmdSketcherCreateBSplineByInterpolation()); + // rcCmdMgr.addCommand(new CmdSketcherCreatePeriodicBSplineByInterpolation()); rcCmdMgr.addCommand(new CmdSketcherCompCreateBSpline()); rcCmdMgr.addCommand(new CmdSketcherCreateLine()); rcCmdMgr.addCommand(new CmdSketcherCreatePolyline()); diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 9babd176dc..571d7662b0 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -211,7 +211,9 @@ inline void SketcherAddWorkspaceArcs(Gui::MenuItem& geom) << "Sketcher_CreateArcOfHyperbola" << "Sketcher_CreateArcOfParabola" << "Sketcher_CreateBSpline" - << "Sketcher_CreatePeriodicBSpline"; + << "Sketcher_CreatePeriodicBSpline" + << "Sketcher_CreateBSplineByInterpolation"; + // << "Sketcher_CreatePeriodicBSplineByInterpolation"; } template <>