QvisExpressionsWindow.C 37.8 KB
Newer Older
hrchilds's avatar
hrchilds committed
1
2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-400142
hrchilds's avatar
hrchilds committed
6
7
* All rights reserved.
*
brugger's avatar
 
brugger committed
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9
10
11
12
13
14
15
16
17
18
* 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
brugger's avatar
 
brugger committed
19
20
21
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
hrchilds's avatar
hrchilds committed
22
23
24
25
26
*    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
brugger's avatar
 
brugger committed
27
28
29
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
hrchilds's avatar
hrchilds committed
30
31
32
33
34
35
36
37
38
* 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
39
#include <QvisExpressionsWindow.h>
hrchilds's avatar
hrchilds committed
40

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

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

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

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

hrchilds's avatar
hrchilds committed
64
65
66
67
68
// ****************************************************************************
//  Expression Lists
//
//  Purpose:
//    Categorized expression lists data.  These structures are self-contained
69
//    and to be parsed correctly require only the terminating nulls.
hrchilds's avatar
hrchilds committed
70
71
72
73
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 23, 2004
//
hrchilds's avatar
hrchilds committed
74
75
76
77
78
//  Modifications:
//
//    Hank Childs, Sun Jan  2 15:32:00 PST 2005
//    Added curl, divergence, Laplacian, materror.
//
hrchilds's avatar
hrchilds committed
79
80
81
//    Hank Childs, Thu Jan 20 15:51:16 PST 2005
//    Added side volume, resrad.
//
hrchilds's avatar
hrchilds committed
82
83
84
85
86
//    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
87
88
89
//    Hank Childs, Tue Aug 16 09:05:03 PDT 2005
//    Added image processing category.
//
hrchilds's avatar
hrchilds committed
90
91
92
//    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
93
94
95
//    Hank Childs, Sun Jan 22 12:47:29 PST 2006
//    Renamed comparison to relational.  Added new category for comparison.
//
hrchilds's avatar
hrchilds committed
96
97
98
//    Hank Childs, Tue Feb 14 14:06:20 PST 2006
//    Added ijk_gradient.
//
hrchilds's avatar
hrchilds committed
99
100
101
//    Hank Childs, Sun Mar  5 16:03:38 PST 2006
//    Added time.
//
hrchilds's avatar
hrchilds committed
102
103
104
//    Hank Childs, Mon Mar 13 16:48:23 PST 2006
//    Added minimum and maximum.
//
hrchilds's avatar
hrchilds committed
105
106
107
108
//    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
109
110
111
//    Hank Childs, Fri Oct  6 15:47:04 PDT 2006
//    Added abel_inversion.
//
hrchilds's avatar
hrchilds committed
112
113
114
//    Mark C. Miller, Wed Nov 15 12:47:05 PST 2006
//    Added zonetype expression
//
hrchilds's avatar
hrchilds committed
115
116
117
//    Hank Childs, Fri Dec 22 10:27:45 PST 2006
//    Added symm_point.
//
hrchilds's avatar
hrchilds committed
118
119
120
//    Hank Childs, Fri Jan 12 13:20:33 PST 2007
//    Added array_compose_with_bins
//
hrchilds's avatar
hrchilds committed
121
122
123
//    Cyrus Harrison, Tue Feb 20 12:02:00 PST 2007
//    Added conn_components
//
124
125
126
//    Cyrus Harrison, Fri Jun  1 14:49:49 PDT 2007
//    Added contraction and viscous_stress
//
127
128
129
//    Jeremy Meredith, Thu Aug 30 16:02:58 EDT 2007
//    Added hsvcolor.
//
130
131
132
//    Gunther H. Weber, Thu Jan 10 12:00:23 PST 2008
//    Added colorlookup.
//
133
134
135
//    Cyrus Harrison, Thu Jan 31 09:45:30 PST 2008
//    Added value_for_material
//
hrchilds's avatar
hrchilds committed
136
137
138
//    Hank Childs, Thu Feb 21 15:50:36 PST 2008
//    Added transpose.
//
139
140
141
//    Brad Whitlock, Tue Apr  8 12:17:11 PDT 2008
//    Added support for internalization of the expression category names.
//
brugger's avatar
 
brugger committed
142
143
144
145
//    Eric Brugger, Wed Aug  6 17:49:59 PDT 2008
//    Renamed smallest_angle to minimum_angle and largest_angle to
//    maximum_angle.
//
hrchilds's avatar
hrchilds committed
146
// ****************************************************************************
hrchilds's avatar
hrchilds committed
147

hrchilds's avatar
hrchilds committed
148
149
struct ExprNameList
{
150
    QString      name;
hrchilds's avatar
hrchilds committed
151
152
153
154
155
156
157
158
159
160
161
    const char **list;
};

