1 /************************************************************************
2 **
3 ** @file vgeometrydef.h
4 ** @author Roman Telezhynskyi <dismine(at)gmail.com>
5 ** @date 7 5, 2015
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) 2015 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
29 #ifndef VGEOMETRYDEF_H
30 #define VGEOMETRYDEF_H
31
32 #include <QVector>
33 #include <QPolygonF>
34 #include <QTransform>
35
36 #include "../ifc/ifcdef.h"
37
38 enum class GOType : qint8
39 {
40 Point,
41 Arc,
42 EllipticalArc,
43 Spline,
44 SplinePath,
45 CubicBezier,
46 CubicBezierPath,
47 PlaceLabel,
48 Unknown
49 };
50 enum class SplinePointPosition : qint8 { FirstPoint, LastPoint };
51
52 // Keep synchronized with XSD schema
53 enum class PlaceLabelType : quint8
54 {
55 Segment= 0,
56 Rectangle = 1,
57 Cross = 2,
58 Tshaped = 3,
59 Doubletree = 4,
60 Corner = 5,
61 Triangle = 6,
62 Hshaped = 7,
63 Button = 8,
64 Circle = 9
65 };
66
67 typedef QVector<QPolygonF> PlaceLabelImg;
68
69 struct VLayoutPlaceLabel
70 {
71 QPointF center{};
72 PlaceLabelType type{PlaceLabelType::Button};
73 PlaceLabelImg shape{};
74 QTransform rotationMatrix{};
75 QRectF box{};
76
77 friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPlaceLabel& data);
78 friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPlaceLabel& data);
79 private:
80 static const quint32 streamHeader;
81 static const quint16 classVersion;
82 };
83 Q_DECLARE_METATYPE(VLayoutPlaceLabel)
84
85 struct VLayoutPassmark
86 {
87 QVector<QLineF> lines{};
88 PassmarkLineType type{PassmarkLineType::OneLine};
89 QLineF baseLine{};
90 bool isBuiltIn{false};
91
92 friend QDataStream& operator<<(QDataStream& dataStream, const VLayoutPassmark& data);
93 friend QDataStream& operator>>(QDataStream& dataStream, VLayoutPassmark& data);
94 private:
95 static const quint32 streamHeader;
96 static const quint16 classVersion;
97 };
98 Q_DECLARE_METATYPE(VLayoutPassmark)
99
100 constexpr qreal accuracyPointOnLine = (0.1555/*mm*/ / 25.4) * PrintDPI;
101
102 Q_REQUIRED_RESULT static inline bool VFuzzyComparePoints(const QPointF &p1, const QPointF &p2,
103 qreal accuracy = accuracyPointOnLine);
VFuzzyComparePoints(const QPointF & p1,const QPointF & p2,qreal accuracy)104 static inline bool VFuzzyComparePoints(const QPointF &p1, const QPointF &p2, qreal accuracy)
105 {
106 return QLineF(p1, p2).length() <= accuracy;
107 }
108
109 Q_REQUIRED_RESULT static inline bool VFuzzyOnAxis(qreal v1, qreal v2, qreal accuracy = accuracyPointOnLine);
VFuzzyOnAxis(qreal v1,qreal v2,qreal accuracy)110 static inline bool VFuzzyOnAxis(qreal v1, qreal v2, qreal accuracy)
111 {
112 return qAbs(v1 - v2) <= accuracy;
113 }
114
115 #endif // VGEOMETRYDEF_H
116