diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index a4abaa5b7..a64fa8895 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -94,7 +94,6 @@ void VLayoutGenerator::Generate() { if (stopGeneration) { - state = LayoutErrors::ProcessStoped; break; } @@ -104,7 +103,7 @@ void VLayoutGenerator::Generate() if (bank->LeftArrange() > 0) { const int index = bank->GetTiket(); - if (paper.ArrangeDetail(bank->GetDetail(index))) + if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration)) { bank->Arranged(index); emit Arranged(bank->ArrangedCount()); @@ -113,6 +112,11 @@ void VLayoutGenerator::Generate() { bank->NotArranged(index); } + + if (stopGeneration) + { + break; + } } else { @@ -160,6 +164,7 @@ QList VLayoutGenerator::GetItems() const void VLayoutGenerator::Abort() { stopGeneration = true; + state = LayoutErrors::ProcessStoped; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 116875906..55d84d779 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -183,7 +183,7 @@ void VLayoutPaper::SetPaperIndex(quint32 index) } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail) +bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail, bool &stop) { // First need set size of paper if (d->paperHeight <= 0 || d->paperWidth <= 0) @@ -200,11 +200,11 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail) if (Count() == 0) { - return AddToBlankSheet(detail); + return AddToBlankSheet(detail, stop); } else { - return AddToSheet(detail); + return AddToSheet(detail, stop); } } @@ -215,7 +215,7 @@ int VLayoutPaper::Count() const } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail) +bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail, bool &stop) { BestResult bestResult; @@ -225,6 +225,11 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail) { QCoreApplication::processEvents(); + if (stop) + { + return false; + } + // We should use copy of the detail. VLayoutDetail workDetail = detail; @@ -244,6 +249,11 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail) { QCoreApplication::processEvents(); + if (stop) + { + return false; + } + // We should use copy of the detail. VLayoutDetail workDetail = detail; @@ -265,7 +275,7 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail) } //--------------------------------------------------------------------------------------------------------------------- -bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail) +bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop) { BestResult bestResult; @@ -278,6 +288,11 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail) { QCoreApplication::processEvents(); + if (stop) + { + return false; + } + int dEdge = i;// For mirror detail edge will be different if (CheckCombineEdges(workDetail, j, dEdge)) { diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 8c3b2e154..0bf62e1b6 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -60,7 +60,7 @@ public: void SetPaperIndex(quint32 index); - bool ArrangeDetail(const VLayoutDetail &detail); + bool ArrangeDetail(const VLayoutDetail &detail, bool &stop); int Count() const; QGraphicsItem *GetItem() const; @@ -81,8 +81,8 @@ private: EdgeError = 2 }; - bool AddToBlankSheet(const VLayoutDetail &detail); - bool AddToSheet(const VLayoutDetail &detail); + bool AddToBlankSheet(const VLayoutDetail &detail, bool &stop); + bool AddToSheet(const VLayoutDetail &detail, bool &stop); bool CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) const; bool CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, int angle) const;