QvisExpressionsWindow.C 34.6 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
hrchilds's avatar
hrchilds committed
3
* Copyright (c) 2000 - 2007, The Regents of the University of California
hrchilds's avatar
hrchilds committed
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
* Produced at the Lawrence Livermore National Laboratory
* All rights reserved.
*
* This file is part of VisIt. For details, see http://www.llnl.gov/visit/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or materials provided with the distribution.
*  - Neither the name of the UC/LLNL nor  the names of its contributors may be
*    used to  endorse or  promote products derived from  this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED.  IN  NO  EVENT  SHALL  THE  REGENTS  OF  THE  UNIVERSITY OF
* CALIFORNIA, THE U.S.  DEPARTMENT  OF  ENERGY OR CONTRIBUTORS BE  LIABLE  FOR
* ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
38
#include <QvisExpressionsWindow.h>
hrchilds's avatar
hrchilds committed
39

hrchilds's avatar
hrchilds committed
40
41
#include <Expression.h>
#include <ExpressionList.h>
hrchilds's avatar
hrchilds committed
42
43
#include <ViewerProxy.h>

hrchilds's avatar
hrchilds committed
44
45
46
47
48
49
50
51
#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
52
53
#include <qmultilineedit.h>
#include <qpopupmenu.h>
hrchilds's avatar
hrchilds committed
54
#include <qpushbutton.h>
hrchilds's avatar
hrchilds committed
55
#include <qsplitter.h>
hrchilds's avatar
hrchilds committed
56

hrchilds's avatar
hrchilds committed
57
#include <QNarrowLineEdit.h>
hrchilds's avatar
hrchilds committed
58
#include <QvisVariableButton.h>
hrchilds's avatar
hrchilds committed
59

hrchilds's avatar
hrchilds committed
60
61
62
#define STDMIN(A,B) (((A)<(B)) ? (A) : (B))
#define STDMAX(A,B) (((A)<(B)) ? (B) : (A))

hrchilds's avatar
hrchilds committed
63
64
65
66
67
// ****************************************************************************
//  Expression Lists
//
//  Purpose:
//    Categorized expression lists data.  These structures are self-contained
68
//    and to be parsed correctly require only the terminating nulls.
hrchilds's avatar
hrchilds committed
69
70
71
72
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 23, 2004
//
hrchilds's avatar
hrchilds committed
73
74
75
76
77
//  Modifications:
//
//    Hank Childs, Sun Jan  2 15:32:00 PST 2005
//    Added curl, divergence, Laplacian, materror.
//
hrchilds's avatar
hrchilds committed
78
79
80
//    Hank Childs, Thu Jan 20 15:51:16 PST 2005
//    Added side volume, resrad.
//
hrchilds's avatar
hrchilds committed
81
82
83
84
85
//    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
86
87
88
//    Hank Childs, Tue Aug 16 09:05:03 PDT 2005
//    Added image processing category.
//
hrchilds's avatar
hrchilds committed
89
90
91
//    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
92
93
94
//    Hank Childs, Sun Jan 22 12:47:29 PST 2006
//    Renamed comparison to relational.  Added new category for comparison.
//
hrchilds's avatar
hrchilds committed
95
96
97
//    Hank Childs, Tue Feb 14 14:06:20 PST 2006
//    Added ijk_gradient.
//
hrchilds's avatar
hrchilds committed
98
99
100
//    Hank Childs, Sun Mar  5 16:03:38 PST 2006
//    Added time.
//
hrchilds's avatar
hrchilds committed
101
102
103
//    Hank Childs, Mon Mar 13 16:48:23 PST 2006
//    Added minimum and maximum.
//
hrchilds's avatar
hrchilds committed
104
105
106
107
//    Hank Childs, Thu May 11 12:45:39 PDT 2006
//    Added mean_curvature, gauss_curvature, compose vector, and compose 
//    tensor.
//
hrchilds's avatar
hrchilds committed
108
109
110
//    Hank Childs, Fri Oct  6 15:47:04 PDT 2006
//    Added abel_inversion.
//
hrchilds's avatar
hrchilds committed
111
112
113
//    Mark C. Miller, Wed Nov 15 12:47:05 PST 2006
//    Added zonetype expression
//
hrchilds's avatar
hrchilds committed
114
115
116
//    Hank Childs, Fri Dec 22 10:27:45 PST 2006
//    Added symm_point.
//
hrchilds's avatar
hrchilds committed
117
118
119
//    Hank Childs, Fri Jan 12 13:20:33 PST 2007
//    Added array_compose_with_bins
//
hrchilds's avatar
hrchilds committed
120
121
122
//    Cyrus Harrison, Tue Feb 20 12:02:00 PST 2007
//    Added conn_components
//
123
124
125
//    Cyrus Harrison, Fri Jun  1 14:49:49 PDT 2007
//    Added contraction and viscous_stress
//
126
127
128
//    Jeremy Meredith, Thu Aug 30 16:02:58 EDT 2007
//    Added hsvcolor.
//
hrchilds's avatar
hrchilds committed
129
// ****************************************************************************
hrchilds's avatar
hrchilds committed
130

