QvisExpressionsWindow.C 29.5 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
// ****************************************************************************
//  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
//
hrchilds's avatar
hrchilds committed
37
38
39
40
41
//  Modifications:
//
//    Hank Childs, Sun Jan  2 15:32:00 PST 2005
//    Added curl, divergence, Laplacian, materror.
//
hrchilds's avatar
hrchilds committed
42
43
44
//    Hank Childs, Thu Jan 20 15:51:16 PST 2005
//    Added side volume, resrad.
//
hrchilds's avatar
hrchilds committed
45
46
47
48
49
//    Hank Childs, Thu Jun 30 15:00:42 PDT 2005
//    Added polar_radius, polar_theta, polar_phi, cylindrical_radius,
//    cylindrical_theta, cylindrical, mod, round, ceil, floor, zoneid,
//    nodeid, global_zoneid, and global_nodeid.
//
hrchilds's avatar
hrchilds committed
50
51
52
//    Hank Childs, Tue Aug 16 09:05:03 PDT 2005
//    Added image processing category.
//
hrchilds's avatar
hrchilds committed
53
54
55
//    Hank Childs, Wed Sep 21 17:31:59 PDT 2005
//    Added external_node, surface normal, min/max edge length/side volume.
//
hrchilds's avatar
hrchilds committed
56
57
58
//    Hank Childs, Sun Jan 22 12:47:29 PST 2006
//    Renamed comparison to relational.  Added new category for comparison.
//
hrchilds's avatar
hrchilds committed
59
60
61
//    Hank Childs, Tue Feb 14 14:06:20 PST 2006
//    Added ijk_gradient.
//
hrchilds's avatar
hrchilds committed
62
63
64
//    Hank Childs, Sun Mar  5 16:03:38 PST 2006
//    Added time.
//
hrchilds's avatar
hrchilds committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// ****************************************************************************
struct ExprNameList
{
    const char *name;
    const char **list;
};

const char *expr_meshquality[] = {
    "aspect",
    "aspect_gamma",
    "condition",
    "degree",
    "diagonal",
    "dimension",
    "jacobian",
    "largest_angle",
hrchilds's avatar
hrchilds committed
81
82
83
84
    "max_edge_length",
    "max_side_volume",
    "min_edge_length",
    "min_side_volume",
hrchilds's avatar
hrchilds committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
    "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",
hrchilds's avatar
hrchilds committed
103
104
    "ceil",
    "floor",
hrchilds's avatar
hrchilds committed
105
106
    "ln",
    "log10",
hrchilds's avatar
hrchilds committed
107
108
    "mod",
    "round",
hrchilds's avatar
hrchilds committed
109
110
111
112
113
114
115
116
117
118
    "sqr",
    "sqrt",
    "+",
    "-",
    "*",
    "/",
    "^",
    NULL
};

hrchilds's avatar
hrchilds committed
119
const char *expr_relational[] = {
hrchilds's avatar
hrchilds committed
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
    "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
};

hrchilds's avatar
hrchilds committed
173
174
175
176
177
178
const char *expr_array[] = {
    "array_compose",
    "array_decompose",
    NULL
};

hrchilds's avatar
hrchilds committed
179
const char *expr_materials[] = {
hrchilds's avatar
hrchilds committed
180
    "materror",
hrchilds's avatar
hrchilds committed
181
182
183
184
185
186
187
188
189
    "matvf",
    "nmats",
    "specmf",
    NULL
};

const char *expr_mesh[] = {
    "area",
    "coord",
hrchilds's avatar
hrchilds committed
190
191
192
    "cylindrical",
    "cylindrical_radius",
    "cylindrical_theta",
hrchilds's avatar
hrchilds committed
193
    "external_node",
hrchilds's avatar
hrchilds committed
194
195
196
    "global_nodeid",
    "global_zoneid",
    "nodeid",
hrchilds's avatar
hrchilds committed
197
    "polar",
hrchilds's avatar
hrchilds committed
198
199
200
    "polar_radius",
    "polar_theta",
    "polar_phi",
hrchilds's avatar
hrchilds committed
201
202
203
    "revolved_surface_area",
    "revolved_volume",
    "volume",
hrchilds's avatar
hrchilds committed
204
    "zoneid",
hrchilds's avatar
hrchilds committed
205
206
207
208
    NULL
};

