From 63ea3bf2f9b128b9444643188612d75dd06db656 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 27 Mar 2019 09:03:19 +0200 Subject: [PATCH] If user selects SaveLength option add fake contour edge. * * * Fixing issue with pieces on edge. --HG-- branch : develop --- src/libs/vlayout/vcontour.cpp | 19 ++++++++++++++++--- src/libs/vlayout/vcontour.h | 4 +++- src/libs/vlayout/vcontour_p.h | 26 +++++++++++++++++--------- src/libs/vlayout/vlayoutgenerator.cpp | 9 +++------ src/libs/vlayout/vlayoutpaper.cpp | 13 +++++++++---- src/libs/vlayout/vlayoutpaper.h | 2 +- src/libs/vlayout/vlayoutpaper_p.h | 16 +++------------- src/libs/vlayout/vposition.cpp | 5 +++++ 8 files changed, 57 insertions(+), 37 deletions(-) diff --git a/src/libs/vlayout/vcontour.cpp b/src/libs/vlayout/vcontour.cpp index 03a458b45..3fbc6b3de 100644 --- a/src/libs/vlayout/vcontour.cpp +++ b/src/libs/vlayout/vcontour.cpp @@ -46,8 +46,8 @@ VContour::VContour() {} //--------------------------------------------------------------------------------------------------------------------- -VContour::VContour(int height, int width) - :d(new VContourData(height, width)) +VContour::VContour(int height, int width, qreal layoutWidth) + :d(new VContourData(height, width, layoutWidth)) {} //--------------------------------------------------------------------------------------------------------------------- @@ -70,6 +70,16 @@ VContour &VContour::operator=(const VContour &contour) VContour::~VContour() {} +//--------------------------------------------------------------------------------------------------------------------- +void VContour::CeateEmptySheetContour() +{ + if (d->globalContour.isEmpty()) + { + d->globalContour = CutEmptySheetEdge(); + d->globalContour.append(d->globalContour.first()); // Close path + } +} + //--------------------------------------------------------------------------------------------------------------------- void VContour::SetContour(const QVector &contour) { @@ -371,5 +381,8 @@ bool VContour::IsPortrait() const //--------------------------------------------------------------------------------------------------------------------- QLineF VContour::EmptySheetEdge() const { - return IsPortrait() ? QLineF(0, 0, d->paperWidth, 0) : QLineF(0, 0, 0, d->paperHeight); + static const int offset = 2; + const int layoutOffset = qCeil(d->layoutWidth + accuracyPointOnLine); + return IsPortrait() ? QLineF(offset, -layoutOffset, d->paperWidth-offset, -layoutOffset) : + QLineF(-layoutOffset, offset, -layoutOffset, d->paperHeight-offset); } diff --git a/src/libs/vlayout/vcontour.h b/src/libs/vlayout/vcontour.h index 206a1ca99..1933cee8e 100644 --- a/src/libs/vlayout/vcontour.h +++ b/src/libs/vlayout/vcontour.h @@ -48,7 +48,7 @@ class VContour { public: VContour(); - VContour(int height, int width); + VContour(int height, int width, qreal layoutWidth); VContour(const VContour &contour); ~VContour(); @@ -61,6 +61,8 @@ public: inline void Swap(VContour &contour) Q_DECL_NOTHROW { std::swap(d, contour.d); } + void CeateEmptySheetContour(); + void SetContour(const QVector &contour); QVector GetContour() const; diff --git a/src/libs/vlayout/vcontour_p.h b/src/libs/vlayout/vcontour_p.h index 00a98fb6d..97a18cf5f 100644 --- a/src/libs/vlayout/vcontour_p.h +++ b/src/libs/vlayout/vcontour_p.h @@ -31,6 +31,7 @@ #include #include +#include #include "../vmisc/diagnostic.h" @@ -42,30 +43,37 @@ class VContourData : public QSharedData { public: VContourData() - :globalContour(QVector()), paperHeight(0), paperWidth(0), shift(0) {} - VContourData(int height, int width) - :globalContour(QVector()), paperHeight(height), paperWidth(width), shift(0) + VContourData(int height, int width, qreal layoutWidth) + : paperHeight(height), + paperWidth(width), + layoutWidth(layoutWidth) {} VContourData(const VContourData &contour) - :QSharedData(contour), globalContour(contour.globalContour), paperHeight(contour.paperHeight), - paperWidth(contour.paperWidth), shift(contour.shift) + : QSharedData(contour), + globalContour(contour.globalContour), + paperHeight(contour.paperHeight), + paperWidth(contour.paperWidth), + shift(contour.shift), + layoutWidth(contour.layoutWidth) {} ~VContourData() {} /** @brief globalContour list of global points contour. */ - QVector globalContour; + QVector globalContour{}; /** @brief paperHeight height of paper in pixels*/ - int paperHeight; + int paperHeight{0}; /** @brief paperWidth width of paper in pixels*/ - int paperWidth; + int paperWidth{0}; - quint32 shift; + quint32 shift{0}; + + qreal layoutWidth{0}; private: VContourData &operator=(const VContourData &) Q_DECL_EQ_DELETE; diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 7d97fe3d9..83744240b 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -141,9 +141,8 @@ void VLayoutGenerator::Generate() break; } - VLayoutPaper paper(height, width); + VLayoutPaper paper(height, width, bank->GetLayoutWidth()); paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(static_cast(papers.count())); paper.SetRotate(rotate); paper.SetFollowGrainline(followGrainline); @@ -380,9 +379,8 @@ void VLayoutGenerator::GatherPages() QVector nPapers; for (int i = 0; i < nDetails.size(); ++i) { - VLayoutPaper paper(PageHeight(), PageWidth()); + VLayoutPaper paper(PageHeight(), PageWidth(), bank->GetLayoutWidth()); paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(static_cast(i)); paper.SetRotate(rotate); paper.SetFollowGrainline(followGrainline); @@ -484,9 +482,8 @@ void VLayoutGenerator::UnitePages() const int height = IsPortrait() ? qFloor(papersLength.at(i)) : PageHeight(); const int width = IsPortrait() ? PageWidth() : qFloor(papersLength.at(i)); - VLayoutPaper paper(height, width); + VLayoutPaper paper(height, width, bank->GetLayoutWidth()); paper.SetShift(shift); - paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(static_cast(i)); paper.SetRotate(rotate); paper.SetFollowGrainline(followGrainline); diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index de22cba95..a7bf0fb87 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -55,8 +55,8 @@ VLayoutPaper::VLayoutPaper() {} //--------------------------------------------------------------------------------------------------------------------- -VLayoutPaper::VLayoutPaper(int height, int width) - :d(new VLayoutPaperData(height, width)) +VLayoutPaper::VLayoutPaper(int height, int width, qreal layoutWidth) + :d(new VLayoutPaperData(height, width, layoutWidth)) {} //--------------------------------------------------------------------------------------------------------------------- @@ -238,8 +238,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop thread_pool->setExpiryTimeout(1000); QVector threads; - int detailEdgesCount = d->globalContour.GetContour().isEmpty() ? detail.DetailEdgesCount() : - detail.LayoutEdgesCount(); + int detailEdgesCount = detail.LayoutEdgesCount(); for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j) { @@ -307,6 +306,12 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece VLayoutPiece workDetail = detail; workDetail.SetMatrix(bestResult.Matrix());// Don't forget set matrix workDetail.SetMirror(bestResult.Mirror()); + + if (d->saveLength) + { + d->globalContour.CeateEmptySheetContour(); + } + const QVector newGContour = d->globalContour.UniteWithContour(workDetail, bestResult.GContourEdge(), bestResult.DetailEdge(), bestResult.Type()); diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 80724885d..de20dcd45 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -50,7 +50,7 @@ class VLayoutPaper { public: VLayoutPaper(); - VLayoutPaper(int height, int width); + VLayoutPaper(int height, int width, qreal layoutWidth); VLayoutPaper(const VLayoutPaper &paper); ~VLayoutPaper(); diff --git a/src/libs/vlayout/vlayoutpaper_p.h b/src/libs/vlayout/vlayoutpaper_p.h index c9d9a0939..4e3d12389 100644 --- a/src/libs/vlayout/vlayoutpaper_p.h +++ b/src/libs/vlayout/vlayoutpaper_p.h @@ -46,19 +46,9 @@ public: VLayoutPaperData() {} - VLayoutPaperData(int height, - int width) - : details(QVector()), - globalContour(VContour(height, width)), - paperIndex(0), - frame(0), - layoutWidth(0), - globalRotate(true), - localRotate(true), - globalRotationIncrease(180), - localRotationIncrease(180), - saveLength(false), - followGrainline(false) + VLayoutPaperData(int height, int width, qreal layoutWidth) + : globalContour(VContour(height, width, layoutWidth)), + layoutWidth(layoutWidth) {} VLayoutPaperData(const VLayoutPaperData &paper) diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index ed8ac759a..a749e2116 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -307,6 +307,11 @@ int VPosition::Bias(int length, int maxLength) void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, BestFrom type) { + if (bestResult.IsSaveLength()) + { + m_data.gContour.CeateEmptySheetContour(); + } + QVector newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type); newGContour.append(newGContour.first()); const QSizeF size = QPolygonF(newGContour).boundingRect().size();