Layout detail.
--HG-- branch : feature
This commit is contained in:
parent
06e945d8a3
commit
9effd8af02
|
@ -10,7 +10,6 @@ HEADERS += \
|
||||||
$$PWD/varc.h \
|
$$PWD/varc.h \
|
||||||
$$PWD/vgobject.h \
|
$$PWD/vgobject.h \
|
||||||
$$PWD/vpointf.h \
|
$$PWD/vpointf.h \
|
||||||
$$PWD/vequidistant.h \
|
|
||||||
$$PWD/vabstractcurve.h \
|
$$PWD/vabstractcurve.h \
|
||||||
$$PWD/vnodedetail_p.h \
|
$$PWD/vnodedetail_p.h \
|
||||||
$$PWD/vdetail_p.h \
|
$$PWD/vdetail_p.h \
|
||||||
|
@ -30,5 +29,4 @@ SOURCES += \
|
||||||
$$PWD/varc.cpp \
|
$$PWD/varc.cpp \
|
||||||
$$PWD/vgobject.cpp \
|
$$PWD/vgobject.cpp \
|
||||||
$$PWD/vpointf.cpp \
|
$$PWD/vpointf.cpp \
|
||||||
$$PWD/vequidistant.cpp \
|
|
||||||
$$PWD/vabstractcurve.cpp
|
$$PWD/vabstractcurve.cpp
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include "vdetail_p.h"
|
#include "vdetail_p.h"
|
||||||
#include "../container/vcontainer.h"
|
#include "../container/vcontainer.h"
|
||||||
#include "vpointf.h"
|
#include "vpointf.h"
|
||||||
|
#include "../core/vapplication.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
@ -434,6 +435,49 @@ QVector<QPointF> VDetail::SeamAllowancePoints(const VContainer *data) const
|
||||||
return pointsEkv;
|
return pointsEkv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QPainterPath VDetail::ContourPath(const VContainer *data) const
|
||||||
|
{
|
||||||
|
QVector<QPointF> points = ContourPoints(data);
|
||||||
|
QVector<QPointF> pointsEkv = SeamAllowancePoints(data);
|
||||||
|
|
||||||
|
QPainterPath path;
|
||||||
|
|
||||||
|
// contour
|
||||||
|
path.moveTo(points[0]);
|
||||||
|
for (qint32 i = 1; i < points.count(); ++i)
|
||||||
|
{
|
||||||
|
path.lineTo(points.at(i));
|
||||||
|
}
|
||||||
|
path.lineTo(points.at(0));
|
||||||
|
|
||||||
|
// seam allowence
|
||||||
|
if (getSeamAllowance() == true)
|
||||||
|
{
|
||||||
|
QPainterPath ekv;
|
||||||
|
QVector<QPointF> p;
|
||||||
|
if (getClosed() == true)
|
||||||
|
{
|
||||||
|
p = Equidistant(pointsEkv, EquidistantType::CloseEquidistant, qApp->toPixel(getWidth()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = Equidistant(pointsEkv, EquidistantType::OpenEquidistant, qApp->toPixel(getWidth()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ekv.moveTo(p.at(0));
|
||||||
|
for (qint32 i = 1; i < p.count(); ++i)
|
||||||
|
{
|
||||||
|
ekv.lineTo(p.at(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
path.addPath(ekv);
|
||||||
|
path.setFillRule(Qt::WindingFill);
|
||||||
|
}
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief listNodePoint return list nodes only with points.
|
* @brief listNodePoint return list nodes only with points.
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
class VDetailData;
|
class VDetailData;
|
||||||
class VContainer;
|
class VContainer;
|
||||||
|
class QPainterPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VDetail class for path of object (points, arcs, splines).
|
* @brief The VDetail class for path of object (points, arcs, splines).
|
||||||
|
@ -79,6 +80,8 @@ public:
|
||||||
|
|
||||||
QVector<QPointF> ContourPoints(const VContainer *data) const;
|
QVector<QPointF> ContourPoints(const VContainer *data) const;
|
||||||
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;
|
QVector<QPointF> SeamAllowancePoints(const VContainer *data) const;
|
||||||
|
|
||||||
|
QPainterPath ContourPath(const VContainer *data) const;
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VDetailData> d;
|
QSharedDataPointer<VDetailData> d;
|
||||||
|
|
||||||
|
|
|
@ -1,445 +0,0 @@
|
||||||
/************************************************************************
|
|
||||||
**
|
|
||||||
** @file vequidistant.cpp
|
|
||||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
||||||
** @date 28 1, 2014
|
|
||||||
**
|
|
||||||
** @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) 2013 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 "varc.h"
|
|
||||||
#include "vequidistant.h"
|
|
||||||
#include "vpointf.h"
|
|
||||||
#include "vspline.h"
|
|
||||||
#include "vsplinepath.h"
|
|
||||||
#include "../core/vapplication.h"
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QPainterPath>
|
|
||||||
#include "../container/vcontainer.h"
|
|
||||||
#include <QtMath>
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
VEquidistant::VEquidistant(const VContainer *data)
|
|
||||||
:data(data)
|
|
||||||
{
|
|
||||||
SCASSERT(data != nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QPainterPath VEquidistant::ContourPath(const quint32 &idDetail) const
|
|
||||||
{
|
|
||||||
SCASSERT(data != nullptr);
|
|
||||||
VDetail detail = data->GetDetail(idDetail);
|
|
||||||
QVector<QPointF> points;
|
|
||||||
QVector<QPointF> pointsEkv;
|
|
||||||
for (int i = 0; i< detail.CountNode(); ++i)
|
|
||||||
{
|
|
||||||
switch (detail.at(i).getTypeTool())
|
|
||||||
{
|
|
||||||
case (Tool::NodePoint):
|
|
||||||
{
|
|
||||||
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(detail.at(i).getId());
|
|
||||||
points.append(point->toQPointF());
|
|
||||||
if (detail.getSeamAllowance() == true)
|
|
||||||
{
|
|
||||||
QPointF pEkv = point->toQPointF();
|
|
||||||
pEkv.setX(pEkv.x()+detail.at(i).getMx());
|
|
||||||
pEkv.setY(pEkv.y()+detail.at(i).getMy());
|
|
||||||
pointsEkv.append(pEkv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (Tool::NodeArc):
|
|
||||||
case (Tool::NodeSpline):
|
|
||||||
case (Tool::NodeSplinePath):
|
|
||||||
{
|
|
||||||
const QSharedPointer<VAbstractCurve> curve=data->GeometricObject<VAbstractCurve>(detail.at(i).getId());
|
|
||||||
|
|
||||||
const QPointF begin = StartSegment(detail, i);
|
|
||||||
const QPointF end = EndSegment(detail, i);
|
|
||||||
|
|
||||||
QVector<QPointF> nodePoints = curve->GetSegmentPoints(begin, end, detail.at(i).getReverse());
|
|
||||||
points << nodePoints;
|
|
||||||
if (detail.getSeamAllowance() == true)
|
|
||||||
{
|
|
||||||
pointsEkv << biasPoints(nodePoints, detail.at(i).getMx(), detail.at(i).getMy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
qDebug()<<"Get wrong tool type. Ignore."<< static_cast<char>(detail.at(i).getTypeTool());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPainterPath path;
|
|
||||||
path.moveTo(points[0]);
|
|
||||||
for (qint32 i = 1; i < points.count(); ++i)
|
|
||||||
{
|
|
||||||
path.lineTo(points.at(i));
|
|
||||||
}
|
|
||||||
path.lineTo(points.at(0));
|
|
||||||
|
|
||||||
pointsEkv = CorrectEquidistantPoints(pointsEkv);
|
|
||||||
pointsEkv = CheckLoops(pointsEkv);
|
|
||||||
|
|
||||||
if (detail.getSeamAllowance() == true)
|
|
||||||
{
|
|
||||||
QPainterPath ekv;
|
|
||||||
if (detail.getClosed() == true)
|
|
||||||
{
|
|
||||||
ekv = Equidistant(pointsEkv, EquidistantType::CloseEquidistant, qApp->toPixel(detail.getWidth()));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ekv = Equidistant(pointsEkv, EquidistantType::OpenEquidistant, qApp->toPixel(detail.getWidth()));
|
|
||||||
}
|
|
||||||
path.addPath(ekv);
|
|
||||||
path.setFillRule(Qt::WindingFill);
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QPointF VEquidistant::StartSegment(const VDetail &detail, const int &i) const
|
|
||||||
{
|
|
||||||
QPointF begin;
|
|
||||||
if (detail.CountNode() > 1)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
if (detail.at(detail.CountNode()-1).getTypeTool() == Tool::NodePoint)
|
|
||||||
{
|
|
||||||
begin = data->GeometricObject<VPointF>(detail.at(detail.CountNode()-1).getId())->toQPointF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (detail.at(i-1).getTypeTool() == Tool::NodePoint)
|
|
||||||
{
|
|
||||||
begin = data->GeometricObject<VPointF>(detail.at(i-1).getId())->toQPointF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return begin;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QPointF VEquidistant::EndSegment(const VDetail &detail, const int &i) const
|
|
||||||
{
|
|
||||||
QPointF end;
|
|
||||||
if (detail.CountNode() > 2)
|
|
||||||
{
|
|
||||||
if (i == detail.CountNode() - 1)
|
|
||||||
{
|
|
||||||
if (detail.at(0).getTypeTool() == Tool::NodePoint)
|
|
||||||
{
|
|
||||||
end = data->GeometricObject<VPointF>(detail.at(0).getId())->toQPointF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (detail.at(i+1).getTypeTool() == Tool::NodePoint)
|
|
||||||
{
|
|
||||||
end = data->GeometricObject<VPointF>(detail.at(i+1).getId())->toQPointF();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QVector<QPointF> VEquidistant::biasPoints(const QVector<QPointF> &points, const qreal &mx, const qreal &my)
|
|
||||||
{
|
|
||||||
QVector<QPointF> p;
|
|
||||||
for (qint32 i = 0; i < points.size(); ++i)
|
|
||||||
{
|
|
||||||
QPointF point = points.at(i);
|
|
||||||
point.setX(point.x() + mx);
|
|
||||||
point.setY(point.y() + my);
|
|
||||||
p.append(point);
|
|
||||||
}
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QVector<QPointF> VEquidistant::CorrectEquidistantPoints(const QVector<QPointF> &points)
|
|
||||||
{
|
|
||||||
QVector<QPointF> correctPoints;
|
|
||||||
if (points.size()<4)//Better don't check if only three points. We can destroy equidistant.
|
|
||||||
{
|
|
||||||
qDebug()<<"Only three points.";
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
//Clear equivalent points
|
|
||||||
for (qint32 i = 0; i <points.size(); ++i)
|
|
||||||
{
|
|
||||||
if (i == points.size()-1)
|
|
||||||
{
|
|
||||||
correctPoints.append(points.at(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (points.at(i) == points.at(i+1))
|
|
||||||
{
|
|
||||||
correctPoints.append(points.at(i));
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
correctPoints.append(points.at(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (correctPoints.size()<3)
|
|
||||||
{
|
|
||||||
return correctPoints;
|
|
||||||
}
|
|
||||||
//Remove point on line
|
|
||||||
QPointF point;
|
|
||||||
for (qint32 i = 1; i <correctPoints.size()-1; ++i)
|
|
||||||
{
|
|
||||||
QLineF l1(correctPoints.at(i-1), correctPoints.at(i));
|
|
||||||
QLineF l2(correctPoints.at(i), correctPoints.at(i+1));
|
|
||||||
QLineF::IntersectType intersect = l1.intersect(l2, &point);
|
|
||||||
if (intersect == QLineF::NoIntersection)
|
|
||||||
{
|
|
||||||
correctPoints.remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return correctPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QPainterPath VEquidistant::Equidistant(QVector<QPointF> points, const EquidistantType &eqv, const qreal &width)
|
|
||||||
{
|
|
||||||
QPainterPath ekv;
|
|
||||||
QVector<QPointF> ekvPoints;
|
|
||||||
if ( points.size() < 3 )
|
|
||||||
{
|
|
||||||
qDebug()<<"Not enough points for building the equidistant.";
|
|
||||||
return ekv;
|
|
||||||
}
|
|
||||||
if (width <= 0)
|
|
||||||
{
|
|
||||||
qDebug()<<"Width <= 0.";
|
|
||||||
return ekv;
|
|
||||||
}
|
|
||||||
for (qint32 i = 0; i < points.size(); ++i )
|
|
||||||
{
|
|
||||||
if (i != points.size()-1)
|
|
||||||
{
|
|
||||||
if (points.at(i) == points.at(i+1))
|
|
||||||
{
|
|
||||||
points.remove(i+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (points.at(i) == points.at(0))
|
|
||||||
{
|
|
||||||
points.remove(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (eqv == EquidistantType::CloseEquidistant)
|
|
||||||
{
|
|
||||||
points.append(points.at(0));
|
|
||||||
}
|
|
||||||
for (qint32 i = 0; i < points.size(); ++i )
|
|
||||||
{
|
|
||||||
if ( i == 0 && eqv == EquidistantType::CloseEquidistant)
|
|
||||||
{//first point, polyline closed
|
|
||||||
ekvPoints<<EkvPoint(QLineF(points.at(points.size()-2), points.at(points.size()-1)),
|
|
||||||
QLineF(points.at(1), points.at(0)), width);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (i == 0 && eqv == EquidistantType::OpenEquidistant)
|
|
||||||
{//first point, polyline doesn't closed
|
|
||||||
ekvPoints.append(SingleParallelPoint(QLineF(points.at(0), points.at(1)), 90, width));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (i == points.size()-1 && eqv == EquidistantType::CloseEquidistant)
|
|
||||||
{//last point, polyline closed
|
|
||||||
ekvPoints.append(ekvPoints.at(0));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (i == points.size()-1 && eqv == EquidistantType::OpenEquidistant)
|
|
||||||
{//last point, polyline doesn't closed
|
|
||||||
ekvPoints.append(SingleParallelPoint(QLineF(points.at(points.size()-1), points.at(points.size()-2)),
|
|
||||||
-90, width));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//points in the middle of polyline
|
|
||||||
ekvPoints<<EkvPoint(QLineF(points.at(i-1), points.at(i)), QLineF(points.at(i+1), points.at(i)), width);
|
|
||||||
}
|
|
||||||
ekvPoints = CheckLoops(ekvPoints);
|
|
||||||
ekv.moveTo(ekvPoints.at(0));
|
|
||||||
for (qint32 i = 1; i < ekvPoints.count(); ++i)
|
|
||||||
{
|
|
||||||
ekv.lineTo(ekvPoints.at(i));
|
|
||||||
}
|
|
||||||
return ekv;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QVector<QPointF> VEquidistant::CheckLoops(const QVector<QPointF> &points)
|
|
||||||
{
|
|
||||||
QVector<QPointF> ekvPoints;
|
|
||||||
/*If we got less than 4 points no need seek loops.*/
|
|
||||||
if (points.size() < 4)
|
|
||||||
{
|
|
||||||
qDebug()<<"Less then 4 points. Doesn't need check for loops.";
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
bool closed = false;
|
|
||||||
if (points.at(0) == points.at(points.size()-1))
|
|
||||||
{
|
|
||||||
closed = true;
|
|
||||||
}
|
|
||||||
qint32 i, j;
|
|
||||||
for (i = 0; i < points.size(); ++i)
|
|
||||||
{
|
|
||||||
/*Last three points no need check.*/
|
|
||||||
if (i >= points.size()-3)
|
|
||||||
{
|
|
||||||
ekvPoints.append(points.at(i));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
QPointF crosPoint;
|
|
||||||
QLineF::IntersectType intersect = QLineF::NoIntersection;
|
|
||||||
QLineF line1(points.at(i), points.at(i+1));
|
|
||||||
for (j = i+2; j < points.size()-1; ++j)
|
|
||||||
{
|
|
||||||
QLineF line2(points.at(j), points.at(j+1));
|
|
||||||
intersect = line1.intersect(line2, &crosPoint);
|
|
||||||
if (intersect == QLineF::BoundedIntersection)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (intersect == QLineF::BoundedIntersection)
|
|
||||||
{
|
|
||||||
if (i == 0 && j+1 == points.size()-1 && closed)
|
|
||||||
{
|
|
||||||
/*We got closed contour.*/
|
|
||||||
ekvPoints.append(points.at(i));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*We found loop.*/
|
|
||||||
ekvPoints.append(points.at(i));
|
|
||||||
ekvPoints.append(crosPoint);
|
|
||||||
i = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/*We did not found loop.*/
|
|
||||||
ekvPoints.append(points.at(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ekvPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QVector<QPointF> VEquidistant::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)
|
|
||||||
{
|
|
||||||
SCASSERT(width > 0);
|
|
||||||
QVector<QPointF> points;
|
|
||||||
if (line1.p2() != line2.p2())
|
|
||||||
{
|
|
||||||
qDebug()<<"Last points of two lines must be equal.";
|
|
||||||
return QVector<QPointF>();
|
|
||||||
}
|
|
||||||
QPointF CrosPoint;
|
|
||||||
QLineF bigLine1 = ParallelLine(line1, width );
|
|
||||||
QLineF bigLine2 = ParallelLine(QLineF(line2.p2(), line2.p1()), width );
|
|
||||||
QLineF::IntersectType type = bigLine1.intersect( bigLine2, &CrosPoint );
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case (QLineF::BoundedIntersection):
|
|
||||||
points.append(CrosPoint);
|
|
||||||
return points;
|
|
||||||
break;
|
|
||||||
case (QLineF::UnboundedIntersection):
|
|
||||||
{
|
|
||||||
QLineF line( line1.p2(), CrosPoint );
|
|
||||||
const qreal length = line.length();
|
|
||||||
if (length > width*2.4)
|
|
||||||
{ // Cutting too long an acute angle
|
|
||||||
line.setLength(width); // Not sure about width value here
|
|
||||||
QLineF cutLine(line.p2(), CrosPoint); // Cut line is a perpendicular
|
|
||||||
cutLine.setLength(length); // Decided take this length
|
|
||||||
|
|
||||||
// We do not check intersection type because intersection must alwayse exist
|
|
||||||
QPointF px;
|
|
||||||
cutLine.setAngle(cutLine.angle()+90);
|
|
||||||
QLineF::IntersectType type = bigLine1.intersect( cutLine, &px );
|
|
||||||
if (type == QLineF::NoIntersection)
|
|
||||||
{
|
|
||||||
qDebug()<<"Couldn't find intersection with cut line.";
|
|
||||||
}
|
|
||||||
points.append(px);
|
|
||||||
|
|
||||||
cutLine.setAngle(cutLine.angle()-180);
|
|
||||||
type = bigLine2.intersect( cutLine, &px );
|
|
||||||
if (type == QLineF::NoIntersection)
|
|
||||||
{
|
|
||||||
qDebug()<<"Couldn't find intersection with cut line.";
|
|
||||||
}
|
|
||||||
points.append(px);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
points.append(CrosPoint);
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (QLineF::NoIntersection):
|
|
||||||
/*If we have correct lines this means lines lie on a line.*/
|
|
||||||
points.append(bigLine1.p2());
|
|
||||||
return points;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QLineF VEquidistant::ParallelLine(const QLineF &line, qreal width)
|
|
||||||
{
|
|
||||||
SCASSERT(width > 0);
|
|
||||||
QLineF paralel = QLineF (SingleParallelPoint(line, 90, width), SingleParallelPoint(QLineF(line.p2(), line.p1()),
|
|
||||||
-90, width));
|
|
||||||
return paralel;
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
|
||||||
QPointF VEquidistant::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width)
|
|
||||||
{
|
|
||||||
SCASSERT(width > 0);
|
|
||||||
QLineF pLine = line;
|
|
||||||
pLine.setAngle( pLine.angle() + angle );
|
|
||||||
pLine.setLength( width );
|
|
||||||
return pLine.p2();
|
|
||||||
}
|
|
|
@ -1,113 +0,0 @@
|
||||||
/************************************************************************
|
|
||||||
**
|
|
||||||
** @file vequidistant.h
|
|
||||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
||||||
** @date 28 1, 2014
|
|
||||||
**
|
|
||||||
** @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) 2013 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/>.
|
|
||||||
**
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
#ifndef VEQUIDISTANT_H
|
|
||||||
#define VEQUIDISTANT_H
|
|
||||||
|
|
||||||
#include "vdetail.h"
|
|
||||||
|
|
||||||
class QPainterPath;
|
|
||||||
class VContainer;
|
|
||||||
class QPointF;
|
|
||||||
class QLineF;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief The VEquidistant class calculate equidistant for detail.
|
|
||||||
*/
|
|
||||||
class VEquidistant
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
VEquidistant(const VContainer *data);
|
|
||||||
~VEquidistant(){}
|
|
||||||
/**
|
|
||||||
* @brief ContourPath create painter path for detail.
|
|
||||||
* @param idDetail id of detail.
|
|
||||||
* @param data container with objects (points, arcs, splines).
|
|
||||||
* @return return painter path of contour detail.
|
|
||||||
*/
|
|
||||||
QPainterPath ContourPath(const quint32 &idDetail) const;
|
|
||||||
private:
|
|
||||||
Q_DISABLE_COPY(VEquidistant)
|
|
||||||
const VContainer *data;
|
|
||||||
/**
|
|
||||||
* @brief biasPoints bias point.
|
|
||||||
* @param points vector of points.
|
|
||||||
* @param mx offset respect to x.
|
|
||||||
* @param my offset respect to y.
|
|
||||||
* @return new vector biased points.
|
|
||||||
*/
|
|
||||||
static QVector<QPointF> biasPoints(const QVector<QPointF> &points, const qreal &mx, const qreal &my);
|
|
||||||
/**
|
|
||||||
* @brief CorrectEquidistantPoints clear equivalent points and remove point on line from equdistant.
|
|
||||||
* @param points list of points equdistant.
|
|
||||||
* @return corrected list.
|
|
||||||
*/
|
|
||||||
static QVector<QPointF> CorrectEquidistantPoints(const QVector<QPointF> &points);
|
|
||||||
/**
|
|
||||||
* @brief Equidistant create equidistant painter path for detail.
|
|
||||||
* @param points vector of points.
|
|
||||||
* @param eqv type of equidistant.
|
|
||||||
* @param width width of equidistant.
|
|
||||||
* @return return painter path of equidistant.
|
|
||||||
*/
|
|
||||||
static QPainterPath Equidistant(QVector<QPointF> points, const EquidistantType &eqv, const qreal &width);
|
|
||||||
/**
|
|
||||||
* @brief CheckLoops seek and delete loops in equidistant.
|
|
||||||
* @param points vector of points of equidistant.
|
|
||||||
* @return vector of points of equidistant.
|
|
||||||
*/
|
|
||||||
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);
|
|
||||||
/**
|
|
||||||
* @brief EkvPoint return vector of points of equidistant two lines. Last point of two lines must be equal.
|
|
||||||
* @param line1 first line.
|
|
||||||
* @param line2 second line.
|
|
||||||
* @param width width of equidistant.
|
|
||||||
* @return vector of points.
|
|
||||||
*/
|
|
||||||
static QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width);
|
|
||||||
/**
|
|
||||||
* @brief ParallelLine create parallel line.
|
|
||||||
* @param line starting line.
|
|
||||||
* @param width width to parallel line.
|
|
||||||
* @return parallel line.
|
|
||||||
*/
|
|
||||||
static QLineF ParallelLine(const QLineF &line, qreal width );
|
|
||||||
/**
|
|
||||||
* @brief SingleParallelPoint return point of parallel line.
|
|
||||||
* @param line starting line.
|
|
||||||
* @param angle angle in degree.
|
|
||||||
* @param width width to parallel line.
|
|
||||||
* @return point of parallel line.
|
|
||||||
*/
|
|
||||||
static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width);
|
|
||||||
|
|
||||||
QPointF StartSegment(const VDetail &detail, const int &i) const;
|
|
||||||
QPointF EndSegment(const VDetail &detail, const int &i) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // VEQUIDISTANT_H
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "geometry/vspline.h"
|
#include "geometry/vspline.h"
|
||||||
#include "geometry/vequidistant.h"
|
|
||||||
#include "exception/vexceptionobjecterror.h"
|
#include "exception/vexceptionobjecterror.h"
|
||||||
#include "exception/vexceptionconversionerror.h"
|
#include "exception/vexceptionconversionerror.h"
|
||||||
#include "exception/vexceptionemptyparameter.h"
|
#include "exception/vexceptionemptyparameter.h"
|
||||||
|
@ -1908,7 +1907,7 @@ void MainWindow::ActionLayout(bool checked)
|
||||||
{
|
{
|
||||||
Q_UNUSED(checked);
|
Q_UNUSED(checked);
|
||||||
ActionDetails(true);//Get all list of details.
|
ActionDetails(true);//Get all list of details.
|
||||||
QVector<VItem*> listDetails;
|
QVector<VLayoutDetail> listDetails;
|
||||||
const QHash<quint32, VDetail> *details = pattern->DataDetails();
|
const QHash<quint32, VDetail> *details = pattern->DataDetails();
|
||||||
if (details->count() == 0)
|
if (details->count() == 0)
|
||||||
{
|
{
|
||||||
|
@ -1919,8 +1918,14 @@ void MainWindow::ActionLayout(bool checked)
|
||||||
while (idetail.hasNext())
|
while (idetail.hasNext())
|
||||||
{
|
{
|
||||||
idetail.next();
|
idetail.next();
|
||||||
QPainterPath path = VEquidistant(pattern).ContourPath(idetail.key());
|
VLayoutDetail det = VLayoutDetail();
|
||||||
listDetails.append(new VItem(path, listDetails.size()));
|
det.SetCountour(idetail.value().ContourPoints(pattern));
|
||||||
|
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern));
|
||||||
|
det.setSeamAllowance(idetail.value().getSeamAllowance());
|
||||||
|
det.setName(idetail.value().getName());
|
||||||
|
det.SetLayoutAllowence();
|
||||||
|
|
||||||
|
listDetails.append(det);
|
||||||
}
|
}
|
||||||
QString description = doc->GetDescription();
|
QString description = doc->GetDescription();
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,12 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "widgets/vmaingraphicsscene.h"
|
#include "widgets/vmaingraphicsscene.h"
|
||||||
#include "widgets/vmaingraphicsview.h"
|
#include "widgets/vmaingraphicsview.h"
|
||||||
#include "widgets/vitem.h"
|
|
||||||
#include "dialogs/dialogs.h"
|
#include "dialogs/dialogs.h"
|
||||||
#include "tools/vtooldetail.h"
|
#include "tools/vtooldetail.h"
|
||||||
#include "tools/vtooluniondetails.h"
|
#include "tools/vtooluniondetails.h"
|
||||||
#include "tools/drawTools/drawtools.h"
|
#include "tools/drawTools/drawtools.h"
|
||||||
#include "xml/vdomdocument.h"
|
#include "xml/vdomdocument.h"
|
||||||
|
#include "../libs/vlayout/vlayoutdetail.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -136,7 +136,8 @@ signals:
|
||||||
* @param listDetails list of details.
|
* @param listDetails list of details.
|
||||||
* @param description pattern description.
|
* @param description pattern description.
|
||||||
*/
|
*/
|
||||||
void ModelChosen(QVector<VItem*> listDetails, const QString &curFile, const QString &description);
|
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &curFile,
|
||||||
|
const QString &description);
|
||||||
void RefreshHistory();
|
void RefreshHistory();
|
||||||
protected:
|
protected:
|
||||||
virtual void keyPressEvent(QKeyEvent *event);
|
virtual void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
|
@ -118,7 +118,6 @@ enum class Source : char { FromGui, FromFile, FromTool };
|
||||||
enum class Draw : char { Calculation, Modeling };
|
enum class Draw : char { Calculation, Modeling };
|
||||||
enum class NodeDetail : char { Contour, Modeling };
|
enum class NodeDetail : char { Contour, Modeling };
|
||||||
enum class Contour : char { OpenContour, CloseContour };
|
enum class Contour : char { OpenContour, CloseContour };
|
||||||
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
|
|
||||||
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
|
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
|
||||||
enum class SplinePointPosition : char { FirstPoint, LastPoint };
|
enum class SplinePointPosition : char { FirstPoint, LastPoint };
|
||||||
enum class VarType : char { Measurement, Increment, LineLength, SplineLength, ArcLength, LineAngle, Unknown };
|
enum class VarType : char { Measurement, Increment, LineLength, SplineLength, ArcLength, LineAngle, Unknown };
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
*/
|
*/
|
||||||
TableWindow::TableWindow(QWidget *parent)
|
TableWindow::TableWindow(QWidget *parent)
|
||||||
:QMainWindow(parent), numberDetal(nullptr), colission(nullptr), ui(new Ui::TableWindow),
|
:QMainWindow(parent), numberDetal(nullptr), colission(nullptr), ui(new Ui::TableWindow),
|
||||||
listDetails(QVector<VItem*>()), outItems(false), collidingItems(false), tableScene(nullptr),
|
listDetails(QVector<VLayoutDetail>()), outItems(false), collidingItems(false), tableScene(nullptr),
|
||||||
paper(nullptr), shadowPaper(nullptr), listOutItems(nullptr), listCollidingItems(QList<QGraphicsItem*>()),
|
paper(nullptr), shadowPaper(nullptr), listOutItems(nullptr), listCollidingItems(QList<QGraphicsItem*>()),
|
||||||
indexDetail(0), sceneRect(QRectF()), fileName(QString()), description(QString())
|
indexDetail(0), sceneRect(QRectF()), fileName(QString()), description(QString())
|
||||||
{
|
{
|
||||||
|
@ -112,30 +112,30 @@ void TableWindow::AddPaper()
|
||||||
*/
|
*/
|
||||||
void TableWindow::AddDetail()
|
void TableWindow::AddDetail()
|
||||||
{
|
{
|
||||||
if (indexDetail<listDetails.count())
|
// if (indexDetail<listDetails.count())
|
||||||
{
|
// {
|
||||||
tableScene->clearSelection();
|
// tableScene->clearSelection();
|
||||||
VItem* Detail = listDetails[indexDetail];
|
// VItem* Detail = listDetails[indexDetail];
|
||||||
SCASSERT(Detail != nullptr);
|
// SCASSERT(Detail != nullptr);
|
||||||
connect(Detail, &VItem::itemOut, this, &TableWindow::itemOut);
|
// connect(Detail, &VItem::itemOut, this, &TableWindow::itemOut);
|
||||||
connect(Detail, &VItem::itemColliding, this, &TableWindow::itemColliding);
|
// connect(Detail, &VItem::itemColliding, this, &TableWindow::itemColliding);
|
||||||
connect(this, &TableWindow::LengthChanged, Detail, &VItem::LengthChanged);
|
// connect(this, &TableWindow::LengthChanged, Detail, &VItem::LengthChanged);
|
||||||
Detail->setPen(QPen(Qt::black, 1));
|
// Detail->setPen(QPen(Qt::black, 1));
|
||||||
Detail->setBrush(QBrush(Qt::white));
|
// Detail->setBrush(QBrush(Qt::white));
|
||||||
Detail->setPos(paper->boundingRect().center());
|
// Detail->setPos(paper->boundingRect().center());
|
||||||
Detail->setFlag(QGraphicsItem::ItemIsMovable, true);
|
// Detail->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
Detail->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
// Detail->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
// Detail->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
Detail->setPaper(paper);
|
// Detail->setPaper(paper);
|
||||||
tableScene->addItem(Detail);
|
// tableScene->addItem(Detail);
|
||||||
Detail->setSelected(true);
|
// Detail->setSelected(true);
|
||||||
indexDetail++;
|
// indexDetail++;
|
||||||
if (indexDetail==listDetails.count())
|
// if (indexDetail==listDetails.count())
|
||||||
{
|
// {
|
||||||
ui->actionSave->setEnabled(true);
|
// ui->actionSave->setEnabled(true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
numberDetal->setText(QString(tr("%1 details left.")).arg(listDetails.count()-indexDetail));
|
// numberDetal->setText(QString(tr("%1 details left.")).arg(listDetails.count()-indexDetail));
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -147,7 +147,7 @@ void TableWindow::AddDetail()
|
||||||
/*
|
/*
|
||||||
* Get details for creation layout.
|
* Get details for creation layout.
|
||||||
*/
|
*/
|
||||||
void TableWindow::ModelChosen(QVector<VItem*> listDetails, const QString &fileName, const QString &description)
|
void TableWindow::ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName, const QString &description)
|
||||||
{
|
{
|
||||||
this->description = description;
|
this->description = description;
|
||||||
|
|
||||||
|
@ -390,67 +390,67 @@ void TableWindow::itemOut(int number, bool flag)
|
||||||
void TableWindow::itemColliding(QList<QGraphicsItem *> list, int number)
|
void TableWindow::itemColliding(QList<QGraphicsItem *> list, int number)
|
||||||
{
|
{
|
||||||
//qDebug()<<"number="<<number;
|
//qDebug()<<"number="<<number;
|
||||||
if (number==0)
|
// if (number==0)
|
||||||
{
|
// {
|
||||||
if (listCollidingItems.isEmpty()==false)
|
// if (listCollidingItems.isEmpty()==false)
|
||||||
{
|
// {
|
||||||
if (listCollidingItems.contains(list.at(0))==true)
|
// if (listCollidingItems.contains(list.at(0))==true)
|
||||||
{
|
// {
|
||||||
listCollidingItems.removeAt(listCollidingItems.indexOf(list.at(0)));
|
// listCollidingItems.removeAt(listCollidingItems.indexOf(list.at(0)));
|
||||||
if (listCollidingItems.size()>1)
|
// if (listCollidingItems.size()>1)
|
||||||
{
|
// {
|
||||||
for ( int i = 0; i < listCollidingItems.count(); ++i )
|
// for ( int i = 0; i < listCollidingItems.count(); ++i )
|
||||||
{
|
// {
|
||||||
QList<QGraphicsItem *> lis = listCollidingItems.at(i)->collidingItems();
|
// QList<QGraphicsItem *> lis = listCollidingItems.at(i)->collidingItems();
|
||||||
if (lis.size()-2 <= 0)
|
// if (lis.size()-2 <= 0)
|
||||||
{
|
// {
|
||||||
VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(i) );
|
// VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(i) );
|
||||||
SCASSERT(bitem != nullptr);
|
// SCASSERT(bitem != nullptr);
|
||||||
bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
// bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
||||||
listCollidingItems.removeAt(i);
|
// listCollidingItems.removeAt(i);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (listCollidingItems.size()==1)
|
// else if (listCollidingItems.size()==1)
|
||||||
{
|
// {
|
||||||
VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(0) );
|
// VItem * bitem = qgraphicsitem_cast<VItem *> ( listCollidingItems.at(0) );
|
||||||
SCASSERT(bitem != nullptr);
|
// SCASSERT(bitem != nullptr);
|
||||||
bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
// bitem->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine())));
|
||||||
listCollidingItems.clear();
|
// listCollidingItems.clear();
|
||||||
collidingItems = true;
|
// collidingItems = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
collidingItems = true;
|
// collidingItems = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
collidingItems = true;
|
// collidingItems = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else if (number==1)
|
// else if (number==1)
|
||||||
{
|
// {
|
||||||
if (list.contains(paper)==true)
|
// if (list.contains(paper)==true)
|
||||||
{
|
// {
|
||||||
list.removeAt(list.indexOf(paper));
|
// list.removeAt(list.indexOf(paper));
|
||||||
}
|
// }
|
||||||
if (list.contains(shadowPaper)==true)
|
// if (list.contains(shadowPaper)==true)
|
||||||
{
|
// {
|
||||||
list.removeAt(list.indexOf(shadowPaper));
|
// list.removeAt(list.indexOf(shadowPaper));
|
||||||
}
|
// }
|
||||||
for ( int i = 0; i < list.count(); ++i )
|
// for ( int i = 0; i < list.count(); ++i )
|
||||||
{
|
// {
|
||||||
if (listCollidingItems.contains(list.at(i))==false)
|
// if (listCollidingItems.contains(list.at(i))==false)
|
||||||
{
|
// {
|
||||||
listCollidingItems.append(list.at(i));
|
// listCollidingItems.append(list.at(i));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
collidingItems = false;
|
// collidingItems = false;
|
||||||
}
|
// }
|
||||||
qDebug()<<"itemColliding::outItems="<<outItems<<"&& collidingItems"<<collidingItems;
|
// qDebug()<<"itemColliding::outItems="<<outItems<<"&& collidingItems"<<collidingItems;
|
||||||
checkNext();
|
// checkNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "widgets/vitem.h"
|
|
||||||
|
#include "../../libs/vlayout/vlayoutdetail.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
|
@ -55,7 +56,8 @@ public:
|
||||||
~TableWindow();
|
~TableWindow();
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void ModelChosen(QVector<VItem*> listDetails, const QString &fileName, const QString &description);
|
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &fileName,
|
||||||
|
const QString &description);
|
||||||
|
|
||||||
void StopTable();
|
void StopTable();
|
||||||
|
|
||||||
|
@ -96,7 +98,7 @@ private:
|
||||||
Ui::TableWindow* ui;
|
Ui::TableWindow* ui;
|
||||||
|
|
||||||
/** @brief listDetails list of details. */
|
/** @brief listDetails list of details. */
|
||||||
QVector<VItem*> listDetails;
|
QVector<VLayoutDetail> listDetails;
|
||||||
|
|
||||||
/** @brief outItems true if we have details out paper sheet. */
|
/** @brief outItems true if we have details out paper sheet. */
|
||||||
bool outItems;
|
bool outItems;
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "nodeDetails/nodedetails.h"
|
#include "nodeDetails/nodedetails.h"
|
||||||
#include "../geometry/varc.h"
|
#include "../geometry/varc.h"
|
||||||
#include "../geometry/vsplinepath.h"
|
#include "../geometry/vsplinepath.h"
|
||||||
#include "../geometry/vequidistant.h"
|
|
||||||
#include "../widgets/vmaingraphicsscene.h"
|
#include "../widgets/vmaingraphicsscene.h"
|
||||||
#include "../dialogs/tools/dialogtool.h"
|
#include "../dialogs/tools/dialogtool.h"
|
||||||
#include "../dialogs/tools/dialogdetail.h"
|
#include "../dialogs/tools/dialogdetail.h"
|
||||||
|
@ -511,10 +510,8 @@ void VToolDetail::ShowVisualization(bool show)
|
||||||
void VToolDetail::RefreshGeometry()
|
void VToolDetail::RefreshGeometry()
|
||||||
{
|
{
|
||||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false);
|
||||||
QPainterPath path = VEquidistant(this->getData()).ContourPath(id);
|
|
||||||
this->setPath(path);
|
|
||||||
|
|
||||||
VDetail detail = VAbstractTool::data.GetDetail(id);
|
VDetail detail = VAbstractTool::data.GetDetail(id);
|
||||||
|
this->setPath(detail.ContourPath(this->getData()));
|
||||||
this->setPos(detail.getMx(), detail.getMy());
|
this->setPos(detail.getMx(), detail.getMy());
|
||||||
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
this->setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
#include "vabstractdetail.h"
|
#include "vabstractdetail.h"
|
||||||
#include "vabstractdetail_p.h"
|
#include "vabstractdetail_p.h"
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QLineF>
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* @brief VAbstractDetail default contructor. Create empty detail.
|
* @brief VAbstractDetail default contructor. Create empty detail.
|
||||||
|
@ -166,3 +170,294 @@ void VAbstractDetail::setWidth(const qreal &value)
|
||||||
{
|
{
|
||||||
d->width = value;
|
d->width = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QPointF> VAbstractDetail::Equidistant(const QVector<QPointF> &points, const EquidistantType &eqv, qreal width)
|
||||||
|
{
|
||||||
|
QVector<QPointF> ekvPoints;
|
||||||
|
|
||||||
|
if (width <= 0)
|
||||||
|
{
|
||||||
|
qDebug()<<"Width <= 0.";
|
||||||
|
return QVector<QPointF>();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<QPointF> p = CorrectEquidistantPoints(points);
|
||||||
|
if ( p.size() < 3 )
|
||||||
|
{
|
||||||
|
qDebug()<<"Not enough points for building the equidistant.";
|
||||||
|
return QVector<QPointF>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eqv == EquidistantType::CloseEquidistant)
|
||||||
|
{
|
||||||
|
p.append(points.at(0));
|
||||||
|
}
|
||||||
|
for (qint32 i = 0; i < points.size(); ++i )
|
||||||
|
{
|
||||||
|
if ( i == 0 && eqv == EquidistantType::CloseEquidistant)
|
||||||
|
{//first point, polyline closed
|
||||||
|
ekvPoints<<EkvPoint(QLineF(points.at(points.size()-2), points.at(points.size()-1)),
|
||||||
|
QLineF(points.at(1), points.at(0)), width);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (i == 0 && eqv == EquidistantType::OpenEquidistant)
|
||||||
|
{//first point, polyline doesn't closed
|
||||||
|
ekvPoints.append(SingleParallelPoint(QLineF(points.at(0), points.at(1)), 90, width));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i == points.size()-1 && eqv == EquidistantType::CloseEquidistant)
|
||||||
|
{//last point, polyline closed
|
||||||
|
ekvPoints.append(ekvPoints.at(0));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (i == points.size()-1 && eqv == EquidistantType::OpenEquidistant)
|
||||||
|
{//last point, polyline doesn't closed
|
||||||
|
ekvPoints.append(SingleParallelPoint(QLineF(points.at(points.size()-1), points.at(points.size()-2)),
|
||||||
|
-90, width));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//points in the middle of polyline
|
||||||
|
ekvPoints<<EkvPoint(QLineF(points.at(i-1), points.at(i)), QLineF(points.at(i+1), points.at(i)), width);
|
||||||
|
}
|
||||||
|
return ekvPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QPointF> VAbstractDetail::RemoveDublicates(const QVector<QPointF> &points)
|
||||||
|
{
|
||||||
|
QVector<QPointF> p = points;
|
||||||
|
for(int i = 0; i < p.size(); i++)
|
||||||
|
{
|
||||||
|
QPointF current = p.at(i);
|
||||||
|
|
||||||
|
for(int j = i; j < p.size(); j++)
|
||||||
|
{
|
||||||
|
if(j == i)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QPointF temp = p.at(j);
|
||||||
|
if(current == temp)
|
||||||
|
{
|
||||||
|
QVector<QPointF>::iterator iter = p.begin() + j;
|
||||||
|
p.erase(iter);
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief CorrectEquidistantPoints clear equivalent points and remove point on line from equdistant.
|
||||||
|
* @param points list of points equdistant.
|
||||||
|
* @return corrected list.
|
||||||
|
*/
|
||||||
|
QVector<QPointF> VAbstractDetail::CorrectEquidistantPoints(const QVector<QPointF> &points)
|
||||||
|
{
|
||||||
|
QVector<QPointF> correctPoints;
|
||||||
|
if (points.size()<4)//Better don't check if only three points. We can destroy equidistant.
|
||||||
|
{
|
||||||
|
qDebug()<<"Only three points.";
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Clear equivalent points
|
||||||
|
correctPoints = RemoveDublicates(points);
|
||||||
|
|
||||||
|
if (correctPoints.size()<3)
|
||||||
|
{
|
||||||
|
return correctPoints;
|
||||||
|
}
|
||||||
|
//Remove point on line
|
||||||
|
QPointF point;
|
||||||
|
for (qint32 i = 1; i <correctPoints.size()-1; ++i)
|
||||||
|
{
|
||||||
|
QLineF l1(correctPoints.at(i-1), correctPoints.at(i));
|
||||||
|
QLineF l2(correctPoints.at(i), correctPoints.at(i+1));
|
||||||
|
QLineF::IntersectType intersect = l1.intersect(l2, &point);
|
||||||
|
if (intersect == QLineF::NoIntersection)
|
||||||
|
{
|
||||||
|
correctPoints.remove(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
correctPoints = CheckLoops(correctPoints);
|
||||||
|
return correctPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief CheckLoops seek and delete loops in equidistant.
|
||||||
|
* @param points vector of points of equidistant.
|
||||||
|
* @return vector of points of equidistant.
|
||||||
|
*/
|
||||||
|
QVector<QPointF> VAbstractDetail::CheckLoops(const QVector<QPointF> &points)
|
||||||
|
{
|
||||||
|
QVector<QPointF> ekvPoints;
|
||||||
|
/*If we got less than 4 points no need seek loops.*/
|
||||||
|
if (points.size() < 4)
|
||||||
|
{
|
||||||
|
qDebug()<<"Less then 4 points. Doesn't need check for loops.";
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
bool closed = false;
|
||||||
|
if (points.at(0) == points.at(points.size()-1))
|
||||||
|
{
|
||||||
|
closed = true;
|
||||||
|
}
|
||||||
|
qint32 i, j;
|
||||||
|
for (i = 0; i < points.size(); ++i)
|
||||||
|
{
|
||||||
|
/*Last three points no need check.*/
|
||||||
|
if (i >= points.size()-3)
|
||||||
|
{
|
||||||
|
ekvPoints.append(points.at(i));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QPointF crosPoint;
|
||||||
|
QLineF::IntersectType intersect = QLineF::NoIntersection;
|
||||||
|
QLineF line1(points.at(i), points.at(i+1));
|
||||||
|
for (j = i+2; j < points.size()-1; ++j)
|
||||||
|
{
|
||||||
|
QLineF line2(points.at(j), points.at(j+1));
|
||||||
|
intersect = line1.intersect(line2, &crosPoint);
|
||||||
|
if (intersect == QLineF::BoundedIntersection)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (intersect == QLineF::BoundedIntersection)
|
||||||
|
{
|
||||||
|
if (i == 0 && j+1 == points.size()-1 && closed)
|
||||||
|
{
|
||||||
|
/*We got closed contour.*/
|
||||||
|
ekvPoints.append(points.at(i));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*We found loop.*/
|
||||||
|
ekvPoints.append(points.at(i));
|
||||||
|
ekvPoints.append(crosPoint);
|
||||||
|
i = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*We did not found loop.*/
|
||||||
|
ekvPoints.append(points.at(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ekvPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief EkvPoint return vector of points of equidistant two lines. Last point of two lines must be equal.
|
||||||
|
* @param line1 first line.
|
||||||
|
* @param line2 second line.
|
||||||
|
* @param width width of equidistant.
|
||||||
|
* @return vector of points.
|
||||||
|
*/
|
||||||
|
QVector<QPointF> VAbstractDetail::EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width)
|
||||||
|
{
|
||||||
|
if (width <= 0)
|
||||||
|
{
|
||||||
|
return QVector<QPointF>();
|
||||||
|
}
|
||||||
|
QVector<QPointF> points;
|
||||||
|
if (line1.p2() != line2.p2())
|
||||||
|
{
|
||||||
|
qDebug()<<"Last points of two lines must be equal.";
|
||||||
|
return QVector<QPointF>();
|
||||||
|
}
|
||||||
|
QPointF CrosPoint;
|
||||||
|
QLineF bigLine1 = ParallelLine(line1, width );
|
||||||
|
QLineF bigLine2 = ParallelLine(QLineF(line2.p2(), line2.p1()), width );
|
||||||
|
QLineF::IntersectType type = bigLine1.intersect( bigLine2, &CrosPoint );
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case (QLineF::BoundedIntersection):
|
||||||
|
points.append(CrosPoint);
|
||||||
|
return points;
|
||||||
|
break;
|
||||||
|
case (QLineF::UnboundedIntersection):
|
||||||
|
{
|
||||||
|
QLineF line( line1.p2(), CrosPoint );
|
||||||
|
const qreal length = line.length();
|
||||||
|
if (length > width*2.4)
|
||||||
|
{ // Cutting too long an acute angle
|
||||||
|
line.setLength(width); // Not sure about width value here
|
||||||
|
QLineF cutLine(line.p2(), CrosPoint); // Cut line is a perpendicular
|
||||||
|
cutLine.setLength(length); // Decided take this length
|
||||||
|
|
||||||
|
// We do not check intersection type because intersection must alwayse exist
|
||||||
|
QPointF px;
|
||||||
|
cutLine.setAngle(cutLine.angle()+90);
|
||||||
|
QLineF::IntersectType type = bigLine1.intersect( cutLine, &px );
|
||||||
|
if (type == QLineF::NoIntersection)
|
||||||
|
{
|
||||||
|
qDebug()<<"Couldn't find intersection with cut line.";
|
||||||
|
}
|
||||||
|
points.append(px);
|
||||||
|
|
||||||
|
cutLine.setAngle(cutLine.angle()-180);
|
||||||
|
type = bigLine2.intersect( cutLine, &px );
|
||||||
|
if (type == QLineF::NoIntersection)
|
||||||
|
{
|
||||||
|
qDebug()<<"Couldn't find intersection with cut line.";
|
||||||
|
}
|
||||||
|
points.append(px);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
points.append(CrosPoint);
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case (QLineF::NoIntersection):
|
||||||
|
/*If we have correct lines this means lines lie on a line.*/
|
||||||
|
points.append(bigLine1.p2());
|
||||||
|
return points;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief ParallelLine create parallel line.
|
||||||
|
* @param line starting line.
|
||||||
|
* @param width width to parallel line.
|
||||||
|
* @return parallel line.
|
||||||
|
*/
|
||||||
|
QLineF VAbstractDetail::ParallelLine(const QLineF &line, qreal width)
|
||||||
|
{
|
||||||
|
QLineF paralel = QLineF (SingleParallelPoint(line, 90, width), SingleParallelPoint(QLineF(line.p2(), line.p1()),
|
||||||
|
-90, width));
|
||||||
|
return paralel;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* @brief SingleParallelPoint return point of parallel line.
|
||||||
|
* @param line starting line.
|
||||||
|
* @param angle angle in degree.
|
||||||
|
* @param width width to parallel line.
|
||||||
|
* @return point of parallel line.
|
||||||
|
*/
|
||||||
|
QPointF VAbstractDetail::SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width)
|
||||||
|
{
|
||||||
|
QLineF pLine = line;
|
||||||
|
pLine.setAngle( pLine.angle() + angle );
|
||||||
|
pLine.setLength( width );
|
||||||
|
return pLine.p2();
|
||||||
|
}
|
||||||
|
|
|
@ -31,8 +31,12 @@
|
||||||
|
|
||||||
#include <QSharedDataPointer>
|
#include <QSharedDataPointer>
|
||||||
|
|
||||||
|
#include "vlayoutdef.h"
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
class VAbstractDetailData;
|
class VAbstractDetailData;
|
||||||
|
class QPointF;
|
||||||
|
class QLineF;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The VAbstractDetail class abstract class for all details.
|
* @brief The VAbstractDetail class abstract class for all details.
|
||||||
|
@ -59,8 +63,17 @@ public:
|
||||||
|
|
||||||
qreal getWidth() const;
|
qreal getWidth() const;
|
||||||
void setWidth(const qreal &value);
|
void setWidth(const qreal &value);
|
||||||
|
|
||||||
|
static QVector<QPointF> Equidistant(const QVector<QPointF> &points, const EquidistantType &eqv, qreal width);
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<VAbstractDetailData> d;
|
QSharedDataPointer<VAbstractDetailData> d;
|
||||||
|
|
||||||
|
static QVector<QPointF> RemoveDublicates(const QVector<QPointF> &points);
|
||||||
|
static QVector<QPointF> CorrectEquidistantPoints(const QVector<QPointF> &points);
|
||||||
|
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);
|
||||||
|
static QVector<QPointF> EkvPoint(const QLineF &line1, const QLineF &line2, const qreal &width);
|
||||||
|
static QLineF ParallelLine(const QLineF &line, qreal width );
|
||||||
|
static QPointF SingleParallelPoint(const QLineF &line, const qreal &angle, const qreal &width);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VABSTRACTDETAIL_H
|
#endif // VABSTRACTDETAIL_H
|
||||||
|
|
|
@ -6,7 +6,9 @@ HEADERS += \
|
||||||
$$PWD/vlayoutgenerator.h \
|
$$PWD/vlayoutgenerator.h \
|
||||||
$$PWD/vlayoutdetail.h \
|
$$PWD/vlayoutdetail.h \
|
||||||
$$PWD/vabstractdetail.h \
|
$$PWD/vabstractdetail.h \
|
||||||
$$PWD/vabstractdetail_p.h
|
$$PWD/vabstractdetail_p.h \
|
||||||
|
$$PWD/vlayoutdetail_p.h \
|
||||||
|
$$PWD/vlayoutdef.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/stable.cpp \
|
$$PWD/stable.cpp \
|
||||||
|
|
|
@ -7,9 +7,6 @@
|
||||||
# File with common stuff for whole project
|
# File with common stuff for whole project
|
||||||
include(../../../Valentina.pri)
|
include(../../../Valentina.pri)
|
||||||
|
|
||||||
# We don't need gui library.
|
|
||||||
QT -= gui
|
|
||||||
|
|
||||||
# Name of library
|
# Name of library
|
||||||
TARGET = vlayout
|
TARGET = vlayout
|
||||||
|
|
||||||
|
|
34
src/libs/vlayout/vlayoutdef.h
Normal file
34
src/libs/vlayout/vlayoutdef.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlayoutdef.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 7 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/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VLAYOUTDEF_H
|
||||||
|
#define VLAYOUTDEF_H
|
||||||
|
|
||||||
|
enum class EquidistantType : char { OpenEquidistant, CloseEquidistant };
|
||||||
|
|
||||||
|
#endif // VLAYOUTDEF_H
|
|
@ -27,7 +27,146 @@
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
#include "vlayoutdetail.h"
|
#include "vlayoutdetail.h"
|
||||||
|
#include "vlayoutdetail_p.h"
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
VLayoutDetail::VLayoutDetail()
|
VLayoutDetail::VLayoutDetail()
|
||||||
|
: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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QVector<QPointF> VLayoutDetail::GetSeamAllowencePoints() const
|
||||||
|
{
|
||||||
|
return d->seamAllowence;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutDetail::SetSeamAllowencePoints(const QVector<QPointF> &points)
|
||||||
|
{
|
||||||
|
d->seamAllowence = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutDetail::translate(qreal dx, qreal dy)
|
||||||
|
{
|
||||||
|
const QMatrix m = d->matrix.translate(dx, dy);
|
||||||
|
d->matrix = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VLayoutDetail::rotate(qreal degrees)
|
||||||
|
{
|
||||||
|
const QMatrix m = d->matrix.rotate(degrees);
|
||||||
|
d->matrix = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
int VLayoutDetail::EdgesCount() const
|
||||||
|
{
|
||||||
|
return d->layoutAllowence.count()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
QLineF VLayoutDetail::Edge(int i) const
|
||||||
|
{
|
||||||
|
if (i < 1 || i > EdgesCount())
|
||||||
|
{ // Doesn't exist such edge
|
||||||
|
return QLineF();
|
||||||
|
}
|
||||||
|
const QLineF line(d->layoutAllowence.at(i-1), d->layoutAllowence.at(i));
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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
|
||||||
|
{
|
||||||
|
QVector<QPointF> p;
|
||||||
|
for (int i = 0; i < points.size(); ++i)
|
||||||
|
{
|
||||||
|
p.append(d->matrix.map(points.at(i)));
|
||||||
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,46 @@
|
||||||
#ifndef VLAYOUTDETAIL_H
|
#ifndef VLAYOUTDETAIL_H
|
||||||
#define VLAYOUTDETAIL_H
|
#define VLAYOUTDETAIL_H
|
||||||
|
|
||||||
class VLayoutDetail
|
#include "vabstractdetail.h"
|
||||||
|
|
||||||
|
#include <QMatrix>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
class VLayoutDetailData;
|
||||||
|
|
||||||
|
class VLayoutDetail :public VAbstractDetail
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VLayoutDetail();
|
VLayoutDetail();
|
||||||
|
VLayoutDetail(const VLayoutDetail &detail);
|
||||||
|
VLayoutDetail &operator=(const VLayoutDetail &detail);
|
||||||
|
virtual ~VLayoutDetail();
|
||||||
|
|
||||||
|
QVector<QPointF> GetContour() const;
|
||||||
|
void SetCountour(const QVector<QPointF> &points);
|
||||||
|
|
||||||
|
QVector<QPointF> GetSeamAllowencePoints() const;
|
||||||
|
void SetSeamAllowencePoints(const QVector<QPointF> &points);
|
||||||
|
|
||||||
|
QVector<QPointF> GetLayoutAllowence() const;
|
||||||
|
void SetLayoutAllowence();
|
||||||
|
|
||||||
|
QMatrix GetMatrix() const;
|
||||||
|
void SetMatrix(const QMatrix &matrix);
|
||||||
|
|
||||||
|
qreal GetLayoutWidth() const;
|
||||||
|
void SetLayoutWidth(const qreal &value);
|
||||||
|
|
||||||
|
void translate(qreal dx, qreal dy);
|
||||||
|
void rotate(qreal degrees);
|
||||||
|
|
||||||
|
int EdgesCount() const;
|
||||||
|
QLineF Edge(int i) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<VLayoutDetailData> d;
|
||||||
|
|
||||||
|
QVector<QPointF> Map(const QVector<QPointF> &points) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VLAYOUTDETAIL_H
|
#endif // VLAYOUTDETAIL_H
|
||||||
|
|
77
src/libs/vlayout/vlayoutdetail_p.h
Normal file
77
src/libs/vlayout/vlayoutdetail_p.h
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
/************************************************************************
|
||||||
|
**
|
||||||
|
** @file vlayoutdetail_p.h
|
||||||
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||||
|
** @date 3 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/>.
|
||||||
|
**
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
#ifndef VLAYOUTDETAIL_P_H
|
||||||
|
#define VLAYOUTDETAIL_P_H
|
||||||
|
|
||||||
|
#include <QSharedData>
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QVector>
|
||||||
|
#include <QMatrix>
|
||||||
|
|
||||||
|
#ifdef Q_CC_GNU
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Weffc++"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class VLayoutDetailData : public QSharedData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VLayoutDetailData()
|
||||||
|
:contour(QVector<QPointF>()), seamAllowence(QVector<QPointF>()), layoutAllowence(QVector<QPointF>()),
|
||||||
|
matrix(QMatrix()), layoutWidth(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
VLayoutDetailData(const VLayoutDetailData &detail)
|
||||||
|
:QSharedData(detail), contour(detail.contour), seamAllowence(detail.seamAllowence),
|
||||||
|
layoutAllowence(detail.layoutAllowence), matrix(detail.matrix), layoutWidth(detail.layoutWidth)
|
||||||
|
{}
|
||||||
|
|
||||||
|
~VLayoutDetailData() {}
|
||||||
|
|
||||||
|
/** @brief contour list of contour points. */
|
||||||
|
QVector<QPointF> contour;
|
||||||
|
|
||||||
|
/** @brief seamAllowence list of seam allowence points. */
|
||||||
|
QVector<QPointF> seamAllowence;
|
||||||
|
|
||||||
|
/** @brief layoutAllowence list of layout allowence points. */
|
||||||
|
QVector<QPointF> layoutAllowence;
|
||||||
|
|
||||||
|
/** @brief matrix transformation matrix*/
|
||||||
|
QMatrix matrix;
|
||||||
|
|
||||||
|
/** @brief layoutWidth value layout allowence width in pixels. */
|
||||||
|
qreal layoutWidth;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef Q_CC_GNU
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // VLAYOUTDETAIL_P_H
|
Loading…
Reference in New Issue
Block a user