QvisExpressionsWindow.C 25.1 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
#include <QvisExpressionsWindow.h>
hrchilds's avatar
hrchilds committed
2

hrchilds's avatar
hrchilds committed
3
4
#include <Expression.h>
#include <ExpressionList.h>
hrchilds's avatar
hrchilds committed
5
6
#include <ViewerProxy.h>

hrchilds's avatar
hrchilds committed
7
8
9
10
11
12
13
14
#include <qapplication.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlistbox.h>
hrchilds's avatar
hrchilds committed
15
16
#include <qmultilineedit.h>
#include <qpopupmenu.h>
hrchilds's avatar
hrchilds committed
17
#include <qpushbutton.h>
hrchilds's avatar
hrchilds committed
18
#include <qsplitter.h>
hrchilds's avatar
hrchilds committed
19

hrchilds's avatar
hrchilds committed
20
#include <QNarrowLineEdit.h>
hrchilds's avatar
hrchilds committed
21
#include <QvisVariableButton.h>
hrchilds's avatar
hrchilds committed
22

hrchilds's avatar
hrchilds committed
23
24
25
#define STDMIN(A,B) (((A)<(B)) ? (A) : (B))
#define STDMAX(A,B) (((A)<(B)) ? (B) : (A))

hrchilds's avatar
hrchilds committed
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
// ****************************************************************************
//  Expression Lists
//
//  Purpose:
//    Categorized expression lists data.  These structures are self-contained
//    and require the terminating nulls to be parsed correctly.  Keep in mind
//    that 
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 23, 2004
//
// ****************************************************************************
struct ExprNameList
{
    const char *name;
    const char **list;
};

const char *expr_meshquality[] = {
    "aspect",
    "aspect_gamma",
    "condition",
    "degree",
    "diagonal",
    "dimension",
    "jacobian",
    "largest_angle",
    "neighbor",
    "node_degree",
    "oddy",
    "relative_size",
    "scaled_jacobian",
    "shape",
    "shape_and_size",
    "shear",
    "skew",
    "smallest_angle",
    "stretch",
    "taper",
    "warpage",
    NULL
};

const char *expr_math[] = {
    "abs",
    "ln",
    "log10",
    "sqr",
    "sqrt",
    "+",
    "-",
    "*",
    "/",
    "^",
    NULL
};

const char *expr_comparison[] = {
    "eq",
    "ge",
    "gt",
    "le",
    "lt",
    "ne",
    NULL
};

const char *expr_conditional[] = {
    "if",
    NULL
};

const char *expr_logical[] = {
    "and",
    "not",
    "or",
    NULL
};

const char *expr_trig[] = {
    "acos",
    "asin",
    "atan",
    "cos",
    "deg2rad",
    "rad2deg",
    "sin",
    "tan",
    NULL
};

const char *expr_vector[] = {
    "cross",
    "dot",
    "magnitude",
    NULL
};

const char *expr_tensor[] = {
    "determinant",
    "effective_tensor",
    "eigenvalue",
    "eigenvector",
    "inverse",
    "principal_deviatoric_tensor",
    "principal_tensor",
    "tensor_maximum_shear",
    "trace",
    NULL
};

const char *expr_materials[] = {
    "matvf",
    "nmats",
    "specmf",
    NULL
};

const char *expr_mesh[] = {
    "area",
    "coord",
    "polar",
    "revolved_surface_area",
    "revolved_volume",
    "volume",
    NULL
};

const char *expr_misc[] = {
    "gradient",
    "recenter",
    NULL
};

ExprNameList exprlist[] =
{
    {"Math",          expr_math},
    {"Vector",        expr_vector},
    {"Tensor",        expr_tensor},
    {"Material",      expr_materials},
    {"Mesh",          expr_mesh},
    {"Mesh Quality",  expr_meshquality},
    {"Miscellaneous", expr_misc},
    {"Trigonometry",  expr_trig},
    {"Comparison",    expr_comparison},
    {"Conditional",   expr_conditional},
    {"Logical",       expr_logical},
    {NULL,NULL}
hrchilds's avatar
hrchilds committed
174
175
};

