Save each frame to png file for debuging creation layout.
--HG-- branch : feature
This commit is contained in:
parent
789dcea6bc
commit
166f2fbcdb
|
@ -1923,7 +1923,7 @@ void MainWindow::ActionLayout(bool checked)
|
|||
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern));
|
||||
det.setSeamAllowance(idetail.value().getSeamAllowance());
|
||||
det.setName(idetail.value().getName());
|
||||
det.SetLayoutAllowencePoints();
|
||||
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
|
||||
|
||||
listDetails.append(det);
|
||||
}
|
||||
|
|
|
@ -40,4 +40,12 @@ enum class LayoutErrors : char
|
|||
EmptyPaperError
|
||||
};
|
||||
|
||||
#define LAYOUT_DEBUG // Enable debug mode
|
||||
|
||||
#ifdef LAYOUT_DEBUG
|
||||
# define SHOW_VERTICES // Show contour vertices
|
||||
# define SHOW_DIRECTION // Show contour direction
|
||||
# define ARRANGED_DETAILS // Show already arranged details
|
||||
#endif//LAYOUT_DEBUG
|
||||
|
||||
#endif // VLAYOUTDEF_H
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "vlayoutdetail.h"
|
||||
#include "vlayoutdetail_p.h"
|
||||
|
||||
#include <QPainterPath>
|
||||
#include <QtMath>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -316,3 +317,43 @@ QVector<QPointF> VLayoutDetail::Map(const QVector<QPointF> &points) const
|
|||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPainterPath VLayoutDetail::ContourPath() const
|
||||
{
|
||||
QPainterPath path;
|
||||
|
||||
// contour
|
||||
path.moveTo(d->contour[0]);
|
||||
for (qint32 i = 1; i < d->contour.count(); ++i)
|
||||
{
|
||||
path.lineTo(d->contour.at(i));
|
||||
}
|
||||
path.lineTo(d->contour.at(0));
|
||||
|
||||
// seam allowence
|
||||
if (getSeamAllowance() == true)
|
||||
{
|
||||
QPainterPath ekv;
|
||||
QVector<QPointF> p;
|
||||
if (getClosed() == true)
|
||||
{
|
||||
p = Equidistant(d->seamAllowence, EquidistantType::CloseEquidistant, getWidth());
|
||||
}
|
||||
else
|
||||
{
|
||||
p = Equidistant(d->seamAllowence, EquidistantType::OpenEquidistant, getWidth());
|
||||
}
|
||||
|
||||
ekv.moveTo(p.at(0));
|
||||
for (qint32 i = 1; i < p.count(); ++i)
|
||||
{
|
||||
ekv.lineTo(p.at(i));
|
||||
}
|
||||
|
||||
path.addPath(ekv);
|
||||
path.setFillRule(Qt::WindingFill);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
|
||||
bool isNull() const;
|
||||
qint64 Square() const;
|
||||
QPainterPath ContourPath() const;
|
||||
|
||||
private:
|
||||
QSharedDataPointer<VLayoutDetailData> d;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include "vlayoutdetail.h"
|
||||
|
||||
#include <QRectF>
|
||||
#include <QImage>
|
||||
#include <QDir>
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VLayoutGenerator::VLayoutGenerator(QObject *parent)
|
||||
|
@ -74,6 +76,14 @@ void VLayoutGenerator::Generate()
|
|||
stopGeneration = false;
|
||||
papers.clear();
|
||||
state = LayoutErrors::NoError;
|
||||
|
||||
#ifdef LAYOUT_DEBUG
|
||||
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug");
|
||||
QDir debugDir(path);
|
||||
debugDir.removeRecursively();
|
||||
debugDir.mkpath(path);
|
||||
#endif
|
||||
|
||||
emit Start();
|
||||
|
||||
if (bank->Prepare())
|
||||
|
@ -89,6 +99,7 @@ void VLayoutGenerator::Generate()
|
|||
|
||||
VLayoutPaper paper(paperHeight, paperWidth);
|
||||
paper.SetShift(shift);
|
||||
paper.SetPaperIndex(papers.count());
|
||||
if (bank->LeftArrange() > 0)
|
||||
{
|
||||
const int index = bank->GetTiket();
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
#include <climits>
|
||||
#include <QPointF>
|
||||
#include <QtMath>
|
||||
#include <QImage>
|
||||
#include <QDir>
|
||||
#include <QPainter>
|
||||
|
||||
class BestResult
|
||||
{
|
||||
|
@ -171,6 +174,12 @@ void VLayoutPaper::SetShift(unsigned int shift)
|
|||
d->shift = shift;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VLayoutPaper::SetPaperIndex(quint32 index)
|
||||
{
|
||||
d->paperIndex = index;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail)
|
||||
{
|
||||
|
@ -185,6 +194,8 @@ bool VLayoutPaper::ArrangeDetail(const VLayoutDetail &detail)
|
|||
return false;//Not enough edges
|
||||
}
|
||||
|
||||
d->frame = 0;
|
||||
|
||||
if (Count() == 0)
|
||||
{
|
||||
return AddToBlankSheet(detail);
|
||||
|
@ -223,6 +234,7 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail)
|
|||
workDetail.GetMatrix());
|
||||
}
|
||||
}
|
||||
++d->frame;
|
||||
|
||||
for (int angle = 0; angle < 360; ++angle)
|
||||
{
|
||||
|
@ -238,6 +250,7 @@ bool VLayoutPaper::AddToBlankSheet(const VLayoutDetail &detail)
|
|||
workDetail.GetMatrix());
|
||||
}
|
||||
}
|
||||
++d->frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -273,6 +286,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail)
|
|||
continue; // Outside of sheet.
|
||||
}
|
||||
}
|
||||
++d->frame;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,6 +302,10 @@ bool VLayoutPaper::CheckCombineEdges(VLayoutDetail &detail, int j, int &dEdge) c
|
|||
|
||||
CombineEdges(detail, globalEdge, dEdge);
|
||||
|
||||
#ifdef LAYOUT_DEBUG
|
||||
DrawDebug(detail);
|
||||
#endif
|
||||
|
||||
switch (Crossing(detail, j, dEdge))
|
||||
{
|
||||
case CrossingType::EdgeError:
|
||||
|
@ -363,6 +381,10 @@ bool VLayoutPaper::CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, i
|
|||
|
||||
RotateEdges(detail, globalEdge, dEdge, angle);
|
||||
|
||||
#ifdef LAYOUT_DEBUG
|
||||
DrawDebug(detail);
|
||||
#endif
|
||||
|
||||
switch (Crossing(detail, j, dEdge))
|
||||
{
|
||||
case CrossingType::EdgeError:
|
||||
|
@ -735,3 +757,103 @@ bool VLayoutPaper::SaveResult(const BestResult &bestResult, const VLayoutDetail
|
|||
|
||||
return bestResult.ValideResult(); // Do we have the best result?
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VLayoutPaper::DrawDebug(const VLayoutDetail &detail) const
|
||||
{
|
||||
QImage frameImage ( d->paperWidth, d->paperHeight, QImage::Format_RGB32 );
|
||||
frameImage.fill(Qt::white);
|
||||
QPainter paint;
|
||||
paint.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
|
||||
paint.begin(&frameImage);
|
||||
|
||||
if (d->globalContour.isEmpty())
|
||||
{
|
||||
paint.drawPath(DrawContour(CutEdge(QLineF(0, 0, d->paperWidth, 0))));
|
||||
}
|
||||
else
|
||||
{
|
||||
paint.drawPath(DrawContour(d->globalContour));
|
||||
}
|
||||
|
||||
paint.setPen(QPen(Qt::darkGreen, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
|
||||
paint.drawPath(DrawContour(detail.GetLayoutAllowencePoints()));
|
||||
|
||||
#ifdef ARRANGED_DETAILS
|
||||
paint.setPen(QPen(Qt::blue, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
|
||||
paint.drawPath(DrawDetails());
|
||||
#endif
|
||||
|
||||
paint.end();
|
||||
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug/")+QString("%1_%2.png").arg(d->paperIndex)
|
||||
.arg(d->frame);
|
||||
frameImage.save (path);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPainterPath VLayoutPaper::ShowDirection(const QLineF &edge) const
|
||||
{
|
||||
QLineF arrow = edge;
|
||||
arrow.setLength(edge.length()/2.0);
|
||||
|
||||
//Reverse line because we want start arrow from this point
|
||||
arrow = QLineF(arrow.p2(), arrow.p1());
|
||||
const qreal angle = arrow.angle();//we each time change line angle, better save original angle value
|
||||
arrow.setLength(14);//arrow length in pixels
|
||||
|
||||
QPainterPath path;
|
||||
arrow.setAngle(angle-35);
|
||||
path.moveTo(arrow.p1());
|
||||
path.lineTo(arrow.p2());
|
||||
|
||||
arrow.setAngle(angle+35);
|
||||
path.moveTo(arrow.p1());
|
||||
path.lineTo(arrow.p2());
|
||||
return path;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPainterPath VLayoutPaper::DrawContour(const QVector<QPointF> &points) const
|
||||
{
|
||||
QPainterPath path;
|
||||
path.setFillRule(Qt::WindingFill);
|
||||
if (points.count() >= 2)
|
||||
{
|
||||
for (qint32 i = 0; i < points.count()-1; ++i)
|
||||
{
|
||||
path.moveTo(points.at(i));
|
||||
path.lineTo(points.at(i+1));
|
||||
}
|
||||
path.lineTo(points.at(0));
|
||||
|
||||
#ifdef SHOW_DIRECTION
|
||||
for (qint32 i = 0; i < points.count()-1; ++i)
|
||||
{
|
||||
path.addPath(ShowDirection(QLineF(points.at(i), points.at(i+1))));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SHOW_VERTICES
|
||||
for (qint32 i = 0; i < points.count(); ++i)
|
||||
{
|
||||
path.addRect(points.at(i).x()-3, points.at(i).y()-3, 6, 6);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
QPainterPath VLayoutPaper::DrawDetails() const
|
||||
{
|
||||
QPainterPath path;
|
||||
path.setFillRule(Qt::WindingFill);
|
||||
if (Count() > 0)
|
||||
{
|
||||
for (int i = 0; i < d->details.size(); ++i)
|
||||
{
|
||||
path.addPath(d->details.at(i).ContourPath());
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class QPointF;
|
|||
class QLineF;
|
||||
class QPolygonF;
|
||||
class BestResult;
|
||||
class QPainterPath;
|
||||
|
||||
class VLayoutPaper
|
||||
{
|
||||
|
@ -56,6 +57,8 @@ public:
|
|||
unsigned int GetShift() const;
|
||||
void SetShift(unsigned int shift);
|
||||
|
||||
void SetPaperIndex(quint32 index);
|
||||
|
||||
bool ArrangeDetail(const VLayoutDetail &detail);
|
||||
int Count() const;
|
||||
private:
|
||||
|
@ -98,6 +101,11 @@ private:
|
|||
QVector<QPointF> CutEdge(const QLineF &edge) const;
|
||||
|
||||
bool SaveResult(const BestResult &bestResult, const VLayoutDetail &detail);
|
||||
|
||||
void DrawDebug(const VLayoutDetail &detail) const;
|
||||
QPainterPath ShowDirection(const QLineF &edge) const;
|
||||
QPainterPath DrawContour(const QVector<QPointF> &points) const;
|
||||
QPainterPath DrawDetails() const;
|
||||
};
|
||||
|
||||
#endif // VLAYOUTPAPER_H
|
||||
|
|
|
@ -44,17 +44,18 @@ class VLayoutPaperData : public QSharedData
|
|||
{
|
||||
public:
|
||||
VLayoutPaperData()
|
||||
:details(QVector<VLayoutDetail>()), globalContour(QVector<QPointF>()), paperHeight(0), paperWidth(0), shift(0)
|
||||
:details(QVector<VLayoutDetail>()), globalContour(QVector<QPointF>()), paperHeight(0), paperWidth(0), shift(0),
|
||||
paperIndex(0), frame(0)
|
||||
{}
|
||||
|
||||
VLayoutPaperData(int height, int width)
|
||||
:details(QVector<VLayoutDetail>()), globalContour(QVector<QPointF>()), paperHeight(height), paperWidth(width),
|
||||
shift(0)
|
||||
shift(0), paperIndex(0), frame(0)
|
||||
{}
|
||||
|
||||
VLayoutPaperData(const VLayoutPaperData &paper)
|
||||
:QSharedData(paper), details(paper.details), globalContour(paper.globalContour), paperHeight(paper.paperHeight),
|
||||
paperWidth(paper.paperWidth), shift(paper.shift)
|
||||
paperWidth(paper.paperWidth), shift(paper.shift), paperIndex(paper.paperIndex), frame(paper.frame)
|
||||
{}
|
||||
|
||||
~VLayoutPaperData() {}
|
||||
|
@ -72,6 +73,8 @@ public:
|
|||
int paperWidth;
|
||||
|
||||
unsigned int shift;
|
||||
quint32 paperIndex;
|
||||
quint32 frame;
|
||||
};
|
||||
|
||||
#ifdef Q_CC_GNU
|
||||
|
|
Loading…
Reference in New Issue
Block a user