If user selects SaveLength option add fake contour edge.

* * *
Fixing issue with pieces on edge.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-03-27 09:03:19 +02:00
parent ed23a4ee71
commit 63ea3bf2f9
8 changed files with 57 additions and 37 deletions

View File

@ -46,8 +46,8 @@ VContour::VContour()
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VContour::VContour(int height, int width) VContour::VContour(int height, int width, qreal layoutWidth)
:d(new VContourData(height, width)) :d(new VContourData(height, width, layoutWidth))
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -70,6 +70,16 @@ VContour &VContour::operator=(const VContour &contour)
VContour::~VContour() 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<QPointF> &contour) void VContour::SetContour(const QVector<QPointF> &contour)
{ {
@ -371,5 +381,8 @@ bool VContour::IsPortrait() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QLineF VContour::EmptySheetEdge() 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);
} }

View File

@ -48,7 +48,7 @@ class VContour
{ {
public: public:
VContour(); VContour();
VContour(int height, int width); VContour(int height, int width, qreal layoutWidth);
VContour(const VContour &contour); VContour(const VContour &contour);
~VContour(); ~VContour();
@ -61,6 +61,8 @@ public:
inline void Swap(VContour &contour) Q_DECL_NOTHROW inline void Swap(VContour &contour) Q_DECL_NOTHROW
{ std::swap(d, contour.d); } { std::swap(d, contour.d); }
void CeateEmptySheetContour();
void SetContour(const QVector<QPointF> &contour); void SetContour(const QVector<QPointF> &contour);
QVector<QPointF> GetContour() const; QVector<QPointF> GetContour() const;

View File

@ -31,6 +31,7 @@
#include <QSharedData> #include <QSharedData>
#include <QPointF> #include <QPointF>
#include <QVector>
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
@ -42,30 +43,37 @@ class VContourData : public QSharedData
{ {
public: public:
VContourData() VContourData()
:globalContour(QVector<QPointF>()), paperHeight(0), paperWidth(0), shift(0)
{} {}
VContourData(int height, int width) VContourData(int height, int width, qreal layoutWidth)
:globalContour(QVector<QPointF>()), paperHeight(height), paperWidth(width), shift(0) : paperHeight(height),
paperWidth(width),
layoutWidth(layoutWidth)
{} {}
VContourData(const VContourData &contour) VContourData(const VContourData &contour)
:QSharedData(contour), globalContour(contour.globalContour), paperHeight(contour.paperHeight), : QSharedData(contour),
paperWidth(contour.paperWidth), shift(contour.shift) globalContour(contour.globalContour),
paperHeight(contour.paperHeight),
paperWidth(contour.paperWidth),
shift(contour.shift),
layoutWidth(contour.layoutWidth)
{} {}
~VContourData() {} ~VContourData() {}
/** @brief globalContour list of global points contour. */ /** @brief globalContour list of global points contour. */
QVector<QPointF> globalContour; QVector<QPointF> globalContour{};
/** @brief paperHeight height of paper in pixels*/ /** @brief paperHeight height of paper in pixels*/
int paperHeight; int paperHeight{0};
/** @brief paperWidth width of paper in pixels*/ /** @brief paperWidth width of paper in pixels*/
int paperWidth; int paperWidth{0};
quint32 shift; quint32 shift{0};
qreal layoutWidth{0};
private: private:
VContourData &operator=(const VContourData &) Q_DECL_EQ_DELETE; VContourData &operator=(const VContourData &) Q_DECL_EQ_DELETE;

View File

@ -141,9 +141,8 @@ void VLayoutGenerator::Generate()
break; break;
} }
VLayoutPaper paper(height, width); VLayoutPaper paper(height, width, bank->GetLayoutWidth());
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(papers.count())); paper.SetPaperIndex(static_cast<quint32>(papers.count()));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline); paper.SetFollowGrainline(followGrainline);
@ -380,9 +379,8 @@ void VLayoutGenerator::GatherPages()
QVector<VLayoutPaper> nPapers; QVector<VLayoutPaper> nPapers;
for (int i = 0; i < nDetails.size(); ++i) for (int i = 0; i < nDetails.size(); ++i)
{ {
VLayoutPaper paper(PageHeight(), PageWidth()); VLayoutPaper paper(PageHeight(), PageWidth(), bank->GetLayoutWidth());
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(i)); paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline); paper.SetFollowGrainline(followGrainline);
@ -484,9 +482,8 @@ void VLayoutGenerator::UnitePages()
const int height = IsPortrait() ? qFloor(papersLength.at(i)) : PageHeight(); const int height = IsPortrait() ? qFloor(papersLength.at(i)) : PageHeight();
const int width = IsPortrait() ? PageWidth() : qFloor(papersLength.at(i)); const int width = IsPortrait() ? PageWidth() : qFloor(papersLength.at(i));
VLayoutPaper paper(height, width); VLayoutPaper paper(height, width, bank->GetLayoutWidth());
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(i)); paper.SetPaperIndex(static_cast<quint32>(i));
paper.SetRotate(rotate); paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline); paper.SetFollowGrainline(followGrainline);

