From a6d91940516f0959ccfb92a3fdbfd7f73cc7871a Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 24 Jul 2021 11:15:48 +0300 Subject: [PATCH] New warnings. Warn a user about incorrect cut curve segment length. --- ChangeLog.txt | 1 + src/libs/vgeometry/vabstractcubicbezier.cpp | 16 ++++++ .../vgeometry/vabstractcubicbezierpath.cpp | 17 +++++++ src/libs/vgeometry/varc.cpp | 51 ++++++++++++++++++- src/libs/vgeometry/vellipticalarc.cpp | 17 +++++++ 5 files changed, 100 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e86e2647b..7c75803c1 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -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. diff --git a/src/libs/vgeometry/vabstractcubicbezier.cpp b/src/libs/vgeometry/vabstractcubicbezier.cpp index 396826f85..f6769426e 100644 --- a/src/libs/vgeometry/vabstractcubicbezier.cpp +++ b/src/libs/vgeometry/vabstractcubicbezier.cpp @@ -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); diff --git a/src/libs/vgeometry/vabstractcubicbezierpath.cpp b/src/libs/vgeometry/vabstractcubicbezierpath.cpp index 3a9144e6d..99de0e36b 100644 --- a/src/libs/vgeometry/vabstractcubicbezierpath.cpp +++ b/src/libs/vgeometry/vabstractcubicbezierpath.cpp @@ -30,12 +30,14 @@ #include "vsplinepoint.h" #include +#include #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; diff --git a/src/libs/vgeometry/varc.cpp b/src/libs/vgeometry/varc.cpp index 9ec997da1..ffff21381 100644 --- a/src/libs/vgeometry/varc.cpp +++ b/src/libs/vgeometry/varc.cpp @@ -30,6 +30,7 @@ #include #include +#include #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(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)); } diff --git a/src/libs/vgeometry/vellipticalarc.cpp b/src/libs/vgeometry/vellipticalarc.cpp index 42deedbd7..593fefe46 100644 --- a/src/libs/vgeometry/vellipticalarc.cpp +++ b/src/libs/vgeometry/vellipticalarc.cpp @@ -31,10 +31,12 @@ #include #include #include +#include #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 {