hrchilds's avatar
hrchilds committed
176
177
178
179
180
181
182
183
184
185
// ****************************************************************************
// Method: QvisExpressionsWindow::QvisExpressionsWindow
//
// Purpose: 
//   This is the constructor for the QvisExpressionsWindow class.
//
// Arguments:
//   exprList_  The ExpressionList subject to observe
//   
//
hrchilds's avatar
hrchilds committed
186
187
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//
// ****************************************************************************
QvisExpressionsWindow::QvisExpressionsWindow(
    ExpressionList *exprList_, const char *caption,
    const char *shortName, QvisNotepadArea *notepad) :
    QvisPostableWindowObserver(exprList_, caption, shortName, notepad,
                               QvisPostableWindowObserver::ApplyButton,
                               false)
{
    exprList = exprList_;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::~QvisExpressionsWindow
//
// Purpose: 
//   Destructor for the QvisExpressionsWindow class.
//
hrchilds's avatar
hrchilds committed
206
207
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//
// Modifications:
//   
// ****************************************************************************
QvisExpressionsWindow::~QvisExpressionsWindow()
{
    exprList = NULL;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
hrchilds's avatar
hrchilds committed
223
224
225
226
227
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Note: as of writing, unsure if I want to use the splitter or not.
//       We should pick one of the two methods eventually.
hrchilds's avatar
hrchilds committed
228
229
//
// Modifications:
hrchilds's avatar
hrchilds committed
230
231
232
233
234
235
236
237
//    Jeremy Meredith, Sat Oct 23 11:50:35 PDT 2004
//    Changed the layout a bit: use group boxes with titles for the two
//    panes, change to use splitters, change the resize proportions,
//    move the "hidden" toggle to the bottom and change its sense,
//    move "insert function" to the right side and group expressions into
//    categorized submenus, reword some other labels to make them more
//    descriptive.
//
hrchilds's avatar
hrchilds committed
238
239
240
//    Brad Whitlock, Thu Dec 9 10:50:12 PDT 2004
//    I added a variable button that lets us insert variables.
//
hrchilds's avatar
hrchilds committed
241
// ****************************************************************************
hrchilds's avatar
hrchilds committed
242

hrchilds's avatar
hrchilds committed
243
244
245
void
QvisExpressionsWindow::CreateWindowContents()
{
hrchilds's avatar
hrchilds committed
246
#define USE_SPLITTER
hrchilds's avatar
hrchilds committed
247
248
249
250
251
252
253
254
255
256
#ifndef USE_SPLITTER
    QHBoxLayout *mainLayout = new QHBoxLayout(topLayout, -1, "mainLayout");
#else
    QSplitter *mainSplitter = new QSplitter(central);
    topLayout->addWidget(mainSplitter);
    topLayout->setStretchFactor(mainSplitter, 100);
#endif

#ifndef USE_SPLITTER
    QGridLayout *listLayout = new QGridLayout(mainLayout, 3,2, 5, "listLayout");
hrchilds's avatar
hrchilds committed
257
    mainLayout->setStretchFactor(listLayout, 50);
hrchilds's avatar
hrchilds committed
258
259
#define f1 central
#else
hrchilds's avatar
hrchilds committed
260
261
    QGroupBox *f1 = new QGroupBox("Expression List",mainSplitter);
    QGridLayout *listLayout = new QGridLayout(f1, 4,2, 7, 5, "listLayout");
hrchilds's avatar
hrchilds committed
262
263
#endif

hrchilds's avatar
hrchilds committed
264
265
    listLayout->addRowSpacing(0, 10);

hrchilds's avatar
hrchilds committed
266
    exprListBox = new QListBox(f1);
hrchilds's avatar
hrchilds committed
267
    listLayout->addMultiCellWidget(exprListBox, 1,1, 0,1);
hrchilds's avatar
hrchilds committed
268
269

    newButton = new QPushButton("New", f1, "newButton");
hrchilds's avatar
hrchilds committed
270
    listLayout->addWidget(newButton, 2,0);
hrchilds's avatar
hrchilds committed
271

hrchilds's avatar
hrchilds committed
272
273
    delButton = new QPushButton("Delete", f1, "delButton");
    listLayout->addWidget(delButton, 2,1);
hrchilds's avatar
hrchilds committed
274

hrchilds's avatar
hrchilds committed
275
276
    displayAllVars = new QCheckBox("Display expressions from database", f1, "displayAllVars");
    listLayout->addMultiCellWidget(displayAllVars, 3,3, 0,1);
hrchilds's avatar
hrchilds committed
277
278
279
280

#ifndef USE_SPLITTER
    mainLayout->addSpacing(10);
    QGridLayout *editLayout = new QGridLayout(mainLayout, 6,2, 5, "editLayout");
hrchilds's avatar
hrchilds committed
281
    mainLayout->setStretchFactor(editLayout, 50);
hrchilds's avatar
hrchilds committed
282
283
#define f2 central
#else
hrchilds's avatar
hrchilds committed
284
285
    QGroupBox *f2 = new QGroupBox("Definition", mainSplitter);
    QGridLayout *editLayout = new QGridLayout(f2, 6,4, 7, 5, "editLayout");
hrchilds's avatar
hrchilds committed
286
287
288
#endif
    int row = 0;

hrchilds's avatar
hrchilds committed
289
290
291
    editLayout->addRowSpacing(row, 10);
    row++;

hrchilds's avatar
hrchilds committed
292
    nameEditLabel = new QLabel("Name", f2, "nameEditLabel");
hrchilds's avatar
hrchilds committed
293
294
295
    nameEdit = new QNarrowLineEdit(f2, "nameEdit");
    editLayout->addMultiCellWidget(nameEditLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(nameEdit, row,row, 1,3);
hrchilds's avatar
hrchilds committed
296
297
298
299
300
301
    row++;

    typeLabel = new QLabel("Type", f2, "typeLabel");
    typeList = new QComboBox(f2, "typeList");
    int numtypes = Expression::GetNumTypes();
    numtypes = 5;  // HACK!!!  Variable types after 5 currently fail.  FIXME!!!
hrchilds's avatar
hrchilds committed
302
303
    int i;
    for (i=1; i < numtypes ; i++)
hrchilds's avatar
hrchilds committed
304
        typeList->insertItem(Expression::GetTypeString((Expression::ExprType)i));
hrchilds's avatar
hrchilds committed
305
306
    editLayout->addMultiCellWidget(typeLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(typeList, row,row, 1,3);
hrchilds's avatar
hrchilds committed
307
308
309
310
311
312
313
314
315
    row++;

    definitionEditLabel = new QLabel("Definition", f2, "definitionEditLabel");
    editLayout->addWidget(definitionEditLabel, row, 0);
    row++;

    definitionEdit = new QMultiLineEdit(f2, "definitionEdit");
    definitionEdit->setWordWrap(QMultiLineEdit::WidgetWidth);
    definitionEdit->setWrapPolicy(QMultiLineEdit::AtWhiteSpace);
hrchilds's avatar
hrchilds committed
316
    editLayout->addMultiCellWidget(definitionEdit, row,row, 0,3);
hrchilds's avatar
hrchilds committed
317
318
    row++;

hrchilds's avatar
hrchilds committed
319
    notHidden = new QCheckBox("Show variable in plot menus", f2, "notHidden");
hrchilds's avatar
hrchilds committed
320
    editLayout->addWidget(notHidden, row, 0);
hrchilds's avatar
hrchilds committed
321

hrchilds's avatar
hrchilds committed
322
    insertFunctionButton = new QPushButton("Insert Function...", f2);
hrchilds's avatar
hrchilds committed
323
    insertFunctionMenu = new QPopupMenu(f2, "insertFunctionMenu");
hrchilds's avatar
hrchilds committed
324
    for (i=0; exprlist[i].name; i++)
hrchilds's avatar
hrchilds committed
325
326
327
328
329
330
331
332
333
334
    {
        QPopupMenu *tmpMenu = new QPopupMenu(f2, exprlist[i].name);
        for (int j=0; exprlist[i].list[j]; j++)
        {
            tmpMenu->insertItem(exprlist[i].list[j]);
        }
        insertFunctionMenu->insertItem(exprlist[i].name, tmpMenu);
        connect(tmpMenu, SIGNAL(activated(int)),
                this, SLOT(insertFunction(int)));
    }
hrchilds's avatar
hrchilds committed
335
    insertFunctionButton->setPopup(insertFunctionMenu);
hrchilds's avatar
hrchilds committed
336
337
338
339
340
341
342
343
344
345
346
    editLayout->addWidget(insertFunctionButton, row, 2);

    // Create a variable button so we can insert variables for the
    // active source.
    insertVariableButton = new QvisVariableButton(false, false, false, -1, f2,
        "insertVariableButton");
    insertVariableButton->setChangeTextOnVariableChange(false);
    insertVariableButton->setText("Insert Variable...");
    connect(insertVariableButton, SIGNAL(activated(const QString &)),
            this, SLOT(insertVariable(const QString &)));
    editLayout->addWidget(insertVariableButton, row, 3);
hrchilds's avatar
hrchilds committed
347
    row++;
hrchilds's avatar
hrchilds committed
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

    // connect signals

    connect(exprListBox, SIGNAL(selectionChanged()),
            this, SLOT(UpdateWindowSingleItem()));
    connect(nameEdit, SIGNAL(textChanged(const QString&)),
            this, SLOT(nameTextChanged(const QString&)));
    connect(definitionEdit, SIGNAL(textChanged()),
            this, SLOT(definitionTextChanged()));
    connect(newButton, SIGNAL(pressed()),
            this, SLOT(addExpression()));
    connect(delButton, SIGNAL(pressed()),
            this, SLOT(delExpression()));
    connect(typeList, SIGNAL(activated(int)),
            this, SLOT(typeChanged(int)));
hrchilds's avatar
hrchilds committed
363
364
    connect(notHidden, SIGNAL(clicked()),
            this, SLOT(notHiddenChanged()));
hrchilds's avatar
hrchilds committed
365
366
    connect(displayAllVars, SIGNAL(clicked()),
            this, SLOT(displayAllVarsChanged()));
hrchilds's avatar
hrchilds committed
367
368
369
370
371
372
373
374
375
376
377
378
}

// ****************************************************************************
// Method: QvisExpressionsWindow::UpdateWindow
//
// Purpose: 
//   This method is called when the window's subject is changed. The
//   subject tells this window what attributes changed and we put the
//   new values into those widgets.
//
// Arguments:
//   doAll : If this flag is true, update all the widgets regardless
hrchilds's avatar
hrchilds committed
379
//           of whether or not they are selected.  Currently ignored.
hrchilds's avatar
hrchilds committed
380
//
hrchilds's avatar
hrchilds committed
381
382
383
384
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
385
386
387
388
//    Jeremy Meredith, Mon Oct 25 12:52:45 PDT 2004
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.  Keep in mind we need
//    a map from the list-position index to expressionlist index.
hrchilds's avatar
hrchilds committed
389
//
hrchilds's avatar
hrchilds committed
390
391
392
393
394
395
396
// ****************************************************************************
void
QvisExpressionsWindow::UpdateWindow(bool)
{
    BlockAllSignals(true);

    exprListBox->clear();
hrchilds's avatar
hrchilds committed
397
398
    indexMap.clear();
    int pos = 0;
hrchilds's avatar
hrchilds committed
399
400
401
402
403
    for (int i=0; i<exprList->GetNumExpressions(); i++)
    {
        if (displayAllVars->isChecked() ||
            !exprList->GetExpression(i).GetFromDB())
        {
hrchilds's avatar
hrchilds committed
404
            exprListBox->insertItem(exprList->GetExpression(i).GetName().c_str());
hrchilds's avatar
hrchilds committed
405
            indexMap[pos++] = i;
hrchilds's avatar
hrchilds committed
406
407
408
409
410
411
412
413
414
        }
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSingleItem
hrchilds's avatar
hrchilds committed
415
//
hrchilds's avatar
hrchilds committed
416
417
//  Purpose:
//    Update the pane of the window where a single expression is being edited.
hrchilds's avatar
hrchilds committed
418
//
hrchilds's avatar
hrchilds committed
419
420
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
hrchilds's avatar
hrchilds committed
421
//
hrchilds's avatar
hrchilds committed
422
423
424
425
426
427
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 11:34:35 PDT 2004
//    Reversed the sense of the "hidden" button.
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
428
429
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
430
QvisExpressionsWindow::UpdateWindowSingleItem()
hrchilds's avatar
hrchilds committed
431
{
hrchilds's avatar
hrchilds committed
432
433
434
    BlockAllSignals(true);
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
435
    if (index <  0)
hrchilds's avatar
hrchilds committed
436
437
    {
        nameEdit->setText("");
hrchilds's avatar
hrchilds committed
438
        notHidden->setChecked(true);
hrchilds's avatar
hrchilds committed
439
440
441
        definitionEdit->setText("");
    }
    else
hrchilds's avatar
hrchilds committed
442
    {
hrchilds's avatar
hrchilds committed
443
444
        Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
445
        nameEdit->setText(e.GetName().c_str());
hrchilds's avatar
hrchilds committed
446
447
        notHidden->setChecked(! e.GetHidden());
        typeList->setCurrentText(Expression::GetTypeString(e.GetType()));
hrchilds's avatar
hrchilds committed
448
        definitionEdit->setText(e.GetDefinition().c_str());
hrchilds's avatar
hrchilds committed
449
    }
hrchilds's avatar
hrchilds committed
450
451
452
453
    
    UpdateWindowSensitivity();
    BlockAllSignals(false);
}
hrchilds's avatar
hrchilds committed
454

hrchilds's avatar
hrchilds committed
455
456
457
458
459
460
461
462
463
// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSensitivity
//
//  Purpose:
//    Update the sensitivity of any widget needing it.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
464
465
466
467
468
469
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 11:34:35 PDT 2004
//    Reversed the sense of the "hidden" button.
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
470
471
472
//    Brad Whitlock, Thu Dec 9 14:04:22 PST 2004
//    Added a button to insert variable names.
//
hrchilds's avatar
hrchilds committed
473
// ****************************************************************************
hrchilds's avatar
hrchilds committed
474

hrchilds's avatar
hrchilds committed
475
476
477
478
void
QvisExpressionsWindow::UpdateWindowSensitivity()
{
    bool enable = true;
hrchilds's avatar
hrchilds committed
479
480
481
    int index = exprListBox->currentItem();

    if (index <  0)
hrchilds's avatar
hrchilds committed
482
    {
hrchilds's avatar
hrchilds committed
483
484
        enable = false;
    }
hrchilds's avatar
hrchilds committed
485
    else if ((*exprList)[indexMap[index]].GetFromDB())
hrchilds's avatar
hrchilds committed
486
487
    {
        enable = false;
hrchilds's avatar
hrchilds committed
488
489
    }

hrchilds's avatar
hrchilds committed
490
491
    nameEdit->setEnabled(enable);
    delButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
492
    notHidden->setEnabled(enable);
hrchilds's avatar
hrchilds committed
493
494
495
    typeList->setEnabled(enable);
    definitionEdit->setEnabled(enable);
    insertFunctionButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
496
    insertVariableButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::BlockAllSignals
//
//  Purpose:
//    Block signals for all important widgets.  Or unblock, of course.
//
//  Arguments:
//    block      true to block, false to unblock
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
// ****************************************************************************
void
QvisExpressionsWindow::BlockAllSignals(bool block)
{
    exprListBox->blockSignals(block);
    nameEdit->blockSignals(block);
    definitionEdit->blockSignals(block);
hrchilds's avatar
hrchilds committed
518
519
520
521
522
523
524
525
}

// ****************************************************************************
// Method: QvisExpressionsWindow::Apply
//
// Purpose: 
//   This is a Qt slot function that is called when the Apply button is clicked.
//
hrchilds's avatar
hrchilds committed
526
527
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::Apply(bool forceUpdate)
{
    exprList->Notify();

    if (AutoUpdate() || forceUpdate)
        viewer->ProcessExpressions();
}

// ****************************************************************************
// Method: QvisExpressionsWindow::apply
//
// Purpose: 
//   This is a Qt slot function that is called when the window's Apply
//   button is clicked.
//
hrchilds's avatar
hrchilds committed
548
549
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
550
551
552
553
554
555
556
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::apply()
{
hrchilds's avatar
hrchilds committed
557
558
559
560
561
    // Apply will recreate the window and unselect the current expression.
    // If we have an expression selected, reselect it afterwards.
    int reselect = (exprListBox->currentItem() != -1);
    QString item = exprListBox->currentText();

hrchilds's avatar
hrchilds committed
562
    Apply(true);
hrchilds's avatar
hrchilds committed
563
564
565
566
567
568
569
570
571

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
572
573
574
575
576
577
578
579
}

// ****************************************************************************
// Method: QvisExpressionsWindow::addExpression
//
// Purpose: 
//   This is a Qt slot function that adds a new expression that is empty.
//
hrchilds's avatar
hrchilds committed
580
581
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
582
583
//
// Modifications:
hrchilds's avatar
hrchilds committed
584
585
586
//    Jeremy Meredith, Mon Oct 25 12:39:53 PDT 2004
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
hrchilds's avatar
hrchilds committed
587
588
589
590
591
//   
// ****************************************************************************
void
QvisExpressionsWindow::addExpression()
{
hrchilds's avatar
hrchilds committed
592
593
594
595
596
597
598
599
600
601
602
603
    // Find an unused expression name
    int newid = 1;
    bool okay = false;
    QString newName;
    while (!okay)
    {
        newName.sprintf("unnamed%d", newid);
        if ((*exprList)[newName.latin1()])
            newid++;
        else
            okay = true;
    }
hrchilds's avatar
hrchilds committed
604

hrchilds's avatar
hrchilds committed
605
606
607
608
    Expression e;
    e.SetName(newName.latin1());
    e.SetDefinition("");
    exprList->AddExpression(e);
hrchilds's avatar
hrchilds committed
609
610

    exprList->Notify();
hrchilds's avatar
hrchilds committed
611
612
613
614
615
616

    for (int i=0; i<exprListBox->count(); i++)
    {
        if (exprListBox->text(i) == newName)
            exprListBox->setSelected(i, true);
    }
hrchilds's avatar
hrchilds committed
617
618
619
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
620
// Method: QvisExpressionsWindow::delExpression
hrchilds's avatar
hrchilds committed
621
622
623
624
//
// Purpose: 
//   This is a Qt slot function that is called to delete an expression.
//
hrchilds's avatar
hrchilds committed
625
626
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
627
628
629
630
631
//
// Modifications:
//   
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
632
QvisExpressionsWindow::delExpression()
hrchilds's avatar
hrchilds committed
633
{
hrchilds's avatar
hrchilds committed
634
635
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
636
    if (index <  0)
hrchilds's avatar
hrchilds committed
637
638
        return;

hrchilds's avatar
hrchilds committed
639
    exprList->RemoveExpression(index);
hrchilds's avatar
hrchilds committed
640
641
642

    exprList->Notify();
}
hrchilds's avatar
hrchilds committed
643
644
645
646
647
648
649
650
651
652
653

// ****************************************************************************
//  Method:  QvisExpressionsWindow::definitionTextChanged
//
//  Purpose:
//    Slot function when definition text is changed.  This is called for
//    any change to the definition text.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
654
655
656
657
658
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 12:40:01 PDT 2004
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
659
660
661
662
663
664
// ****************************************************************************
void
QvisExpressionsWindow::definitionTextChanged()
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
665
    if (index <  0)
hrchilds's avatar
hrchilds committed
666
667
        return;

hrchilds's avatar
hrchilds committed
668
669
    Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
670
    e.SetDefinition(definitionEdit->text().latin1());
hrchilds's avatar
hrchilds committed
671
672
673
674
675
676
677
678
679
680
681
682
683
684
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::nameTextChanged
//
//  Purpose:
//    Slot function when any change happens to the expression names.
//
//  Arguments:
//    text       the new text.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
685
686
687
688
689
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 12:40:31 PDT 2004
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
690
691
692
693
694
695
// ****************************************************************************
void
QvisExpressionsWindow::nameTextChanged(const QString &text)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
696
    if (index <  0)
hrchilds's avatar
hrchilds committed
697
698
        return;

hrchilds's avatar
hrchilds committed
699
700
    Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
701
    QString newname = text.stripWhiteSpace();
hrchilds's avatar
hrchilds committed
702
    e.SetName(newname.latin1());
hrchilds's avatar
hrchilds committed
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
    BlockAllSignals(true);
    exprListBox->changeItem(newname, index);
    BlockAllSignals(false);
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::typeChanged
//
//  Purpose:
//    Slot function for the "type" combo box.  Sets the expression type.
//
//  Arguments:
//    value      the new type
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
720
721
722
723
724
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 12:40:37 PDT 2004
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
725
726
727
728
729
730
// ****************************************************************************
void
QvisExpressionsWindow::typeChanged(int value)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
731
    if (index <  0)
hrchilds's avatar
hrchilds committed
732
733
        return;

hrchilds's avatar
hrchilds committed
734
735
    Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
736
737
    // Add one because we skipped index 0 (unknown) when creating the
    // list box originally
hrchilds's avatar
hrchilds committed
738
    e.SetType(Expression::ExprType(value+1));
hrchilds's avatar
hrchilds committed
739
740
741
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
742
//  Method:  QvisExpressionsWindow::notHiddenChanged
hrchilds's avatar
hrchilds committed
743
744
//
//  Purpose:
hrchilds's avatar
hrchilds committed
745
746
//    Slot function for the notHidden toggle.
//    Sets the "notHidden" flag of an expression.
hrchilds's avatar
hrchilds committed
747
748
749
750
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
751
752
753
754
755
756
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 11:34:35 PDT 2004
//    Reversed the sense of the "hidden" button.
//    Always access the expression list by index, just in case there
//    are two expressions with the same name.
//
hrchilds's avatar
hrchilds committed
757
758
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
759
QvisExpressionsWindow::notHiddenChanged()
hrchilds's avatar
hrchilds committed
760
761
762
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
763
    if (index <  0)
hrchilds's avatar
hrchilds committed
764
765
        return;

hrchilds's avatar
hrchilds committed
766
767
768
    Expression &e = (*exprList)[indexMap[index]];

    e.SetHidden(!notHidden->isChecked());
hrchilds's avatar
hrchilds committed
769
770
771
772
773
774
775
776
777
778
779
780
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::displayAllVarsChanged
//
//  Purpose:
//    Slot function, called when "display all variables" is toggled.
//    Just update the window because it will be taken care of.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
781
782
783
784
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 13:33:35 PDT 2004
//    Made it reselect an expression that was already selected, like Apply.
//
hrchilds's avatar
hrchilds committed
785
786
787
788
// ****************************************************************************
void
QvisExpressionsWindow::displayAllVarsChanged()
{
hrchilds's avatar
hrchilds committed
789
790
791
792
793
    // This updates the window, which rebuilds the expression list.
    // If we have an expression selected, reselect it afterwards.
    int reselect = (exprListBox->currentItem() != -1);
    QString item = exprListBox->currentText();

hrchilds's avatar
hrchilds committed
794
    UpdateWindow(true);
hrchilds's avatar
hrchilds committed
795
796
797
798
799
800
801
802
803

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::insertFunction
//
//  Purpose:
//    Slot function when a function was selected for insertion by 
//    the popup menu.
//
//  Arguments:
//    id         the menu item id of the function
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
819
820
821
822
823
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 11:33:43 PDT 2004
//    Make sure it's not just a single-char operator before adding the
//    function call parentheses.
//
hrchilds's avatar
hrchilds committed
824
825
826
//    Brad Whitlock, Thu Dec 9 14:15:01 PST 2004
//    Added code to set the focus to the definition edit.
//
hrchilds's avatar
hrchilds committed
827
// ****************************************************************************
hrchilds's avatar
hrchilds committed
828

hrchilds's avatar
hrchilds committed
829
830
831
832
833
834
835
836
void
QvisExpressionsWindow::insertFunction(int id)
{
    if (!definitionEdit->isEnabled())
        return;

    QString orig = definitionEdit->text();
    definitionEdit->insert(insertFunctionMenu->text(id));
hrchilds's avatar
hrchilds committed
837
838
839
840
841
842
843
844
845
846
847
848

    if (insertFunctionMenu->text(id).length() >= 2)
    {
        definitionEdit->insert("()");

        int col,line;
        definitionEdit->getCursorPosition(&line, &col);
        col--;
        if (col < 0)
            col = 0;
        definitionEdit->setCursorPosition(line, col);
    }
hrchilds's avatar
hrchilds committed
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913

    definitionEdit->setFocus();
}

// ****************************************************************************
// Method: QvisExpressionWindow::insertVariable
//
// Purpose: 
//   This is a Qt slot function that inserts a variable name into the 
//   current variable definition.
//
// Arguments:
//   var : The variable.
//
// Programmer: Brad Whitlock
// Creation:   Thu Dec 9 10:52:37 PDT 2004
//
// Modifications:
//   
// ****************************************************************************

void
QvisExpressionsWindow::insertVariable(const QString &var)
{
    if (!definitionEdit->isEnabled())
        return;

    // If the variable name contains slashes then put the <> around the
    // variable name.
    QString newVar(var);
    if(var.find("/") != -1)
        newVar = QString("<") + var + QString(">");

    definitionEdit->insert(newVar);
    definitionEdit->setFocus();
}

// ****************************************************************************
// Method: QvisExpressionsWindow::newExpression
//
// Purpose: 
//   This is a Qt slot function that can be called on the window to add a
//   new expression and set the focus of the window to the name line edit
//   and select all of its text.
//
// Note:       This method is used by the "Create new expression ..." option
//             in QvisVariableButtons.
//
// Programmer: Brad Whitlock
// Creation:   Thu Dec 9 10:18:13 PDT 2004
//
// Modifications:
//   
// ****************************************************************************

void
QvisExpressionsWindow::newExpression()
{
    // Add a new expression
    addExpression();

    // Make the name line edit be the active widget and select its text.
    nameEdit->setFocus();
    nameEdit->setCursorPosition(0);
    nameEdit->selectAll();
hrchilds's avatar
hrchilds committed
914
}