2015-01-10 14:47:46 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vlayoutpaper.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 7 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-01-10 14:47:46 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-01-10 14:47:46 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vlayoutpaper.h"
|
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QBrush>
|
2015-01-16 13:54:37 +01:00
|
|
|
#include <QCoreApplication>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QGraphicsRectItem>
|
2015-05-02 18:21:47 +02:00
|
|
|
#include <QGraphicsScene>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPointF>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QRectF>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QThreadPool>
|
|
|
|
#include <QVector>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtAlgorithms>
|
|
|
|
|
|
|
|
#include "vbestsquare.h"
|
|
|
|
#include "vcontour.h"
|
2017-01-22 10:02:02 +01:00
|
|
|
#include "vlayoutpiece.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vlayoutpaper_p.h"
|
|
|
|
#include "vposition.h"
|
2019-06-24 11:14:10 +02:00
|
|
|
#include "../ifc/exception/vexceptionterminatedposition.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2015-01-10 14:47:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutPaper::VLayoutPaper()
|
|
|
|
:d(new VLayoutPaperData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 08:03:19 +01:00
|
|
|
VLayoutPaper::VLayoutPaper(int height, int width, qreal layoutWidth)
|
|
|
|
:d(new VLayoutPaperData(height, width, layoutWidth))
|
2015-01-10 14:47:46 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutPaper::VLayoutPaper(const VLayoutPaper &paper)
|
|
|
|
:d (paper.d)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutPaper &VLayoutPaper::operator=(const VLayoutPaper &paper)
|
|
|
|
{
|
|
|
|
if ( &paper == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
d = paper.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
VLayoutPaper::VLayoutPaper(const VLayoutPaper &&paper) Q_DECL_NOTHROW
|
|
|
|
:d (paper.d)
|
|
|
|
{}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
VLayoutPaper &VLayoutPaper::operator=(VLayoutPaper &&paper) Q_DECL_NOTHROW
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
|
|
|
std::swap(d, paper.d);
|
2019-12-30 16:13:18 +01:00
|
|
|
return *this;
|
2019-12-30 12:00:57 +01:00
|
|
|
}
|
2019-12-30 16:13:18 +01:00
|
|
|
#endif
|
2019-12-30 12:00:57 +01:00
|
|
|
|
2015-01-10 14:47:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutPaper::~VLayoutPaper()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutPaper::GetHeight() const
|
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
return d->globalContour.GetHeight();
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetHeight(int height)
|
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
d->globalContour.SetHeight(height);
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutPaper::GetWidth() const
|
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
return d->globalContour.GetWidth();
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetWidth(int width)
|
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
d->globalContour.SetWidth(width);
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-17 15:00:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutPaper::GetLayoutWidth() const
|
|
|
|
{
|
|
|
|
return d->layoutWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetLayoutWidth(qreal width)
|
|
|
|
{
|
|
|
|
if (width >= 0)
|
|
|
|
{
|
|
|
|
d->layoutWidth = width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 16:23:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
qreal VLayoutPaper::GetShift() const
|
2015-01-12 16:23:25 +01:00
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
return d->globalContour.GetShift();
|
2015-01-12 16:23:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
void VLayoutPaper::SetShift(qreal shift)
|
2015-01-12 16:23:25 +01:00
|
|
|
{
|
2015-01-21 19:56:59 +01:00
|
|
|
d->globalContour.SetShift(shift);
|
2015-01-12 16:23:25 +01:00
|
|
|
}
|
|
|
|
|
2015-01-22 15:11:50 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPaper::GetRotate() const
|
|
|
|
{
|
2016-09-06 15:00:25 +02:00
|
|
|
return d->globalRotate;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetRotate(bool value)
|
|
|
|
{
|
2016-09-06 15:00:25 +02:00
|
|
|
d->globalRotate = value;
|
|
|
|
d->localRotate = d->globalRotate;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPaper::GetFollowGrainline() const
|
|
|
|
{
|
|
|
|
return d->followGrainline;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetFollowGrainline(bool value)
|
|
|
|
{
|
|
|
|
d->followGrainline = value;
|
|
|
|
}
|
|
|
|
|
2015-01-22 15:11:50 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
int VLayoutPaper::GetRotationNumber() const
|
2015-01-22 15:11:50 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
return d->globalRotationNumber;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-29 18:52:37 +01:00
|
|
|
void VLayoutPaper::SetRotationNumber(int value)
|
2015-01-22 15:11:50 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
d->globalRotationNumber = value;
|
2015-01-22 15:11:50 +01:00
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
if (d->globalRotationNumber > 360 || d->globalRotationNumber < 1)
|
2015-01-22 15:11:50 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
d->globalRotationNumber = 2;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
2016-09-06 15:00:25 +02:00
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
d->localRotationNumber = d->globalRotationNumber;
|
2015-01-22 15:11:50 +01:00
|
|
|
}
|
|
|
|
|
2015-05-08 12:10:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPaper::IsSaveLength() const
|
|
|
|
{
|
|
|
|
return d->saveLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetSaveLength(bool value)
|
|
|
|
{
|
|
|
|
d->saveLength = value;
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:35:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetPaperIndex(quint32 index)
|
|
|
|
{
|
|
|
|
d->paperIndex = index;
|
|
|
|
}
|
|
|
|
|
2019-06-18 13:28:16 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPaper::IsOriginPaperPortrait() const
|
|
|
|
{
|
|
|
|
return d->originPaperOrientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPaper::SetOriginPaperPortrait(bool portrait)
|
|
|
|
{
|
|
|
|
d->originPaperOrientation = portrait;
|
|
|
|
}
|
|
|
|
|
2015-01-10 14:47:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-22 13:04:47 +01:00
|
|
|
bool VLayoutPaper::ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2016-12-10 17:38:34 +01:00
|
|
|
if (detail.LayoutEdgesCount() < 3 || detail.DetailEdgesCount() < 3)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
|
|
|
return false;//Not enough edges
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:06:46 +01:00
|
|
|
if ((detail.IsForceFlipping() || detail.IsForbidFlipping()) && not d->globalRotate)
|
2016-09-06 15:00:25 +02:00
|
|
|
{ // Compensate forbidden flipping by rotating. 180 degree will be enough.
|
|
|
|
d->localRotate = true;
|
2019-03-29 18:52:37 +01:00
|
|
|
d->localRotationNumber = 2;
|
2016-09-06 15:00:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Return to global values if was changed
|
|
|
|
d->localRotate = d->globalRotate;
|
2019-03-29 18:52:37 +01:00
|
|
|
d->localRotationNumber = d->globalRotationNumber;
|
2016-09-06 15:00:25 +02:00
|
|
|
}
|
|
|
|
|
2019-06-18 14:10:08 +02:00
|
|
|
VPositionData data;
|
|
|
|
data.gContour = d->globalContour;
|
|
|
|
data.detail = detail;
|
|
|
|
data.rotate = d->localRotate;
|
|
|
|
data.rotationNumber = d->localRotationNumber;
|
|
|
|
data.followGrainline = d->followGrainline;
|
|
|
|
data.positionsCache = d->positionsCache;
|
|
|
|
data.isOriginPaperOrientationPortrait = d->originPaperOrientation;
|
|
|
|
|
|
|
|
const VBestSquare result = VPosition::ArrangeDetail(data, &stop, d->saveLength);
|
|
|
|
return SaveResult(result, detail);
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutPaper::Count() const
|
|
|
|
{
|
|
|
|
return d->details.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece &detail)
|
2015-01-12 16:23:25 +01:00
|
|
|
{
|
2019-03-27 08:31:02 +01:00
|
|
|
if (bestResult.HasValidResult())
|
2015-01-12 16:23:25 +01:00
|
|
|
{
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece workDetail = detail;
|
2015-01-12 16:23:25 +01:00
|
|
|
workDetail.SetMatrix(bestResult.Matrix());// Don't forget set matrix
|
2015-01-18 19:56:01 +01:00
|
|
|
workDetail.SetMirror(bestResult.Mirror());
|
2019-03-27 08:03:19 +01:00
|
|
|
|
|
|
|
if (d->saveLength)
|
|
|
|
{
|
|
|
|
d->globalContour.CeateEmptySheetContour();
|
|
|
|
}
|
|
|
|
|
2015-01-21 19:56:59 +01:00
|
|
|
const QVector<QPointF> newGContour = d->globalContour.UniteWithContour(workDetail, bestResult.GContourEdge(),
|
|
|
|
bestResult.DetailEdge(),
|
|
|
|
bestResult.Type());
|
2015-01-12 16:23:25 +01:00
|
|
|
if (newGContour.isEmpty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
d->details.append(workDetail);
|
2015-01-21 19:56:59 +01:00
|
|
|
d->globalContour.SetContour(newGContour);
|
2019-07-22 15:42:37 +02:00
|
|
|
|
|
|
|
VCachedPositions positionChache;
|
|
|
|
QVector<QPointF> layoutPoints = workDetail.GetLayoutAllowancePoints();
|
|
|
|
positionChache.boundingRect = VLayoutPiece::BoundingRect(layoutPoints);
|
|
|
|
positionChache.layoutAllowancePath = VLayoutPiece::PainterPath(layoutPoints);
|
|
|
|
d->positionsCache.append(positionChache);
|
2015-01-12 16:23:25 +01:00
|
|
|
}
|
2019-06-24 11:14:10 +02:00
|
|
|
else if (bestResult.IsTerminatedByException())
|
|
|
|
{
|
|
|
|
throw VExceptionTerminatedPosition(bestResult.ReasonTerminatedByException());
|
|
|
|
}
|
2015-01-12 16:23:25 +01:00
|
|
|
|
2019-03-27 08:31:02 +01:00
|
|
|
return bestResult.HasValidResult(); // Do we have the best result?
|
2015-01-12 16:23:25 +01:00
|
|
|
}
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-10-16 10:16:16 +02:00
|
|
|
QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCropLength, bool autoCropWidth, bool textAsPaths) const
|
2015-01-13 11:38:51 +01:00
|
|
|
{
|
2019-10-16 10:16:16 +02:00
|
|
|
int height = d->globalContour.GetHeight();
|
|
|
|
int width = d->globalContour.GetWidth();
|
|
|
|
|
|
|
|
if (autoCropLength || autoCropWidth)
|
2015-05-02 18:21:47 +02:00
|
|
|
{
|
2016-12-10 17:38:34 +01:00
|
|
|
QScopedPointer<QGraphicsScene> scene(new QGraphicsScene());
|
2017-07-01 19:32:54 +02:00
|
|
|
QList<QGraphicsItem *> list = GetItemDetails(textAsPaths);
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto item : list)
|
2015-05-02 18:21:47 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
scene->addItem(item);
|
2015-05-02 18:21:47 +02:00
|
|
|
}
|
2019-01-03 18:35:04 +01:00
|
|
|
|
2019-03-12 18:45:27 +01:00
|
|
|
const QRect boundingRect = scene->itemsBoundingRect().toRect();
|
2019-10-16 10:16:16 +02:00
|
|
|
|
|
|
|
if (autoCropLength)
|
2015-05-02 18:21:47 +02:00
|
|
|
{
|
2019-10-16 10:16:16 +02:00
|
|
|
if (d->globalContour.IsPortrait())
|
|
|
|
{
|
|
|
|
height = boundingRect.height() + boundingRect.y() + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = boundingRect.width() + boundingRect.x() + 1;
|
|
|
|
}
|
2015-05-02 18:21:47 +02:00
|
|
|
}
|
2019-10-16 10:16:16 +02:00
|
|
|
|
|
|
|
if (autoCropWidth)
|
2015-05-02 18:21:47 +02:00
|
|
|
{
|
2019-10-16 10:16:16 +02:00
|
|
|
if (d->globalContour.IsPortrait())
|
|
|
|
{
|
|
|
|
width = boundingRect.width() + boundingRect.x() + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
height = boundingRect.height() + boundingRect.y() + 1;
|
|
|
|
}
|
2015-05-02 18:21:47 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-16 10:16:16 +02:00
|
|
|
|
|
|
|
auto *paper = new QGraphicsRectItem(QRectF(0, 0, width, height));
|
2015-01-13 11:38:51 +01:00
|
|
|
paper->setPen(QPen(Qt::black, 1));
|
|
|
|
paper->setBrush(QBrush(Qt::white));
|
2015-01-23 11:07:58 +01:00
|
|
|
return paper;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-27 09:29:59 +01:00
|
|
|
QGraphicsPathItem *VLayoutPaper::GetGlobalContour() const
|
|
|
|
{
|
|
|
|
// contour
|
|
|
|
const QVector<QPointF> points = d->globalContour.GetContour();
|
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
if (points.size() > 0)
|
|
|
|
{
|
|
|
|
path.moveTo(points.at(0));
|
|
|
|
for (auto point : points)
|
|
|
|
{
|
|
|
|
path.lineTo(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const qreal radius = 1;
|
|
|
|
for (auto point : points)
|
|
|
|
{
|
|
|
|
path.addEllipse(point.x()-radius, point.y()-radius, radius*2, radius*2);
|
|
|
|
}
|
|
|
|
|
2019-07-21 09:33:25 +02:00
|
|
|
for (int i=0; i < points.size()-1; ++i)
|
|
|
|
{
|
|
|
|
QLineF line(points.at(i), points.at(i+1));
|
|
|
|
line.setLength(line.length()/2);
|
|
|
|
|
|
|
|
path.moveTo(line.p2());
|
|
|
|
QLineF side1(line.p2(), line.p1());
|
|
|
|
side1.setAngle(side1.angle()+35);
|
|
|
|
side1.setLength(3);
|
|
|
|
path.lineTo(side1.p2());
|
|
|
|
|
|
|
|
path.moveTo(line.p2());
|
|
|
|
QLineF side2(line.p2(), line.p1());
|
|
|
|
side2.setAngle(side2.angle()-35);
|
|
|
|
side2.setLength(3);
|
|
|
|
path.lineTo(side2.p2());
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsPathItem *item = new QGraphicsPathItem(path);
|
|
|
|
QPen pen = item->pen();
|
|
|
|
pen.setWidthF(0.25);
|
|
|
|
item->setPen(pen);
|
|
|
|
|
|
|
|
return item;
|
2019-03-27 09:29:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-07-01 19:32:54 +02:00
|
|
|
QList<QGraphicsItem *> VLayoutPaper::GetItemDetails(bool textAsPaths) const
|
2015-01-23 11:07:58 +01:00
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> list;
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &detail : d->details)
|
2015-01-13 11:38:51 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
list.append(detail.GetItem(textAsPaths));
|
2015-01-13 11:38:51 +01:00
|
|
|
}
|
2015-01-23 11:07:58 +01:00
|
|
|
return list;
|
2015-01-13 11:38:51 +01:00
|
|
|
}
|
2016-02-23 13:13:10 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<VLayoutPiece> VLayoutPaper::GetDetails() const
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
|
|
|
return d->details;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPaper::SetDetails(const QList<VLayoutPiece> &details)
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
|
|
|
d->details = details.toVector();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-12-10 17:38:34 +01:00
|
|
|
QRectF VLayoutPaper::DetailsBoundingRect() const
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
|
|
|
QRectF rec;
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &detail : d->details)
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
rec = rec.united(detail.DetailBoundingRect());
|
2016-02-23 13:13:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
}
|
2019-03-29 18:52:37 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutPaper::Efficiency() const
|
|
|
|
{
|
|
|
|
qreal efficiency = 0;
|
|
|
|
for(auto &detail : d->details)
|
|
|
|
{
|
2019-03-30 10:17:54 +01:00
|
|
|
efficiency += static_cast<qreal>(detail.Square());
|
2019-03-29 18:52:37 +01:00
|
|
|
}
|
|
|
|
|
2019-03-30 10:17:54 +01:00
|
|
|
const QRectF boundingRect = DetailsBoundingRect();
|
|
|
|
|
|
|
|
return efficiency / (boundingRect.width() * boundingRect.height()) * 100.0;
|
2019-03-29 18:52:37 +01:00
|
|
|
}
|