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/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vlayoutdetail.h"
|
2015-01-07 17:54:43 +01:00
|
|
|
#include "vlayoutdetail_p.h"
|
2015-01-02 15:14:28 +01:00
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
#include <QGraphicsItem>
|
2015-01-12 21:35:32 +01:00
|
|
|
#include <QPainterPath>
|
2016-07-18 20:38:27 +02:00
|
|
|
#include <QFont>
|
2016-07-19 02:26:50 +02:00
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QApplication>
|
2015-10-08 19:07:48 +02:00
|
|
|
|
2015-04-01 20:21:24 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
2015-10-08 19:07:48 +02:00
|
|
|
# include "../vmisc/vmath.h"
|
2015-04-01 20:21:24 +02:00
|
|
|
#else
|
|
|
|
# include <QtMath>
|
|
|
|
#endif
|
2015-10-08 19:07:48 +02:00
|
|
|
|
2015-03-14 13:38:44 +01:00
|
|
|
#include <QDebug>
|
2015-01-11 14:11:56 +01:00
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 15:14:28 +01:00
|
|
|
VLayoutDetail::VLayoutDetail()
|
2016-07-19 02:26:50 +02:00
|
|
|
:VAbstractDetail(), d(new VLayoutDetailData), m_tmDetail()
|
2015-01-07 17:54:43 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail)
|
2016-07-19 02:26:50 +02:00
|
|
|
:VAbstractDetail(detail), d(detail.d), m_tmDetail(detail.m_tmDetail)
|
2015-01-07 17:54:43 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail)
|
|
|
|
{
|
|
|
|
if ( &detail == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VAbstractDetail::operator=(detail);
|
|
|
|
d = detail.d;
|
2016-07-19 02:26:50 +02:00
|
|
|
m_tmDetail = detail.m_tmDetail;
|
2015-01-07 17:54:43 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail::~VLayoutDetail()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-01-11 14:11:56 +01:00
|
|
|
QVector<QPointF> VLayoutDetail::GetContourPoints() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
return d->contour;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-11 14:11:56 +01:00
|
|
|
void VLayoutDetail::SetCountourPoints(const QVector<QPointF> &points)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-05-17 17:31:17 +02:00
|
|
|
d->contour = RemoveDublicates(RoundPoints(points));
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-01-07 17:54:43 +01:00
|
|
|
QVector<QPointF> VLayoutDetail::GetSeamAllowencePoints() const
|
|
|
|
{
|
|
|
|
return d->seamAllowence;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-11-15 18:06:25 +01:00
|
|
|
void VLayoutDetail::SetSeamAllowencePoints(const QVector<QPointF> &points, bool seamAllowence, bool closed)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-03-14 13:38:44 +01:00
|
|
|
if (seamAllowence)
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2015-03-14 13:38:44 +01:00
|
|
|
setSeamAllowance(seamAllowence);
|
2015-11-15 18:06:25 +01:00
|
|
|
setClosed(closed);
|
2015-03-14 13:38:44 +01:00
|
|
|
d->seamAllowence = points;
|
|
|
|
if (not d->seamAllowence.isEmpty())
|
|
|
|
{
|
|
|
|
d->seamAllowence = RemoveDublicates(RoundPoints(d->seamAllowence));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"Seam allowence is empty.";
|
|
|
|
setSeamAllowance(false);
|
|
|
|
}
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-11 14:11:56 +01:00
|
|
|
QVector<QPointF> VLayoutDetail::GetLayoutAllowencePoints() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
return Map(d->layoutAllowence);
|
|
|
|
}
|
|
|
|
|
2016-07-17 22:52:53 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-19 02:26:50 +02:00
|
|
|
void VLayoutDetail::SetDetail(const QString& qsName, const VPatternPieceData& data)
|
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)
|
|
|
|
v[i] = RotatePoint(ptCenter, v[i], dAng);
|
|
|
|
d->detailLabel = RoundPoints(v);
|
2016-07-19 02:26:50 +02:00
|
|
|
|
|
|
|
// generate text
|
|
|
|
QFont fnt = QApplication::font();
|
|
|
|
m_tmDetail.SetFont(fnt);
|
|
|
|
m_tmDetail.SetFontSize(data.GetFontSize());
|
|
|
|
m_tmDetail.Clear();
|
|
|
|
TextLine tl;
|
|
|
|
// letter
|
|
|
|
tl.m_qsText = data.GetLetter();
|
|
|
|
if (tl.m_qsText.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_eAlign = Qt::AlignCenter;
|
|
|
|
tl.m_eFontWeight = QFont::Bold;
|
|
|
|
tl.m_eStyle = QFont::StyleNormal;
|
|
|
|
tl.m_iFontSize = 6;
|
|
|
|
m_tmDetail.AddLine(tl);
|
|
|
|
}
|
|
|
|
// name
|
|
|
|
if (qsName.isEmpty() == false)
|
|
|
|
{
|
|
|
|
tl.m_qsText = qsName;
|
|
|
|
tl.m_eFontWeight = QFont::DemiBold;
|
|
|
|
tl.m_iFontSize = 2;
|
|
|
|
m_tmDetail.AddLine(tl);
|
|
|
|
}
|
|
|
|
|
|
|
|
// MCP
|
|
|
|
QString qsText = "Cut %1 of %2%3";
|
|
|
|
QStringList qslPlace;
|
|
|
|
qslPlace << "" << " on Fold";
|
|
|
|
tl.m_eAlign = Qt::AlignLeft | Qt::AlignVCenter;
|
|
|
|
tl.m_eFontWeight = QFont::Normal;
|
|
|
|
tl.m_iFontSize = 0;
|
|
|
|
for (int i = 0; i < data.GetMCPCount(); ++i)
|
|
|
|
{
|
|
|
|
MaterialCutPlacement mcp = data.GetMCP(i);
|
|
|
|
if (mcp.m_iCutNumber > 0)
|
|
|
|
{
|
|
|
|
tl.m_qsText = qsText.arg(mcp.m_iCutNumber).arg(mcp.m_qsMaterialUserDef).arg(qslPlace[int(mcp.m_ePlacement)]);
|
|
|
|
m_tmDetail.AddLine(tl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// will generate the lines of text
|
|
|
|
m_tmDetail.IsBigEnough(data.GetLabelWidth(), data.GetLabelHeight(), data.GetFontSize());
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::GetPatternInfoPoints() const
|
|
|
|
{
|
|
|
|
return d->patternInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetPatternInfoPoints(const QPointF& ptPos, qreal dWidth, qreal dHeight, qreal dRot)
|
|
|
|
{
|
|
|
|
qreal dAng = qDegreesToRadians(dRot);
|
|
|
|
QPointF ptCenter(ptPos.x() + dWidth/2, ptPos.y() + dHeight/2);
|
|
|
|
QVector<QPointF> v;
|
|
|
|
v << ptPos << QPointF(ptPos.x() + dWidth, ptPos.y()) << QPointF(ptPos.x() + dWidth, ptPos.y() + dHeight)
|
2016-07-18 20:38:27 +02:00
|
|
|
<< QPointF(ptPos.x(), ptPos.y() + dHeight);
|
2016-07-17 22:52:53 +02:00
|
|
|
for (int i = 0; i < v.count(); ++i)
|
|
|
|
v[i] = RotatePoint(ptCenter, v[i], dAng);
|
|
|
|
d->patternInfo = RoundPoints(v);
|
|
|
|
}
|
|
|
|
|
2015-01-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-18 19:56:01 +01:00
|
|
|
QTransform VLayoutDetail::GetMatrix() const
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
return d->matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-18 19:56:01 +01:00
|
|
|
void VLayoutDetail::SetMatrix(const QTransform &matrix)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
d->matrix = matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutDetail::GetLayoutWidth() const
|
|
|
|
{
|
|
|
|
return d->layoutWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetLayoutWidth(const qreal &value)
|
|
|
|
{
|
|
|
|
d->layoutWidth = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-10 14:47:46 +01:00
|
|
|
void VLayoutDetail::Translate(qreal dx, qreal dy)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-10 14:47:46 +01:00
|
|
|
void VLayoutDetail::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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutDetail::EdgesCount() const
|
|
|
|
{
|
2015-01-10 14:47:46 +01:00
|
|
|
return d->layoutAllowence.count();
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QLineF VLayoutDetail::Edge(int i) const
|
|
|
|
{
|
|
|
|
if (i < 1 || i > EdgesCount())
|
|
|
|
{ // Doesn't exist such edge
|
|
|
|
return QLineF();
|
|
|
|
}
|
2015-01-19 15:13:26 +01:00
|
|
|
|
|
|
|
int i1, i2;
|
2015-01-10 14:47:46 +01:00
|
|
|
if (i < EdgesCount())
|
|
|
|
{
|
2015-01-19 15:13:26 +01:00
|
|
|
i1 = i-1;
|
|
|
|
i2 = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i1 = EdgesCount()-1;
|
|
|
|
i2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mirror)
|
|
|
|
{
|
|
|
|
const int oldI1 = i1;
|
2015-11-15 18:06:25 +01:00
|
|
|
const int size = d->layoutAllowence.size()-1; //-V807
|
2015-10-28 15:22:36 +01:00
|
|
|
i1 = size - i2;
|
|
|
|
i2 = size - oldI1;
|
2015-01-19 15:13:26 +01:00
|
|
|
return QLineF(d->matrix.map(d->layoutAllowence.at(i2)), d->matrix.map(d->layoutAllowence.at(i1)));
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-19 15:13:26 +01:00
|
|
|
return QLineF(d->matrix.map(d->layoutAllowence.at(i1)), d->matrix.map(d->layoutAllowence.at(i2)));
|
2015-01-10 14:47:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutDetail::EdgeByPoint(const QPointF &p1) const
|
|
|
|
{
|
|
|
|
if (p1.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EdgesCount() < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-11 14:11:56 +01:00
|
|
|
const QVector<QPointF> points = GetLayoutAllowencePoints();
|
2015-01-10 14:47:46 +01:00
|
|
|
for (int i=0; i< points.size(); i++)
|
|
|
|
{
|
|
|
|
if (points.at(i) == p1)
|
|
|
|
{
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; // Did not find edge
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-06-21 15:04:15 +02:00
|
|
|
QRectF VLayoutDetail::DetailBoundingRect() const
|
|
|
|
{
|
|
|
|
QVector<QPointF> points;
|
|
|
|
if (getSeamAllowance())
|
|
|
|
{
|
|
|
|
points = GetSeamAllowencePoints();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
points = GetContourPoints();
|
|
|
|
}
|
|
|
|
|
|
|
|
points.append(points.first());
|
|
|
|
return QPolygonF(points).boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QRectF VLayoutDetail::LayoutBoundingRect() const
|
2015-01-10 14:47:46 +01:00
|
|
|
{
|
2015-01-11 14:11:56 +01:00
|
|
|
QVector<QPointF> points = GetLayoutAllowencePoints();
|
2015-01-10 14:47:46 +01:00
|
|
|
points.append(points.first());
|
2016-02-23 13:13:10 +01:00
|
|
|
return QPolygonF(points).boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutDetail::Diagonal() const
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-11 14:11:56 +01:00
|
|
|
bool VLayoutDetail::isNull() const
|
|
|
|
{
|
|
|
|
if (d->contour.isEmpty() == false && d->layoutWidth > 0)
|
|
|
|
{
|
|
|
|
if (getSeamAllowance() && d->seamAllowence.isEmpty() == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qint64 VLayoutDetail::Square() const
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
if (d->layoutAllowence.isEmpty()) //-V807
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-22 15:47:50 +01:00
|
|
|
const qreal res = SumTrapezoids(d->layoutAllowence);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetLayoutAllowencePoints()
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
|
|
|
if (d->layoutWidth > 0)
|
|
|
|
{
|
|
|
|
if (getSeamAllowance())
|
|
|
|
{
|
|
|
|
d->layoutAllowence = Equidistant(d->seamAllowence, EquidistantType::CloseEquidistant, d->layoutWidth);
|
2015-01-16 13:54:37 +01:00
|
|
|
if (d->layoutAllowence.isEmpty() == false)
|
|
|
|
{
|
2015-04-01 20:38:42 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
d->layoutAllowence.remove(d->layoutAllowence.size() - 1);
|
|
|
|
#else
|
|
|
|
d->layoutAllowence.removeLast();
|
|
|
|
#endif
|
2015-01-16 13:54:37 +01:00
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->layoutAllowence = Equidistant(d->contour, EquidistantType::CloseEquidistant, d->layoutWidth);
|
2015-01-16 13:54:37 +01:00
|
|
|
if (d->layoutAllowence.isEmpty() == false)
|
|
|
|
{
|
2015-04-01 20:38:42 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
d->layoutAllowence.remove(d->layoutAllowence.size() - 1);
|
|
|
|
#else
|
2015-01-16 13:54:37 +01:00
|
|
|
d->layoutAllowence.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
|
|
|
|
{
|
|
|
|
d->layoutAllowence.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-03-02 18:54:33 +01:00
|
|
|
QVector<QPointF> VLayoutDetail::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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPainterPath VLayoutDetail::ContourPath() const
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
|
|
|
|
// contour
|
2015-01-13 11:38:51 +01:00
|
|
|
QVector<QPointF> points = Map(d->contour);
|
|
|
|
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
|
|
|
|
|
|
|
// seam allowence
|
|
|
|
if (getSeamAllowance() == true)
|
|
|
|
{
|
2015-01-13 11:38:51 +01:00
|
|
|
points = Map(d->seamAllowence);
|
2015-01-16 20:35:50 +01:00
|
|
|
|
2015-01-12 21:35:32 +01:00
|
|
|
if (getClosed() == true)
|
|
|
|
{
|
2015-01-16 20:35:50 +01:00
|
|
|
points.append(points.at(0));
|
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-17 22:52:53 +02:00
|
|
|
if (d->detailLabel.count() > 0)
|
|
|
|
{
|
2016-07-19 02:26:50 +02:00
|
|
|
points = Map(Mirror(d->detailLabel));
|
2016-07-18 20:38:27 +02:00
|
|
|
points.push_back(points.at(0));
|
2016-07-17 22:52:53 +02:00
|
|
|
|
|
|
|
QPainterPath pathDet;
|
|
|
|
pathDet.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
pathDet.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(pathDet);
|
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());
|
|
|
|
qreal dW = GetDistance(points.at(0), points.at(1));
|
|
|
|
qreal dY = 0;
|
|
|
|
qreal dX;
|
|
|
|
for (int i = 0; i < m_tmDetail.GetCount(); ++i)
|
|
|
|
{
|
|
|
|
const TextLine& tl = m_tmDetail.GetLine(i);
|
|
|
|
QFont fnt = m_tmDetail.GetFont();
|
|
|
|
fnt.setPixelSize(m_tmDetail.GetFont().pixelSize() + tl.m_iFontSize);
|
|
|
|
fnt.setWeight(tl.m_eFontWeight);
|
|
|
|
fnt.setStyle(tl.m_eStyle);
|
|
|
|
dY += tl.m_iHeight;
|
|
|
|
QMatrix mat;
|
|
|
|
mat.translate(points.at(0).x(), points.at(0).y());
|
|
|
|
mat.rotate(qRadiansToDegrees(dAng));
|
|
|
|
QFontMetrics fm(fnt);
|
|
|
|
if ((tl.m_eAlign & Qt::AlignLeft) > 0)
|
|
|
|
{
|
|
|
|
dX = 0;
|
|
|
|
}
|
|
|
|
else if ((tl.m_eAlign & Qt::AlignHCenter) > 0)
|
|
|
|
{
|
|
|
|
dX = (dW - fm.width(tl.m_qsText))/2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dX = dW - fm.width(tl.m_qsText);
|
|
|
|
}
|
|
|
|
QPainterPath pathText;
|
|
|
|
pathText.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, tl.m_qsText);
|
|
|
|
path.addPath(mat.map(pathText));
|
|
|
|
dY += m_tmDetail.GetSpacing();
|
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->patternInfo.count() > 0)
|
|
|
|
{
|
2016-07-19 02:26:50 +02:00
|
|
|
points = Map(Mirror(d->patternInfo));
|
2016-07-18 20:38:27 +02:00
|
|
|
points.push_back(points.at(0));
|
2016-07-17 22:52:53 +02:00
|
|
|
|
|
|
|
QPainterPath pathDet;
|
|
|
|
pathDet.moveTo(points.at(0));
|
|
|
|
for (qint32 i = 1; i < points.count(); ++i)
|
|
|
|
{
|
|
|
|
pathDet.lineTo(points.at(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
path.addPath(pathDet);
|
|
|
|
}
|
|
|
|
|
2015-01-12 21:35:32 +01:00
|
|
|
return path;
|
|
|
|
}
|
2015-01-13 11:38:51 +01:00
|
|
|
|
2016-03-28 10:53:02 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QPainterPath VLayoutDetail::LayoutAllowencePath() const
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
path.setFillRule(Qt::WindingFill);
|
|
|
|
|
|
|
|
const QVector<QPointF> points = GetLayoutAllowencePoints();
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QGraphicsItem *VLayoutDetail::GetItem() const
|
|
|
|
{
|
|
|
|
QGraphicsPathItem *item = new QGraphicsPathItem();
|
|
|
|
item->setPath(ContourPath());
|
|
|
|
return item;
|
|
|
|
}
|
2015-01-18 19:56:01 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutDetail::IsMirror() const
|
|
|
|
{
|
|
|
|
return d->mirror;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetMirror(bool value)
|
|
|
|
{
|
|
|
|
d->mirror = value;
|
|
|
|
}
|
2016-07-17 22:52:53 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2016-07-18 20:38:27 +02:00
|
|
|
QPointF VLayoutDetail::RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) const
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::Mirror(const QVector<QPointF> &points) const
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VLayoutDetail::GetDistance(const QPointF &pt1, const QPointF &pt2) const
|
|
|
|
{
|
|
|
|
qreal dX = pt1.x() - pt2.x();
|
|
|
|
qreal dY = pt1.y() - pt2.y();
|
|
|
|
|
|
|
|
return qSqrt(dX*dX + dY*dY);
|
|
|
|
}
|