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.
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
** <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-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-01-12 16:23:25 +01:00
|
|
|
stopGeneration(false), state(LayoutErrors::NoError), shift(0)
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
CheckDetailsSize();
|
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-12 21:35:32 +01:00
|
|
|
paper.SetPaperIndex(papers.count());
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
QList<QGraphicsItem *> VLayoutGenerator::GetItems() const
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> list;
|
|
|
|
for (int i=0; i < papers.count(); ++i)
|
|
|
|
{
|
|
|
|
list.append(papers.at(i).GetItem());
|
|
|
|
}
|
|
|
|
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-01-12 13:12:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
void VLayoutGenerator::CheckDetailsSize()
|
|
|
|
{
|
|
|
|
const QRectF rec = bank->GetBiggestBoundingRect();
|
|
|
|
if (rec.width() > paperWidth || rec.height() > paperHeight)
|
|
|
|
{
|
|
|
|
state = LayoutErrors::PaperSizeError;
|
|
|
|
emit Error(state);
|
|
|
|
stopGeneration = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
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;
|
|
|
|
}
|