From 35b9dea4b2ab3950f993f44f5bcb23cb159742d3 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 13 Feb 2016 23:39:47 +0200 Subject: [PATCH] Fixes creating spline path. --HG-- branch : feature --- src/libs/vgeometry/vsplinepoint.cpp | 4 +- .../vtools/dialogs/tools/dialogspline.cpp | 3 +- .../vtools/dialogs/tools/dialogsplinepath.cpp | 5 +- .../visualization/vistoolsplinepath.cpp | 79 ++++++++++++------- .../vtools/visualization/vistoolsplinepath.h | 1 - 5 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/libs/vgeometry/vsplinepoint.cpp b/src/libs/vgeometry/vsplinepoint.cpp index 0168b0312..3f89f2805 100644 --- a/src/libs/vgeometry/vsplinepoint.cpp +++ b/src/libs/vgeometry/vsplinepoint.cpp @@ -87,7 +87,7 @@ void VSplinePoint::SetAngle1(const qreal &value) line.setAngle(value); d->angle1 = line.angle(); - line.setAngle(value+180); + line.setAngle(d->angle1+180); d->angle2 = line.angle(); } @@ -102,7 +102,7 @@ void VSplinePoint::SetAngle2(const qreal &value) line.setAngle(value); d->angle2 = line.angle(); - line.setAngle(value-180); + line.setAngle(d->angle2+180); d->angle1 = line.angle(); } diff --git a/src/libs/vtools/dialogs/tools/dialogspline.cpp b/src/libs/vtools/dialogs/tools/dialogspline.cpp index ed6913d19..cf91e8bf0 100644 --- a/src/libs/vtools/dialogs/tools/dialogspline.cpp +++ b/src/libs/vtools/dialogs/tools/dialogspline.cpp @@ -139,7 +139,7 @@ void DialogSpline::SaveData() kAsm2 = ui->doubleSpinBoxKasm2->value(); kCurve = ui->doubleSpinBoxKcurve->value(); - VisToolSpline *path = qobject_cast(vis); + auto path = qobject_cast(vis); SCASSERT(path != nullptr); path->setObject1Id(GetP1()); @@ -149,6 +149,7 @@ void DialogSpline::SaveData() path->SetKAsm1(kAsm1); path->SetKAsm2(kAsm2); path->SetKCurve(kCurve); + path->SetMode(Mode::Show); path->RefreshGeometry(); } diff --git a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp index f53504de0..dde11226a 100644 --- a/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp +++ b/src/libs/vtools/dialogs/tools/dialogsplinepath.cpp @@ -95,7 +95,7 @@ void DialogSplinePath::SetPath(const VSplinePath &value) ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.GetKCurve()); - VisToolSplinePath *visPath = qobject_cast(vis); + auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); visPath->setPath(path); ui->listWidget->blockSignals(false); @@ -155,9 +155,10 @@ void DialogSplinePath::SaveData() { SavePath(); - VisToolSplinePath *visPath = qobject_cast(vis); + auto visPath = qobject_cast(vis); SCASSERT(visPath != nullptr); visPath->setPath(path); + visPath->SetMode(Mode::Show); visPath->RefreshGeometry(); } diff --git a/src/libs/vtools/visualization/vistoolsplinepath.cpp b/src/libs/vtools/visualization/vistoolsplinepath.cpp index 3618257d9..c1b388ecb 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.cpp +++ b/src/libs/vtools/visualization/vistoolsplinepath.cpp @@ -66,6 +66,22 @@ void VisToolSplinePath::RefreshGeometry() if (mode == Mode::Creation) { + if (size > 1) + { + for (qint32 i = 1; i<=path.Count(); ++i) + { + const int preLastPoint = (path.Count() - 1) * 2; + const int lastPoint = preLastPoint + 1; + + VSpline spl = path.GetSpline(i); + + ctrlPoints[preLastPoint]->RefreshCtrlPoint(i, SplinePointPosition::FirstPoint, spl.GetP2(), + spl.GetP1().toQPointF()); + ctrlPoints[lastPoint]->RefreshCtrlPoint(i, SplinePointPosition::LastPoint, spl.GetP3(), + spl.GetP4().toQPointF()); + } + } + Creating(pathPoints.at(size-1).P().toQPointF(), size); } @@ -160,29 +176,6 @@ QGraphicsEllipseItem *VisToolSplinePath::getPoint(quint32 i) return nullptr; } -//--------------------------------------------------------------------------------------------------------------------- -QSharedPointer VisToolSplinePath::NewCurveSegmen(const QPointF &pSpl, int size) -{ - auto spline = QSharedPointer(new VSpline(VPointF(pSpl), ctrlPoint, Visualization::scenePos, - VPointF(Visualization::scenePos), path.GetKCurve())); - - if (size == 1) - { - path[size-1].SetAngle2(spline->GetStartAngle()); - path[size-1].SetKAsm2(spline->GetKasm1()); - emit PathChanged(path); - } - else - { - path[size-1].SetAngle2(spline->GetStartAngle()); - path[size-1].SetKAsm1(spline->GetKasm1()); - path[size-1].SetKAsm2(spline->GetKasm1()); - emit PathChanged(path); - } - - return spline; -} - //--------------------------------------------------------------------------------------------------------------------- void VisToolSplinePath::Creating(const QPointF &pSpl, int size) { @@ -224,15 +217,15 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) } } + QLineF ctrlLine (pSpl, Visualization::scenePos); + ctrlLine.setAngle(ctrlLine.angle()+180); + if (size == 1) { ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); } else { - QLineF ctrlLine (pSpl, Visualization::scenePos); - ctrlLine.setAngle(ctrlLine.angle()+180); - ctrlPoints[preLastPoint]->RefreshCtrlPoint(size-1, SplinePointPosition::LastPoint, ctrlLine.p2(), pSpl); ctrlPoints[lastPoint]->RefreshCtrlPoint(size, SplinePointPosition::FirstPoint, ctrlPoint, pSpl); } @@ -243,14 +236,32 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) if (size == 1) { path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm2(spline.GetKasm1()); + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm2(0); + } emit PathChanged(path); } else { + const VSpline spl = path.GetSpline(size - 1); + VSpline preSpl(spl.GetP1(), spl.GetP2(), ctrlLine.p2(), VPointF(pSpl), path.GetKCurve()); + path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm1(spline.GetKasm1()); - path[size-1].SetKAsm2(spline.GetKasm1()); + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm1(preSpl.GetKasm2()); + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm1(0); + path[size-1].SetKAsm2(0); + } emit PathChanged(path); } } @@ -262,7 +273,15 @@ void VisToolSplinePath::Creating(const QPointF &pSpl, int size) VPointF(Visualization::scenePos), path.GetKCurve()); path[size-1].SetAngle2(spline.GetStartAngle()); - path[size-1].SetKAsm2(spline.GetKasm1()); + + if (ctrlPoint != pSpl) + { + path[size-1].SetKAsm2(spline.GetKasm1()); + } + else + { + path[size-1].SetKAsm2(0); + } emit PathChanged(path); DrawPath(newCurveSegment, spline.GetPath(PathDirection::Hide), mainColor, Qt::SolidLine, Qt::RoundCap); diff --git a/src/libs/vtools/visualization/vistoolsplinepath.h b/src/libs/vtools/visualization/vistoolsplinepath.h index 309f57127..cbddfef70 100644 --- a/src/libs/vtools/visualization/vistoolsplinepath.h +++ b/src/libs/vtools/visualization/vistoolsplinepath.h @@ -69,7 +69,6 @@ protected: QPointF ctrlPoint; QGraphicsEllipseItem * getPoint(quint32 i); - QSharedPointer NewCurveSegmen(const QPointF &pSpl, int size); void Creating(const QPointF &pSpl, int size); };