2015-01-02 15:14:28 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vlayoutdetail.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 2 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-02 15:14:28 +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
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-01-02 15:14:28 +01:00
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
2017-01-22 10:02:02 +01:00
|
|
|
#include "vlayoutpiece.h"
|
2015-01-02 15:14:28 +01:00
|
|
|
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QBrush>
|
|
|
|
#include <QFlags>
|
2016-07-18 20:38:27 +02:00
|
|
|
#include <QFont>
|
2016-07-19 02:26:50 +02:00
|
|
|
#include <QFontMetrics>
|
2018-01-21 21:00:07 +01:00
|
|
|
#include <QFuture>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
2016-08-08 13:44:49 +02:00
|
|
|
#include <QGraphicsPathItem>
|
|
|
|
#include <QList>
|
|
|
|
#include <QMatrix>
|
|
|
|
#include <QMessageLogger>
|
|
|
|
#include <QPainterPath>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QPolygonF>
|
|
|
|
#include <QTransform>
|
|
|
|
#include <Qt>
|
|
|
|
#include <QtDebug>
|
2020-04-22 13:32:25 +02:00
|
|
|
#include <QUuid>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2017-02-23 10:37:19 +01:00
|
|
|
#include "../vpatterndb/floatItemData/vpatternlabeldata.h"
|
|
|
|
#include "../vpatterndb/floatItemData/vpiecelabeldata.h"
|
2016-08-16 18:57:32 +02:00
|
|
|
#include "../vmisc/vmath.h"
|
2020-10-15 17:05:21 +02:00
|
|
|
#include "../vmisc/vabstractvalapplication.h"
|
2020-01-16 16:34:08 +01:00
|
|
|
#include "../vmisc/compatibility.h"
|
2019-07-22 16:06:30 +02:00
|
|
|
#include "../vpatterndb/vcontainer.h"
|
2016-10-16 11:38:08 +02:00
|
|
|
#include "../vpatterndb/calculator.h"
|
2019-05-27 13:57:36 +02:00
|
|
|
#include "../vpatterndb/vpassmark.h"
|
2019-06-18 13:28:16 +02:00
|
|
|
#include "../vpatterndb/vpiecenode.h"
|
2017-03-01 10:13:36 +01:00
|
|
|
#include "../vgeometry/vpointf.h"
|
2017-10-15 11:25:20 +02:00
|
|
|
#include "../vgeometry/vplacelabelitem.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vlayoutdef.h"
|
2017-01-22 10:02:02 +01:00
|
|
|
#include "vlayoutpiece_p.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
#include "vtextmanager.h"
|
2016-10-16 15:00:53 +02:00
|
|
|
#include "vgraphicsfillitem.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2019-07-01 10:02:09 +02:00
|
|
|
const quint32 VLayoutPieceData::streamHeader = 0x80D7D009; // CRC-32Q string "VLayoutPieceData"
|
2019-07-04 13:33:45 +02:00
|
|
|
const quint16 VLayoutPieceData::classVersion = 2;
|
2019-07-01 10:02:09 +02:00
|
|
|
|
2017-02-08 12:48:05 +01:00
|
|
|
namespace
|
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-08 12:48:05 +01:00
|
|
|
QVector<VLayoutPiecePath> ConvertInternalPaths(const VPiece &piece, const VContainer *pattern)
|
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
SCASSERT(pattern != nullptr)
|
|
|
|
|
2017-02-08 12:48:05 +01:00
|
|
|
QVector<VLayoutPiecePath> paths;
|
|
|
|
const QVector<quint32> pathsId = piece.GetInternalPaths();
|
2018-07-26 19:00:24 +02:00
|
|
|
const QVector<QPointF> cuttingPath = piece.CuttingPathPoints(pattern);
|
2019-10-28 13:52:49 +01:00
|
|
|
paths.reserve(pathsId.size());
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto id : pathsId)
|
2017-02-08 12:48:05 +01:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
const VPiecePath path = pattern->GetPiecePath(id);
|
2018-02-13 17:22:38 +01:00
|
|
|
if (path.GetType() == PiecePathType::InternalPath && path.IsVisible(pattern->DataVariables()))
|
2017-02-08 12:48:05 +01:00
|
|
|
{
|
2019-05-27 13:51:58 +02:00
|
|
|
VLayoutPiecePath convertedPath = VLayoutPiecePath(path.PathPoints(pattern, cuttingPath));
|
|
|
|
convertedPath.SetCutPath(path.IsCutPath());
|
|
|
|
convertedPath.SetPenStyle(path.GetPenType());
|
|
|
|
paths.append(convertedPath);
|
2017-02-08 12:48:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return paths;
|
|
|
|
}
|
2017-03-01 10:13:36 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-13 13:27:29 +01:00
|
|
|
bool FindLabelGeometry(const VPatternLabelData &labelData, const VContainer *pattern, qreal &rotationAngle,
|
|
|
|
qreal &labelWidth, qreal &labelHeight, QPointF &pos)
|
2017-03-01 10:13:36 +01:00
|
|
|
{
|
|
|
|
SCASSERT(pattern != nullptr)
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Calculator cal1;
|
2017-08-04 19:29:43 +02:00
|
|
|
rotationAngle = cal1.EvalFormula(pattern->DataVariables(), labelData.GetRotation());
|
2017-03-13 13:27:29 +01:00
|
|
|
}
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-01 10:13:36 +01:00
|
|
|
const quint32 topLeftPin = labelData.TopLeftPin();
|
|
|
|
const quint32 bottomRightPin = labelData.BottomRightPin();
|
|
|
|
|
|
|
|
if (topLeftPin != NULL_ID && bottomRightPin != NULL_ID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto topLeftPinPoint = pattern->GeometricObject<VPointF>(topLeftPin);
|
|
|
|
const auto bottomRightPinPoint = pattern->GeometricObject<VPointF>(bottomRightPin);
|
|
|
|
|
2017-03-31 16:04:11 +02:00
|
|
|
const QRectF labelRect = QRectF(static_cast<QPointF>(*topLeftPinPoint),
|
|
|
|
static_cast<QPointF>(*bottomRightPinPoint));
|
2017-03-01 10:13:36 +01:00
|
|
|
labelWidth = qAbs(labelRect.width());
|
|
|
|
labelHeight = qAbs(labelRect.height());
|
|
|
|
|
|
|
|
pos = labelRect.topLeft();
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
return true;
|
2017-03-01 10:13:36 +01:00
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
// do nothing.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-13 13:27:29 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Calculator cal1;
|
2017-08-04 19:29:43 +02:00
|
|
|
labelWidth = cal1.EvalFormula(pattern->DataVariables(), labelData.GetLabelWidth());
|
2020-09-23 15:54:06 +02:00
|
|
|
labelWidth = ToPixel(labelWidth, *pattern->GetPatternUnit());
|
2017-03-13 13:27:29 +01:00
|
|
|
|
|
|
|
Calculator cal2;
|
2017-08-04 19:29:43 +02:00
|
|
|
labelHeight = cal2.EvalFormula(pattern->DataVariables(), labelData.GetLabelHeight());
|
2020-09-23 15:54:06 +02:00
|
|
|
labelHeight = ToPixel(labelHeight, *pattern->GetPatternUnit());
|
2017-03-13 13:27:29 +01:00
|
|
|
}
|
|
|
|
catch(qmu::QmuParserError &e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const quint32 centerPin = labelData.CenterPin();
|
|
|
|
if (centerPin != NULL_ID)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const auto centerPinPoint = pattern->GeometricObject<VPointF>(centerPin);
|
2020-09-23 15:54:06 +02:00
|
|
|
pos = static_cast<QPointF>(*centerPinPoint) - QRectF(0, 0, labelWidth, labelHeight).center();
|
2017-03-13 13:27:29 +01:00
|
|
|
}
|
|
|
|
catch(const VExceptionBadId &)
|
|
|
|
{
|
|
|
|
pos = labelData.GetPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = labelData.GetPos();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2017-03-01 10:13:36 +01:00
|
|
|
}
|
|
|
|
|
2017-03-02 08:12:48 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VSAPoint> PrepareAllowance(const QVector<QPointF> &points)
|
|
|
|
{
|
|
|
|
QVector<VSAPoint> allowancePoints;
|
2018-10-22 13:42:13 +02:00
|
|
|
allowancePoints.reserve(points.size());
|
2020-08-28 13:57:14 +02:00
|
|
|
for(auto &point : points)
|
2017-03-02 08:12:48 +01:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
allowancePoints.append(VSAPoint(point));
|
2017-03-02 08:12:48 +01:00
|
|
|
}
|
|
|
|
return allowancePoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief VLayoutDetail::RotatePoint rotates a point around the center for given angle
|
|
|
|
* @param ptCenter center around which the point is rotated
|
|
|
|
* @param pt point, which is rotated around the center
|
|
|
|
* @param dAng angle of rotation
|
|
|
|
* @return position of point pt after rotating it around the center for dAng radians
|
|
|
|
*/
|
|
|
|
QPointF RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng)
|
|
|
|
{
|
|
|
|
QPointF ptDest;
|
|
|
|
QPointF ptRel = pt - ptCenter;
|
|
|
|
ptDest.setX(cos(dAng)*ptRel.x() - sin(dAng)*ptRel.y());
|
|
|
|
ptDest.setY(sin(dAng)*ptRel.x() + cos(dAng)*ptRel.y());
|
|
|
|
|
|
|
|
return ptDest + ptCenter;
|
|
|
|
}
|
2017-07-16 20:10:48 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList PieceLabelText(const QVector<QPointF> &labelShape, const VTextManager &tm)
|
|
|
|
{
|
|
|
|
QStringList text;
|
|
|
|
if (labelShape.count() > 2)
|
|
|
|
{
|
2020-08-28 13:57:14 +02:00
|
|
|
int sourceCount = tm.GetSourceLinesCount();
|
|
|
|
text.reserve(sourceCount);
|
|
|
|
for (int i = 0; i < sourceCount; ++i)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
text.append(tm.GetSourceLine(i).m_qsText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VLayoutPlaceLabel> ConvertPlaceLabels(const VPiece &piece, const VContainer *pattern)
|
|
|
|
{
|
|
|
|
QVector<VLayoutPlaceLabel> labels;
|
2020-08-28 13:57:14 +02:00
|
|
|
const auto placeLabels = piece.GetPlaceLabels();
|
2019-10-28 13:52:49 +01:00
|
|
|
labels.reserve(placeLabels.size());
|
2020-08-28 13:57:14 +02:00
|
|
|
for(auto &placeLabel : placeLabels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2018-04-02 19:38:56 +02:00
|
|
|
const auto label = pattern->GeometricObject<VPlaceLabelItem>(placeLabel);
|
2018-07-20 09:30:05 +02:00
|
|
|
if (label->IsVisible())
|
|
|
|
{
|
2020-01-07 11:55:23 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wnoexcept")
|
|
|
|
// noexcept-expression evaluates to 'false' because of a call to 'constexpr QPointF::QPointF()'
|
|
|
|
|
2018-07-20 09:30:05 +02:00
|
|
|
VLayoutPlaceLabel layoutLabel;
|
|
|
|
layoutLabel.shape = label->LabelShape();
|
2019-05-27 13:54:44 +02:00
|
|
|
layoutLabel.rotationMatrix = label->RotationMatrix();
|
|
|
|
layoutLabel.box = label->Box();
|
2018-07-20 09:30:05 +02:00
|
|
|
layoutLabel.center = label->toQPointF();
|
|
|
|
layoutLabel.type = label->GetLabelType();
|
|
|
|
labels.append(layoutLabel);
|
2020-01-07 11:55:23 +01:00
|
|
|
|
|
|
|
QT_WARNING_POP
|
2018-07-20 09:30:05 +02:00
|
|
|
}
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
return labels;
|
|
|
|
}
|
2019-05-27 13:57:36 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VLayoutPassmark> ConvertPassmarks(const VPiece &piece, const VContainer *pattern)
|
|
|
|
{
|
|
|
|
const QVector<VPassmark> passmarks = piece.Passmarks(pattern);
|
|
|
|
QVector<VLayoutPassmark> layoutPassmarks;
|
|
|
|
for(auto &passmark : passmarks)
|
|
|
|
{
|
|
|
|
if (not passmark.IsNull())
|
|
|
|
{
|
|
|
|
VPiecePassmarkData pData = passmark.Data();
|
|
|
|
|
|
|
|
auto PreapreBuiltInSAPassmark = [pData, passmark, piece, &layoutPassmarks, pattern]()
|
|
|
|
{
|
2021-02-05 16:44:58 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wnoexcept")
|
|
|
|
// noexcept-expression evaluates to 'false' because of a call to 'constexpr QPointF::QPointF()'
|
|
|
|
|
2019-05-27 13:57:36 +02:00
|
|
|
VLayoutPassmark layoutPassmark;
|
|
|
|
|
2021-02-05 16:44:58 +01:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2019-06-08 14:32:25 +02:00
|
|
|
const QVector<VPieceNode> path = piece.GetUnitedPath(pattern);
|
|
|
|
const int nodeIndex = VPiecePath::indexOfNode(path, pData.id);
|
2019-05-27 13:57:36 +02:00
|
|
|
if (nodeIndex != -1)
|
|
|
|
{
|
2020-09-22 13:43:39 +02:00
|
|
|
const QVector<QLineF> lines = passmark.BuiltInSAPassmark(piece, pattern);
|
|
|
|
if (lines.isEmpty())
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark is empty.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2020-09-22 13:43:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutPassmark.lines = lines;
|
|
|
|
|
|
|
|
const QVector<QLineF> baseLines = passmark.BuiltInSAPassmarkBaseLine(piece);
|
|
|
|
if (baseLines.isEmpty())
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Cannot prepare builtin passmark '%1' for piece '%2'. Passmark base line is "
|
|
|
|
"empty.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2020-09-22 13:43:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
layoutPassmark.baseLine = ConstFirst (baseLines);
|
|
|
|
|
|
|
|
|
2019-05-27 13:57:36 +02:00
|
|
|
layoutPassmark.type = pData.passmarkLineType;
|
|
|
|
layoutPassmark.isBuiltIn = true;
|
|
|
|
|
|
|
|
layoutPassmarks.append(layoutPassmark);
|
|
|
|
}
|
2019-06-08 14:32:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Passmark '%1' is not part of piece '%2'.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2019-06-08 14:32:25 +02:00
|
|
|
}
|
2019-05-27 13:57:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
auto PrepareSAPassmark = [pData, passmark, piece, &layoutPassmarks, pattern](PassmarkSide side)
|
|
|
|
{
|
2020-01-07 11:55:23 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wnoexcept")
|
|
|
|
// noexcept-expression evaluates to 'false' because of a call to 'constexpr QPointF::QPointF()'
|
|
|
|
|
2019-05-27 13:57:36 +02:00
|
|
|
VLayoutPassmark layoutPassmark;
|
|
|
|
|
2020-01-07 11:55:23 +01:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2019-06-08 14:32:25 +02:00
|
|
|
const QVector<VPieceNode> path = piece.GetUnitedPath(pattern);
|
|
|
|
const int nodeIndex = VPiecePath::indexOfNode(path, pData.id);
|
2019-05-27 13:57:36 +02:00
|
|
|
if (nodeIndex != -1)
|
|
|
|
{
|
2020-09-22 13:43:39 +02:00
|
|
|
QVector<QLineF> baseLines =
|
2019-05-27 13:57:36 +02:00
|
|
|
passmark.SAPassmarkBaseLine(piece, pattern, static_cast<PassmarkSide>(side));
|
2020-09-22 13:43:39 +02:00
|
|
|
if (baseLines.isEmpty())
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark base line is empty.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2020-09-22 13:43:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-05-27 16:05:42 +02:00
|
|
|
|
|
|
|
if (side == PassmarkSide::All || side == PassmarkSide::Right)
|
|
|
|
{
|
2020-09-22 13:43:39 +02:00
|
|
|
layoutPassmark.baseLine = baseLines.first();
|
2019-05-27 16:05:42 +02:00
|
|
|
}
|
|
|
|
else if (side == PassmarkSide::Right)
|
|
|
|
{
|
2020-09-22 13:43:39 +02:00
|
|
|
layoutPassmark.baseLine = baseLines.last();
|
2019-05-27 16:05:42 +02:00
|
|
|
}
|
2020-09-22 13:43:39 +02:00
|
|
|
|
|
|
|
const QVector<QLineF> lines = passmark.SAPassmark(piece, pattern, side);
|
|
|
|
if (lines.isEmpty())
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Cannot prepare passmark '%1' for piece '%2'. Passmark is empty.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2020-09-22 13:43:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutPassmark.lines = lines;
|
2019-05-27 13:57:36 +02:00
|
|
|
layoutPassmark.type = pData.passmarkLineType;
|
|
|
|
layoutPassmark.isBuiltIn = false;
|
|
|
|
|
|
|
|
layoutPassmarks.append(layoutPassmark);
|
|
|
|
}
|
2019-06-08 14:32:25 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const QString errorMsg =
|
|
|
|
QObject::tr("Passmark '%1' is not part of piece '%2'.")
|
|
|
|
.arg(pData.nodeName, piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2019-06-08 14:32:25 +02:00
|
|
|
}
|
2019-05-27 13:57:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (not piece.IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
|
|
|
if (pData.passmarkAngleType == PassmarkAngleType::Straightforward
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::Bisector)
|
|
|
|
{
|
|
|
|
PrepareSAPassmark(PassmarkSide::All);
|
|
|
|
}
|
|
|
|
else if (pData.passmarkAngleType == PassmarkAngleType::Intersection
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::IntersectionOnlyLeft
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::IntersectionOnlyRight
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::Intersection2
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::Intersection2OnlyLeft
|
|
|
|
|| pData.passmarkAngleType == PassmarkAngleType::Intersection2OnlyRight)
|
|
|
|
{
|
|
|
|
if (pData.passmarkAngleType == PassmarkAngleType::Intersection ||
|
|
|
|
pData.passmarkAngleType == PassmarkAngleType::Intersection2)
|
|
|
|
{
|
|
|
|
PrepareSAPassmark(PassmarkSide::Left);
|
|
|
|
PrepareSAPassmark(PassmarkSide::Right);
|
|
|
|
}
|
|
|
|
else if (pData.passmarkAngleType == PassmarkAngleType::IntersectionOnlyLeft ||
|
|
|
|
pData.passmarkAngleType == PassmarkAngleType::Intersection2OnlyLeft)
|
|
|
|
{
|
|
|
|
PrepareSAPassmark(PassmarkSide::Left);
|
|
|
|
}
|
|
|
|
else if (pData.passmarkAngleType == PassmarkAngleType::IntersectionOnlyRight ||
|
|
|
|
pData.passmarkAngleType == PassmarkAngleType::Intersection2OnlyRight)
|
|
|
|
{
|
|
|
|
PrepareSAPassmark(PassmarkSide::Right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
if (VAbstractApplication::VApp()->Settings()->IsDoublePassmark()
|
|
|
|
&& (VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() ||
|
|
|
|
not piece.IsHideMainPath())
|
2019-05-27 13:57:36 +02:00
|
|
|
&& pData.isMainPathNode
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::Intersection
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyLeft
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::IntersectionOnlyRight
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyLeft
|
|
|
|
&& pData.passmarkAngleType != PassmarkAngleType::Intersection2OnlyRight
|
|
|
|
&& pData.isShowSecondPassmark)
|
|
|
|
{
|
|
|
|
PreapreBuiltInSAPassmark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PreapreBuiltInSAPassmark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return layoutPassmarks;
|
|
|
|
}
|
2017-02-08 12:48:05 +01:00
|
|
|
}
|
|
|
|
|
2019-07-01 10:02:09 +02:00
|
|
|
// Friend functions
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator<<(QDataStream &dataStream, const VLayoutPiece &piece)
|
|
|
|
{
|
2019-07-01 11:26:08 +02:00
|
|
|
dataStream << static_cast<VAbstractPiece>(piece);
|
2019-07-01 10:02:09 +02:00
|
|
|
dataStream << *piece.d;
|
|
|
|
return dataStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QDataStream &operator>>(QDataStream &dataStream, VLayoutPiece &piece)
|
|
|
|
{
|
2019-07-01 11:26:08 +02:00
|
|
|
dataStream >> static_cast<VAbstractPiece &>(piece);
|
2019-07-01 10:02:09 +02:00
|
|
|
dataStream >> *piece.d;
|
|
|
|
return dataStream;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece::VLayoutPiece()
|
|
|
|
:VAbstractPiece(), d(new VLayoutPieceData)
|
2015-01-07 17:54:43 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece::VLayoutPiece(const VLayoutPiece &detail)
|
2017-01-22 09:50:23 +01:00
|
|
|
:VAbstractPiece(detail), d(detail.d)
|
2015-01-07 17:54:43 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece &VLayoutPiece::operator=(const VLayoutPiece &detail)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
if ( &detail == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
2017-01-22 09:50:23 +01:00
|
|
|
VAbstractPiece::operator=(detail);
|
2015-01-07 17:54:43 +01:00
|
|
|
d = detail.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-12-30 12:00:57 +01:00
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
VLayoutPiece::VLayoutPiece(const VLayoutPiece &&detail) Q_DECL_NOTHROW
|
|
|
|
:VAbstractPiece(detail), d(detail.d)
|
|
|
|
{}
|
2019-12-30 12:00:57 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-12-30 16:13:18 +01:00
|
|
|
VLayoutPiece &VLayoutPiece::operator=(VLayoutPiece &&detail) Q_DECL_NOTHROW
|
2019-12-30 12:00:57 +01:00
|
|
|
{
|
2019-12-30 16:13:18 +01:00
|
|
|
VAbstractPiece::operator=(detail);
|
2019-12-30 12:00:57 +01:00
|
|
|
std::swap(d, detail.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-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece::~VLayoutPiece()
|
2015-01-07 17:54:43 +01:00
|
|
|
{}
|
|
|
|
|
2017-01-22 09:32:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
VLayoutPiece VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pattern)
|
2017-01-22 09:32:01 +01:00
|
|
|
{
|
2018-01-21 21:00:07 +01:00
|
|
|
QFuture<QVector<QPointF> > futureSeamAllowance = QtConcurrent::run(piece, &VPiece::SeamAllowancePoints, pattern);
|
2019-02-23 17:43:06 +01:00
|
|
|
QFuture<bool> futureSeamAllowanceValid = QtConcurrent::run(piece, &VPiece::IsSeamAllowanceValid, pattern);
|
2018-01-21 21:00:07 +01:00
|
|
|
QFuture<QVector<QPointF> > futureMainPath = QtConcurrent::run(piece, &VPiece::MainPathPoints, pattern);
|
|
|
|
QFuture<QVector<VLayoutPiecePath> > futureInternalPaths = QtConcurrent::run(ConvertInternalPaths, piece, pattern);
|
2019-05-27 13:57:36 +02:00
|
|
|
QFuture<QVector<VLayoutPassmark> > futurePassmarks = QtConcurrent::run(ConvertPassmarks, piece, pattern);
|
2018-01-21 21:00:07 +01:00
|
|
|
QFuture<QVector<VLayoutPlaceLabel> > futurePlaceLabels = QtConcurrent::run(ConvertPlaceLabels, piece, pattern);
|
|
|
|
|
2017-01-22 13:32:25 +01:00
|
|
|
VLayoutPiece det;
|
2017-07-09 21:27:54 +02:00
|
|
|
|
|
|
|
det.SetMx(piece.GetMx());
|
|
|
|
det.SetMy(piece.GetMy());
|
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
det.SetName(piece.GetName());
|
2020-04-22 13:32:25 +02:00
|
|
|
det.SetUUID(piece.GetUUID());
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2021-02-06 14:52:21 +01:00
|
|
|
det.SetSAWidth(VAbstractValApplication::VApp()->toPixel(piece.GetSAWidth()));
|
2018-01-21 21:00:07 +01:00
|
|
|
det.SetForbidFlipping(piece.IsForbidFlipping());
|
|
|
|
det.SetForceFlipping(piece.IsForceFlipping());
|
2019-07-19 09:45:57 +02:00
|
|
|
det.SetId(id);
|
2018-01-21 21:00:07 +01:00
|
|
|
|
2019-02-23 17:43:06 +01:00
|
|
|
if (not futureSeamAllowanceValid.result())
|
|
|
|
{
|
|
|
|
const QString errorMsg = QObject::tr("Piece '%1'. Seam allowance is not valid.")
|
|
|
|
.arg(piece.GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2019-02-23 17:43:06 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 14:28:23 +01:00
|
|
|
det.SetCountourPoints(futureMainPath.result(),
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->Settings()->IsPieceShowMainPath() ? false
|
|
|
|
: piece.IsHideMainPath());
|
2018-01-21 21:00:07 +01:00
|
|
|
det.SetSeamAllowancePoints(futureSeamAllowance.result(), piece.IsSeamAllowance(), piece.IsSeamAllowanceBuiltIn());
|
|
|
|
det.SetInternalPaths(futureInternalPaths.result());
|
2019-05-27 13:57:36 +02:00
|
|
|
det.SetPassmarks(futurePassmarks.result());
|
2018-01-21 21:00:07 +01:00
|
|
|
det.SetPlaceLabels(futurePlaceLabels.result());
|
2019-07-19 09:45:57 +02:00
|
|
|
det.SetPriority(piece.GetPriority());
|
2018-01-21 21:00:07 +01:00
|
|
|
|
2017-03-02 08:12:48 +01:00
|
|
|
// Very important to set main path first!
|
2021-05-27 18:52:37 +02:00
|
|
|
if (det.MappedContourPath().isEmpty())
|
2017-03-02 08:12:48 +01:00
|
|
|
{
|
|
|
|
throw VException (tr("Piece %1 doesn't have shape.").arg(piece.GetName()));
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:19:27 +01:00
|
|
|
const VPieceLabelData& data = piece.GetPatternPieceData();
|
2019-07-04 13:33:45 +02:00
|
|
|
det.SetQuantity(data.GetQuantity());
|
|
|
|
if (data.IsVisible())
|
2017-01-22 09:32:01 +01:00
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
det.SetPieceText(piece.GetName(), data, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern);
|
2017-01-22 09:32:01 +01:00
|
|
|
}
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2017-02-23 10:26:25 +01:00
|
|
|
const VPatternLabelData& geom = piece.GetPatternInfo();
|
2019-07-04 13:33:45 +02:00
|
|
|
if (geom.IsVisible())
|
2017-01-22 09:32:01 +01:00
|
|
|
{
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractPattern* pDoc = VAbstractValApplication::VApp()->getCurrentDocument();
|
|
|
|
det.SetPatternInfo(pDoc, geom, VAbstractApplication::VApp()->Settings()->GetLabelFont(), pattern);
|
2017-01-22 09:32:01 +01:00
|
|
|
}
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2017-02-23 10:33:17 +01:00
|
|
|
const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry();
|
2017-01-22 09:32:01 +01:00
|
|
|
if (grainlineGeom.IsVisible() == true)
|
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
det.SetGrainline(grainlineGeom, pattern);
|
2017-01-22 09:32:01 +01:00
|
|
|
}
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2017-01-22 09:32:01 +01:00
|
|
|
return det;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
2019-04-02 14:30:31 +02:00
|
|
|
QVector<T> VLayoutPiece::Map(QVector<T> points) const
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2020-08-28 14:09:16 +02:00
|
|
|
std::transform(points.begin(), points.end(), points.begin(),
|
2020-09-22 08:45:17 +02:00
|
|
|
[this](const T &point) { return d->matrix.map(point); });
|
2017-10-15 11:25:20 +02:00
|
|
|
if (d->mirror)
|
|
|
|
{
|
2020-08-28 14:09:16 +02:00
|
|
|
std::reverse(points.begin(), points.end());
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
2019-04-02 14:30:31 +02:00
|
|
|
return points;
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
2019-04-02 14:30:31 +02:00
|
|
|
QVector<VLayoutPlaceLabel> VLayoutPiece::Map<VLayoutPlaceLabel>(QVector<VLayoutPlaceLabel> points) const
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2019-04-02 14:30:31 +02:00
|
|
|
for (int i = 0; i < points.size(); ++i)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2019-04-02 14:30:31 +02:00
|
|
|
points[i].shape = Map(points.at(i).shape);
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
|
2019-04-02 14:30:31 +02:00
|
|
|
return points;
|
2017-10-15 11:25:20 +02:00
|
|
|
}
|
|
|
|
|
2019-05-27 13:57:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <>
|
|
|
|
QVector<VLayoutPassmark> VLayoutPiece::Map<VLayoutPassmark>(QVector<VLayoutPassmark> passmarks) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < passmarks.size(); ++i)
|
|
|
|
{
|
|
|
|
passmarks[i].lines = Map(passmarks.at(i).lines);
|
2020-03-25 14:28:23 +01:00
|
|
|
passmarks[i].baseLine = d->matrix.map(passmarks.at(i).baseLine);
|
2019-05-27 13:57:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return passmarks;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2019-05-27 16:04:26 +02:00
|
|
|
QVector<QPointF> VLayoutPiece::GetMappedContourPoints() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2016-12-10 17:38:34 +01:00
|
|
|
return Map(d->contour);
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:04:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutPiece::GetContourPoints() const
|
|
|
|
{
|
|
|
|
return d->contour;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-05-16 14:16:50 +02:00
|
|
|
void VLayoutPiece::SetCountourPoints(const QVector<QPointF> &points, bool hideMainPath)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-07-21 13:31:47 +02:00
|
|
|
d->contour = RemoveDublicates(points, false);
|
2017-05-16 14:16:50 +02:00
|
|
|
SetHideMainPath(hideMainPath);
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2019-05-27 16:04:26 +02:00
|
|
|
QVector<QPointF> VLayoutPiece::GetMappedSeamAllowancePoints() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return Map(d->seamAllowance);
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:04:26 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutPiece::GetSeamAllowancePoints() const
|
|
|
|
{
|
|
|
|
return d->seamAllowance;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-04-05 12:22:33 +02:00
|
|
|
void VLayoutPiece::SetSeamAllowancePoints(const QVector<QPointF> &points, bool seamAllowance, bool seamAllowanceBuiltIn)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
if (seamAllowance)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
SetSeamAllowance(seamAllowance);
|
2017-04-05 12:22:33 +02:00
|
|
|
SetSeamAllowanceBuiltIn(seamAllowanceBuiltIn);
|
2017-01-25 12:29:03 +01:00
|
|
|
d->seamAllowance = points;
|
|
|
|
if (not d->seamAllowance.isEmpty())
|
2015-03-14 13:38:44 +01:00
|
|
|
{
|
2017-07-21 13:31:47 +02:00
|
|
|
d->seamAllowance = RemoveDublicates(d->seamAllowance, false);
|
2015-03-14 13:38:44 +01:00
|
|
|
}
|
2017-04-05 12:22:33 +02:00
|
|
|
else if (not IsSeamAllowanceBuiltIn())
|
2015-03-14 13:38:44 +01:00
|
|
|
{
|
2017-01-23 17:20:15 +01:00
|
|
|
qWarning()<<"Seam allowance is empty.";
|
2017-01-22 09:50:23 +01:00
|
|
|
SetSeamAllowance(false);
|
2015-03-14 13:38:44 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QVector<QPointF> VLayoutPiece::GetMappedLayoutAllowancePoints() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return Map(d->layoutAllowance);
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutPiece::GetLayoutAllowancePoints() const
|
|
|
|
{
|
|
|
|
return d->layoutAllowance;
|
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-07-16 20:10:48 +02:00
|
|
|
QPointF VLayoutPiece::GetPieceTextPosition() const
|
|
|
|
{
|
|
|
|
if (d->detailLabel.count() > 2)
|
|
|
|
{
|
|
|
|
return d->matrix.map(d->detailLabel.first());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VLayoutPiece::GetPieceText() const
|
|
|
|
{
|
|
|
|
return PieceLabelText(d->detailLabel, d->m_tmDetail);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::SetPieceText(const QString& qsName, const VPieceLabelData& data, const QFont &font,
|
|
|
|
const VContainer *pattern)
|
2016-07-17 22:52:53 +02:00
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
QPointF ptPos;
|
|
|
|
qreal labelWidth = 0;
|
|
|
|
qreal labelHeight = 0;
|
2017-03-13 13:27:29 +01:00
|
|
|
qreal labelAngle = 0;
|
|
|
|
if (not FindLabelGeometry(data, pattern, labelAngle, labelWidth, labelHeight, ptPos))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
QVector<QPointF> v;
|
2017-03-01 10:13:36 +01:00
|
|
|
v << ptPos
|
|
|
|
<< QPointF(ptPos.x() + labelWidth, ptPos.y())
|
|
|
|
<< QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight)
|
|
|
|
<< QPointF(ptPos.x(), ptPos.y() + labelHeight);
|
|
|
|
|
2017-06-29 12:00:06 +02:00
|
|
|
const qreal dAng = qDegreesToRadians(-labelAngle);
|
2017-03-01 10:13:36 +01:00
|
|
|
const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2);
|
2017-06-29 12:00:06 +02:00
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
for (int i = 0; i < v.count(); ++i)
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
2016-07-22 11:56:45 +02:00
|
|
|
v[i] = RotatePoint(ptCenter, v.at(i), dAng);
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2017-07-11 12:53:36 +02:00
|
|
|
QScopedPointer<QGraphicsItem> item(GetMainPathItem());
|
2017-07-21 13:31:47 +02:00
|
|
|
d->detailLabel = CorrectPosition(item->boundingRect(), v);
|
2016-07-19 02:26:50 +02:00
|
|
|
|
|
|
|
// generate text
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_tmDetail.SetFont(font);
|
2016-12-14 10:59:21 +01:00
|
|
|
d->m_tmDetail.SetFontSize(data.GetFontSize());
|
2020-10-16 12:43:54 +02:00
|
|
|
d->m_tmDetail.Update(qsName, data, pattern);
|
2016-07-21 21:46:49 +02:00
|
|
|
// this will generate the lines of text
|
2016-12-14 10:59:21 +01:00
|
|
|
d->m_tmDetail.SetFontSize(data.GetFontSize());
|
2017-03-01 10:13:36 +01:00
|
|
|
d->m_tmDetail.FitFontSize(labelWidth, labelHeight);
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPointF VLayoutPiece::GetPatternTextPosition() const
|
|
|
|
{
|
|
|
|
if (d->patternInfo.count() > 2)
|
|
|
|
{
|
|
|
|
return d->matrix.map(d->patternInfo.first());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QStringList VLayoutPiece::GetPatternText() const
|
|
|
|
{
|
|
|
|
return PieceLabelText(d->patternInfo, d->m_tmPattern);
|
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-08-19 18:52:33 +02:00
|
|
|
void VLayoutPiece::SetPatternInfo(VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font,
|
2017-08-15 14:22:33 +02:00
|
|
|
const VContainer *pattern)
|
2016-07-17 22:52:53 +02:00
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
QPointF ptPos;
|
|
|
|
qreal labelWidth = 0;
|
|
|
|
qreal labelHeight = 0;
|
2017-03-13 13:27:29 +01:00
|
|
|
qreal labelAngle = 0;
|
|
|
|
if (not FindLabelGeometry(geom, pattern, labelAngle, labelWidth, labelHeight, ptPos))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
QVector<QPointF> v;
|
2017-03-01 10:13:36 +01:00
|
|
|
v << ptPos
|
|
|
|
<< QPointF(ptPos.x() + labelWidth, ptPos.y())
|
|
|
|
<< QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight)
|
|
|
|
<< QPointF(ptPos.x(), ptPos.y() + labelHeight);
|
|
|
|
|
2017-06-29 12:00:06 +02:00
|
|
|
const qreal dAng = qDegreesToRadians(-labelAngle);
|
2017-03-01 10:13:36 +01:00
|
|
|
const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2);
|
2016-07-17 22:52:53 +02:00
|
|
|
for (int i = 0; i < v.count(); ++i)
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
2016-07-22 12:40:02 +02:00
|
|
|
v[i] = RotatePoint(ptCenter, v.at(i), dAng);
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
2017-07-11 12:53:36 +02:00
|
|
|
QScopedPointer<QGraphicsItem> item(GetMainPathItem());
|
2017-07-21 13:31:47 +02:00
|
|
|
d->patternInfo = CorrectPosition(item->boundingRect(), v);
|
2016-07-19 13:47:21 +02:00
|
|
|
|
|
|
|
// Generate text
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_tmPattern.SetFont(font);
|
2016-12-14 10:59:21 +01:00
|
|
|
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
2016-07-21 21:46:49 +02:00
|
|
|
|
2020-10-16 12:43:54 +02:00
|
|
|
d->m_tmPattern.Update(pDoc, pattern);
|
2016-12-14 00:56:30 +01:00
|
|
|
|
2016-07-19 13:47:21 +02:00
|
|
|
// generate lines of text
|
2016-12-14 10:59:21 +01:00
|
|
|
d->m_tmPattern.SetFontSize(geom.GetFontSize());
|
2017-03-01 10:13:36 +01:00
|
|
|
d->m_tmPattern.FitFontSize(labelWidth, labelHeight);
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-10-16 11:38:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-01 10:13:36 +01:00
|
|
|
void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer* pattern)
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
2017-03-01 10:13:36 +01:00
|
|
|
qreal dAng = 0;
|
2019-01-28 19:35:10 +01:00
|
|
|
|
|
|
|
QScopedPointer<QGraphicsItem> item(GetMainPathItem());
|
|
|
|
const QVector<QPointF> v = GrainlinePoints(geom, pattern, item->boundingRect(), dAng);
|
|
|
|
|
|
|
|
if (v.isEmpty())
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
d->grainlineEnabled = true;
|
|
|
|
d->grainlineArrowType = geom.GetArrowType();
|
|
|
|
d->grainlineAngle = qRadiansToDegrees(dAng);
|
2019-01-28 19:35:10 +01:00
|
|
|
d->grainlinePoints = v;
|
2016-10-16 11:38:08 +02:00
|
|
|
}
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QVector<QPointF> VLayoutPiece::GetMappedGrainline() const
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
return Map(d->grainlinePoints);
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutPiece::GetGrainline() const
|
|
|
|
{
|
|
|
|
return d->grainlinePoints;
|
|
|
|
}
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPiece::IsGrainlineEnabled() const
|
|
|
|
{
|
|
|
|
return d->grainlineEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutPiece::GrainlineAngle() const
|
|
|
|
{
|
|
|
|
return d->grainlineAngle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-01-07 12:54:23 +01:00
|
|
|
GrainlineArrowDirection VLayoutPiece::GrainlineArrowType() const
|
2018-12-27 14:54:29 +01:00
|
|
|
{
|
|
|
|
return d->grainlineArrowType;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QTransform VLayoutPiece::GetMatrix() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
return d->matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::SetMatrix(const QTransform &matrix)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
d->matrix = matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
qreal VLayoutPiece::GetLayoutWidth() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
return d->layoutWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2018-10-22 13:42:13 +02:00
|
|
|
void VLayoutPiece::SetLayoutWidth(qreal value)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
d->layoutWidth = value;
|
|
|
|
}
|
|
|
|
|
2019-07-04 13:33:45 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
quint16 VLayoutPiece::GetQuantity() const
|
|
|
|
{
|
|
|
|
return d->m_quantity;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::SetQuantity(quint16 value)
|
|
|
|
{
|
|
|
|
d->m_quantity = qMax(static_cast<quint16>(1), value);
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
vidtype VLayoutPiece::GetId() const
|
|
|
|
{
|
|
|
|
return d->m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::SetId(vidtype id)
|
|
|
|
{
|
|
|
|
d->m_id = id;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::Translate(qreal dx, qreal dy)
|
2021-08-09 14:09:10 +02:00
|
|
|
{
|
|
|
|
Translate(QPointF(dx, dy));
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::Translate(const QPointF &p)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2015-01-18 19:56:01 +01:00
|
|
|
QTransform m;
|
2021-08-09 14:09:10 +02:00
|
|
|
m.translate(p.x(), p.y());
|
2015-01-16 13:54:37 +01:00
|
|
|
d->matrix *= m;
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 14:28:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::Scale(qreal sx, qreal sy)
|
|
|
|
{
|
|
|
|
QTransform m;
|
|
|
|
m.scale(sx, sy);
|
|
|
|
d->matrix *= m;
|
|
|
|
}
|
|
|
|
|
2015-01-10 14:47:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::Rotate(const QPointF &originPoint, qreal degrees)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-01-18 19:56:01 +01:00
|
|
|
QTransform m;
|
2015-01-16 13:54:37 +01:00
|
|
|
m.translate(originPoint.x(), originPoint.y());
|
|
|
|
m.rotate(-degrees);
|
|
|
|
m.translate(-originPoint.x(), -originPoint.y());
|
|
|
|
d->matrix *= m;
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::Mirror(const QLineF &edge)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-01-10 14:47:46 +01:00
|
|
|
if (edge.isNull())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-17 18:23:54 +01:00
|
|
|
const QLineF axis = QLineF(edge.x2(), edge.y2(), edge.x2() + 100, edge.y2()); // Ox axis
|
2015-01-10 14:47:46 +01:00
|
|
|
|
2015-01-16 14:20:15 +01:00
|
|
|
const qreal angle = edge.angleTo(axis);
|
2015-11-15 18:06:25 +01:00
|
|
|
const QPointF p2 = edge.p2();
|
2015-01-18 19:56:01 +01:00
|
|
|
QTransform m;
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(p2.x(), p2.y());
|
2015-01-16 14:20:15 +01:00
|
|
|
m.rotate(-angle);
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(-p2.x(), -p2.y());
|
2015-01-17 18:23:54 +01:00
|
|
|
d->matrix *= m;
|
|
|
|
|
|
|
|
m.reset();
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(p2.x(), p2.y());
|
2015-01-16 14:20:15 +01:00
|
|
|
m.scale(m.m11(), m.m22()*-1);
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(-p2.x(), -p2.y());
|
2015-01-17 18:23:54 +01:00
|
|
|
d->matrix *= m;
|
|
|
|
|
|
|
|
m.reset();
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(p2.x(), p2.y());
|
2015-01-17 18:23:54 +01:00
|
|
|
m.rotate(-(360-angle));
|
2015-10-28 15:22:36 +01:00
|
|
|
m.translate(-p2.x(), -p2.y());
|
2015-01-16 14:20:15 +01:00
|
|
|
d->matrix *= m;
|
2015-01-18 19:56:01 +01:00
|
|
|
|
|
|
|
d->mirror = !d->mirror;
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 14:29:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::Mirror()
|
|
|
|
{
|
|
|
|
QTransform m;
|
|
|
|
m.scale(-1, 1);
|
|
|
|
d->matrix *= m;
|
|
|
|
d->mirror = !d->mirror;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
int VLayoutPiece::DetailEdgesCount() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2016-12-10 17:38:34 +01:00
|
|
|
return DetailPath().count();
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
int VLayoutPiece::LayoutEdgesCount() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2019-07-22 15:15:28 +02:00
|
|
|
const int count = d->layoutAllowance.count();
|
|
|
|
return count > 2 ? count : 0;
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
2015-01-19 15:13:26 +01:00
|
|
|
|
2015-01-10 14:47:46 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QLineF VLayoutPiece::LayoutEdge(int i) const
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return Edge(d->layoutAllowance, i);
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
2015-01-10 14:47:46 +01:00
|
|
|
|
2016-12-10 17:38:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
int VLayoutPiece::LayoutEdgeByPoint(const QPointF &p1) const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return EdgeByPoint(d->layoutAllowance, p1);
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QRectF VLayoutPiece::MappedDetailBoundingRect() const
|
2016-06-21 15:04:15 +02:00
|
|
|
{
|
2019-05-27 16:04:26 +02:00
|
|
|
return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? BoundingRect(GetMappedSeamAllowancePoints()) :
|
|
|
|
BoundingRect(GetMappedContourPoints());
|
2016-06-21 15:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QRectF VLayoutPiece::DetailBoundingRect() const
|
|
|
|
{
|
|
|
|
return IsSeamAllowance() && not IsSeamAllowanceBuiltIn() ? BoundingRect(GetSeamAllowancePoints()) :
|
|
|
|
BoundingRect(GetContourPoints());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QRectF VLayoutPiece::MappedLayoutBoundingRect() const
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
return BoundingRect(GetMappedLayoutAllowancePoints());
|
2016-02-23 13:13:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
qreal VLayoutPiece::Diagonal() const
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
const QRectF rec = MappedLayoutBoundingRect();
|
2016-02-23 13:13:10 +01:00
|
|
|
return qSqrt(pow(rec.height(), 2) + pow(rec.width(), 2));
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
bool VLayoutPiece::isNull() const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (d->contour.isEmpty() == false && d->layoutWidth > 0)
|
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn() && d->seamAllowance.isEmpty() == false)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
qint64 VLayoutPiece::Square() const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-03-29 18:52:37 +01:00
|
|
|
return d->m_square;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-25 12:29:03 +01:00
|
|
|
void VLayoutPiece::SetLayoutAllowancePoints()
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2019-07-18 16:32:19 +02:00
|
|
|
d->m_square = 0;
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
if (d->layoutWidth > 0)
|
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn())
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2019-07-18 16:32:19 +02:00
|
|
|
d->layoutAllowance = Equidistant(PrepareAllowance(GetMappedSeamAllowancePoints()), d->layoutWidth,
|
|
|
|
GetName());
|
|
|
|
if (not d->layoutAllowance.isEmpty())
|
2015-01-16 13:54:37 +01:00
|
|
|
{
|
2017-05-30 18:52:38 +02:00
|
|
|
d->layoutAllowance.removeLast();
|
2019-07-18 16:32:19 +02:00
|
|
|
|
|
|
|
d->m_square = qFloor(qAbs(SumTrapezoids(GetSeamAllowancePoints())/2.0));
|
2015-01-16 13:54:37 +01:00
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-27 16:04:26 +02:00
|
|
|
d->layoutAllowance = Equidistant(PrepareAllowance(GetMappedContourPoints()), d->layoutWidth, GetName());
|
2019-07-18 16:32:19 +02:00
|
|
|
if (not d->layoutAllowance.isEmpty())
|
2015-01-16 13:54:37 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.removeLast();
|
2019-07-18 16:32:19 +02:00
|
|
|
|
|
|
|
d->m_square = qFloor(qAbs(SumTrapezoids(GetContourPoints())/2.0));
|
2015-01-16 13:54:37 +01:00
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.clear();
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-30 12:27:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QVector<VLayoutPassmark> VLayoutPiece::GetMappedPassmarks() const
|
2017-03-30 12:27:57 +02:00
|
|
|
{
|
|
|
|
return Map(d->passmarks);
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VLayoutPassmark> VLayoutPiece::GetPassmarks() const
|
|
|
|
{
|
|
|
|
return d->passmarks;
|
|
|
|
}
|
|
|
|
|
2017-03-30 12:27:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-05-27 13:57:36 +02:00
|
|
|
void VLayoutPiece::SetPassmarks(const QVector<VLayoutPassmark> &passmarks)
|
2017-03-30 12:27:57 +02:00
|
|
|
{
|
|
|
|
if (IsSeamAllowance())
|
|
|
|
{
|
|
|
|
d->passmarks = passmarks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-14 14:18:15 +02:00
|
|
|
QVector<VLayoutPlaceLabel> VLayoutPiece::GetMappedPlaceLabels() const
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
|
|
|
return Map(d->m_placeLabels);
|
|
|
|
}
|
|
|
|
|
2021-08-14 14:18:15 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<VLayoutPlaceLabel> VLayoutPiece::GetPlaceLabels() const
|
|
|
|
{
|
|
|
|
return d->m_placeLabels;
|
|
|
|
}
|
|
|
|
|
2017-10-15 11:25:20 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::SetPlaceLabels(const QVector<VLayoutPlaceLabel> &labels)
|
|
|
|
{
|
|
|
|
d->m_placeLabels = labels;
|
|
|
|
}
|
|
|
|
|
2017-07-16 20:10:48 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-08-14 14:18:15 +02:00
|
|
|
QVector<QVector<QPointF> > VLayoutPiece::MappedInternalPathsForCut(bool cut) const
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
|
|
|
QVector<QVector<QPointF> > paths;
|
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &path : d->m_internalPaths)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
if (path.IsCutPath() == cut)
|
2017-07-16 20:10:48 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
paths.append(Map(path.Points()));
|
2017-07-16 20:10:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2017-01-22 13:32:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-08 12:48:05 +01:00
|
|
|
QVector<VLayoutPiecePath> VLayoutPiece::GetInternalPaths() const
|
2017-01-22 13:32:25 +01:00
|
|
|
{
|
|
|
|
return d->m_internalPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-08 12:48:05 +01:00
|
|
|
void VLayoutPiece::SetInternalPaths(const QVector<VLayoutPiecePath> &internalPaths)
|
2017-01-22 13:32:25 +01:00
|
|
|
{
|
2017-02-08 12:48:05 +01:00
|
|
|
d->m_internalPaths = internalPaths;
|
2017-01-22 13:32:25 +01:00
|
|
|
}
|
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPainterPath VLayoutPiece::MappedContourPath() const
|
|
|
|
{
|
|
|
|
return d->matrix.map(ContourPath());
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:35:32 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QPainterPath VLayoutPiece::ContourPath() const
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2017-07-25 15:33:50 +02:00
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// contour
|
|
|
|
if (not IsHideMainPath() || not IsSeamAllowance() || IsSeamAllowanceBuiltIn())
|
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
path = PainterPath(GetContourPoints());
|
2017-07-25 15:33:50 +02:00
|
|
|
}
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2017-01-23 17:20:15 +01:00
|
|
|
// seam allowance
|
2017-04-05 12:22:33 +02:00
|
|
|
if (IsSeamAllowance())
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
if (not IsSeamAllowanceBuiltIn())
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
// Draw seam allowance
|
2021-05-27 18:52:37 +02:00
|
|
|
QVector<QPointF>points = GetSeamAllowancePoints();
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
if (points.last().toPoint() != points.first().toPoint())
|
|
|
|
{
|
|
|
|
points.append(points.at(0));// Should be always closed
|
|
|
|
}
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
QPainterPath ekv;
|
|
|
|
ekv.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
ekv.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(ekv);
|
|
|
|
}
|
2017-03-30 12:27:57 +02:00
|
|
|
|
|
|
|
// Draw passmarks
|
|
|
|
QPainterPath passmaksPath;
|
2019-05-27 13:57:36 +02:00
|
|
|
const QVector<VLayoutPassmark> passmarks = GetPassmarks();
|
2021-05-27 18:52:37 +02:00
|
|
|
for(const auto &passmark : passmarks)
|
2017-03-30 12:27:57 +02:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
for (const auto &line : passmark.lines)
|
2019-05-27 13:57:36 +02:00
|
|
|
{
|
|
|
|
passmaksPath.moveTo(line.p1());
|
|
|
|
passmaksPath.lineTo(line.p2());
|
|
|
|
}
|
2017-03-30 12:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(passmaksPath);
|
2015-01-12 21:35:32 +01:00
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
}
|
|
|
|
|
2016-07-19 09:06:29 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-03-28 10:53:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 18:52:37 +02:00
|
|
|
QPainterPath VLayoutPiece::MappedLayoutAllowancePath() const
|
2019-04-10 14:54:18 +02:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
return PainterPath(GetMappedLayoutAllowancePoints());
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2021-05-27 19:58:18 +02:00
|
|
|
void VLayoutPiece::DrawMiniature(QPainter &painter) const
|
2021-05-27 18:52:37 +02:00
|
|
|
{
|
|
|
|
painter.drawPath(ContourPath());
|
|
|
|
|
2021-05-27 20:11:32 +02:00
|
|
|
for (const auto &path : d->m_internalPaths)
|
2021-05-27 18:52:37 +02:00
|
|
|
{
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
QPen pen = painter.pen();
|
|
|
|
pen.setStyle(path.PenStyle());
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
painter.drawPath(path.GetPainterPath());
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
}
|
|
|
|
|
2021-05-27 20:11:32 +02:00
|
|
|
for (const auto &label : d->m_placeLabels)
|
2021-05-27 18:52:37 +02:00
|
|
|
{
|
|
|
|
painter.drawPath(VPlaceLabelItem::LabelShapePath(label.shape));
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> gPoints = GetGrainline();
|
2021-07-27 09:13:11 +02:00
|
|
|
if (not gPoints.isEmpty())
|
2021-05-27 18:52:37 +02:00
|
|
|
{
|
2021-07-27 09:13:11 +02:00
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(gPoints.at(0));
|
|
|
|
for (auto p : qAsConst(gPoints))
|
|
|
|
{
|
|
|
|
path.lineTo(p);
|
|
|
|
}
|
|
|
|
painter.drawPath(path);
|
2021-05-27 18:52:37 +02:00
|
|
|
}
|
2019-04-10 14:54:18 +02:00
|
|
|
}
|
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-07-01 19:32:54 +02:00
|
|
|
QGraphicsItem *VLayoutPiece::GetItem(bool textAsPaths) const
|
2015-01-13 11:38:51 +01:00
|
|
|
{
|
2017-03-02 08:12:48 +01:00
|
|
|
QGraphicsPathItem *item = GetMainItem();
|
2017-02-08 12:48:05 +01:00
|
|
|
|
2018-04-03 13:36:38 +02:00
|
|
|
for (auto &path : d->m_internalPaths)
|
2017-02-08 12:48:05 +01:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
auto* pathItem = new QGraphicsPathItem(item);
|
2018-04-03 13:36:38 +02:00
|
|
|
pathItem->setPath(d->matrix.map(path.GetPainterPath()));
|
2017-10-15 11:25:20 +02:00
|
|
|
|
|
|
|
QPen pen = pathItem->pen();
|
2018-04-03 13:36:38 +02:00
|
|
|
pen.setStyle(path.PenStyle());
|
2021-02-06 14:52:21 +01:00
|
|
|
pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine());
|
2017-10-15 11:25:20 +02:00
|
|
|
pathItem->setPen(pen);
|
|
|
|
}
|
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
for (const auto &label : d->m_placeLabels)
|
2017-10-15 11:25:20 +02:00
|
|
|
{
|
2021-05-27 18:52:37 +02:00
|
|
|
auto* pathItem = new QGraphicsPathItem(item);
|
2021-01-23 17:54:07 +01:00
|
|
|
QPen pen = pathItem->pen();
|
2021-02-06 14:52:21 +01:00
|
|
|
pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine());
|
2021-01-23 17:54:07 +01:00
|
|
|
pathItem->setPen(pen);
|
2019-05-08 14:19:03 +02:00
|
|
|
pathItem->setPath(d->matrix.map(VPlaceLabelItem::LabelShapePath(label.shape)));
|
2017-02-08 12:48:05 +01:00
|
|
|
}
|
2017-01-22 13:32:25 +01:00
|
|
|
|
2017-07-01 19:32:54 +02:00
|
|
|
CreateLabelStrings(item, d->detailLabel, d->m_tmDetail, textAsPaths);
|
|
|
|
CreateLabelStrings(item, d->patternInfo, d->m_tmPattern, textAsPaths);
|
2017-01-22 13:32:25 +01:00
|
|
|
CreateGrainlineItem(item);
|
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
return item;
|
|
|
|
}
|
2015-01-18 19:56:01 +01:00
|
|
|
|
2017-12-11 16:46:13 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutPiece::IsLayoutAllowanceValid() const
|
|
|
|
{
|
2019-02-23 17:43:06 +01:00
|
|
|
QVector<QPointF> base = (IsSeamAllowance() && not IsSeamAllowanceBuiltIn()) ? d->seamAllowance : d->contour;
|
|
|
|
return VAbstractPiece::IsAllowanceValid(base, d->layoutAllowance);
|
2017-12-11 16:46:13 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:52:37 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutPiece::BiggestEdge() const
|
|
|
|
{
|
|
|
|
qreal edge = 0;
|
|
|
|
|
2019-07-22 15:15:28 +02:00
|
|
|
if (LayoutEdgesCount() < 1)
|
2019-03-29 18:52:37 +01:00
|
|
|
{
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
2019-07-22 15:15:28 +02:00
|
|
|
for (int i = 1; i < LayoutEdgesCount(); ++i)
|
2019-03-29 18:52:37 +01:00
|
|
|
{
|
2019-07-22 15:15:28 +02:00
|
|
|
const qreal length = LayoutEdge(i).length();
|
2019-03-29 18:52:37 +01:00
|
|
|
if (length > edge)
|
|
|
|
{
|
|
|
|
edge = length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:54:18 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QRectF VLayoutPiece::BoundingRect(QVector<QPointF> points)
|
|
|
|
{
|
|
|
|
points.append(points.first());
|
|
|
|
return QPolygonF(points).boundingRect();
|
|
|
|
}
|
|
|
|
|
2017-06-29 12:00:06 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector<QPointF> &labelShape,
|
2017-07-01 19:32:54 +02:00
|
|
|
const VTextManager &tm, bool textAsPaths) const
|
2017-06-29 12:00:06 +02:00
|
|
|
{
|
|
|
|
SCASSERT(parent != nullptr)
|
|
|
|
|
|
|
|
if (labelShape.count() > 2)
|
|
|
|
{
|
|
|
|
const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length();
|
|
|
|
const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length();
|
|
|
|
const qreal angle = - QLineF(labelShape.at(0), labelShape.at(1)).angle();
|
|
|
|
qreal dY = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < tm.GetSourceLinesCount(); ++i)
|
|
|
|
{
|
2020-06-04 12:45:32 +02:00
|
|
|
|
2017-06-29 12:00:06 +02:00
|
|
|
const TextLine& tl = tm.GetSourceLine(i);
|
|
|
|
QFont fnt = tm.GetFont();
|
|
|
|
fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize);
|
2019-07-01 10:02:09 +02:00
|
|
|
fnt.setBold(tl.m_bold);
|
|
|
|
fnt.setItalic(tl.m_italic);
|
2017-06-29 12:00:06 +02:00
|
|
|
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
|
2017-07-01 19:32:54 +02:00
|
|
|
if (textAsPaths)
|
|
|
|
{
|
|
|
|
dY += fm.height();
|
|
|
|
}
|
|
|
|
|
2017-06-29 12:00:06 +02:00
|
|
|
if (dY > dH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString qsText = tl.m_qsText;
|
2019-07-24 12:42:22 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
if (fm.horizontalAdvance(qsText) > dW)
|
|
|
|
#else
|
2017-06-29 12:00:06 +02:00
|
|
|
if (fm.width(qsText) > dW)
|
2019-07-24 12:42:22 +02:00
|
|
|
#endif
|
2017-06-29 12:00:06 +02:00
|
|
|
{
|
|
|
|
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
|
|
|
|
}
|
2020-06-04 12:45:32 +02:00
|
|
|
|
|
|
|
qreal dX = 0;
|
|
|
|
if (tl.m_eAlign == 0 || (tl.m_eAlign & Qt::AlignLeft) > 0)
|
2017-06-29 12:00:06 +02:00
|
|
|
{
|
|
|
|
dX = 0;
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
|
|
|
{
|
2019-07-24 12:42:22 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
dX = (dW - fm.horizontalAdvance(qsText))/2;
|
|
|
|
#else
|
2017-06-29 12:00:06 +02:00
|
|
|
dX = (dW - fm.width(qsText))/2;
|
2019-07-24 12:42:22 +02:00
|
|
|
#endif
|
2017-06-29 12:00:06 +02:00
|
|
|
}
|
2020-06-04 12:45:32 +02:00
|
|
|
else if ((tl.m_eAlign & Qt::AlignRight) > 0)
|
2017-06-29 12:00:06 +02:00
|
|
|
{
|
2019-07-24 12:42:22 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
|
|
|
dX = dW - fm.horizontalAdvance(qsText);
|
|
|
|
#else
|
2017-06-29 12:00:06 +02:00
|
|
|
dX = dW - fm.width(qsText);
|
2019-07-24 12:42:22 +02:00
|
|
|
#endif
|
2017-06-29 12:00:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up the rotation around top-left corner matrix
|
|
|
|
QTransform labelMatrix;
|
|
|
|
labelMatrix.translate(labelShape.at(0).x(), labelShape.at(0).y());
|
|
|
|
if (d->mirror)
|
|
|
|
{
|
|
|
|
labelMatrix.scale(-1, 1);
|
2017-07-11 14:14:08 +02:00
|
|
|
labelMatrix.rotate(-angle);
|
2017-06-29 12:00:06 +02:00
|
|
|
labelMatrix.translate(-dW, 0);
|
|
|
|
labelMatrix.translate(dX, dY); // Each string has own position
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelMatrix.rotate(angle);
|
|
|
|
labelMatrix.translate(dX, dY); // Each string has own position
|
|
|
|
}
|
|
|
|
|
|
|
|
labelMatrix *= d->matrix;
|
|
|
|
|
2017-07-01 19:32:54 +02:00
|
|
|
if (textAsPaths)
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
path.addText(0, - static_cast<qreal>(fm.ascent())/6., fnt, qsText);
|
|
|
|
|
|
|
|
QGraphicsPathItem* item = new QGraphicsPathItem(parent);
|
|
|
|
item->setPath(path);
|
|
|
|
item->setBrush(QBrush(Qt::black));
|
|
|
|
item->setTransform(labelMatrix);
|
2017-06-29 12:00:06 +02:00
|
|
|
|
2017-07-01 19:32:54 +02:00
|
|
|
dY += tm.GetSpacing();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsSimpleTextItem* item = new QGraphicsSimpleTextItem(parent);
|
|
|
|
item->setFont(fnt);
|
|
|
|
item->setText(qsText);
|
|
|
|
item->setTransform(labelMatrix);
|
|
|
|
|
|
|
|
dY += (fm.height() + tm.GetSpacing());
|
|
|
|
}
|
2017-06-29 12:00:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-16 11:38:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 13:32:25 +01:00
|
|
|
void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
2017-01-22 13:32:25 +01:00
|
|
|
SCASSERT(parent != nullptr)
|
|
|
|
|
2018-12-27 14:54:29 +01:00
|
|
|
if (not d->grainlineEnabled || d->grainlinePoints.count() < 2)
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
2017-01-22 13:32:25 +01:00
|
|
|
return;
|
2016-10-16 11:38:08 +02:00
|
|
|
}
|
2021-01-23 17:54:07 +01:00
|
|
|
auto* item = new VGraphicsFillItem(parent);
|
2021-02-06 14:52:21 +01:00
|
|
|
item->SetWidth(VAbstractApplication::VApp()->Settings()->WidthHairLine());
|
2017-03-02 08:12:48 +01:00
|
|
|
|
2016-10-16 11:38:08 +02:00
|
|
|
QPainterPath path;
|
2017-04-28 14:37:31 +02:00
|
|
|
|
2021-05-27 18:52:37 +02:00
|
|
|
QVector<QPointF> gPoints = GetMappedGrainline();
|
2017-03-02 08:12:48 +01:00
|
|
|
path.moveTo(gPoints.at(0));
|
2021-01-23 17:54:07 +01:00
|
|
|
for (auto p : qAsConst(gPoints))
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
2018-04-03 13:36:38 +02:00
|
|
|
path.lineTo(p);
|
2016-10-16 11:38:08 +02:00
|
|
|
}
|
|
|
|
item->setPath(path);
|
2017-01-22 13:32:25 +01:00
|
|
|
}
|
|
|
|
|
2016-12-10 17:38:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::DetailPath() const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2017-04-05 12:22:33 +02:00
|
|
|
if (IsSeamAllowance() && not IsSeamAllowanceBuiltIn())
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return d->seamAllowance;
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return d->contour;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-03-02 08:12:48 +01:00
|
|
|
QGraphicsPathItem *VLayoutPiece::GetMainItem() const
|
2017-01-22 09:50:23 +01:00
|
|
|
{
|
2017-03-02 08:12:48 +01:00
|
|
|
QGraphicsPathItem *item = new QGraphicsPathItem();
|
2021-01-23 17:54:07 +01:00
|
|
|
QPen pen = item->pen();
|
2021-02-06 14:52:21 +01:00
|
|
|
pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine());
|
2021-01-23 17:54:07 +01:00
|
|
|
item->setPen(pen);
|
2021-05-27 18:52:37 +02:00
|
|
|
item->setPath(MappedContourPath());
|
2017-03-02 08:12:48 +01:00
|
|
|
return item;
|
2017-01-22 09:50:23 +01:00
|
|
|
}
|
|
|
|
|
2017-07-11 12:53:36 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QGraphicsPathItem *VLayoutPiece::GetMainPathItem() const
|
|
|
|
{
|
|
|
|
QGraphicsPathItem *item = new QGraphicsPathItem();
|
2021-01-23 17:54:07 +01:00
|
|
|
QPen pen = item->pen();
|
2021-02-06 14:52:21 +01:00
|
|
|
pen.setWidthF(VAbstractApplication::VApp()->Settings()->WidthHairLine());
|
2021-01-23 17:54:07 +01:00
|
|
|
item->setPen(pen);
|
2017-07-25 15:33:50 +02:00
|
|
|
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// contour
|
2019-05-27 16:04:26 +02:00
|
|
|
QVector<QPointF> points = GetMappedContourPoints();
|
2017-07-25 15:33:50 +02:00
|
|
|
|
|
|
|
path.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
path.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
path.lineTo(points.at(0));
|
|
|
|
|
|
|
|
item->setPath(path);
|
2017-07-11 12:53:36 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2015-01-18 19:56:01 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
bool VLayoutPiece::IsMirror() const
|
2015-01-18 19:56:01 +01:00
|
|
|
{
|
|
|
|
return d->mirror;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::SetMirror(bool value)
|
2015-01-18 19:56:01 +01:00
|
|
|
{
|
|
|
|
d->mirror = value;
|
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
|
2016-12-10 17:38:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QLineF VLayoutPiece::Edge(const QVector<QPointF> &path, int i) const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2019-07-21 09:34:32 +02:00
|
|
|
if (i < 1)
|
2016-12-10 17:38:34 +01:00
|
|
|
{ // Doesn't exist such edge
|
|
|
|
return QLineF();
|
|
|
|
}
|
|
|
|
|
|
|
|
int i1, i2;
|
|
|
|
if (i < path.count())
|
|
|
|
{
|
|
|
|
i1 = i-1;
|
|
|
|
i2 = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i1 = path.count()-1;
|
|
|
|
i2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mirror)
|
|
|
|
{
|
2019-07-21 09:34:32 +02:00
|
|
|
QVector<QPointF> newPath = Map(path);
|
|
|
|
return QLineF(newPath.at(i1), newPath.at(i2));
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QLineF(d->matrix.map(path.at(i1)), d->matrix.map(path.at(i2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-08-28 14:18:41 +02:00
|
|
|
// NOTE: Once C++17 is made mandatory, this method can further be refactored with std::optional<int>
|
2017-01-22 10:02:02 +01:00
|
|
|
int VLayoutPiece::EdgeByPoint(const QVector<QPointF> &path, const QPointF &p1) const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2020-08-28 14:18:41 +02:00
|
|
|
if (p1.isNull() || path.count() < 3)
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-28 14:18:41 +02:00
|
|
|
const auto points = Map(path);
|
|
|
|
const auto posIter = std::find_if(points.cbegin(), points.cend(),
|
2020-09-22 09:23:27 +02:00
|
|
|
[&p1](const QPointF &point){ return VFuzzyComparePoints(point, p1); });
|
2020-08-28 14:18:41 +02:00
|
|
|
if (posIter != points.cend())
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
2020-08-28 17:32:35 +02:00
|
|
|
return static_cast<int>(posIter - points.cbegin() + 1);
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
|
|
|
return 0; // Did not find edge
|
|
|
|
}
|