From ef73b351edeea29cfe3b9bca029f58c78a80c595 Mon Sep 17 00:00:00 2001 From: dismine Date: Thu, 22 Jan 2015 16:11:50 +0200 Subject: [PATCH] New options: rotatate and rotation increase. --HG-- branch : feature --- src/app/dialogs/app/dialoglayoutsettings.cpp | 31 ++ src/app/dialogs/app/dialoglayoutsettings.h | 6 + src/app/dialogs/app/dialoglayoutsettings.ui | 472 +++++++++++++------ src/app/tablewindow.cpp | 2 + src/libs/vlayout/vlayoutgenerator.cpp | 33 +- src/libs/vlayout/vlayoutgenerator.h | 8 + src/libs/vlayout/vlayoutpaper.cpp | 33 +- src/libs/vlayout/vlayoutpaper.h | 6 + src/libs/vlayout/vlayoutpaper_p.h | 10 +- src/libs/vlayout/vposition.cpp | 24 +- src/libs/vlayout/vposition.h | 5 +- 11 files changed, 464 insertions(+), 166 deletions(-) diff --git a/src/app/dialogs/app/dialoglayoutsettings.cpp b/src/app/dialogs/app/dialoglayoutsettings.cpp index e5cea7856..9b4dc7a86 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.cpp +++ b/src/app/dialogs/app/dialoglayoutsettings.cpp @@ -153,6 +153,37 @@ void DialogLayoutSettings::SetGroup(const Cases &value) } } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogLayoutSettings::GetRotate() const +{ + return ui->groupBoxRotate->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetRotate(bool state) +{ + ui->groupBoxRotate->setChecked(state); +} + +//--------------------------------------------------------------------------------------------------------------------- +int DialogLayoutSettings::GetIncrease() const +{ + return ui->comboBoxIncrease->currentText().toInt(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetIncrease(int increase) +{ + int index = ui->comboBoxIncrease->findText(QString::number(increase)); + + if (index == -1) + { + index = 21; + } + + ui->comboBoxIncrease->setCurrentIndex(index); +} + //--------------------------------------------------------------------------------------------------------------------- void DialogLayoutSettings::TemplateSelected() { diff --git a/src/app/dialogs/app/dialoglayoutsettings.h b/src/app/dialogs/app/dialoglayoutsettings.h index 1739d468d..4936c9997 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.h +++ b/src/app/dialogs/app/dialoglayoutsettings.h @@ -61,6 +61,12 @@ public: Cases GetGroup() const; void SetGroup(const Cases &value); + bool GetRotate() const; + void SetRotate(bool state); + + int GetIncrease() const; + void SetIncrease(int increase); + public slots: void ConvertPaperSize(); void ConvertLayoutSize(); diff --git a/src/app/dialogs/app/dialoglayoutsettings.ui b/src/app/dialogs/app/dialoglayoutsettings.ui index f50ad9533..2fae9b45c 100644 --- a/src/app/dialogs/app/dialoglayoutsettings.ui +++ b/src/app/dialogs/app/dialoglayoutsettings.ui @@ -6,182 +6,344 @@ 0 0 - 659 - 273 + 661 + 289 Creation a layout - + - + - - - Paper size - - - - - - 6 - + + + + + Paper size + + + false + + + false + + + false + + - - - - 0 - 0 - + + + 6 - - Templates: - - - - - - - - - - - - - - - 0 - 0 - - - - - 124 - 0 - - - - - - - - - 0 - 0 - - - - Width: - - - - - - - - 0 - 0 - - - - Height: - - - - - - - - 94 - 0 - - - - 2 - - - 99999.000000000000000 - - - - - - - - 94 - 0 - - - - 2 - - - 99999.990000000005239 - - - - - - - TextLabel - - - - - - + + + + 0 + 0 + + - ... + Templates: - - - :/icon/16x16/portrait.png:/icon/16x16/portrait.png - - - true - - - true - - - true - - - buttonGroup - - - - ... + + + + + + + + + + + 0 + 0 + - - - :/icon/16x16/landscape.png:/icon/16x16/landscape.png + + + 124 + 0 + - - true - - - false - - - true - - - buttonGroup - + + + + + 0 + 0 + + + + Width: + + + + + + + + 0 + 0 + + + + Height: + + + + + + + + 94 + 0 + + + + 2 + + + 99999.000000000000000 + + + + + + + + 94 + 0 + + + + 2 + + + 99999.990000000005239 + + + + + + + TextLabel + + + + + + + + + ... + + + + :/icon/16x16/portrait.png:/icon/16x16/portrait.png + + + true + + + true + + + true + + + buttonGroup + + + + + + + ... + + + + :/icon/16x16/landscape.png:/icon/16x16/landscape.png + + + true + + + false + + + true + + + buttonGroup + + + + + - - - + + + + + + Rotate workpiece + + + true + + + + + + + 0 + 0 + + + + Rotate by + + + + + + + 21 + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 8 + + + + + 9 + + + + + 10 + + + + + 12 + + + + + 15 + + + + + 18 + + + + + 20 + + + + + 24 + + + + + 30 + + + + + 36 + + + + + 40 + + + + + 45 + + + + + 60 + + + + + 72 + + + + + 90 + + + + + 180 + + + + + + + + degree + + + + + + + @@ -349,7 +511,7 @@ - + diff --git a/src/app/tablewindow.cpp b/src/app/tablewindow.cpp index bd47d5691..f348bc020 100644 --- a/src/app/tablewindow.cpp +++ b/src/app/tablewindow.cpp @@ -285,6 +285,8 @@ void TableWindow::Layout() lGenerator.SetPaperHeight(layout.GetPaperHeight()); lGenerator.SetPaperWidth(layout.GetPaperWidth()); lGenerator.SetShift(layout.GetShift()); + lGenerator.SetRotate(layout.GetRotate()); + lGenerator.SetRotationIncrease(layout.GetIncrease()); DialogLayoutProgress progress(listDetails.count(), this); diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 0501440da..d7ccad3c8 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -38,7 +38,7 @@ //--------------------------------------------------------------------------------------------------------------------- VLayoutGenerator::VLayoutGenerator(QObject *parent) :QObject(parent), papers(QVector()), bank(new VBank()), paperHeight(0), paperWidth(0), - stopGeneration(false), state(LayoutErrors::NoError), shift(0) + stopGeneration(false), state(LayoutErrors::NoError), shift(0), rotate(true), rotationIncrease(180) {} //--------------------------------------------------------------------------------------------------------------------- @@ -101,6 +101,8 @@ void VLayoutGenerator::Generate() paper.SetShift(shift); paper.SetLayoutWidth(bank->GetLayoutWidth()); paper.SetPaperIndex(papers.count()); + paper.SetRotate(rotate); + paper.SetRotationIncrease(rotationIncrease); do { const int index = bank->GetTiket(); @@ -170,6 +172,35 @@ void VLayoutGenerator::Abort() state = LayoutErrors::ProcessStoped; } +//--------------------------------------------------------------------------------------------------------------------- +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; +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutGenerator::CheckDetailsSize() { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 5146a19ff..2e8f30d0e 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -66,6 +66,12 @@ public: QList GetItems() const; + bool GetRotate() const; + void SetRotate(bool value); + + int GetRotationIncrease() const; + void SetRotationIncrease(int value); + signals: void Start(); void Arranged(int count); @@ -84,6 +90,8 @@ private: bool stopGeneration; LayoutErrors state; unsigned int shift; + bool rotate; + int rotationIncrease; void CheckDetailsSize(); }; diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 1574ee7b6..247af5e98 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -122,6 +122,35 @@ void VLayoutPaper::SetShift(unsigned int shift) d->globalContour.SetShift(shift); } +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutPaper::GetRotate() const +{ + return d->rotate; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPaper::SetRotate(bool value) +{ + d->rotate = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VLayoutPaper::GetRotationIncrease() const +{ + return d->rotationIncrease; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPaper::SetRotationIncrease(int value) +{ + d->rotationIncrease = value; + + if ((d->rotationIncrease >= 1 && d->rotationIncrease <= 180 && 360 % d->rotationIncrease == 0) == false) + { + d->rotationIncrease = 180; + } +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutPaper::SetPaperIndex(quint32 index) { @@ -164,7 +193,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop) { for (int i=1; i<= detail.EdgesCount(); i++) { - VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop); + VPosition *thread = new VPosition(d->globalContour, j, detail, i, &stop, d->rotate, d->rotationIncrease); //Info for debug #ifdef LAYOUT_DEBUG thread->setPaperIndex(d->paperIndex); @@ -177,7 +206,7 @@ bool VLayoutPaper::AddToSheet(const VLayoutDetail &detail, bool &stop) threads.append(thread); thread_pool->start(thread); - d->frame = d->frame + 3 + 360/180*2; + d->frame = d->frame + 3 + 360/d->rotationIncrease*2; } } diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 2bc3c45f6..fe0310ad3 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -64,6 +64,12 @@ public: unsigned int GetShift() const; void SetShift(unsigned int shift); + bool GetRotate() const; + void SetRotate(bool value); + + int GetRotationIncrease() const; + void SetRotationIncrease(int value); + void SetPaperIndex(quint32 index); bool ArrangeDetail(const VLayoutDetail &detail, bool &stop); diff --git a/src/libs/vlayout/vlayoutpaper_p.h b/src/libs/vlayout/vlayoutpaper_p.h index 0834895b9..09acd09e1 100644 --- a/src/libs/vlayout/vlayoutpaper_p.h +++ b/src/libs/vlayout/vlayoutpaper_p.h @@ -45,17 +45,19 @@ class VLayoutPaperData : public QSharedData { public: VLayoutPaperData() - :details(QVector()), globalContour(VContour()), paperIndex(0), frame(0), layoutWidth(0) + :details(QVector()), globalContour(VContour()), paperIndex(0), frame(0), layoutWidth(0), + rotate(true), rotationIncrease(180) {} VLayoutPaperData(int height, int width) :details(QVector()), globalContour(VContour(height, width)), paperIndex(0), frame(0), - layoutWidth(0) + layoutWidth(0), rotate(true), rotationIncrease(180) {} VLayoutPaperData(const VLayoutPaperData &paper) :QSharedData(paper), details(paper.details), globalContour(paper.globalContour), paperIndex(paper.paperIndex), - frame(paper.frame), layoutWidth(paper.layoutWidth) + frame(paper.frame), layoutWidth(paper.layoutWidth), rotate(paper.rotate), + rotationIncrease(paper.rotationIncrease) {} ~VLayoutPaperData() {} @@ -69,6 +71,8 @@ public: quint32 paperIndex; quint32 frame; qreal layoutWidth; + bool rotate; + int rotationIncrease; }; #ifdef Q_CC_GNU diff --git a/src/libs/vlayout/vposition.cpp b/src/libs/vlayout/vposition.cpp index cf8a2e685..e99b5a0c9 100644 --- a/src/libs/vlayout/vposition.cpp +++ b/src/libs/vlayout/vposition.cpp @@ -38,10 +38,16 @@ #include //--------------------------------------------------------------------------------------------------------------------- -VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop) +VPosition::VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop, bool rotate, + int rotationIncrease) :QRunnable(), bestResult(VBestSquare()), gContour(gContour), detail(detail), i(i), j(j), paperIndex(0), frame(0), - detailsCount(0), details(QVector()), stop(stop) -{} + detailsCount(0), details(QVector()), stop(stop), rotate(rotate), rotationIncrease(rotationIncrease) +{ + if ((rotationIncrease >= 1 && rotationIncrease <= 180 && 360 % rotationIncrease == 0) == false) + { + rotationIncrease = 180; + } +} //--------------------------------------------------------------------------------------------------------------------- void VPosition::run() @@ -69,7 +75,17 @@ void VPosition::run() } frame = frame + 3; - Rotate(180); + if (rotate) + { + Rotate(rotationIncrease); + } + else + { + if (gContour.GetContour().isEmpty()) + { + Rotate(rotationIncrease); + } + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vlayout/vposition.h b/src/libs/vlayout/vposition.h index 833fdccc0..2ec01169c 100644 --- a/src/libs/vlayout/vposition.h +++ b/src/libs/vlayout/vposition.h @@ -46,7 +46,8 @@ class QPainterPath; class VPosition : public QRunnable { public: - VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop); + VPosition(const VContour &gContour, int j, const VLayoutDetail &detail, int i, bool *stop, bool rotate, + int rotationIncrease); virtual ~VPosition(){} virtual void run(); @@ -79,6 +80,8 @@ private: quint32 detailsCount; QVector details; bool *stop; + bool rotate; + int rotationIncrease; enum class CrossingType : char {