const char *expr_meshquality[] = {
    "aspect",
    "aspect_gamma",
    "condition",
    "degree",
    "diagonal",
    "dimension",
    "jacobian",
hrchilds's avatar
hrchilds committed
162
163
    "max_edge_length",
    "max_side_volume",
brugger's avatar
 
brugger committed
164
    "maximum_angle",
hrchilds's avatar
hrchilds committed
165
166
    "min_edge_length",
    "min_side_volume",
brugger's avatar
 
brugger committed
167
    "minimum_angle",
hrchilds's avatar
hrchilds committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
    "neighbor",
    "node_degree",
    "oddy",
    "relative_size",
    "scaled_jacobian",
    "shape",
    "shape_and_size",
    "shear",
    "skew",
    "stretch",
    "taper",
    "warpage",
    NULL
};

const char *expr_math[] = {
    "abs",
hrchilds's avatar
hrchilds committed
185
186
    "ceil",
    "floor",
187
    "exp",
hrchilds's avatar
hrchilds committed
188
189
    "ln",
    "log10",
hrchilds's avatar
hrchilds committed
190
191
    "max",
    "min",
hrchilds's avatar
hrchilds committed
192
193
    "mod",
    "round",
hrchilds's avatar
hrchilds committed
194
195
    "sqr",
    "sqrt",
196
    "random",
hrchilds's avatar
hrchilds committed
197
198
199
200
201
    "+",
    "-",
    "*",
    "/",
    "^",
202
    "&",
hrchilds's avatar
hrchilds committed
203
204
205
    NULL
};

hrchilds's avatar
hrchilds committed
206
const char *expr_relational[] = {
hrchilds's avatar
hrchilds committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
    "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
241
242
    "color",
    "color4",
243
    "colorlookup",
hrchilds's avatar
hrchilds committed
244
245
    "cross",
    "dot",
246
    "hsvcolor",
hrchilds's avatar
hrchilds committed
247
    "magnitude",
hrchilds's avatar
hrchilds committed
248
    "normalize",
hrchilds's avatar
hrchilds committed
249
250
251
252
    NULL
};

const char *expr_tensor[] = {
253
    "contraction",
hrchilds's avatar
hrchilds committed
254
255
256
257
258
259
260
261
262
    "determinant",
    "effective_tensor",
    "eigenvalue",
    "eigenvector",
    "inverse",
    "principal_deviatoric_tensor",
    "principal_tensor",
    "tensor_maximum_shear",
    "trace",
hrchilds's avatar
hrchilds committed
263
    "transpose",
264
    "viscous_stress",
hrchilds's avatar
hrchilds committed
265
266
267
    NULL
};

hrchilds's avatar
hrchilds committed
268
269
const char *expr_array[] = {
    "array_compose",
hrchilds's avatar
hrchilds committed
270
    "array_compose_with_bins",
hrchilds's avatar
hrchilds committed
271
272
273
274
    "array_decompose",
    NULL
};

hrchilds's avatar
hrchilds committed
275
const char *expr_materials[] = {
hrchilds's avatar
hrchilds committed
276
    "materror",
hrchilds's avatar
hrchilds committed
277
278
279
    "matvf",
    "nmats",
    "specmf",
280
    "value_for_material",
hrchilds's avatar
hrchilds committed
281
282
283
284
285
286
    NULL
};

const char *expr_mesh[] = {
    "area",
    "coord",
hrchilds's avatar
hrchilds committed
287
288
289
    "cylindrical",
    "cylindrical_radius",
    "cylindrical_theta",
hrchilds's avatar
hrchilds committed
290
    "external_node",
hrchilds's avatar
hrchilds committed
291
292
293
    "global_nodeid",
    "global_zoneid",
    "nodeid",
hrchilds's avatar
hrchilds committed
294
    "polar",
hrchilds's avatar
hrchilds committed
295
296
297
    "polar_radius",
    "polar_theta",
    "polar_phi",
hrchilds's avatar
hrchilds committed
298
299
300
    "revolved_surface_area",
    "revolved_volume",
    "volume",
hrchilds's avatar
hrchilds committed
301
    "zoneid",
hrchilds's avatar
hrchilds committed
302
    "zonetype",
hrchilds's avatar
hrchilds committed
303
304
305
306
    NULL
};

