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.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <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-07 17:54:43 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-02 15:14:28 +01:00
|
|
|
VLayoutDetail::VLayoutDetail()
|
2015-01-07 17:54:43 +01:00
|
|
|
:VAbstractDetail(), d(new VLayoutDetailData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail::VLayoutDetail(const VLayoutDetail &detail)
|
|
|
|
:VAbstractDetail(detail), d (detail.d)
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail &VLayoutDetail::operator=(const VLayoutDetail &detail)
|
|
|
|
{
|
|
|
|
if ( &detail == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
VAbstractDetail::operator=(detail);
|
|
|
|
d = detail.d;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutDetail::~VLayoutDetail()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::GetContour() const
|
|
|
|
{
|
|
|
|
return d->contour;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetCountour(const QVector<QPointF> &points)
|
|
|
|
{
|
|
|
|
d->contour = points;
|
2015-01-10 14:47:46 +01:00
|
|
|
// Contour can't be closed
|
|
|
|
if (d->contour.first() == d->contour.last())
|
|
|
|
{
|
|
|
|
d->contour.removeLast();
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::GetSeamAllowencePoints() const
|
|
|
|
{
|
|
|
|
return d->seamAllowence;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetSeamAllowencePoints(const QVector<QPointF> &points)
|
|
|
|
{
|
|
|
|
d->seamAllowence = points;
|
2015-01-10 14:47:46 +01:00
|
|
|
// Seam allowence can't be closed
|
|
|
|
if (d->seamAllowence.first() == d->seamAllowence.last())
|
|
|
|
{
|
|
|
|
d->seamAllowence.removeLast();
|
|
|
|
}
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QVector<QPointF> VLayoutDetail::GetLayoutAllowence() const
|
|
|
|
{
|
|
|
|
return Map(d->layoutAllowence);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QMatrix VLayoutDetail::GetMatrix() const
|
|
|
|
{
|
|
|
|
return d->matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetMatrix(const QMatrix &matrix)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
d->matrix = d->matrix.translate(dx, dy);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::Rotate(const QPointF &originPoint, qreal degrees)
|
2015-01-07 17:54:43 +01:00
|
|
|
{
|
2015-01-10 14:47:46 +01:00
|
|
|
Translate(-originPoint.x(), -originPoint.y());
|
|
|
|
d->matrix = d->matrix.rotate(degrees);
|
|
|
|
Translate(originPoint.x(), originPoint.y());
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
QLineF axis = QLineF(edge.x1(), edge.y1(), 100, edge.y2()); // Ox axis
|
|
|
|
|
|
|
|
qreal angle = edge.angleTo(axis);
|
|
|
|
Rotate(edge.p1(), angle);
|
|
|
|
d->matrix = d->matrix.scale(d->matrix.m11()*-1, d->matrix.m22());
|
|
|
|
Rotate(edge.p1(), 360 - angle);
|
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-10 14:47:46 +01:00
|
|
|
const QVector<QPointF> points = GetLayoutAllowence();
|
|
|
|
QLineF edge;
|
|
|
|
if (i < EdgesCount())
|
|
|
|
{
|
|
|
|
edge = QLineF(points.at(i-1), points.at(i));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edge = QLineF(points.at(EdgesCount()-1), points.at(0));
|
|
|
|
}
|
|
|
|
return edge;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutDetail::EdgeByPoint(const QPointF &p1) const
|
|
|
|
{
|
|
|
|
if (p1.isNull())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EdgesCount() < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<QPointF> points = GetLayoutAllowence();
|
|
|
|
for (int i=0; i< points.size(); i++)
|
|
|
|
{
|
|
|
|
if (points.at(i) == p1)
|
|
|
|
{
|
|
|
|
return i+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; // Did not find edge
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QRectF VLayoutDetail::BoundingRect() const
|
|
|
|
{
|
|
|
|
QVector<QPointF> points = GetLayoutAllowence();
|
|
|
|
points.append(points.first());
|
|
|
|
return QPolygonF(points).boundingRect();
|
2015-01-07 17:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutDetail::SetLayoutAllowence()
|
|
|
|
{
|
|
|
|
if (d->layoutWidth > 0)
|
|
|
|
{
|
|
|
|
if (getSeamAllowance())
|
|
|
|
{
|
|
|
|
d->layoutAllowence = Equidistant(d->seamAllowence, EquidistantType::CloseEquidistant, d->layoutWidth);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d->layoutAllowence = Equidistant(d->contour, EquidistantType::CloseEquidistant, d->layoutWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
if (d->matrix.m11() < 0)
|
|
|
|
{
|
|
|
|
QList<QPointF> list = p.toList();
|
|
|
|
for(int k=0, s=list.size(), max=(s/2); k<max; k++)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|