Be pendantic about notch errors.

--HG--
branch : release
This commit is contained in:
Roman Telezhynskyi 2018-09-28 14:29:10 +03:00
parent ac3b8a2726
commit 10a20b08b8
7 changed files with 153 additions and 4 deletions

View File

@ -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!!")),

View File

@ -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

View File

@ -0,0 +1,49 @@
/************************************************************************
**
** @file vexceptioninvalidnotch.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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;
}

View File

@ -0,0 +1,42 @@
/************************************************************************
**
** @file vexceptioninvalidnotch.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <https://bitbucket.org/dismine/valentina> 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 <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#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

View File

@ -33,6 +33,7 @@
#include "../vgeometry/vplacelabelitem.h"
#include "vcontainer.h"
#include "../vmisc/vabstractapplication.h"
#include "../ifc/exception/vexceptioninvalidnotch.h"
#include <QSharedPointer>
#include <QDebug>
@ -1250,19 +1251,28 @@ QVector<QLineF> VPiece::CreatePassmark(const QVector<VPieceNode> &path, int prev
VSAPoint passmarkSAPoint;
if (not GetPassmarkSAPoint(path, passmarkIndex, data, passmarkSAPoint))
{
return QVector<QLineF>(); // 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<QLineF>();
}
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<QLineF>(); // 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<QLineF>(); // Something wrong
}
@ -1298,18 +1308,28 @@ QVector<QLineF> VPiece::SAPassmark(const QVector<VPieceNode> &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<QLineF>(); // 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<QLineF>(); // 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());

View File

@ -660,6 +660,12 @@ QVector<quint32> 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<VSAPoint> VPiecePath::CurveSeamAllowanceSegment(const VContainer *data,
return pointsEkv;
}
//---------------------------------------------------------------------------------------------------------------------
QString VPiecePath::NodeName(const QVector<VPieceNode> &nodes, int nodeIndex, const VContainer *data)
{
if (not nodes.isEmpty() && (nodeIndex < 0 || nodeIndex >= nodes.size()))
{
return QString();
}
try
{
QSharedPointer<VGObject> obj = data->GetGObject(nodes.at(nodeIndex).GetId());
return obj->name();
}
catch (VExceptionBadId) {
// ignore
}
return QString();
}

View File

@ -103,6 +103,8 @@ public:
QList<quint32> Dependencies() const;
QVector<quint32> 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<VAbstractCurve> &curve,
int i, bool reverse, qreal width);
static QString NodeName(const QVector<VPieceNode> &nodes, int nodeIndex, const VContainer *data);
private:
QSharedDataPointer<VPiecePathData> d;
};