[Sketcher] Fix and support periodic B-spline by interpolation

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".
This commit is contained in:
Ajinkya Dahale
2023-03-10 01:21:00 +05:30
committed by abdullahtahiriyo
parent 68d67ecb87
commit 8803404d88
3 changed files with 53 additions and 46 deletions

View File

@@ -951,35 +951,35 @@ bool CmdSketcherCreateBSplineByInterpolation::isActive()
return isCommandActive(getActiveGuiDocument());
}
// /// @brief Macro that declares a new sketcher command class 'CmdSketcherCreatePeriodicBSplineByInterpolation'
// DEF_STD_CMD_AU(CmdSketcherCreatePeriodicBSplineByInterpolation)
/// @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;
// }
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")
CONSTRUCTION_UPDATE_ACTION(CmdSketcherCreatePeriodicBSplineByInterpolation,"Sketcher_CreatePeriodicBSplineByInterpolation")
// void CmdSketcherCreatePeriodicBSplineByInterpolation::activated(int iMsg)
// {
// Q_UNUSED(iMsg);
// ActivateHandler(getActiveGuiDocument(),new DrawSketchHandlerBSplineByInterpolation(1) );
// }
void CmdSketcherCreatePeriodicBSplineByInterpolation::activated(int iMsg)
{
Q_UNUSED(iMsg);
ActivateHandler(getActiveGuiDocument(),new DrawSketchHandlerBSplineByInterpolation(1) );
}
// bool CmdSketcherCreatePeriodicBSplineByInterpolation::isActive()
// {
// return isCommandActive(getActiveGuiDocument());
// }
bool CmdSketcherCreatePeriodicBSplineByInterpolation::isActive()
{
return isCommandActive(getActiveGuiDocument());
}
/// @brief Macro that declares a new sketcher command class 'CmdSketcherCompCreateBSpline'
@@ -1015,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;
}
@@ -1046,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();
@@ -1073,14 +1073,14 @@ void CmdSketcherCompCreateBSpline::updateAction(int mode)
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"));
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"));
a[3]->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_Create_Periodic_BSplineByInterpolation_Constr"));
getAction()->setIcon(a[index]->icon());
break;
}
@@ -1107,10 +1107,10 @@ void CmdSketcherCompCreateBSpline::languageChange()
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"));
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()
@@ -2011,7 +2011,7 @@ void CreateSketcherCommandsCreateGeo()
rcCmdMgr.addCommand(new CmdSketcherCreateBSpline());
rcCmdMgr.addCommand(new CmdSketcherCreatePeriodicBSpline());
rcCmdMgr.addCommand(new CmdSketcherCreateBSplineByInterpolation());
// rcCmdMgr.addCommand(new CmdSketcherCreatePeriodicBSplineByInterpolation());
rcCmdMgr.addCommand(new CmdSketcherCreatePeriodicBSplineByInterpolation());
rcCmdMgr.addCommand(new CmdSketcherCompCreateBSpline());
rcCmdMgr.addCommand(new CmdSketcherCreateLine());
rcCmdMgr.addCommand(new CmdSketcherCreatePolyline());

View File

@@ -391,26 +391,33 @@ private:
unsigned int myDegree = 3;
BSplineMults.front() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
BSplineMults.back() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
if (ConstrMethod == 0) {
BSplineMults.front() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
BSplineMults.back() = myDegree + 1; // FIXME: This is hardcoded until degree can be changed
}
std::vector<std::stringstream> streams;
for (size_t i = 0; i < BSplineKnots.size(); ++i) {
if (!streams.empty())
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
if (BSplineMults[i] >= myDegree && i != (BSplineKnots.size() - 1)) {
// The first point
streams.emplace_back();
streams.back() << "App.Vector(" << BSplineKnots.front().x << "," << BSplineKnots.front().y << "),";
// Middle points
for (size_t i = 1; i < BSplineKnots.size() - 1; ++i) {
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
if (BSplineMults[i] >= myDegree) {
streams.emplace_back();
streams.back() << "App.Vector(" << BSplineKnots[i].x << "," << BSplineKnots[i].y << "),";
}
}
// The last point
streams.back() << "App.Vector(" << BSplineKnots.back().x << "," << BSplineKnots.back().y << "),";
std::vector<std::string> controlpointses; // Gollum gollum
controlpointses.reserve(streams.size());
for (auto & stream: streams) {
// TODO: Use subset of points between C0 knots.
controlpointses.emplace_back(stream.str());
auto & controlpoints = controlpointses.back();

View File

@@ -212,8 +212,8 @@ inline void SketcherAddWorkspaceArcs<Gui::MenuItem>(Gui::MenuItem& geom)
<< "Sketcher_CreateArcOfParabola"
<< "Sketcher_CreateBSpline"
<< "Sketcher_CreatePeriodicBSpline"
<< "Sketcher_CreateBSplineByInterpolation";
// << "Sketcher_CreatePeriodicBSplineByInterpolation";
<< "Sketcher_CreateBSplineByInterpolation"
<< "Sketcher_CreatePeriodicBSplineByInterpolation";
}
template <>