From 10a20b08b80d90c7fda88426509f43a7cfd7f6fa Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Fri, 28 Sep 2018 14:29:10 +0300 Subject: [PATCH] Be pendantic about notch errors. --HG-- branch : release --- src/app/valentina/core/vapplication.cpp | 7 +++ src/libs/ifc/exception/exception.pri | 6 ++- .../ifc/exception/vexceptioninvalidnotch.cpp | 49 +++++++++++++++++++ .../ifc/exception/vexceptioninvalidnotch.h | 42 ++++++++++++++++ src/libs/vpatterndb/vpiece.cpp | 24 ++++++++- src/libs/vpatterndb/vpiecepath.cpp | 25 ++++++++++ src/libs/vpatterndb/vpiecepath.h | 4 ++ 7 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 src/libs/ifc/exception/vexceptioninvalidnotch.cpp create mode 100644 src/libs/ifc/exception/vexceptioninvalidnotch.h diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index 9fe9c4eca..6751f6577 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -32,6 +32,7 @@ #include "../ifc/exception/vexceptionconversionerror.h" #include "../ifc/exception/vexceptionemptyparameter.h" #include "../ifc/exception/vexceptionwrongid.h" +#include "../ifc/exception/vexceptioninvalidnotch.h" #include "../vwidgets/vmaingraphicsview.h" #include "../version.h" #include "../vmisc/logging.h" @@ -366,6 +367,12 @@ bool VApplication::notify(QObject *receiver, QEvent *event) qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); exit(V_EX_DATAERR); } + catch(const VExceptionInvalidNotch &e) + { + qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Invalid notch.")), + qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); + exit(V_EX_DATAERR); + } catch (const VException &e) { qCCritical(vApp, "%s\n\n%s\n\n%s", qUtf8Printable(tr("Something's wrong!!")), diff --git a/src/libs/ifc/exception/exception.pri b/src/libs/ifc/exception/exception.pri index a0b16deb2..fcd84681e 100644 --- a/src/libs/ifc/exception/exception.pri +++ b/src/libs/ifc/exception/exception.pri @@ -8,7 +8,8 @@ HEADERS += \ $$PWD/vexceptionbadid.h \ $$PWD/vexception.h \ $$PWD/vexceptionwrongid.h \ - $$PWD/vexceptionundo.h + $$PWD/vexceptionundo.h \ + $$PWD/vexceptioninvalidnotch.h SOURCES += \ $$PWD/vexceptionobjecterror.cpp \ @@ -17,4 +18,5 @@ SOURCES += \ $$PWD/vexceptionbadid.cpp \ $$PWD/vexception.cpp \ $$PWD/vexceptionwrongid.cpp \ - $$PWD/vexceptionundo.cpp + $$PWD/vexceptionundo.cpp \ + $$PWD/vexceptioninvalidnotch.cpp diff --git a/src/libs/ifc/exception/vexceptioninvalidnotch.cpp b/src/libs/ifc/exception/vexceptioninvalidnotch.cpp new file mode 100644 index 000000000..2af2bfcef --- /dev/null +++ b/src/libs/ifc/exception/vexceptioninvalidnotch.cpp @@ -0,0 +1,49 @@ +/************************************************************************ + ** + ** @file vexceptioninvalidnotch.cpp + ** @author Roman Telezhynskyi + ** @date 28 9, 2018 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2018 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** 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. + ** + ** Valentina is distributed in the hope that it will be useful, + ** 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 . + ** + *************************************************************************/ +#include "vexceptioninvalidnotch.h" + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionInvalidNotch::VExceptionInvalidNotch(const QString &error) + :VException(error) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionInvalidNotch::VExceptionInvalidNotch(const VExceptionInvalidNotch &e) + :VException(e) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionInvalidNotch &VExceptionInvalidNotch::operator=(const VExceptionInvalidNotch &e) +{ + if ( &e == this ) + { + return *this; + } + VException::operator=(e); + return *this; +} diff --git a/src/libs/ifc/exception/vexceptioninvalidnotch.h b/src/libs/ifc/exception/vexceptioninvalidnotch.h new file mode 100644 index 000000000..3b0c9fcd9 --- /dev/null +++ b/src/libs/ifc/exception/vexceptioninvalidnotch.h @@ -0,0 +1,42 @@ +/************************************************************************ + ** + ** @file vexceptioninvalidnotch.h + ** @author Roman Telezhynskyi + ** @date 28 9, 2018 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2018 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** 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. + ** + ** Valentina is distributed in the hope that it will be useful, + ** 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 . + ** + *************************************************************************/ +#ifndef VEXCEPTIONINVALIDNOTCH_H +#define VEXCEPTIONINVALIDNOTCH_H + +#include "vexception.h" + +class VExceptionInvalidNotch : public VException +{ +public: + explicit VExceptionInvalidNotch(const QString &error); + VExceptionInvalidNotch(const VExceptionInvalidNotch &e); + VExceptionInvalidNotch &operator=(const VExceptionInvalidNotch &e); + virtual ~VExceptionInvalidNotch() V_NOEXCEPT_EXPR (true) Q_DECL_EQ_DEFAULT; +}; + +#endif // VEXCEPTIONINVALIDNOTCH_H diff --git a/src/libs/vpatterndb/vpiece.cpp b/src/libs/vpatterndb/vpiece.cpp index a7beb9057..6684a175f 100644 --- a/src/libs/vpatterndb/vpiece.cpp +++ b/src/libs/vpatterndb/vpiece.cpp @@ -33,6 +33,7 @@ #include "../vgeometry/vplacelabelitem.h" #include "vcontainer.h" #include "../vmisc/vabstractapplication.h" +#include "../ifc/exception/vexceptioninvalidnotch.h" #include #include @@ -1250,19 +1251,28 @@ QVector VPiece::CreatePassmark(const QVector &path, int prev VSAPoint passmarkSAPoint; if (not GetPassmarkSAPoint(path, passmarkIndex, data, passmarkSAPoint)) { - return QVector(); // Something wrong + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; + return QVector(); } VSAPoint previousSAPoint; if (not GetPassmarkPreviousSAPoints(path, previousIndex, passmarkSAPoint, data, previousSAPoint)) { + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return QVector(); // Something wrong } VSAPoint nextSAPoint; if (not GetPassmarkNextSAPoints(path, nextIndex, passmarkSAPoint, data, nextSAPoint)) { + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'.") + .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return QVector(); // Something wrong } @@ -1298,18 +1308,28 @@ QVector VPiece::SAPassmark(const QVector &path, VSAPoint &pr { if (seamAllowance.size() < 2) { + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Seam allowance is " + "empty.").arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return QVector(); // Something wrong } QPointF seamPassmarkSAPoint; if (not GetSeamPassmarkSAPoint(previousSAPoint, passmarkSAPoint, nextSAPoint, data, seamPassmarkSAPoint)) { + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Cannot find " + "position for a notch.") + .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; return QVector(); // Something wrong } if (not FixNotchPoint(seamAllowance, passmarkSAPoint, &seamPassmarkSAPoint)) { - // Show warning + const QString errorMsg = QObject::tr("Cannot calculate a notch for point '%1' in piece '%2'. Unable to fix a " + "notch position.") + .arg(VPiecePath::NodeName(path, passmarkIndex, data), GetName()); + qApp->IsPedantic() ? throw VExceptionInvalidNotch(errorMsg) : qWarning() << errorMsg; } const qreal width = ToPixel(GetSAWidth(), *data->GetPatternUnit()); diff --git a/src/libs/vpatterndb/vpiecepath.cpp b/src/libs/vpatterndb/vpiecepath.cpp index 7ca3862a2..4bdedaf80 100644 --- a/src/libs/vpatterndb/vpiecepath.cpp +++ b/src/libs/vpatterndb/vpiecepath.cpp @@ -660,6 +660,12 @@ QVector VPiecePath::MissingNodes(const VPiecePath &path) const return nodes; } +//--------------------------------------------------------------------------------------------------------------------- +QString VPiecePath::NodeName(int nodeIndex, const VContainer *data) const +{ + return NodeName(d->m_nodes, nodeIndex, data); +} + //--------------------------------------------------------------------------------------------------------------------- int VPiecePath::indexOfNode(quint32 id) const { @@ -1178,3 +1184,22 @@ QVector VPiecePath::CurveSeamAllowanceSegment(const VContainer *data, return pointsEkv; } + +//--------------------------------------------------------------------------------------------------------------------- +QString VPiecePath::NodeName(const QVector &nodes, int nodeIndex, const VContainer *data) +{ + if (not nodes.isEmpty() && (nodeIndex < 0 || nodeIndex >= nodes.size())) + { + return QString(); + } + + try + { + QSharedPointer obj = data->GetGObject(nodes.at(nodeIndex).GetId()); + return obj->name(); + } + catch (VExceptionBadId) { + // ignore + } + return QString(); +} diff --git a/src/libs/vpatterndb/vpiecepath.h b/src/libs/vpatterndb/vpiecepath.h index 36548f73f..efa8b3e80 100644 --- a/src/libs/vpatterndb/vpiecepath.h +++ b/src/libs/vpatterndb/vpiecepath.h @@ -103,6 +103,8 @@ public: QList Dependencies() const; QVector MissingNodes(const VPiecePath &path) const; + QString NodeName(int nodeIndex, const VContainer *data) const; + int indexOfNode(quint32 id) const; void NodeOnEdge(quint32 index, VPieceNode &p1, VPieceNode &p2) const; bool Contains(quint32 id) const; @@ -135,6 +137,8 @@ public: const QSharedPointer &curve, int i, bool reverse, qreal width); + static QString NodeName(const QVector &nodes, int nodeIndex, const VContainer *data); + private: QSharedDataPointer d; };