const char *expr_misc[] = {
307
    "cell_constant",
hrchilds's avatar
hrchilds committed
308
    "conn_components",
hrchilds's avatar
hrchilds committed
309
310
    "curl",
    "divergence",
311
    "enumerate",
hrchilds's avatar
hrchilds committed
312
    "gauss_curvature",
hrchilds's avatar
hrchilds committed
313
    "gradient",
hrchilds's avatar
hrchilds committed
314
315
    "ij_gradient",
    "ijk_gradient",
hrchilds's avatar
hrchilds committed
316
    "Laplacian",
hrchilds's avatar
hrchilds committed
317
    "mean_curvature",
318
    "point_constant",
hrchilds's avatar
hrchilds committed
319
    "recenter",
hrchilds's avatar
hrchilds committed
320
    "resrad",
hrchilds's avatar
hrchilds committed
321
322
323
    "surface_normal",
    "   point_surface_normal",
    "   cell_surface_normal",
hrchilds's avatar
hrchilds committed
324
    "time",
hrchilds's avatar
hrchilds committed
325
326
327
    NULL
};

hrchilds's avatar
hrchilds committed
328
const char *expr_imageprocessing[] = {
hrchilds's avatar
hrchilds committed
329
    "abel_inversion",
hrchilds's avatar
hrchilds committed
330
331
332
333
334
335
    "conservative_smoothing",
    "mean_filter",
    "median_filter",
    NULL
};

hrchilds's avatar
hrchilds committed
336
337
338
const char *expr_comparison[] = {
    "conn_cmfe",
    "pos_cmfe",
hrchilds's avatar
hrchilds committed
339
    "symm_point",
hrchilds's avatar
hrchilds committed
340
341
342
343
344
    "symm_plane",
    "symm_transform",
    NULL
};

345
346
#define NUM_EXPRESSION_CATEGORIES 14
ExprNameList exprlist[NUM_EXPRESSION_CATEGORIES];
hrchilds's avatar
hrchilds committed
347

hrchilds's avatar
hrchilds committed
348
349
350
351
352
353
354
355
356
357
// ****************************************************************************
// Method: QvisExpressionsWindow::QvisExpressionsWindow
//
// Purpose: 
//   This is the constructor for the QvisExpressionsWindow class.
//
// Arguments:
//   exprList_  The ExpressionList subject to observe
//   
//
hrchilds's avatar
hrchilds committed
358
359
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
360
//
361
362
363
364
// Modifications:
//   Brad Whitlock, Tue Apr  8 12:15:08 PDT 2008
//   Support for internationalization.
//
hrchilds's avatar
hrchilds committed
365
// ****************************************************************************
366

hrchilds's avatar
hrchilds committed
367
QvisExpressionsWindow::QvisExpressionsWindow(
368
369
    ExpressionList *exprList_, const QString &caption,
    const QString &shortName, QvisNotepadArea *notepad) :