View File

@ -55,8 +55,8 @@ VLayoutPaper::VLayoutPaper()
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPaper::VLayoutPaper(int height, int width) VLayoutPaper::VLayoutPaper(int height, int width, qreal layoutWidth)
:d(new VLayoutPaperData(height, width)) :d(new VLayoutPaperData(height, width, layoutWidth))
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -238,8 +238,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutPiece &detail, std::atomic_bool &stop
thread_pool->setExpiryTimeout(1000); thread_pool->setExpiryTimeout(1000);
QVector<VPosition *> threads; QVector<VPosition *> threads;
int detailEdgesCount = d->globalContour.GetContour().isEmpty() ? detail.DetailEdgesCount() : int detailEdgesCount = detail.LayoutEdgesCount();
detail.LayoutEdgesCount();
for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j) for (int j=1; j <= d->globalContour.GlobalEdgesCount(); ++j)
{ {
@ -307,6 +306,12 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece
VLayoutPiece workDetail = detail; VLayoutPiece workDetail = detail;
workDetail.SetMatrix(bestResult.Matrix());// Don't forget set matrix workDetail.SetMatrix(bestResult.Matrix());// Don't forget set matrix
workDetail.SetMirror(bestResult.Mirror()); workDetail.SetMirror(bestResult.Mirror());
if (d->saveLength)
{
d->globalContour.CeateEmptySheetContour();
}
const QVector<QPointF> newGContour = d->globalContour.UniteWithContour(workDetail, bestResult.GContourEdge(), const QVector<QPointF> newGContour = d->globalContour.UniteWithContour(workDetail, bestResult.GContourEdge(),
bestResult.DetailEdge(), bestResult.DetailEdge(),
bestResult.Type()); bestResult.Type());

View File

@ -50,7 +50,7 @@ class VLayoutPaper
{ {
public: public:
VLayoutPaper(); VLayoutPaper();
VLayoutPaper(int height, int width); VLayoutPaper(int height, int width, qreal layoutWidth);
VLayoutPaper(const VLayoutPaper &paper); VLayoutPaper(const VLayoutPaper &paper);
~VLayoutPaper(); ~VLayoutPaper();

View File

@ -46,19 +46,9 @@ public:
VLayoutPaperData() VLayoutPaperData()
{} {}
VLayoutPaperData(int height, VLayoutPaperData(int height, int width, qreal layoutWidth)
int width) : globalContour(VContour(height, width, layoutWidth)),
: details(QVector<VLayoutPiece>()), layoutWidth(layoutWidth)
globalContour(VContour(height, width)),
paperIndex(0),
frame(0),
layoutWidth(0),
globalRotate(true),
localRotate(true),
globalRotationIncrease(180),
localRotationIncrease(180),
saveLength(false),
followGrainline(false)
{} {}
VLayoutPaperData(const VLayoutPaperData &paper) VLayoutPaperData(const VLayoutPaperData &paper)

View File

@ -307,6 +307,11 @@ int VPosition::Bias(int length, int maxLength)
void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ, void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detail, int globalI, int detJ,
BestFrom type) BestFrom type)
{ {
if (bestResult.IsSaveLength())
{
m_data.gContour.CeateEmptySheetContour();
}
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type); QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
newGContour.append(newGContour.first()); newGContour.append(newGContour.first());
const QSizeF size = QPolygonF(newGContour).boundingRect().size(); const QSizeF size = QPolygonF(newGContour).boundingRect().size();