Allow controlling priority selecting pieces in layout.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2019-07-19 10:45:57 +03:00
parent a3e643b5dd
commit e37afae597
15 changed files with 404 additions and 153 deletions

View File

@ -25,6 +25,7 @@
- New feature Pattern recipe. - New feature Pattern recipe.
- New options to hide all/show all visibility groups. - New options to hide all/show all visibility groups.
- New feature "Hide piece's main path". - New feature "Hide piece's main path".
- Allow controlling priority selecting pieces in layout.
# Version 0.6.2 (unreleased) # Version 0.6.2 (unreleased)
- [#903] Bug in tool Cut Spline path. - [#903] Bug in tool Cut Spline path.

View File

@ -975,7 +975,7 @@ QVector<VLayoutPiece> MainWindowsNoGUI::PrepareDetailsForLayout(const QVector<De
{ {
VAbstractTool *tool = qobject_cast<VAbstractTool*>(VAbstractPattern::getTool(data.id)); VAbstractTool *tool = qobject_cast<VAbstractTool*>(VAbstractPattern::getTool(data.id));
SCASSERT(tool != nullptr) SCASSERT(tool != nullptr)
return VLayoutPiece::Create(data.piece, tool->getData()); return VLayoutPiece::Create(data.piece, data.id, tool->getData());
}; };
QProgressDialog progress(tr("Preparing details for layout"), QString(), 0, details.size()); QProgressDialog progress(tr("Preparing details for layout"), QString(), 0, details.size());

View File

@ -837,6 +837,7 @@ void VPattern::ParseDetailElement(QDomElement &domElement, const Document &parse
QString().setNum(qApp->ValentinaSettings()->GetForceWorkpieceFlipping()))); QString().setNum(qApp->ValentinaSettings()->GetForceWorkpieceFlipping())));
initData.detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr)); initData.detail.SetInLayout(GetParametrBool(domElement, AttrInLayout, trueStr));
initData.detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr)); initData.detail.SetUnited(GetParametrBool(domElement, VToolSeamAllowance::AttrUnited, falseStr));
initData.detail.SetPriority(GetParametrUInt(domElement, VToolSeamAllowance::AttrPiecePriority, QChar('0')));
initData.width = GetParametrString(domElement, AttrWidth, QStringLiteral("0.0")); initData.width = GetParametrString(domElement, AttrWidth, QStringLiteral("0.0"));
const QString w = initData.width;//need for saving fixed formula; const QString w = initData.width;//need for saving fixed formula;

View File

