New options: rotatate and rotation increase.

--HG--
branch : feature
This commit is contained in:
dismine 2015-01-22 16:11:50 +02:00
parent dd098506dd
commit ef73b351ed
11 changed files with 464 additions and 166 deletions

View File

@ -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()
{

View File

@ -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();

View File

@ -6,21 +6,32 @@
<rect>
<x>0</x>
<y>0</y>
<width>659</width>
<height>273</height>
<width>661</width>
<height>289</height>
</rect>
</property>
<property name="windowTitle">
<string>Creation a layout</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBoxPaperSize">
<property name="title">
<string>Paper size</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
@ -183,6 +194,157 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxRotate">
<property name="title">
<string>Rotate workpiece</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Rotate by</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxIncrease">
<property name="currentIndex">
<number>21</number>
</property>
<item>
<property name="text">
<string notr="true">1</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">2</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">3</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">4</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">5</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">6</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">8</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">9</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">10</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">12</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">15</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">18</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">20</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">24</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">30</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">36</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">40</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">45</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">60</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">72</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">90</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">180</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>degree</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBoxCreationOptions">
<property name="title">
@ -349,7 +511,7 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroupPrinciple"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

View File

@ -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);

View File

@ -38,7 +38,7 @@
//---------------------------------------------------------------------------------------------------------------------
VLayoutGenerator::VLayoutGenerator(QObject *parent)
:QObject(parent), papers(QVector<VLayoutPaper>()), 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()
{

View File

@ -66,6 +66,12 @@ public:
QList<QGraphicsItem *> 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();
};

View File

@ -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;
}
}

View File

@ -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);

View File

@ -45,17 +45,19 @@ class VLayoutPaperData : public QSharedData
{
public:
VLayoutPaperData()
:details(QVector<VLayoutDetail>()), globalContour(VContour()), paperIndex(0), frame(0), layoutWidth(0)
:details(QVector<VLayoutDetail>()), globalContour(VContour()), paperIndex(0), frame(0), layoutWidth(0),
rotate(true), rotationIncrease(180)
{}
VLayoutPaperData(int height, int width)
:details(QVector<VLayoutDetail>()), 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

View File

@ -38,10 +38,16 @@
#include <QCoreApplication>
//---------------------------------------------------------------------------------------------------------------------
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<VLayoutDetail>()), stop(stop)
{}
detailsCount(0), details(QVector<VLayoutDetail>()), 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);
}
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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<VLayoutDetail> details;
bool *stop;
bool rotate;
int rotationIncrease;
enum class CrossingType : char
{