2016-11-03 19:15:53 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 3 11, 2016
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2016-11-03 19:15:53 +01:00
|
|
|
** 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;
|
2017-10-15 11:25:20 +02:00
|
|
|
class QPainterPath;
|
2019-01-28 19:35:10 +01:00
|
|
|
class VGrainlineData;
|
|
|
|
class VContainer;
|
2019-07-22 16:06:30 +02:00
|
|
|
enum class LayoutGravity : qint8;
|
|
|
|
enum class CuttingTime : unsigned char;
|
2016-11-03 19:15:53 +01:00
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Weffc++")
|
2017-05-30 17:44:16 +02:00
|
|
|
QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
|
2016-11-11 11:54:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
2019-04-17 12:02:22 +02:00
|
|
|
Q_DECL_CONSTEXPR explicit VSAPoint(QPointF p);
|
2016-11-11 11:54:17 +01:00
|
|
|
|
|
|
|
Q_DECL_CONSTEXPR qreal GetSABefore() const;
|
2017-04-25 10:42:08 +02:00
|
|
|
qreal GetSABefore(qreal width) const;
|
2016-11-11 11:54:17 +01:00
|
|
|
void SetSABefore(qreal value);
|
|
|
|
|
|
|
|
Q_DECL_CONSTEXPR qreal GetSAAfter() const;
|
2017-04-25 10:42:08 +02:00
|
|
|
qreal GetSAAfter(qreal width) const;
|
2016-11-11 11:54:17 +01:00
|
|
|
void SetSAAfter(qreal value);
|
|
|
|
|
2016-11-19 14:29:54 +01:00
|
|
|
Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const;
|
|
|
|
void SetAngleType(PieceNodeAngle value);
|
|
|
|
|
2019-04-17 12:02:22 +02:00
|
|
|
Q_DECL_CONSTEXPR bool IsManualPasskmarkLength() const;
|
2019-04-17 16:35:11 +02:00
|
|
|
Q_DECL_RELAXED_CONSTEXPR void SetManualPasskmarkLength(bool value);
|
2019-04-17 12:02:22 +02:00
|
|
|
|
|
|
|
Q_DECL_CONSTEXPR qreal GetPasskmarkLength() const;
|
2019-04-17 16:35:11 +02:00
|
|
|
Q_DECL_RELAXED_CONSTEXPR void SetPasskmarkLength(qreal value);
|
2019-04-17 12:02:22 +02:00
|
|
|
|
2018-09-13 16:31:14 +02:00
|
|
|
qreal MaxLocalSA(qreal width) const;
|
2019-01-09 16:46:02 +01:00
|
|
|
qreal PassmarkLength(qreal width) const;
|
|
|
|
|
2019-08-07 16:53:18 +02:00
|
|
|
QJsonObject toJson() const;
|
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
static const qreal passmarkFactor;
|
|
|
|
static const qreal maxPassmarkLength;
|
2018-09-13 16:31:14 +02:00
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
private:
|
2019-04-17 12:02:22 +02:00
|
|
|
qreal m_before{-1};
|
|
|
|
qreal m_after{-1};
|
|
|
|
PieceNodeAngle m_angle{PieceNodeAngle::ByLength};
|
|
|
|
bool m_manualPassmarkLength{false};
|
|
|
|
qreal m_passmarkLength{0};
|
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()
|
|
|
|
{}
|
|
|
|
|
2016-11-18 11:58:47 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos)
|
2019-04-17 12:02:22 +02:00
|
|
|
: QPointF(xpos, ypos)
|
2016-11-18 11:58:47 +01:00
|
|
|
{}
|
|
|
|
|
2016-11-11 11:54:17 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-04-17 12:02:22 +02:00
|
|
|
Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(QPointF p)
|
|
|
|
: QPointF(p)
|
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;
|
2019-04-17 12:02:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline bool VSAPoint::IsManualPasskmarkLength() const
|
|
|
|
{
|
|
|
|
return m_manualPassmarkLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-04-17 16:35:11 +02:00
|
|
|
Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetManualPasskmarkLength(bool value)
|
2019-04-17 12:02:22 +02:00
|
|
|
{
|
|
|
|
m_manualPassmarkLength = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
Q_DECL_CONSTEXPR inline qreal VSAPoint::GetPasskmarkLength() const
|
|
|
|
{
|
|
|
|
return m_passmarkLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-04-17 16:35:11 +02:00
|
|
|
Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetPasskmarkLength(qreal value)
|
2019-04-17 12:02:22 +02:00
|
|
|
{
|
|
|
|
m_passmarkLength = value;
|
2016-11-19 14:29:54 +01:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
virtual ~VAbstractPiece();
|
|
|
|
|
2017-04-19 12:27:17 +02:00
|
|
|
VAbstractPiece &operator=(const VAbstractPiece &piece);
|
|
|
|
#ifdef Q_COMPILER_RVALUE_REFS
|
|
|
|
VAbstractPiece &operator=(VAbstractPiece &&piece) Q_DECL_NOTHROW { Swap(piece); return *this; }
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 12:32:06 +02:00
|
|
|
inline void Swap(VAbstractPiece &piece) Q_DECL_NOTHROW
|
2017-04-19 12:27:17 +02:00
|
|
|
{ std::swap(d, piece.d); }
|
|
|
|
|
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);
|
|
|
|
|
2017-12-17 14:06:46 +01:00
|
|
|
bool IsForceFlipping() const;
|
|
|
|
void SetForceFlipping(bool value);
|
|
|
|
|
2016-11-10 11:53:02 +01:00
|
|
|
bool IsSeamAllowance() const;
|
|
|
|
void SetSeamAllowance(bool value);
|
|
|
|
|
2017-04-05 12:22:33 +02:00
|
|
|
bool IsSeamAllowanceBuiltIn() const;
|
|
|
|
void SetSeamAllowanceBuiltIn(bool value);
|
|
|
|
|
2017-05-16 14:16:50 +02:00
|
|
|
bool IsHideMainPath() const;
|
|
|
|
void SetHideMainPath(bool value);
|
|
|
|
|
2016-11-10 11:53:02 +01:00
|
|
|
qreal GetSAWidth() const;
|
|
|
|
void SetSAWidth(qreal value);
|
|
|
|
|
2017-07-09 21:27:54 +02:00
|
|
|
qreal GetMx() const;
|
|
|
|
void SetMx(qreal value);
|
|
|
|
|
|
|
|
qreal GetMy() const;
|
|
|
|
void SetMy(qreal value);
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
uint GetPriority() const;
|
|
|
|
void SetPriority(uint value);
|
2017-07-09 21:27:54 +02:00
|
|
|
|
2018-10-22 13:43:06 +02:00
|
|
|
static QVector<QPointF> Equidistant(QVector<VSAPoint> points, qreal width, const QString &name);
|
2016-11-03 19:15:53 +01:00
|
|
|
static qreal SumTrapezoids(const QVector<QPointF> &points);
|
|
|
|
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);
|
2019-08-06 15:39:14 +02:00
|
|
|
static QVector<QPointF> EkvPoint(QVector<QPointF> points, const VSAPoint &p1Line1, const VSAPoint &p2Line1,
|
|
|
|
const VSAPoint &p1Line2, const VSAPoint &p2Line2, qreal width,
|
2019-01-09 16:46:02 +01:00
|
|
|
bool *needRollback = nullptr);
|
2017-03-28 12:09:00 +02:00
|
|
|
static QLineF ParallelLine(const VSAPoint &p1, const VSAPoint &p2, qreal width);
|
2019-02-23 17:43:06 +01:00
|
|
|
static bool IsAllowanceValid(const QVector<QPointF> &base, const QVector<QPointF> &allowance);
|
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
|
|
|
|
2019-01-09 16:46:02 +01:00
|
|
|
static QVector<QPointF> RollbackSeamAllowance(QVector<QPointF> points, const QLineF &cuttingEdge, bool *success);
|
|
|
|
|
2019-01-28 19:35:10 +01:00
|
|
|
static QVector<QPointF> GrainlinePoints(const VGrainlineData &geom, const VContainer *pattern,
|
|
|
|
const QRectF &boundingRect, qreal &dAng);
|
|
|
|
|
2019-07-01 11:26:08 +02:00
|
|
|
friend QDataStream& operator<< (QDataStream& dataStream, const VAbstractPiece& piece);
|
|
|
|
friend QDataStream& operator>> (QDataStream& dataStream, VAbstractPiece& piece);
|
|
|
|
|
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);
|
2017-04-27 17:19:23 +02:00
|
|
|
static bool IsEkvPointOnLine(const QPointF &iPoint, const QPointF &prevPoint, const QPointF &nextPoint);
|
2017-04-18 20:39:13 +02:00
|
|
|
static bool IsEkvPointOnLine(const VSAPoint &iPoint, const VSAPoint &prevPoint, const VSAPoint &nextPoint);
|
2016-11-09 14:53:22 +01:00
|
|
|
|
2019-01-28 19:35:10 +01:00
|
|
|
static bool IsItemContained(const QRectF &parentBoundingRect, const QVector<QPointF> &shape, qreal &dX,
|
|
|
|
qreal &dY);
|
|
|
|
static QVector<QPointF> CorrectPosition(const QRectF &parentBoundingRect, QVector<QPointF> points);
|
|
|
|
static bool FindGrainlineGeometry(const VGrainlineData& geom, const VContainer *pattern, qreal &length,
|
|
|
|
qreal &rotationAngle, QPointF &pos);
|
2016-11-09 14:53:22 +01:00
|
|
|
private:
|
|
|
|
QSharedDataPointer<VAbstractPieceData> d;
|
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
|
|
|
}
|
|
|
|
|
2017-03-20 07:16:35 +01:00
|
|
|
int prev = -1;
|
|
|
|
|
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.
|
2017-03-20 07:16:35 +01:00
|
|
|
if (prev == -1)
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
2019-05-27 16:07:18 +02:00
|
|
|
prev = (i == 0) ? buf1.size() - 1 : i-1;
|
2016-12-10 19:09:03 +01:00
|
|
|
}
|
2017-03-20 07:16:35 +01:00
|
|
|
|
2019-05-27 16:07:18 +02:00
|
|
|
const int next = (i == buf1.size() - 1) ? 0 : i+1;
|
2016-12-10 19:09:03 +01:00
|
|
|
|
2017-03-30 10:06:47 +02:00
|
|
|
const T &iPoint = buf1.at(i);
|
|
|
|
const T &prevPoint = buf1.at(prev);
|
|
|
|
const T &nextPoint = buf1.at(next);
|
2016-12-10 19:09:03 +01:00
|
|
|
|
2017-04-18 20:39:13 +02:00
|
|
|
if (not (IsEkvPointOnLine(iPoint, prevPoint, nextPoint) && prevPoint == nextPoint/*not zigzag*/)
|
2017-03-30 10:06:47 +02:00
|
|
|
// If RemoveDublicates does not remove these points it is a valid case.
|
|
|
|
// Case where last point equal first point
|
|
|
|
|| ((i == 0 || i == buf1.size() - 1) && (iPoint == prevPoint || iPoint == nextPoint)))
|
2016-12-10 19:09:03 +01:00
|
|
|
{
|
2017-03-30 10:06:47 +02:00
|
|
|
buf2.append(iPoint);
|
2017-03-20 07:16:35 +01:00
|
|
|
prev = -1;
|
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
|
2017-05-18 14:10:05 +02:00
|
|
|
// See issue #686
|
2018-09-27 13:52:21 +02:00
|
|
|
if (VFuzzyComparePoints(p.first(), p.last()))
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
|
|
|
p.removeLast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < p.size()-1; ++i)
|
|
|
|
{
|
2018-09-27 13:52:21 +02:00
|
|
|
if (VFuzzyComparePoints(p.at(i), p.at(i+1)))
|
2016-11-11 16:55:02 +01:00
|
|
|
{
|
|
|
|
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
|