hrchilds's avatar
hrchilds committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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
146
147
148
149
    "max_edge_length",
    "max_side_volume",
    "min_edge_length",
    "min_side_volume",
hrchilds's avatar
hrchilds committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    "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
168
169
    "ceil",
    "floor",
hrchilds's avatar
hrchilds committed
170
171
    "ln",
    "log10",
hrchilds's avatar
hrchilds committed
172
173
    "max",
    "min",
hrchilds's avatar
hrchilds committed
174
175
    "mod",
    "round",
hrchilds's avatar
hrchilds committed
176
177
178
179
180
181
182
183
184
185
    "sqr",
    "sqrt",
    "+",
    "-",
    "*",
    "/",
    "^",
    NULL
};

hrchilds's avatar
hrchilds committed
186
const char *expr_relational[] = {
hrchilds's avatar
hrchilds committed
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
    "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[] = {
hrchilds's avatar
hrchilds committed
221
222
    "color",
    "color4",
hrchilds's avatar
hrchilds committed
223
224
    "cross",
    "dot",
225
    "hsvcolor",
hrchilds's avatar
hrchilds committed
226
    "magnitude",
hrchilds's avatar
hrchilds committed
227
    "normalize",
hrchilds's avatar
hrchilds committed
228
229
230
231
    NULL
};

const char *expr_tensor[] = {
232
    "contraction",
hrchilds's avatar
hrchilds committed
233
234
235
236
237
238
239
240
241
    "determinant",
    "effective_tensor",
    "eigenvalue",
    "eigenvector",
    "inverse",
    "principal_deviatoric_tensor",
    "principal_tensor",
    "tensor_maximum_shear",
    "trace",
242
    "viscous_stress",
hrchilds's avatar
hrchilds committed
243
244
245
    NULL
};

hrchilds's avatar
hrchilds committed
246
247
const char *expr_array[] = {
    "array_compose",
hrchilds's avatar
hrchilds committed
248
    "array_compose_with_bins",
hrchilds's avatar
hrchilds committed
249
250
251
252
    "array_decompose",
    NULL
};

hrchilds's avatar
hrchilds committed
253
const char *expr_materials[] = {
hrchilds's avatar
hrchilds committed
254
    "materror",
hrchilds's avatar
hrchilds committed
255
256
257
258
259
260
261
262
263
    "matvf",
    "nmats",
    "specmf",
    NULL
};

const char *expr_mesh[] = {
    "area",
    "coord",
hrchilds's avatar
hrchilds committed
264
265
266
    "cylindrical",
    "cylindrical_radius",
    "cylindrical_theta",
hrchilds's avatar
hrchilds committed
267
    "external_node",
hrchilds's avatar
hrchilds committed
268
269
270
    "global_nodeid",
    "global_zoneid",
    "nodeid",
hrchilds's avatar
hrchilds committed
271
    "polar",
hrchilds's avatar
hrchilds committed
272
273
274
    "polar_radius",
    "polar_theta",
    "polar_phi",
hrchilds's avatar
hrchilds committed
275
276
277
    "revolved_surface_area",
    "revolved_volume",
    "volume",
hrchilds's avatar
hrchilds committed
278
    "zoneid",
hrchilds's avatar
hrchilds committed
279
    "zonetype",
hrchilds's avatar
hrchilds committed
280
281
282
283
    NULL
};

