From 56aa09a6392c4fe1a83d7137cdec4b8b48c1196a Mon Sep 17 00:00:00 2001 From: dismine Date: Sat, 17 Jan 2015 15:14:28 +0200 Subject: [PATCH] Don't save last options for creation a layout. --HG-- branch : feature --- src/app/dialogs/app/dialoglayoutsettings.cpp | 2 +- src/app/tablewindow.cpp | 75 +++++++++++--------- src/app/tablewindow.h | 6 -- src/libs/vlayout/vlayoutdef.h | 3 +- src/libs/vlayout/vlayoutgenerator.cpp | 5 ++ src/libs/vlayout/vlayoutpaper.cpp | 6 +- 6 files changed, 52 insertions(+), 45 deletions(-) diff --git a/src/app/dialogs/app/dialoglayoutsettings.cpp b/src/app/dialogs/app/dialoglayoutsettings.cpp index 41fdca2b3..e5cea7856 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.cpp +++ b/src/app/dialogs/app/dialoglayoutsettings.cpp @@ -262,7 +262,7 @@ void DialogLayoutSettings::InitLayoutUnits() } 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)); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index 78371a773..bd47d5691 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -54,8 +54,7 @@ TableWindow::TableWindow(QWidget *parent) :QMainWindow(parent), ui(new Ui::TableWindow), listDetails(QVector()), papers(QList()), shadows(QList()), - scenes(QList()), fileName(QString()), description(QString()), paperHeight(0), paperWidth(0), - shift(0), layoutWidth(0), group(Cases::CaseDesc), tempScene(nullptr) + scenes(QList()), fileName(QString()), description(QString()), tempScene(nullptr) { ui->setupUi(this); 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->fitInView(ui->view->scene()->sceneRect(), Qt::KeepAspectRatio); ui->horizontalLayout->addWidget(ui->view); - //connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn); - //connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut); + connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomIn); + connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VTableGraphicsView::ZoomOut); connect(ui->actionStop, &QAction::triggered, this, &TableWindow::StopTable); //connect(ui->actionSave, &QAction::triggered, this, &TableWindow::saveScene); connect(ui->actionLayout, &QAction::triggered, this, &TableWindow::Layout); @@ -255,49 +254,39 @@ void TableWindow::saveScene() // delete brush; } +//--------------------------------------------------------------------------------------------------------------------- void TableWindow::ShowPaper(int index) { if (index < 0 || index > scenes.size()) { 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() { 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) { return; } - paperHeight = layout.GetPaperHeight(); - paperWidth = layout.GetPaperWidth(); - shift = layout.GetShift(); - layoutWidth = layout.GetLayoutWidth(); - group = layout.GetGroup(); - VLayoutGenerator lGenerator(this); lGenerator.SetDetails(listDetails); - lGenerator.SetLayoutWidth(layoutWidth); - lGenerator.SetCaseType(group); - lGenerator.SetPaperHeight(paperHeight); - lGenerator.SetPaperWidth(paperWidth); - lGenerator.SetShift(shift); + lGenerator.SetLayoutWidth(layout.GetLayoutWidth()); + lGenerator.SetCaseType(layout.GetGroup()); + lGenerator.SetPaperHeight(layout.GetPaperHeight()); + lGenerator.SetPaperWidth(layout.GetPaperWidth()); + lGenerator.SetShift(layout.GetShift()); - DialogLayoutProgress progress(lGenerator.DetailsCount(), this); + DialogLayoutProgress progress(listDetails.count(), this); connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start); connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged); @@ -307,14 +296,25 @@ void TableWindow::Layout() lGenerator.Generate(); - if (lGenerator.State() == LayoutErrors::NoError) + switch (lGenerator.State()) { - ClearLayout(); - papers = lGenerator.GetItems(); - CreateShadows(); - CreateScenes(); - // Create previews - PrepareSceneList(); + case LayoutErrors::NoError: + ClearLayout(); + papers = lGenerator.GetItems(); + CreateShadows(); + CreateScenes(); + // Create previews + 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); scenes.clear(); - listDetails.clear(); shadows.clear(); papers.clear(); + ui->listWidget->clear(); } //--------------------------------------------------------------------------------------------------------------------- @@ -517,9 +517,14 @@ void TableWindow::CreateScenes() void TableWindow::PrepareSceneList() { const QIcon ico("://icon/64x64/icon64x64.png"); - for (int i=0; ilistWidget->addItem(item); } + + if (scenes.isEmpty() == false) + { + ui->listWidget->setCurrentRow(0); + } } diff --git a/src/app/tablewindow.h b/src/app/tablewindow.h index 071561ba8..d038308d5 100644 --- a/src/app/tablewindow.h +++ b/src/app/tablewindow.h @@ -87,12 +87,6 @@ private: /** @brief description pattern description */ QString description; - int paperHeight; - int paperWidth; - unsigned int shift; - qreal layoutWidth; - Cases group; - QGraphicsScene* tempScene; void SvgFile(const QString &name)const; diff --git a/src/libs/vlayout/vlayoutdef.h b/src/libs/vlayout/vlayoutdef.h index 30f7593ab..3ceb260f8 100644 --- a/src/libs/vlayout/vlayoutdef.h +++ b/src/libs/vlayout/vlayoutdef.h @@ -40,12 +40,13 @@ enum class LayoutErrors : char EmptyPaperError }; -#define LAYOUT_DEBUG // Enable debug mode +//#define LAYOUT_DEBUG // Enable debug mode #ifdef LAYOUT_DEBUG # define SHOW_VERTICES // Show contour vertices # define SHOW_DIRECTION // Show contour direction # define ARRANGED_DETAILS // Show already arranged details +//# define SHOW_ROTATION #endif//LAYOUT_DEBUG #endif // VLAYOUTDEF_H diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index d5f229c20..01f5b6038 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -119,6 +119,11 @@ void VLayoutGenerator::Generate() } } while(bank->LeftArrange() > 0); + if (stopGeneration) + { + break; + } + if (paper.Count() > 0) { papers.append(paper); diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 32f7eedee..34e86beaf 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -69,7 +69,7 @@ BestResult::BestResult() //--------------------------------------------------------------------------------------------------------------------- void BestResult::NewResult(qint64 square, int i, int j, const QMatrix &matrix) { - if (square < resSquare && square > 0) + if (square <= resSquare && square > 0) { resI = i; resJ = j; @@ -409,7 +409,9 @@ bool VLayoutPaper::CheckRotationEdges(VLayoutDetail &detail, int j, int dEdge, i RotateEdges(detail, globalEdge, dEdge, angle); #ifdef LAYOUT_DEBUG - DrawDebug(detail, d->frame); + #ifdef SHOW_ROTATION + DrawDebug(detail, d->frame); + #endif #endif switch (Crossing(detail, j, dEdge))