56 #include <QCoreApplication>
57 #include <QGraphicsRectItem>
58 #include <QGraphicsScene>
65 #include <QThreadPool>
68 #include <QtAlgorithms>
76 #ifdef Q_COMPILER_RVALUE_REFS
81 { std::swap(d, paper.d); }
101 if ( &paper ==
this )
116 return d->globalContour.GetHeight();
122 d->globalContour.SetHeight(height);
128 return d->globalContour.GetWidth();
134 d->globalContour.SetWidth(width);
140 return d->layoutWidth;
148 d->layoutWidth = width;
155 return d->globalContour.GetShift();
161 d->globalContour.SetShift(shift);
167 return d->globalRotate;
173 d->globalRotate = value;
174 d->localRotate =
d->globalRotate;
180 return d->globalRotationIncrease;
186 d->globalRotationIncrease = value;
188 if ((
d->globalRotationIncrease >= 1
189 &&
d->globalRotationIncrease <= 180
190 && 360 %
d->globalRotationIncrease == 0) ==
false)
192 d->globalRotationIncrease = 180;
195 d->localRotationIncrease =
d->globalRotationIncrease;
201 return d->saveLength;
207 d->saveLength = value;
213 d->paperIndex = index;
220 if (
d->globalContour.GetHeight() <= 0 ||
d->globalContour.GetWidth() <= 0)
232 d->localRotate =
true;
233 d->localRotationIncrease = 180;
237 d->localRotate =
d->globalRotate;
238 d->localRotationIncrease =
d->globalRotationIncrease;
249 return d->pieces.count();
255 VBestSquare bestResult(
d->globalContour.GetSize(),
d->saveLength);
256 QThreadPool *thread_pool = QThreadPool::globalInstance();
257 thread_pool->setExpiryTimeout(1000);
260 int pieceEdgesCount = 0;
262 if (
d->globalContour.GetContour().isEmpty())
271 for (
int j=1; j <=
d->globalContour.GlobalEdgesCount(); ++j)
273 for (
int i=1; i<= pieceEdgesCount; ++i)
276 d->localRotationIncrease,
286 thread->setAutoDelete(
false);
287 threads.append(thread);
288 thread_pool->start(thread);
290 d->frame =
d->frame + 3 +
static_cast<quint32
>(360/
d->localRotationIncrease*2);
297 QCoreApplication::processEvents();
298 QThread::msleep(250);
300 while(thread_pool->activeThreadCount() > 0 && not stop.load());
304 qDeleteAll(threads.begin(), threads.end());
309 for (
int i=0; i < threads.size(); ++i)
311 bestResult.
NewResult(threads.at(i)->getBestResult());
314 qDeleteAll(threads.begin(), threads.end());
331 if (newGContour.isEmpty())
335 d->pieces.append(workDetail);
336 d->globalContour.SetContour(newGContour);
351 QGraphicsRectItem *paper;
354 QScopedPointer<QGraphicsScene> scene(
new QGraphicsScene());
356 for (
int i=0; i < list.size(); ++i)
358 scene->addItem(list.at(i));
360 const int height = scene->itemsBoundingRect().toRect().height();
361 if (
d->globalContour.GetHeight() > height)
363 paper =
new QGraphicsRectItem(QRectF(0, 0,
d->globalContour.GetWidth(), height));
367 paper =
new QGraphicsRectItem(QRectF(0, 0,
d->globalContour.GetWidth(),
d->globalContour.GetHeight()));
372 paper =
new QGraphicsRectItem(QRectF(0, 0,
d->globalContour.GetWidth(),
d->globalContour.GetHeight()));
374 paper->setPen(QPen(Qt::black, 1));
375 paper->setBrush(QBrush(Qt::white));
383 for (
int i=0; i <
d->pieces.count(); ++i)
385 list.append(
d->pieces.at(i).GetItem(textAsPaths));
399 d->pieces = pieces.toVector();
406 for (
int i=0; i <
d->pieces.count(); ++i)
408 rec = rec.united(
d->pieces.at(i).pieceBoundingRect());
bool IsForbidFlipping() const
QTransform Transform() const
void NewResult(const QSizeF &candidate, int i, int j, const QTransform &transform, bool mirror, BestFrom type)
VLayoutPaper & operator=(const VLayoutPaper &paper)
bool arrangePiece(const VLayoutPiece &piece, std::atomic_bool &stop)
void setPieces(const QList< VLayoutPiece > &pieces)
bool SaveResult(const VBestSquare &bestResult, const VLayoutPiece &piece)
void SetRotationIncrease(int value)
void Swap(VLayoutPaper &paper) Q_DECL_NOTHROW
void SetShift(quint32 shift)
QRectF piecesBoundingRect() const
void SetSaveLength(bool value)
void SetRotate(bool value)
QVector< VLayoutPiece > getPieces() const
void SetHeight(int height)
void SetPaperIndex(quint32 index)
bool AddToSheet(const VLayoutPiece &piece, std::atomic_bool &stop)
int GetRotationIncrease() const
void SetLayoutWidth(qreal width)
Q_REQUIRED_RESULT QList< QGraphicsItem * > getPieceItems(bool textAsPaths) const
bool IsSaveLength() const
qreal GetLayoutWidth() const
Q_REQUIRED_RESULT QGraphicsRectItem * GetPaperItem(bool autoCrop, bool textAsPaths) const
QSharedDataPointer< VLayoutPaperData > d
int pieceEdgesCount() const
int LayoutEdgesCount() const
void setTransform(const QTransform &transform)
void SetMirror(bool value)
static void DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex, int piecesCount, const QVector< VLayoutPiece > &pieces=QVector< VLayoutPiece >())
void setPieces(const QVector< VLayoutPiece > &pieces)
void setFrame(const quint32 &value)
void setPaperIndex(const quint32 &value)
void setPieceCount(const quint32 &value)