-
Notifications
You must be signed in to change notification settings - Fork 5
/
setting.cpp
412 lines (358 loc) · 12 KB
/
setting.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
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
//##########################################################################
//# This software is part of the Treescaper i
//# -- Version 0.1
//# Copyright (C) 2010 Wen Huang
//#
//# This program is free software; you can redistribute it and/or
//# modify it under the terms of the GNU General Public License
//# as published by the Free Software Foundation; either version 2
//# of the License, or (at your option) any later version.
//#
//# This program is distributed in the hope that it will be useful,
//# but WITHOUT ANY WARRANTY; without even the implied warranty of
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//# GNU General Public License for more details.
//# http://www.gnu.org/copyleft/gpl.html
//##########################################################################
#ifndef SETTING_CPP
#define SETTING_CPP
#include "treescaper.h"
#include "setting.h"
#include "ui_setting.h"
#include <QTableWidgetItem>
#include <iostream>
#include "warray.cpp"
#include <QMessageBox>
#include <QFile>
setting::setting(QWidget *parent) :
QDialog(parent),
ui(new Ui::setting)
{
ui->setupUi(this);
ui->tableWidgetplot->setColumnWidth(0, 60);
ui->tableWidgetplot->setColumnWidth(1, 245);
ui->tableWidgetplotindex->setColumnWidth(0, 70);
ui->textplotstepsize->setReadOnly(true);
// ui->pushplotapply->setEnabled(true);
paravalues = NULL;
indexvalues = NULL;
loadplotparas();
}
setting::~setting()
{
for(int i = 0; i < nparavalues; i++)
delete paravalues[i];
for(int i = 0; i < nindex; i++)
delete indexvalues[i];
delete [] paravalues;
delete [] indexvalues;
delete ui;
}
void setting::loadplotparas()
{
QMessageBox msgBox;
//================load plotparas==================
// File fparas("plotparas");
// if(!fparas.is_open())
// {
// msgBox.setText("error: can not open parameter files \"plotparas\"!");
// msgBox.exec();
// return;
// }
// Array<String> entries;
// String element;
// fparas >> element;
// int countelements = 1; // Skip newline at the end of the file
// while(! fparas.is_end())
// {
// entries.add(element);
// if(countelements > 1024)
// break;
// else
// fparas >> element;
// countelements += 1;
// }
ifstream plotfparas;
plotfparas.open("plotparas");
if(!plotfparas.is_open())
{
msgBox.setText("Error: Cannot open parameter file \"plotparas\"!");
msgBox.exec();
return;
}
string linefromfile;
string elementfromline;
Array<String> entries;
while(getline(plotfparas, linefromfile))
{
std::istringstream iss(linefromfile);
while(iss >> elementfromline)
{
String element(elementfromline.c_str());
entries.add(element);
}
}
if(entries[1] == (String) "Points")
ui->comboBoxplottype->setCurrentIndex(0);
else
ui->comboBoxplottype->setCurrentIndex(1);
if(entries[3] == (String) "1")
ui->checkBoxplotmovie->setChecked(true);
else
ui->checkBoxplotmovie->setChecked(false);
QString qtstr(entries[5]);
ui->textplotnumber->setPlainText(qtstr);
ui->pushplotnum->click();
if(entries[7] == (String) "1")
ui->checkBoxplotsort->setChecked(true);
else
ui->checkBoxplotsort->setChecked(false);
if(entries[9] == (String) "1")
{
ui->radioplotgradual->setChecked(true);
ui->radioplotmost->setChecked(false);
} else
{
ui->radioplotgradual->setChecked(false);
ui->radioplotmost->setChecked(true);
}
nparavalues = 8;
paravalues = new QTableWidgetItem *[nparavalues];
for(int i = 0; i < nparavalues; i++)
{
paravalues[i] = new QTableWidgetItem((char *) entries[i * 2 + 11]);
ui->tableWidgetplot->setItem(i, 0, paravalues[i]);
}
nindex = qtstr.toInt();
indexvalues = new QTableWidgetItem *[nindex];
for(int i = 0; i < nindex; i++)
indexvalues[i] = NULL;
for(int i = 0; i < nindex; i++)
{
if(i * 2 + 27 >= entries.get_length())
{
msgBox.setText("Warning: The index is wrong! Please fix it.");
msgBox.exec();
break;
}
indexvalues[i] = new QTableWidgetItem((char *) entries[i * 2 + 27]);
ui->tableWidgetplotindex->setItem(i, 0, indexvalues[i]);
}
}
void setting::on_pushplotapply_clicked()
{
File fparas("plotparas");
QMessageBox msgBox;
if(!fparas.is_open())
{
msgBox.setText("Error: Cannot open parameter files \"plotparas\"!");
msgBox.exec();
return;
}
fparas.clean();
fparas.seek(0);
QString qtplottype = ui->comboBoxplottype->currentText();
string stdplottype =qtplottype.toStdString();
String plottype(stdplottype.c_str());
paras::plot_type = plottype;
fparas << "plot_type\t" << plottype << endl;
paras::plot_makemovie = ui->checkBoxplotmovie->isChecked();
if(paras::plot_makemovie)
fparas << "plot_makemovie\t" << 1 << endl;
else
fparas << "plot_makemovie\t" << 0 << endl;
QString qtplotnumber = ui->textplotnumber->toPlainText();
paras::imageparas.cluster_num = qtplotnumber.toInt();
fparas << "cluster_num\t" << paras::imageparas.cluster_num << endl;
if(! paras::imageparas.cluster_num)
{
msgBox.setText("warning: invalid cluster number, it must be greater than 0. It may cause errors. Please fix it and click apply again.");
msgBox.exec();
return;
}
paras::is_sort_volume = ui->checkBoxplotsort->isChecked();
if(paras::is_sort_volume)
fparas << "is_sort_volume\t" << 1 << endl;
else
fparas << "is_sort_volume\t" << 0 << endl;
if(ui->radioplotgradual->isChecked())
paras::imageparas.color_type = 1;
else
paras::imageparas.color_type = 0;
fparas << "color_type\t" << paras::imageparas.color_type << endl;
QString stritem;
QTableWidgetItem *item;
item = ui->tableWidgetplot->item(0, 0);
stritem = item->text();
paras::imageparas.outlier_e = stritem.toDouble();
fparas << "outlier_e\t" << paras::imageparas.outlier_e << endl;
item = ui->tableWidgetplot->item(1, 0);
stritem = item->text();
paras::imageparas.outlierpercent = stritem.toDouble();
fparas << "outlierpercent\t" << paras::imageparas.outlierpercent << endl;
item = ui->tableWidgetplot->item(2, 0);
stritem = item->text();
paras::imageparas.sep_factor = stritem.toDouble();
fparas << "sep_factor\t" << paras::imageparas.sep_factor << endl;
item = ui->tableWidgetplot->item(3, 0);
stritem = item->text();
paras::imageparas.point_size = stritem.toDouble();
fparas << "point_size\t" << paras::imageparas.point_size << endl;
item = ui->tableWidgetplot->item(4, 0);
stritem = item->text();
paras::imageparas.moviesizex = stritem.toInt();
fparas << "moviesizex\t" << paras::imageparas.moviesizex << endl;
item = ui->tableWidgetplot->item(5, 0);
stritem = item->text();
paras::imageparas.moviesizey = stritem.toInt();
fparas << "moviesizey\t" << paras::imageparas.moviesizey << endl;
item = ui->tableWidgetplot->item(6, 0);
stritem = item->text();
paras::imageparas.zoom = stritem.toDouble();
fparas << "zoom\t" << paras::imageparas.zoom << endl;
item = ui->tableWidgetplot->item(7, 0);
stritem = item->text();
paras::imageparas.frame_num = stritem.toInt();
fparas << "frame_num\t" << paras::imageparas.frame_num << endl;
int row = ui->tableWidgetplotindex->rowCount();
int max_index = 0;
QStringList indices, range;
QString qtelement;
for(int i = 0; i < row; i++)
{
item = ui->tableWidgetplotindex->item(i, 0);
if(item == NULL)
{
msgBox.setText("Warning: Index is not allow to be empty! Please fill them in.");
msgBox.exec();
return;
}
qtelement = (QString) item->text();
qtelement = qtelement.remove(QChar(' '));
indices = qtelement.split(",", QString::SkipEmptyParts);
for(int j = 0; j < indices.size(); j++)
{
range = indices[j].split("-", QString::SkipEmptyParts);
for(int k = 0; k < range.size(); k++)
if(range[k].toInt() > max_index)
max_index = range[k].toInt();
}
}
delete [] paras::imageparas.cluster_index;
paras::imageparas.cluster_index = new int [max_index + 1];
paras::imageparas.index_size = max_index + 1;
for(int i = 0; i < row; i++)
{
item = ui->tableWidgetplotindex->item(i, 0);
qtelement = (QString) item->text();
qtelement = qtelement.remove(QChar(' '));
fparas << i << "\t" << qtelement.toStdString() << endl;
indices = qtelement.split(",", QString::SkipEmptyParts);
for(int j = 0; j < indices.size(); j++)
{
range = indices[j].split("-", QString::SkipEmptyParts);
if(range.size() == 1)
paras::imageparas.cluster_index[range[0].toInt()] = i;
else
{
for(int k = 0; k < range.size(); k = k + 2)
{
for(int h = range[k].toInt(); h <= range[k + 1].toInt(); h++)
paras::imageparas.cluster_index[h] = i;
}
}
}
}
// ui->pushplotapply->setEnabled(false);
}
void setting::on_textplotnumber_textChanged()
{
}
void setting::on_pushplotnum_clicked()
{
int row = ui->tableWidgetplotindex->rowCount();
QString qtnum = ui->textplotnumber->toPlainText();
int num = qtnum.toInt();
if(num > row)
{
for(int i = 0; i < num - row; i++)
{
ui->tableWidgetplotindex->insertRow(i + row);
}
}
if(num < row)
{
for(int i = 0; i < row - num; i++)
ui->tableWidgetplotindex->removeRow(row - i - 1);
for(int i = num; i < nindex; i++)
indexvalues[i] = NULL;
}
}
void setting::on_textplotstepsize_textChanged()
{
if(ui->checkBoxplotstepsize->isChecked())
{
QString qtstepsize = ui->textplotstepsize->toPlainText();
int stepsize = qtstepsize.toInt();
int row = ui->tableWidgetplotindex->rowCount();
QTableWidgetItem *element;
QString qtstart, qtend, range;
for(int i = 0; i < row; i++)
{
qtstart = QString::number(i * stepsize);
qtend = QString::number((i + 1) * stepsize - 1);
range = qtstart;
range += "-";
range += qtend;
element = ui->tableWidgetplotindex->item(i, 0);
if(element == NULL)
{
element = new QTableWidgetItem(range);
ui->tableWidgetplotindex->setItem(i, 0, element);
} else
element->setText(range);
}
}
}
void setting::on_checkBoxplotstepsize_stateChanged(int )
{
if(ui->checkBoxplotstepsize->isChecked())
{
ui->textplotstepsize->setReadOnly(false);
} else
{
ui->textplotstepsize->setPlainText("");
ui->textplotstepsize->setReadOnly(true);
}
}
void setting::on_pushplotcancel_clicked()
{
loadplotparas();
// ui->pushplotapply->setEnabled(true);
}
void setting::on_pushButton_clicked()
{
QMessageBox MSmsgBox;
MSmsgBox.setText("Restore all original setting for plot parameters?");
MSmsgBox.addButton(QMessageBox::Yes);
MSmsgBox.addButton(QMessageBox::No);
int ret = MSmsgBox.exec();
if(ret == QMessageBox::No)
return;
QFile defaultplotparas("plotparas_default");
QMessageBox msgBox;
if(!defaultplotparas.open(QIODevice::ReadOnly | QIODevice::Text))
{
msgBox.setText("Error: Cannot open default parameter file \"plotparas_default\"!");
msgBox.exec();
return;
}
defaultplotparas.remove("plotparas");
defaultplotparas.copy("plotparas");
ui->pushplotcancel->click();
}
void setting::on_pushplotclose_clicked()
{
QDialog::accept();
}
#endif