1 /************************************************************************
2  **
3  **  @file
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   3 11, 2016
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) 2016 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 VPIECE_H
30 #define VPIECE_H
31 
32 #include <QtGlobal>
33 #include <QSharedDataPointer>
34 
35 #include "../vlayout/vabstractpiece.h"
36 #include "../vgeometry/vgeometrydef.h"
37 
38 class VPieceData;
39 class VPieceNode;
40 class VPiecePath;
41 class VPatternLabelData;
42 class VPieceLabelData;
43 class VGrainlineData;
44 class VContainer;
45 class QPainterPath;
46 class VPointF;
47 class VPassmark;
48 
49 class VPiece : public VAbstractPiece
50 {
51     Q_DECLARE_TR_FUNCTIONS(VPiece)
52 public:
53     VPiece();
54     VPiece(const VPiece &piece);
55 
56     virtual ~VPiece();
57 
58     VPiece &operator=(const VPiece &piece);
59 #ifdef Q_COMPILER_RVALUE_REFS
60     VPiece(const VPiece &&piece) Q_DECL_NOTHROW;
61     VPiece &operator=(VPiece &&piece) Q_DECL_NOTHROW;
62 #endif
63 
64     VPiecePath GetPath() const;
65     VPiecePath &GetPath();
66     void       SetPath(const VPiecePath &path);
67 
68     QVector<QPointF>       MainPathPoints(const VContainer *data) const;
69     QVector<QPointF>       UniteMainPathPoints(const VContainer *data) const;
70     QVector<VPointF>       MainPathNodePoints(const VContainer *data, bool showExcluded = false) const;
71     QVector<QPointF>       SeamAllowancePoints(const VContainer *data) const;
72     QVector<QPointF>       CuttingPathPoints(const VContainer *data) const;
73     QVector<QLineF>        PassmarksLines(const VContainer *data) const;
74 
75     QVector<VPassmark>     Passmarks(const VContainer *data) const;
76 
77     QVector<QPainterPath> CurvesPainterPath(const VContainer *data) const;
78 
79     QPainterPath        MainPathPath(const VContainer *data) const;
80     static QPainterPath MainPathPath(const QVector<QPointF> &points);
81 
82     QPainterPath SeamAllowancePath(const VContainer *data) const;
83     QPainterPath SeamAllowancePath(const QVector<QPointF> &points) const;
84     QPainterPath PassmarksPath(const VContainer *data) const;
85     QPainterPath PlaceLabelPath(const VContainer *data) const;
86 
87     bool IsSeamAllowanceValid(const VContainer *data) const;
88 
89     bool IsInLayout() const;
90     void SetInLayout(bool inLayout);
91 
92     bool IsUnited() const;
93     void SetUnited(bool united);
94 
95     QString GetFormulaSAWidth() const;
96     void    SetFormulaSAWidth(const QString &formula, qreal value);
97 
98     QVector<quint32> GetInternalPaths() const;
99     QVector<quint32> &GetInternalPaths();
100     void             SetInternalPaths(const QVector<quint32> &iPaths);
101 
102     QVector<CustomSARecord> GetCustomSARecords() const;
103     QVector<CustomSARecord> &GetCustomSARecords();
104     void                    SetCustomSARecords(const QVector<CustomSARecord> &records);
105 
106     QVector<quint32> GetPins() const;
107     QVector<quint32> &GetPins();
108     void             SetPins(const QVector<quint32> &pins);
109 
110     QVector<quint32> GetPlaceLabels() const;
111     QVector<quint32> &GetPlaceLabels();
112     void             SetPlaceLabels(const QVector<quint32> &labels);
113 
114     QList<quint32> Dependencies() const;
115     QVector<quint32> MissingNodes(const VPiece &det) const;
116     QVector<quint32> MissingCSAPath(const VPiece &det) const;
117     QVector<quint32> MissingInternalPaths(const VPiece &det) const;
118     QVector<quint32> MissingPins(const VPiece &det) const;
119     QVector<quint32> MissingPlaceLabels(const VPiece &det) const;
120 
121     void                   SetPatternPieceData(const VPieceLabelData &data);
122     VPieceLabelData&       GetPatternPieceData();
123     const VPieceLabelData& GetPatternPieceData() const;
124 
125     void                     SetPatternInfo(const VPatternLabelData &info);
126     VPatternLabelData&       GetPatternInfo();
127     const VPatternLabelData& GetPatternInfo() const;
128 
129     void                    SetGrainlineGeometry(const VGrainlineData &data);
130     VGrainlineData&         GetGrainlineGeometry();
131     const VGrainlineData&   GetGrainlineGeometry() const;
132 
133     QVector<VPieceNode> GetUnitedPath(const VContainer *data) const;
134 
135     QVector<QPointF> SeamAllowancePointsWithRotation(const VContainer *data, int makeFirst) const;
136 
137     static void DumpPiece(const VPiece &piece, const VContainer *data);
138 private:
139     QSharedDataPointer<VPieceData> d;
140 
141     QVector<CustomSARecord> GetValidRecords() const;
142     QVector<CustomSARecord> FilterRecords(QVector<CustomSARecord> records) const;
143 
144     QVector<VSAPoint> GetNodeSAPoints(const QVector<VPieceNode> &path, int index, const VContainer *data) const;
145 
146     bool GetPassmarkSAPoint(const QVector<VPieceNode> &path, int index, const VContainer *data, VSAPoint &point) const;
147     bool GetPassmarkPreviousSAPoints(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
148                                      const VContainer *data, VSAPoint &point, int passmarkIndex) const;
149     bool GetPassmarkNextSAPoints(const QVector<VPieceNode> &path, int index, const VSAPoint &passmarkSAPoint,
150                                  const VContainer *data, VSAPoint &point, int passmarkIndex) const;
151 
152     bool IsPassmarkVisible(const QVector<VPieceNode> &path, int passmarkIndex) const;
153 
154     VPassmark CreatePassmark(const QVector<VPieceNode> &path, int previousIndex, int passmarkIndex, int nextIndex,
155                              const VContainer *data) const;
156 
157     static int IsCSAStart(const QVector<CustomSARecord> &records, quint32 id);
158 
159     QJsonObject MainPathToJson() const;
160     QJsonObject DBToJson(const VContainer *data) const;
161 
162     qreal GlobalPassmarkLength(const VContainer *data) const;
163 };
164 
165 Q_DECLARE_TYPEINFO(VPiece, Q_MOVABLE_TYPE);
166 
167 #endif // VPIECE_H
168