1 /************************************************************************
2  **
3  **  @file   vsapoint.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   1 9, 2019
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2019 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 #ifndef VSAPOINT_H
29 #define VSAPOINT_H
30 
31 #include "../vmisc/diagnostic.h"
32 #include "../vmisc/def.h"
33 #include "../ifc/ifcdef.h"
34 
35 #include <QPointF>
36 
37 QT_WARNING_PUSH
38 QT_WARNING_DISABLE_GCC("-Weffc++")
39 QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor")
40 
41 /**
42  * @brief The VSAPoint class seam allowance point
43  */
44 class VSAPoint : public QPointF
45 {
46 public:
47     Q_DECL_CONSTEXPR VSAPoint() V_NOEXCEPT_EXPR (true);
48     Q_DECL_CONSTEXPR VSAPoint(qreal xpos, qreal ypos);
49     Q_DECL_CONSTEXPR explicit VSAPoint(QPointF p);
50 
51     Q_DECL_CONSTEXPR qreal GetSABefore() const;
52                      qreal GetSABefore(qreal width) const;
53                      void  SetSABefore(qreal value);
54 
55     Q_DECL_CONSTEXPR qreal GetSAAfter() const;
56                      qreal GetSAAfter(qreal width) const;
57                      void  SetSAAfter(qreal value);
58 
59     Q_DECL_CONSTEXPR PieceNodeAngle GetAngleType() const;
60                      void           SetAngleType(PieceNodeAngle value);
61 
62     Q_DECL_CONSTEXPR bool IsManualPasskmarkLength() const;
63     Q_DECL_RELAXED_CONSTEXPR void SetManualPasskmarkLength(bool value);
64 
65     Q_DECL_CONSTEXPR qreal GetPasskmarkLength() const;
66     Q_DECL_RELAXED_CONSTEXPR void  SetPasskmarkLength(qreal value);
67 
68     qreal MaxLocalSA(qreal width) const;
69     qreal PassmarkLength(qreal width) const;
70 
71     QJsonObject toJson() const;
72 
73     static const qreal passmarkFactor;
74     static const qreal maxPassmarkLength;
75     static const qreal minSAWidth;
76 
77 private:
78     qreal          m_before{-1};
79     qreal          m_after{-1};
80     PieceNodeAngle m_angle{PieceNodeAngle::ByLength};
81     bool           m_manualPassmarkLength{false};
82     qreal          m_passmarkLength{0};
83 };
84 
85 Q_DECLARE_METATYPE(VSAPoint)
86 Q_DECLARE_TYPEINFO(VSAPoint, Q_MOVABLE_TYPE);
87 
88 //---------------------------------------------------------------------------------------------------------------------
VSAPoint()89 Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint() V_NOEXCEPT_EXPR (true)
90 {}
91 
92 //---------------------------------------------------------------------------------------------------------------------
VSAPoint(qreal xpos,qreal ypos)93 Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(qreal xpos, qreal ypos)
94     : QPointF(xpos, ypos)
95 {}
96 
97 //---------------------------------------------------------------------------------------------------------------------
98 // cppcheck-suppress passedByValue
VSAPoint(QPointF p)99 Q_DECL_CONSTEXPR inline VSAPoint::VSAPoint(QPointF p)
100     : QPointF(p)
101 {}
102 
103 //---------------------------------------------------------------------------------------------------------------------
GetSABefore()104 Q_DECL_CONSTEXPR inline qreal VSAPoint::GetSABefore() const
105 {
106     return m_before;
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
SetSABefore(qreal value)110 inline void VSAPoint::SetSABefore(qreal value)
111 {
112     value < 0 ? m_before = -1 : m_before = value;
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
GetSAAfter()116 Q_DECL_CONSTEXPR inline qreal VSAPoint::GetSAAfter() const
117 {
118     return m_after;
119 }
120 
121 //---------------------------------------------------------------------------------------------------------------------
SetSAAfter(qreal value)122 inline void VSAPoint::SetSAAfter(qreal value)
123 {
124     value < 0 ? m_after = -1 : m_after = value;
125 }
126 
127 //---------------------------------------------------------------------------------------------------------------------
GetAngleType()128 Q_DECL_CONSTEXPR inline PieceNodeAngle VSAPoint::GetAngleType() const
129 {
130     return m_angle;
131 }
132 
133 //---------------------------------------------------------------------------------------------------------------------
SetAngleType(PieceNodeAngle value)134 inline void VSAPoint::SetAngleType(PieceNodeAngle value)
135 {
136     m_angle = value;
137 }
138 
139 //---------------------------------------------------------------------------------------------------------------------
IsManualPasskmarkLength()140 Q_DECL_CONSTEXPR inline bool VSAPoint::IsManualPasskmarkLength() const
141 {
142     return m_manualPassmarkLength;
143 }
144 
145 //---------------------------------------------------------------------------------------------------------------------
SetManualPasskmarkLength(bool value)146 Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetManualPasskmarkLength(bool value)
147 {
148     m_manualPassmarkLength = value;
149 }
150 
151 //---------------------------------------------------------------------------------------------------------------------
GetPasskmarkLength()152 Q_DECL_CONSTEXPR inline qreal VSAPoint::GetPasskmarkLength() const
153 {
154     return m_passmarkLength;
155 }
156 
157 //---------------------------------------------------------------------------------------------------------------------
SetPasskmarkLength(qreal value)158 Q_DECL_RELAXED_CONSTEXPR inline void VSAPoint::SetPasskmarkLength(qreal value)
159 {
160     m_passmarkLength = value;
161 }
162 
163 QT_WARNING_POP
164 
165 #endif // VSAPOINT_H
166