59 #include <QPainterPath>
67 #include <QStaticStringData>
69 #include <QStringData>
70 #include <QStringDataPtr>
73 #include "../vmisc/def.h"
74 #include "../vmisc/vmath.h"
78 bool rotate,
int rotationIncrease,
bool saveLength)
80 bestResult(
VBestSquare(gContour.GetSize(), saveLength)),
91 rotationIncrease(rotationIncrease),
96 this->rotationIncrease = 180;
115 # ifdef SHOW_CANDIDATE_BEST
197 paint.begin(&picture);
199 paint.setPen(QPen(Qt::black, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
204 path.translate(biasWidth/2, biasHeight/2);
205 paint.drawPath(path);
210 path.translate(biasWidth/2, biasHeight/2);
211 paint.drawPath(path);
214 #ifdef SHOW_CANDIDATE
215 paint.setPen(QPen(Qt::darkGreen, 6, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
217 path.translate(biasWidth/2, biasHeight/2);
218 paint.drawPath(path);
224 #ifdef ARRANGED_PIECES
225 paint.setPen(QPen(Qt::blue, 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
227 path.translate(biasWidth/2, biasHeight/2);
228 paint.drawPath(path);
234 const QRect pictureRect = picture.boundingRect();
238 paint.setPen(QPen(Qt::darkRed, 15, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
239 paint.drawRect(QRectF(biasWidth/2, biasHeight/2, contour.
GetWidth(), contour.
GetHeight()));
247 QImage frameImage(pictureRect.width()+biasWidth, pictureRect.height()+biasHeight, QImage::Format_RGB32);
249 if (frameImage.isNull())
254 frameImage.fill(Qt::white);
256 QPainter paintFrameImage;
257 paintFrameImage.begin(&frameImage);
258 paintFrameImage.drawPicture(0, 0, picture);
259 paintFrameImage.end();
261 const QString fileName = QDir::homePath()+QStringLiteral(
"/LayoutDebug/")+QString(
"%1_%2_%3.png").arg(
paperIndex)
263 frameImage.save (fileName);
269 if (length < maxLength && length*2 < maxLength)
275 return maxLength-length;
284 newGContour.append(newGContour.first());
285 const QSizeF size = QPolygonF(newGContour).boundingRect().size();
293 bool flagMirror =
false;
294 bool flagSquare =
false;
381 bool flagSquare =
false;
438 return bRect.contains(rect);
455 const qreal dx = globalEdge.x2() - pieceEdge.x2();
456 const qreal dy = globalEdge.y2() - pieceEdge.y2();
458 pieceEdge.translate(dx, dy);
484 const qreal dx = globalEdge.x2() - pieceEdge.x2();
485 const qreal dy = globalEdge.y2() - pieceEdge.y2();
487 pieceEdge.translate(dx, dy);
500 startAngle = increase;
502 for (
int angle = startAngle; angle < 360; angle = angle+increase)
515 # ifdef SHOW_CANDIDATE_BEST
530 const int arrowLength = 14;
532 if (edge.length()/arrowLength < 5)
538 arrow.setLength(edge.length()/2.0);
541 arrow = QLineF(arrow.p2(), arrow.p1());
542 const qreal angle = arrow.angle();
543 arrow.setLength(arrowLength);
545 arrow.setAngle(angle-35);
546 path.moveTo(arrow.p1());
547 path.lineTo(arrow.p2());
549 arrow.setAngle(angle+35);
550 path.moveTo(arrow.p1());
551 path.lineTo(arrow.p2());
559 path.setFillRule(Qt::WindingFill);
560 if (points.count() >= 2)
562 for (qint32
i = 0;
i < points.count()-1; ++
i)
564 path.moveTo(points.at(
i));
565 path.lineTo(points.at(
i+1));
567 path.lineTo(points.at(0));
569 #ifdef SHOW_DIRECTION
570 for (qint32
i = 0;
i < points.count()-1; ++
i)
577 for (qint32
i = 0;
i < points.count(); ++
i)
579 path.addRect(points.at(
i).x()-3, points.at(
i).y()-3, 6, 6);
590 path.setFillRule(Qt::WindingFill);
595 path.addPath(
pieces.at(
i).createMainPath());
bool IsForbidFlipping() const
void NewResult(const QSizeF &candidate, int i, int j, const QTransform &transform, bool mirror, BestFrom type)
QPainterPath ContourPath() const
QRectF BoundingRect() const
QVector< QPointF > GetContour() const
QLineF GlobalEdge(int i) const
QVector< QPointF > CutEmptySheetEdge() const
QVector< QPointF > UniteWithContour(const VLayoutPiece &detail, int globalI, int detJ, BestFrom type) const
void Mirror(const QLineF &edge)
QTransform getTransform() const
QPainterPath createMainPath() const
QRectF LayoutBoundingRect() const
void Translate(qreal dx, qreal dy)
int pieceEdgeByPoint(const QPointF &p1) const
QRectF pieceBoundingRect() const
QLineF pieceEdge(int i) const
QVector< QPointF > getLayoutAllowancePoints() const
QLineF LayoutEdge(int i) const
int LayoutEdgeByPoint(const QPointF &p1) const
QPainterPath LayoutAllowancePath() const
void Rotate(const QPointF &originPoint, qreal degrees)
QVector< VLayoutPiece > pieces
qreal angle_between
angle_between keep angle between global edge and piece edge. Need for optimization rotation.
CrossingType Crossing(const VLayoutPiece &piece) const
static int Bias(int length, int maxLength)
VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, bool rotate, int rotationIncrease, bool saveLength)
static QPainterPath ShowDirection(const QLineF &edge)
void Rotate(int increase)
bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const
VBestSquare getBestResult() const
quint32 getPaperIndex() const
void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge)
static void DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex, int piecesCount, const QVector< VLayoutPiece > &pieces=QVector< VLayoutPiece >())
virtual void run() Q_DECL_OVERRIDE
static QPainterPath drawPieces(const QVector< VLayoutPiece > &pieces)
void setPieces(const QVector< VLayoutPiece > &pieces)
static QPainterPath DrawContour(const QVector< QPointF > &points)
void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const
void setFrame(const quint32 &value)
bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge)
bool SheetContains(const QRectF &rect) const
void setPaperIndex(const quint32 &value)
quint32 getPieceCount() const
void setPieceCount(const quint32 &value)
void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type)
static Q_REQUIRED_RESULT bool VFuzzyComparePossibleNulls(double p1, double p2)