const char *expr_misc[] = {
hrchilds's avatar
hrchilds committed
284
    "conn_components",
hrchilds's avatar
hrchilds committed
285
286
    "curl",
    "divergence",
hrchilds's avatar
hrchilds committed
287
    "gauss_curvature",
hrchilds's avatar
hrchilds committed
288
    "gradient",
hrchilds's avatar
hrchilds committed
289
290
    "ij_gradient",
    "ijk_gradient",
hrchilds's avatar
hrchilds committed
291
    "Laplacian",
hrchilds's avatar
hrchilds committed
292
    "mean_curvature",
hrchilds's avatar
hrchilds committed
293
    "recenter",
hrchilds's avatar
hrchilds committed
294
    "resrad",
hrchilds's avatar
hrchilds committed
295
296
297
    "surface_normal",
    "   point_surface_normal",
    "   cell_surface_normal",
hrchilds's avatar
hrchilds committed
298
    "time",
hrchilds's avatar
hrchilds committed
299
300
301
    NULL
};

hrchilds's avatar
hrchilds committed
302
const char *expr_imageprocessing[] = {
hrchilds's avatar
hrchilds committed
303
    "abel_inversion",
hrchilds's avatar
hrchilds committed
304
305
306
307
308
309
    "conservative_smoothing",
    "mean_filter",
    "median_filter",
    NULL
};

hrchilds's avatar
hrchilds committed
310
311
312
const char *expr_comparison[] = {
    "conn_cmfe",
    "pos_cmfe",
hrchilds's avatar
hrchilds committed
313
    "symm_point",
hrchilds's avatar
hrchilds committed
314
315
316
317
318
    "symm_plane",
    "symm_transform",
    NULL
};

