2015-01-02 14:53:36 +01:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vlayoutgenerator.cpp
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
** @date 2 1, 2015
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
2015-02-27 11:27:48 +01:00
|
|
|
** Copyright (C) 2013-2015 Valentina project
|
2015-01-02 14:53:36 +01:00
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
**
|
|
|
|
** 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 "vlayoutgenerator.h"
|
2015-01-12 13:12:15 +01:00
|
|
|
#include "vlayoutpaper.h"
|
|
|
|
#include "vlayoutdetail.h"
|
2015-01-02 14:53:36 +01:00
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
#include <QRectF>
|
2015-01-12 21:35:32 +01:00
|
|
|
#include <QImage>
|
|
|
|
#include <QDir>
|
2015-01-13 11:38:51 +01:00
|
|
|
#include <QGraphicsItem>
|
2015-05-02 19:18:31 +02:00
|
|
|
#include <QThreadPool>
|
2015-01-02 14:53:36 +01:00
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutGenerator::VLayoutGenerator(QObject *parent)
|
|
|
|
:QObject(parent), papers(QVector<VLayoutPaper>()), bank(new VBank()), paperHeight(0), paperWidth(0),
|
2015-05-02 18:21:47 +02:00
|
|
|
stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180),
|
2015-05-18 13:26:37 +02:00
|
|
|
autoCrop(false), saveLength(false), unitePages(false)
|
2015-01-12 13:12:15 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
VLayoutGenerator::~VLayoutGenerator()
|
|
|
|
{
|
|
|
|
delete bank;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetDetails(const QVector<VLayoutDetail> &details)
|
2015-01-02 14:53:36 +01:00
|
|
|
{
|
2015-01-12 13:12:15 +01:00
|
|
|
bank->SetDetails(details);
|
2015-01-02 14:53:36 +01:00
|
|
|
}
|
2015-01-12 13:12:15 +01:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetLayoutWidth(qreal width)
|
|
|
|
{
|
|
|
|
bank->SetLayoutWidth(width);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetCaseType(Cases caseType)
|
|
|
|
{
|
|
|
|
bank->SetCaseType(caseType);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-01-12 13:12:15 +01:00
|
|
|
int VLayoutGenerator::DetailsCount()
|
|
|
|
{
|
|
|
|
return bank->AllDetailsCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::Generate()
|
|
|
|
{
|
|
|
|
stopGeneration = false;
|
|
|
|
papers.clear();
|
|
|
|
state = LayoutErrors::NoError;
|
2015-01-12 21:35:32 +01:00
|
|
|
|
|
|
|
#ifdef LAYOUT_DEBUG
|
|
|
|
const QString path = QDir::homePath()+QStringLiteral("/LayoutDebug");
|
|
|
|
QDir debugDir(path);
|
|
|
|
debugDir.removeRecursively();
|
|
|
|
debugDir.mkpath(path);
|
|
|
|
#endif
|
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
emit Start();
|
|
|
|
|
|
|
|
if (bank->Prepare())
|
|
|
|
{
|
2015-01-16 20:34:37 +01:00
|
|
|
while (bank->AllDetailsCount() > 0)
|
2015-01-12 13:12:15 +01:00
|
|
|
{
|
|
|
|
if (stopGeneration)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
VLayoutPaper paper(paperHeight, paperWidth);
|
2015-01-12 16:23:25 +01:00
|
|
|
paper.SetShift(shift);
|
2015-01-17 15:00:46 +01:00
|
|
|
paper.SetLayoutWidth(bank->GetLayoutWidth());
|
2015-03-16 13:23:02 +01:00
|
|
|
paper.SetPaperIndex(static_cast<quint32>(papers.count()));
|
2015-01-22 15:11:50 +01:00
|
|
|
paper.SetRotate(rotate);
|
|
|
|
paper.SetRotationIncrease(rotationIncrease);
|
2015-05-08 12:10:56 +02:00
|
|
|
paper.SetSaveLength(saveLength);
|
2015-01-16 20:34:37 +01:00
|
|
|
do
|
2015-01-12 13:12:15 +01:00
|
|
|
{
|
|
|
|
const int index = bank->GetTiket();
|
2015-01-16 15:45:56 +01:00
|
|
|
if (paper.ArrangeDetail(bank->GetDetail(index), stopGeneration))
|
2015-01-12 13:12:15 +01:00
|
|
|
{
|
|
|
|
bank->Arranged(index);
|
2015-01-16 13:53:14 +01:00
|
|
|
emit Arranged(bank->ArrangedCount());
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bank->NotArranged(index);
|
|
|
|
}
|
2015-01-16 15:45:56 +01:00
|
|
|
|
|
|
|
if (stopGeneration)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-01-16 20:34:37 +01:00
|
|
|
} while(bank->LeftArrange() > 0);
|
|
|
|
|
2015-01-17 14:14:28 +01:00
|
|
|
if (stopGeneration)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-16 20:34:37 +01:00
|
|
|
if (paper.Count() > 0)
|
|
|
|
{
|
|
|
|
papers.append(paper);
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-16 20:34:37 +01:00
|
|
|
state = LayoutErrors::EmptyPaperError;
|
|
|
|
emit Error(state);
|
|
|
|
return;
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
2015-01-16 20:34:37 +01:00
|
|
|
}
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state = LayoutErrors::PrepareLayoutError;
|
|
|
|
emit Error(state);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-15 14:10:05 +01:00
|
|
|
emit Finished();
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
LayoutErrors VLayoutGenerator::State() const
|
|
|
|
{
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2015-01-13 11:38:51 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-01-23 11:07:58 +01:00
|
|
|
QList<QGraphicsItem *> VLayoutGenerator::GetPapersItems() const
|
2015-01-13 11:38:51 +01:00
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> list;
|
|
|
|
for (int i=0; i < papers.count(); ++i)
|
|
|
|
{
|
2015-05-02 18:21:47 +02:00
|
|
|
list.append(papers.at(i).GetPaperItem(autoCrop));
|
2015-01-23 11:07:58 +01:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<QList<QGraphicsItem *> > VLayoutGenerator::GetAllDetails() const
|
|
|
|
{
|
|
|
|
QList<QList<QGraphicsItem *> > list;
|
|
|
|
for (int i=0; i < papers.count(); ++i)
|
|
|
|
{
|
|
|
|
list.append(papers.at(i).GetDetails());
|
2015-01-13 11:38:51 +01:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::Abort()
|
|
|
|
{
|
|
|
|
stopGeneration = true;
|
2015-01-16 15:45:56 +01:00
|
|
|
state = LayoutErrors::ProcessStoped;
|
2015-05-02 19:18:31 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)
|
|
|
|
QThreadPool::globalInstance()->clear();
|
|
|
|
#endif
|
2015-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
|
2015-05-18 13:26:37 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutGenerator::IsUnitePages() const
|
|
|
|
{
|
|
|
|
return unitePages;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetUnitePages(bool value)
|
|
|
|
{
|
|
|
|
unitePages = value;
|
|
|
|
}
|
|
|
|
|
2015-05-08 12:10:56 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutGenerator::IsSaveLength() const
|
|
|
|
{
|
|
|
|
return saveLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetSaveLength(bool value)
|
|
|
|
{
|
|
|
|
saveLength = value;
|
|
|
|
}
|
|
|
|
|
2015-05-02 18:21:47 +02:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutGenerator::GetAutoCrop() const
|
|
|
|
{
|
|
|
|
return autoCrop;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetAutoCrop(bool value)
|
|
|
|
{
|
|
|
|
autoCrop = value;
|
|
|
|
}
|
|
|
|
|
2015-01-22 15:11:50 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-04-15 14:44:57 +02:00
|
|
|
// cppcheck-suppress unusedFunction
|
2015-01-22 15:11:50 +01:00
|
|
|
int VLayoutGenerator::GetRotationIncrease() const
|
|
|
|
{
|
|
|
|
return rotationIncrease;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetRotationIncrease(int value)
|
|
|
|
{
|
|
|
|
rotationIncrease = value;
|
|
|
|
|
|
|
|
if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false)
|
|
|
|
{
|
|
|
|
rotationIncrease = 180;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
bool VLayoutGenerator::GetRotate() const
|
|
|
|
{
|
|
|
|
return rotate;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetRotate(bool value)
|
|
|
|
{
|
|
|
|
rotate = value;
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutGenerator::GetPaperWidth() const
|
|
|
|
{
|
|
|
|
return paperWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetPaperWidth(int value)
|
|
|
|
{
|
|
|
|
paperWidth = value;
|
|
|
|
}
|
|
|
|
|
2015-01-12 16:23:25 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
unsigned int VLayoutGenerator::GetShift() const
|
|
|
|
{
|
|
|
|
return shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetShift(unsigned int shift)
|
|
|
|
{
|
|
|
|
this->shift = shift;
|
|
|
|
}
|
|
|
|
|
2015-01-12 13:12:15 +01:00
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
int VLayoutGenerator::GetPaperHeight() const
|
|
|
|
{
|
|
|
|
return paperHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::SetPaperHeight(int value)
|
|
|
|
{
|
|
|
|
paperHeight = value;
|
|
|
|
}
|