2016-11-03 19:15:53 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 11, 2016
|
|
|
|
**
|
|
|
|
** @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) 2016 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 VABSTRACTPIECE_H
|
|
|
|
#define VABSTRACTPIECE_H
|
|
|
|
|
|
|
|
#include <QtGlobal>
|
2016-11-09 14:53:22 +01:00
|
|
|
#include <QSharedDataPointer>
|
2016-11-11 11:54:17 +01:00
|
|
|
#include <QPointF>
|
2016-11-11 16:55:02 +01:00
|
|
|
#include <QDebug>
|
2016-11-11 11:54:17 +01:00
|
|
|
|
|
|
|
#include "../vmisc/diagnostic.h"
|
2016-11-19 14:29:54 +01:00
|
|
|
#include "../vmisc/def.h"
|
2016-11-11 16:55:02 +01:00
|
|
|
#include "../vgeometry/vgobject.h"
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
|
|
template <class T> class QVector;
|
2016-11-11 11:54:17 +01:00
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
class VAbstractPieceData;
|
2016-11-03 19:15:53 +01:00
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The VSAPoint class seam allowance point
|
|
|
|
*/
|
|
|
|
class VSAPoint : public QPointF
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Q_DECL_CONSTEXPR VSAPoint();
|
2016-11-18 11:58:47 +01:00
|
|
|
Q_DECL_CONSTEXPR VSAPoint(qreal xpos, qreal ypos);
|
2016-11-18 12:24:19 +01:00
|
|
|
Q_DECL_CONSTEXPR explicit VSAPoint(const QPointF &p);
|
2016-11-11 11:54:17 +01:00
|
|
|
|
|
|
|
Q_DECL_CONSTEXPR qreal GetSABefore() const;
|
|
|
|
void SetSABefore(qreal value);
|
|
|
|
|
|
|
|
Q_DECL_CONSTEXPR qreal GetSAAfter() const;
|
|
|
|
void SetSAAfter(qreal value);
|
|
|
|
|
2016-11-19 14:29:54 +01:00
|
|
|
Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const;
|
|
|
|
void SetAngleType(PieceNodeAngle value);
|
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
private:
|
2016-11-19 14:29:54 +01:00
|
|
|
qreal m_before;
|
|
|
|
qreal m_after;
|
|
|
|
PieceNodeAngle m_angle;
|
2016-11-11 11:54:17 +01:00
|
|
|
};
|
|
|
|
|
2016-11-18 11:58:47 +01:00
|
|
|
Q_DECLARE_METATYPE(VSAPoint)
|
2016-11-11 11:54:17 +01:00
|
|
|
Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE);
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint()
|
|
|
|
: QPointF(),
|
|
|
|
m_before(-1),
|
2016-11-19 14:29:54 +01:00
|
|
|
m_after(-1),
|
|
|
|
m_angle(PieceNodeAngle::ByLength)
|
2016-11-11 11:54:17 +01:00
|
|
|
{}
|
|
|
|
|
2016-11-18 11:58:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos)
|
|
|
|
: QPointF(xpos, ypos),
|
|
|
|
m_before(-1),
|
2016-11-19 14:29:54 +01:00
|
|
|
m_after(-1),
|
|
|
|
m_angle(PieceNodeAngle::ByLength)
|
2016-11-18 11:58:47 +01:00
|
|
|
{}
|
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(const QPointF &p)
|
|
|
|
: QPointF(p),
|
|
|
|
m_before(-1),
|
2016-11-19 14:29:54 +01:00
|
|
|
m_after(-1),
|
|
|
|
m_angle(PieceNodeAngle::ByLength)
|
2016-11-11 11:54:17 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline qreal VSAPoint::GetSABefore() const
|
|
|
|
{
|
|
|
|
return m_before;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VSAPoint::SetSABefore(qreal value)
|
|
|
|
{
|
|
|
|
value < 0 ? m_before = -1 : m_before = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline qreal VSAPoint::GetSAAfter() const
|
|
|
|
{
|
|
|
|
return m_after;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VSAPoint::SetSAAfter(qreal value)
|
|
|
|
{
|
|
|
|
value < 0 ? m_after = -1 : m_after = value;
|
|
|
|
}
|
|
|
|
|
2016-11-19 14:29:54 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline PieceNodeAngle VSAPoint::GetAngleType() const
|
|
|
|
{
|
|
|
|
return m_angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void VSAPoint::SetAngleType(PieceNodeAngle value)
|
|
|
|
{
|
|
|
|
m_angle = value;
|
|
|
|
}
|
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
QT_WARNING_POP
|
|
|
|
|
2016-11-03 19:15:53 +01:00
|
|
|
class VAbstractPiece
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VAbstractPiece();
|
|
|
|
VAbstractPiece(const VAbstractPiece &piece);
|
|
|
|
VAbstractPiece &operator=(const VAbstractPiece &piece);
|
|
|
|
virtual ~VAbstractPiece();
|
|
|
|
|
2016-11-09 14:53:22 +01:00
|
|
|
QString GetName() const;
|
|
|
|
void SetName(const QString &value);
|
|
|
|
|
2016-11-10 10:56:40 +01:00
|
|
|
bool IsForbidFlipping() const;
|
|
|
|
void SetForbidFlipping(bool value);
|
|
|
|
|
2016-11-10 11:53:02 +01:00
|
|
|
bool IsSeamAllowance() const;
|
|
|
|
void SetSeamAllowance(bool value);
|
|
|
|
|
|
|
|
qreal GetSAWidth() const;
|
|
|
|
void SetSAWidth(qreal value);
|
|
|
|
|
2016-11-11 16:55:02 +01:00
|
|
|
static QVector<QPointF> Equidistant(const QVector<VSAPoint> &points, qreal width);
|
2016-11-03 19:15:53 +01:00
|
|
|
static qreal SumTrapezoids(const QVector<QPointF> &points);
|
|
|
|
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);
|
2016-11-11 16:55:02 +01:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static QVector<T> CorrectEquidistantPoints(const QVector<T> &points, bool removeFirstAndLast = true);
|
2016-11-03 19:15:53 +01:00
|
|
|
|
|
|
|
protected:
|
2016-11-11 16:55:02 +01:00
|
|
|
template <class T>
|
|
|
|
static QVector<T> RemoveDublicates(const QVector<T> &points, bool removeFirstAndLast = true);
|
2016-11-09 14:53:22 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
QSharedDataPointer<VAbstractPieceData> d;
|
2016-11-10 13:06:09 +01:00
|
|
|
|
2017-01-11 13:53:16 +01:00
|
|
|
static bool CheckIntersection(const QVector<QPointF> &points, int i, int iNext, int j, int jNext,
|
|
|
|
const QPointF &crossPoint);
|
|
|
|
static bool ParallelCrossPoint(const QLineF &line1, const QLineF &line2, QPointF &point);
|
|
|
|
static bool Crossing(const QVector<QPointF> &sub1, const QVector<QPointF> &sub2);
|
|
|
|
static QVector<QPointF> SubPath(const QVector<QPointF> &path, int startIndex, int endIndex);
|
2016-11-13 10:23:04 +01:00
|
|
|
static Q_DECL_CONSTEXPR qreal PointPosition(const QPointF &p, const QLineF &line);
|
|
|
|
static qreal MaxLocalSA(const VSAPoint &p, qreal width);
|
2016-11-11 16:55:02 +01:00
|
|
|
static QVector<QPointF> EkvPoint(const VSAPoint &p1Line1, const VSAPoint &p2Line1,
|
|
|
|
const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width);
|
2016-11-19 14:29:54 +01:00
|
|
|
static QVector<QPointF> AngleByLength(const QPointF &p2, const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
2016-11-19 17:27:06 +01:00
|
|
|
static QVector<QPointF> AngleByIntersection(const QPointF &p1, const QPointF &p2, const QPointF &p3,
|
|
|
|
const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
|
|
|
static QVector<QPointF> AngleByFirstSymmetry(const QPointF &p1, const QPointF &p2,
|
|
|
|
const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
|
|
|
static QVector<QPointF> AngleBySecondSymmetry(const QPointF &p2, const QPointF &p3,
|
|
|
|
const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
|
|
|
static QVector<QPointF> AngleByFirstRightAngle(const QPointF &p1, const QPointF &p2,
|
|
|
|
const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
|
|
|
static QVector<QPointF> AngleBySecondRightAngle(const QPointF &p2, const QPointF &p3,
|
|
|
|
const QPointF &sp1, const QPointF &sp2, const QPointF &sp3,
|
|
|
|
qreal width);
|
2016-11-11 16:55:02 +01:00
|
|
|
static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width);
|
2016-11-13 10:23:04 +01:00
|
|
|
static QLineF ParallelLine(const QPointF &p1, const QPointF &p2, qreal width);
|
2016-11-11 15:26:00 +01:00
|
|
|
static QPointF SingleParallelPoint(const QPointF &p1, const QPointF &p2, qreal angle, qreal width);
|
2016-11-13 20:13:55 +01:00
|
|
|
static QLineF BisectorLine(const QPointF &p1, const QPointF &p2, const QPointF &p3);
|
|
|
|
static qreal AngleBetweenBisectors(const QLineF &b1, const QLineF &b2);
|
2016-11-03 19:15:53 +01:00
|
|
|
};
|
|
|
|
|
2017-01-22 09:50:23 +01:00
|
|
|
Q_DECLARE_TYPEINFO(VAbstractPiece, Q_MOVABLE_TYPE);
|
|
|
|
|
2016-11-11 16:55:02 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
|
|
* @brief CorrectEquidistantPoints clear equivalent points and remove point on line from equdistant.
|
|
|
|
* @param points list of points equdistant.
|
|
|
|
* @return corrected list.
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
QVector<T> VAbstractPiece::CorrectEquidistantPoints(const QVector<T> &points, bool removeFirstAndLast)
|
|
|
|
{
|
|
|
|
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
|
2016-12-10 19:09:03 +01:00
|
|
|
QVector<T> buf1 = RemoveDublicates(points, removeFirstAndLast);
|
2016-11-11 16:55:02 +01:00
|
|
|
|
2016-12-10 19:09:03 +01:00
|
|
|
if (buf1.size()<3)
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
2016-12-10 19:09:03 +01:00
|
|
|
return buf1;
|
2016-11-11 16:55:02 +01:00
|
|
|
}
|
|
|
|
|
2016-12-10 19:09:03 +01:00
|
|
|
QVector<T> buf2;
|
2016-11-11 16:55:02 +01:00
|
|
|
//Remove point on line
|
2016-12-10 19:09:03 +01:00
|
|
|
for (qint32 i = 0; i < buf1.size(); ++i)
|
2016-11-11 16:55:02 +01:00
|
|
|
{// In this case we alwayse will have bounded intersection, so all is need is to check if point i is on line.
|
|
|
|
// Unfortunatelly QLineF::intersect can't be used in this case because of the floating-point accuraccy problem.
|
2016-12-10 19:09:03 +01:00
|
|
|
int prev = i-1;
|
|
|
|
int next = i+1;
|
|
|
|
if (i == 0)
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
2016-12-10 19:09:03 +01:00
|
|
|
prev = buf1.size() - 1;
|
|
|
|
}
|
|
|
|
else if (i == buf1.size() - 1)
|
|
|
|
{
|
|
|
|
next = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QPointF &iPoint = buf1.at(i);
|
|
|
|
const QPointF &prevPoint = buf1.at(prev);
|
|
|
|
const QPointF &nextPoint = buf1.at(next);
|
|
|
|
|
|
|
|
if (not VGObject::IsPointOnLineviaPDP(buf1.at(i), buf1.at(prev), buf1.at(next))
|
|
|
|
&& prevPoint != nextPoint) // not zigzag
|
|
|
|
{
|
|
|
|
buf2.append(buf1.at(i));
|
|
|
|
}
|
|
|
|
else if ((i == 0 || i == buf1.size() - 1) && (iPoint == prevPoint || iPoint == nextPoint))
|
|
|
|
{
|
|
|
|
// If RemoveDublicates does not remove these points it is a valid case.
|
|
|
|
// Case where last point equal first point
|
|
|
|
buf2.append(buf1.at(i));
|
2016-11-11 16:55:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 19:09:03 +01:00
|
|
|
buf2 = RemoveDublicates(buf2, false);
|
|
|
|
|
|
|
|
return buf2;
|
2016-11-11 16:55:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
QVector<T> VAbstractPiece::RemoveDublicates(const QVector<T> &points, bool removeFirstAndLast)
|
|
|
|
{
|
|
|
|
QVector<T> p = points;
|
|
|
|
|
|
|
|
if (removeFirstAndLast)
|
|
|
|
{
|
|
|
|
if (not p.isEmpty() && p.size() > 1)
|
|
|
|
{
|
|
|
|
// Path can't be closed
|
|
|
|
if (p.first() == p.last())
|
|
|
|
{
|
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
p.remove(p.size() - 1);
|
|
|
|
#else
|
|
|
|
p.removeLast();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < p.size()-1; ++i)
|
|
|
|
{
|
|
|
|
if (p.at(i) == p.at(i+1))
|
|
|
|
{
|
|
|
|
if (not removeFirstAndLast && (i == p.size()-1))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
p.erase(p.begin() + i + 1);
|
|
|
|
--i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-11-03 19:15:53 +01:00
|
|
|
#endif // VABSTRACTPIECE_H
|