From 31f92c361027d5ede973a076719debcce2bef83d Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 22 Mar 2020 18:21:13 +0200 Subject: [PATCH] Improve calculation of the layout efficiency for cases with several pages. --- src/libs/vlayout/vlayoutgenerator.cpp | 92 ++++++++++++++++++++++++--- src/libs/vlayout/vlayoutgenerator.h | 5 +- 2 files changed, 87 insertions(+), 10 deletions(-) diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 61709a112..c34d403c3 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -275,12 +275,7 @@ qreal VLayoutGenerator::LayoutEfficiency() const qreal efficiency = 0; if (not papers.isEmpty()) { - for(auto &paper : papers) - { - efficiency += paper.Efficiency(); - } - - efficiency /= papers.size(); + efficiency = MasterPage().Efficiency(); } return efficiency; } @@ -613,7 +608,7 @@ void VLayoutGenerator::UnitePages() } //--------------------------------------------------------------------------------------------------------------------- -void VLayoutGenerator::UniteDetails(int j, QList > &nDetails, qreal length, int i) +void VLayoutGenerator::UniteDetails(int j, QList > &nDetails, qreal length, int i) const { if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size()) {//First or new details in paper @@ -639,7 +634,7 @@ void VLayoutGenerator::UnitePapers(int j, QList &papersLength, qreal leng } //--------------------------------------------------------------------------------------------------------------------- -QList VLayoutGenerator::MoveDetails(qreal length, const QVector &details) +QList VLayoutGenerator::MoveDetails(qreal length, const QVector &details) const { if (qFuzzyIsNull(length)) { @@ -656,6 +651,87 @@ QList VLayoutGenerator::MoveDetails(qreal length, const QVector > nDetails; + qreal length = 0; + const int j = 0; // papers count. Always 1. + + for (int i = 0; i < papers.size(); ++i) + { + if (IsPortrait()) + { + int paperHeight = 0; + if (autoCropLength) + { + const QRectF rec = papers.at(i).DetailsBoundingRect(); + paperHeight = qRound(rec.y() + rec.height()); + } + else + { + paperHeight = papers.at(i).GetHeight(); + } + + if (i != papers.size()-1) + { + paperHeight = qRound(paperHeight + bank->GetLayoutWidth()*2); + } + + UniteDetails(j, nDetails, length, i); + length += paperHeight; + } + else + { + int paperWidth = 0; + if (autoCropLength) + { + const QRectF rec = papers.at(i).DetailsBoundingRect(); + paperWidth = qRound(rec.x() + rec.width()); + } + else + { + paperWidth = papers.at(i).GetWidth(); + } + + if (i != papers.size()-1) + { + paperWidth = qRound(paperWidth + bank->GetLayoutWidth()*2); + } + + UniteDetails(j, nDetails, length, i); + length += paperWidth; + } + } + + const int height = IsPortrait() ? qRound(length+accuracyPointOnLine*4) : PageHeight(); + const int width = IsPortrait() ? PageWidth() : qRound(length+accuracyPointOnLine*4); + + VLayoutPaper paper(height, width, bank->GetLayoutWidth()); + paper.SetShift(shift); + paper.SetPaperIndex(static_cast(0)); + paper.SetRotate(rotate); + paper.SetFollowGrainline(followGrainline); + paper.SetRotationNumber(rotationNumber); + paper.SetSaveLength(saveLength); + paper.SetDetails(nDetails.at(0)); + + return paper; +} + //--------------------------------------------------------------------------------------------------------------------- bool VLayoutGenerator::IsUnitePages() const { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 38b8edb80..e7c4d011b 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -171,9 +171,10 @@ private: void GatherPages(); void UnitePages(); - void UniteDetails(int j, QList > &nDetails, qreal length, int i); + void UniteDetails(int j, QList > &nDetails, qreal length, int i) const; void UnitePapers(int j, QList &papersLength, qreal length); - QList MoveDetails(qreal length, const QVector &details); + QList MoveDetails(qreal length, const QVector &details) const; + VLayoutPaper MasterPage() const; }; #endif // VLAYOUTGENERATOR_H