-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconvert_road_test_data_dialog.cpp
More file actions
630 lines (483 loc) · 18.4 KB
/
Copy pathconvert_road_test_data_dialog.cpp
File metadata and controls
630 lines (483 loc) · 18.4 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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/****************************************/
/* This class creates dialog for user to*/
/* input the requirment data for road */
/* test data conversion. */
/* Auther: */
/* Wei Ben */
/* Data : */
/* Sept. 07, 2004 */
/* Revise: Oct. 11, 2004 */
/* Nov, 16, 2004 */
/****************************************/
#include "cconst.h"
#include "wisim.h"
#include "convert_road_test_data_dialog.h"
#include "helpdialog.h"
// added by Wei on Nov. 15, 2004
#include "road_test_pair.h"
#include <qstringlist.h>
#include <q3whatsthis.h>
#include <q3header.h>
#include <qtooltip.h>
#include <qvariant.h>
#include <q3buttongroup.h>
#include <q3frame.h>
#include <qimage.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qlineedit.h>
#include <q3filedialog.h>
#include <qmessagebox.h>
#include <qcombobox.h>
#include <q3listbox.h>
#include <qlayout.h>
#include <qregexp.h>
//Added by qt3to4:
#include <Q3HBoxLayout>
#include <Q3GridLayout>
#include <Q3VBoxLayout>
#include <stdio.h>
#include <stdlib.h>
#ifdef __linux__
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#else
#include <process.h>
#endif
// added on Oct. 11, 2004
#include "server.h"
#include <iostream>
#define CGDEBUG 0
extern char *wisim_home;
ConvertRoadTestDataDialog::ConvertRoadTestDataDialog(QWidget* parent, const char* name, \
bool modal, Qt::WFlags f)
: QDialog(parent, name, modal, f)
{
data = new Element();
help = new helpDialog(data->getHelpFile(), this, tr ("help"), TRUE );
// added on Nov. 16, 2004
m_bTypeC = false;
oTypeSpecialDlg = new SpecialFormatDialog(this);
sExtension = QString("crtd");
setCaption( tr("Convert Road Test Data") );
resize( 400, 380);
roadtestFormLayout = new Q3VBoxLayout(this, 11, 6, "whole_Form");
Q3GridLayout *grid = new Q3GridLayout(roadtestFormLayout, 0, 0, 10);
int row = 0;
int labelCol = 0;
int linedCol = 1;
oFileTypeComboBox = new QComboBox( FALSE, this );
oFileTypeComboBox->insertItem("a" );
oFileTypeComboBox->insertItem("b" );
oFileTypeComboBox->insertItem("c" );
oFileTypeComboBox->insertItem("d" );
oFileTypeComboBox->insertItem("e" );
oFileTypeComboBox->insertItem("f" );
oFileTypeComboBox->insertItem("g" );
oFileTypeComboBox->insertItem("h" );
oFileTypeComboBox->insertItem("i" );
oFileTypeComboBox->insertItem("j" );
grid->addWidget(oFileTypeComboBox, row, linedCol);
oDataFormatLabel = new QLabel(oFileTypeComboBox, tr( "Input File &Type") ,this, "TypeLabe");
grid->addWidget(oDataFormatLabel, row, labelCol);
oTypeHelp = new QPushButton( tr ("Help"), this);
grid->addWidget(oTypeHelp, row, linedCol+1);
// modified on Nov. 16, 2004
oInputPushButton = new QPushButton(tr ("Input &Files ..." ), this);
grid->addWidget(oInputPushButton, row+1, labelCol);
oDisplayInputFiles = new Q3ListBox(this, "only display", 0);
//oDisplayInputFiles->setSelectionMode(QListBox::Extended);
grid->addMultiCellWidget(oDisplayInputFiles, row+1, row+3, linedCol, linedCol+1);//linedCol, linedCol);
// added on Nov. 16, 2004
removeBtn = new QPushButton(tr("&Remove"), this);
grid->addWidget(removeBtn, row+2, labelCol);
// added on Nov. 25, 2004
oUnitComboBox = new QComboBox( FALSE, this, "comboBox1" );
oUnitComboBox->clear();
oUnitComboBox->insertItem( "dBm" );
oUnitComboBox->insertItem( "dBuV_107" );
oUnitComboBox->insertItem( "dBuV_113" );
oUnitComboBox->setCurrentItem( 2 ); // added by Liu Tao, 05-03-10
grid->addWidget(oUnitComboBox, row+3, labelCol);
// the output file format
OutputLayout = new Q3HBoxLayout( 0, 0, 6);
oOutputTextLabel = new QLabel( tr ("&Out file..." ), this );
OutputLayout->addWidget( oOutputTextLabel );
fileChooser = new FileChooser( this, "fileChooser ", CConst::saveFileMode );
fileChooser ->setFileFilter( tr("Road Test Data Files") + " (*.crtd);;" + tr("All Files") + " (*)" );
fileChooser ->setDialogCaption( tr ("Choose File..."));
OutputLayout->addWidget( fileChooser );
roadtestFormLayout->addLayout( OutputLayout );
oOutputTextLabel->setBuddy(fileChooser);
// the threshold and resolution items
thresholdLayout = new Q3HBoxLayout( 0, 0, 6 );
oThresholdLabel = new QLabel( tr ("Threshold") + " (dBuV_113)", this );
thresholdLayout->addWidget(oThresholdLabel );
oThresholdSpinBox = new QSpinBox( this );
oThresholdSpinBox->setMinValue( -200);
oThresholdSpinBox->setMaxValue( 200 );
oThresholdSpinBox->setValue(80);
thresholdLayout->addWidget( oThresholdSpinBox );
roadtestFormLayout->addLayout( thresholdLayout );
oThresholdLabel->setBuddy(oThresholdSpinBox);
resolutionLayout = new Q3HBoxLayout( 0, 0, 6);
oResolutionLabel = new QLabel(tr ("Resolution "), this);
resolutionLayout->addWidget(oResolutionLabel);
oResolutionSpinBox = new QSpinBox(this);
oResolutionSpinBox->setMinValue(1);
oResolutionSpinBox->setMaxValue(32);
resolutionLayout->addWidget(oResolutionSpinBox);
oResolutionLabel->setBuddy(oResolutionSpinBox);
roadtestFormLayout->addLayout( resolutionLayout );
buttonsLayout = new Q3HBoxLayout( 0, 0, 6 );
QSpacerItem *spacer = new QSpacerItem( 0, 0,
QSizePolicy::Expanding, QSizePolicy::Minimum );
buttonsLayout->addItem( spacer );
okPushButton = new QPushButton(tr("OK"), this );
okPushButton->setDefault(false);
okPushButton->setEnabled(false);
buttonsLayout->addWidget( okPushButton );
cancelPushButton = new QPushButton( tr("Cancel"), this );
okPushButton->setDefault(true);
buttonsLayout->addWidget( cancelPushButton );
roadtestFormLayout->addLayout( buttonsLayout );
connect( oTypeHelp, SIGNAL( clicked() ), this,
SLOT( openHelp() ) );
connect( oInputPushButton, SIGNAL( clicked() ),
this, SLOT( chooseInputFiles() ) );
connect( fileChooser->lineEdit, SIGNAL( textChanged(const QString &) ),
this, SLOT( chooseOutputFile(const QString&) ) );
connect( okPushButton, SIGNAL( clicked() ),
this, SLOT( runPerl() ) );
connect( cancelPushButton, SIGNAL( clicked() ),
this, SLOT( cancelResponse() ) );
// added on Nov. 16, 2004
connect( oFileTypeComboBox, SIGNAL( activated(const QString&) ), \
this, SLOT( changeOptions(const QString&) ) );
connect( oUnitComboBox, SIGNAL( activated(const QString&) ), \
this, SLOT( changeUnitOpt(const QString&) ) );
connect( removeBtn, SIGNAL( clicked()), this, SLOT( removeItem()) );
//------------------
// user defined signal/slot
connect( this, SIGNAL( listboxchanged(bool )) , \
this, SLOT( updateOkEnabled(bool )) );
exec();
}
/**********************************/
/* the deconstructor */
/**********************************/
ConvertRoadTestDataDialog::~ConvertRoadTestDataDialog() {
delete data;
// added on Nov. 16, 2004
delete oTypeSpecialDlg;
}
/**********************************/
/* the help button slot */
/**********************************/
void ConvertRoadTestDataDialog::openHelp() {
help->exec();
}
/**********************************/
/* the cancel button slot */
/**********************************/
void ConvertRoadTestDataDialog::cancelResponse() {
delete this;
}
/**********************************/
/* the input file slot */
/**********************************/
void ConvertRoadTestDataDialog::chooseInputFiles() {
static int iPairCount = 1;
// added on Nov. 16, 2004
if (m_bTypeC) {
// popup the oTypeSpecialDlg to input files
if (oTypeSpecialDlg->exec() == QDialog::Accepted ) {
oDisplayInputFiles->insertItem(QString("%1 %2").arg(oTypeSpecialDlg->getGpsName(),oTypeSpecialDlg->getPhsName()));
iPairCount++;
list.append(oTypeSpecialDlg->getGpsName());
list.append(oTypeSpecialDlg->getPhsName());
//qDebug(list.join("*"));
}
}
else {
QStringList tlst;
QString filt = tr("Files") + " (*.txt);;" + tr("All Files") + " (*)";
iPairCount = 1;
QStringList files = Q3FileDialog::getOpenFileNames(filt,
QString::null,
this,
"open files dialog"
"Select one or more files to open" );
tlst = files;
if (! tlst.isEmpty())
{
oDisplayInputFiles->insertStringList(tlst, -1);
list += tlst;
}
#if CGDEBUG
std::cout << " input file, list.size() " << list.size() << std::endl;
#endif
}
emit listboxchanged(true);
}
/**********************************/
/* choose output file slot */
/**********************************/
void ConvertRoadTestDataDialog::chooseOutputFile() {
int answer;
QString filename;
Q3FileDialog* fd = new Q3FileDialog(QString::null,
tr("Road Test Data Files") + " (*.crtd);;" + tr("All Files") + " (*)",
this,
"file create", "Road Test Convert -- File Output" );
fd->setMode( Q3FileDialog::AnyFile );
if ( fd->exec() == QDialog::Accepted ) {
filename = fd->selectedFile();
if ( !filename.isEmpty() ) {
if ( QFile::exists( filename ) ) {
answer = QMessageBox::warning(
this, "Road Test Convert -- Overwrite File",
QString( "Overwrite\n\'%1\'?" ).
arg( filename ),
"&Yes", "&No", QString::null, 1, 1 );
if ( answer == 0 ) {
setOutputFile(filename);
}
}
else {
setOutputFile(filename);
}
}
}
data->setOutputFile(filename);
}
/********************************************/
/* new output file button response */
/* Modified: Oct. 19, 2004 */
/********************************************/
void ConvertRoadTestDataDialog::chooseOutputFile(const QString& filename ) {
QString fn = filename;
qDebug(fn);
if (filename != "") {
QRegExp rx = QRegExp("\\." + sExtension + "$");
if (rx.search(filename) == -1) {
fn += "." + sExtension;
}
data->setOutputFile(fn);
emit listboxchanged(true);
}
else
emit listboxchanged(false);
}
/********************************************/
/* The dialog's ok button slot */
/* get the input, run convert_rtd.pl */
/* using socket technique to comm. with GUI */
/* Modified: Oct. 14, 2004: using fork() */
/* Oct. 26, 2004 not using fork()*/
/********************************************/
void ConvertRoadTestDataDialog::runPerl() {
getInput();
if ( validInput()) {
#ifdef __linux__
// -----------------------------------------------------------------
// Modified on Nov. 29, 2004.
// changed to use CVECTOR() to adapt to no-GUI, no QT support --------
char *exefile;
exefile = CVECTOR(strlen(wisim_home) + 1 + strlen("convert_rtd.pl"));
sprintf(exefile, "%s%cconvert_rtd.pl", wisim_home, FPATH_SEPARATOR);
//printf("%s\n", exefile);
char *txtfile;
txtfile = CVECTOR(strlen(wisim_home) + 3 + strlen("rtd_input.txt"));
sprintf(txtfile, "%s%crtd_input.txt", wisim_home, FPATH_SEPARATOR);
//printf("%s\n", txtfile);
char *cmd;
//cmd = CVECTOR(strlen(exefile) + strlen(txtfile) + 11);
// sprintf(cmd, "%s %s %s %c", exefile, "-socket", txtfile, '&');
// convert_rtd.pl lies at wisim_home dir.
cmd = CVECTOR(strlen("convert_rtd.pl") + strlen(txtfile) + 11);
sprintf(cmd, "%s %s %s %c", "convert_rtd.pl", "-socket", txtfile, '&');
// convert_rtd.pl lies at current directory
system(cmd);
ServerInfo *server = new ServerInfo();
free(exefile);
free(txtfile);
free (cmd);
delete this;
// ------------------------------------------------------------------
#else
//_spawnl( _P_WAIT, "convert_rtd.exe -socket < file.txt &", NULL ); // under current directory.
// modified on Oct. 14, 2004
// under current directory
//_spawnl( _P_DETACH, "convert_rtd.exe", "convert_rtd.exe","-socket", "file.txt", NULL );
/*
// ----------------------------------------------------------------
// modified on Nov. 25, 2004 by Wei Ben -- use the path --
QString sParaName = QString(wisim_home) + QString(QChar(FPATH_SEPARATOR)) + "file.txt";
QString sExeName = QString(wisim_home) + QString(QChar(FPATH_SEPARATOR)) + "convert_rtd.exe";
QString sCmd = QString("_P_DETACH, \"%1\", \"convert_rtd.exe\",\"-socket\", \"%2\"").arg(sExeName.latin1(), sParaName.latin1());
_spawnl( sCmd.latin1(), NULL);
ServerInfo *server = new ServerInfo();
delete this;
// -----------------------------------------------------------------
*/
// -----------------------------------------------------------------
// Modified on Nov. 29, 2004.
// changed to use CVECTOR() to adapt to no-GUI, no QT support --------
char *exefile;
exefile = CVECTOR(strlen(wisim_home) + 1 + strlen("convert_rtd.exe"));
sprintf(exefile, "%s%cconvert_rtd.exe", wisim_home, FPATH_SEPARATOR);
char *txtfile;
txtfile = CVECTOR(strlen(wisim_home) + 3 + strlen("rtd_input.txt"));
sprintf(txtfile, "\"%s%crtd_input.txt\"", wisim_home, FPATH_SEPARATOR);
_spawnl( _P_DETACH, exefile, "convert_rtd.exe", "-socket", txtfile, NULL );
ServerInfo *server = new ServerInfo();
free(exefile);
free(txtfile);
delete this;
// ------------------------------------------------------------------
#endif
}
else {
QMessageBox::warning( this, "Alert",
tr("Input Data Incomplete!"),
tr ("OK"), QString::null, 0,1 );
}
}
/*******************************************/
/* check the user's input data validation */
/*******************************************/
void ConvertRoadTestDataDialog::validNum(const QString &text) {
QString fileNum;
bool ok;
fileNum = text;
int dec = fileNum.toInt( &ok, 10 );
if ( ( ok) && ( dec == 0)) {
QMessageBox::warning( this, "Valadition of the user's input",
QString( "Input File Number can't be zero!\n" ),
"&OK", QString::null, 0,1 );
}
else if ( ! ok) {
QMessageBox::warning( this, "Valadition of the user's input",
QString( "Input File Number will be digit!\n" ),
"&OK", QString::null, 0,1 );
}
}
/*******************************************/
/* display the user's choosed output file */
/*******************************************/
void ConvertRoadTestDataDialog::setOutputFile(QString filename) {
oOutputTextLabel->setText( filename);
}
/******************************************/
/* fill the data object: element */
/* and save the input in a specific file */
/******************************************/
void ConvertRoadTestDataDialog::getInput() {
int threshold, resolution;
QString tmp, fileNum, sUnit;
tmp = oFileTypeComboBox->currentText();
sUnit = oUnitComboBox->currentText();
threshold = oThresholdSpinBox->value();
resolution = oResolutionSpinBox->value();
data->setResolution((double) resolution);
data->setFormat(tmp);
data->setThreshold(threshold);
// added on Nov. 16, 2004
if (m_bTypeC)
data->setNumInput(list.count() / 2 );
else
data->setNumInput(list.count());
data->setInputFiles(list);
#if CGDEBUG
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
std::cout << "size " << list.size() << " " << *it << "\n";
}
std::cout << std::endl;
#endif
// added on Nov. 25, 2004
data->setUnitName(sUnit);
data->writeToFile();
}
bool ConvertRoadTestDataDialog::validInput() {
if (data->validation())
return true;
else
return false;
}
/*********************************/
/* slot for choosing type */
/* specially handle the type c */
/* Date: Nov. 16, 2004 */
/*********************************/
void ConvertRoadTestDataDialog::changeOptions(const QString & s)
{
if (s.compare("c") == 0) {
//qDebug("choose the type c");
m_bTypeC = true;
} else {
m_bTypeC = false;
}
}
void ConvertRoadTestDataDialog::removeItem() {
QString sItemText;
QStringList tmp;
if( oDisplayInputFiles->currentItem() > -1 ) {
sItemText = oDisplayInputFiles->currentText();
oDisplayInputFiles->removeItem( oDisplayInputFiles->currentItem() );
if (m_bTypeC) {
tmp = QStringList::split(" ", sItemText, false);
for ( QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it ) {
list.remove(*it);
}
}
else
list.remove(sItemText);
//qDebug(sItemText);
//qDebug(list.join("*"));
}
if (oDisplayInputFiles->count() == 0)
emit listboxchanged(false);
else
emit listboxchanged(true);
}
/*****************************************/
/* slot for unit option change */
/* change the "oThresholdLabel" text */
/*****************************************/
void ConvertRoadTestDataDialog::changeUnitOpt( const QString & stmp)
{
QString s_tmp;
s_tmp = QString("Threshold") + " (" + stmp + ")";
//added by Liu Tao, 050310
QString text_old = oThresholdLabel->text();
int base_old, base_new;
if( text_old == "Threshold (dBm)" ) base_old = 0;
else if( text_old == "Threshold (dBuV_107)" ) base_old = 107;
else base_old = 113;
oThresholdLabel->setText(s_tmp);
if( s_tmp == "Threshold (dBm)" ) base_new = 0;
else if( s_tmp == "Threshold (dBuV_107)" ) base_new = 107;
else base_new = 113;
int change = base_new - base_old;
int newThreshold = oThresholdSpinBox->value() + change ;
oThresholdSpinBox->setValue( newThreshold );
}
/****************************************/
/* slot for enabling OK button */
/* */
/****************************************/
void ConvertRoadTestDataDialog::updateOkEnabled(bool bYes)
{
if ( bYes ){
getInput();
if ( validInput() )
okPushButton->setEnabled(true);
}
else
okPushButton->setEnabled(false);
}
#undef CGDEBUG