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);
int papersCount = INT_MAX;
qreal efficiency = 0;
bool hasResult = false;
QCoreApplication::processEvents();
@ -293,7 +294,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
break;
}
lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs());
lGenerator.Generate(timer, lGenerator.GetNestingTimeMSecs(), nestingState);
if (IsTimeout())
{
@ -334,6 +335,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
isAutoCrop = lGenerator.GetAutoCrop();
isUnitePages = lGenerator.IsUnitePages();
isLayoutStale = false;
hasResult = true;
}
}
lGenerator.SetShift(lGenerator.GetShift()/2.0);
@ -399,7 +401,7 @@ bool MainWindowsNoGUI::GenerateLayout(VLayoutGenerator& lGenerator)
QApplication::alert(this);
}
if (not papers.isEmpty() && nestingState != LayoutErrors::ProcessStoped)
if (hasResult && nestingState != LayoutErrors::ProcessStoped)
{
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);
papers.clear();
bank->Reset();
state = LayoutErrors::NoError;
state = previousState;
int width = PageWidth();
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 (bank->PrepareDetails())
@ -138,17 +151,15 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
}
}
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
if (bank->PrepareUnsorted())
{
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
@ -159,9 +170,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return;
}
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
@ -192,9 +202,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
break;
}
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
} while(bank->LeftToArrange() > 0);
@ -204,9 +213,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return;
}
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
@ -227,9 +235,8 @@ void VLayoutGenerator::Generate(QElapsedTimer timer, qint64 timeout)
return;
}
if (timer.hasExpired(timeout))
if (HasExpired())
{
state = LayoutErrors::Timeout;
return;
}
@ -322,7 +329,10 @@ void VLayoutGenerator::Abort()
void VLayoutGenerator::Timeout()
{
stopGeneration.store(true);
state = LayoutErrors::Timeout;
if (state == LayoutErrors::NoError)
{
state = LayoutErrors::Timeout;
}
QThreadPool::globalInstance()->clear();
}

View File

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