1 /************************************************************************
2  **
3  **  @file   vbank.h
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   11 1, 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) 2013-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 VBANK_H
30 #define VBANK_H
31 
32 #include <QHash>
33 #include <QMap>
34 #include <QRectF>
35 #include <QVector>
36 #include <QtGlobal>
37 #include <QLoggingCategory>
38 
39 #include "../vmisc/typedef.h"
40 #include "vlayoutpiece.h"
41 #include "vlayoutdef.h"
42 
43 // An annoying char define, from the Windows team in <rpcndr.h>
44 // #define small char
45 // http://stuartjames.info/Journal/c--visual-studio-2012-vs2012--win8--converting-projects-up-some-conflicts-i-found.aspx
46 #if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
47 #pragma push_macro("small")
48 #undef small
49 #endif
50 
Q_DECLARE_LOGGING_CATEGORY(lBank)51 Q_DECLARE_LOGGING_CATEGORY(lBank)
52 
53 class VBank
54 {
55     Q_DECLARE_TR_FUNCTIONS(VBank)
56 public:
57     VBank();
58 
59     qreal GetLayoutWidth() const;
60     void SetLayoutWidth(qreal value);
61 
62     bool GetManualPriority() const;
63     void SetManualPriority(bool value);
64 
65     bool IsNestQuantity() const;
66     void SetNestQuantity(bool value);
67 
68     void SetDetails(const QVector<VLayoutPiece> &details);
69     int  GetNext();
70     VLayoutPiece GetDetail(int i) const;
71 
72     void Arranged(int i);
73     void NotArranged(int i);
74 
75     bool PrepareUnsorted();
76     bool PrepareDetails();
77     void Reset();
78     void SetCaseType(Cases caseType);
79 
80     int AllDetailsCount() const;
81     int LeftToArrange() const;
82     int FailedToArrange() const;
83 
84     qreal GetBiggestDiagonal() const;
85 
86     bool IsRotationNeeded() const;
87 
88 private:
89     Q_DISABLE_COPY(VBank)
90     QVector<VLayoutPiece> details{};
91 
92     QMap<uint, QHash<int, qint64>> unsorted{};
93     QMap<uint, QHash<int, qint64>> big{};
94     QMap<uint, QHash<int, qint64>> middle{};
95     QMap<uint, QHash<int, qint64>> small{};
96     QMap<uint, QMultiMap<qint64, int>> desc{};
97 
98     QVector<uint> groups{};
99     QVector<vidtype> arranged{};
100 
101     qreal layoutWidth{0};
102 
103     Cases caseType{Cases::CaseDesc};
104     bool prepare{false};
105     qreal diagonal{0};
106     bool m_nestQuantity{false};
107     bool m_manualPriority{false};
108 
109     void PrepareGroup();
110 
111     void PrepareThreeGroups(uint priority);
112     void PrepareTwoGroups(uint priority);
113     void PrepareDescGroup(uint priority);
114 
115     int GetNextThreeGroups(uint priority) const;
116     int GetNextTwoGroups(uint priority) const;
117     int GetNextDescGroup(uint priority) const;
118 
119     void SqMaxMin(qint64 &sMax, qint64 &sMin, uint priority) const;
120 
121     bool ArrangedDetail(QMap<uint, QHash<int, qint64>> &container, int i);
122     bool ArrangedDetail(QMap<uint, QMultiMap<qint64, int>> &container, int i);
123 };
124 
125 #if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
126 #pragma pop_macro("small")
127 #endif
128 
129 #endif // VBANK_H
130