Resolved issue #306. Layout generator optimization. Divide into strips.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2016-02-23 14:13:10 +02:00
parent fcd254f08c
commit 595e5b0bf5
16 changed files with 437 additions and 144 deletions

View File

@ -1,4 +1,5 @@
# Version 0.5.0 # Version 0.5.0
- [#306] Layout generator optimization. Divide into strips.
- Fixed case with duplicate names of curves if they connect same points. - Fixed case with duplicate names of curves if they connect same points.
- [#216] Better powerful way creation curved path. - [#216] Better powerful way creation curved path.
- Improved exporting to dxf. QPainterPath export as Polyline. - Improved exporting to dxf. QPainterPath export as Polyline.

View File

@ -302,6 +302,30 @@ void DialogLayoutSettings::SetUnitePages(bool save)
ui->checkBoxUnitePages->setChecked(save); ui->checkBoxUnitePages->setChecked(save);
} }
//---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::IsStripOptimization() const
{
return ui->groupBoxStrips->isChecked();
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetStripOptimization(bool save)
{
ui->groupBoxStrips->setChecked(save);
}
//---------------------------------------------------------------------------------------------------------------------
quint8 DialogLayoutSettings::GetMultiplier() const
{
return static_cast<quint8>(ui->spinBoxMultiplier->value());
}
//---------------------------------------------------------------------------------------------------------------------
void DialogLayoutSettings::SetMultiplier(const quint8 &value)
{
ui->spinBoxMultiplier->setValue(static_cast<int>(value));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool DialogLayoutSettings::IsIgnoreAllFields() const bool DialogLayoutSettings::IsIgnoreAllFields() const
{ {
@ -537,6 +561,8 @@ void DialogLayoutSettings::DialogAccepted()
generator->SetAutoCrop(GetAutoCrop()); generator->SetAutoCrop(GetAutoCrop());
generator->SetSaveLength(IsSaveLength()); generator->SetSaveLength(IsSaveLength());
generator->SetUnitePages(IsUnitePages()); generator->SetUnitePages(IsUnitePages());
generator->SetStripOptimization(IsStripOptimization());
generator->SetMultiplier(GetMultiplier());
if (IsIgnoreAllFields()) if (IsIgnoreAllFields())
{ {
@ -603,6 +629,7 @@ void DialogLayoutSettings::RestoreDefaults()
SetIncrease(VSettings::GetDefLayoutRotationIncrease()); SetIncrease(VSettings::GetDefLayoutRotationIncrease());
SetFields(VSettings::GetDefFields()); SetFields(VSettings::GetDefFields());
SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields()); SetIgnoreAllFields(VSettings::GetDefIgnoreAllFields());
SetMultiplier(VSettings::GetDefMultiplier());
CorrectMaxFileds(); CorrectMaxFileds();
IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked());
@ -953,6 +980,8 @@ void DialogLayoutSettings::ReadSettings()
SetUnitePages(settings->GetLayoutUnitePages()); SetUnitePages(settings->GetLayoutUnitePages());
SetFields(settings->GetFields()); SetFields(settings->GetFields());
SetIgnoreAllFields(settings->GetIgnoreAllFields()); SetIgnoreAllFields(settings->GetIgnoreAllFields());
SetStripOptimization(settings->GetStripOptimization());
SetMultiplier(settings->GetMultiplier());
FindTemplate(); FindTemplate();
@ -976,6 +1005,8 @@ void DialogLayoutSettings::WriteSettings() const
settings->SetLayoutUnitePages(IsUnitePages()); settings->SetLayoutUnitePages(IsUnitePages());
settings->SetFields(GetFields()); settings->SetFields(GetFields());
settings->SetIgnoreAllFields(IsIgnoreAllFields()); settings->SetIgnoreAllFields(IsIgnoreAllFields());
settings->SetStripOptimization(IsStripOptimization());
settings->SetMultiplier(GetMultiplier());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -998,4 +1029,5 @@ void DialogLayoutSettings::SetAdditionalOptions(bool value)
SetAutoCrop(value); SetAutoCrop(value);
SetSaveLength(value); SetSaveLength(value);
SetUnitePages(value); SetUnitePages(value);
SetStripOptimization(value);
} }

View File

@ -102,6 +102,12 @@ public:
bool IsUnitePages() const; bool IsUnitePages() const;
void SetUnitePages(bool save); void SetUnitePages(bool save);
bool IsStripOptimization() const;
void SetStripOptimization(bool save);
quint8 GetMultiplier() const;
void SetMultiplier(const quint8 &value);
bool IsIgnoreAllFields() const; bool IsIgnoreAllFields() const;
void SetIgnoreAllFields(bool value); void SetIgnoreAllFields(bool value);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>661</width> <width>623</width>
<height>453</height> <height>531</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -278,6 +278,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBoxCreationOptions"> <widget class="QGroupBox" name="groupBoxCreationOptions">
<property name="title"> <property name="title">
@ -587,6 +594,54 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxStrips">
<property name="toolTip">
<string>Enabling for sheets that have big height will speed up creating. </string>
</property>
<property name="title">
<string>Divide into strips</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Multiplier</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxMultiplier">
<property name="toolTip">
<string>Set multiplier for length of the biggest workpiece in layout.</string>
</property>
<property name="prefix">
<string>x</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>10</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -124,10 +124,6 @@ bool MainWindowsNoGUI::LayoutSettings(VLayoutGenerator& lGenerator)
CleanLayout(); CleanLayout();
papers = lGenerator.GetPapersItems();// Blank sheets papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetails();// All details details = lGenerator.GetAllDetails();// All details
if (lGenerator.IsUnitePages())
{
UnitePages();
}
CreateShadows(); CreateShadows();
CreateScenes(); CreateScenes();
PrepareSceneList(); PrepareSceneList();
@ -998,91 +994,3 @@ int MainWindowsNoGUI::ContinueIfLayoutStale()
msgBox.exec(); msgBox.exec();
return msgBox.result(); return msgBox.result();
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::UnitePages()
{
if (papers.size() < 2)
{
return;
}
QList<QGraphicsItem *> nPapers;
QList<QList<QGraphicsItem *> > nDetails;
qreal length = 0;
int j = 0; // papers count
for (int i = 0; i < papers.size(); ++i)
{
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
SCASSERT(paper != nullptr);
const QRectF rec = paper->rect();
if (length + rec.height() <= QIMAGE_MAX)
{
UniteDetails(j, nDetails, length, i);
length += rec.height();
UnitePapers(j, nPapers, rec.width(), length);
}
else
{
length = 0; // Strat new paper
++j;// New paper
UniteDetails(j, nDetails, length, i);
length += rec.height();
UnitePapers(j, nPapers, rec.width(), length);
}
}
qDeleteAll (papers);
papers.clear();
papers = nPapers;
details.clear();
details = nDetails;
}
//---------------------------------------------------------------------------------------------------------------------
QList<QGraphicsItem *> MainWindowsNoGUI::MoveDetails(qreal length, const QList<QGraphicsItem *> &details)
{
if (qFuzzyCompare(length+1, 0+1))
{
return details;
}
for (int i = 0; i < details.size(); ++i)
{
details.at(i)->moveBy(0, length);
}
return details;
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::UnitePapers(int j, QList<QGraphicsItem *> &nPapers, qreal width, qreal length)
{
if ((j == 0 && nPapers.isEmpty()) || j >= nPapers.size())
{//First or new paper in list
QGraphicsRectItem *paper = new QGraphicsRectItem(0, 0, width, length);
paper->setPen(QPen(Qt::black, 1));
paper->setBrush(QBrush(Qt::white));
nPapers.insert(j, paper);
}
else
{// Avoid memory leak
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(nPapers.at(j));
paper->setRect(0, 0, width, length);
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::UniteDetails(int j, QList<QList<QGraphicsItem *> > &nDetails, qreal length, int i)
{
if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size())
{//First or new details in paper
nDetails.insert(j, MoveDetails(length, details.at(i)));
}
else
{
nDetails[j].append(MoveDetails(length, details.at(i)));
}
}

View File

@ -130,11 +130,6 @@ private:
QString FileName() const; QString FileName() const;
int ContinueIfLayoutStale(); int ContinueIfLayoutStale();
void UnitePages();
QList<QGraphicsItem *> MoveDetails(qreal length, const QList<QGraphicsItem *> &details);
void UnitePapers(int j, QList<QGraphicsItem *> &nPapers, qreal width, qreal length);
void UniteDetails(int j, QList<QList<QGraphicsItem *> > &nDetails, qreal length, int i);
}; };
#endif // MAINWINDOWSNOGUI_H #endif // MAINWINDOWSNOGUI_H

View File

@ -37,7 +37,7 @@
VBank::VBank() VBank::VBank()
:details(QVector<VLayoutDetail>()), unsorted(QHash<int, qint64>()), big(QHash<int, qint64>()), :details(QVector<VLayoutDetail>()), unsorted(QHash<int, qint64>()), big(QHash<int, qint64>()),
middle(QHash<int, qint64>()), small(QHash<int, qint64>()), layoutWidth(0), caseType(Cases::CaseDesc), middle(QHash<int, qint64>()), small(QHash<int, qint64>()), layoutWidth(0), caseType(Cases::CaseDesc),
prepare(false), boundingRect(QRectF()) prepare(false), diagonal(0)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -168,10 +168,18 @@ bool VBank::Prepare()
return prepare; return prepare;
} }
diagonal = 0;
for (int i=0; i < details.size(); ++i) for (int i=0; i < details.size(); ++i)
{ {
details[i].SetLayoutWidth(layoutWidth); details[i].SetLayoutWidth(layoutWidth);
details[i].SetLayoutAllowencePoints(); details[i].SetLayoutAllowencePoints();
const qreal d = details.at(i).Diagonal();
if (d > diagonal)
{
diagonal = d;
}
const qint64 square = details.at(i).Square(); const qint64 square = details.at(i).Square();
if (square <= 0) if (square <= 0)
{ {
@ -181,7 +189,6 @@ bool VBank::Prepare()
unsorted.insert(i, square); unsorted.insert(i, square);
} }
BiggestBoundingRect();
PrepareGroup(); PrepareGroup();
prepare = true; prepare = true;
@ -196,7 +203,7 @@ void VBank::Reset()
big.clear(); big.clear();
middle.clear(); middle.clear();
small.clear(); small.clear();
boundingRect = QRectF(); diagonal = 0;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -218,37 +225,9 @@ int VBank::LeftArrange() const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VBank::BiggestBoundingRect() qreal VBank::GetBiggestDiagonal() const
{ {
int index = -1; return diagonal;
qint64 sMax = LLONG_MIN;
QHash<int, qint64>::const_iterator i = unsorted.constBegin();
while (i != unsorted.constEnd())
{
if (i.value() > sMax)
{
sMax = i.value();
index = i.key();
}
++i;
}
if (index >= 0 && index < details.size())
{
boundingRect = QPolygonF(details.at(index).GetLayoutAllowencePoints()).boundingRect();
}
else
{
boundingRect = QRectF();
}
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VBank::GetBiggestBoundingRect() const
{
return boundingRect;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -69,7 +69,7 @@ public:
int LeftArrange() const; int LeftArrange() const;
int ArrangedCount() const; int ArrangedCount() const;
QRectF GetBiggestBoundingRect() const; qreal GetBiggestDiagonal() const;
private: private:
Q_DISABLE_COPY(VBank) Q_DISABLE_COPY(VBank)
@ -84,7 +84,7 @@ private:
Cases caseType; Cases caseType;
bool prepare; bool prepare;
QRectF boundingRect; qreal diagonal;
void PrepareGroup(); void PrepareGroup();
@ -97,7 +97,6 @@ private:
int GetNextDescGroup() const; int GetNextDescGroup() const;
void SqMaxMin(qint64 &sMax, qint64 &sMin) const; void SqMaxMin(qint64 &sMax, qint64 &sMin) const;
void BiggestBoundingRect();
}; };
#if defined (Q_OS_WIN) && defined (Q_CC_MSVC) #if defined (Q_OS_WIN) && defined (Q_CC_MSVC)

View File

@ -256,8 +256,14 @@ QRectF VLayoutDetail::BoundingRect() const
{ {
QVector<QPointF> points = GetLayoutAllowencePoints(); QVector<QPointF> points = GetLayoutAllowencePoints();
points.append(points.first()); points.append(points.first());
QRectF rec = QPolygonF(points).boundingRect(); return QPolygonF(points).boundingRect();
return rec; }
//---------------------------------------------------------------------------------------------------------------------
qreal VLayoutDetail::Diagonal() const
{
const QRectF rec = BoundingRect();
return qSqrt(pow(rec.height(), 2) + pow(rec.width(), 2));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -72,6 +72,7 @@ public:
int EdgeByPoint(const QPointF &p1) const; int EdgeByPoint(const QPointF &p1) const;
QRectF BoundingRect() const; QRectF BoundingRect() const;
qreal Diagonal() const;
bool isNull() const; bool isNull() const;
qint64 Square() const; qint64 Square() const;

View File

@ -29,18 +29,21 @@
#include "vlayoutgenerator.h" #include "vlayoutgenerator.h"
#include "vlayoutpaper.h" #include "vlayoutpaper.h"
#include "vlayoutdetail.h" #include "vlayoutdetail.h"
#include "../vmisc/def.h"
#include <QRectF> #include <QRectF>
#include <QImage> #include <QImage>
#include <QDir> #include <QDir>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QThreadPool> #include <QThreadPool>
#include <QtCore/qmath.h>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent) VLayoutGenerator::VLayoutGenerator(QObject *parent)
:QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0), margins(), :QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0), margins(),
stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180), stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180),
autoCrop(false), saveLength(false), unitePages(false) autoCrop(false), saveLength(false), unitePages(false), stripOptimizationEnabled(false), multiplier(1),
stripOptimization(false)
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -92,6 +95,20 @@ void VLayoutGenerator::Generate()
if (bank->Prepare()) if (bank->Prepare())
{ {
const int width = PageWidth();
int height = PageHeight();
if (stripOptimization)
{
const qreal b = bank->GetBiggestDiagonal() * multiplier + bank->GetLayoutWidth();
if (height >= b*2)
{
stripOptimizationEnabled = true;
height = qFloor(height / qFloor(height/b));
}
}
while (bank->AllDetailsCount() > 0) while (bank->AllDetailsCount() > 0)
{ {
if (stopGeneration) if (stopGeneration)
@ -99,7 +116,7 @@ void VLayoutGenerator::Generate()
break; break;
} }
VLayoutPaper paper(PageHeight(), PageWidth()); VLayoutPaper paper(height, width);
paper.SetShift(shift); paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(static_cast<quint32>(papers.count())); paper.SetPaperIndex(static_cast<quint32>(papers.count()));
@ -148,6 +165,17 @@ void VLayoutGenerator::Generate()
emit Error(state); emit Error(state);
return; return;
} }
if (stripOptimizationEnabled)
{
GatherPages();
}
if (IsUnitePages())
{
UnitePages();
}
emit Finished(); emit Finished();
} }
@ -174,7 +202,7 @@ QList<QList<QGraphicsItem *> > VLayoutGenerator::GetAllDetails() const
QList<QList<QGraphicsItem *> > list; QList<QList<QGraphicsItem *> > list;
for (int i=0; i < papers.count(); ++i) for (int i=0; i < papers.count(); ++i)
{ {
list.append(papers.at(i).GetDetails()); list.append(papers.at(i).GetItemDetails());
} }
return list; return list;
} }
@ -189,6 +217,41 @@ void VLayoutGenerator::Abort()
#endif #endif
} }
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsStripOptimization() const
{
return stripOptimization;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetStripOptimization(bool value)
{
stripOptimization = value;
}
//---------------------------------------------------------------------------------------------------------------------
quint8 VLayoutGenerator::GetMultiplier() const
{
return multiplier;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::SetMultiplier(const quint8 &value)
{
if (value > 10)
{
multiplier = 10;
}
else if (value == 0)
{
multiplier = 1;
}
else
{
multiplier = value;
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
int VLayoutGenerator::PageHeight() const int VLayoutGenerator::PageHeight() const
{ {
@ -201,6 +264,161 @@ int VLayoutGenerator::PageWidth() const
return static_cast<int>(paperWidth - (margins.left() + margins.right())); return static_cast<int>(paperWidth - (margins.left() + margins.right()));
} }
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::GatherPages()
{
if (papers.size() < 2)
{
return;
}
QList<QList<VLayoutDetail>> nDetails;
qreal length = 0;
int j = 0; // papers count
for (int i = 0; i < papers.size(); ++i)
{
const int paperHeight = qRound(papers.at(i).BoundingRect().height());
if (length + paperHeight <= PageHeight())
{
UniteDetails(j, nDetails, length, i);
length += paperHeight;
}
else
{
length = 0; // Start new paper
++j;// New paper
UniteDetails(j, nDetails, length, i);
length += paperHeight;
}
}
QVector<VLayoutPaper> nPapers;
for (int i = 0; i < nDetails.size(); ++i)
{
VLayoutPaper paper(PageHeight(), PageWidth());
paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(i);
paper.SetRotate(rotate);
paper.SetRotationIncrease(rotationIncrease);
paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i));
nPapers.append(paper);
}
papers.clear();
papers = nPapers;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::UnitePages()
{
if (papers.size() < 2)
{
return;
}
QList<qreal> papersLength;
QList<QList<VLayoutDetail> > nDetails;
qreal length = 0;
int j = 0; // papers count
for (int i = 0; i < papers.size(); ++i)
{
int paperHeight = 0;
if (autoCrop)
{
paperHeight = qRound(papers.at(i).BoundingRect().height());
}
else
{
paperHeight = papers.at(i).GetHeight();
}
paperHeight = qRound(paperHeight + bank->GetLayoutWidth());
if (length + paperHeight <= QIMAGE_MAX)
{
UniteDetails(j, nDetails, length, i);
length += paperHeight;
UnitePapers(j, papersLength, length);
}
else
{
length = 0; // Start new paper
++j;// New paper
UniteDetails(j, nDetails, length, i);
length += paperHeight;
UnitePapers(j, papersLength, length);
}
}
QVector<VLayoutPaper> nPapers;
for (int i = 0; i < nDetails.size(); ++i)
{
VLayoutPaper paper(qFloor(papersLength.at(i)), PageWidth());
paper.SetShift(shift);
paper.SetLayoutWidth(bank->GetLayoutWidth());
paper.SetPaperIndex(i);
paper.SetRotate(rotate);
paper.SetRotationIncrease(rotationIncrease);
paper.SetSaveLength(saveLength);
paper.SetDetails(nDetails.at(i));
nPapers.append(paper);
}
papers.clear();
papers = nPapers;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::UniteDetails(int j, QList<QList<VLayoutDetail> > &nDetails, qreal length, int i)
{
if ((j == 0 && nDetails.isEmpty()) || j >= nDetails.size())
{//First or new details in paper
nDetails.insert(j, MoveDetails(length, papers.at(i).GetDetails()));
}
else
{
nDetails[j].append(MoveDetails(length, papers.at(i).GetDetails()));
}
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::UnitePapers(int j, QList<qreal> &papersLength, qreal length)
{
if ((j == 0 && papersLength.isEmpty()) || j >= papersLength.size())
{
papersLength.insert(j, length);
}
else
{
papersLength[j] = length;
}
}
//---------------------------------------------------------------------------------------------------------------------
QList<VLayoutDetail> VLayoutGenerator::MoveDetails(qreal length, const QVector<VLayoutDetail> &details)
{
if (qFuzzyIsNull(length))
{
return details.toList();
}
QList<VLayoutDetail> newDetails;
for (int i = 0; i < details.size(); ++i)
{
VLayoutDetail d = details.at(i);
d.Translate(0, length);
newDetails.append(d);
}
return newDetails;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::IsUnitePages() const bool VLayoutGenerator::IsUnitePages() const
{ {

View File

@ -92,6 +92,12 @@ public:
bool IsUnitePages() const; bool IsUnitePages() const;
void SetUnitePages(bool value); void SetUnitePages(bool value);
quint8 GetMultiplier() const;
void SetMultiplier(const quint8 &value);
bool IsStripOptimization() const;
void SetStripOptimization(bool value);
signals: signals:
void Start(); void Start();
void Arranged(int count); void Arranged(int count);
@ -116,9 +122,18 @@ private:
bool autoCrop; bool autoCrop;
bool saveLength; bool saveLength;
bool unitePages; bool unitePages;
bool stripOptimizationEnabled;
quint8 multiplier;
bool stripOptimization;
int PageHeight() const; int PageHeight() const;
int PageWidth() const; int PageWidth() const;
void GatherPages();
void UnitePages();
void UniteDetails(int j, QList<QList<VLayoutDetail> > &nDetails, qreal length, int i);
void UnitePapers(int j, QList<qreal> &papersLength, qreal length);
QList<VLayoutDetail> MoveDetails(qreal length, const QVector<VLayoutDetail> &details);
}; };
typedef std::shared_ptr<VLayoutGenerator> VLayoutGeneratorPtr; typedef std::shared_ptr<VLayoutGenerator> VLayoutGeneratorPtr;

View File

@ -281,7 +281,7 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop) const
if (autoCrop) if (autoCrop)
{ {
QGraphicsScene *scene = new QGraphicsScene(); QGraphicsScene *scene = new QGraphicsScene();
QList<QGraphicsItem *> list = GetDetails(); QList<QGraphicsItem *> list = GetItemDetails();
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
scene->addItem(list.at(i)); scene->addItem(list.at(i));
@ -307,7 +307,7 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop) const
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<QGraphicsItem *> VLayoutPaper::GetDetails() const QList<QGraphicsItem *> VLayoutPaper::GetItemDetails() const
{ {
QList<QGraphicsItem *> list; QList<QGraphicsItem *> list;
for (int i=0; i < d->details.count(); ++i) for (int i=0; i < d->details.count(); ++i)
@ -316,3 +316,27 @@ QList<QGraphicsItem *> VLayoutPaper::GetDetails() const
} }
return list; return list;
} }
//---------------------------------------------------------------------------------------------------------------------
QVector<VLayoutDetail> VLayoutPaper::GetDetails() const
{
return d->details;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetDetails(const QList<VLayoutDetail> &details)
{
d->details = details.toVector();
}
//---------------------------------------------------------------------------------------------------------------------
QRectF VLayoutPaper::BoundingRect() const
{
QRectF rec;
for (int i=0; i < d->details.count(); ++i)
{
rec = rec.united(d->details.at(i).BoundingRect());
}
return rec;
}

View File

@ -37,6 +37,7 @@ class VLayoutDetail;
class QGraphicsItem; class QGraphicsItem;
class VBestSquare; class VBestSquare;
class QGraphicsRectItem; class QGraphicsRectItem;
class QRectF;
class VLayoutPaper class VLayoutPaper
{ {
@ -57,7 +58,7 @@ public:
void SetLayoutWidth(qreal width); void SetLayoutWidth(qreal width);
quint32 GetShift() const; quint32 GetShift() const;
void SetShift(quint32 shift); void SetShift(quint32 shift);
bool GetRotate() const; bool GetRotate() const;
void SetRotate(bool value); void SetRotate(bool value);
@ -73,7 +74,12 @@ public:
bool ArrangeDetail(const VLayoutDetail &detail, volatile bool &stop); bool ArrangeDetail(const VLayoutDetail &detail, volatile bool &stop);
int Count() const; int Count() const;
QGraphicsRectItem *GetPaperItem(bool autoCrop) const; QGraphicsRectItem *GetPaperItem(bool autoCrop) const;
QList<QGraphicsItem *> GetDetails() const; QList<QGraphicsItem *> GetItemDetails() const;
QVector<VLayoutDetail> GetDetails() const;
void SetDetails(const QList<VLayoutDetail>& details);
QRectF BoundingRect() const;
private: private:
QSharedDataPointer<VLayoutPaperData> d; QSharedDataPointer<VLayoutPaperData> d;

View File

@ -75,6 +75,8 @@ const QString VSettings::SettingLayoutSaveLength = QStringLitera
const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages"); const QString VSettings::SettingLayoutUnitePages = QStringLiteral("layout/unitePages");
const QString VSettings::SettingFields = QStringLiteral("layout/fields"); const QString VSettings::SettingFields = QStringLiteral("layout/fields");
const QString VSettings::SettingIgnoreFields = QStringLiteral("layout/ignoreFields"); const QString VSettings::SettingIgnoreFields = QStringLiteral("layout/ignoreFields");
const QString VSettings::SettingStripOptimization = QStringLiteral("layout/stripOptimization");
const QString VSettings::SettingMultiplier = QStringLiteral("layout/multiplier");
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application,
@ -560,3 +562,39 @@ void VSettings::SetIgnoreAllFields(bool value)
{ {
setValue(SettingIgnoreFields, value); setValue(SettingIgnoreFields, value);
} }
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetStripOptimization() const
{
return value(SettingStripOptimization, GetDefStripOptimization()).toBool();
}
//---------------------------------------------------------------------------------------------------------------------
bool VSettings::GetDefStripOptimization()
{
return false;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetStripOptimization(bool value)
{
setValue(SettingStripOptimization, value);
}
//---------------------------------------------------------------------------------------------------------------------
quint8 VSettings::GetMultiplier() const
{
return static_cast<quint8>(value(SettingMultiplier, GetDefMultiplier()).toUInt());
}
//---------------------------------------------------------------------------------------------------------------------
quint8 VSettings::GetDefMultiplier()
{
return 1;
}
//---------------------------------------------------------------------------------------------------------------------
void VSettings::SetMultiplier(quint8 value)
{
setValue(SettingMultiplier, value);
}

View File

@ -134,6 +134,14 @@ public:
static bool GetDefIgnoreAllFields(); static bool GetDefIgnoreAllFields();
void SetIgnoreAllFields(bool value); void SetIgnoreAllFields(bool value);
bool GetStripOptimization() const;
static bool GetDefStripOptimization();
void SetStripOptimization(bool value);
quint8 GetMultiplier() const;
static quint8 GetDefMultiplier();
void SetMultiplier(quint8 value);
private: private:
Q_DISABLE_COPY(VSettings) Q_DISABLE_COPY(VSettings)
static const QString SettingConfigurationLabelLanguage; static const QString SettingConfigurationLabelLanguage;
@ -166,6 +174,8 @@ private:
static const QString SettingLayoutUnitePages; static const QString SettingLayoutUnitePages;
static const QString SettingFields; static const QString SettingFields;
static const QString SettingIgnoreFields; static const QString SettingIgnoreFields;
static const QString SettingStripOptimization;
static const QString SettingMultiplier;
}; };
#endif // VSETTINGS_H #endif // VSETTINGS_H