Refactoring. Move class VSAPoint to separate file.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-09-01 12:58:54 +03:00
parent d12070b146
commit 27a08641fa
6 changed files with 206 additions and 172 deletions

View File

@ -35,6 +35,8 @@
#include <QJsonDocument>
#include <QPointF>
#include "vsapoint.h"
//---------------------------------------------------------------------------------------------------------------------
#if !defined(V_NO_ASSERT)
// Use for writing tests
@ -54,19 +56,14 @@ void VectorToJson(const QVector<QPointF> &points, QJsonObject &json)
}
//---------------------------------------------------------------------------------------------------------------------
void DumpVector(const QVector<QPointF> &points)
void VectorToJson(const QVector<VSAPoint> &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)

View File

@ -28,13 +28,45 @@
#ifndef TESTPATH_H
#define TESTPATH_H
#include <QDir>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <QTemporaryFile>
#include <QTextStream>
class QPointF;
class QJsonObject;
template <class T> class QVector;
class VSAPoint;
#if !defined(V_NO_ASSERT)
void VectorToJson(const QVector<QPointF> &points, QJsonObject &json);
void DumpVector(const QVector<QPointF> &points);
void VectorToJson(const QVector<VSAPoint> &points, QJsonObject &json);
//---------------------------------------------------------------------------------------------------------------------
template <class T>
void DumpVector(const QVector<T> &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

View File

@ -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<VSAPoint> &points, QJsonObject &json)
{
QJsonArray pointsArray;
for (auto point: points)
{
pointsArray.append(point.toJson());
}
json[QLatin1String("vector")] = pointsArray;
}
//---------------------------------------------------------------------------------------------------------------------
void DumpVector(const QVector<VSAPoint> &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<class T>
QVector<T> CorrectPathDistortion(QVector<T> path)

View File

@ -37,8 +37,8 @@
#include "../vmisc/diagnostic.h"
#include "../vmisc/def.h"
#include "../vgeometry/vgobject.h"
template <class T> 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:

View File

@ -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 \

162
src/libs/vlayout/vsapoint.h Normal file
View File

@ -0,0 +1,162 @@
/************************************************************************
**
** @file vsapoint.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @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
** <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 VSAPOINT_H
#define VSAPOINT_H
#include "../vmisc/diagnostic.h"
#include "../vmisc/def.h"
#include <QPointF>
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