const char *expr_misc[] = {
hrchilds's avatar
hrchilds committed
209
210
    "curl",
    "divergence",
hrchilds's avatar
hrchilds committed
211
    "gradient",
hrchilds's avatar
hrchilds committed
212
213
    "ij_gradient",
    "ijk_gradient",
hrchilds's avatar
hrchilds committed
214
    "Laplacian",
hrchilds's avatar
hrchilds committed
215
    "recenter",
hrchilds's avatar
hrchilds committed
216
    "resrad",
hrchilds's avatar
hrchilds committed
217
218
219
    "surface_normal",
    "   point_surface_normal",
    "   cell_surface_normal",
hrchilds's avatar
hrchilds committed
220
    "time",
hrchilds's avatar
hrchilds committed
221
222
223
    NULL
};

hrchilds's avatar
hrchilds committed
224
225
226
227
228
229
230
const char *expr_imageprocessing[] = {
    "conservative_smoothing",
    "mean_filter",
    "median_filter",
    NULL
};

hrchilds's avatar
hrchilds committed
231
232
233
234
235
236
237
238
const char *expr_comparison[] = {
    "conn_cmfe",
    "pos_cmfe",
    "symm_plane",
    "symm_transform",
    NULL
};

hrchilds's avatar
hrchilds committed
239
240
ExprNameList exprlist[] =
{
hrchilds's avatar
hrchilds committed
241
242
243
244
245
246
247
    {"Math",             expr_math},
    {"Vector",           expr_vector},
    {"Tensor",           expr_tensor},
    {"Array",            expr_array},
    {"Material",         expr_materials},
    {"Mesh",             expr_mesh},
    {"Mesh Quality",     expr_meshquality},
hrchilds's avatar
hrchilds committed
248
    {"Comparison",       expr_comparison},
hrchilds's avatar
hrchilds committed
249
250
251
    {"Image Processing", expr_imageprocessing},
    {"Miscellaneous",    expr_misc},
    {"Trigonometry",     expr_trig},
hrchilds's avatar
hrchilds committed
252
    {"Relational",       expr_relational},
hrchilds's avatar
hrchilds committed
253
254
    {"Conditional",      expr_conditional},
    {"Logical",          expr_logical},
hrchilds's avatar
hrchilds committed
255
    {NULL,NULL}
hrchilds's avatar
hrchilds committed
256
257
};

