From bd2f7a09248f58c44f870a11cca3ebb6b27caa7a Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 27 Feb 2017 15:40:59 +0100 Subject: [PATCH] Sketcher: Add toolbar command to increase knot multiplicity --- .../Sketcher/Gui/CommandSketcherBSpline.cpp | 102 +++++++++++++++++- src/Mod/Sketcher/Gui/Workbench.cpp | 6 +- 2 files changed, 105 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index a797d0809b..5407da2409 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -49,7 +49,7 @@ #include #include -#include "ViewProviderSketch.h" +#include "CommandConstraints.h" using namespace std; using namespace SketcherGui; @@ -488,6 +488,105 @@ bool CmdSketcherIncreaseDegree::isActive(void) return isSketcherBSplineActive( getActiveGuiDocument(), true ); } +DEF_STD_CMD_A(CmdSketcherIncreaseKnotMultiplicity); + +CmdSketcherIncreaseKnotMultiplicity::CmdSketcherIncreaseKnotMultiplicity() +:Command("Sketcher_BSplineIncreaseKnotMultiplicity") +{ + sAppModule = "Sketcher"; + sGroup = QT_TR_NOOP("Sketcher"); + sMenuText = QT_TR_NOOP("Increase degree"); + sToolTipText = QT_TR_NOOP("Increases the multiplicity of the selected knot of a B-spline"); + sWhatsThis = "Sketcher_BSplineIncreaseKnotMultiplicity"; + sStatusTip = sToolTipText; + sPixmap = "Sketcher_BSplineIncreaseKnotMultiplicity"; + sAccel = ""; + eType = ForEdit; +} + +void CmdSketcherIncreaseKnotMultiplicity::activated(int iMsg) +{ + Q_UNUSED(iMsg); + + // get the selection + std::vector selection = getSelection().getSelectionEx(); + + // only one sketch with its subelements are allowed to be selected + if (selection.size() != 1) { + return; + } + + // get the needed lists and objects + const std::vector &SubNames = selection[0].getSubNames(); + Sketcher::SketchObject* Obj = static_cast(selection[0].getObject()); + + openCommand("Increase knot multiplicity"); + + bool applied = false; + + for (unsigned int i=0; i &vals = Obj->Constraints.getValues(); + + for (std::vector< Sketcher::Constraint * >::const_iterator it= vals.begin(); it != vals.end(); ++it) { + if((*it)->Type == Sketcher::InternalAlignment && (*it)->First == GeoId && (*it)->AlignmentType == Sketcher::BSplineKnotPoint) + { + try { + Gui::Command::doCommand( + Doc,"App.ActiveDocument.%s.modifyBSplineKnotMultiplicity(%d,%d,%d) ", + selection[0].getFeatName(),(*it)->Second, (*it)->InternalAlignmentIndex + 1, 1); + + Obj->solve(); + + // add internalalignment for new pole + Gui::Command::doCommand(Gui::Command::Doc, + "App.ActiveDocument.%s.exposeInternalGeometry(%d)", + selection[0].getFeatName(), + (*it)->Second); + + applied = true; + } + catch (const Base::Exception& e) { + Base::Console().Error("%s\n", e.what()); + } + + break; // we applied to a knot, because the constraints have changed in the meanwhile, this loop is now invalid, so we exit. + + } + } + + } + } + + if(!applied) { + abortCommand(); + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), + QObject::tr("None of the selected elements is a knot of a bspline or the knot has already reached the maximum multiplicity.")); + } + else { + commitCommand(); + } + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if (autoRecompute) + Gui::Command::updateActive(); + else + Obj->solve(); + +} + +bool CmdSketcherIncreaseKnotMultiplicity::isActive(void) +{ + return isSketcherBSplineActive( getActiveGuiDocument(), true ); +} + void CreateSketcherCommandsBSpline(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -499,4 +598,5 @@ void CreateSketcherCommandsBSpline(void) rcCmdMgr.addCommand(new CmdSketcherCompBSplineShowHideGeometryInformation()); rcCmdMgr.addCommand(new CmdSketcherConvertToNURB()); rcCmdMgr.addCommand(new CmdSketcherIncreaseDegree()); + rcCmdMgr.addCommand(new CmdSketcherIncreaseKnotMultiplicity()); } diff --git a/src/Mod/Sketcher/Gui/Workbench.cpp b/src/Mod/Sketcher/Gui/Workbench.cpp index 25bad44d54..bbac4af9aa 100644 --- a/src/Mod/Sketcher/Gui/Workbench.cpp +++ b/src/Mod/Sketcher/Gui/Workbench.cpp @@ -288,14 +288,16 @@ inline void SketcherAddWorkbenchBSplines(Gui::MenuItem& bspline){ << "Sketcher_BSplineComb" << "Sketcher_BSplineKnotMultiplicity" << "Sketcher_BSplineConvertToNURB" - << "Sketcher_BSplineIncreaseDegree"; + << "Sketcher_BSplineIncreaseDegree" + << "Sketcher_BSplineIncreaseKnotMultiplicity"; } template <> inline void SketcherAddWorkbenchBSplines(Gui::ToolBarItem& bspline){ bspline << "Sketcher_CompBSplineShowHideGeometryInformation" << "Sketcher_BSplineConvertToNURB" - << "Sketcher_BSplineIncreaseDegree"; + << "Sketcher_BSplineIncreaseDegree" + << "Sketcher_BSplineIncreaseKnotMultiplicity"; } template