New warning. Error calculating segment of curve.

This commit is contained in:
Roman Telezhynskyi 2020-07-04 15:13:45 +03:00
parent 5f2bec91d9
commit a887fcb3df
4 changed files with 42 additions and 7 deletions

View File

@ -50,6 +50,7 @@
- Improve the property browser. Show full arc name.
- [smart-pattern/valentina#45] Optimize tool box position for big screen resolutions.
- [smart-pattern/valentina#40] Invalid name of arc in modeling mode.
- New warning. Error calculating segment of curve.
# Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path.

View File

@ -38,6 +38,7 @@
#include "vabstractcurve_p.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include "../ifc/exception/vexceptionobjecterror.h"
VAbstractCurve::VAbstractCurve(const GOType &type, const quint32 &idObject, const Draw &mode)
:VGObject(type, idObject, mode), d (new VAbstractCurveData())
@ -81,7 +82,7 @@ VAbstractCurve::~VAbstractCurve()
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QVector<QPointF> &points, const QPointF &begin,
const QPointF &end, bool reverse)
const QPointF &end, bool reverse, QString &error)
{
QVector<QPointF> segment = points;
if (reverse)
@ -98,15 +99,47 @@ QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QVector<QPointF> &points
finish = segment.last();
}
segment = FromBegin(segment, start);
segment = ToEnd(segment, finish);
bool ok = false;
segment = FromBegin(segment, start, &ok);
if (not ok)
{
error = QObject::tr("Could not find the segment start.");
return segment;
}
ok = false;
segment = ToEnd(segment, finish, &ok);
if (not ok)
{
error = QObject::tr("Could not find the segment end.");
return segment;
}
if (segment.length() < 2)
{
error = QObject::tr("Segment is too short.");
}
return segment;
}
//---------------------------------------------------------------------------------------------------------------------
QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse) const
{
return GetSegmentPoints(GetPoints(), begin, end, reverse);
QString error;
QVector<QPointF> segment = GetSegmentPoints(GetPoints(), begin, end, reverse, error);
if (not error.isEmpty())
{
const QString errorMsg = QObject::tr("Error calculating segment for curve '%1'. %2")
.arg(name(), error);
qApp->IsPedantic() ? throw VExceptionObjectError(errorMsg) :
qWarning() << VAbstractApplication::patternMessageSignature + errorMsg;
}
return segment;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -63,8 +63,8 @@ public:
virtual QVector<QPointF> GetPoints() const =0;
static QVector<QPointF> GetSegmentPoints(const QVector<QPointF> &points, const QPointF &begin, const QPointF &end,
bool reverse = false);
QVector<QPointF> GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse = false) const;
bool reverse, QString &error);
QVector<QPointF> GetSegmentPoints(const QPointF &begin, const QPointF &end, bool reverse) const;
virtual QPainterPath GetPath() const;
virtual qreal GetLength() const =0;

View File

@ -665,7 +665,8 @@ void TST_VSpline::GetSegmentPoints_issue767()
points.append(QPointF(4214.980535433111, 2269.448333408385));
points.append(QPointF(4214.980535433071, 2235.242494488189));
const QVector<QPointF> res = VAbstractCurve::GetSegmentPoints(points, begin, end, false);
QString error;
const QVector<QPointF> res = VAbstractCurve::GetSegmentPoints(points, begin, end, false, error);
QVector<QPointF> origPoints;
origPoints.append(QPointF(3964.650771379471, 3212.2173150777817));