2015-01-02 15:14:28 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vlayoutdetail.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 2 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** 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-02 15:14:28 +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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
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>
|
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>
|
|
|
|
|
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"
|
2016-10-16 11:38:08 +02:00
|
|
|
#include "../vmisc/vabstractapplication.h"
|
|
|
|
#include "../vpatterndb/calculator.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
|
|
|
|
2017-02-08 12:48:05 +01:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QVector<VLayoutPiecePath> ConvertInternalPaths(const VPiece &piece, const VContainer *pattern)
|
|
|
|
{
|
|
|
|
QVector<VLayoutPiecePath> paths;
|
|
|
|
const QVector<quint32> pathsId = piece.GetInternalPaths();
|
|
|
|
for (int i = 0; i < pathsId.size(); ++i)
|
|
|
|
{
|
|
|
|
const VPiecePath path = pattern->GetPiecePath(pathsId.at(i));
|
|
|
|
if (path.GetType() == PiecePathType::InternalPath)
|
|
|
|
{
|
|
|
|
paths.append(VLayoutPiecePath(path.PathPoints(pattern), path.GetPenType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern)
|
2017-01-22 09:32:01 +01:00
|
|
|
{
|
2017-01-22 13:32:25 +01:00
|
|
|
VLayoutPiece det;
|
2017-01-22 09:32:01 +01:00
|
|
|
det.SetCountourPoints(piece.MainPathPoints(pattern));
|
2017-01-25 12:29:03 +01:00
|
|
|
det.SetSeamAllowancePoints(piece.SeamAllowancePoints(pattern), piece.IsSeamAllowance());
|
2017-02-08 12:48:05 +01:00
|
|
|
det.SetInternalPaths(ConvertInternalPaths(piece, pattern));
|
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
det.SetName(piece.GetName());
|
2017-02-23 10:19:27 +01:00
|
|
|
const VPieceLabelData& data = piece.GetPatternPieceData();
|
2017-01-22 09:32:01 +01:00
|
|
|
if (data.IsVisible() == true)
|
|
|
|
{
|
|
|
|
det.SetDetail(piece.GetName(), data, qApp->font());
|
|
|
|
}
|
2017-02-23 10:26:25 +01:00
|
|
|
const VPatternLabelData& geom = piece.GetPatternInfo();
|
2017-01-22 09:32:01 +01:00
|
|
|
if (geom.IsVisible() == true)
|
|
|
|
{
|
|
|
|
VAbstractPattern* pDoc = qApp->getCurrentDocument();
|
|
|
|
det.SetPatternInfo(pDoc, geom, qApp->font(), pattern->size(), pattern->height());
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
det.SetGrainline(grainlineGeom, *pattern);
|
|
|
|
}
|
2017-01-22 09:50:23 +01:00
|
|
|
det.SetSAWidth(qApp->toPixel(piece.GetSAWidth()));
|
2017-01-22 09:32:01 +01:00
|
|
|
det.CreateTextItems();
|
2017-01-22 09:50:23 +01:00
|
|
|
det.SetForbidFlipping(piece.IsForbidFlipping());
|
2017-01-22 09:32:01 +01:00
|
|
|
|
|
|
|
return det;
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::GetContourPoints() 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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::SetCountourPoints(const QVector<QPointF> &points)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-01-22 12:21:07 +01:00
|
|
|
d->contour = RemoveDublicates(RoundPoints(points), false);
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2017-01-25 12:29:03 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::GetSeamAllowancePoints() 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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-25 12:29:03 +01:00
|
|
|
void VLayoutPiece::SetSeamAllowancePoints(const QVector<QPointF> &points, bool seamAllowance)
|
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);
|
|
|
|
d->seamAllowance = points;
|
|
|
|
if (not d->seamAllowance.isEmpty())
|
2015-03-14 13:38:44 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
d->seamAllowance = RemoveDublicates(RoundPoints(d->seamAllowance), false);
|
2015-03-14 13:38:44 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-25 12:29:03 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::GetLayoutAllowancePoints() 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
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-23 10:19:27 +01:00
|
|
|
void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, const QFont &font)
|
2016-07-17 22:52:53 +02:00
|
|
|
{
|
2016-07-19 02:26:50 +02:00
|
|
|
d->detailData = data;
|
|
|
|
qreal dAng = qDegreesToRadians(data.GetRotation());
|
|
|
|
QPointF ptCenter(data.GetPos().x() + data.GetLabelWidth()/2, data.GetPos().y() + data.GetLabelHeight()/2);
|
|
|
|
QPointF ptPos = data.GetPos();
|
2016-07-17 22:52:53 +02:00
|
|
|
QVector<QPointF> v;
|
2016-07-19 02:26:50 +02:00
|
|
|
v << ptPos << QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y())
|
|
|
|
<< QPointF(ptPos.x() + data.GetLabelWidth(), ptPos.y() + data.GetLabelHeight())
|
|
|
|
<< QPointF(ptPos.x(), ptPos.y() + data.GetLabelHeight());
|
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
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
d->detailLabel = RoundPoints(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());
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_tmDetail.Update(qsName, data);
|
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());
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_tmDetail.FitFontSize(data.GetLabelWidth(), data.GetLabelHeight());
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-23 10:26:25 +01:00
|
|
|
void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLabelData& geom, const QFont &font,
|
2016-08-15 13:03:59 +02:00
|
|
|
qreal dSize, qreal dHeight)
|
2016-07-17 22:52:53 +02:00
|
|
|
{
|
2016-07-19 13:47:21 +02:00
|
|
|
d->patternGeom = geom;
|
|
|
|
qreal dAng = qDegreesToRadians(geom.GetRotation());
|
|
|
|
QPointF ptCenter(geom.GetPos().x() + geom.GetLabelWidth()/2, geom.GetPos().y() + geom.GetLabelHeight()/2);
|
|
|
|
QPointF ptPos = geom.GetPos();
|
2016-07-17 22:52:53 +02:00
|
|
|
QVector<QPointF> v;
|
2016-07-19 13:47:21 +02:00
|
|
|
v << ptPos << QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y())
|
|
|
|
<< QPointF(ptPos.x() + geom.GetLabelWidth(), ptPos.y() + geom.GetLabelHeight())
|
|
|
|
<< QPointF(ptPos.x(), ptPos.y() + geom.GetLabelHeight());
|
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
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
d->patternInfo = RoundPoints(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
|
|
|
|
2016-08-15 13:03:59 +02:00
|
|
|
d->m_tmPattern.Update(pDoc, dSize, dHeight);
|
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());
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_tmPattern.FitFontSize(geom.GetLabelWidth(), geom.GetLabelHeight());
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
2016-10-16 11:38:08 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-02-23 10:33:17 +01:00
|
|
|
void VLayoutPiece::SetGrainline(const VGrainlineData& geom, const VContainer& rPattern)
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
|
|
|
d->grainlineGeom = geom;
|
|
|
|
qreal dAng;
|
|
|
|
qreal dLen;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QString qsFormula = geom.GetRotation().replace("\n", " ");
|
|
|
|
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
|
|
|
Calculator cal1;
|
|
|
|
dAng = cal1.EvalFormula(rPattern.PlainVariables(), qsFormula);
|
|
|
|
dAng = qDegreesToRadians(dAng);
|
|
|
|
|
|
|
|
qsFormula = geom.GetLength().replace("\n", " ");
|
|
|
|
qsFormula = qApp->TrVars()->FormulaFromUser(qsFormula, qApp->Settings()->GetOsSeparator());
|
|
|
|
Calculator cal2;
|
|
|
|
dLen = cal2.EvalFormula(rPattern.PlainVariables(), qsFormula);
|
|
|
|
dLen = ToPixel(dLen, *rPattern.GetPatternUnit());
|
|
|
|
}
|
2017-02-22 18:49:17 +01:00
|
|
|
catch(qmu::QmuParserError &e)
|
2016-10-16 11:38:08 +02:00
|
|
|
{
|
2017-02-22 18:49:17 +01:00
|
|
|
Q_UNUSED(e);
|
2016-10-16 11:38:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF pt1 = geom.GetPos();
|
|
|
|
QPointF pt2;
|
|
|
|
pt2.setX(pt1.x() + dLen * qCos(dAng));
|
|
|
|
pt2.setY(pt1.y() - dLen * qSin(dAng));
|
|
|
|
QVector<QPointF> v;
|
2016-10-16 15:00:53 +02:00
|
|
|
QPointF pt;
|
|
|
|
qreal dArrowLen = ToPixel(0.5, *rPattern.GetPatternUnit());
|
|
|
|
qreal dArrowAng = M_PI/9;
|
|
|
|
|
|
|
|
v << pt1;
|
|
|
|
|
2017-02-23 10:33:17 +01:00
|
|
|
if (geom.GetArrowType() != VGrainlineData::atRear) {
|
2016-10-25 00:53:01 +02:00
|
|
|
pt.setX(pt1.x() + dArrowLen * qCos(dAng + dArrowAng));
|
|
|
|
pt.setY(pt1.y() - dArrowLen * qSin(dAng + dArrowAng));
|
|
|
|
v << pt;
|
|
|
|
pt.setX(pt1.x() + dArrowLen * qCos(dAng - dArrowAng));
|
|
|
|
pt.setY(pt1.y() - dArrowLen * qSin(dAng - dArrowAng));
|
|
|
|
v << pt;
|
2016-10-16 15:00:53 +02:00
|
|
|
|
2016-10-25 00:53:01 +02:00
|
|
|
v << pt1;
|
|
|
|
}
|
|
|
|
|
|
|
|
v << pt2;
|
2016-10-16 15:00:53 +02:00
|
|
|
|
2017-02-23 10:33:17 +01:00
|
|
|
if (geom.GetArrowType() != VGrainlineData::atFront)
|
2016-10-25 00:53:01 +02:00
|
|
|
{
|
|
|
|
dAng += M_PI;
|
2016-10-16 15:00:53 +02:00
|
|
|
|
2016-10-25 00:53:01 +02:00
|
|
|
pt.setX(pt2.x() + dArrowLen * qCos(dAng + dArrowAng));
|
|
|
|
pt.setY(pt2.y() - dArrowLen * qSin(dAng + dArrowAng));
|
|
|
|
v << pt;
|
|
|
|
pt.setX(pt2.x() + dArrowLen * qCos(dAng - dArrowAng));
|
|
|
|
pt.setY(pt2.y() - dArrowLen * qSin(dAng - dArrowAng));
|
|
|
|
v << pt;
|
2016-10-16 15:00:53 +02:00
|
|
|
|
2016-10-25 00:53:01 +02:00
|
|
|
v << pt2;
|
|
|
|
}
|
2016-10-16 15:00:53 +02:00
|
|
|
|
2016-10-16 11:38:08 +02:00
|
|
|
d->grainlinePoints = RoundPoints(v);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::SetLayoutWidth(const qreal &value)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
d->layoutWidth = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::Translate(qreal dx, qreal dy)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2015-01-18 19:56:01 +01:00
|
|
|
QTransform m;
|
2015-01-16 13:54:37 +01:00
|
|
|
m.translate(dx, dy);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
return d->layoutAllowance.count();
|
2016-12-10 17:38:34 +01:00
|
|
|
}
|
2015-01-19 15:13:26 +01:00
|
|
|
|
2016-12-10 17:38:34 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QLineF VLayoutPiece::DetailEdge(int i) const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
|
|
|
return Edge(DetailPath(), i);
|
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::DetailEdgeByPoint(const QPointF &p1) const
|
2016-12-10 17:38:34 +01:00
|
|
|
{
|
|
|
|
return EdgeByPoint(DetailPath(), p1);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QRectF VLayoutPiece::DetailBoundingRect() const
|
2016-06-21 15:04:15 +02:00
|
|
|
{
|
|
|
|
QVector<QPointF> points;
|
2017-01-22 09:50:23 +01:00
|
|
|
if (IsSeamAllowance())
|
2016-06-21 15:04:15 +02:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
points = GetSeamAllowancePoints();
|
2016-06-21 15:04:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
points = GetContourPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
points.append(points.first());
|
|
|
|
return QPolygonF(points).boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QRectF VLayoutPiece::LayoutBoundingRect() const
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
QVector<QPointF> points = GetLayoutAllowancePoints();
|
2015-01-10 14:47:46 +01:00
|
|
|
points.append(points.first());
|
2016-02-23 13:13:10 +01:00
|
|
|
return QPolygonF(points).boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
qreal VLayoutPiece::Diagonal() const
|
2016-02-23 13:13:10 +01:00
|
|
|
{
|
2016-06-21 15:04:15 +02:00
|
|
|
const QRectF rec = LayoutBoundingRect();
|
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-01-25 12:29:03 +01:00
|
|
|
if (IsSeamAllowance() && 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
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
if (d->layoutAllowance.isEmpty()) //-V807
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-25 12:29:03 +01:00
|
|
|
const qreal res = SumTrapezoids(d->layoutAllowance);
|
2015-01-11 14:11:56 +01:00
|
|
|
|
2015-11-22 14:58:31 +01:00
|
|
|
const qint64 sq = qFloor(qAbs(res/2.0));
|
2015-01-11 14:11:56 +01:00
|
|
|
return sq;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-25 12:29:03 +01:00
|
|
|
void VLayoutPiece::SetLayoutAllowancePoints()
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
if (d->layoutWidth > 0)
|
|
|
|
{
|
2017-01-22 09:50:23 +01:00
|
|
|
if (IsSeamAllowance())
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance = Equidistant(PrepareAllowance(GetSeamAllowancePoints()), d->layoutWidth);
|
|
|
|
if (d->layoutAllowance.isEmpty() == false)
|
2015-01-16 13:54:37 +01:00
|
|
|
{
|
2015-04-01 20:38:42 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.remove(d->layoutAllowance.size() - 1);
|
2015-04-01 20:38:42 +02:00
|
|
|
#else
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.removeLast();
|
2015-04-01 20:38:42 +02:00
|
|
|
#endif
|
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 = Equidistant(PrepareAllowance(GetContourPoints()), d->layoutWidth);
|
|
|
|
if (d->layoutAllowance.isEmpty() == false)
|
2015-01-16 13:54:37 +01:00
|
|
|
{
|
2015-04-01 20:38:42 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.remove(d->layoutAllowance.size() - 1);
|
2015-04-01 20:38:42 +02:00
|
|
|
#else
|
2017-01-25 12:29:03 +01:00
|
|
|
d->layoutAllowance.removeLast();
|
2015-04-01 20:38:42 +02:00
|
|
|
#endif
|
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-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
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::Map(const QVector<QPointF> &points) const
|
2015-01-02 15:14:28 +01:00
|
|
|
{
|
2015-01-07 17:54:43 +01:00
|
|
|
QVector<QPointF> p;
|
|
|
|
for (int i = 0; i < points.size(); ++i)
|
|
|
|
{
|
|
|
|
p.append(d->matrix.map(points.at(i)));
|
|
|
|
}
|
2015-01-10 14:47:46 +01:00
|
|
|
|
2015-01-18 19:56:01 +01:00
|
|
|
if (d->mirror)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
|
|
|
QList<QPointF> list = p.toList();
|
2015-03-02 18:11:43 +01:00
|
|
|
for (int k=0, s=list.size(), max=(s/2); k<max; k++)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
|
|
|
list.swap(k, s-(1+k));
|
|
|
|
}
|
|
|
|
p = list.toVector();
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
return p;
|
2015-01-02 15:14:28 +01:00
|
|
|
}
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2015-01-16 13:54:37 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::RoundPoints(const QVector<QPointF> &points)
|
2015-01-16 13:54:37 +01:00
|
|
|
{
|
|
|
|
QVector<QPointF> p;
|
|
|
|
for (int i=0; i < points.size(); ++i)
|
|
|
|
{
|
|
|
|
p.append(QPointF(qRound(points.at(i).x()), qRound(points.at(i).y())));
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// contour
|
2016-12-10 17:38:34 +01:00
|
|
|
QVector<QPointF> points = GetContourPoints();
|
2015-01-13 11:38:51 +01:00
|
|
|
path.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2015-01-13 11:38:51 +01:00
|
|
|
path.lineTo(points.at(i));
|
2015-01-12 21:35:32 +01:00
|
|
|
}
|
2015-01-13 11:38:51 +01:00
|
|
|
path.lineTo(points.at(0));
|
2015-01-12 21:35:32 +01:00
|
|
|
|
2017-01-23 17:20:15 +01:00
|
|
|
// seam allowance
|
2017-01-22 09:50:23 +01:00
|
|
|
if (IsSeamAllowance() == true)
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2017-01-25 12:29:03 +01:00
|
|
|
points = GetSeamAllowancePoints();
|
2015-01-16 20:35:50 +01:00
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
if (points.last().toPoint() != points.first().toPoint())
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2017-01-22 09:50:23 +01:00
|
|
|
points.append(points.at(0));// Should be always closed
|
2015-01-12 21:35:32 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 20:35:50 +01:00
|
|
|
QPainterPath ekv;
|
|
|
|
ekv.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
2015-01-12 21:35:32 +01:00
|
|
|
{
|
2015-01-16 20:35:50 +01:00
|
|
|
ekv.lineTo(points.at(i));
|
2015-01-12 21:35:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(ekv);
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
}
|
|
|
|
|
2016-07-19 09:06:29 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::ClearTextItems()
|
2016-07-19 09:06:29 +02:00
|
|
|
{
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_liPP.clear();
|
2016-07-19 09:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VLayoutPiece::CreateTextItems()
|
2016-07-19 09:06:29 +02:00
|
|
|
{
|
|
|
|
ClearTextItems();
|
2016-07-19 13:47:21 +02:00
|
|
|
// first add detail texts
|
2016-07-19 09:06:29 +02:00
|
|
|
if (d->detailLabel.count() > 0)
|
|
|
|
{
|
2016-07-23 15:26:15 +02:00
|
|
|
// get the mapped label vertices
|
2016-07-19 09:06:29 +02:00
|
|
|
QVector<QPointF> points = Map(Mirror(d->detailLabel));
|
2016-07-23 15:26:15 +02:00
|
|
|
// append the first point to obtain the closed rectangle
|
2016-07-19 09:06:29 +02:00
|
|
|
points.push_back(points.at(0));
|
2016-07-23 15:26:15 +02:00
|
|
|
// calculate the angle of rotation
|
2016-07-19 02:26:50 +02:00
|
|
|
qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x());
|
2016-12-14 00:56:30 +01:00
|
|
|
// calculate the label width and height
|
2016-07-19 02:26:50 +02:00
|
|
|
qreal dW = GetDistance(points.at(0), points.at(1));
|
2016-12-14 00:56:30 +01:00
|
|
|
qreal dH = GetDistance(points.at(1), points.at(2));
|
2016-07-19 02:26:50 +02:00
|
|
|
qreal dY = 0;
|
|
|
|
qreal dX;
|
2016-07-23 15:26:15 +02:00
|
|
|
// set up the rotation around top-left corner matrix
|
|
|
|
QMatrix mat;
|
|
|
|
mat.translate(points.at(0).x(), points.at(0).y());
|
|
|
|
mat.rotate(qRadiansToDegrees(dAng));
|
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
for (int i = 0; i < d->m_tmDetail.GetSourceLinesCount(); ++i)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
const TextLine& tl = d->m_tmDetail.GetSourceLine(i);
|
2016-07-22 12:50:21 +02:00
|
|
|
QFont fnt = d->m_tmDetail.GetFont();
|
|
|
|
fnt.setPixelSize(d->m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize);
|
2016-07-19 02:26:50 +02:00
|
|
|
fnt.setWeight(tl.m_eFontWeight);
|
|
|
|
fnt.setStyle(tl.m_eStyle);
|
2016-12-15 07:46:45 +01:00
|
|
|
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
|
|
|
|
dY += fm.height();
|
2016-12-14 00:56:30 +01:00
|
|
|
// check if the next line will go out of bounds
|
|
|
|
if (dY > dH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-07-19 09:06:29 +02:00
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
QString qsText = tl.m_qsText;
|
|
|
|
if (fm.width(qsText) > dW)
|
|
|
|
{
|
2016-12-14 10:59:21 +01:00
|
|
|
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
|
2016-12-14 00:56:30 +01:00
|
|
|
}
|
2016-07-23 15:26:15 +02:00
|
|
|
// find the correct horizontal offset, depending on the alignment flag
|
2016-07-19 02:26:50 +02:00
|
|
|
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
|
|
|
|
{
|
|
|
|
dX = 0;
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
dX = (dW - fm.width(qsText))/2;
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
dX = dW - fm.width(qsText);
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
2016-07-23 15:26:15 +02:00
|
|
|
// create text path and add it to the list
|
2016-07-19 09:06:29 +02:00
|
|
|
QPainterPath path;
|
2016-12-14 00:56:30 +01:00
|
|
|
path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText);
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_liPP << mat.map(path);
|
|
|
|
dY += d->m_tmDetail.GetSpacing();
|
2016-07-19 02:26:50 +02:00
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
2016-07-19 13:47:21 +02:00
|
|
|
// and then add pattern texts
|
|
|
|
if (d->patternInfo.count() > 0)
|
|
|
|
{
|
2016-07-23 15:26:15 +02:00
|
|
|
// similar approach like for the detail label
|
2016-07-19 13:47:21 +02:00
|
|
|
QVector<QPointF> points = Map(Mirror(d->patternInfo));
|
|
|
|
points.push_back(points.at(0));
|
|
|
|
qreal dAng = qAtan2(points.at(1).y() - points.at(0).y(), points.at(1).x() - points.at(0).x());
|
|
|
|
qreal dW = GetDistance(points.at(0), points.at(1));
|
2016-12-14 00:56:30 +01:00
|
|
|
qreal dH = GetDistance(points.at(1), points.at(2));
|
2016-07-19 13:47:21 +02:00
|
|
|
qreal dY = 0;
|
|
|
|
qreal dX;
|
2016-07-23 15:26:15 +02:00
|
|
|
QMatrix mat;
|
|
|
|
mat.translate(points.at(0).x(), points.at(0).y());
|
|
|
|
mat.rotate(qRadiansToDegrees(dAng));
|
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
for (int i = 0; i < d->m_tmPattern.GetSourceLinesCount(); ++i)
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
const TextLine& tl = d->m_tmPattern.GetSourceLine(i);
|
2016-07-22 12:50:21 +02:00
|
|
|
QFont fnt = d->m_tmPattern.GetFont();
|
|
|
|
fnt.setPixelSize(d->m_tmPattern.GetFont().pixelSize() + tl.m_iFontSize);
|
2016-07-19 13:47:21 +02:00
|
|
|
fnt.setWeight(tl.m_eFontWeight);
|
|
|
|
fnt.setStyle(tl.m_eStyle);
|
2016-12-15 07:46:45 +01:00
|
|
|
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
|
|
|
|
dY += fm.height();
|
2016-12-14 00:56:30 +01:00
|
|
|
if (dY > dH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2016-07-19 13:47:21 +02:00
|
|
|
|
2016-12-14 00:56:30 +01:00
|
|
|
QString qsText = tl.m_qsText;
|
|
|
|
if (fm.width(qsText) > dW)
|
|
|
|
{
|
2016-12-14 10:59:21 +01:00
|
|
|
qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast<int>(dW));
|
2016-12-14 00:56:30 +01:00
|
|
|
}
|
2016-07-19 13:47:21 +02:00
|
|
|
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
|
|
|
|
{
|
|
|
|
dX = 0;
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
dX = (dW - fm.width(qsText))/2;
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-14 00:56:30 +01:00
|
|
|
dX = dW - fm.width(qsText);
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
|
|
|
QPainterPath path;
|
2016-12-14 00:56:30 +01:00
|
|
|
path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText);
|
2016-07-22 12:50:21 +02:00
|
|
|
d->m_liPP << mat.map(path);
|
|
|
|
dY += d->m_tmPattern.GetSpacing();
|
2016-07-19 13:47:21 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-19 09:06:29 +02:00
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
|
2017-02-08 12:48:05 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutPiece::CreateInternalPathItem(int i, QGraphicsItem *parent) const
|
|
|
|
{
|
|
|
|
SCASSERT(parent != nullptr)
|
|
|
|
QGraphicsPathItem* item = new QGraphicsPathItem(parent);
|
|
|
|
item->setPath(d->matrix.map(d->m_internalPaths.at(i).GetPainterPath()));
|
|
|
|
|
|
|
|
QPen pen = item->pen();
|
|
|
|
pen.setStyle(d->m_internalPaths.at(i).PenStyle());
|
|
|
|
item->setPen(pen);
|
|
|
|
}
|
|
|
|
|
2016-07-19 09:06:29 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
2017-01-22 13:32:25 +01:00
|
|
|
* @brief CreateTextItem Creates the i-th text item
|
2016-07-23 15:26:15 +02:00
|
|
|
* @param i index of the requested item
|
2017-01-22 13:32:25 +01:00
|
|
|
* @param parent parent of this text item. Can't be null.
|
2016-07-23 15:26:15 +02:00
|
|
|
*/
|
2017-01-22 13:32:25 +01:00
|
|
|
void VLayoutPiece::CreateTextItem(int i, QGraphicsItem *parent) const
|
2016-07-19 09:06:29 +02:00
|
|
|
{
|
2017-01-22 13:32:25 +01:00
|
|
|
SCASSERT(parent != nullptr)
|
|
|
|
|
|
|
|
QGraphicsPathItem* item = new QGraphicsPathItem(parent);
|
2017-02-08 12:48:05 +01:00
|
|
|
QPainterPath path = d->matrix.map(d->m_liPP.at(i));
|
2016-07-17 22:52:53 +02:00
|
|
|
|
2016-07-19 09:06:29 +02:00
|
|
|
if (d->mirror == true)
|
|
|
|
{
|
2016-07-19 13:47:21 +02:00
|
|
|
QVector<QPointF> points;
|
2016-12-14 00:56:30 +01:00
|
|
|
if (i < d->m_tmDetail.GetSourceLinesCount())
|
2016-07-19 13:47:21 +02:00
|
|
|
{
|
|
|
|
points = Map(Mirror(d->detailLabel));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
points = Map(Mirror(d->patternInfo));
|
|
|
|
}
|
2016-07-19 09:06:29 +02:00
|
|
|
QPointF ptCenter = (points.at(1) + points.at(3))/2;
|
2017-02-08 12:48:05 +01:00
|
|
|
qreal dRot = qRadiansToDegrees(qAtan2(points.at(1).y() - points.at(0).y(),
|
|
|
|
points.at(1).x() - points.at(0).x()));
|
2016-07-19 09:06:29 +02:00
|
|
|
|
|
|
|
// we need to move the center back to the origin, rotate it to align it with x axis,
|
2016-07-23 15:26:15 +02:00
|
|
|
// then mirror it to obtain the proper text direction, rotate it and translate it back to original position.
|
|
|
|
// The operations must be added in reverse order
|
2016-07-19 09:06:29 +02:00
|
|
|
QTransform t;
|
2016-07-23 15:26:15 +02:00
|
|
|
// move the label back to its original position
|
2016-07-19 09:06:29 +02:00
|
|
|
t.translate(ptCenter.x(), ptCenter.y());
|
2016-07-23 15:26:15 +02:00
|
|
|
// rotate the label back to original angle
|
2016-07-19 09:06:29 +02:00
|
|
|
t.rotate(dRot);
|
2016-07-23 15:26:15 +02:00
|
|
|
// mirror the label horizontally
|
2016-07-19 09:06:29 +02:00
|
|
|
t.scale(-1, 1);
|
2016-07-23 15:26:15 +02:00
|
|
|
// rotate the label to normal position
|
2016-07-19 09:06:29 +02:00
|
|
|
t.rotate(-dRot);
|
2016-07-23 15:26:15 +02:00
|
|
|
// move the label center into origin
|
2016-07-19 09:06:29 +02:00
|
|
|
t.translate(-ptCenter.x(), -ptCenter.y());
|
|
|
|
path = t.map(path);
|
|
|
|
}
|
2016-07-19 13:47:21 +02:00
|
|
|
|
2016-07-19 09:06:29 +02:00
|
|
|
item->setPath(path);
|
|
|
|
item->setBrush(QBrush(Qt::black));
|
2015-01-12 21:35:32 +01:00
|
|
|
}
|
2015-01-13 11:38:51 +01:00
|
|
|
|
2016-03-28 10:53:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-25 12:29:03 +01:00
|
|
|
QPainterPath VLayoutPiece::LayoutAllowancePath() const
|
2016-03-28 10:53:02 +02:00
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
|
2017-01-25 12:29:03 +01:00
|
|
|
const QVector<QPointF> points = GetLayoutAllowancePoints();
|
2016-03-28 10:53:02 +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));
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
QGraphicsItem *VLayoutPiece::GetItem() const
|
2015-01-13 11:38:51 +01:00
|
|
|
{
|
|
|
|
QGraphicsPathItem *item = new QGraphicsPathItem();
|
2017-02-08 12:48:05 +01:00
|
|
|
item->setPath(ContourPath());
|
|
|
|
|
|
|
|
for (int i = 0; i < d->m_internalPaths.count(); ++i)
|
|
|
|
{
|
|
|
|
CreateInternalPathItem(i, item);
|
|
|
|
}
|
2017-01-22 13:32:25 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < d->m_liPP.count(); ++i)
|
|
|
|
{
|
|
|
|
CreateTextItem(i, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateGrainlineItem(item);
|
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
return item;
|
|
|
|
}
|
2015-01-18 19:56:01 +01: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)
|
|
|
|
|
2016-10-25 00:53:01 +02:00
|
|
|
if (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
|
|
|
}
|
2017-01-22 13:32:25 +01:00
|
|
|
VGraphicsFillItem* item = new VGraphicsFillItem(parent);
|
2016-10-16 11:38:08 +02:00
|
|
|
QPainterPath path;
|
|
|
|
QVector<QPointF> v = Map(d->grainlinePoints);
|
|
|
|
path.moveTo(v.at(0));
|
|
|
|
for (int i = 1; i < v.count(); ++i)
|
|
|
|
{
|
|
|
|
path.lineTo(v.at(i));
|
|
|
|
}
|
|
|
|
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-01-22 09:50:23 +01:00
|
|
|
if (IsSeamAllowance())
|
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-01-22 10:02:02 +01:00
|
|
|
QVector<VSAPoint> VLayoutPiece::PrepareAllowance(const QVector<QPointF> &points)
|
2017-01-22 09:50:23 +01:00
|
|
|
{
|
|
|
|
QVector<VSAPoint> allowancePoints;
|
2017-01-22 12:20:04 +01:00
|
|
|
for(int i = 0; i < points.size(); ++i)
|
2017-01-22 09:50:23 +01:00
|
|
|
{
|
|
|
|
allowancePoints.append(VSAPoint(points.at(i)));
|
|
|
|
}
|
|
|
|
return allowancePoints;
|
|
|
|
}
|
|
|
|
|
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-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2017-01-22 10:02:02 +01:00
|
|
|
QPointF VLayoutPiece::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng)
|
2016-07-17 22:52:53 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2016-07-18 20:38:27 +02:00
|
|
|
|
2016-07-19 02:26:50 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VLayoutDetail::Mirror if the detail layout is rotated, this method will flip the
|
|
|
|
* label points over vertical axis, which goes through the center of the label
|
2016-11-01 09:42:32 +01:00
|
|
|
* @param points list of 4 label vertices
|
2016-07-23 15:26:15 +02:00
|
|
|
* @return list of flipped points
|
|
|
|
*/
|
2017-01-22 10:02:02 +01:00
|
|
|
QVector<QPointF> VLayoutPiece::Mirror(const QVector<QPointF> &points) const
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
|
|
|
// should only call this method with rectangular shapes
|
|
|
|
Q_ASSERT(points.count() == 4);
|
|
|
|
if (d->mirror == false)
|
|
|
|
{
|
|
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QPointF> v;
|
|
|
|
v.resize(4);
|
|
|
|
v[0] = points.at(2);
|
|
|
|
v[1] = points.at(3);
|
|
|
|
v[2] = points.at(0);
|
|
|
|
v[3] = points.at(1);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-23 15:26:15 +02:00
|
|
|
/**
|
|
|
|
* @brief VLayoutDetail::GetDistance calculates the Euclidian distance between the points
|
|
|
|
* @param pt1 first point
|
|
|
|
* @param pt2 second point
|
|
|
|
* @return Euclidian distance between the two points
|
|
|
|
*/
|
2017-01-22 10:02:02 +01:00
|
|
|
qreal VLayoutPiece::GetDistance(const QPointF &pt1, const QPointF &pt2)
|
2016-07-19 02:26:50 +02:00
|
|
|
{
|
2016-08-02 14:12:13 +02:00
|
|
|
const qreal dX = pt1.x() - pt2.x();
|
|
|
|
const qreal dY = pt1.y() - pt2.y();
|
2016-07-19 02:26:50 +02:00
|
|
|
|
|
|
|
return qSqrt(dX*dX + dY*dY);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (i < 1 || i > path.count())
|
|
|
|
{ // 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)
|
|
|
|
{
|
|
|
|
const int oldI1 = i1;
|
|
|
|
const int size = path.size()-1; //-V807
|
|
|
|
i1 = size - i2;
|
|
|
|
i2 = size - oldI1;
|
|
|
|
return QLineF(d->matrix.map(path.at(i2)), d->matrix.map(path.at(i1)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QLineF(d->matrix.map(path.at(i1)), d->matrix.map(path.at(i2)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
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
|
|
|
{
|
|
|
|
if (p1.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path.count() < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<QPointF> points = Map(path);
|
|
|
|
for (int i=0; i < points.size(); i++)
|
|
|
|
{
|
|
|
|
if (points.at(i) == p1)
|
|
|
|
{
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; // Did not find edge
|
|
|
|
}
|