-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.cpp
More file actions
468 lines (377 loc) · 14.5 KB
/
Copy pathdashboard.cpp
File metadata and controls
468 lines (377 loc) · 14.5 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#include "dashboard.h"
Dashboard::Dashboard(QLabel *infoText, QProgressBar *progress, QWidget *parent)
:
QTabWidget(parent)
{
this->infoText = infoText;
this->progressBar = progress;
this->progressBar->setMaximum(99);
this->progressBar->setMinimum(0);
this->setTabsClosable(true);
this->tabBar()->setCursor(Qt::PointingHandCursor);
this->tabBar()->setIconSize(QSize(16, 16));
this->tabBar()->setExpanding(false);
createAddTab();
// Create corner widgets
QGroupBox *cornerWidget = new QGroupBox();
cornerWidget->setObjectName("cornerWidget");
QHBoxLayout *cornerLayout = new QHBoxLayout();
cornerWidget->setLayout(cornerLayout);
cornerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QLabel *textTuples = new QLabel("Total Generated Options (APOLLO_TXTRY) : ");
cornerLayout->addWidget(textTuples);
cornerText = new QLabel("0");
cornerText->setObjectName("cornerText");
cornerText->setAlignment(Qt::AlignCenter);
cornerLayout->addWidget(cornerText);
this->setCornerWidget(cornerWidget);
addRowBtn = new QPushButton();
addRowBtn->setObjectName("miniAdd");
addRowBtn->setCursor(Qt::PointingHandCursor);
this->setCornerWidget(addRowBtn, Qt::TopLeftCorner);
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateTuplesCount(int)));
connect(this, SIGNAL(tabBarClicked(int)), this, SLOT(updateAddBtn(int)));
connect(this, SIGNAL(tabBarClicked(int)), this, SLOT(appendTab(int)));
connect(addRowBtn, SIGNAL(released()), this, SLOT(addOption()));
createTab(true);
}
// PUBLIC FUNCTIONS
int Dashboard::getCurrentCount(){
return Tabs[currentIndex()]->numberRows;
}
QString Dashboard::getCurrentPath(){
return Tabs[currentIndex()]->filePath;
}
QVBoxLayout *Dashboard::getCurrentLayout(){
return Tabs[currentIndex()]->layout;
}
bool Dashboard::isBoardEmpty(){
return count()<=1;
}
bool Dashboard::isCurrentSaved(){
bool exists = QFile::exists(Tabs[currentIndex()]->filePath);
return Tabs[currentIndex()]->saved && exists;
}
void Dashboard::setInfoText(QString s){
infoText->setText(s+" ");
}
void Dashboard::loadFileCurrent(QString path) {
if(path.isEmpty())
return;
QFile file(path);
if(!file.open(QIODevice::ReadOnly)) {
setInfoText("Couln't open file.");
return;
}
int rank = count()-1;
createTab(false);
Tabs[rank]->filePath = path;
QTextStream in(&file);
// Load every row from file
while (!in.atEnd()) {
QString line = in.readLine();
QStringList opts = line.split(',');
if(opts.size()<14)
break;
int idxPara = opts[0].toInt();
int idxTile = opts[1].toInt();
int idxIntraOpt = opts[2].toInt();
int idx2Tile = opts[3].toInt();
int idxIdent = opts[4].toInt();
int idxRar = opts[5].toInt();
int idxPartTile = opts[6].toInt();
int idxLbTile = opts[7].toInt();
int idxFuse = opts[8].toInt();
int idxUnroll = opts[9].toInt();
int idxUnrollF = opts[10].toInt();
int idxIsl = opts[11].toInt();
Matrix tileOpt;
int maxSuites = opts[12].toInt();
QStringList tileOptStr = opts[13].split('/');
if (maxSuites > tileOptStr.length())
break;
// Load every suites for this row from list
for (auto it=tileOptStr.begin(); it!=tileOptStr.end(); ++it){
QStringList suites = (*it).split(':');
if (suites.size() < 2)
break;
vector<int> row;
for(auto it2=suites.begin(); it2!=suites.end(); ++it2){
if(!(*it2).isEmpty())
row.push_back((*it2).toInt());
}
tileOpt.push_back(row);
}
int nrows = Tabs[rank]->numberRows;
OptionSet *newRow = new OptionSet(nrows, idxPara, idxTile, idxIntraOpt, idx2Tile, idxIdent, idxRar, idxPartTile, idxLbTile, idxFuse, idxUnroll, idxUnrollF, idxIsl, tileOpt, this);
addOptionSetToCurrent(newRow);
}
file.close();
Tabs[rank]->saved = true;
QFileInfo fileInfo(file);
setTabText(rank, fileInfo.fileName());
setTabIcon(rank, QIcon(":/images/check.png"));
setInfoText("Successfully opened file at path " + path + ".");
updateCurrentTuplesCount();
}
void Dashboard::saveCurrent(QString path){
int rank = currentIndex();
if (Tabs.size() <= 1 || (Tabs[rank]->saved && path==Tabs[rank]->filePath))
return;
QFile file(path);
if (!file.open(QFile::WriteOnly | QFile::Text)){
setInfoText("Couln't open file.");
return;
}
// Save every row and all of its suites into file
QList<OptionSet *> options = widget(rank)->findChildren<OptionSet *>();
for(auto it=options.begin(); it!=options.end(); ++it){
QTextStream out(&file);
out << (*it)->getParaIdx() << "," << (*it)->getTileIdx() << "," << (*it)->getIntraOptIdx() << ",";
out << (*it)->get2TileIdx() << "," << (*it)->getIdentIdx() << "," << (*it)->getRarIdx() << ",";
out << (*it)->getPartTileIdx() << "," << (*it)->getLbTileIdx() << "," << (*it)->getFuseIdx() << ",";
out << (*it)->getUnrollIdx() << "," << (*it)->getUnrollFIdx() << "," << (*it)->getIslIdx() << ",";
Matrix tilingOpt = (*it)->getTileOptions();
int suitesSize = tilingOpt.size();
out << suitesSize << ",";
for (auto it2=tilingOpt.begin(); it2!=tilingOpt.end(); ++it2) {
for(auto it3=it2->begin(); it3!=it2->end(); ++it3) {
if (*it3==0)
out << *it3;
else
out << ":" << *it3;
}
out << "/";
}
out << "\n";
}
file.close();
Tabs[rank]->filePath = path;
Tabs[rank]->saved = true;
QFileInfo fileInfo(file);
setTabText(rank, fileInfo.fileName());
setTabIcon(rank, QIcon(":/images/check.png"));
setInfoText("Successfully saved file in " + path + ".");
}
void Dashboard::exportCurrent(QString path){
if (Tabs.size() <= 1)
return;
int rank = currentIndex();
progressBar->setValue(0);
QFile file(path);
if (!file.open(QFile::WriteOnly | QFile::Text)){
setInfoText("Couln't open file.");
return;
}
QList<OptionSet *> options = widget(rank)->findChildren<OptionSet *>();
int total=0, optSetAnalyzed=0, optSetCount=options.size();
for(auto it=options.begin(); it!=options.end(); ++it){
QTextStream out(&file);
Matrix *tilingOpt = (*it)->getTileTuples();
if(tilingOpt==nullptr)
break;
for (auto it2=tilingOpt->begin(); it2!=tilingOpt->end(); ++it2){
out << (*it)->getParaIdx() << "," << (*it)->getTileIdx() << "," << (*it)->getIntraOptIdx() << ",";
out << (*it)->get2TileIdx() << "," << (*it)->getIdentIdx() << "," << (*it)->getRarIdx() << ",";
out << (*it)->getPartTileIdx() << "," << (*it)->getLbTileIdx() << "," << (*it)->getFuseIdx() << ",";
out << (*it)->getUnrollIdx() << "," << (*it)->getUnrollFIdx() << "," << (*it)->getIslIdx() << ",";
int size = (*it2).size();
out << size;
for (auto it3=it2->begin(); it3!=it2->end(); ++it3)
out << "," << (*it3);
out << ";";
total++;
}
optSetAnalyzed++;
float prct = (float)optSetAnalyzed/(float)optSetCount * 99.;
progressBar->setValue(prct);
}
file.close();
progressBar->setValue(0);
QString n = QString::number(total);
std::reverse(n.begin(), n.end());
n = n.replace(QRegularExpression("(.{3})"), "\\1 ");
std::reverse(n.begin(), n.end());
setInfoText("Successfully exported file at " + path + ", " + n + " options generated.");
}
void Dashboard::addOptionSetToCurrent(OptionSet *newRow){
int tab = currentIndex();
int rank = Tabs[tab]->numberRows;
Tabs[tab]->layout->insertWidget(rank, newRow);
Tabs[tab]->numberRows++;
connect(newRow, SIGNAL(upClicked(int)), this, SLOT(moveLineUp(int)));
connect(newRow, SIGNAL(downClicked(int)), this, SLOT(moveLineDown(int)));
connect(newRow, SIGNAL(deleted(int)), this, SLOT(updateCurrentRows(int)));
connect(newRow, SIGNAL(setChanged()), this, SLOT(updateCurrentTuplesCount()));
connect(newRow, SIGNAL(setChanged()), this, SLOT(unsaveCurrent()));
if(Tabs[tab]->saved)
unsaveCurrent();
updateCurrentTuplesCount();
}
// PRIVATE FUNCTIONS
void Dashboard::permutRows(int i1, int i2) {
QList<OptionSet *> listOpts = this->widget(currentIndex())->findChildren<OptionSet *>();
int nOpts = listOpts.length();
if (i1<0 || i2<0 || i1>=nOpts || i2>=nOpts)
return;
OptionSet *clickedRow = listOpts[i1];
OptionSet *otherRow = listOpts[i2];
// savedRow := clickedRow
bool idxPara = clickedRow->getParaIdx();
bool idxTile = clickedRow->getTileIdx();
bool idxIntraOpt = clickedRow->getIntraOptIdx();
bool idx2Tile = clickedRow->get2TileIdx();
bool idxIdent = clickedRow->getIdentIdx();
bool idxRar = clickedRow->getRarIdx();
bool idxPartTile = clickedRow->getPartTileIdx();
bool idxLbTile = clickedRow->getLbTileIdx();
int idxFuse = clickedRow->getFuseIdx();
bool idxUnroll = clickedRow->getUnrollIdx();
int idxUnrollF = clickedRow->getUnrollFIdx();
bool idxIsl = clickedRow->getIslIdx();
Matrix tiling = clickedRow->getTileOptions();
// clickedRow := otherRow
clickedRow->setParaIdx(otherRow->getParaIdx());
clickedRow->setIdentIdx(otherRow->getIdentIdx());
clickedRow->setRarIdx(otherRow->getRarIdx());
clickedRow->setFuseIdx(otherRow->getFuseIdx());
clickedRow->setUnrollIdx(otherRow->getUnrollIdx());
clickedRow->setUnrollFIdx(otherRow->getUnrollFIdx());
clickedRow->setIslIdx(otherRow->getIslIdx());
clickedRow->setTileOptions(otherRow->getTileIdx(), otherRow->getIntraOptIdx(), otherRow->get2TileIdx(), otherRow->getPartTileIdx(), otherRow->getLbTileIdx(), otherRow->getTileOptions());
// otherRow := savedRow
otherRow->setParaIdx(idxPara);
otherRow->setIdentIdx(idxIdent);
otherRow->setRarIdx(idxRar);
otherRow->setFuseIdx(idxFuse);
otherRow->setUnrollIdx(idxUnroll);
otherRow->setUnrollFIdx(idxUnrollF);
otherRow->setIslIdx(idxIsl);
otherRow->setTileOptions(idxTile, idxIntraOpt, idx2Tile, idxPartTile, idxLbTile, tiling);
updateCurrentTuplesCount();
}
void Dashboard::createTab(bool firstRow){
QScrollArea *scroll = new QScrollArea();
TabContent *innerScroll = new TabContent();
int rank = this->count()-1;
Tabs.insert(rank, innerScroll);
scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scroll->setWidgetResizable(true);
scroll->setWidget(innerScroll);
this->insertTab(rank, scroll, "New");
this->tabBar()->tabButton(rank, QTabBar::RightSide)->setCursor(Qt::PointingHandCursor);
this->setCurrentIndex(rank);
if (firstRow)
addOption();
}
// PRIVATE SLOTS
void Dashboard::unsaveCurrent(){
int rank = currentIndex();
if (!Tabs[rank]->filePath.isEmpty()){
setTabIcon(rank, QIcon(":/images/check-negativ.png"));
Tabs[rank]->saved = false;
}
}
void Dashboard::updateAddBtn(int rank){
int tabs = this->count();
if (tabs<=1 || rank==tabs-1)
addRowBtn->setDisabled(false);
}
void Dashboard::moveLineUp(int rank) {
int idxTab = currentIndex();
int nOpts = Tabs[idxTab]->numberRows;
int rank2 = mod(rank - 1, nOpts);
permutRows(rank, rank2);
unsaveCurrent();
setInfoText("Option " + QString::number(rank+1) + " successfully swapped with option " + QString::number(rank2+1) + ".");
}
void Dashboard::moveLineDown(int rank) {
int idxTab = currentIndex();
int nOpts = Tabs[idxTab]->numberRows;
int rank2 = mod(rank + 1, nOpts);
permutRows(rank, rank2);
unsaveCurrent();
setInfoText("Option " + QString::number(rank+1) + " successfully swapped with option " + QString::number(rank2+1) + ".");
}
// PUBLIC SLOTS
void Dashboard::appendTab(){
createTab(true);
}
void Dashboard::appendTab(int n){
if (n == count()-1)
createTab(true);
}
void Dashboard::createAddTab(){
TabContent *innerScroll = new TabContent();
innerScroll->scrollBar = new QScrollArea();
Tabs.append(innerScroll);
innerScroll->scrollBar->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
innerScroll->scrollBar->setWidget(innerScroll);
this->addTab(innerScroll->scrollBar, "+");
tabBar()->tabButton(0, QTabBar::RightSide)->setDisabled(true);
tabBar()->tabButton(0, QTabBar::RightSide)->setVisible(false);
tabBar()->tabButton(0, QTabBar::RightSide)->setFixedSize(0, 0);
}
void Dashboard::closeTab(int rank){
if (Tabs.size() <= 1)
return;
Tabs.removeAt(rank);
removeTab(rank);
setCurrentIndex(rank-1);
updateTuplesCount(rank-1);
setInfoText("File successfully closed.");
}
void Dashboard::closeCurrent(){
int index = currentIndex();
closeTab(index);
updateAddBtn(index);
}
void Dashboard::addOption(){
if (isBoardEmpty())
return;
int nrows = Tabs[currentIndex()]->numberRows;
Matrix base;
OptionSet *newRow = new OptionSet(nrows,1,1,0,0,0,0,0,0,0,0,8,0, base);
addOptionSetToCurrent(newRow);
if (isCurrentSaved())
setTabIcon(currentIndex(), QIcon(":/images/check-negativ.png"));
setInfoText("Successfully added option to current tab.");
}
void Dashboard::updateCurrentRows(int rank){
Tabs[currentIndex()]->numberRows--;
QList<OptionSet *> listOpts = this->widget(currentIndex())->findChildren<OptionSet *>();
OptionSet *toDelete = listOpts[rank];
delete toDelete;
listOpts.removeAt(rank);
for (int i=0; i<listOpts.length(); i++)
listOpts[i]->setRank(i);
updateCurrentTuplesCount();
unsaveCurrent();
}
void Dashboard::updateTuplesCount(int rank){
if(count() <= 1){
cornerText->setText("NaN");
return;
}
QList<OptionSet *> options = widget(rank)->findChildren<OptionSet *>();
unsigned long total = 0;
for(auto it=options.begin(); it!=options.end(); ++it)
total += (*it)->getNbTuples();
if(total < 1){
cornerText->setText(QString::number(total));
return;
}
if(total > LIMIT_TUPLES)
total = LIMIT_TUPLES;
QString n = QString::number(total-1);
std::reverse(n.begin(), n.end());
n = n.replace(QRegularExpression("(.{3})"), "\\1 ");
std::reverse(n.begin(), n.end());
if(total==LIMIT_TUPLES)
cornerText->setText(" > " + n);
else
cornerText->setText(n);
}
void Dashboard::updateCurrentTuplesCount(){
updateTuplesCount(currentIndex());
}