Improve handling layout errors.

Show Timeout error only if none errors appeared before.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-06-18 15:14:52 +03:00
parent 80d55659ab
commit f7c4bdf2a7
3 changed files with 30 additions and 18 deletions

View File

@ -283,6 +283,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
lGenerator.SetRotate(false); lGenerator.SetRotate(false);
int papersCount = INT_MAX; int papersCount = INT_MAX;
qreal efficiency = 0; qreal efficiency = 0;
bool hasResult = false;
QCoreApplication::processEvents(); QCoreApplication::processEvents();
@ -293,7 +294,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
break; break;
} }
lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs()); lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState);
if (IsTimeout()) if (IsTimeout())
{ {
@ -334,6 +335,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
isAutoCrop = lGenerator.GetAutoCrop(); isAutoCrop = lGenerator.GetAutoCrop();
isUnitePages = lGenerator.IsUnitePages(); isUnitePages = lGenerator.IsUnitePages();
isLayoutStale = false; isLayoutStale = false;
hasResult = true;
} }
} }
lGenerator.SetShift(lGenerator.GetShift()/2.0); lGenerator.SetShift(lGenerator.GetShift()/2.0);
@ -399,7 +401,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
QApplication::alert(this); QApplication::alert(this);
} }
if (not papers.isEmpty() && nestingState != LayoutErrors::ProcessStoped) if (hasResult && nestingState != LayoutErrors::ProcessStoped)
{ {
return true; return true;
} }

View File

@ -99,16 +99,29 @@ int VLayoutGenerator::DetailsCount()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout) void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout, LayoutErrors previousState)
{ {
stopGeneration.store(false); stopGeneration.store(false);
papers.clear(); papers.clear();
bank->Reset(); bank->Reset();
state = LayoutErrors::NoError; state = previousState;
int width = PageWidth(); int width = PageWidth();
int height = PageHeight(); int height = PageHeight();
auto HasExpired = [this, timer, timeout]()
{
if (timer.hasExpired(timeout))
{
if (state == LayoutErrors::NoError)
{
state = LayoutErrors::Timeout;
}
return true;
}
return false;
};
if (VFuzzyComparePossibleNulls(shift, -1)) if (VFuzzyComparePossibleNulls(shift, -1))
{ {
if (bank->PrepareDetails()) if (bank->PrepareDetails())
@ -138,17 +151,15 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
} }
} }
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
if (bank->PrepareUnsorted()) if (bank->PrepareUnsorted())
{ {
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
@ -159,9 +170,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return; return;
} }
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
@ -192,9 +202,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
break; break;
} }
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
} while(bank->LeftToArrange() > 0); } while(bank->LeftToArrange() > 0);
@ -204,9 +213,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return; return;
} }
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
@ -227,9 +235,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return; return;
} }
if (timer.hasExpired(timeout)) if (HasExpired())
{ {
state = LayoutErrors::Timeout;
return; return;
} }
@ -322,7 +329,10 @@ void VLayoutGenerator::Abort()
void VLayoutGenerator::Timeout() void VLayoutGenerator::Timeout()
{ {
stopGeneration.store(true); stopGeneration.store(true);
if (state == LayoutErrors::NoError)
{
state = LayoutErrors::Timeout; state = LayoutErrors::Timeout;
}
QThreadPool::globalInstance()->clear(); QThreadPool::globalInstance()->clear();
} }

View File

@ -79,7 +79,7 @@ public:
qreal GetShift() const; qreal GetShift() const;
void SetShift(qreal shift); void SetShift(qreal shift);
void Generate(QElapsedTimer timer, qint64 timeout); void Generate(QElapsedTimer timer, qint64 timeout, LayoutErrors previousState = LayoutErrors::NoError);
qreal LayoutEfficiency() const; qreal LayoutEfficiency() const;