-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcvg_part_wizard.cpp
577 lines (454 loc) · 15.5 KB
/
cvg_part_wizard.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
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
/**********************************************************/
/* cvg_part_wizard.cpp file implements choosing part/all */
/* cells to do simulation */
/**********************************************************/
#include "cvg_part_wizard.h"
#include <q3buttongroup.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <q3listbox.h>
#include <qmessagebox.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qstringlist.h>
#include <qtoolbutton.h>
#include <qtooltip.h>
#include <qvalidator.h>
#include <qvariant.h>
#include <q3whatsthis.h>
#include <qwidget.h>
//Added by qt3to4:
#include <Q3HBoxLayout>
#include <Q3VBoxLayout>
#include "gconst.h"
#include "cconst.h"
#include "wisim.h"
#include "wisim_gui.h"
#include "list.h"
#include <q3valuelist.h>
#define Debug 0
Cvg_Part_Wizard::Cvg_Part_Wizard( FigureEditor* editor_para, NetworkClass* np_param, QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
: Q3Wizard( parent, name, modal, fl )
{
editor = editor_para;
np = np_param;
setModal(true);
if ( !name )
setName( "Cvg_Part_Wizard" );
chooseWizardPage = new QWidget( this, "chooseWizardPage" );
Q3VBoxLayout *vlayout = new Q3VBoxLayout( chooseWizardPage, 11, 6);
buttonGroup1 = new Q3ButtonGroup( chooseWizardPage, "buttonGroup1" );
buttonGroup1->setGeometry( QRect( 40, 20, 370, 210 ) );
vlayout->addWidget( buttonGroup1 );
chooseAll = new QRadioButton( buttonGroup1, "chooseAll" );
chooseAll->setGeometry( QRect( 20, 40, 71, 21 ) );
chooseAll->setChecked( TRUE );
choosePartBtn = new QRadioButton( buttonGroup1, "choosePartBtn" );
choosePartBtn->setEnabled( TRUE );
choosePartBtn->setGeometry( QRect( 20, 80, 96, 21 ) );
QWidget* privateLayoutWidget = new QWidget( buttonGroup1, "layout6" );
privateLayoutWidget->setGeometry( QRect( 60, 140, 260, 40 ) );
layout6 = new Q3HBoxLayout( privateLayoutWidget, 11, 6, "layout6");
textLabel1 = new QLabel( privateLayoutWidget, "textLabel1" );
layout6->addWidget( textLabel1 );
spacer1 = new QSpacerItem( 30, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
layout6->addItem( spacer1 );
maxDist = new QLineEdit( privateLayoutWidget, "maxDist" );
layout6->addWidget( maxDist );
useGPMCheckBox = new QCheckBox(tr("Use Global Propagation Models"), chooseWizardPage);
useGPMCheckBox->setChecked( TRUE );
vlayout->addWidget( useGPMCheckBox );
addPage( chooseWizardPage, QString("") );
partWizardPage = new QWidget( this, "partWizardPage" );
textLabel1_2 = new QLabel( partWizardPage, "textLabel1_2" );
textLabel1_2->setGeometry( QRect( 63, 31, 60, 25 ) );
DeleteToolBtn = new QToolButton( partWizardPage, "DeleteToolBtn" );
DeleteToolBtn->setGeometry( QRect( 196, 237, 48, 42 ) );
DeleteToolBtn->setEnabled ( false );
Category_comboBox = new QComboBox( FALSE, partWizardPage, "Category_comboBox" );
Category_comboBox->setGeometry( QRect( 210, 30, 141, 23 ) );
ChooseToolBtn = new QToolButton( partWizardPage, "ChooseToolBtn" );
ChooseToolBtn->setGeometry( QRect( 196, 132, 48, 42 ) );
Source_listBox = new Q3ListBox( partWizardPage, "Source_listBox" );
Source_listBox->setGeometry( QRect( 30, 90, 140, 240 ) );
Source_listBox->setSelectionMode( Q3ListBox::Extended);
Dest_listBox = new Q3ListBox( partWizardPage, "Dest_listBox" );
Dest_listBox->setGeometry( QRect( 280, 90, 140, 240 ) );
Dest_listBox->setSelectionMode( Q3ListBox::Extended );
addPage( partWizardPage, QString("") );
languageChange();
resize( QSize(442, 440).expandedTo(minimumSizeHint()) ); // (442, 363)
// signals and slots connections
connect( buttonGroup1, SIGNAL( clicked(int) ), this, SLOT( checkToJump(int) ) );
connect( Category_comboBox, SIGNAL( activated(const QString&) ), this, SLOT( changeOptions(const QString&) ) );
connect( ChooseToolBtn, SIGNAL( clicked() ), this, SLOT( selectCells() ) );
connect( DeleteToolBtn, SIGNAL( clicked() ), this, SLOT( deleteCells() ) );
connect( Dest_listBox, SIGNAL( selectionChanged()), this, SLOT( setBtnEnable() ) );
connect( maxDist, SIGNAL( textChanged(const QString&) ), this, SLOT( changeDistValue(const QString&) ) );
// tab order
setTabOrder( Category_comboBox, Source_listBox );
setTabOrder( Source_listBox, Dest_listBox );
setTabOrder( Dest_listBox, chooseAll );
setTabOrder( chooseAll, maxDist );
init();
}
/*
* Destroys the object and frees any allocated resources
*/
Cvg_Part_Wizard::~Cvg_Part_Wizard()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Cvg_Part_Wizard::languageChange()
{
setCaption( tr( "Part_or_All" ) );
buttonGroup1->setTitle( tr( "Scope Choice" ) );
chooseAll->setText( tr( "All Cells" ) );
choosePartBtn->setText( tr( "Cell Group" ) );
textLabel1->setText( tr( "Max. Distance :" ) );
maxDist->setInputMask( QString::null );
setTitle( chooseWizardPage, tr( "Choose single or multiple cells" ) );
textLabel1_2->setText( tr("Show Cells By") + ": " );
DeleteToolBtn->setText( "..." );
Category_comboBox->clear();
Category_comboBox->insertItem( tr( "Cell Index" ) );
Category_comboBox->insertItem( tr( "GW_CSC_CS" ) );
Category_comboBox->insertItem( tr( "CSID" ) );
ChooseToolBtn->setText( "..." );
setTitle( partWizardPage, tr( "Choose cells" ) );
//setTitle( WizardPage, tr( "Page_3" ) );
DeleteToolBtn->setText("<==");
ChooseToolBtn->setText("==>");
backButton()->setText(tr("&Back") + " <");
nextButton()->setText(tr("&Next") + " >");
finishButton()->setText(tr("&Finish"));
cancelButton()->setText(tr("&Cancel"));
helpButton()->setText(tr("&Help"));
}
void Cvg_Part_Wizard::checkToJump(int i)
{
if (Debug == 1)
qDebug( "the radiobutton's output = %d", i);
if ( i == 0 ) {
m_bIsPart = false;
setAppropriate(partWizardPage, false);
maxDist->setEnabled(false);
}
if ( i == 1) {
m_bIsPart = true;
setAppropriate(partWizardPage, true);
maxDist->setEnabled(true);
}
}
void Cvg_Part_Wizard::init()
{
setHelpEnabled( chooseWizardPage, FALSE );
setHelpEnabled( partWizardPage, FALSE );
m_CellList = new QStringList();
if (!m_CellList->isEmpty() )
m_CellList->clear();
maxDist->setValidator( new QDoubleValidator( maxDist ) );
// when m_bIsPart = true, m_dMaxlength is valid
// added on Dec. 3, 2003 for right-click
if(editor->select_cell_list->getSize() == 0) {
m_bIsPart = false; // default to choose all
chooseAll->setChecked( TRUE );
choosePartBtn->setChecked( FALSE );
maxDist->setEnabled(false);
}
else {
choosePartBtn->setChecked( TRUE );
maxDist->setEnabled(true);
chooseAll->setChecked( FALSE );
m_bIsPart = true;
setAppropriate(partWizardPage, true);
setFinishEnabled(partWizardPage, true);
}
// initial the ListBox -- source Listbox
// modified on Dec. 3, 2004
//if ( editor->select_cell_list->getSize() == 0) {
int cell_idx, name_pref = -1;
CellClass *cell1;
QString s;
Source_listBox->clear();
name_pref = CConst::CellIdxRef;
for (cell_idx=0; cell_idx<=np->num_cell-1; cell_idx++) {
cell1 = np->cell_list[cell_idx];
s = QString("%1").arg(cell1->view_name(cell_idx, name_pref));
// added on Nov. 23, 2004
// modified on Dec. 3, 2004 for right-click function
if (editor->select_cell_list->contains( cell_idx )) {
m_CellList->append(s);
m_Map[s] = 1;
}
else {
m_osList.append(s);
m_Map[s] = -1;
}
m_oMapIndex[s] = cell_idx;
}
Source_listBox->insertStringList(m_osList);
Dest_listBox->insertStringList(*m_CellList);
}
void Cvg_Part_Wizard::changeOptions( const QString & )
{
enum userInput {
CSID,
CS_Number,
CS_Index
};
QString sDispName;
QStringList source, dest;
source = m_osList;
dest = *m_CellList;
int cell_idx, name_pref = -1;
CellClass *cell;
Source_listBox->clear();
m_osList.clear();
m_CellList->clear();
m_CellVector.clear();
Dest_listBox->clear();
switch ( Category_comboBox->currentItem() ) {
case CSID:
name_pref = CConst::CellIdxRef;
break;
case CS_Number:
name_pref = CConst::CellCSNumberRef;
break;
case CS_Index:
name_pref = CConst::CellHexCSIDRef;
break;
}
/*
// init. the source listbox and the map
for (cell_idx=0; cell_idx<=np->num_cell-1; cell_idx++) {
cell = np->cell_list[cell_idx];
sDispName = QString("%1\n").arg(cell->view_name(cell_idx, name_pref));
m_osList.append(sDispName);
m_Map[sDispName] = -1;
m_oMapIndex[sDispName] = cell_idx;
}
*/
int idx;
QStringList::Iterator it;
// change the strings in destination listbox
for ( it = dest.begin(); it != dest.end(); ++it ) {
idx = m_oMapIndex[*it];
cell = np->cell_list[idx];
sDispName = QString("%1").arg(cell->view_name(idx, name_pref));
m_Map.remove(*it);
m_Map.insert( sDispName, 1);
m_CellList->append(sDispName);
}
// change the strings in source listbox
for ( it = source.begin(); it != source.end(); ++it ) {
idx = m_oMapIndex[*it];
cell = np->cell_list[idx];
sDispName = QString("%1").arg(cell->view_name(idx, name_pref));
m_Map.remove(*it);
m_Map.insert( sDispName, -1);
m_osList.append(sDispName);
}
// change the m_oMapIndex contents
m_oMapIndex.clear();
for (cell_idx=0; cell_idx<=np->num_cell-1; cell_idx++) {
cell = np->cell_list[cell_idx];
sDispName = QString("%1").arg(cell->view_name(cell_idx, name_pref));
m_oMapIndex[sDispName] = cell_idx;
}
printf("change --------------\n");
CellIndexMap::Iterator itt;
for ( itt = m_oMapIndex.begin(); itt != m_oMapIndex.end(); ++itt ) {
printf("%s %d\n", itt.key().latin1(), itt.data());
}
for ( itt = m_Map.begin(); itt != m_Map.end(); ++itt ) {
printf("%s %d\n", itt.key().latin1(), itt.data());
}
Source_listBox->insertStringList(m_osList);
Dest_listBox->insertStringList(*m_CellList);
}
void Cvg_Part_Wizard::selectCells()
{
Q3ListBoxItem *item;
// Go through all items of the first ListBox
for ( unsigned int i = 0; i < Source_listBox->count(); i++ ) {
if ( Source_listBox->isSelected(i) ) {
item = Source_listBox->item( i );
Dest_listBox->insertItem(item->text(), -1);
//m_CellVector.push_back(i); // for cmd
m_CellList->append(item->text()); // for display
// added on Nov. 22
m_Map[item->text()] = 1;
}
}
Source_listBox->clearSelection();
setFinishEnabled(partWizardPage, true);
if (Debug == 1) {
//for( unsigned int k = 0; k < m_CellVector.size(); k++)
// printf("the index = %d\n", m_CellVector[k]);
qDebug(m_CellList->join("#"));
}
// added on Nov. 22, 2004
for ( QStringList::Iterator it = m_CellList->begin(); it != m_CellList->end(); ++it ) {
//printf("the target = %s\n", (*it).latin1());
item = Source_listBox->findItem((*it).latin1(), Q3ListBox::ExactMatch);
if( item > 0) {
m_osList.remove(item->text());
//printf("find the one to match = %s\n", (item->text()).latin1());
//Source_listBox->takeItem(item);
delete(item);
}
//else
// qDebug("can't find the string");
}
Source_listBox->clear();
Source_listBox->insertStringList(m_osList);
}
void Cvg_Part_Wizard::deleteCells()
{
// Go through all items of the destination ListBox
QStringList finalList;
//printf("the size = %d\n", Dest_listBox->count());
for ( unsigned int i = 0; i < Dest_listBox->count(); i++ ) {
Q3ListBoxItem *item = Dest_listBox->item( i );
// if the item is selected...
if ( item->isSelected() ) {
m_Map[item->text()] = -1;
//printf("delete %s", item->text().latin1());
m_CellList->remove(item->text());
m_osList.append(item->text());
}
else {
finalList.append(item->text());
}
}
Dest_listBox->clear();
if (Debug == 1) {
qDebug(finalList.join(": "));
qDebug(m_CellList->join("*"));
}
Dest_listBox->insertStringList(finalList);
Source_listBox->clear();
// sort the m_osList and displayed in Source_listBox
sortStringList(m_osList);
Source_listBox->insertStringList(m_osList);
if (Dest_listBox->count() == 0)
setFinishEnabled(partWizardPage, false);
}
void Cvg_Part_Wizard::next() {
if (!m_bIsPart) { // all
Q3Wizard::accept();
emit chooseAllSig();
}
else { // part
if ( maxDist->text().isEmpty () ) {
QMessageBox::warning( this, "Validation of the user's input",
QString( "Please input max. distance value!\n"),
"&OK", QString::null, 0,1 );
}
else {
Q3Wizard::next ();
}
}
}
void Cvg_Part_Wizard::accept() {
/*
if ( m_bIsPart) {
//m_CellVector = m_Map.values();
if (m_CellVector.size() == 0)
QMessageBox::warning( this, "Validation of the user's input",
QString( "Please choose the research cell!\n"),
"&OK", QString::null, 0,1 );
}
else
*/
Q3Wizard::accept();
}
void Cvg_Part_Wizard::changeDistValue(const QString& text)
{
QString t = text;
m_dMaxDistance = text.toDouble();
if (Debug == 1)
qDebug("the max length = %f\n", m_dMaxDistance);
}
void Cvg_Part_Wizard::setBtnEnable() {
DeleteToolBtn->setEnabled ( true );
}
/***********************************************************/
/* Logical functions. */
/***********************************************************/
bool Cvg_Part_Wizard::getChoice() {
return m_bIsPart;
}
QStringList& Cvg_Part_Wizard::getPartCellList() {
return (*m_CellList);
}
Q3ValueVector <int>& Cvg_Part_Wizard::getPartCellVector() {
int kk;
CellIndexMap::Iterator itt;
for ( itt = m_Map.begin(); itt != m_Map.end(); ++itt ) {
//printf( "%s, %d\n", itt.key().latin1(),itt.data());
if( itt.data() == 1) {
kk = (m_oMapIndex.find(itt.key())).data();
m_CellVector.push_back(kk);
}
}
/*
// qDebug(oCellIndexList);
QValueVector<int> ::iterator it;
QString ss;
for( it = m_CellVector.begin(); it != m_CellVector.end(); ++it ) {
ss = QString("the value of index = %1 \n").arg((*it));
qDebug(ss);
}
*/
return m_CellVector;
}
double Cvg_Part_Wizard::getMaxDist() {
return m_dMaxDistance;
}
//---------------------------------------------------
// added on Nov. 23, 2004
// Descprition:
// sort a QStringList in ascending sequence,
// but not dictionary.
//---------------------------------------------------
void Cvg_Part_Wizard::sortStringList(QStringList &sl)
{
QString s0, s2;
QStringList sList;
bool bFound = false;
s0 = sl.join("*");
sList = QStringList::split("*", s0);
//qDebug(sList.join("#"));
sl.clear();
for ( QStringList::Iterator it = sList.begin(); it != sList.end(); ++it ) {
s0 = (*it);
if ( sl.isEmpty() )
sl.append(s0);
else {
for ( QStringList::Iterator itt = sl.begin(); itt != sl.end(); ++itt ) {
s2 = (*itt);
if (!s2.isEmpty() || !s2.isNull() ) {
//printf("the compared s0 = %s, s2 = %s", s0.latin1(), s2.latin1());
if ( qstringcmp(s0, s2) < 0) {
bFound = true;
sl.insert(itt, s0);
break;
}
} // end if
} // end for
if( ! bFound)
sl.append(s0);
}
} // end for
}