-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cpp
223 lines (169 loc) · 7.95 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**************************************************************************
** Code written by Hesam Gholami.
**
** Email: hesamgholami@yahoo.com
** Website: http://hesam.org
**
** This file created in 12.
**************************************************************************/
#include "CumulativeStatistics.hpp"
#include "DataProvider.hpp"
#include "DialogSimulation.hpp"
#include "FutureEventList.hpp"
#include "MainWindow.hpp"
#include "ui_MainWindow.h"
#include <QDebug>
#include <QMessageBox>
#include <QSettings>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Loading time
this->initializeLoadingTimeTable();
// Weighing time
this->initializeWeghingTimeTable();
// Travel time
this->initializeTravelTimeTable();
// Load data
this->loadData();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::initializeLoadingTimeTable()
{
// Headers
QStringList strLstHeaders;
strLstHeaders << "Loading Time" << "Probability" << "Cumulative Probability" << "Random Digit Assignment";
ui->tableWidgetLoadingTime->setHorizontalHeaderLabels(strLstHeaders);
// Items
QTableWidgetItem *item1 = new QTableWidgetItem("5");
ui->tableWidgetLoadingTime->setItem(0, 0, item1);
QTableWidgetItem *item2 = new QTableWidgetItem("10");
ui->tableWidgetLoadingTime->setItem(1, 0, item2);
QTableWidgetItem *item3 = new QTableWidgetItem("15");
ui->tableWidgetLoadingTime->setItem(2, 0, item3);
QTableWidgetItem *item4 = new QTableWidgetItem("0.30");
ui->tableWidgetLoadingTime->setItem(0, 1, item4);
QTableWidgetItem *item5 = new QTableWidgetItem("0.50");
ui->tableWidgetLoadingTime->setItem(1, 1, item5);
QTableWidgetItem *item6 = new QTableWidgetItem("0.20");
ui->tableWidgetLoadingTime->setItem(2, 1, item6);
QTableWidgetItem *item7 = new QTableWidgetItem("0.30");
ui->tableWidgetLoadingTime->setItem(0, 2, item7);
QTableWidgetItem *item8 = new QTableWidgetItem("0.80");
ui->tableWidgetLoadingTime->setItem(1, 2, item8);
QTableWidgetItem *item9 = new QTableWidgetItem("1.00");
ui->tableWidgetLoadingTime->setItem(2, 2, item9);
QTableWidgetItem *item10 = new QTableWidgetItem("1-3");
ui->tableWidgetLoadingTime->setItem(0, 3, item10);
QTableWidgetItem *item11 = new QTableWidgetItem("4-8");
ui->tableWidgetLoadingTime->setItem(1, 3, item11);
QTableWidgetItem *item12 = new QTableWidgetItem("9-0");
ui->tableWidgetLoadingTime->setItem(2, 3, item12);
}
void MainWindow::initializeWeghingTimeTable()
{
// Headers
QStringList strLstHeaders;
strLstHeaders << "Weighing Time" << "Probability" << "Cumulative Probability" << "Random Digit Assignment";
ui->tableWidgetWeighingTime->setHorizontalHeaderLabels(strLstHeaders);
// Items
QTableWidgetItem *item1 = new QTableWidgetItem("12");
ui->tableWidgetWeighingTime->setItem(0, 0, item1);
QTableWidgetItem *item2 = new QTableWidgetItem("16");
ui->tableWidgetWeighingTime->setItem(1, 0, item2);
QTableWidgetItem *item3 = new QTableWidgetItem("0.70");
ui->tableWidgetWeighingTime->setItem(0, 1, item3);
QTableWidgetItem *item4 = new QTableWidgetItem("0.30");
ui->tableWidgetWeighingTime->setItem(1, 1, item4);
QTableWidgetItem *item5 = new QTableWidgetItem("0.70");
ui->tableWidgetWeighingTime->setItem(0, 2, item5);
QTableWidgetItem *item6 = new QTableWidgetItem("1.00");
ui->tableWidgetWeighingTime->setItem(1, 2, item6);
QTableWidgetItem *item7 = new QTableWidgetItem("1-7");
ui->tableWidgetWeighingTime->setItem(0, 3, item7);
QTableWidgetItem *item8 = new QTableWidgetItem("8-0");
ui->tableWidgetWeighingTime->setItem(1, 3, item8);
}
void MainWindow::initializeTravelTimeTable()
{
// Headers
QStringList strLstHeaders;
strLstHeaders << "Travel Time" << "Probability" << "Cumulative Probability" << "Random Digit Assignment";
ui->tableWidgetTravelTime->setHorizontalHeaderLabels(strLstHeaders);
// Items
QTableWidgetItem *item1 = new QTableWidgetItem("40");
ui->tableWidgetTravelTime->setItem(0, 0, item1);
QTableWidgetItem *item2 = new QTableWidgetItem("60");
ui->tableWidgetTravelTime->setItem(1, 0, item2);
QTableWidgetItem *item3 = new QTableWidgetItem("80");
ui->tableWidgetTravelTime->setItem(2, 0, item3);
QTableWidgetItem *item4 = new QTableWidgetItem("100");
ui->tableWidgetTravelTime->setItem(3, 0, item4);
QTableWidgetItem *item5 = new QTableWidgetItem("0.40");
ui->tableWidgetTravelTime->setItem(0, 1, item5);
QTableWidgetItem *item6 = new QTableWidgetItem("0.30");
ui->tableWidgetTravelTime->setItem(1, 1, item6);
QTableWidgetItem *item7 = new QTableWidgetItem("0.20");
ui->tableWidgetTravelTime->setItem(2, 1, item7);
QTableWidgetItem *item8 = new QTableWidgetItem("0.10");
ui->tableWidgetTravelTime->setItem(3, 1, item8);
QTableWidgetItem *item9 = new QTableWidgetItem("0.40");
ui->tableWidgetTravelTime->setItem(0, 2, item9);
QTableWidgetItem *item10 = new QTableWidgetItem("0.70");
ui->tableWidgetTravelTime->setItem(1, 2, item10);
QTableWidgetItem *item11 = new QTableWidgetItem("0.90");
ui->tableWidgetTravelTime->setItem(2, 2, item11);
QTableWidgetItem *item12 = new QTableWidgetItem("1.00");
ui->tableWidgetTravelTime->setItem(3, 2, item12);
QTableWidgetItem *item13 = new QTableWidgetItem("1-4");
ui->tableWidgetTravelTime->setItem(0, 3, item13);
QTableWidgetItem *item14 = new QTableWidgetItem("5-7");
ui->tableWidgetTravelTime->setItem(1, 3, item14);
QTableWidgetItem *item15 = new QTableWidgetItem("8-9");
ui->tableWidgetTravelTime->setItem(2, 3, item15);
QTableWidgetItem *item16 = new QTableWidgetItem("0");
ui->tableWidgetTravelTime->setItem(3, 3, item16);
}
void MainWindow::saveData()
{
QSettings settings;
settings.setValue("simulation/count", ui->spinBoxSimulationCount->value());
settings.setValue("simulation/itemsInitialize/trucks", ui->spinBoxNumberOfTrucks->value());
settings.setValue("simulation/itemsInitialize/loadingQueue", ui->spinBoxNumberOfTrucksInLoadingQueue->value());
settings.setValue("simulation/itemsInitialize/loader", ui->spinBoxNumberOfTrucksInLoaders->value());
settings.setValue("simulation/itemsInitialize/weighQueue", ui->spinBoxNumberOftrucksInWeighQueue->value());
settings.setValue("simulation/itemsInitialize/scale", ui->checkBoxTruckInScale->isChecked());
}
void MainWindow::loadData()
{
QSettings settings;
ui->spinBoxSimulationCount->setValue(settings.value("simulation/count").toInt());
ui->spinBoxNumberOfTrucks->setValue(settings.value("simulation/itemsInitialize/trucks").toInt());
ui->spinBoxNumberOfTrucksInLoadingQueue->setValue(settings.value("simulation/itemsInitialize/loadingQueue").toInt());
ui->spinBoxNumberOfTrucksInLoaders->setValue(settings.value("simulation/itemsInitialize/loader").toInt());
ui->spinBoxNumberOftrucksInWeighQueue->setValue(settings.value("simulation/itemsInitialize/weighQueue").toInt());
ui->checkBoxTruckInScale->setChecked(settings.value("simulation/itemsInitialize/scale").toBool());
}
void MainWindow::on_pushButtonSimulation_clicked()
{
int numberOfTrucks = ui->spinBoxNumberOfTrucks->value();
int totalOtherTrucksCount = ui->spinBoxNumberOfTrucksInLoadingQueue->value();
totalOtherTrucksCount += ui->spinBoxNumberOfTrucksInLoaders->value();
totalOtherTrucksCount += ui->spinBoxNumberOftrucksInWeighQueue->value();
totalOtherTrucksCount += ui->checkBoxTruckInScale->isChecked() ? 1 : 0;
if(numberOfTrucks != totalOtherTrucksCount) {
QMessageBox::critical(this, "Inavlid Input Data", "Total number of trucks in loading queue, loader, weigh queue and scale must be equvalent to number of trucks input.");
return;
}
FutureEventList::getInstance()->clear();
DataProvider::clear();
CumulativeStatistics::clear();
this->saveData();
DialogSimulation dlg(this);
dlg.exec();
}