Seamly2D
Code documentation
vposition.h
Go to the documentation of this file.
1 /***************************************************************************
2  ** @file vposition.h
3  ** @author Douglas S Caskey
4  ** @date Dec 11, 2022
5  **
6  ** @copyright
7  ** Copyright (C) 2017 - 2022 Seamly, LLC
8  ** https://github.com/fashionfreedom/seamly2d
9  **
10  ** @brief
11  ** Seamly2D is free software: you can redistribute it and/or modify
12  ** it under the terms of the GNU General Public License as published by
13  ** the Free Software Foundation, either version 3 of the License, or
14  ** (at your option) any later version.
15  **
16  ** Seamly2D is distributed in the hope that it will be useful,
17  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  ** GNU General Public License for more details.
20  **
21  ** You should have received a copy of the GNU General Public License
22  ** along with Seamly2D. if not, see <http://www.gnu.org/licenses/>.
23  **************************************************************************/
24 
25 /************************************************************************
26  **
27  ** @file vposition.h
28  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
29  ** @date 20 1, 2015
30  **
31  ** @brief
32  ** @copyright
33  ** This source code is part of the Valentina project, a pattern making
34  ** program, whose allow create and modeling patterns of clothing.
35  ** Copyright (C) 2013-2015 Valentina project
36  ** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
37  **
38  ** Valentina is free software: you can redistribute it and/or modify
39  ** it under the terms of the GNU General Public License as published by
40  ** the Free Software Foundation, either version 3 of the License, or
41  ** (at your option) any later version.
42  **
43  ** Valentina is distributed in the hope that it will be useful,
44  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46  ** GNU General Public License for more details.
47  **
48  ** You should have received a copy of the GNU General Public License
49  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
50  **
51  *************************************************************************/
52 
53 #ifndef VPOSITION_H
54 #define VPOSITION_H
55 
56 #include <qcompilerdetection.h>
57 #include <QRunnable>
58 #include <QVector>
59 #include <QtGlobal>
60 #include <atomic>
61 
62 #include "vbestsquare.h"
63 #include "vcontour.h"
64 #include "vlayoutdef.h"
65 #include "vlayoutpiece.h"
66 
67 class VPosition : public QRunnable
68 {
69 public:
70  VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, bool rotate,
71  int rotationIncrease, bool saveLength);
72  virtual ~VPosition() Q_DECL_OVERRIDE{}
73 
74  quint32 getPaperIndex() const;
75  void setPaperIndex(const quint32 &value);
76 
77  quint32 getFrame() const;
78  void setFrame(const quint32 &value);
79 
80  quint32 getPieceCount() const;
81  void setPieceCount(const quint32 &value);
82 
84 
85  VBestSquare getBestResult() const;
86 
87  static void DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex,
89 
90  static int Bias(int length, int maxLength);
91 
92 private:
93  Q_DISABLE_COPY(VPosition)
97  int i;
98  int j;
99  quint32 paperIndex;
100  quint32 frame;
101  quint32 piecesCount;
103  std::atomic_bool *stop;
104  bool rotate;
106  /**
107  * @brief angle_between keep angle between global edge and piece edge. Need for optimization rotation.
108  */
110 
111  enum class CrossingType : char
112  {
113  NoIntersection = 0,
114  Intersection = 1,
115  EdgeError = 2
116  };
117 
118  enum class InsideType : char
119  {
120  Outside = 0,
121  Inside = 1,
122  EdgeError = 2
123  };
124 
125  virtual void run() Q_DECL_OVERRIDE;
126 
127  void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type);
128 
129  bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge);
130  bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const;
131 
132  CrossingType Crossing(const VLayoutPiece &piece) const;
133  bool SheetContains(const QRectF &rect) const;
134 
135  void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge);
136  void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const;
137 
138  static QPainterPath ShowDirection(const QLineF &edge);
139  static QPainterPath DrawContour(const QVector<QPointF> &points);
140  static QPainterPath drawPieces(const QVector<VLayoutPiece> &pieces);
141 
142  void Rotate(int increase);
143 };
144 
145 #endif // VPOSITION_H
QVector< VLayoutPiece > pieces
Definition: vposition.h:102
VBestSquare bestResult
Definition: vposition.h:94
qreal angle_between
angle_between keep angle between global edge and piece edge. Need for optimization rotation.
Definition: vposition.h:109
CrossingType Crossing(const VLayoutPiece &piece) const
Definition: vposition.cpp:414
static int Bias(int length, int maxLength)
Definition: vposition.cpp:267
quint32 frame
Definition: vposition.h:100
quint32 paperIndex
Definition: vposition.h:99
VPosition(const VContour &gContour, int j, const VLayoutPiece &piece, int i, std::atomic_bool *stop, bool rotate, int rotationIncrease, bool saveLength)
Definition: vposition.cpp:77
static QPainterPath ShowDirection(const QLineF &edge)
Definition: vposition.cpp:528
void Rotate(int increase)
Definition: vposition.cpp:495
bool CheckRotationEdges(VLayoutPiece &piece, int j, int dEdge, int angle) const
Definition: vposition.cpp:378
VBestSquare getBestResult() const
Definition: vposition.cpp:183
quint32 getPaperIndex() const
Definition: vposition.cpp:139
void CombineEdges(VLayoutPiece &piece, const QLineF &globalEdge, const int &dEdge)
Definition: vposition.cpp:442
static void DrawDebug(const VContour &contour, const VLayoutPiece &piece, int frame, quint32 paperIndex, int piecesCount, const QVector< VLayoutPiece > &pieces=QVector< VLayoutPiece >())
Definition: vposition.cpp:189
bool rotate
Definition: vposition.h:104
const VLayoutPiece piece
Definition: vposition.h:96
virtual void run() Q_DECL_OVERRIDE
Definition: vposition.cpp:101
static QPainterPath drawPieces(const QVector< VLayoutPiece > &pieces)
Definition: vposition.cpp:587
void setPieces(const QVector< VLayoutPiece > &pieces)
Definition: vposition.cpp:177
static QPainterPath DrawContour(const QVector< QPointF > &points)
Definition: vposition.cpp:556
void RotateEdges(VLayoutPiece &piece, const QLineF &globalEdge, int dEdge, int angle) const
Definition: vposition.cpp:471
std::atomic_bool * stop
Definition: vposition.h:103
void setFrame(const quint32 &value)
Definition: vposition.cpp:158
const VContour gContour
Definition: vposition.h:95
bool CheckCombineEdges(VLayoutPiece &piece, int j, int &dEdge)
Definition: vposition.cpp:290
bool SheetContains(const QRectF &rect) const
Definition: vposition.cpp:435
void setPaperIndex(const quint32 &value)
Definition: vposition.cpp:145
quint32 getFrame() const
Definition: vposition.cpp:152
quint32 piecesCount
Definition: vposition.h:101
virtual ~VPosition() Q_DECL_OVERRIDE
Definition: vposition.h:72
quint32 getPieceCount() const
Definition: vposition.cpp:165
void setPieceCount(const quint32 &value)
Definition: vposition.cpp:171
int rotationIncrease
Definition: vposition.h:105
void SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &piece, int globalI, int detJ, BestFrom type)
Definition: vposition.cpp:280
BestFrom
Definition: vlayoutdef.h:68