hrchilds's avatar
hrchilds committed
258
259
260
261
262
263
264
265
266
267
// ****************************************************************************
// Method: QvisExpressionsWindow::QvisExpressionsWindow
//
// Purpose: 
//   This is the constructor for the QvisExpressionsWindow class.
//
// Arguments:
//   exprList_  The ExpressionList subject to observe
//   
//
hrchilds's avatar
hrchilds committed
268
269
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
//
// ****************************************************************************
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
288
289
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//
// Modifications:
//   
// ****************************************************************************
QvisExpressionsWindow::~QvisExpressionsWindow()
{
    exprList = NULL;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
hrchilds's avatar
hrchilds committed
305
306
307
308
309
// 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
310
311
//
// Modifications:
hrchilds's avatar
hrchilds committed
312
313
314
315
316
317
318
319
//    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
320
321
322
//    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
323
324
325
//    Hank Childs, Thu Jul 21 11:12:43 PDT 2005
//    Add support for array mesh variables.
//
hrchilds's avatar
hrchilds committed
326
// ****************************************************************************
hrchilds's avatar
hrchilds committed
327

hrchilds's avatar
hrchilds committed
328
329
330
void
QvisExpressionsWindow::CreateWindowContents()
{
hrchilds's avatar
hrchilds committed
331
#define USE_SPLITTER
hrchilds's avatar
hrchilds committed
332
333
334
335
336
337
338
339
340
341
#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
342
    mainLayout->setStretchFactor(listLayout, 50);
hrchilds's avatar
hrchilds committed
343
344
#define f1 central
#else
hrchilds's avatar
hrchilds committed
345
346
    QGroupBox *f1 = new QGroupBox("Expression List",mainSplitter);
    QGridLayout *listLayout = new QGridLayout(f1, 4,2, 7, 5, "listLayout");
hrchilds's avatar
hrchilds committed
347
348
#endif

hrchilds's avatar
hrchilds committed
349
350
    listLayout->addRowSpacing(0, 10);

hrchilds's avatar
hrchilds committed
351
    exprListBox = new QListBox(f1);
hrchilds's avatar
hrchilds committed
352
    listLayout->addMultiCellWidget(exprListBox, 1,1, 0,1);
hrchilds's avatar
hrchilds committed
353
354

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

hrchilds's avatar
hrchilds committed
357
358
    delButton = new QPushButton("Delete", f1, "delButton");
    listLayout->addWidget(delButton, 2,1);
hrchilds's avatar
hrchilds committed
359

hrchilds's avatar
hrchilds committed
360
361
    displayAllVars = new QCheckBox("Display expressions from database", f1, "displayAllVars");
    listLayout->addMultiCellWidget(displayAllVars, 3,3, 0,1);
hrchilds's avatar
hrchilds committed
362
363
364
365

#ifndef USE_SPLITTER
    mainLayout->addSpacing(10);
    QGridLayout *editLayout = new QGridLayout(mainLayout, 6,2, 5, "editLayout");
hrchilds's avatar
hrchilds committed
366
    mainLayout->setStretchFactor(editLayout, 50);
hrchilds's avatar
hrchilds committed
367
368
#define f2 central
#else
hrchilds's avatar
hrchilds committed
369
370
    QGroupBox *f2 = new QGroupBox("Definition", mainSplitter);
    QGridLayout *editLayout = new QGridLayout(f2, 6,4, 7, 5, "editLayout");
hrchilds's avatar
hrchilds committed
371
372
373
#endif
    int row = 0;

hrchilds's avatar
hrchilds committed
374
375
376
    editLayout->addRowSpacing(row, 10);
    row++;

hrchilds's avatar
hrchilds committed
377
    nameEditLabel = new QLabel("Name", f2, "nameEditLabel");
hrchilds's avatar
hrchilds committed
378
379
380
    nameEdit = new QNarrowLineEdit(f2, "nameEdit");
    editLayout->addMultiCellWidget(nameEditLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(nameEdit, row,row, 1,3);
hrchilds's avatar
hrchilds committed
381
382
383
384
385
    row++;

    typeLabel = new QLabel("Type", f2, "typeLabel");
    typeList = new QComboBox(f2, "typeList");
    int numtypes = Expression::GetNumTypes();
hrchilds's avatar
hrchilds committed
386
    numtypes = 6;  // HACK!!!  Variable types after 6 currently fail.  FIXME!!!
hrchilds's avatar
hrchilds committed
387
388
    int i;
    for (i=1; i < numtypes ; i++)
hrchilds's avatar
hrchilds committed
389
        typeList->insertItem(Expression::GetTypeString((Expression::ExprType)i));
hrchilds's avatar
hrchilds committed
390
391
    editLayout->addMultiCellWidget(typeLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(typeList, row,row, 1,3);
hrchilds's avatar
hrchilds committed
392
393
394
395
396
397
398
399
400
    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
401
    editLayout->addMultiCellWidget(definitionEdit, row,row, 0,3);
hrchilds's avatar
hrchilds committed
402
403
    row++;

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

hrchilds's avatar
hrchilds committed
407
    insertFunctionButton = new QPushButton("Insert Function...", f2);
hrchilds's avatar
hrchilds committed
408
    insertFunctionMenu = new QPopupMenu(f2, "insertFunctionMenu");
hrchilds's avatar
hrchilds committed
409
    for (i=0; exprlist[i].name; i++)
hrchilds's avatar
hrchilds committed
410
411
412
413
414
415
416
417
418
419
    {
        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
420
    insertFunctionButton->setPopup(insertFunctionMenu);
hrchilds's avatar
hrchilds committed
421
422
423
424
425
426
427
428
429
430
431
    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
432
    row++;
hrchilds's avatar
hrchilds committed
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447

    // 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
448
449
    connect(notHidden, SIGNAL(clicked()),
            this, SLOT(notHiddenChanged()));
hrchilds's avatar
hrchilds committed
450
451
    connect(displayAllVars, SIGNAL(clicked()),
            this, SLOT(displayAllVarsChanged()));
hrchilds's avatar
hrchilds committed
452
453
454
455
456
457
458
459
460
461
462
463
}

// ****************************************************************************
// 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
464
//           of whether or not they are selected.  Currently ignored.
hrchilds's avatar
hrchilds committed
465
//
hrchilds's avatar
hrchilds committed
466
467
468
469
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
470
471
472
473
//    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
474
//
hrchilds's avatar
hrchilds committed
475
476
477
478
479
480
481
// ****************************************************************************
void
QvisExpressionsWindow::UpdateWindow(bool)
{
    BlockAllSignals(true);

    exprListBox->clear();
hrchilds's avatar
hrchilds committed
482
483
    indexMap.clear();
    int pos = 0;
hrchilds's avatar
hrchilds committed
484
485
486
487
488
    for (int i=0; i<exprList->GetNumExpressions(); i++)
    {
        if (displayAllVars->isChecked() ||
            !exprList->GetExpression(i).GetFromDB())
        {
hrchilds's avatar
hrchilds committed
489
            exprListBox->insertItem(exprList->GetExpression(i).GetName().c_str());
hrchilds's avatar
hrchilds committed
490
            indexMap[pos++] = i;
hrchilds's avatar
hrchilds committed
491
492
493
494
495
496
497
498
499
        }
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSingleItem
hrchilds's avatar
hrchilds committed
500
//
hrchilds's avatar
hrchilds committed
501
502
//  Purpose:
//    Update the pane of the window where a single expression is being edited.
hrchilds's avatar
hrchilds committed
503
//
hrchilds's avatar
hrchilds committed
504
505
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
hrchilds's avatar
hrchilds committed
506
//
hrchilds's avatar
hrchilds committed
507
508
509
510
511
512
//  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
513
514
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
515
QvisExpressionsWindow::UpdateWindowSingleItem()
hrchilds's avatar
hrchilds committed
516
{
hrchilds's avatar
hrchilds committed
517
518
519
    BlockAllSignals(true);
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
520
    if (index <  0)
hrchilds's avatar
hrchilds committed
521
522
    {
        nameEdit->setText("");
hrchilds's avatar
hrchilds committed
523
        notHidden->setChecked(true);
hrchilds's avatar
hrchilds committed
524
525
526
        definitionEdit->setText("");
    }
    else
hrchilds's avatar
hrchilds committed
527
    {
hrchilds's avatar
hrchilds committed
528
529
        Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
530
        nameEdit->setText(e.GetName().c_str());
hrchilds's avatar
hrchilds committed
531
532
        notHidden->setChecked(! e.GetHidden());
        typeList->setCurrentText(Expression::GetTypeString(e.GetType()));
hrchilds's avatar
hrchilds committed
533
        definitionEdit->setText(e.GetDefinition().c_str());
hrchilds's avatar
hrchilds committed
534
    }
hrchilds's avatar
hrchilds committed
535
536
537
538
    
    UpdateWindowSensitivity();
    BlockAllSignals(false);
}
hrchilds's avatar
hrchilds committed
539

hrchilds's avatar
hrchilds committed
540
541
542
543
544
545
546
547
548
// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSensitivity
//
//  Purpose:
//    Update the sensitivity of any widget needing it.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
549
550
551
552
553
554
//  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
555
556
557
//    Brad Whitlock, Thu Dec 9 14:04:22 PST 2004
//    Added a button to insert variable names.
//
hrchilds's avatar
hrchilds committed
558
// ****************************************************************************
hrchilds's avatar
hrchilds committed
559

hrchilds's avatar
hrchilds committed
560
561
562
563
void
QvisExpressionsWindow::UpdateWindowSensitivity()
{
    bool enable = true;
hrchilds's avatar
hrchilds committed
564
565
566
    int index = exprListBox->currentItem();

    if (index <  0)
hrchilds's avatar
hrchilds committed
567
    {
hrchilds's avatar
hrchilds committed
568
569
        enable = false;
    }
hrchilds's avatar
hrchilds committed
570
    else if ((*exprList)[indexMap[index]].GetFromDB())
hrchilds's avatar
hrchilds committed
571
572
    {
        enable = false;
hrchilds's avatar
hrchilds committed
573
574
    }

hrchilds's avatar
hrchilds committed
575
576
    nameEdit->setEnabled(enable);
    delButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
577
    notHidden->setEnabled(enable);
hrchilds's avatar
hrchilds committed
578
579
580
    typeList->setEnabled(enable);
    definitionEdit->setEnabled(enable);
    insertFunctionButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
581
    insertVariableButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
}

// ****************************************************************************
//  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
603
604
605
606
607
608
609
610
}

// ****************************************************************************
// Method: QvisExpressionsWindow::Apply
//
// Purpose: 
//   This is a Qt slot function that is called when the Apply button is clicked.
//
hrchilds's avatar
hrchilds committed
611
612
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
//
// 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
633
634
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
635
636
637
638
639
640
641
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::apply()
{
hrchilds's avatar
hrchilds committed
642
643
644
645
646
    // 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
647
    Apply(true);
hrchilds's avatar
hrchilds committed
648
649
650
651
652
653
654
655
656

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
657
658
659
660
661
662
663
664
}

// ****************************************************************************
// Method: QvisExpressionsWindow::addExpression
//
// Purpose: 
//   This is a Qt slot function that adds a new expression that is empty.
//
hrchilds's avatar
hrchilds committed
665
666
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
667
668
//
// Modifications:
hrchilds's avatar
hrchilds committed
669
670
671
//    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
672
673
674
675
676
//   
// ****************************************************************************
void
QvisExpressionsWindow::addExpression()
{
hrchilds's avatar
hrchilds committed
677
678
679
680
681
682
683
684
685
686
687
688
    // 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
689

hrchilds's avatar
hrchilds committed
690
691
692
693
    Expression e;
    e.SetName(newName.latin1());
    e.SetDefinition("");
    exprList->AddExpression(e);
hrchilds's avatar
hrchilds committed
694
695

    exprList->Notify();
hrchilds's avatar
hrchilds committed
696
697
698
699
700
701

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

// ****************************************************************************
hrchilds's avatar
hrchilds committed
705
// Method: QvisExpressionsWindow::delExpression
hrchilds's avatar
hrchilds committed
706
707
708
709
//
// Purpose: 
//   This is a Qt slot function that is called to delete an expression.
//
hrchilds's avatar
hrchilds committed
710
711
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
712
713
//
// Modifications:
hrchilds's avatar
hrchilds committed
714
715
716
717
//    Jeremy Meredith, Mon Oct 17 10:39:56 PDT 2005
//    Made the delete action access the expression list by index in the
//    expression list (instead of assuming its index in the list box was
//    correct).  This was an oversight from my 10/25/04 change.  ('5682)
hrchilds's avatar
hrchilds committed
718
719
720
//   
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
721
QvisExpressionsWindow::delExpression()
hrchilds's avatar
hrchilds committed
722
{
hrchilds's avatar
hrchilds committed
723
724
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
725
    if (index <  0)
hrchilds's avatar
hrchilds committed
726
727
        return;

hrchilds's avatar
hrchilds committed
728
    exprList->RemoveExpression(indexMap[index]);
hrchilds's avatar
hrchilds committed
729
730
731

    exprList->Notify();
}
hrchilds's avatar
hrchilds committed
732
733
734
735
736
737
738
739
740
741
742

// ****************************************************************************
//  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
743
744
745
746
747
//  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
748
749
750
751
752
753
// ****************************************************************************
void
QvisExpressionsWindow::definitionTextChanged()
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
754
    if (index <  0)
hrchilds's avatar
hrchilds committed
755
756
        return;

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

hrchilds's avatar
hrchilds committed
759
    e.SetDefinition(definitionEdit->text().latin1());
hrchilds's avatar
hrchilds committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
}

// ****************************************************************************
//  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
774
775
776
777
778
//  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
779
780
781
782
//    Jeremy Meredith, Mon Oct 17 10:42:08 PDT 2005
//    Never allow an empty name to get into the expression list.  This
//    could cause crashes.  ('6295)
//
hrchilds's avatar
hrchilds committed
783
784
785
786
787
788
// ****************************************************************************
void
QvisExpressionsWindow::nameTextChanged(const QString &text)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
789
    if (index <  0)
hrchilds's avatar
hrchilds committed
790
791
        return;

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

hrchilds's avatar
hrchilds committed
794
    QString newname = text.stripWhiteSpace();
hrchilds's avatar
hrchilds committed
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809

    if (newname.isEmpty())
    {
        int newid = 1;
        bool okay = false;
        while (!okay)
        {
            newname.sprintf("unnamed%d", newid);
            if ((*exprList)[newname.latin1()])
                newid++;
            else
                okay = true;
        }
    }

hrchilds's avatar
hrchilds committed
810
    e.SetName(newname.latin1());
hrchilds's avatar
hrchilds committed
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
    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
828
829
830
831
832
//  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
833
834
835
836
837
838
// ****************************************************************************
void
QvisExpressionsWindow::typeChanged(int value)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
839
    if (index <  0)
hrchilds's avatar
hrchilds committed
840
841
        return;

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

hrchilds's avatar
hrchilds committed
844
845
    // Add one because we skipped index 0 (unknown) when creating the
    // list box originally
hrchilds's avatar
hrchilds committed
846
    e.SetType(Expression::ExprType(value+1));
hrchilds's avatar
hrchilds committed
847
848
849
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
850
//  Method:  QvisExpressionsWindow::notHiddenChanged
hrchilds's avatar
hrchilds committed
851
852
//
//  Purpose:
hrchilds's avatar
hrchilds committed
853
854
//    Slot function for the notHidden toggle.
//    Sets the "notHidden" flag of an expression.
hrchilds's avatar
hrchilds committed
855
856
857
858
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
859
860
861
862
863
864
//  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
865
866
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
867
QvisExpressionsWindow::notHiddenChanged()
hrchilds's avatar
hrchilds committed
868
869
870
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
871
    if (index <  0)
hrchilds's avatar
hrchilds committed
872
873
        return;

hrchilds's avatar
hrchilds committed
874
875
876
    Expression &e = (*exprList)[indexMap[index]];

    e.SetHidden(!notHidden->isChecked());
hrchilds's avatar
hrchilds committed
877
878
879
880
881
882
883
884
885
886
887
888
}

// ****************************************************************************
//  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
889
890
891
892
//  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
893
894
895
896
// ****************************************************************************
void
QvisExpressionsWindow::displayAllVarsChanged()
{
hrchilds's avatar
hrchilds committed
897
898
899
900
901
    // 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
902
    UpdateWindow(true);
hrchilds's avatar
hrchilds committed
903
904
905
906
907
908
909
910
911

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
}

// ****************************************************************************
//  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
927
928
929
930
931
//  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
932
933
934
//    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
935
936
937
//    Hank Childs, Sun Jan 22 12:49:57 PST 2006
//    Add special insertion code for complicated expressions.
//
hrchilds's avatar
hrchilds committed
938
// ****************************************************************************
hrchilds's avatar
hrchilds committed
939

hrchilds's avatar
hrchilds committed
940
941
942
943
944
945
946
void
QvisExpressionsWindow::insertFunction(int id)
{
    if (!definitionEdit->isEnabled())
        return;

    definitionEdit->insert(insertFunctionMenu->text(id));
hrchilds's avatar
hrchilds committed
947

hrchilds's avatar
hrchilds committed
948
    bool doParens = (insertFunctionMenu->text(id).length() >= 2);
hrchilds's avatar
hrchilds committed
949
    std::string str = insertFunctionMenu->text(id).latin1();
hrchilds's avatar
hrchilds committed
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
    if (str == "conn_cmfe")
    {
        definitionEdit->insert("(<filename:var>, <meshname>)");
        doParens = false;
    }
    else if (str == "pos_cmfe")
    {
        definitionEdit->insert("(<filename:var>, <default-var>, <meshname>)");
        doParens = false;
    }
    else if (str == "symm_plane")
    {
        definitionEdit->insert("(<var>, [Nx, Ny, Nz, Ox, Oy, Oz])");
        doParens = false;
    }
    else if (str == "symm_transform")
    {
        definitionEdit->insert("(<var>, [T00, T01, T02, T10, T11, T12, "
                                        "T20, T21, T22])");
        doParens = false;
    }
    else if (str == "matvf")
    {
        definitionEdit->insert("(<material-name>, [#, #, ... #])");
        doParens = false;
    }
    else if (str == "specmf")
    {
        definitionEdit->insert("(<material-name>, [#, #, ... #])");
        doParens = false;
    }
    else if (str == "if")
    {
        definitionEdit->insert("(<condition>, <then-var>, <else-var>)");
        doParens = false;
    }

    if (doParens)
hrchilds's avatar
hrchilds committed
988
989
990
991
992
993
994
995
996
997
    {
        definitionEdit->insert("()");

        int col,line;
        definitionEdit->getCursorPosition(&line, &col);
        col--;
        if (col < 0)
            col = 0;
        definitionEdit->setCursorPosition(line, col);
    }
hrchilds's avatar
hrchilds committed
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016

    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:
//   
hrchilds's avatar
hrchilds committed
1017
1018
1019
//    Jeremy Meredith, Fri Sep  2 16:26:42 PDT 2005
//    Made it be more aggressive about quoting.
//
hrchilds's avatar
hrchilds committed
1020
1021
1022
1023
1024
1025
1026
1027
// ****************************************************************************

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

hrchilds's avatar
hrchilds committed
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
    // If the variable name contains special characters
    // then put the <> around the variable name.
    bool needs_quoting = false;

    for (int i=0; i<var.length(); i++)
    {
        char c = var[i];
        if ((c < 'A' || c > 'Z') &&
            (c < 'a' || c > 'z') &&
            (c < '0' || c > '9') &&
            c != '_')
        {
            needs_quoting = true;
            break;
        }
    }

    QString newVar;
    if (needs_quoting)
hrchilds's avatar
hrchilds committed
1047
        newVar = QString("<") + var + QString(">");
hrchilds's avatar
hrchilds committed
1048
1049
    else
        newVar = var;
hrchilds's avatar
hrchilds committed
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082

    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
1083
}