Don't save last options for creation a layout.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-17 15:14:28 +02:00
parent 28b2f97aaa
commit 56aa09a639
6 changed files with 52 additions and 45 deletions

View File

@ -262,7 +262,7 @@ void DialogLayoutSettings::InitLayoutUnits()
} }
ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(1, Unit::Mm, oldLayoutUnit)); ui->doubleSpinBoxLayoutWidth->setValue(VAbstractMeasurements::UnitConvertor(1, Unit::Mm, oldLayoutUnit));
ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(10, Unit::Mm, oldLayoutUnit)); ui->doubleSpinBoxShift->setValue(VAbstractMeasurements::UnitConvertor(50, Unit::Mm, oldLayoutUnit));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -54,8 +54,7 @@
TableWindow::TableWindow(QWidget *parent) TableWindow::TableWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::TableWindow), :QMainWindow(parent), ui(new Ui::TableWindow),
listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()), listDetails(QVector<VLayoutDetail>()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
scenes(QList<QGraphicsScene *>()), fileName(QString()), description(QString()), paperHeight(0), paperWidth(0), scenes(QList<QGraphicsScene *>()), fileName(QString()), description(QString()), tempScene(nullptr)
shift(0), layoutWidth(0), group(Cases::CaseDesc), tempScene(nullptr)
{ {
ui->setupUi(this); ui->setupUi(this);
tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm))); tempScene = new QGraphicsScene(QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm)));
@ -67,8 +66,8 @@ TableWindow::TableWindow(QWidget *parent)
ui->view->setScene(tempScene); ui->view->setScene(tempScene);
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
ui->horizontalLayout->addWidget(ui->view); ui->horizontalLayout->addWidget(ui->view);
//connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn); connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn);
//connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut); connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut);
connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable); connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable);
//connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene); //connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene);
connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout); connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout);
@ -255,49 +254,39 @@ void TableWindow::saveScene()
// delete brush; // delete brush;
} }
//---------------------------------------------------------------------------------------------------------------------
void TableWindow::ShowPaper(int index) void TableWindow::ShowPaper(int index)
{ {
if (index < 0 || index > scenes.size()) if (index < 0 || index > scenes.size())
{ {
ui->view->setScene(tempScene); ui->view->setScene(tempScene);
} }
else
{
ui->view->setScene(scenes.at(index)); ui->view->setScene(scenes.at(index));
}
ui->view->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TableWindow::Layout() void TableWindow::Layout()
{ {
DialogLayoutSettings layout(this); DialogLayoutSettings layout(this);
if (paperHeight != 0)
{
layout.SetPaperHeight(paperHeight);
layout.SetPaperWidth(paperWidth);
layout.SetLayoutWidth(layoutWidth);
layout.SetShift(shift);
layout.SetGroup(group);
}
if (layout.exec() == QDialog::Rejected) if (layout.exec() == QDialog::Rejected)
{ {
return; return;
} }
paperHeight = layout.GetPaperHeight();
paperWidth = layout.GetPaperWidth();
shift = layout.GetShift();
layoutWidth = layout.GetLayoutWidth();
group = layout.GetGroup();
VLayoutGenerator lGenerator(this); VLayoutGenerator lGenerator(this);
lGenerator.SetDetails(listDetails); lGenerator.SetDetails(listDetails);
lGenerator.SetLayoutWidth(layoutWidth); lGenerator.SetLayoutWidth(layout.GetLayoutWidth());
lGenerator.SetCaseType(group); lGenerator.SetCaseType(layout.GetGroup());
lGenerator.SetPaperHeight(paperHeight); lGenerator.SetPaperHeight(layout.GetPaperHeight());
lGenerator.SetPaperWidth(paperWidth); lGenerator.SetPaperWidth(layout.GetPaperWidth());
lGenerator.SetShift(shift); lGenerator.SetShift(layout.GetShift());
DialogLayoutProgress progress(lGenerator.DetailsCount(), this); DialogLayoutProgress progress(listDetails.count(), this);
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start); connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged); connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
@ -307,14 +296,25 @@ void TableWindow::Layout()
lGenerator.Generate(); lGenerator.Generate();
if (lGenerator.State() == LayoutErrors::NoError) switch (lGenerator.State())
{ {
case LayoutErrors::NoError:
ClearLayout(); ClearLayout();
papers = lGenerator.GetItems(); papers = lGenerator.GetItems();
CreateShadows(); CreateShadows();
CreateScenes(); CreateScenes();
// Create previews // Create previews
PrepareSceneList(); PrepareSceneList();
break;
case LayoutErrors::ProcessStoped:
break;
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::PaperSizeError:
case LayoutErrors::EmptyPaperError:
ClearLayout();
break;
default:
break;
} }
} }
@ -470,9 +470,9 @@ void TableWindow::ClearLayout()
{ {
qDeleteAll (scenes); qDeleteAll (scenes);
scenes.clear(); scenes.clear();
listDetails.clear();
shadows.clear(); shadows.clear();
papers.clear(); papers.clear();
ui->listWidget->clear();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -517,9 +517,14 @@ void TableWindow::CreateScenes()
void TableWindow::PrepareSceneList() void TableWindow::PrepareSceneList()
{ {
const QIcon ico("://icon/64x64/icon64x64.png"); const QIcon ico("://icon/64x64/icon64x64.png");
for (int i=0; i<scenes.size(); ++i) for (int i=1; i<=scenes.size(); ++i)
{ {
QListWidgetItem *item = new QListWidgetItem(ico, QString::number(i)); QListWidgetItem *item = new QListWidgetItem(ico, QString::number(i));
ui->listWidget->addItem(item); ui->listWidget->addItem(item);
} }
if (scenes.isEmpty() == false)
{
ui->listWidget->setCurrentRow(0);
}
} }

View File

@ -87,12 +87,6 @@ private:
/** @brief description pattern description */ /** @brief description pattern description */
QString description; QString description;
int paperHeight;
int paperWidth;
unsigned int shift;
qreal layoutWidth;
Cases group;
QGraphicsScene* tempScene; QGraphicsScene* tempScene;
void SvgFile(const QString &name)const; void SvgFile(const QString &name)const;

View File

@ -40,12 +40,13 @@ enum class LayoutErrors : char
EmptyPaperError EmptyPaperError
}; };
#define LAYOUT_DEBUG // Enable debug mode //#define LAYOUT_DEBUG // Enable debug mode
#ifdef LAYOUT_DEBUG #ifdef LAYOUT_DEBUG
# define SHOW_VERTICES // Show contour vertices # define SHOW_VERTICES // Show contour vertices
# define SHOW_DIRECTION // Show contour direction # define SHOW_DIRECTION // Show contour direction
# define ARRANGED_DETAILS // Show already arranged details # define ARRANGED_DETAILS // Show already arranged details
//# define SHOW_ROTATION
#endif//LAYOUT_DEBUG #endif//LAYOUT_DEBUG
#endif // VLAYOUTDEF_H #endif // VLAYOUTDEF_H

View File

@ -119,6 +119,11 @@ void VLayoutGenerator::Generate()
} }
} while(bank->LeftArrange() > 0); } while(bank->LeftArrange() > 0);
if (stopGeneration)
{
break;
}
if (paper.Count() > 0) if (paper.Count() > 0)
{ {
papers.append(paper); papers.append(paper);

View File

@ -69,7 +69,7 @@ BestResult::BestResult()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void BestResult::NewResult(qint64 square, int i, int j, const QMatrix &matrix) void BestResult::NewResult(qint64 square, int i, int j, const QMatrix &matrix)
{ {
if (square < resSquare && square > 0) if (square <= resSquare && square > 0)
{ {
resI = i; resI = i;
resJ = j; resJ = j;
@ -409,7 +409,9 @@ bool VLayoutPaper::CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, i
RotateEdges(detail, globalEdge, dEdge, angle); RotateEdges(detail, globalEdge, dEdge, angle);
#ifdef LAYOUT_DEBUG #ifdef LAYOUT_DEBUG
#ifdef SHOW_ROTATION
DrawDebug(detail, d->frame); DrawDebug(detail, d->frame);
#endif
#endif #endif
switch (Crossing(detail, j, dEdge)) switch (Crossing(detail, j, dEdge))