hrchilds's avatar
hrchilds committed
370
371
372
373
    QvisPostableWindowObserver(exprList_, caption, shortName, notepad,
                               QvisPostableWindowObserver::ApplyButton,
                               false)
{
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
    // Populate the expression categories. If you add a new one, increment
    // the NUM_EXPRESSION_CATEGORIES macro.
    exprlist[0].name = tr("Math");
    exprlist[0].list = expr_math;
    exprlist[1].name = tr("Vector");
    exprlist[1].list = expr_vector;
    exprlist[2].name = tr("Tensor");
    exprlist[2].list = expr_tensor;
    exprlist[3].name = tr("Array");
    exprlist[3].list = expr_array;
    exprlist[4].name = tr("Material");
    exprlist[4].list = expr_materials;
    exprlist[5].name = tr("Mesh");
    exprlist[5].list = expr_mesh;
    exprlist[6].name = tr("Mesh Quality");
    exprlist[6].list = expr_meshquality;
    exprlist[7].name = tr("Comparison");
    exprlist[7].list = expr_comparison;
    exprlist[8].name = tr("Image Processing");
    exprlist[8].list = expr_imageprocessing;
    exprlist[9].name = tr("Miscellaneous");
    exprlist[9].list = expr_misc;
    exprlist[10].name = tr("Trigonometry");
    exprlist[10].list = expr_trig;
    exprlist[11].name = tr("Relational");
    exprlist[11].list = expr_relational;
    exprlist[12].name = tr("Conditional");
    exprlist[12].list = expr_conditional;
    exprlist[13].name = tr("Logical");
    exprlist[13].list = expr_logical;

hrchilds's avatar
hrchilds committed
405
406
407
408
409
410
411
412
413
    exprList = exprList_;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::~QvisExpressionsWindow
//
// Purpose: 
//   Destructor for the QvisExpressionsWindow class.
//
hrchilds's avatar
hrchilds committed
414
415
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//
// Modifications:
//   
// ****************************************************************************
QvisExpressionsWindow::~QvisExpressionsWindow()
{
    exprList = NULL;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
hrchilds's avatar
hrchilds committed
431
432
433
434
435
// 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
436
437
//
// Modifications:
hrchilds's avatar
hrchilds committed
438
439
440
441
442
443
444
445
//    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
446
447
448
//    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
449
450
451
//    Hank Childs, Thu Jul 21 11:12:43 PDT 2005
//    Add support for array mesh variables.
//
hrchilds's avatar
hrchilds committed
452
453
454
//    Kathleen Bonnell, Thu Aug  3 08:42:33 PDT 2006 
//    Changed numtypes to 7 to support CurveMeshVar.
//
455
456
457
//    Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//    Support for internationalization.
//
458
459
//    Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
//    Added '&' bitwise binary and operation
hrchilds's avatar
hrchilds committed
460
// ****************************************************************************
hrchilds's avatar
hrchilds committed
461

hrchilds's avatar
hrchilds committed
462
463
464
void
QvisExpressionsWindow::CreateWindowContents()
{
hrchilds's avatar
hrchilds committed
465
#define USE_SPLITTER
hrchilds's avatar
hrchilds committed
466
467
468
469
470
471
472
473
474
475
#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
476
    mainLayout->setStretchFactor(listLayout, 50);
hrchilds's avatar
hrchilds committed
477
478
#define f1 central
#else
479
    QGroupBox *f1 = new QGroupBox(tr("Expression List"),mainSplitter);
hrchilds's avatar
hrchilds committed
480
    QGridLayout *listLayout = new QGridLayout(f1, 4,2, 7, 5, "listLayout");
hrchilds's avatar
hrchilds committed
481
482
#endif

hrchilds's avatar
hrchilds committed
483
484
    listLayout->addRowSpacing(0, 10);

hrchilds's avatar
hrchilds committed
485
    exprListBox = new QListBox(f1);
hrchilds's avatar
hrchilds committed
486
    listLayout->addMultiCellWidget(exprListBox, 1,1, 0,1);
hrchilds's avatar
hrchilds committed
487

488
    newButton = new QPushButton(tr("New"), f1, "newButton");
hrchilds's avatar
hrchilds committed
489
    listLayout->addWidget(newButton, 2,0);
hrchilds's avatar
hrchilds committed
490

491
    delButton = new QPushButton(tr("Delete"), f1, "delButton");
hrchilds's avatar
hrchilds committed
492
    listLayout->addWidget(delButton, 2,1);
hrchilds's avatar
hrchilds committed
493

494
    displayAllVars = new QCheckBox(tr("Display expressions from database"), f1, "displayAllVars");
hrchilds's avatar
hrchilds committed
495
    listLayout->addMultiCellWidget(displayAllVars, 3,3, 0,1);
hrchilds's avatar
hrchilds committed
496
497
498
499

#ifndef USE_SPLITTER
    mainLayout->addSpacing(10);
    QGridLayout *editLayout = new QGridLayout(mainLayout, 6,2, 5, "editLayout");
hrchilds's avatar
hrchilds committed
500
    mainLayout->setStretchFactor(editLayout, 50);
hrchilds's avatar
hrchilds committed
501
502
#define f2 central
#else
503
    QGroupBox *f2 = new QGroupBox(tr("Definition"), mainSplitter);
hrchilds's avatar
hrchilds committed
504
    QGridLayout *editLayout = new QGridLayout(f2, 6,4, 7, 5, "editLayout");
hrchilds's avatar
hrchilds committed
505
506
507
#endif
    int row = 0;

hrchilds's avatar
hrchilds committed
508
509
510
    editLayout->addRowSpacing(row, 10);
    row++;

511
    nameEditLabel = new QLabel(tr("Name"), f2, "nameEditLabel");
hrchilds's avatar
hrchilds committed
512
513
514
    nameEdit = new QNarrowLineEdit(f2, "nameEdit");
    editLayout->addMultiCellWidget(nameEditLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(nameEdit, row,row, 1,3);
hrchilds's avatar
hrchilds committed
515
516
    row++;

517
    typeLabel = new QLabel(tr("Type"), f2, "typeLabel");
hrchilds's avatar
hrchilds committed
518
    typeList = new QComboBox(f2, "typeList");
519
520
521
522
523
524
525
526
527
    // Extracted from Expression::GetTypeString so we can internationalize.
    typeList->insertItem(tr("Scalar Mesh Variable"));
    typeList->insertItem(tr("Vector Mesh Variable"));
    typeList->insertItem(tr("Tensor Mesh Variable"));
    typeList->insertItem(tr("Symmetric Tensor Mesh Variable"));
    typeList->insertItem(tr("Array Mesh Variable"));
    typeList->insertItem(tr("Curve Mesh Variable"));
    //typeList->insertItem(tr("Mesh"));

hrchilds's avatar
hrchilds committed
528
529
    editLayout->addMultiCellWidget(typeLabel, row,row, 0,0);
    editLayout->addMultiCellWidget(typeList, row,row, 1,3);
hrchilds's avatar
hrchilds committed
530
531
    row++;

532
    definitionEditLabel = new QLabel(tr("Definition"), f2, "definitionEditLabel");
hrchilds's avatar
hrchilds committed
533
534
535
536
537
538
    editLayout->addWidget(definitionEditLabel, row, 0);
    row++;

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

542
    notHidden = new QCheckBox(tr("Show variable in plot menus"), f2, "notHidden");
hrchilds's avatar
hrchilds committed
543
    editLayout->addWidget(notHidden, row, 0);
hrchilds's avatar
hrchilds committed
544

545
    insertFunctionButton = new QPushButton(tr("Insert Function..."), f2);
hrchilds's avatar
hrchilds committed
546
    insertFunctionMenu = new QPopupMenu(f2, "insertFunctionMenu");
547
    for (int i=0; i < NUM_EXPRESSION_CATEGORIES; i++)
hrchilds's avatar
hrchilds committed
548
    {
549
        QPopupMenu *tmpMenu = new QPopupMenu(f2, exprlist[i].name.ascii());
hrchilds's avatar
hrchilds committed
550
551
        for (int j=0; exprlist[i].list[j]; j++)
        {
552
            if (exprlist[i].list[j]=="&")
553
                tmpMenu->insertItem("&&");
554
            else
555
                tmpMenu->insertItem(exprlist[i].list[j]);
hrchilds's avatar
hrchilds committed
556
557
558
559
560
        }
        insertFunctionMenu->insertItem(exprlist[i].name, tmpMenu);
        connect(tmpMenu, SIGNAL(activated(int)),
                this, SLOT(insertFunction(int)));
    }
hrchilds's avatar
hrchilds committed
561
    insertFunctionButton->setPopup(insertFunctionMenu);
hrchilds's avatar
hrchilds committed
562
563
564
565
566
567
568
    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);
569
    insertVariableButton->setText(tr("Insert Variable..."));
hrchilds's avatar
hrchilds committed
570
571
572
    connect(insertVariableButton, SIGNAL(activated(const QString &)),
            this, SLOT(insertVariable(const QString &)));
    editLayout->addWidget(insertVariableButton, row, 3);
hrchilds's avatar
hrchilds committed
573
    row++;
hrchilds's avatar
hrchilds committed
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588

    // 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
589
590
    connect(notHidden, SIGNAL(clicked()),
            this, SLOT(notHiddenChanged()));
hrchilds's avatar
hrchilds committed
591
592
    connect(displayAllVars, SIGNAL(clicked()),
            this, SLOT(displayAllVarsChanged()));
hrchilds's avatar
hrchilds committed
593
594
595
596
597
598
599
600
601
602
603
604
}

// ****************************************************************************
// 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
605
//           of whether or not they are selected.  Currently ignored.
hrchilds's avatar
hrchilds committed
606
//
hrchilds's avatar
hrchilds committed
607
608
609
610
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
611
612
613
614
//    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
615
//
616
617
618
//    Jeremy Meredith, Tue Feb 19 14:20:57 EST 2008
//    Don't display expressions that were created by operators.
//
hrchilds's avatar
hrchilds committed
619
620
621
622
623
624
625
// ****************************************************************************
void
QvisExpressionsWindow::UpdateWindow(bool)
{
    BlockAllSignals(true);

    exprListBox->clear();
hrchilds's avatar
hrchilds committed
626
627
    indexMap.clear();
    int pos = 0;
hrchilds's avatar
hrchilds committed
628
629
    for (int i=0; i<exprList->GetNumExpressions(); i++)
    {
630
631
        if (exprList->GetExpressions(i).GetFromOperator())
            continue;
hrchilds's avatar
hrchilds committed
632
        if (displayAllVars->isChecked() ||
hrchilds's avatar
hrchilds committed
633
            !exprList->GetExpressions(i).GetFromDB())
hrchilds's avatar
hrchilds committed
634
        {
hrchilds's avatar
hrchilds committed
635
            exprListBox->insertItem(exprList->GetExpressions(i).GetName().c_str());
hrchilds's avatar
hrchilds committed
636
            indexMap[pos++] = i;
hrchilds's avatar
hrchilds committed
637
638
639
640
641
642
643
644
645
        }
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSingleItem
hrchilds's avatar
hrchilds committed
646
//
hrchilds's avatar
hrchilds committed
647
648
//  Purpose:
//    Update the pane of the window where a single expression is being edited.
hrchilds's avatar
hrchilds committed
649
//
hrchilds's avatar
hrchilds committed
650
651
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
hrchilds's avatar
hrchilds committed
652
//
hrchilds's avatar
hrchilds committed
653
654
655
656
657
658
//  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
659
660
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
661
QvisExpressionsWindow::UpdateWindowSingleItem()
hrchilds's avatar
hrchilds committed
662
{
hrchilds's avatar
hrchilds committed
663
664
665
    BlockAllSignals(true);
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
666
    if (index <  0)
hrchilds's avatar
hrchilds committed
667
668
    {
        nameEdit->setText("");
hrchilds's avatar
hrchilds committed
669
        notHidden->setChecked(true);
hrchilds's avatar
hrchilds committed
670
671
672
        definitionEdit->setText("");
    }
    else
hrchilds's avatar
hrchilds committed
673
    {
hrchilds's avatar
hrchilds committed
674
675
        Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
676
        nameEdit->setText(e.GetName().c_str());
hrchilds's avatar
hrchilds committed
677
678
        notHidden->setChecked(! e.GetHidden());
        typeList->setCurrentText(Expression::GetTypeString(e.GetType()));
hrchilds's avatar
hrchilds committed
679
        definitionEdit->setText(e.GetDefinition().c_str());
hrchilds's avatar
hrchilds committed
680
    }
hrchilds's avatar
hrchilds committed
681
682
683
684
    
    UpdateWindowSensitivity();
    BlockAllSignals(false);
}
hrchilds's avatar
hrchilds committed
685

hrchilds's avatar
hrchilds committed
686
687
688
689
690
691
692
693
694
// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSensitivity
//
//  Purpose:
//    Update the sensitivity of any widget needing it.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
695
696
697
698
699
700
//  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
701
702
703
//    Brad Whitlock, Thu Dec 9 14:04:22 PST 2004
//    Added a button to insert variable names.
//
704
705
706
707
//    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
708
// ****************************************************************************
hrchilds's avatar
hrchilds committed
709

hrchilds's avatar
hrchilds committed
710
711
712
713
void
QvisExpressionsWindow::UpdateWindowSensitivity()
{
    bool enable = true;
hrchilds's avatar
hrchilds committed
714
715
716
    int index = exprListBox->currentItem();

    if (index <  0)
hrchilds's avatar
hrchilds committed
717
    {
hrchilds's avatar
hrchilds committed
718
719
        enable = false;
    }
hrchilds's avatar
hrchilds committed
720
    else if ((*exprList)[indexMap[index]].GetFromDB())
hrchilds's avatar
hrchilds committed
721
722
    {
        enable = false;
hrchilds's avatar
hrchilds committed
723
724
    }

hrchilds's avatar
hrchilds committed
725
726
    nameEdit->setEnabled(enable);
    delButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
727
    notHidden->setEnabled(enable);
hrchilds's avatar
hrchilds committed
728
    typeList->setEnabled(enable);
729
    definitionEdit->setReadOnly(!enable);
hrchilds's avatar
hrchilds committed
730
    insertFunctionButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
731
    insertVariableButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
}

// ****************************************************************************
//  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
753
754
755
756
757
758
759
760
}

// ****************************************************************************
// Method: QvisExpressionsWindow::Apply
//
// Purpose: 
//   This is a Qt slot function that is called when the Apply button is clicked.
//
hrchilds's avatar
hrchilds committed
761
762
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
763
764
765
766
767
768
769
770
771
772
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::Apply(bool forceUpdate)
{
    exprList->Notify();

    if (AutoUpdate() || forceUpdate)
hrchilds's avatar
hrchilds committed
773
        GetViewerMethods()->ProcessExpressions();
hrchilds's avatar
hrchilds committed
774
775
776
777
778
779
780
781
782
}

// ****************************************************************************
// 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
783
784
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
785
786
787
788
789
790
791
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::apply()
{
hrchilds's avatar
hrchilds committed
792
793
794
795
796
    // 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
797
    Apply(true);
hrchilds's avatar
hrchilds committed
798
799
800
801
802
803
804
805
806

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

// ****************************************************************************
// Method: QvisExpressionsWindow::addExpression
//
// Purpose: 
//   This is a Qt slot function that adds a new expression that is empty.
//
hrchilds's avatar
hrchilds committed
815
816
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
817
818
//
// Modifications:
hrchilds's avatar
hrchilds committed
819
820
821
//    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
822
823
824
825
826
//   
// ****************************************************************************
void
QvisExpressionsWindow::addExpression()
{
hrchilds's avatar
hrchilds committed
827
828
829
830
831
832
833
834
835
836
837
838
    // 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
839

hrchilds's avatar
hrchilds committed
840
841
842
    Expression e;
    e.SetName(newName.latin1());
    e.SetDefinition("");
hrchilds's avatar
hrchilds committed
843
    exprList->AddExpressions(e);
hrchilds's avatar
hrchilds committed
844
845

    exprList->Notify();
hrchilds's avatar
hrchilds committed
846
847
848
849
850
851

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

// ****************************************************************************
hrchilds's avatar
hrchilds committed
855
// Method: QvisExpressionsWindow::delExpression
hrchilds's avatar
hrchilds committed
856
857
858
859
//
// Purpose: 
//   This is a Qt slot function that is called to delete an expression.
//
hrchilds's avatar
hrchilds committed
860
861
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
862
863
//
// Modifications:
hrchilds's avatar
hrchilds committed
864
865
866
867
//    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
868
869
870
//   
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
871
QvisExpressionsWindow::delExpression()
hrchilds's avatar
hrchilds committed
872
{
hrchilds's avatar
hrchilds committed
873
874
    int index = exprListBox->currentItem();

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

hrchilds's avatar
hrchilds committed
878
    exprList->RemoveExpressions(indexMap[index]);
hrchilds's avatar
hrchilds committed
879
880
881

    exprList->Notify();
}
hrchilds's avatar
hrchilds committed
882
883
884
885
886
887
888
889
890
891
892

// ****************************************************************************
//  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
893
894
895
896
897
//  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
898
899
900
901
902
903
// ****************************************************************************
void
QvisExpressionsWindow::definitionTextChanged()
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
904
    if (index <  0)
hrchilds's avatar
hrchilds committed
905
906
        return;

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

hrchilds's avatar
hrchilds committed
909
    e.SetDefinition(definitionEdit->text().latin1());
hrchilds's avatar
hrchilds committed
910
911
912
913
914
915
916
917
918
919
920
921
922
923
}

// ****************************************************************************
//  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
924
925
926
927
928
//  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
929
930
931
932
//    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
933
934
935
936
937
938
// ****************************************************************************
void
QvisExpressionsWindow::nameTextChanged(const QString &text)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
939
    if (index <  0)
hrchilds's avatar
hrchilds committed
940
941
        return;

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

hrchilds's avatar
hrchilds committed
944
    QString newname = text.stripWhiteSpace();
hrchilds's avatar
hrchilds committed
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959

    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
960
    e.SetName(newname.latin1());
hrchilds's avatar
hrchilds committed
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    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
978
979
980
981
982
//  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
983
984
985
986
987
988
// ****************************************************************************
void
QvisExpressionsWindow::typeChanged(int value)
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
989
    if (index <  0)
hrchilds's avatar
hrchilds committed
990
991
        return;

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

hrchilds's avatar
hrchilds committed
994
995
    // Add one because we skipped index 0 (unknown) when creating the
    // list box originally
hrchilds's avatar
hrchilds committed
996
    e.SetType(Expression::ExprType(value+1));
hrchilds's avatar
hrchilds committed
997
998
999
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
1000
//  Method:  QvisExpressionsWindow::notHiddenChanged
hrchilds's avatar
hrchilds committed
1001
1002
//
//  Purpose:
hrchilds's avatar
hrchilds committed
1003
1004
//    Slot function for the notHidden toggle.
//    Sets the "notHidden" flag of an expression.
hrchilds's avatar
hrchilds committed
1005
1006
1007
1008
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
1009
1010
1011
1012
1013
1014
//  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
1015
1016
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
1017
QvisExpressionsWindow::notHiddenChanged()
hrchilds's avatar
hrchilds committed
1018
1019
1020
{
    int index = exprListBox->currentItem();

hrchilds's avatar
hrchilds committed
1021
    if (index <  0)
hrchilds's avatar
hrchilds committed
1022
1023
        return;

hrchilds's avatar
hrchilds committed
1024
1025
1026
    Expression &e = (*exprList)[indexMap[index]];

    e.SetHidden(!notHidden->isChecked());
hrchilds's avatar
hrchilds committed
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
}

// ****************************************************************************
//  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
1039
1040
1041
1042
//  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
1043
1044
1045
1046
// ****************************************************************************
void
QvisExpressionsWindow::displayAllVarsChanged()
{
hrchilds's avatar
hrchilds committed
1047
1048
1049
1050
1051
    // 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
1052
    UpdateWindow(true);
hrchilds's avatar
hrchilds committed
1053
1054
1055
1056
1057
1058
1059
1060
1061

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
            if (exprListBox->text(i) == item)
                exprListBox->setSelected(i, true);
        }
    }
hrchilds's avatar
hrchilds committed
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
}

// ****************************************************************************
//  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
1077
1078
1079
1080
1081
//  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
1082
1083
1084
//    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
1085
1086
1087
//    Hank Childs, Sun Jan 22 12:49:57 PST 2006
//    Add special insertion code for complicated expressions.
//
hrchilds's avatar
hrchilds committed
1088
1089
1090
1091
//    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
1092
1093
1094
//    Hank Childs, Mon Mar 13 16:48:23 PST 2006
//    Added min and max.
//
hrchilds's avatar
hrchilds committed
1095
1096
1097
//    Hank Childs, Fri Dec 22 10:31:40 PST 2006
//    Added symm_point.
//
hrchilds's avatar
hrchilds committed
1098
1099
1100
//    Hank Childs, Fri Jan 12 13:20:33 PST 2007
//    Added array_compose and array_compose_with_bins.
//
hrchilds's avatar
hrchilds committed
1101
1102
1103
//    Hank Childs, Sat Mar 17 15:33:54 PDT 2007
//    Fix problem with specmf.
//
hrchilds's avatar
hrchilds committed
1104
1105
1106
//    Brad Whitlock, Mon Apr 23 17:35:13 PST 2007
//    Added color expression.
//
1107
1108
1109
//    Cyrus Harrison, Thu Jan 31 09:45:30 PST 2008
//    Added value_for_material
//
1110
1111
1112
//    Jeremy Meredith, Wed Feb 13 12:27:50 EST 2008
//    Added enumerate
//
1113
1114
1115
//    Jeremy Meredith, Wed Feb 20 10:01:59 EST 2008
//    Added cell_constant and point_constant.
//
1116
1117
//    Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
//    Added support for '&' bitwise binary and operation
hrchilds's avatar
hrchilds committed
1118
// ****************************************************************************
hrchilds's avatar
hrchilds committed
1119

hrchilds's avatar
hrchilds committed
1120
1121
1122
1123
1124
1125
void
QvisExpressionsWindow::insertFunction(int id)
{
    if (!definitionEdit->isEnabled())
        return;

hrchilds's avatar
hrchilds committed
1126
    bool doParens = (insertFunctionMenu->text(id).length() >= 2);
1127
1128
1129
1130

    if (insertFunctionMenu->text(id) == "&&")
    {
        definitionEdit->insert("&");
1131
        doParens = false;
1132
1133
1134
1135
1136
1137
    }
    else
    {
        definitionEdit->insert(insertFunctionMenu->text(id));
    }

hrchilds's avatar
hrchilds committed
1138
    std::string str = insertFunctionMenu->text(id).latin1();
hrchilds's avatar
hrchilds committed
1139
1140
1141
1142
1143
1144
1145
    if (str == "conn_cmfe")
    {
        definitionEdit->insert("(<filename:var>, <meshname>)");
        doParens = false;
    }
    else if (str == "pos_cmfe")
    {
hrchilds's avatar
hrchilds committed
1146
        definitionEdit->insert("(<filename:var>, <meshname>, <default-var>)");
hrchilds's avatar
hrchilds committed
1147
1148
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1149
1150
1151
1152
1153
    else if (str == "symm_point")
    {
        definitionEdit->insert("(<var>, [Px, Py, Pz])");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
    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
1167
        definitionEdit->insert("(<material-object-name>, [#, #, ... #])");
hrchilds's avatar
hrchilds committed
1168
1169
1170
1171
        doParens = false;
    }
    else if (str == "specmf")
    {
hrchilds's avatar
hrchilds committed
1172
        definitionEdit->insert("(<species-variable-name>, <material-name-or-number>, [#, #, ... #])");
hrchilds's avatar
hrchilds committed
1173
1174
1175
1176
1177
1178
1179
        doParens = false;
    }
    else if (str == "if")
    {
        definitionEdit->insert("(<condition>, <then-var>, <else-var>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1180
1181
    else if (str == "min" || str == "max" || str == "cross" || str == "mod" ||
             str == "and" || str == "or")
hrchilds's avatar
hrchilds committed
1182
1183
1184
1185
    {
        definitionEdit->insert("(<var1>, <var2>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
    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
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
    else if(str == "color4")
    {
        definitionEdit->insert("(<var1>, <var2>, <var3>, <var4>)");
        doParens = false;      
    }
    else if(str == "color")
    {
        definitionEdit->insert("(<var1>, <var2>, <var3>)");
        doParens = false;      
    }
1212
1213
1214
1215
1216
    else if(str == "value_for_material")
    {
        definitionEdit->insert("(<var>, <material-name-or-number>)");
        doParens = false;
    }
1217
1218
1219
1220
1221
    else if (str == "enumerate")
    {
        definitionEdit->insert("(<var>, [<val-if-0>, <val-if-1>, ...])");
        doParens = false;
    }
1222
1223
1224
1225
1226
    else if (str == "cell_constant" || str == "point_constant")
    {
        definitionEdit->insert("(<meshvar>, <constantvalue>)");
        doParens = false;
    }
hrchilds's avatar
hrchilds committed
1227
1228

    if (doParens)
hrchilds's avatar
hrchilds committed
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
    {
        definitionEdit->insert("()");

        int col,line;
        definitionEdit->getCursorPosition(&line, &col);
        col--;
        if (col < 0)
            col = 0;
        definitionEdit->setCursorPosition(line, col);
    }
hrchilds's avatar
hrchilds committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257

    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
1258
1259
1260
//    Jeremy M