2013-11-15 13:41:26 +01:00
|
|
|
/************************************************************************
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:50:05 +01:00
|
|
|
** @file vsplinepath.cpp
|
2014-04-30 07:38:52 +02:00
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
2013-11-15 13:50:05 +01:00
|
|
|
** @date November 15, 2013
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2013-11-15 13:41:26 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2013-09-18 21:16:19 +02:00
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
2013-09-18 21:16:19 +02:00
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
2013-10-27 13:36:29 +01:00
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
2013-09-18 21:16:19 +02:00
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
2013-11-15 13:41:26 +01:00
|
|
|
*************************************************************************/
|
2013-09-18 21:16:19 +02:00
|
|
|
|
2013-08-09 08:49:34 +02:00
|
|
|
#include "vsplinepath.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QJsonObject>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QPoint>
|
|
|
|
|
2015-05-07 14:31:53 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vabstractcurve.h"
|
|
|
|
#include "vsplinepath_p.h"
|
2013-08-09 08:49:34 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief VSplinePath constructor.
|
|
|
|
* @param idObject parent id.
|
|
|
|
* @param mode mode creation spline path.
|
|
|
|
*/
|
|
|
|
VSplinePath::VSplinePath(quint32 idObject, Draw mode)
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
|
|
|
d(new VSplinePathData())
|
|
|
|
{
|
|
|
|
}
|
2013-08-20 12:26:02 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
VSplinePath::VSplinePath(const QVector<VFSplinePoint> &points, qreal kCurve, quint32 idObject, Draw mode)
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
|
|
|
d(new VSplinePathData())
|
2016-03-04 17:08:29 +01:00
|
|
|
{
|
|
|
|
if (points.size() < 3)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-10 17:03:15 +02:00
|
|
|
QVector<VSplinePoint> newPoints(points.size());
|
2023-07-15 09:58:28 +02:00
|
|
|
for (qint32 i = 1; i <= points.size() - 1; ++i)
|
2016-03-04 17:08:29 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
const VFSplinePoint &p1 = points.at(i - 1);
|
2016-03-04 17:08:29 +01:00
|
|
|
const VFSplinePoint &p2 = points.at(i);
|
|
|
|
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p2.Angle1(), p1.KAsm2(), p2.KAsm1(), kCurve);
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
newPoints[i - 1].SetP(p1.P());
|
|
|
|
newPoints[i - 1].SetAngle2(p1.Angle2(), spl.GetStartAngleFormula());
|
|
|
|
newPoints[i - 1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
newPoints[i].SetP(p2.P());
|
2016-03-05 14:37:47 +01:00
|
|
|
newPoints[i].SetAngle1(p2.Angle1(), spl.GetEndAngleFormula());
|
2016-03-04 17:08:29 +01:00
|
|
|
newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
|
|
|
|
d->path = newPoints;
|
|
|
|
CreateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VSplinePath::VSplinePath(const QVector<VSplinePoint> &points, quint32 idObject, Draw mode)
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractCubicBezierPath(GOType::SplinePath, idObject, mode),
|
|
|
|
d(new VSplinePathData())
|
2016-03-04 17:08:29 +01:00
|
|
|
{
|
|
|
|
if (points.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->path = points;
|
|
|
|
CreateName();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
COPY_CONSTRUCTOR_IMPL_2(VSplinePath, VAbstractCubicBezierPath)
|
2014-08-20 16:05:19 +02:00
|
|
|
|
2016-04-10 17:03:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::Rotate(const QPointF &originPoint, qreal degrees, const QString &prefix) const -> VSplinePath
|
2016-04-10 17:03:15 +02:00
|
|
|
{
|
|
|
|
QVector<VSplinePoint> newPoints(CountPoints());
|
|
|
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
|
|
|
{
|
2016-09-09 14:18:59 +02:00
|
|
|
const VSpline spl = GetSpline(i).Rotate(originPoint, degrees);
|
2016-04-10 17:03:15 +02:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
newPoints[i - 1].SetP(spl.GetP1());
|
|
|
|
newPoints[i - 1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula());
|
|
|
|
newPoints[i - 1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
2016-04-10 17:03:15 +02:00
|
|
|
|
2016-09-10 20:40:30 +02:00
|
|
|
newPoints[i].SetP(spl.GetP4());
|
|
|
|
newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula());
|
|
|
|
newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
|
|
|
|
VSplinePath splPath(newPoints);
|
|
|
|
splPath.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
splPath.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
splPath.SetColor(GetColor());
|
|
|
|
splPath.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
splPath.SetApproximationScale(GetApproximationScale());
|
2016-09-10 20:40:30 +02:00
|
|
|
return splPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::Flip(const QLineF &axis, const QString &prefix) const -> VSplinePath
|
2016-09-10 20:40:30 +02:00
|
|
|
{
|
|
|
|
QVector<VSplinePoint> newPoints(CountPoints());
|
|
|
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spl = GetSpline(i).Flip(axis);
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
newPoints[i - 1].SetP(spl.GetP1());
|
|
|
|
newPoints[i - 1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula());
|
|
|
|
newPoints[i - 1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
2016-09-10 20:40:30 +02:00
|
|
|
|
2016-09-09 14:18:59 +02:00
|
|
|
newPoints[i].SetP(spl.GetP4());
|
|
|
|
newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula());
|
2016-04-10 17:03:15 +02:00
|
|
|
newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
|
|
|
|
VSplinePath splPath(newPoints);
|
|
|
|
splPath.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
splPath.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
splPath.SetColor(GetColor());
|
|
|
|
splPath.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
splPath.SetApproximationScale(GetApproximationScale());
|
2016-04-10 17:03:15 +02:00
|
|
|
return splPath;
|
|
|
|
}
|
|
|
|
|
2016-10-04 16:34:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::Move(qreal length, qreal angle, const QString &prefix) const -> VSplinePath
|
2016-10-04 16:34:37 +02:00
|
|
|
{
|
|
|
|
QVector<VSplinePoint> newPoints(CountPoints());
|
|
|
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
|
|
|
{
|
|
|
|
const VSpline spl = GetSpline(i).Move(length, angle);
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
newPoints[i - 1].SetP(spl.GetP1());
|
|
|
|
newPoints[i - 1].SetAngle2(spl.GetStartAngle(), spl.GetStartAngleFormula());
|
|
|
|
newPoints[i - 1].SetLength2(spl.GetC1Length(), spl.GetC1LengthFormula());
|
2016-10-04 16:34:37 +02:00
|
|
|
|
|
|
|
newPoints[i].SetP(spl.GetP4());
|
|
|
|
newPoints[i].SetAngle1(spl.GetEndAngle(), spl.GetEndAngleFormula());
|
|
|
|
newPoints[i].SetLength1(spl.GetC2Length(), spl.GetC2LengthFormula());
|
|
|
|
}
|
|
|
|
|
|
|
|
VSplinePath splPath(newPoints);
|
|
|
|
splPath.setName(name() + prefix);
|
2020-11-07 14:02:30 +01:00
|
|
|
|
|
|
|
if (not GetAliasSuffix().isEmpty())
|
|
|
|
{
|
|
|
|
splPath.SetAliasSuffix(GetAliasSuffix() + prefix);
|
|
|
|
}
|
|
|
|
|
2017-05-16 12:07:53 +02:00
|
|
|
splPath.SetColor(GetColor());
|
|
|
|
splPath.SetPenStyle(GetPenStyle());
|
2017-10-11 12:51:06 +02:00
|
|
|
splPath.SetApproximationScale(GetApproximationScale());
|
2016-10-04 16:34:37 +02:00
|
|
|
return splPath;
|
|
|
|
}
|
|
|
|
|
2014-08-20 16:05:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
VSplinePath::~VSplinePath() = default;
|
2013-08-28 10:55:11 +02:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief append add point in the end of list points.
|
|
|
|
* @param point new point.
|
|
|
|
*/
|
2013-11-07 15:40:39 +01:00
|
|
|
void VSplinePath::append(const VSplinePoint &point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-20 16:05:19 +02:00
|
|
|
d->path.append(point);
|
2016-02-15 15:30:48 +01:00
|
|
|
CreateName();
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
2016-03-16 19:07:50 +01:00
|
|
|
* @brief CountSubSpl return count of simple splines.
|
2016-03-04 17:08:29 +01:00
|
|
|
* @return count.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::CountSubSpl() const -> vsizetype
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-19 15:20:09 +01:00
|
|
|
if (d->path.isEmpty())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-08-09 08:49:34 +02:00
|
|
|
return 0;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
2022-03-16 16:43:22 +01:00
|
|
|
|
|
|
|
return d->path.size() - 1;
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief GetSpline return spline by index.
|
|
|
|
* @param index index spline in spline path.
|
|
|
|
* @return spline
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetSpline(vsizetype index) const -> VSpline
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
if (CountPoints() < 1)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-09-30 18:29:03 +02:00
|
|
|
throw VException(tr("Not enough points to create the spline."));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2016-03-16 19:07:50 +01:00
|
|
|
|
|
|
|
if (index < 1 || index > CountSubSpl())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-19 15:30:11 +01:00
|
|
|
throw VException(tr("This spline does not exist."));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2016-03-16 19:07:50 +01:00
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
const VSplinePoint &p1 = d->path.at(index - 1);
|
2016-02-15 15:30:48 +01:00
|
|
|
const VSplinePoint &p2 = d->path.at(index);
|
2016-03-04 17:08:29 +01:00
|
|
|
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
|
|
|
p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1);
|
2017-10-11 12:51:06 +02:00
|
|
|
spl.SetApproximationScale(GetApproximationScale());
|
2013-08-09 08:49:34 +02:00
|
|
|
return spl;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief UpdatePoint update spline point in list.
|
|
|
|
* @param indexSpline spline index in list.
|
|
|
|
* @param pos position point in spline.
|
|
|
|
* @param point point.
|
|
|
|
*/
|
2014-06-12 09:22:29 +02:00
|
|
|
void VSplinePath::UpdatePoint(qint32 indexSpline, const SplinePointPosition &pos, const VSplinePoint &point)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-16 19:07:50 +01:00
|
|
|
if (indexSpline < 1 || indexSpline > CountSubSpl())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-19 15:30:11 +01:00
|
|
|
throw VException(tr("This spline does not exist."));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
if (pos == SplinePointPosition::FirstPoint)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
d->path[indexSpline - 1] = point;
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-20 16:05:19 +02:00
|
|
|
d->path[indexSpline] = point;
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief GetSplinePoint return spline point from list.
|
|
|
|
* @param indexSpline spline index in list.
|
|
|
|
* @param pos position point in spline.
|
|
|
|
* @return spline point.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetSplinePoint(qint32 indexSpline, SplinePointPosition pos) const -> VSplinePoint
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2016-03-16 19:07:50 +01:00
|
|
|
if (indexSpline < 1 || indexSpline > CountSubSpl())
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2013-12-19 15:30:11 +01:00
|
|
|
throw VException(tr("This spline does not exist."));
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2014-06-12 09:22:29 +02:00
|
|
|
if (pos == SplinePointPosition::FirstPoint)
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
return d->path.at(indexSpline - 1);
|
2013-11-04 21:35:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-20 16:05:19 +02:00
|
|
|
return d->path.at(indexSpline);
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief operator = assignment operator.
|
|
|
|
* @param path spline path.
|
|
|
|
* @return spline path.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::operator=(const VSplinePath &path) -> VSplinePath &
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
if (&path == this)
|
2014-07-27 14:30:28 +02:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2018-03-23 14:40:36 +01:00
|
|
|
VAbstractCubicBezierPath::operator=(path);
|
2014-08-20 16:05:19 +02:00
|
|
|
d = path.d;
|
2013-08-09 08:49:34 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-13 16:49:20 +02:00
|
|
|
VSplinePath::VSplinePath(VSplinePath &&splPath) noexcept
|
2023-07-15 09:58:28 +02:00
|
|
|
: VAbstractCubicBezierPath(std::move(splPath)),
|
|
|
|
d(std::move(splPath.d))
|
|
|
|
{
|
|
|
|
}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-07-15 09:58:28 +02:00
|
|
|
auto VSplinePath::operator=(VSplinePath &&path) noexcept -> VSplinePath &
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VAbstractCubicBezierPath::operator=(path);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, path.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief operator [] return spline point by index.
|
|
|
|
* @param indx index in list.
|
|
|
|
* @return spline point.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::operator[](vsizetype indx) -> VSplinePoint &
|
2013-11-04 21:35:15 +01:00
|
|
|
{
|
2014-08-20 16:05:19 +02:00
|
|
|
return d->path[indx];
|
2013-08-09 08:49:34 +02:00
|
|
|
}
|
2013-12-18 12:13:32 +01:00
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief at return spline point by index.
|
|
|
|
* @param indx index in list.
|
|
|
|
* @return spline point.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::at(vsizetype indx) const -> const VSplinePoint &
|
2013-12-29 17:48:57 +01:00
|
|
|
{
|
2014-08-20 16:05:19 +02:00
|
|
|
return d->path[indx];
|
2013-12-29 17:48:57 +01:00
|
|
|
}
|
|
|
|
|
2019-08-29 14:01:27 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::ToJson() const -> QJsonObject
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
QJsonObject object = VAbstractCubicBezierPath::ToJson();
|
|
|
|
object[QLatin1String("aScale")] = GetApproximationScale();
|
|
|
|
|
|
|
|
QJsonArray nodesArray;
|
2023-05-03 13:07:02 +02:00
|
|
|
for (const auto &node : d->path)
|
2019-08-29 14:01:27 +02:00
|
|
|
{
|
|
|
|
nodesArray.append(node.ToJson());
|
|
|
|
}
|
|
|
|
object[QLatin1String("nodes")] = nodesArray;
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2014-05-02 13:11:30 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetStartAngle() const -> qreal
|
2013-12-18 12:13:32 +01:00
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
return CountPoints() > 0 ? GetSplinePath().constFirst().Angle2() : 0;
|
2015-02-12 16:42:44 +01:00
|
|
|
}
|
|
|
|
|
2015-06-02 15:53:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetEndAngle() const -> qreal
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2016-03-16 19:07:50 +01:00
|
|
|
if (CountPoints() > 0)
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
return GetSplinePath().constLast().Angle1();
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
2023-08-12 11:03:28 +02:00
|
|
|
|
|
|
|
return 0;
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
|
|
|
|
2016-09-24 19:44:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetC1Length() const -> qreal
|
2016-09-24 19:44:06 +02:00
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
return CountPoints() > 0 ? GetSplinePath().constFirst().Length2() : 0;
|
2016-09-24 19:44:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetC2Length() const -> qreal
|
2016-09-24 19:44:06 +02:00
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
return CountPoints() > 0 ? GetSplinePath().constFirst().Length1() : 0;
|
2016-09-24 19:44:06 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 15:53:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::FirstPoint() const -> VPointF
|
2015-06-02 15:53:19 +02:00
|
|
|
{
|
2023-08-12 11:03:28 +02:00
|
|
|
return not d->path.isEmpty() ? d->path.constFirst().P() : VPointF();
|
2015-06-02 15:53:19 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 15:30:48 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::LastPoint() const -> VPointF
|
2016-02-15 15:30:48 +01:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
const vsizetype count = CountSubSpl();
|
2023-07-15 09:58:28 +02:00
|
|
|
return count >= 1 ? d->path.at(count).P() : // Take last point of the last real spline
|
|
|
|
VPointF();
|
2016-02-15 15:30:48 +01:00
|
|
|
}
|
|
|
|
|
2014-08-20 16:05:19 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
2016-03-16 19:07:50 +01:00
|
|
|
* @brief CountPoints return count of points.
|
2016-03-04 17:08:29 +01:00
|
|
|
* @return count.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::CountPoints() const -> vsizetype
|
2014-08-20 16:05:19 +02:00
|
|
|
{
|
|
|
|
return d->path.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief GetSplinePath return list with spline points.
|
|
|
|
* @return list.
|
|
|
|
*/
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetSplinePath() const -> QVector<VSplinePoint>
|
2014-08-20 16:05:19 +02:00
|
|
|
{
|
|
|
|
return d->path;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-05-03 13:07:02 +02:00
|
|
|
auto VSplinePath::GetFSplinePath() const -> QVector<VFSplinePoint>
|
2014-08-20 16:05:19 +02:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
QVector<VFSplinePoint> points;
|
|
|
|
points.reserve(d->path.size());
|
2014-08-20 16:05:19 +02:00
|
|
|
|
2016-03-16 19:07:50 +01:00
|
|
|
for (qint32 i = 1; i <= CountSubSpl(); ++i)
|
2014-09-03 13:10:51 +02:00
|
|
|
{
|
2023-07-15 09:58:28 +02:00
|
|
|
const VSplinePoint &p1 = d->path.at(i - 1);
|
2016-03-04 17:08:29 +01:00
|
|
|
const VSplinePoint &p2 = d->path.at(i);
|
|
|
|
VSpline spl(p1.P(), p2.P(), p1.Angle2(), p1.Angle2Formula(), p2.Angle1(), p2.Angle1Formula(), p1.Length2(),
|
|
|
|
p1.Length2Formula(), p2.Length1(), p2.Length1Formula(), 1);
|
|
|
|
|
2023-07-15 09:58:28 +02:00
|
|
|
points[i - 1].SetP(p1.P());
|
|
|
|
points[i - 1].SetAngle2(p1.Angle2());
|
|
|
|
points[i - 1].SetKAsm2(spl.GetKasm1());
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
points[i].SetP(p2.P());
|
|
|
|
points[i].SetAngle1(p2.Angle1());
|
|
|
|
points[i].SetKAsm1(spl.GetKasm2());
|
2014-09-03 13:10:51 +02:00
|
|
|
}
|
2016-03-04 17:08:29 +01:00
|
|
|
|
|
|
|
return points;
|
2014-08-20 16:05:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-03-04 17:08:29 +01:00
|
|
|
/**
|
|
|
|
* @brief Clear clear list of points.
|
|
|
|
*/
|
|
|
|
void VSplinePath::Clear()
|
2014-08-20 16:05:19 +02:00
|
|
|
{
|
2016-03-04 17:08:29 +01:00
|
|
|
d->path.clear();
|
|
|
|
SetDuplicate(0);
|
2014-01-08 21:23:08 +01:00
|
|
|
}
|