diff --git a/src/libs/vlayout/testpath.cpp b/src/libs/vlayout/testpath.cpp index 719bc965a..35f4d1533 100644 --- a/src/libs/vlayout/testpath.cpp +++ b/src/libs/vlayout/testpath.cpp @@ -35,6 +35,8 @@ #include #include +#include "vsapoint.h" + //--------------------------------------------------------------------------------------------------------------------- #if !defined(V_NO_ASSERT) // Use for writing tests @@ -54,19 +56,14 @@ void VectorToJson(const QVector &points, QJsonObject &json) } //--------------------------------------------------------------------------------------------------------------------- -void DumpVector(const QVector &points) +void VectorToJson(const QVector &points, QJsonObject &json) { - QTemporaryFile temp; // Go to tmp folder to find dump - temp.setAutoRemove(false); // Remove dump manually - if (temp.open()) + QJsonArray pointsArray; + for (auto point: points) { - QJsonObject vectorObject; - VectorToJson(points, vectorObject); - QJsonDocument vector(vectorObject); - - QTextStream out(&temp); - out << vector.toJson(); - out.flush(); + pointsArray.append(point.toJson()); } + json[QLatin1String("vector")] = pointsArray; } + #endif // !defined(V_NO_ASSERT) diff --git a/src/libs/vlayout/testpath.h b/src/libs/vlayout/testpath.h index 48e1d253b..192c4e18d 100644 --- a/src/libs/vlayout/testpath.h +++ b/src/libs/vlayout/testpath.h @@ -28,13 +28,45 @@ #ifndef TESTPATH_H #define TESTPATH_H +#include +#include +#include +#include +#include +#include + class QPointF; class QJsonObject; template class QVector; +class VSAPoint; #if !defined(V_NO_ASSERT) void VectorToJson(const QVector &points, QJsonObject &json); -void DumpVector(const QVector &points); +void VectorToJson(const QVector &points, QJsonObject &json); + +//--------------------------------------------------------------------------------------------------------------------- +template +void DumpVector(const QVector &points, const QString &templateName=QString()) +{ + QTemporaryFile temp; // Go to tmp folder to find dump + temp.setAutoRemove(false); // Remove dump manually + + if (not templateName.isEmpty()) + { + temp.setFileTemplate(QDir::tempPath() + QDir::separator() + templateName); + } + + if (temp.open()) + { + QJsonObject vectorObject; + VectorToJson(points, vectorObject); + QJsonDocument vector(vectorObject); + + QTextStream out(&temp); + out << vector.toJson(); + out.flush(); + } +} #endif // !defined(V_NO_ASSERT) #endif // TESTPATH_H diff --git a/src/libs/vlayout/vabstractpiece.cpp b/src/libs/vlayout/vabstractpiece.cpp index 2eaa0daf9..a6c741e0a 100644 --- a/src/libs/vlayout/vabstractpiece.cpp +++ b/src/libs/vlayout/vabstractpiece.cpp @@ -539,38 +539,6 @@ qreal AngleBetweenBisectors(const QLineF &b1, const QLineF &b2) return qMin(angle1, angle2); } -//--------------------------------------------------------------------------------------------------------------------- -#if !defined(V_NO_ASSERT) -// Use for writing tests -//--------------------------------------------------------------------------------------------------------------------- -void VectorToJson(const QVector &points, QJsonObject &json) -{ - QJsonArray pointsArray; - for (auto point: points) - { - pointsArray.append(point.toJson()); - } - json[QLatin1String("vector")] = pointsArray; -} - -//--------------------------------------------------------------------------------------------------------------------- -void DumpVector(const QVector &points) -{ - QTemporaryFile temp; // Go to tmp folder to find dump - temp.setAutoRemove(false); // Remove dump manually - if (temp.open()) - { - QJsonObject vectorObject; - VectorToJson(points, vectorObject); - QJsonDocument vector(vectorObject); - - QTextStream out(&temp); - out << vector.toJson(); - out.flush(); - } -} -#endif // !defined(V_NO_ASSERT) - //--------------------------------------------------------------------------------------------------------------------- template QVector CorrectPathDistortion(QVector path) diff --git a/src/libs/vlayout/vabstractpiece.h b/src/libs/vlayout/vabstractpiece.h index 2504a7abc..17f3882db 100644 --- a/src/libs/vlayout/vabstractpiece.h +++ b/src/libs/vlayout/vabstractpiece.h @@ -37,8 +37,8 @@ #include "../vmisc/diagnostic.h" #include "../vmisc/def.h" #include "../vgeometry/vgobject.h" - -template class QVector; +#include "vsapoint.h" +#include "testpath.h" class VAbstractPieceData; class QPainterPath; @@ -47,132 +47,6 @@ class VContainer; enum class LayoutGravity : qint8; enum class CuttingTime : unsigned char; -QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Weffc++") -QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") - -/** - * @brief The VSAPoint class seam allowance point - */ -class VSAPoint : public QPointF -{ -public: - Q_DECL_CONSTEXPR VSAPoint(); - Q_DECL_CONSTEXPR VSAPoint(qreal xpos, qreal ypos); - Q_DECL_CONSTEXPR explicit VSAPoint(QPointF p); - - Q_DECL_CONSTEXPR qreal GetSABefore() const; - qreal GetSABefore(qreal width) const; - void SetSABefore(qreal value); - - Q_DECL_CONSTEXPR qreal GetSAAfter() const; - qreal GetSAAfter(qreal width) const; - void SetSAAfter(qreal value); - - Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const; - void SetAngleType(PieceNodeAngle value); - - Q_DECL_CONSTEXPR bool IsManualPasskmarkLength() const; - Q_DECL_RELAXED_CONSTEXPR void SetManualPasskmarkLength(bool value); - - Q_DECL_CONSTEXPR qreal GetPasskmarkLength() const; - Q_DECL_RELAXED_CONSTEXPR void SetPasskmarkLength(qreal value); - - qreal MaxLocalSA(qreal width) const; - qreal PassmarkLength(qreal width) const; - - QJsonObject toJson() const; - - static const qreal passmarkFactor; - static const qreal maxPassmarkLength; - -private: - qreal m_before{-1}; - qreal m_after{-1}; - PieceNodeAngle m_angle{PieceNodeAngle::ByLength}; - bool m_manualPassmarkLength{false}; - qreal m_passmarkLength{0}; -}; - -Q_DECLARE_METATYPE(VSAPoint) -Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE); - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint() -{} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos) - : QPointF(xpos, ypos) -{} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(QPointF p) - : QPointF(p) -{} - -//--------------------------------------------------------------------------------------------------------------------- -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; -} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline PieceNodeAngle VSAPoint::GetAngleType() const -{ - return m_angle; -} - -//--------------------------------------------------------------------------------------------------------------------- -inline void VSAPoint::SetAngleType(PieceNodeAngle value) -{ - m_angle = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline bool VSAPoint::IsManualPasskmarkLength() const -{ - return m_manualPassmarkLength; -} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetManualPasskmarkLength(bool value) -{ - m_manualPassmarkLength = value; -} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_CONSTEXPR inline qreal VSAPoint::GetPasskmarkLength() const -{ - return m_passmarkLength; -} - -//--------------------------------------------------------------------------------------------------------------------- -Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetPasskmarkLength(qreal value) -{ - m_passmarkLength = value; -} - -QT_WARNING_POP - class VAbstractPiece { public: diff --git a/src/libs/vlayout/vlayout.pri b/src/libs/vlayout/vlayout.pri index f7b123133..d4acbecb2 100644 --- a/src/libs/vlayout/vlayout.pri +++ b/src/libs/vlayout/vlayout.pri @@ -13,6 +13,7 @@ HEADERS += \ $$PWD/vcontour_p.h \ $$PWD/vbestsquare.h \ $$PWD/vposition.h \ + $$PWD/vsapoint.h \ $$PWD/vtextmanager.h \ $$PWD/vposter.h \ $$PWD/vgraphicsfillitem.h \ diff --git a/src/libs/vlayout/vsapoint.h b/src/libs/vlayout/vsapoint.h new file mode 100644 index 000000000..b0c67dd25 --- /dev/null +++ b/src/libs/vlayout/vsapoint.h @@ -0,0 +1,162 @@ +/************************************************************************ + ** + ** @file vsapoint.h + ** @author Roman Telezhynskyi + ** @date 1 9, 2019 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentina project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2019 Valentina project + ** 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 . + ** + *************************************************************************/ +#ifndef VSAPOINT_H +#define VSAPOINT_H + +#include "../vmisc/diagnostic.h" +#include "../vmisc/def.h" + +#include + +QT_WARNING_PUSH +QT_WARNING_DISABLE_GCC("-Weffc++") +QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") + +/** + * @brief The VSAPoint class seam allowance point + */ +class VSAPoint : public QPointF +{ +public: + Q_DECL_CONSTEXPR VSAPoint(); + Q_DECL_CONSTEXPR VSAPoint(qreal xpos, qreal ypos); + Q_DECL_CONSTEXPR explicit VSAPoint(QPointF p); + + Q_DECL_CONSTEXPR qreal GetSABefore() const; + qreal GetSABefore(qreal width) const; + void SetSABefore(qreal value); + + Q_DECL_CONSTEXPR qreal GetSAAfter() const; + qreal GetSAAfter(qreal width) const; + void SetSAAfter(qreal value); + + Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const; + void SetAngleType(PieceNodeAngle value); + + Q_DECL_CONSTEXPR bool IsManualPasskmarkLength() const; + Q_DECL_RELAXED_CONSTEXPR void SetManualPasskmarkLength(bool value); + + Q_DECL_CONSTEXPR qreal GetPasskmarkLength() const; + Q_DECL_RELAXED_CONSTEXPR void SetPasskmarkLength(qreal value); + + qreal MaxLocalSA(qreal width) const; + qreal PassmarkLength(qreal width) const; + + QJsonObject toJson() const; + + static const qreal passmarkFactor; + static const qreal maxPassmarkLength; + +private: + qreal m_before{-1}; + qreal m_after{-1}; + PieceNodeAngle m_angle{PieceNodeAngle::ByLength}; + bool m_manualPassmarkLength{false}; + qreal m_passmarkLength{0}; +}; + +Q_DECLARE_METATYPE(VSAPoint) +Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE); + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint() +{} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos) + : QPointF(xpos, ypos) +{} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(QPointF p) + : QPointF(p) +{} + +//--------------------------------------------------------------------------------------------------------------------- +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; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline PieceNodeAngle VSAPoint::GetAngleType() const +{ + return m_angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline void VSAPoint::SetAngleType(PieceNodeAngle value) +{ + m_angle = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline bool VSAPoint::IsManualPasskmarkLength() const +{ + return m_manualPassmarkLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetManualPasskmarkLength(bool value) +{ + m_manualPassmarkLength = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_CONSTEXPR inline qreal VSAPoint::GetPasskmarkLength() const +{ + return m_passmarkLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetPasskmarkLength(qreal value) +{ + m_passmarkLength = value; +} + +QT_WARNING_POP + +#endif // VSAPOINT_H