2015-01-11 14:11:56 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vbank.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 11 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
2017-10-05 11:20:01 +02:00
|
|
|
** This source code is part of the Valentina project, a pattern making
|
2015-01-11 14:11:56 +01:00
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2020-01-31 07:00:05 +01:00
|
|
|
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
|
2015-01-11 14:11:56 +01:00
|
|
|
**
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vbank.h"
|
|
|
|
|
|
|
|
#include <climits>
|
2020-02-21 09:47:13 +01:00
|
|
|
#include <QLoggingCategory>
|
2016-08-08 13:44:49 +02:00
|
|
|
|
2020-10-15 17:05:21 +02:00
|
|
|
#include "../vmisc/vabstractvalapplication.h"
|
2020-01-16 18:46:05 +01:00
|
|
|
#include "../vmisc/compatibility.h"
|
2019-07-19 09:45:57 +02:00
|
|
|
#include "vlayoutdef.h"
|
2019-07-22 16:06:30 +02:00
|
|
|
#include "../ifc/exception/vexception.h"
|
2015-01-11 14:11:56 +01:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
|
|
|
|
QT_WARNING_DISABLE_INTEL(1418)
|
2016-07-26 12:33:58 +02:00
|
|
|
|
2022-08-12 17:50:13 +02:00
|
|
|
Q_LOGGING_CATEGORY(lBank, "layout.bank") // NOLINT
|
2016-07-26 12:33:58 +02:00
|
|
|
|
2016-08-06 20:42:40 +02:00
|
|
|
QT_WARNING_POP
|
2016-07-26 12:33:58 +02:00
|
|
|
|
2016-08-05 15:44:20 +02:00
|
|
|
// An annoying char define, from the Windows team in <rpcndr.h>
|
|
|
|
// #define small char
|
|
|
|
// http://stuartjames.info/Journal/c--visual-studio-2012-vs2012--win8--converting-projects-up-some-conflicts-i-found.aspx
|
|
|
|
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
|
|
|
|
#pragma push_macro("small")
|
|
|
|
#undef small
|
|
|
|
#endif
|
|
|
|
|
2019-07-04 13:33:45 +02:00
|
|
|
namespace
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-04 13:33:45 +02:00
|
|
|
QVector<VLayoutPiece> PrepareQuantity(const QVector<VLayoutPiece> &details)
|
|
|
|
{
|
|
|
|
QVector<VLayoutPiece> withQuantity;
|
|
|
|
withQuantity.reserve(details.size());
|
|
|
|
for(auto &piece : details)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < piece.GetQuantity(); ++i)
|
|
|
|
{
|
|
|
|
withQuantity.append(piece);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return withQuantity;
|
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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>
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype CountDetails(const T &container)
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype count = 0;
|
2019-07-19 09:45:57 +02:00
|
|
|
auto i = container.constBegin();
|
|
|
|
while (i != container.constEnd())
|
|
|
|
{
|
|
|
|
count += i.value().count();
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-27 08:02:41 +02:00
|
|
|
bool NotArrangedDetail(QMap<uint, QHash<int, qint64>> &container, QMap<uint, QHash<int, qint64>> &unsorted,
|
|
|
|
int i)
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-27 08:02:41 +02:00
|
|
|
bool NotArrangedDetail(QMap<uint, QMultiMap<qint64, int>> &container, QMap<uint, QHash<int, qint64>> &unsorted,
|
|
|
|
int i)
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
|
|
|
QMutableMapIterator<uint, QMultiMap<qint64, int>> iterator(container);
|
|
|
|
while (iterator.hasNext())
|
|
|
|
{
|
|
|
|
iterator.next();
|
|
|
|
auto containerGroup = container.value(iterator.key());
|
2019-07-27 08:02:41 +02:00
|
|
|
auto detailIterator = std::find(containerGroup.begin(), containerGroup.end(), i);
|
|
|
|
if (detailIterator != containerGroup.end())
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
|
|
|
Insert(unsorted, iterator.key(), i, detailIterator.key());
|
2019-07-27 08:02:41 +02:00
|
|
|
containerGroup.erase(detailIterator);
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
if (not containerGroup.isEmpty())
|
|
|
|
{
|
|
|
|
container.insert(iterator.key(), containerGroup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
container.remove(iterator.key());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-21 16:22:50 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int TakeFirstForPriority(const QMap<uint, QHash<int, qint64>> &container, uint priority)
|
|
|
|
{
|
|
|
|
const QHash<int, qint64> priorityGroup = container.value(priority);
|
|
|
|
if (not priorityGroup.isEmpty())
|
|
|
|
{
|
|
|
|
return priorityGroup.constBegin().key();
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2019-07-04 13:33:45 +02:00
|
|
|
}
|
|
|
|
|
2015-01-11 14:11:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VBank::VBank()
|
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
qreal VBank::GetLayoutWidth() const
|
|
|
|
{
|
|
|
|
return layoutWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-26 16:47:27 +01:00
|
|
|
void VBank::SetLayoutWidth(qreal value)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
layoutWidth = value;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2019-07-21 15:26:21 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBank::GetManualPriority() const
|
|
|
|
{
|
|
|
|
return m_manualPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::SetManualPriority(bool value)
|
|
|
|
{
|
|
|
|
m_manualPriority = value;
|
|
|
|
}
|
|
|
|
|
2019-07-04 13:33:45 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBank::IsNestQuantity() const
|
|
|
|
{
|
|
|
|
return m_nestQuantity;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::SetNestQuantity(bool value)
|
|
|
|
{
|
|
|
|
m_nestQuantity = value;
|
|
|
|
}
|
|
|
|
|
2015-01-11 14:11:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
void VBank::SetDetails(const QVector<VLayoutPiece> &details)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
this->details = details;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-26 16:47:27 +01:00
|
|
|
int VBank::GetNext()
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
if (not prepare)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-03-26 16:47:27 +01:00
|
|
|
if (LeftToArrange() == 0)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
if (CountDetails(unsorted) == 0)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrepareGroup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
auto GetNextInGroup = [this](uint group)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
switch (caseType)
|
|
|
|
{
|
|
|
|
case Cases::CaseThreeGroup:
|
|
|
|
return GetNextThreeGroups(group);
|
|
|
|
case Cases::CaseTwoGroup:
|
|
|
|
return GetNextTwoGroups(group);
|
|
|
|
case Cases::CaseDesc:
|
|
|
|
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);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
return -1;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2017-01-22 10:02:02 +01:00
|
|
|
VLayoutPiece VBank::GetDetail(int i) const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (i >= 0 && i < details.size())
|
|
|
|
{
|
|
|
|
return details.at(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-22 10:02:02 +01:00
|
|
|
return VLayoutPiece();
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::Arranged(int i)
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
if (ArrangedDetail(big, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
if (ArrangedDetail(middle, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
if (ArrangedDetail(small, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
ArrangedDetail(desc, i);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::NotArranged(int i)
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
if (NotArrangedDetail(big, unsorted, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
if (NotArrangedDetail(middle, unsorted, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
if (NotArrangedDetail(small, unsorted, i))
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
NotArrangedDetail(desc, unsorted, i);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-03-30 10:17:54 +01:00
|
|
|
bool VBank::PrepareUnsorted()
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
QSet<uint> uniqueGroup;
|
|
|
|
|
2019-03-30 10:17:54 +01:00
|
|
|
for (int i=0; i < details.size(); ++i)
|
|
|
|
{
|
|
|
|
const qint64 square = details.at(i).Square();
|
|
|
|
if (square <= 0)
|
|
|
|
{
|
2020-11-20 12:18:38 +01:00
|
|
|
qCCritical(lBank) << VAbstractValApplication::warningMessageSignature +
|
2022-03-28 16:40:44 +02:00
|
|
|
tr("Error of preparing data for layout: Detail '%1' square <= 0")
|
2020-02-20 18:35:49 +01:00
|
|
|
.arg(details.at(i).GetName());
|
2019-03-30 10:17:54 +01:00
|
|
|
prepare = false;
|
|
|
|
return prepare;
|
|
|
|
}
|
2019-07-21 15:26:21 +02:00
|
|
|
const uint group = m_manualPriority ? details.at(i).GetPriority() : 0;
|
2019-07-19 09:45:57 +02:00
|
|
|
uniqueGroup.insert(group);
|
|
|
|
Insert(unsorted, group, i, square);
|
2019-03-30 10:17:54 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 18:46:05 +01:00
|
|
|
groups = ConvertToVector(uniqueGroup);
|
2019-07-19 09:45:57 +02:00
|
|
|
std::sort(groups.begin(), groups.end());
|
|
|
|
|
2019-03-30 10:17:54 +01:00
|
|
|
PrepareGroup();
|
|
|
|
|
|
|
|
prepare = true;
|
|
|
|
return prepare;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBank::PrepareDetails()
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (layoutWidth <= 0)
|
|
|
|
{
|
2020-11-20 12:18:38 +01:00
|
|
|
qCCritical(lBank) << VAbstractValApplication::warningMessageSignature +
|
2022-03-28 16:40:44 +02:00
|
|
|
tr("Error of preparing data for layout: Layout paper sheet <= 0");
|
2015-01-11 14:11:56 +01:00
|
|
|
prepare = false;
|
|
|
|
return prepare;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (details.isEmpty())
|
|
|
|
{
|
2020-11-20 12:18:38 +01:00
|
|
|
qCCritical(lBank) << VAbstractValApplication::warningMessageSignature +
|
2022-03-28 16:40:44 +02:00
|
|
|
tr("Error of preparing data for layout: List of details is empty");
|
2015-01-11 14:11:56 +01:00
|
|
|
prepare = false;
|
|
|
|
return prepare;
|
|
|
|
}
|
|
|
|
|
2019-07-04 13:33:45 +02:00
|
|
|
if (m_nestQuantity)
|
|
|
|
{
|
|
|
|
details = PrepareQuantity(details);
|
|
|
|
}
|
|
|
|
|
2016-02-23 13:13:10 +01:00
|
|
|
diagonal = 0;
|
2019-03-30 10:17:54 +01:00
|
|
|
|
2015-01-11 14:11:56 +01:00
|
|
|
for (int i=0; i < details.size(); ++i)
|
|
|
|
{
|
|
|
|
details[i].SetLayoutWidth(layoutWidth);
|
2017-01-25 12:29:03 +01:00
|
|
|
details[i].SetLayoutAllowancePoints();
|
2019-03-30 10:17:54 +01:00
|
|
|
|
2019-02-23 17:43:06 +01:00
|
|
|
if (not details.at(i).IsLayoutAllowanceValid())
|
2017-12-12 09:23:46 +01:00
|
|
|
{
|
2019-02-23 17:43:06 +01:00
|
|
|
const QString errorMsg = QObject::tr("Piece '%1' has invalid layout allowance. Please, check seam allowance"
|
|
|
|
" to check how seam allowance behave.").arg(details.at(i).GetName());
|
2021-02-06 14:52:21 +01:00
|
|
|
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
|
|
|
|
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
|
2017-12-12 09:23:46 +01:00
|
|
|
}
|
2016-02-23 13:13:10 +01:00
|
|
|
|
|
|
|
const qreal d = details.at(i).Diagonal();
|
|
|
|
if (d > diagonal)
|
|
|
|
{
|
|
|
|
diagonal = d;
|
|
|
|
}
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
prepare = true;
|
|
|
|
return prepare;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::Reset()
|
|
|
|
{
|
|
|
|
prepare = false;
|
|
|
|
unsorted.clear();
|
|
|
|
big.clear();
|
|
|
|
middle.clear();
|
|
|
|
small.clear();
|
2019-07-19 09:45:57 +02:00
|
|
|
desc.clear();
|
|
|
|
groups.clear();
|
|
|
|
arranged.clear();
|
2016-02-23 13:13:10 +01:00
|
|
|
diagonal = 0;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::SetCaseType(Cases caseType)
|
|
|
|
{
|
|
|
|
this->caseType = caseType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype VBank::AllDetailsCount() const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return CountDetails(unsorted) + CountDetails(big) + CountDetails(middle) + CountDetails(small) + CountDetails(desc);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype VBank::LeftToArrange() const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return CountDetails(big) + CountDetails(middle) + CountDetails(small) + CountDetails(desc);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2023-02-09 16:23:11 +01:00
|
|
|
vsizetype VBank::FailedToArrange() const
|
2015-01-12 13:12:15 +01:00
|
|
|
{
|
2020-11-26 18:12:59 +01:00
|
|
|
return CountDetails(unsorted);
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-16 13:53:14 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2020-11-26 18:12:59 +01:00
|
|
|
qreal VBank::GetBiggestDiagonal() const
|
2015-01-16 13:53:14 +01:00
|
|
|
{
|
2020-11-26 18:12:59 +01:00
|
|
|
return diagonal;
|
2015-01-16 13:53:14 +01:00
|
|
|
}
|
|
|
|
|
2015-01-11 14:11:56 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VBank::PrepareGroup()
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
QMutableMapIterator<uint, QHash<int, qint64>> i(unsorted);
|
|
|
|
while (i.hasNext())
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
i.next();
|
|
|
|
switch (caseType)
|
|
|
|
{
|
|
|
|
case Cases::CaseThreeGroup:
|
|
|
|
PrepareThreeGroups(i.key());
|
|
|
|
break;
|
|
|
|
case Cases::CaseTwoGroup:
|
|
|
|
PrepareTwoGroups(i.key());
|
|
|
|
break;
|
|
|
|
case Cases::CaseDesc:
|
|
|
|
PrepareDescGroup(i.key());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
void VBank::PrepareThreeGroups(uint priority)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
qint64 sMax = LLONG_MIN;
|
|
|
|
qint64 sMin = LLONG_MAX;
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
SqMaxMin(sMax, sMin, priority);
|
2015-01-11 14:11:56 +01:00
|
|
|
|
|
|
|
const qint64 s1 = sMax - (sMax - sMin)/3;
|
|
|
|
const qint64 s2 = sMin + (sMax - sMin)/3;
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
const QHash<int, qint64> usortedGroup = unsorted.value(priority);
|
|
|
|
QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
|
|
|
|
while (i != usortedGroup.constEnd())
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (i.value() > s1)
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
Insert(big, priority, i.key(), i.value());
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
2015-01-12 13:12:15 +01:00
|
|
|
else if (s1 >= i.value() && i.value() > s2)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
Insert(middle, priority, i.key(), i.value());
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
Insert(small, priority, i.key(), i.value());
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
unsorted.remove(priority);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
void VBank::PrepareTwoGroups(uint priority)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
qint64 sMax = LLONG_MIN;
|
|
|
|
qint64 sMin = LLONG_MAX;
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
SqMaxMin(sMax, sMin, priority);
|
2015-01-11 14:11:56 +01:00
|
|
|
|
|
|
|
const qint64 s = (sMax + sMin)/2;
|
2019-07-19 09:45:57 +02:00
|
|
|
const QHash<int, qint64> usortedGroup = unsorted.value(priority);
|
|
|
|
QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
|
|
|
|
while (i != usortedGroup.constEnd())
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (i.value() >= s)
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
Insert(big, priority, i.key(), i.value());
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
Insert(small, priority, i.key(), i.value());
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
unsorted.remove(priority);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
void VBank::PrepareDescGroup(uint priority)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
QMultiMap<qint64, int> descGroup;
|
|
|
|
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);
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
int VBank::GetNextThreeGroups(uint priority) const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-21 16:22:50 +02:00
|
|
|
int next = TakeFirstForPriority(big, priority);
|
2019-07-19 09:45:57 +02:00
|
|
|
if (next != -1)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return next;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
next = TakeFirstForPriority(middle, priority);
|
|
|
|
if (next != -1)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return next;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
next = TakeFirstForPriority(small, priority);
|
|
|
|
return next;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
int VBank::GetNextTwoGroups(uint priority) const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-21 16:22:50 +02:00
|
|
|
int next = TakeFirstForPriority(big, priority);
|
2019-07-19 09:45:57 +02:00
|
|
|
if (next != -1)
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return next;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
next = TakeFirstForPriority(small, priority);
|
|
|
|
return next;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
int VBank::GetNextDescGroup(uint priority) const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
auto descGroup = desc.value(priority);
|
2023-02-09 15:50:56 +01:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
QMultiMapIterator<qint64, int> i(descGroup);
|
|
|
|
#else
|
2019-07-19 09:45:57 +02:00
|
|
|
QMapIterator<qint64, int> i(descGroup);
|
2023-02-09 15:50:56 +01:00
|
|
|
#endif
|
2019-07-19 09:45:57 +02:00
|
|
|
i.toBack();
|
|
|
|
if (i.hasPrevious())
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
2019-07-19 09:45:57 +02:00
|
|
|
return i.previous().value();
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
return -1;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-19 09:45:57 +02:00
|
|
|
void VBank::SqMaxMin(qint64 &sMax, qint64 &sMin, uint priority) const
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
sMax = LLONG_MIN;
|
|
|
|
sMin = LLONG_MAX;
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
const QHash<int, qint64> usortedGroup = unsorted.value(priority);
|
|
|
|
QHash<int, qint64>::const_iterator i = usortedGroup.constBegin();
|
|
|
|
while (i != usortedGroup.constEnd())
|
2015-01-11 14:11:56 +01:00
|
|
|
{
|
|
|
|
if (i.value() < sMin)
|
|
|
|
{
|
|
|
|
sMin = i.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i.value() > sMax)
|
|
|
|
{
|
|
|
|
sMax = i.value();
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2019-07-19 09:45:57 +02:00
|
|
|
}
|
2015-01-11 14:11:56 +01:00
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2019-07-27 08:02:41 +02:00
|
|
|
bool VBank::ArrangedDetail(QMap<uint, QHash<int, qint64> > &container, int i)
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
|
|
|
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());
|
2019-07-27 08:02:41 +02:00
|
|
|
auto detailIterator = std::find(containerGroup.begin(), containerGroup.end(), i);
|
|
|
|
if (detailIterator != containerGroup.end())
|
2019-07-19 09:45:57 +02:00
|
|
|
{
|
|
|
|
arranged.append(details.at(detailIterator.value()).GetId());
|
2019-07-27 08:02:41 +02:00
|
|
|
containerGroup.erase(detailIterator);
|
2019-07-19 09:45:57 +02:00
|
|
|
|
|
|
|
if (not containerGroup.isEmpty())
|
|
|
|
{
|
|
|
|
container.insert(iterator.key(), containerGroup);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
container.remove(iterator.key());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-01-11 14:11:56 +01:00
|
|
|
}
|
2016-08-05 15:44:20 +02:00
|
|
|
|
2019-03-30 10:17:54 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VBank::IsRotationNeeded() const
|
|
|
|
{
|
|
|
|
for(auto &piece : details)
|
|
|
|
{
|
|
|
|
if (not piece.IsGrainlineEnabled())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-19 09:45:57 +02:00
|
|
|
|
2016-08-05 15:44:20 +02:00
|
|
|
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC)
|
|
|
|
#pragma pop_macro("small")
|
|
|
|
#endif
|