diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 95ff95066..0c9db8e72 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -363,6 +363,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) case LayoutErrors::Timeout: case LayoutErrors::PrepareLayoutError: case LayoutErrors::ProcessStoped: + case LayoutErrors::TerminatedByException: default: break; } @@ -370,6 +371,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator) nestingState = lGenerator.State(); if (nestingState == LayoutErrors::PrepareLayoutError || nestingState == LayoutErrors::ProcessStoped + || nestingState == LayoutErrors::TerminatedByException || (nestingState == LayoutErrors::NoError && not qFuzzyIsNull(lGenerator.GetEfficiencyCoefficient()) && efficiency >= lGenerator.GetEfficiencyCoefficient())) { @@ -433,6 +435,9 @@ void MainWindowsNoGUI::ShowLayoutError(const LayoutErrors &state) case LayoutErrors::Timeout: qCritical() << tr("Timeout."); break; + case LayoutErrors::TerminatedByException: + qCritical() << tr("Process has been stoped because of exception."); + break; case LayoutErrors::ProcessStoped: default: break; diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro index b72602ee1..592efadd2 100644 --- a/src/app/valentina/valentina.pro +++ b/src/app/valentina/valentina.pro @@ -535,6 +535,15 @@ DEPENDPATH += $$PWD/../../libs/fervor win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/fervor/$${DESTDIR}/fervor.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/fervor/$${DESTDIR}/libfervor.a +# VLayout static library (depend on IFC) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout + +INCLUDEPATH += $$PWD/../../libs/vlayout +DEPENDPATH += $$PWD/../../libs/vlayout + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a + # IFC static library (depend on QMuParser, VMisc) unix|win32: LIBS += -L$$OUT_PWD/../../libs/ifc/$${DESTDIR}/ -lifc @@ -571,15 +580,6 @@ DEPENDPATH += $$PWD/../../libs/vdxf win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/vdxf.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vdxf/$${DESTDIR}/libvdxf.a -# VLayout static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR}/ -lvlayout - -INCLUDEPATH += $$PWD/../../libs/vlayout -DEPENDPATH += $$PWD/../../libs/vlayout - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a - # QMuParser library win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 diff --git a/src/libs/ifc/exception/exception.pri b/src/libs/ifc/exception/exception.pri index fcd84681e..d1df21748 100644 --- a/src/libs/ifc/exception/exception.pri +++ b/src/libs/ifc/exception/exception.pri @@ -7,6 +7,7 @@ HEADERS += \ $$PWD/vexceptionconversionerror.h \ $$PWD/vexceptionbadid.h \ $$PWD/vexception.h \ + $$PWD/vexceptionterminatedposition.h \ $$PWD/vexceptionwrongid.h \ $$PWD/vexceptionundo.h \ $$PWD/vexceptioninvalidnotch.h @@ -17,6 +18,7 @@ SOURCES += \ $$PWD/vexceptionconversionerror.cpp \ $$PWD/vexceptionbadid.cpp \ $$PWD/vexception.cpp \ + $$PWD/vexceptionterminatedposition.cpp \ $$PWD/vexceptionwrongid.cpp \ $$PWD/vexceptionundo.cpp \ $$PWD/vexceptioninvalidnotch.cpp diff --git a/src/libs/ifc/exception/vexceptionterminatedposition.cpp b/src/libs/ifc/exception/vexceptionterminatedposition.cpp new file mode 100644 index 000000000..4fab04740 --- /dev/null +++ b/src/libs/ifc/exception/vexceptionterminatedposition.cpp @@ -0,0 +1,68 @@ +/************************************************************************ + ** + ** @file vexceptionterminatedposition.cpp + ** @author Roman Telezhynskyi + ** @date 24 6, 2019 + ** + ** @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) 2019 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 "vexceptionterminatedposition.h" + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionTerminatedPosition::VExceptionTerminatedPosition(const QString &error) V_NOEXCEPT_EXPR (true) + :VException(error) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionTerminatedPosition::VExceptionTerminatedPosition(const VExceptionTerminatedPosition &e) +V_NOEXCEPT_EXPR (true) + :VException(e) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionTerminatedPosition &VExceptionTerminatedPosition::operator=(const VExceptionTerminatedPosition &e) +V_NOEXCEPT_EXPR (true) +{ + if ( &e == this ) + { + return *this; + } + VException::operator=(e); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionTerminatedPosition::~VExceptionTerminatedPosition() V_NOEXCEPT_EXPR (true) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VExceptionTerminatedPosition::raise() const +{ + throw *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VExceptionTerminatedPosition *VExceptionTerminatedPosition::clone() const +{ + return new VExceptionTerminatedPosition(*this); +} diff --git a/src/libs/ifc/exception/vexceptionterminatedposition.h b/src/libs/ifc/exception/vexceptionterminatedposition.h new file mode 100644 index 000000000..33884b67f --- /dev/null +++ b/src/libs/ifc/exception/vexceptionterminatedposition.h @@ -0,0 +1,47 @@ +/************************************************************************ + ** + ** @file vexceptionterminatedposition.h + ** @author Roman Telezhynskyi + ** @date 24 6, 2019 + ** + ** @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) 2019 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 VEXCEPTIONTERMINATEDPOSITION_H +#define VEXCEPTIONTERMINATEDPOSITION_H + +#include "vexception.h" + +class VExceptionTerminatedPosition : public VException +{ +public: + explicit VExceptionTerminatedPosition(const QString &error) V_NOEXCEPT_EXPR (true); + VExceptionTerminatedPosition(const VExceptionTerminatedPosition &e) V_NOEXCEPT_EXPR (true); + VExceptionTerminatedPosition &operator=(const VExceptionTerminatedPosition &e) V_NOEXCEPT_EXPR (true); + virtual ~VExceptionTerminatedPosition() V_NOEXCEPT_EXPR (true); + + Q_NORETURN virtual void raise() const override; + + // cppcheck-suppress unusedFunction + Q_REQUIRED_RESULT virtual VExceptionTerminatedPosition *clone() const override; +}; + +#endif // VEXCEPTIONTERMINATEDPOSITION_H diff --git a/src/libs/vlayout/vbestsquare.cpp b/src/libs/vlayout/vbestsquare.cpp index 00f43ced4..8a14aeee5 100644 --- a/src/libs/vlayout/vbestsquare.cpp +++ b/src/libs/vlayout/vbestsquare.cpp @@ -161,9 +161,23 @@ BestFrom VBestSquare::Type() const } //--------------------------------------------------------------------------------------------------------------------- -qreal VBestSquare::Position() const +bool VBestSquare::IsTerminatedByException() const { - return d->depthPosition; + return d->terminatedByException; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VBestSquare::ReasonTerminatedByException() const +{ + return d->exceptionReason; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VBestSquare::TerminatedByException(const QString &reason) +{ + d->valideResult = false; + d->terminatedByException = true; + d->exceptionReason = reason; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vbestsquare.h b/src/libs/vlayout/vbestsquare.h index 97b91b9c0..a8fe39017 100644 --- a/src/libs/vlayout/vbestsquare.h +++ b/src/libs/vlayout/vbestsquare.h @@ -64,7 +64,9 @@ public: bool HasValidResult() const; bool Mirror() const; BestFrom Type() const; - qreal Position() const; + bool IsTerminatedByException() const; + QString ReasonTerminatedByException() const; + void TerminatedByException(const QString &reason); VBestSquareResData BestResultData() const; diff --git a/src/libs/vlayout/vbestsquare_p.h b/src/libs/vlayout/vbestsquare_p.h index f5940f6d8..5ce4e02b7 100644 --- a/src/libs/vlayout/vbestsquare_p.h +++ b/src/libs/vlayout/vbestsquare_p.h @@ -54,9 +54,10 @@ public: sheetSize(res.sheetSize), valideResult(res.valideResult), saveLength(res.saveLength), - depthPosition(res.depthPosition), data(res.data), - isPortrait(res.isPortrait) + isPortrait(res.isPortrait), + terminatedByException(res.terminatedByException), + exceptionReason(res.exceptionReason) {} ~VBestSquareData() {} @@ -64,9 +65,10 @@ public: QSizeF sheetSize; bool valideResult{false}; bool saveLength; - qreal depthPosition{INT_MAX}; VBestSquareResData data{}; bool isPortrait{true}; + bool terminatedByException{false}; + QString exceptionReason{}; private: VBestSquareData &operator=(const VBestSquareData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 89a67f97c..246f0804f 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -41,7 +41,8 @@ enum class LayoutErrors : char PrepareLayoutError, ProcessStoped, EmptyPaperError, - Timeout + Timeout, + TerminatedByException }; enum class BestFrom : char diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 65d4a52b2..a46a52c8b 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -37,6 +37,7 @@ #include "../vmisc/vmath.h" #include "vlayoutpiece.h" #include "vlayoutpaper.h" +#include "../ifc/exception/vexceptionterminatedposition.h" //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) @@ -186,13 +187,22 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo do { const int index = bank->GetNext(); - if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration)) + try { - bank->Arranged(index); + if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration)) + { + bank->Arranged(index); + } + else + { + bank->NotArranged(index); + } } - else + catch (const VExceptionTerminatedPosition &e) { - bank->NotArranged(index); + qCritical() << e.ErrorMessage(); + state = LayoutErrors::TerminatedByException; + return; } QCoreApplication::processEvents(); diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 120ef8d3c..15d47890a 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -48,6 +48,7 @@ #include "vlayoutpiece.h" #include "vlayoutpaper_p.h" #include "vposition.h" +#include "../ifc/exception/vexceptionterminatedposition.h" //--------------------------------------------------------------------------------------------------------------------- VLayoutPaper::VLayoutPaper() @@ -272,6 +273,10 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints); d->positionsCache.append(positionChache); } + else if (bestResult.IsTerminatedByException()) + { + throw VExceptionTerminatedPosition(bestResult.ReasonTerminatedByException()); + } return bestResult.HasValidResult(); // Do we have the best result? } diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index 487b25931..47aa4ed7d 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -78,7 +78,20 @@ void VPosition::run() return; } - FindBestPosition(); + try + { + FindBestPosition(); + } + catch (const VException &e) + { + m_bestResult.TerminatedByException(QStringLiteral("%1\n\n%2").arg(e.ErrorMessage(), e.DetailedInformation())); + return; + } + catch (std::exception& e) + { + m_bestResult.TerminatedByException(QString::fromLatin1(e.what())); + return; + } } //---------------------------------------------------------------------------------------------------------------------