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)
: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<QPointF> &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);
}

View file

@ -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<QPointF> &contour);
QVector<QPointF> GetContour() const;

View file

@ -31,6 +31,7 @@
#include <QSharedData>
#include <QPointF>
#include <QVector>
#include "../vmisc/diagnostic.h"
@ -42,30 +43,37 @@ class VContourData : public QSharedData
{
public:
VContourData()
:globalContour(QVector<QPointF>()), paperHeight(0), paperWidth(0), shift(0)
{}
VContourData(int height, int width)
:globalContour(QVector<QPointF>()), 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<QPointF> globalContour;
QVector<QPointF> 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;

View file

@ -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<quint32>(papers.count()));
paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);
@ -380,9 +379,8 @@ void VLayoutGenerator::GatherPages()
QVector<VLayoutPaper> 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<quint32>(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<quint32>(i));
paper.SetRotate(rotate);
paper.SetFollowGrainline(followGrainline);

View file

@ -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<VPosition *> 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<QPointF> newGContour = d->globalContour.UniteWithContour(workDetail, bestResult.GContourEdge(),
bestResult.DetailEdge(),
bestResult.Type());

View file

@ -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();

View file

@ -46,19 +46,9 @@ public:
VLayoutPaperData()
{}
VLayoutPaperData(int height,
int width)
: details(QVector<VLayoutPiece>()),
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)

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,
BestFrom type)
{
if (bestResult.IsSaveLength())
{
m_data.gContour.CeateEmptySheetContour();
}
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
newGContour.append(newGContour.first());
const QSizeF size = QPolygonF(newGContour).boundingRect().size();