@ -43,7 +43,7 @@
#include <QTemporaryFile> #include <QTemporaryFile>
const quint32 VAbstractPieceData::streamHeader = 0x05CDD73A; // CRC-32Q string "VAbstractPieceData" const quint32 VAbstractPieceData::streamHeader = 0x05CDD73A; // CRC-32Q string "VAbstractPieceData"
const quint16 VAbstractPieceData::classVersion = 1; const quint16 VAbstractPieceData::classVersion = 2;
const qreal maxL = 2.5; const qreal maxL = 2.5;
@ -1552,6 +1552,18 @@ void VAbstractPiece::SetMy(qreal value)
d->m_my = value; d->m_my = value;
} }
//---------------------------------------------------------------------------------------------------------------------
uint VAbstractPiece::GetPriority() const
{
return d->m_priority;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPiece::SetPriority(uint value)
{
d->m_priority = value;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
qreal VSAPoint::GetSABefore(qreal width) const qreal VSAPoint::GetSABefore(qreal width) const
{ {

View File

@ -211,6 +211,9 @@ public:
qreal GetMy() const; qreal GetMy() const;
void SetMy(qreal value); void SetMy(qreal value);
uint GetPriority() const;
void SetPriority(uint value);
static QVector<QPointF> Equidistant(QVector<VSAPoint> points, qreal width, const QString &name); static QVector<QPointF> Equidistant(QVector<VSAPoint> points, qreal width, const QString &name);
static qreal SumTrapezoids(const QVector<QPointF> &points); static qreal SumTrapezoids(const QVector<QPointF> &points);
static QVector<QPointF> CheckLoops(const QVector<QPointF> &points); static QVector<QPointF> CheckLoops(const QVector<QPointF> &points);

View File

@ -47,15 +47,6 @@ class VAbstractPieceData : public QSharedData
Q_DECLARE_TR_FUNCTIONS(VAbstractPieceData) Q_DECLARE_TR_FUNCTIONS(VAbstractPieceData)
public: public:
VAbstractPieceData() VAbstractPieceData()
: m_name(tr("Detail")),
m_forbidFlipping(false),
m_forceFlipping(false),
m_seamAllowance(false),
m_seamAllowanceBuiltIn(false),
m_hideMainPath(false),
m_width(0),
m_mx(0),
m_my(0)
{} {}
VAbstractPieceData(const VAbstractPieceData &piece) VAbstractPieceData(const VAbstractPieceData &piece)
@ -68,7 +59,8 @@ public:
m_hideMainPath(piece.m_hideMainPath), m_hideMainPath(piece.m_hideMainPath),
m_width(piece.m_width), m_width(piece.m_width),
m_mx(piece.m_mx), m_mx(piece.m_mx),
m_my(piece.m_my) m_my(piece.m_my),
m_priority(piece.m_priority)
{} {}
~VAbstractPieceData() Q_DECL_EQ_DEFAULT; ~VAbstractPieceData() Q_DECL_EQ_DEFAULT;
@ -76,16 +68,17 @@ public:
friend QDataStream& operator<<(QDataStream& dataStream, const VAbstractPieceData& piece); friend QDataStream& operator<<(QDataStream& dataStream, const VAbstractPieceData& piece);
friend QDataStream& operator>>(QDataStream& dataStream, VAbstractPieceData& piece); friend QDataStream& operator>>(QDataStream& dataStream, VAbstractPieceData& piece);
QString m_name; QString m_name{tr("Detail")};
/** @brief forbidFlipping forbid piece be mirrored in a layout. */ /** @brief forbidFlipping forbid piece be mirrored in a layout. */
bool m_forbidFlipping; bool m_forbidFlipping{false};
bool m_forceFlipping; bool m_forceFlipping{false};
bool m_seamAllowance; bool m_seamAllowance{false};
bool m_seamAllowanceBuiltIn; bool m_seamAllowanceBuiltIn{false};
bool m_hideMainPath; bool m_hideMainPath{false};
qreal m_width; qreal m_width{0};
qreal m_mx; qreal m_mx{0};
qreal m_my; qreal m_my{0};
uint m_priority{0};
private: private:
Q_DISABLE_ASSIGN(VAbstractPieceData) Q_DISABLE_ASSIGN(VAbstractPieceData)
@ -114,6 +107,7 @@ inline QDataStream &operator<<(QDataStream &dataStream, const VAbstractPieceData
dataStream << piece.m_my; dataStream << piece.m_my;
// Added in classVersion = 2 // Added in classVersion = 2
dataStream << piece.m_priority;
return dataStream; return dataStream;
} }
@ -154,10 +148,10 @@ inline QDataStream &operator>>(QDataStream &dataStream, VAbstractPieceData &piec
dataStream >> piece.m_mx; dataStream >> piece.m_mx;
dataStream >> piece.m_my; dataStream >> piece.m_my;
// if (actualClassVersion >= 2) if (actualClassVersion >= 2)
// { {
dataStream >> piece.m_priority;
// } }
return dataStream; return dataStream;
} }

View File

@ -33,6 +33,7 @@
#include "../vmisc/diagnostic.h" #include "../vmisc/diagnostic.h"
#include "../vmisc/vabstractapplication.h" #include "../vmisc/vabstractapplication.h"
#include "vlayoutpiece.h" #include "vlayoutpiece.h"
#include "vlayoutdef.h"
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes") QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
@ -52,6 +53,7 @@ QT_WARNING_POP
namespace namespace
{ {
//---------------------------------------------------------------------------------------------------------------------
QVector<VLayoutPiece> PrepareQuantity(const QVector<VLayoutPiece> &details) QVector<VLayoutPiece> PrepareQuantity(const QVector<VLayoutPiece> &details)
{ {
QVector<VLayoutPiece> withQuantity; QVector<VLayoutPiece> withQuantity;
@ -66,6 +68,85 @@ QVector<VLayoutPiece> PrepareQuantity(const QVector<VLayoutPiece> &details)
return withQuantity; return withQuantity;
} }
//---------------------------------------------------------------------------------------------------------------------
void Insert(QMap<uint, QHash<int, qint64>> &container, uint key, int valKey, qint64 valValue)
{
QHash<int, qint64> containerSequence = container.value(key);
containerSequence.insert(valKey, valValue);
container.insert(key, containerSequence);
}
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
int CountDetails(const T &container)
{
int count = 0;
auto i = container.constBegin();
while (i != container.constEnd())
{
count += i.value().count();
++i;
}
return count;
}
//---------------------------------------------------------------------------------------------------------------------
bool NotArrangedDetail(QMap<uint, QHash<int, qint64>> &container, QMap<uint, QHash<int, qint64>> &unsorted, int i)
{
QMutableMapIterator<uint, QHash<int, qint64>> iterator(container);
while (iterator.hasNext())
{
iterator.next();
auto containerGroup = container.value(iterator.key());
if (containerGroup.contains(i))
{
Insert(unsorted, iterator.key(), i, containerGroup.value(i));
containerGroup.remove(i);
if (not containerGroup.isEmpty())
{
container.insert(iterator.key(), containerGroup);
}
else
{
container.remove(iterator.key());
}
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
bool NotArrangedDetail(QMap<uint, QMultiMap<qint64, int>> &container, QMap<uint, QHash<int, qint64>> &unsorted, int i)
{
QMutableMapIterator<uint, QMultiMap<qint64, int>> iterator(container);
while (iterator.hasNext())
{
iterator.next();
auto containerGroup = container.value(iterator.key());
auto detailIterator = std::find(containerGroup.cbegin(), containerGroup.cend(), i);
if (detailIterator != containerGroup.cend())
{
Insert(unsorted, iterator.key(), i, detailIterator.key());
containerGroup.remove(detailIterator.key());
if (not containerGroup.isEmpty())
{
container.insert(iterator.key(), containerGroup);
}
else
{
container.remove(iterator.key());
}
return true;
}
++i;
}
return false;
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -75,6 +156,9 @@ VBank::VBank()
big(), big(),
middle(), middle(),
small(), small(),
desc(),
groups(),
arranged(),
layoutWidth(0), layoutWidth(0),
caseType(Cases::CaseDesc), caseType(Cases::CaseDesc),
prepare(false), prepare(false),
@ -116,14 +200,14 @@ void VBank::SetDetails(const QVector<VLayoutPiece> &details)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VBank::GetNext() int VBank::GetNext()
{ {
if (prepare == false) if (not prepare)
{ {
return -1; return -1;
} }
if (LeftToArrange() == 0) if (LeftToArrange() == 0)
{ {
if (unsorted.isEmpty()) if (CountDetails(unsorted) == 0)
{ {
return -1; return -1;
} }
@ -133,17 +217,41 @@ int VBank::GetNext()
} }
} }
switch (caseType) auto GetNextInGroup = [this](uint group)
{ {
case Cases::CaseThreeGroup: switch (caseType)
return GetNextThreeGroups(); {
case Cases::CaseTwoGroup: case Cases::CaseThreeGroup:
return GetNextTwoGroups(); return GetNextThreeGroups(group);
case Cases::CaseDesc: case Cases::CaseTwoGroup:
return GetNextDescGroup(); return GetNextTwoGroups(group);
default: case Cases::CaseDesc:
return -1; return GetNextDescGroup(group);
default:
return -1;
}
};
for (auto &group: groups)
{
int next = -1;
if (group != 0) // Group 0 must go last
{
next = GetNextInGroup(group);
}
if (next != -1)
{
return next;
}
} }
if (groups.contains(0U))
{
return GetNextInGroup(0);
}
return -1;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -162,51 +270,50 @@ VLayoutPiece VBank::GetDetail(int i) const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::Arranged(int i) void VBank::Arranged(int i)
{ {
if (big.contains(i)) if (ArrangedDetail(big, i))
{ {
big.remove(i);
return; return;
} }
if (middle.contains(i)) if (ArrangedDetail(middle, i))
{ {
middle.remove(i);
return; return;
} }
if (small.contains(i)) if (ArrangedDetail(small, i))
{ {
small.remove(i); return;
} }
ArrangedDetail(desc, i);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::NotArranged(int i) void VBank::NotArranged(int i)
{ {
if (big.contains(i)) if (NotArrangedDetail(big, unsorted, i))
{ {
unsorted.insert(i, big.value(i));
big.remove(i);
return; return;
} }
if (middle.contains(i)) if (NotArrangedDetail(middle, unsorted, i))
{ {
unsorted.insert(i, middle.value(i));
middle.remove(i);
return; return;
} }
if (small.contains(i)) if (NotArrangedDetail(small, unsorted, i))
{ {
unsorted.insert(i, small.value(i)); return;
small.remove(i);
} }
NotArrangedDetail(desc, unsorted, i);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VBank::PrepareUnsorted() bool VBank::PrepareUnsorted()
{ {
QSet<uint> uniqueGroup;
for (int i=0; i < details.size(); ++i) for (int i=0; i < details.size(); ++i)
{ {
const qint64 square = details.at(i).Square(); const qint64 square = details.at(i).Square();
@ -217,9 +324,14 @@ bool VBank::PrepareUnsorted()
prepare = false; prepare = false;
return prepare; return prepare;
} }
unsorted.insert(i, square); const uint group = details.at(i).GetPriority();
uniqueGroup.insert(group);
Insert(unsorted, group, i, square);
} }
groups = QVector<uint>::fromList(uniqueGroup.toList());
std::sort(groups.begin(), groups.end());
PrepareGroup(); PrepareGroup();
prepare = true; prepare = true;
@ -281,6 +393,9 @@ void VBank::Reset()
big.clear(); big.clear();
middle.clear(); middle.clear();
small.clear(); small.clear();
desc.clear();
groups.clear();
arranged.clear();
diagonal = 0; diagonal = 0;
} }
@ -293,13 +408,13 @@ void VBank::SetCaseType(Cases caseType)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VBank::AllDetailsCount() const int VBank::AllDetailsCount() const
{ {
return unsorted.count() + big.count() + middle.count() + small.count(); return CountDetails(unsorted) + CountDetails(big) + CountDetails(middle) + CountDetails(small) + CountDetails(desc);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VBank::LeftToArrange() const int VBank::LeftToArrange() const
{ {
return big.count() + middle.count() + small.count(); return CountDetails(big) + CountDetails(middle) + CountDetails(small) + CountDetails(desc);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -317,156 +432,159 @@ int VBank::ArrangedCount() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::PrepareGroup() void VBank::PrepareGroup()
{ {
switch (caseType) QMutableMapIterator<uint, QHash<int, qint64>> i(unsorted);
while (i.hasNext())
{ {
case Cases::CaseThreeGroup: i.next();
PrepareThreeGroups(); switch (caseType)
break; {
case Cases::CaseTwoGroup: case Cases::CaseThreeGroup:
PrepareTwoGroups(); PrepareThreeGroups(i.key());
break; break;
case Cases::CaseDesc: case Cases::CaseTwoGroup:
PrepareDescGroup(); PrepareTwoGroups(i.key());
break; break;
default: case Cases::CaseDesc:
break; PrepareDescGroup(i.key());
break;
default:
break;
}
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::PrepareThreeGroups() void VBank::PrepareThreeGroups(uint priority)
{ {
qint64 sMax = LLONG_MIN; qint64 sMax = LLONG_MIN;
qint64 sMin = LLONG_MAX; qint64 sMin = LLONG_MAX;
SqMaxMin(sMax, sMin); SqMaxMin(sMax, sMin, priority);
const qint64 s1 = sMax - (sMax - sMin)/3; const qint64 s1 = sMax - (sMax - sMin)/3;
const qint64 s2 = sMin + (sMax - sMin)/3; const qint64 s2 = sMin + (sMax - sMin)/3;
QHash<int, qint64>::const_iterator i = unsorted.constBegin(); const QHash<int, qint64> usortedGroup = unsorted.value(priority);
while (i != unsorted.constEnd()) QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
while (i != usortedGroup.constEnd())
{ {
if (i.value() > s1) if (i.value() > s1)
{ {
big.insert(i.key(), i.value()); Insert(big, priority, i.key(), i.value());
} }
else if (s1 >= i.value() && i.value() > s2) else if (s1 >= i.value() && i.value() > s2)
{ {
middle.insert(i.key(), i.value()); Insert(middle, priority, i.key(), i.value());
} }
else else
{ {
small.insert(i.key(), i.value()); Insert(small, priority, i.key(), i.value());
} }
++i; ++i;
} }
unsorted.clear(); unsorted.remove(priority);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::PrepareTwoGroups() void VBank::PrepareTwoGroups(uint priority)
{ {
qint64 sMax = LLONG_MIN; qint64 sMax = LLONG_MIN;
qint64 sMin = LLONG_MAX; qint64 sMin = LLONG_MAX;
SqMaxMin(sMax, sMin); SqMaxMin(sMax, sMin, priority);
const qint64 s = (sMax + sMin)/2; const qint64 s = (sMax + sMin)/2;
QHash<int, qint64>::const_iterator i = unsorted.constBegin(); const QHash<int, qint64> usortedGroup = unsorted.value(priority);
while (i != unsorted.constEnd()) QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
while (i != usortedGroup.constEnd())
{ {
if (i.value() >= s) if (i.value() >= s)
{ {
big.insert(i.key(), i.value()); Insert(big, priority, i.key(), i.value());
} }
else else
{ {
small.insert(i.key(), i.value()); Insert(small, priority, i.key(), i.value());
} }
++i; ++i;
} }
unsorted.clear(); unsorted.remove(priority);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::PrepareDescGroup() void VBank::PrepareDescGroup(uint priority)
{ {
big = unsorted; QMultiMap<qint64, int> descGroup;
unsorted.clear(); const QHash<int, qint64> usortedGroup = unsorted.value(priority);
QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
while (i != usortedGroup.constEnd())
{
descGroup.insert(i.value(), i.key());
++i;
}
desc.insert(priority, descGroup);
unsorted.remove(priority);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VBank::GetNextThreeGroups() const int VBank::GetNextThreeGroups(uint priority) const
{ {
if (big.isEmpty() == false) int next = -1;
next = TakeFirstForPriority(big, priority);
if (next != -1)
{ {
QHash<int, qint64>::const_iterator i = big.constBegin(); return next;
return i.key();
} }
if (middle.isEmpty() == false) next = TakeFirstForPriority(middle, priority);
if (next != -1)
{ {
QHash<int, qint64>::const_iterator i = middle.constBegin(); return next;
return i.key();
} }
if (small.isEmpty() == false) next = TakeFirstForPriority(small, priority);
return next;
}
//---------------------------------------------------------------------------------------------------------------------
int VBank::GetNextTwoGroups(uint priority) const
{
int next = -1;
next = TakeFirstForPriority(big, priority);
if (next != -1)
{ {
QHash<int, qint64>::const_iterator i = small.constBegin(); return next;
return i.key(); }
next = TakeFirstForPriority(small, priority);
return next;
}
//---------------------------------------------------------------------------------------------------------------------
int VBank::GetNextDescGroup(uint priority) const
{
auto descGroup = desc.value(priority);
QMapIterator<qint64, int> i(descGroup);
i.toBack();
if (i.hasPrevious())
{
return i.previous().value();
} }
return -1; return -1;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VBank::GetNextTwoGroups() const void VBank::SqMaxMin(qint64 &sMax, qint64 &sMin, uint priority) const
{
if (big.isEmpty() == false)
{
QHash<int, qint64>::const_iterator i = big.constBegin();
return i.key();
}
if (small.isEmpty() == false)
{
QHash<int, qint64>::const_iterator i = small.constBegin();
return i.key();
}
return -1;
}
//---------------------------------------------------------------------------------------------------------------------
int VBank::GetNextDescGroup() const
{
int index = -1;
qint64 sMax = LLONG_MIN;
QHash<int, qint64>::const_iterator i = big.constBegin();
while (i != big.constEnd())
{
if (i.value() > sMax)
{
sMax = i.value();
index = i.key();
}
++i;
}
return index;
}
//---------------------------------------------------------------------------------------------------------------------
void VBank::SqMaxMin(qint64 &sMax, qint64 &sMin) const
{ {
sMax = LLONG_MIN; sMax = LLONG_MIN;
sMin = LLONG_MAX; sMin = LLONG_MAX;
QHash<int, qint64>::const_iterator i = unsorted.constBegin(); const QHash<int, qint64> usortedGroup = unsorted.value(priority);
while (i != unsorted.constEnd()) QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
while (i != usortedGroup.constEnd())
{ {
if (i.value() < sMin) if (i.value() < sMin)
{ {
@ -479,7 +597,72 @@ void VBank::SqMaxMin(qint64 &sMax, qint64 &sMin) const
} }
++i; ++i;
} }
}
//---------------------------------------------------------------------------------------------------------------------
int VBank::TakeFirstForPriority(const QMap<uint, QHash<int, qint64>> &container, uint priority) const
{
const QHash<int, qint64> priorityGroup = container.value(priority);
if (not priorityGroup.isEmpty())
{
return priorityGroup.constBegin().key();
}
return -1;
}
//---------------------------------------------------------------------------------------------------------------------
bool VBank::ArrangedDetail(QMap<uint, QHash<int, qint64>> &container, int i)
{
QMutableMapIterator<uint, QHash<int, qint64>> iterator(container);
while (iterator.hasNext())
{
iterator.next();
auto containerGroup = container.value(iterator.key());
if (containerGroup.contains(i))
{
arranged.append(details.at(i).GetId());
containerGroup.remove(i);
if (not containerGroup.isEmpty())
{
container.insert(iterator.key(), containerGroup);
}
else
{
container.remove(iterator.key());
}
return true;
}
}
return false;
}
//---------------------------------------------------------------------------------------------------------------------
bool VBank::ArrangedDetail(QMap<uint, QMultiMap<qint64, int>> &container, int i)
{
QMutableMapIterator<uint, QMultiMap<qint64, int>> iterator(container);
while (iterator.hasNext())
{
iterator.next();
auto containerGroup = container.value(iterator.key());
auto detailIterator = std::find(containerGroup.cbegin(), containerGroup.cend(), i);
if (detailIterator != containerGroup.cend())
{
arranged.append(details.at(detailIterator.value()).GetId());
containerGroup.remove(detailIterator.key(), detailIterator.value());
if (not containerGroup.isEmpty())
{
container.insert(iterator.key(), containerGroup);
}
else
{
container.remove(iterator.key());
}
return true;
}
}
return false;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -511,6 +694,7 @@ bool VBank::IsRotationNeeded() const
return false; return false;
} }
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC) #if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
#pragma pop_macro("small") #pragma pop_macro("small")
#endif #endif

View File

@ -30,10 +30,13 @@
#define VBANK_H #define VBANK_H
#include <QHash> #include <QHash>
#include <QMap>
#include <QRectF> #include <QRectF>
#include <QVector> #include <QVector>
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/typedef.h"
// An annoying char define, from the Windows team in <rpcndr.h> // An annoying char define, from the Windows team in <rpcndr.h>
// #define small char // #define small char
// http://stuartjames.info/Journal/c--visual-studio-2012-vs2012--win8--converting-projects-up-some-conflicts-i-found.aspx // http://stuartjames.info/Journal/c--visual-studio-2012-vs2012--win8--converting-projects-up-some-conflicts-i-found.aspx
@ -81,11 +84,15 @@ public:
private: private:
Q_DISABLE_COPY(VBank) Q_DISABLE_COPY(VBank)
QVector<VLayoutPiece> details; QVector<VLayoutPiece> details;
QHash<int, qint64> unsorted;
QHash<int, qint64> big; QMap<uint, QHash<int, qint64>> unsorted;
QHash<int, qint64> middle; QMap<uint, QHash<int, qint64>> big;
QHash<int, qint64> small; QMap<uint, QHash<int, qint64>> middle;
QMap<uint, QHash<int, qint64>> small;
QMap<uint, QMultiMap<qint64, int>> desc;
QVector<uint> groups;
QVector<vidtype> arranged;
qreal layoutWidth; qreal layoutWidth;
@ -96,15 +103,19 @@ private:
void PrepareGroup(); void PrepareGroup();
void PrepareThreeGroups(); void PrepareThreeGroups(uint priority);
void PrepareTwoGroups(); void PrepareTwoGroups(uint priority);
void PrepareDescGroup(); void PrepareDescGroup(uint priority);
int GetNextThreeGroups() const; int GetNextThreeGroups(uint priority) const;
int GetNextTwoGroups() const; int GetNextTwoGroups(uint priority) const;
int GetNextDescGroup() const; int GetNextDescGroup(uint priority) const;
void SqMaxMin(qint64 &sMax, qint64 &sMin) const; void SqMaxMin(qint64 &sMax, qint64 &sMin, uint priority) const;
int TakeFirstForPriority(const QMap<uint, QHash<int, qint64>> &container, uint priority) const;
bool ArrangedDetail(QMap<uint, QHash<int, qint64>> &container, int i);
bool ArrangedDetail(QMap<uint, QMultiMap<qint64, int>> &container, int i);
}; };
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC) #if defined (Q_OS_WIN) && defined (Q_CC_MSVC)

View File

@ -403,7 +403,7 @@ VLayoutPiece::~VLayoutPiece()
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern) VLayoutPiece VLayoutPiece::Create(const VPiece &piece, vidtype id, const VContainer *pattern)
{ {
QFuture<QVector<QPointF> > futureSeamAllowance = QtConcurrent::run(piece, &VPiece::SeamAllowancePoints, pattern); QFuture<QVector<QPointF> > futureSeamAllowance = QtConcurrent::run(piece, &VPiece::SeamAllowancePoints, pattern);
QFuture<bool> futureSeamAllowanceValid = QtConcurrent::run(piece, &VPiece::IsSeamAllowanceValid, pattern); QFuture<bool> futureSeamAllowanceValid = QtConcurrent::run(piece, &VPiece::IsSeamAllowanceValid, pattern);
@ -422,6 +422,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern
det.SetSAWidth(qApp->toPixel(piece.GetSAWidth())); det.SetSAWidth(qApp->toPixel(piece.GetSAWidth()));
det.SetForbidFlipping(piece.IsForbidFlipping()); det.SetForbidFlipping(piece.IsForbidFlipping());
det.SetForceFlipping(piece.IsForceFlipping()); det.SetForceFlipping(piece.IsForceFlipping());
det.SetId(id);
if (not futureSeamAllowanceValid.result()) if (not futureSeamAllowanceValid.result())
{ {
@ -435,6 +436,7 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern
det.SetInternalPaths(futureInternalPaths.result()); det.SetInternalPaths(futureInternalPaths.result());
det.SetPassmarks(futurePassmarks.result()); det.SetPassmarks(futurePassmarks.result());
det.SetPlaceLabels(futurePlaceLabels.result()); det.SetPlaceLabels(futurePlaceLabels.result());
det.SetPriority(piece.GetPriority());
// Very important to set main path first! // Very important to set main path first!
if (det.ContourPath().isEmpty()) if (det.ContourPath().isEmpty())
@ -770,6 +772,18 @@ void VLayoutPiece::SetQuantity(quint16 value)
d->m_quantity = qMax(static_cast<quint16>(1), value); d->m_quantity = qMax(static_cast<quint16>(1), value);
} }
//---------------------------------------------------------------------------------------------------------------------
vidtype VLayoutPiece::GetId() const
{
return d->m_id;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::SetId(vidtype id)
{
d->m_id = id;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VLayoutPiece::Translate(qreal dx, qreal dy) void VLayoutPiece::Translate(qreal dx, qreal dy)
{ {

View File

@ -71,7 +71,7 @@ public:
inline void Swap(VLayoutPiece &detail) Q_DECL_NOTHROW inline void Swap(VLayoutPiece &detail) Q_DECL_NOTHROW
{ VAbstractPiece::Swap(detail); std::swap(d, detail.d); } { VAbstractPiece::Swap(detail); std::swap(d, detail.d); }
static VLayoutPiece Create(const VPiece &piece, const VContainer *pattern); static VLayoutPiece Create(const VPiece &piece, vidtype id, const VContainer *pattern);
QVector<QPointF> GetMappedContourPoints() const; QVector<QPointF> GetMappedContourPoints() const;
QVector<QPointF> GetContourPoints() const; QVector<QPointF> GetContourPoints() const;
@ -119,6 +119,9 @@ public:
quint16 GetQuantity() const; quint16 GetQuantity() const;
void SetQuantity(quint16 value); void SetQuantity(quint16 value);
vidtype GetId() const;
void SetId(vidtype id);
bool IsMirror() const; bool IsMirror() const;
void SetMirror(bool value); void SetMirror(bool value);

View File

@ -74,7 +74,8 @@ public:
m_tmPattern(detail.m_tmPattern), m_tmPattern(detail.m_tmPattern),
m_placeLabels(detail.m_placeLabels), m_placeLabels(detail.m_placeLabels),
m_square(detail.m_square), m_square(detail.m_square),
m_quantity(detail.m_quantity) m_quantity(detail.m_quantity),
m_id(detail.m_id)
{} {}
~VLayoutPieceData() Q_DECL_EQ_DEFAULT; ~VLayoutPieceData() Q_DECL_EQ_DEFAULT;
@ -131,6 +132,9 @@ public:
quint16 m_quantity{1}; quint16 m_quantity{1};
/** @brief m_id keep id of original piece. */
vidtype m_id;
private: private:
Q_DISABLE_ASSIGN(VLayoutPieceData) Q_DISABLE_ASSIGN(VLayoutPieceData)
@ -164,6 +168,7 @@ inline QDataStream &operator<<(QDataStream &dataStream, const VLayoutPieceData &
// Added in classVersion = 2 // Added in classVersion = 2
dataStream << piece.m_quantity; dataStream << piece.m_quantity;
dataStream << piece.m_id;
return dataStream; return dataStream;
} }
@ -214,6 +219,7 @@ inline QDataStream &operator>>(QDataStream &dataStream, VLayoutPieceData &piece)
if (actualClassVersion >= 2) if (actualClassVersion >= 2)
{ {
dataStream >> piece.m_quantity; dataStream >> piece.m_quantity;
dataStream >> piece.m_id;
} }
return dataStream; return dataStream;

View File

@ -318,6 +318,7 @@ void DialogSeamAllowance::SetPiece(const VPiece &piece)
uiTabPaths->checkBoxSeams->setChecked(piece.IsSeamAllowance()); uiTabPaths->checkBoxSeams->setChecked(piece.IsSeamAllowance());
uiTabPaths->checkBoxBuiltIn->setChecked(piece.IsSeamAllowanceBuiltIn()); uiTabPaths->checkBoxBuiltIn->setChecked(piece.IsSeamAllowanceBuiltIn());
uiTabPaths->lineEditName->setText(piece.GetName()); uiTabPaths->lineEditName->setText(piece.GetName());
uiTabPaths->spinBoxPriority->setValue(static_cast<int>(piece.GetPriority()));
uiTabPaths->plainTextEditFormulaWidth->setPlainText( uiTabPaths->plainTextEditFormulaWidth->setPlainText(
qApp->TrVars()->FormulaToUser(piece.GetFormulaSAWidth(), qApp->Settings()->GetOsSeparator())); qApp->TrVars()->FormulaToUser(piece.GetFormulaSAWidth(), qApp->Settings()->GetOsSeparator()));
@ -2453,6 +2454,7 @@ VPiece DialogSeamAllowance::CreatePiece() const
piece.SetSeamAllowanceBuiltIn(uiTabPaths->checkBoxBuiltIn->isChecked()); piece.SetSeamAllowanceBuiltIn(uiTabPaths->checkBoxBuiltIn->isChecked());
piece.SetHideMainPath(uiTabPaths->checkBoxHideMainPath->isChecked()); piece.SetHideMainPath(uiTabPaths->checkBoxHideMainPath->isChecked());
piece.SetName(uiTabPaths->lineEditName->text()); piece.SetName(uiTabPaths->lineEditName->text());
piece.SetPriority(static_cast<uint>(uiTabPaths->spinBoxPriority->value()));
piece.SetFormulaSAWidth(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidth), m_saWidth); piece.SetFormulaSAWidth(GetFormulaFromUser(uiTabPaths->plainTextEditFormulaWidth), m_saWidth);
piece.GetPatternPieceData().SetLetter(uiTabLabels->lineEditLetter->text()); piece.GetPatternPieceData().SetLetter(uiTabLabels->lineEditLetter->text());
piece.GetPatternPieceData().SetAnnotation(uiTabLabels->lineEditAnnotation->text()); piece.GetPatternPieceData().SetAnnotation(uiTabLabels->lineEditAnnotation->text());

View File

@ -74,15 +74,18 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QFormLayout" name="formLayout">
<item> <property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="labelEditName"> <widget class="QLabel" name="labelEditName">
<property name="text"> <property name="text">
<string>Name of detail:</string> <string>Name of detail:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="VLineEdit" name="lineEditName"> <widget class="VLineEdit" name="lineEditName">
<property name="text"> <property name="text">
<string>Detail</string> <string>Detail</string>
@ -92,6 +95,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Priority:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxPriority">
<property name="toolTip">
<string>Controls priority in layout. 0 - no priority.</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@ -83,6 +83,7 @@ const QString VToolSeamAllowance::AttrBottomRightPin = QStringLiteral("bot
const QString VToolSeamAllowance::AttrCenterPin = QStringLiteral("centerPin"); const QString VToolSeamAllowance::AttrCenterPin = QStringLiteral("centerPin");
const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin"); const QString VToolSeamAllowance::AttrTopPin = QStringLiteral("topPin");
const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin"); const QString VToolSeamAllowance::AttrBottomPin = QStringLiteral("bottomPin");
const QString VToolSeamAllowance::AttrPiecePriority = QStringLiteral("priority");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VToolSeamAllowance *VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene, VToolSeamAllowance *VToolSeamAllowance::Create(const QPointer<DialogTool> &dialog, VMainGraphicsScene *scene,
@ -281,6 +282,7 @@ void VToolSeamAllowance::AddAttributes(VAbstractPattern *doc, QDomElement &domEl
not piece.IsSeamAllowanceBuiltIn()); not piece.IsSeamAllowanceBuiltIn());
doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth()); doc->SetAttribute(domElement, AttrWidth, piece.GetFormulaSAWidth());
doc->SetAttributeOrRemoveIf(domElement, AttrUnited, piece.IsUnited(), not piece.IsUnited()); doc->SetAttributeOrRemoveIf(domElement, AttrUnited, piece.IsUnited(), not piece.IsUnited());
doc->SetAttributeOrRemoveIf(domElement, AttrPiecePriority, piece.GetPriority(), piece.GetPriority() == 0);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -87,6 +87,7 @@ public:
static const QString AttrCenterPin; static const QString AttrCenterPin;
static const QString AttrTopPin; static const QString AttrTopPin;
static const QString AttrBottomPin; static const QString AttrBottomPin;
static const QString AttrPiecePriority;
void RemoveWithConfirm(bool ask); void RemoveWithConfirm(bool ask);