hrchilds's avatar
hrchilds committed
319
320
ExprNameList exprlist[] =
{
hrchilds's avatar
hrchilds committed
321
322
323
324
325
326
327
    {"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
328
    {"Comparison",       expr_comparison},
hrchilds's avatar
hrchilds committed
329
330
331
    {"Image Processing", expr_imageprocessing},
    {"Miscellaneous",    expr_misc},
    {"Trigonometry",     expr_trig},
hrchilds's avatar
hrchilds committed
332
    {"Relational",       expr_relational},
hrchilds's avatar
hrchilds committed
333
334
    {"Conditional",      expr_conditional},
    {"Logical",          expr_logical},
hrchilds's avatar
hrchilds committed
335
    {NULL,NULL}
hrchilds's avatar
hrchilds committed
336
337
};

hrchilds's avatar
hrchilds committed
338
339
340
341
342
343
344
345
346
347
// ****************************************************************************
// Method: QvisExpressionsWindow::QvisExpressionsWindow
//
// Purpose: 
//   This is the constructor for the QvisExpressionsWindow class.
//
// Arguments:
//   exprList_  The ExpressionList subject to observe
//   
//
hrchilds's avatar
hrchilds committed
348
349
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
//
// ****************************************************************************
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
368
369
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
//
// Modifications:
//   
// ****************************************************************************
QvisExpressionsWindow::~QvisExpressionsWindow()
{
    exprList = NULL;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
hrchilds's avatar
hrchilds committed
385
386
387
388
389
// 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
390
391
//
// Modifications:
hrchilds's avatar
hrchilds committed
392
393
394
395
396
397
398
399
//    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
400
401
402
//    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
403
404
405
//    Hank Childs, Thu Jul 21 11:12:43 PDT 2005
//    Add support for array mesh variables.
//
hrchilds's avatar
hrchilds committed
406
407
408
//    Kathleen Bonnell, Thu Aug  3 08:42:33 PDT 2006 
//    Changed numtypes to 7 to support CurveMeshVar.
//
hrchilds's avatar
hrchilds committed
409
// ****************************************************************************
hrchilds's avatar
hrchilds committed
410

hrchilds's avatar
hrchilds committed
411
412
413
void
QvisExpressionsWindow::CreateWindowContents()
{
hrchilds's avatar
hrchilds committed
414
#define USE_SPLITTER
hrchilds's avatar
hrchilds committed
415
416
417
418
419
420
421
422
423
424
#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
425
    mainLayout->setStretchFactor(listLayout, 50);
hrchilds's avatar
hrchilds committed
426
427
#define f1 central
#else
hrchilds's avatar
hrchilds committed
428
429
    QGroupBox *f1 = new QGroupBox("Expression List",mainSplitter);
    QGridLayout *listLayout = new QGridLayout(f1, 4,2, 7, 5, "listLayout");
hrchilds's avatar
hrchilds committed
430
431
#endif

hrchilds's avatar
hrchilds committed
432
433
    listLayout->addRowSpacing(0, 10);

hrchilds's avatar
hrchilds committed
434
    exprListBox = new QListBox(f1);
hrchilds's avatar
hrchilds committed
435
    listLayout->addMultiCellWidget(exprListBox, 1,1, 0,1);
hrchilds's avatar
hrchilds committed
436
437

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

hrchilds's avatar
hrchilds committed
440
441
    delButton = new QPushButton("Delete", f1, "delButton");
    listLayout->addWidget(delButton, 2,1);
hrchilds's avatar
hrchilds committed
442

hrchilds's avatar
hrchilds committed
443
444
    displayAllVars = new QCheckBox("Display expressions from database", f1, "displayAllVars");
    listLayout->addMultiCellWidget(displayAllVars, 3,3, 0,1);
hrchilds's avatar
hrchilds committed
445
446
447
448

#ifndef USE_SPLITTER
    mainLayout->addSpacing(10);
    QGridLayout *editLayout = new QGridLayout(mainLayout, 6,2, 5, "editLayout");
hrchilds's avatar
hrchilds committed
449
    mainLayout->setStretchFactor(editLayout, 50);
hrchilds's avatar
hrchilds committed
450
451
#define f2 central
#else
hrchilds's avatar
hrchilds committed
452
453
    QGroupBox *f2 = new QGroupBox("Definition", mainSplitter);
    QGridLayout *editLayout = new QGridLayout(f2, 6,4, 7, 5, "editLayout");
hrchilds's avatar
hrchilds committed
454
455
456
#endif
    int row = 0;

hrchilds's avatar
hrchilds committed
457
458
459
    editLayout->addRowSpacing(row, 10);
    row++;

hrchilds's avatar
hrchilds committed
460
    nameEditLabel = new QLabel("Name", f2, "nameEditLabel");
hrchilds's avatar
hrchilds committed
461
462
463
    nameEdit = new QNarrowLineEdit(f2, "nameEdit");
    editLayout->addMultiCellWidget(nameEditLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(nameEdit, row,row, 1,3);
hrchilds's avatar
hrchilds committed
464
465
466
467
468
    row++;

    typeLabel = new QLabel("Type", f2, "typeLabel");
    typeList = new QComboBox(f2, "typeList");
    int numtypes = Expression::GetNumTypes();
hrchilds's avatar
hrchilds committed
469
    numtypes = 7;  // HACK!!!  Variable types after 6 currently fail.  FIXME!!!
hrchilds's avatar
hrchilds committed
470
471
    int i;
    for (i=1; i < numtypes ; i++)
hrchilds's avatar
hrchilds committed
472
        typeList->insertItem(Expression::GetTypeString((Expression::ExprType)i));
hrchilds's avatar
hrchilds committed
473
474
    editLayout->addMultiCellWidget(typeLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(typeList, row,row, 1,3);
hrchilds's avatar
hrchilds committed
475
476
477
478
479
480
481
482
483
    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
484
    editLayout->addMultiCellWidget(definitionEdit, row,row, 0,3);
hrchilds's avatar
hrchilds committed
485
486
    row++;

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

hrchilds's avatar
hrchilds committed
490
    insertFunctionButton = new QPushButton("Insert Function...", f2);
hrchilds's avatar
hrchilds committed
491
    insertFunctionMenu = new QPopupMenu(f2, "insertFunctionMenu");
hrchilds's avatar
hrchilds committed
492
    for (i=0; exprlist[i].name; i++)
hrchilds's avatar
hrchilds committed
493
494
495
496
497
498
499
500
501
502
    {
        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
503
    insertFunctionButton->setPopup(insertFunctionMenu);
hrchilds's avatar
hrchilds committed
504
505
506
507
508
509
510
511
512
513
514
    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
515
    row++;
hrchilds's avatar
hrchilds committed
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530

    // 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
531
532
    connect(notHidden, SIGNAL(clicked()),
            this, SLOT(notHiddenChanged()));
hrchilds's avatar
hrchilds committed
533
534
    connect(displayAllVars, SIGNAL(clicked()),
            this, SLOT(displayAllVarsChanged()));
hrchilds's avatar
hrchilds committed
535
536
537
538
539
540
541
542
543
544
545
546
}

// ****************************************************************************
// 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
547
//           of whether or not they are selected.  Currently ignored.
hrchilds's avatar
hrchilds committed
548
//
hrchilds's avatar
hrchilds committed
549
550
551
552
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
553
554
555
556
//    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
557
//
hrchilds's avatar
hrchilds committed
558
559
560
561
562
563
564
// ****************************************************************************
void
QvisExpressionsWindow::UpdateWindow(bool)
{
    BlockAllSignals(true);

    exprListBox->clear();
hrchilds's avatar
hrchilds committed
565
566
    indexMap.clear();
    int pos = 0;
hrchilds's avatar
hrchilds committed
567
568
569
    for (int i=0; i<exprList->GetNumExpressions(); i++)
    {
        if (displayAllVars->isChecked() ||
hrchilds's avatar
hrchilds committed
570
            !exprList->GetExpressions(i).GetFromDB())
hrchilds's avatar
hrchilds committed
571
        {
hrchilds's avatar
hrchilds committed
572
            exprListBox->insertItem(exprList->GetExpressions(i).GetName().c_str());
hrchilds's avatar
hrchilds committed
573
            indexMap[pos++] = i;
hrchilds's avatar
hrchilds committed
574
575
576
577
578
579
580
581
582
        }
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSingleItem
hrchilds's avatar
hrchilds committed
583
//
hrchilds's avatar
hrchilds committed
584
585
//  Purpose:
//    Update the pane of the window where a single expression is being edited.
hrchilds's avatar
hrchilds committed
586
//
hrchilds's avatar
hrchilds committed
587
588
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
hrchilds's avatar
hrchilds committed
589
//
hrchilds's avatar
hrchilds committed
590
591
592
593
594
595
//  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
596
597
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
598
QvisExpressionsWindow::UpdateWindowSingleItem()
hrchilds's avatar
hrchilds committed
599
{
hrchilds's avatar
hrchilds committed
600
601
602
    BlockAllSignals(true);
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
603
    if (index <  0)
hrchilds's avatar
hrchilds committed
604
605
    {
        nameEdit->setText("");
hrchilds's avatar
hrchilds committed
606
        notHidden->setChecked(true);
hrchilds's avatar
hrchilds committed
607
608
609
        definitionEdit->setText("");
    }
    else
hrchilds's avatar
hrchilds committed
610
    {
hrchilds's avatar
hrchilds committed
611
612
        Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
613
        nameEdit->setText(e.GetName().c_str());
hrchilds's avatar
hrchilds committed
614
615
        notHidden->setChecked(! e.GetHidden());
        typeList->setCurrentText(Expression::GetTypeString(e.GetType()));
hrchilds's avatar
hrchilds committed
616
        definitionEdit->setText(e.GetDefinition().c_str());
hrchilds's avatar
hrchilds committed
617
    }
hrchilds's avatar
hrchilds committed
618
619
620
621
    
    UpdateWindowSensitivity();
    BlockAllSignals(false);
}
hrchilds's avatar
hrchilds committed
622

hrchilds's avatar
hrchilds committed
623
624
625
626
627
628
629
630
631
// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSensitivity
//
//  Purpose:
//    Update the sensitivity of any widget needing it.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
632
633
634
635
636
637
//  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
638
639
640
//    Brad Whitlock, Thu Dec 9 14:04:22 PST 2004
//    Added a button to insert variable names.
//
641
642
643
644
//    Cyrus Harrison,  Mon Oct  1 16:24:32 PDT 2007
//    Changed definitionEdit to be readOnly instead of disabled
//    for database expressions so users can select/copy them.
//
hrchilds's avatar
hrchilds committed
645
// ****************************************************************************
hrchilds's avatar
hrchilds committed
646

hrchilds's avatar
hrchilds committed
647
648
649
650
void
QvisExpressionsWindow::UpdateWindowSensitivity()
{
    bool enable = true;
hrchilds's avatar
hrchilds committed
651
652
653
    int index = exprListBox->currentItem();

    if (index <  0)
hrchilds's avatar
hrchilds committed
654
    {
hrchilds's avatar
hrchilds committed
655
656
        enable = false;
    }
hrchilds's avatar
hrchilds committed
657
    else if ((*exprList)[indexMap[index]].GetFromDB())
hrchilds's avatar
hrchilds committed
658
659
    {
        enable = false;
hrchilds's avatar
hrchilds committed
660
661
    }

hrchilds's avatar
hrchilds committed
662
663
    nameEdit->setEnabled(enable);
    delButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
664
    notHidden->setEnabled(enable);
hrchilds's avatar
hrchilds committed
665
    typeList->setEnabled(enable);
666
    definitionEdit->setReadOnly(!enable);
hrchilds's avatar
hrchilds committed
667
    insertFunctionButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
668
    insertVariableButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
}

// ****************************************************************************
//  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
690
691
692
693
694
695
696
697
}

// ****************************************************************************
// Method: QvisExpressionsWindow::Apply
//
// Purpose: 
//   This is a Qt slot function that is called when the Apply button is clicked.
//
hrchilds's avatar
hrchilds committed
698
699
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
700
701
702
703
704
705
706
707
708
709
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::Apply(bool forceUpdate)
{
    exprList->Notify();

    if (AutoUpdate() || forceUpdate)
hrchilds's avatar
hrchilds committed
710
        GetViewerMethods()->ProcessExpressions();
hrchilds's avatar
hrchilds committed
711
712
713
714
715
716
717
718
719
}

// ****************************************************************************
// 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
720
721
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
722
723
724
725
726
727
728
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::apply()
{
hrchilds's avatar
hrchilds committed
729
730
731
732
733
    // 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
734
    Apply(true);
hrchilds's avatar
hrchilds committed
735
736
737
738
739
740
741
742
743

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
744
745
746
747
748
749
750
751
}

// ****************************************************************************
// Method: QvisExpressionsWindow::addExpression
//
// Purpose: 
//   This is a Qt slot function that adds a new expression that is empty.
//
hrchilds's avatar
hrchilds committed
752
753
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
754
755
//
// Modifications:
hrchilds's avatar
hrchilds committed
756
757
758
//    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
759
760
761
762
763
//   
// ****************************************************************************
void
QvisExpressionsWindow::addExpression()
{
hrchilds's avatar
hrchilds committed
764
765
766
767
768
769
770
771
772
773
774
775
    // 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
776

hrchilds's avatar
hrchilds committed
777
778
779
    Expression e;
    e.SetName(newName.latin1());
    e.SetDefinition("");
hrchilds's avatar
hrchilds committed
780
    exprList->AddExpressions(e);
hrchilds's avatar
hrchilds committed
781
782

    exprList->Notify();
hrchilds's avatar
hrchilds committed
783
784
785
786
787
788

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

// ****************************************************************************
hrchilds's avatar
hrchilds committed
792
// Method: QvisExpressionsWindow::delExpression
hrchilds's avatar
hrchilds committed
793
794
795
796
//
// Purpose: 
//   This is a Qt slot function that is called to delete an expression.
//
hrchilds's avatar
hrchilds committed
797
798
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
799
800
//
// Modifications:
hrchilds's avatar
hrchilds committed
801
802
803
804
//    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
805
806
807
//   
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
808
QvisExpressionsWindow::delExpression()
hrchilds's avatar
hrchilds committed
809
{
hrchilds's avatar
hrchilds committed
810
811
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
812
    if (index <  0)
hrchilds's avatar
hrchilds committed
813
814
        return;

hrchilds's avatar
hrchilds committed
815
    exprList->RemoveExpressions(indexMap[index]);
hrchilds's avatar
hrchilds committed
816
817
818

    exprList->Notify();
}
hrchilds's avatar
hrchilds committed
819
820
821
822
823
824
825
826
827
828
829

// ****************************************************************************
//  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
830
831
832
833
834
//  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
835
836
837
838
839
840
// ****************************************************************************
void
QvisExpressionsWindow::definitionTextChanged()
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
841
    if (index <  0)
hrchilds's avatar
hrchilds committed
842
843
        return;

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

hrchilds's avatar
hrchilds committed
846
    e.SetDefinition(definitionEdit->text().latin1());
hrchilds's avatar
hrchilds committed
847
848
849
850
851
852
853
854
855
856
857
858
859
860
}

// ****************************************************************************
//  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
861
862
863
864
865
//  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
866
867
868
869
//    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
870
871
872
873
874
875
// ****************************************************************************
void
QvisExpressionsWindow::nameTextChanged(const QString &text)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
876
    if (index <  0)
hrchilds's avatar
hrchilds committed
877
878
        return;

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

hrchilds's avatar
hrchilds committed
881
    QString newname = text.stripWhiteSpace();
hrchilds's avatar
hrchilds committed
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896

    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
897
    e.SetName(newname.latin1());
hrchilds's avatar
hrchilds committed
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
    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
915
916
917
918
919
//  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
920
921
922
923
924
925
// ****************************************************************************
void
QvisExpressionsWindow::typeChanged(int value)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
926
    if (index <  0)
hrchilds's avatar
hrchilds committed
927
928
        return;

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

hrchilds's avatar
hrchilds committed
931
932
    // Add one because we skipped index 0 (unknown) when creating the
    // list box originally
hrchilds's avatar
hrchilds committed
933
    e.SetType(Expression::ExprType(value+1));
hrchilds's avatar
hrchilds committed
934
935
936
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
937
//  Method:  QvisExpressionsWindow::notHiddenChanged
hrchilds's avatar
hrchilds committed
938
939
//
//  Purpose:
hrchilds's avatar
hrchilds committed
940
941
//    Slot function for the notHidden toggle.
//    Sets the "notHidden" flag of an expression.
hrchilds's avatar
hrchilds committed
942
943
944
945
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
946
947
948
949
950
951
//  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
952
953
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
954
QvisExpressionsWindow::notHiddenChanged()
hrchilds's avatar
hrchilds committed
955
956
957
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
958
    if (index <  0)
hrchilds's avatar
hrchilds committed
959
960
        return;

hrchilds's avatar
hrchilds committed
961
962
963
    Expression &e = (*exprList)[indexMap[index]];

    e.SetHidden(!notHidden->isChecked());
hrchilds's avatar
hrchilds committed
964
965
966
967
968
969
970
971
972
973
974
975
}

// ****************************************************************************
//  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
976
977
978
979
//  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
980
981
982
983
// ****************************************************************************
void
QvisExpressionsWindow::displayAllVarsChanged()
{
hrchilds's avatar
hrchilds committed
984
985
986
987
988
    // 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
989
    UpdateWindow(true);
hrchilds's avatar
hrchilds committed
990
991
992
993
994
995
996
997
998

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
}

// ****************************************************************************
//  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
1014
1015
1016
1017
1018
//  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
1019
1020
1021
//    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
1022
1023
1024
//    Hank Childs, Sun Jan 22 12:49:57 PST 2006
//    Add special insertion code for complicated expressions.
//
hrchilds's avatar
hrchilds committed
1025
1026
1027
1028
//    Hank Childs, Fri Mar 10 14:28:11 PST 2006
//    Change ordering of arguments for pos_cmfe, since the first pass was
//    incorrect.
//
hrchilds's avatar
hrchilds committed
1029
1030
1031
//    Hank Childs, Mon Mar 13 16:48:23 PST 2006
//    Added min and max.
//
hrchilds's avatar
hrchilds committed
1032
1033
1034
//    Hank Childs, Fri Dec 22 10:31:40 PST 2006
//    Added symm_point.
//
hrchilds's avatar
hrchilds committed
1035
1036
1037
//    Hank Childs, Fri Jan 12 13:20:33 PST 2007
//    Added array_compose and array_compose_with_bins.
//
hrchilds's avatar
hrchilds committed
1038
1039
1040
//    Hank Childs, Sat Mar 17 15:33:54 PDT 2007
//    Fix problem with specmf.
//
hrchilds's avatar
hrchilds committed
1041
1042
1043
//    Brad Whitlock, Mon Apr 23 17:35:13 PST 2007
//    Added color expression.
//
hrchilds's avatar
hrchilds committed
1044
// ****************************************************************************
hrchilds's avatar
hrchilds committed
1045

hrchilds's avatar
hrchilds committed
1046
1047
1048
1049
1050
1051
1052
void
QvisExpressionsWindow::insertFunction(int id)
{
    if (!definitionEdit->isEnabled())
        return;

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

hrchilds's avatar
hrchilds committed
1054
    bool doParens = (insertFunctionMenu->text(id).length() >= 2);
hrchilds's avatar
hrchilds committed
1055
    std::string str = insertFunctionMenu->text(id).latin1();
hrchilds's avatar
hrchilds committed
1056
1057
1058
1059
1060
1061
1062
    if (str == "conn_cmfe")
    {
        definitionEdit->insert("(<filename:var>, <meshname>)");
        doParens = false;
    }
    else if (str == "pos_cmfe")
    {
hrchilds's avatar
hrchilds committed
1063
        definitionEdit->insert("(<filename:var>, <meshname>, <default-var>)");
hrchilds's avatar
hrchilds committed
1064
1065
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1066
1067
1068
1069
1070
    else if (str == "symm_point")
    {
        definitionEdit->insert("(<var>, [Px, Py, Pz])");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
    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")
    {
hrchilds's avatar
hrchilds committed
1084
        definitionEdit->insert("(<material-object-name>, [#, #, ... #])");
hrchilds's avatar
hrchilds committed
1085
1086
1087
1088
        doParens = false;
    }
    else if (str == "specmf")
    {
hrchilds's avatar
hrchilds committed
1089
        definitionEdit->insert("(<species-variable-name>, <material-name-or-number>, [#, #, ... #])");
hrchilds's avatar
hrchilds committed
1090
1091
1092
1093
1094
1095
1096
        doParens = false;
    }
    else if (str == "if")
    {
        definitionEdit->insert("(<condition>, <then-var>, <else-var>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1097
1098
    else if (str == "min" || str == "max" || str == "cross" || str == "mod" ||
             str == "and" || str == "or")
hrchilds's avatar
hrchilds committed
1099
1100
1101
1102
    {
        definitionEdit->insert("(<var1>, <var2>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
    else if (str == "array_compose")
    {
        definitionEdit->insert("(<var1>, <var2>, ..., <varN>)");
        doParens = false;
    }
    else if (str == "array_compose_with_bins")
    {
        definitionEdit->insert("(<var1>, <var2>, ..., <varN>, [b1, b2, ..., bN+1])");
        doParens = false;
    }
    else if (str == "eq" || str == "ge" || str == "gt" || 
             str == "le" || str == "lt" || str == "ne")
    {
        definitionEdit->insert("(<var-LHS>, <var-RHS>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
    else if(str == "color4")
    {
        definitionEdit->insert("(<var1>, <var2>, <var3>, <var4>)");
        doParens = false;      
    }
    else if(str == "color")
    {
        definitionEdit->insert("(<var1>, <var2>, <var3>)");
        doParens = false;      
    }
hrchilds's avatar
hrchilds committed
1129
1130

    if (doParens)
hrchilds's avatar
hrchilds committed
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
    {
        definitionEdit->insert("()");

        int col,line;
        definitionEdit->getCursorPosition(&line, &col);
        col--;
        if (col < 0)
            col = 0;
        definitionEdit->setCursorPosition(line, col);
    }
hrchilds's avatar
hrchilds committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

    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
1160
1161
1162
//    Jeremy Meredith, Fri Sep  2 16:26:42 PDT 2005
//    Made it be more aggressive about quoting.
//
hrchilds's avatar
hrchilds committed
1163
1164
1165
1166
1167
1168
1169
1170
// ****************************************************************************

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

hrchilds's avatar
hrchilds committed
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
    // 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
1190
        newVar = QString("<") + var + QString(">");
hrchilds's avatar
hrchilds committed
1191
1192
    else
        newVar = var;
hrchilds's avatar
hrchilds committed
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225

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