New warnings. Warn a user about incorrect cut curve segment length.

This commit is contained in:
Roman Telezhynskyi 2021-07-24 11:15:48 +03:00
parent 95ba17aee3
commit a6d9194051
5 changed files with 100 additions and 2 deletions

View File

@ -4,6 +4,7 @@
- Warn about stale layout only in GUI mode.
- Fix regression. Set default value for detail labels size and grainline length to 10 cm.
- [smart-pattern/valentina#136] 2 decimals for entering values in multi measurements tables.
- New warnings. Warn a user about incorrect cut curve segment length.
# Valentina 0.7.49 July 1, 2021
- Fix crash.

View File

@ -39,6 +39,7 @@
#include "../vmisc/vmath.h"
#include "../vgeometry/vpointf.h"
#include "../vmisc/vabstractapplication.h"
#include "../ifc/exception/vexception.h"
namespace
{
@ -420,6 +421,11 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
if (fullLength <= minLength)
{
spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF();
const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
return QPointF();
}
@ -428,10 +434,20 @@ QPointF VAbstractCubicBezier::CutSpline(qreal length, QPointF &spl1p2, QPointF &
if (length < minLength)
{
length = minLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else if (length > maxLength)
{
length = maxLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
const qreal parT = GetParmT(length);

View File

@ -30,12 +30,14 @@
#include "vsplinepoint.h"
#include <QPainterPath>
#include <QtDebug>
#include "../vmisc/def.h"
#include "../ifc/ifcdef.h"
#include "../ifc/exception/vexception.h"
#include "vpointf.h"
#include "vspline.h"
#include "vabstractapplication.h"
//---------------------------------------------------------------------------------------------------------------------
VAbstractCubicBezierPath::VAbstractCubicBezierPath(const GOType &type, const quint32 &idObject, const Draw &mode)
@ -180,6 +182,11 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32
{
p1 = p2 = -1;
spl1p2 = spl1p3 = spl2p2 = spl2p3 = QPointF();
const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
return QPointF();
}
@ -188,10 +195,20 @@ QPointF VAbstractCubicBezierPath::CutSplinePath(qreal length, qint32 &p1, qint32
if (length < minLength)
{
length = minLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else if (length > maxLength)
{
length = maxLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
fullLength = 0;

View File

@ -30,6 +30,7 @@
#include <QLineF>
#include <QPointF>
#include <QtDebug>
#include "../vmisc/def.h"
#include "../vmisc/vmath.h"
@ -38,6 +39,7 @@
#include "vabstractcurve.h"
#include "varc_p.h"
#include "vspline.h"
#include "../ifc/exception/vexception.h"
//---------------------------------------------------------------------------------------------------------------------
/**
@ -351,10 +353,17 @@ QPointF VArc::CutArc(qreal length, VArc &arc1, VArc &arc2) const
{
arc1 = VArc();
arc2 = VArc();
const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
return QPointF();
}
QLineF line(static_cast<QPointF>(GetCenter()), GetP1());
const qreal minLength = ToPixel(1, Unit::Mm);
const qreal maxLength = fullLength - ToPixel(1, Unit::Mm);
if (not IsFlipped())
{
@ -362,7 +371,26 @@ QPointF VArc::CutArc(qreal length, VArc &arc1, VArc &arc2) const
{
length = fullLength + length;
}
length = qBound(ToPixel(1, Unit::Mm), length, fullLength - ToPixel(1, Unit::Mm));
const qreal minLength = ToPixel(1, Unit::Mm);
const qreal maxLength = fullLength - ToPixel(1, Unit::Mm);
if (length < minLength)
{
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to "
"minimal value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else if (length > maxLength)
{
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to "
"maximal value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
length = qBound(minLength, length, maxLength);
line.setAngle(line.angle() + qRadiansToDegrees(length/d->radius));
}
@ -372,7 +400,26 @@ QPointF VArc::CutArc(qreal length, VArc &arc1, VArc &arc2) const
{
length = fullLength + length;
}
length = qBound(fullLength + ToPixel(1, Unit::Mm), length, ToPixel(-1, Unit::Mm));
const qreal minLength = fullLength + ToPixel(1, Unit::Mm);
const qreal maxLength = ToPixel(-1, Unit::Mm);
if (length > minLength)
{
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to "
"minimal value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else if (length < maxLength)
{
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to "
"maximal value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
length = qBound(minLength, length, maxLength);
line.setAngle(line.angle() - qRadiansToDegrees(qAbs(length)/d->radius));
}

View File

@ -31,10 +31,12 @@
#include <QLineF>
#include <QPoint>
#include <QPainterPath>
#include <QtDebug>
#include "../vmisc/def.h"
#include "../vmisc/vmath.h"
#include "../ifc/ifcdef.h"
#include "../ifc/exception/vexception.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include "vabstractcurve.h"
@ -356,6 +358,11 @@ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllip
{
arc1 = VEllipticalArc();
arc2 = VEllipticalArc();
const QString errorMsg = QObject::tr("Unable to cut curve '%1'. The curve is too short.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
return QPointF();
}
@ -364,10 +371,20 @@ QPointF VEllipticalArc::CutArc(const qreal &length, VEllipticalArc &arc1, VEllip
if (length < minLength)
{
len = minLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too small. Optimize it to minimal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else if (length > maxLength)
{
len = maxLength;
const QString errorMsg = QObject::tr("Curve '%1'. Length of a cut segment is too big. Optimize it to maximal "
"value.").arg(name());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractApplication::warningMessageSignature + errorMsg;
}
else
{