QvisExpressionsWindow.C 43.9 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>

whitlocb's avatar
whitlocb committed
45
46
47
48
49
50
51
52
53
54
55
56
#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QListWidget>
#include <QTextEdit>
#include <QMenu>
#include <QPushButton>
#include <QSplitter>
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.
//
146
147
148
//    Hank Childs, Mon Dec 29 11:56:50 PST 2008
//    Added dominant_mat.
//
hrchilds's avatar
hrchilds committed
149
150
151
//    Hank Childs, Sun Feb 22 08:56:33 PST 2009
//    Added category for time iterating expressions.
//
152
153
154
//    Jeremy Meredith, Mon Mar 16 14:40:13 EDT 2009
//    Added timestep and cycle.
//
155
156
157
//    Kathleen Bonnell, Mon Apr 27 17:35:25 PDT 2009
//    Added sinh, cosh, tanh to expr_trig.
//
hrchilds's avatar
hrchilds committed
158
// ****************************************************************************
hrchilds's avatar
hrchilds committed
159

hrchilds's avatar
hrchilds committed
160
161
struct ExprNameList
{
162
    QString      name;
hrchilds's avatar
hrchilds committed
163
164
165
166
167
168
169
170
    const char **list;
};

const char *expr_meshquality[] = {
    "aspect",
    "aspect_gamma",
    "condition",
    "degree",
171
172
173
    "diagonal_ratio",
    "min_diagonal",
    "max_diagonal",
hrchilds's avatar
hrchilds committed
174
175
    "dimension",
    "jacobian",
hrchilds's avatar
hrchilds committed
176
177
    "max_edge_length",
    "max_side_volume",
brugger's avatar
 
brugger committed
178
    "maximum_angle",
hrchilds's avatar
hrchilds committed
179
180
    "min_edge_length",
    "min_side_volume",
brugger's avatar
 
brugger committed
181
    "minimum_angle",
hrchilds's avatar
hrchilds committed
182
183
184
185
186
187
188
189
190
191
192
193
    "neighbor",
    "node_degree",
    "oddy",
    "relative_size",
    "scaled_jacobian",
    "shape",
    "shape_and_size",
    "shear",
    "skew",
    "stretch",
    "taper",
    "warpage",
194
195
    "face_planarity",
    "relative_face_planarity",
hrchilds's avatar
hrchilds committed
196
197
198
199
200
    NULL
};

const char *expr_math[] = {
    "abs",
hrchilds's avatar
hrchilds committed
201
202
    "ceil",
    "floor",
203
    "exp",
hrchilds's avatar
hrchilds committed
204
205
    "ln",
    "log10",
hrchilds's avatar
hrchilds committed
206
207
    "max",
    "min",
hrchilds's avatar
hrchilds committed
208
209
    "mod",
    "round",
hrchilds's avatar
hrchilds committed
210
211
    "sqr",
    "sqrt",
212
    "random",
hrchilds's avatar
hrchilds committed
213
214
215
216
217
    "+",
    "-",
    "*",
    "/",
    "^",
218
    "&",
hrchilds's avatar
hrchilds committed
219
220
221
    NULL
};

hrchilds's avatar
hrchilds committed
222
const char *expr_relational[] = {
hrchilds's avatar
hrchilds committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
    "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",
249
    "cosh",
hrchilds's avatar
hrchilds committed
250
251
252
    "deg2rad",
    "rad2deg",
    "sin",
253
    "sinh",
hrchilds's avatar
hrchilds committed
254
    "tan",
255
    "tanh",
hrchilds's avatar
hrchilds committed
256
257
258
259
    NULL
};

const char *expr_vector[] = {
hrchilds's avatar
hrchilds committed
260
261
    "color",
    "color4",
262
    "colorlookup",
hrchilds's avatar
hrchilds committed
263
264
    "cross",
    "dot",
265
    "hsvcolor",
hrchilds's avatar
hrchilds committed
266
    "magnitude",
hrchilds's avatar
hrchilds committed
267
    "normalize",
hrchilds's avatar
hrchilds committed
268
269
270
271
    NULL
};

const char *expr_tensor[] = {
272
    "contraction",
hrchilds's avatar
hrchilds committed
273
274
275
276
277
278
279
280
281
    "determinant",
    "effective_tensor",
    "eigenvalue",
    "eigenvector",
    "inverse",
    "principal_deviatoric_tensor",
    "principal_tensor",
    "tensor_maximum_shear",
    "trace",
hrchilds's avatar
hrchilds committed
282
    "transpose",
283
    "viscous_stress",
hrchilds's avatar
hrchilds committed
284
285
286
    NULL
};

hrchilds's avatar
hrchilds committed
287
288
const char *expr_array[] = {
    "array_compose",
hrchilds's avatar
hrchilds committed
289
    "array_compose_with_bins",
hrchilds's avatar
hrchilds committed
290
291
292
293
    "array_decompose",
    NULL
};

hrchilds's avatar
hrchilds committed
294
const char *expr_materials[] = {
295
    "dominant_mat",
hrchilds's avatar
hrchilds committed
296
    "materror",
hrchilds's avatar
hrchilds committed
297
298
299
    "matvf",
    "nmats",
    "specmf",
300
    "value_for_material",
hrchilds's avatar
hrchilds committed
301
302
303
304
305
306
    NULL
};

const char *expr_mesh[] = {
    "area",
    "coord",
hrchilds's avatar
hrchilds committed
307
308
309
    "cylindrical",
    "cylindrical_radius",
    "cylindrical_theta",
hrchilds's avatar
hrchilds committed
310
    "external_node",
hrchilds's avatar
hrchilds committed
311
312
313
    "global_nodeid",
    "global_zoneid",
    "nodeid",
hrchilds's avatar
hrchilds committed
314
    "polar",
hrchilds's avatar
hrchilds committed
315
316
317
    "polar_radius",
    "polar_theta",
    "polar_phi",
hrchilds's avatar
hrchilds committed
318
319
320
    "revolved_surface_area",
    "revolved_volume",
    "volume",
hrchilds's avatar
hrchilds committed
321
    "zoneid",
hrchilds's avatar
hrchilds committed
322
    "zonetype",
hrchilds's avatar
hrchilds committed
323
324
325
326
    NULL
};

const char *expr_misc[] = {
327
    "cell_constant",
hrchilds's avatar
hrchilds committed
328
    "conn_components",
hrchilds's avatar
hrchilds committed
329
    "curl",
330
    "cycle",
hrchilds's avatar
hrchilds committed
331
    "divergence",
332
    "enumerate",
hrchilds's avatar
hrchilds committed
333
    "gauss_curvature",
hrchilds's avatar
hrchilds committed
334
    "gradient",
hrchilds's avatar
hrchilds committed
335
336
    "ij_gradient",
    "ijk_gradient",
hrchilds's avatar
hrchilds committed
337
    "Laplacian",
hrchilds's avatar
hrchilds committed
338
    "mean_curvature",
339
    "point_constant",
hrchilds's avatar
hrchilds committed
340
    "recenter",
hrchilds's avatar
hrchilds committed
341
    "resrad",
hrchilds's avatar
hrchilds committed
342
343
344
    "surface_normal",
    "   point_surface_normal",
    "   cell_surface_normal",
hrchilds's avatar
hrchilds committed
345
    "time",
346
    "timestep",
hrchilds's avatar
hrchilds committed
347
348
349
    NULL
};

hrchilds's avatar
hrchilds committed
350
const char *expr_imageprocessing[] = {
hrchilds's avatar
hrchilds committed
351
    "abel_inversion",
hrchilds's avatar
hrchilds committed
352
353
354
355
356
357
    "conservative_smoothing",
    "mean_filter",
    "median_filter",
    NULL
};

hrchilds's avatar
hrchilds committed
358
359
360
const char *expr_comparison[] = {
    "conn_cmfe",
    "pos_cmfe",
hrchilds's avatar
hrchilds committed
361
    "symm_point",
hrchilds's avatar
hrchilds committed
362
363
364
365
366
    "symm_plane",
    "symm_transform",
    NULL
};

hrchilds's avatar
hrchilds committed
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
const char *expr_time_iteration[] = {
    "average_over_time",
    "cycle_at_minimum",
    "cycle_at_maximum",
    "first_cycle_when_condition_is_true",
    "first_time_when_condition_is_true",
    "first_time_index_when_condition_is_true",
    "last_cycle_when_condition_is_true",
    "last_time_when_condition_is_true",
    "last_time_index_when_condition_is_true",
    "min_over_time", 
    "max_over_time", 
    "sum_over_time", 
    "time_at_minimum",
    "time_at_maximum",
    "time_index_at_minimum",
    "time_index_at_maximum",
    "value_at_minimum",
    "value_at_maximum",
    "var_when_condition_is_first_true",
    "var_when_condition_is_last_true",
    NULL
};

#define NUM_EXPRESSION_CATEGORIES 15
392
ExprNameList exprlist[NUM_EXPRESSION_CATEGORIES];
hrchilds's avatar
hrchilds committed
393

hrchilds's avatar
hrchilds committed
394
395
396
397
398
399
400
401
402
403
// ****************************************************************************
// Method: QvisExpressionsWindow::QvisExpressionsWindow
//
// Purpose: 
//   This is the constructor for the QvisExpressionsWindow class.
//
// Arguments:
//   exprList_  The ExpressionList subject to observe
//   
//
hrchilds's avatar
hrchilds committed
404
405
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
406
//
407
408
409
410
// Modifications:
//   Brad Whitlock, Tue Apr  8 12:15:08 PDT 2008
//   Support for internationalization.
//
hrchilds's avatar
hrchilds committed
411
412
413
//   Hank Childs, Sun Feb 22 09:01:29 PST 2009
//   Add time iteration category.
//
hrchilds's avatar
hrchilds committed
414
// ****************************************************************************
415

hrchilds's avatar
hrchilds committed
416
QvisExpressionsWindow::QvisExpressionsWindow(
417
418
    ExpressionList *exprList_, const QString &caption,
    const QString &shortName, QvisNotepadArea *notepad) :
hrchilds's avatar
hrchilds committed
419
420
421
422
    QvisPostableWindowObserver(exprList_, caption, shortName, notepad,
                               QvisPostableWindowObserver::ApplyButton,
                               false)
{
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
    // 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
453
454
    exprlist[14].name = tr("Time Iteration");
    exprlist[14].list = expr_time_iteration;
455

hrchilds's avatar
hrchilds committed
456
457
458
459
460
461
462
463
464
    exprList = exprList_;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::~QvisExpressionsWindow
//
// Purpose: 
//   Destructor for the QvisExpressionsWindow class.
//
hrchilds's avatar
hrchilds committed
465
466
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
//
// Modifications:
//   
// ****************************************************************************
QvisExpressionsWindow::~QvisExpressionsWindow()
{
    exprList = NULL;
}

// ****************************************************************************
// Method: QvisExpressionsWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
hrchilds's avatar
hrchilds committed
482
483
484
485
486
// 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
487
488
//
// Modifications:
hrchilds's avatar
hrchilds committed
489
490
491
492
493
494
495
496
//    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
497
498
499
//    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
500
501
502
//    Hank Childs, Thu Jul 21 11:12:43 PDT 2005
//    Add support for array mesh variables.
//
hrchilds's avatar
hrchilds committed
503
504
505
//    Kathleen Bonnell, Thu Aug  3 08:42:33 PDT 2006 
//    Changed numtypes to 7 to support CurveMeshVar.
//
506
507
508
//    Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//    Support for internationalization.
//
509
510
//    Mark C. Miller, Mon Apr 14 15:41:21 PDT 2008
//    Added '&' bitwise binary and operation
511
//
whitlocb's avatar
whitlocb committed
512
513
514
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
515
516
517
518
//    Jeremy Meredith, Thu Aug  7 15:37:17 EDT 2008
//    changed an erroneous pointer-based string comparison to a true
//    string based comparison.
//
hrchilds's avatar
hrchilds committed
519
// ****************************************************************************
hrchilds's avatar
hrchilds committed
520

hrchilds's avatar
hrchilds committed
521
522
523
void
QvisExpressionsWindow::CreateWindowContents()
{
whitlocb's avatar
whitlocb committed
524

hrchilds's avatar
hrchilds committed
525
526
527
    QSplitter *mainSplitter = new QSplitter(central);
    topLayout->addWidget(mainSplitter);
    topLayout->setStretchFactor(mainSplitter, 100);
whitlocb's avatar
whitlocb committed
528
529
530
    
    QGroupBox *f1 = new QGroupBox(tr("Expression List"));
    QGridLayout *listLayout = new QGridLayout(f1);
hrchilds's avatar
hrchilds committed
531

whitlocb's avatar
whitlocb committed
532
533
    exprListBox = new QListWidget(f1);
    listLayout->addWidget(exprListBox, 1,0, 1,2);
hrchilds's avatar
hrchilds committed
534

whitlocb's avatar
whitlocb committed
535
    newButton = new QPushButton(tr("New"), f1);
hrchilds's avatar
hrchilds committed
536
    listLayout->addWidget(newButton, 2,0);
hrchilds's avatar
hrchilds committed
537

whitlocb's avatar
whitlocb committed
538
    delButton = new QPushButton(tr("Delete"), f1);
hrchilds's avatar
hrchilds committed
539
    listLayout->addWidget(delButton, 2,1);
hrchilds's avatar
hrchilds committed
540

whitlocb's avatar
whitlocb committed
541
542
543
544
545
546
547
548
    displayAllVars = new QCheckBox(tr("Display expressions from database"), f1);
    listLayout->addWidget(displayAllVars, 3,0, 1,2);

    mainSplitter->addWidget(f1);
    
    QGroupBox *f2 = new QGroupBox(tr("Definition"));
    QGridLayout *editLayout = new QGridLayout(f2);
    
hrchilds's avatar
hrchilds committed
549
550
    int row = 0;

hrchilds's avatar
hrchilds committed
551
552
    row++;

whitlocb's avatar
whitlocb committed
553
554
555
556
    nameEditLabel = new QLabel(tr("Name"), f2);
    nameEdit = new QNarrowLineEdit(f2);
    editLayout->addWidget(nameEditLabel, row,0, 1,1);
    editLayout->addWidget(nameEdit, row,1, 1,3);
hrchilds's avatar
hrchilds committed
557
558
    row++;

whitlocb's avatar
whitlocb committed
559
560
    typeLabel = new QLabel(tr("Type"), f2);
    typeList = new QComboBox(f2);
561
    // Extracted from Expression::GetTypeString so we can internationalize.
whitlocb's avatar
whitlocb committed
562
563
564
565
566
567
568
569
570
    typeList->addItem(tr("Scalar Mesh Variable"));
    typeList->addItem(tr("Vector Mesh Variable"));
    typeList->addItem(tr("Tensor Mesh Variable"));
    typeList->addItem(tr("Symmetric Tensor Mesh Variable"));
    typeList->addItem(tr("Array Mesh Variable"));
    typeList->addItem(tr("Curve Mesh Variable"));

    editLayout->addWidget(typeLabel, row,0, 1,1);
    editLayout->addWidget(typeList, row,1, 1,3);
hrchilds's avatar
hrchilds committed
571
572
    row++;

whitlocb's avatar
whitlocb committed
573
    definitionEditLabel = new QLabel(tr("Definition"), f2);
hrchilds's avatar
hrchilds committed
574
575
576
    editLayout->addWidget(definitionEditLabel, row, 0);
    row++;

whitlocb's avatar
whitlocb committed
577
578
    definitionEdit = new QTextEdit(f2);
    editLayout->addWidget(definitionEdit, row,0,1,4);
hrchilds's avatar
hrchilds committed
579
580
    row++;

whitlocb's avatar
whitlocb committed
581
    notHidden = new QCheckBox(tr("Show variable in plot menus"), f2);
hrchilds's avatar
hrchilds committed
582
    editLayout->addWidget(notHidden, row, 0);
hrchilds's avatar
hrchilds committed
583

whitlocb's avatar
whitlocb committed
584
585
    insertFunctionButton = new QPushButton(tr("Insert Function..."));
    insertFunctionMenu = new QMenu(f2);
586
    for (int i=0; i < NUM_EXPRESSION_CATEGORIES; i++)
hrchilds's avatar
hrchilds committed
587
    {
whitlocb's avatar
whitlocb committed
588
        QMenu *submnu = insertFunctionMenu->addMenu(exprlist[i].name);
hrchilds's avatar
hrchilds committed
589
590
        for (int j=0; exprlist[i].list[j]; j++)
        {
591
            if (std::string(exprlist[i].list[j])=="&")
whitlocb's avatar
whitlocb committed
592
                submnu->addAction("&&");
593
            else
whitlocb's avatar
whitlocb committed
594
                submnu->addAction(exprlist[i].list[j]);
hrchilds's avatar
hrchilds committed
595
        }
whitlocb's avatar
whitlocb committed
596
597
598
        connect(submnu, SIGNAL(triggered(QAction *)),
                this, SLOT(insertFunction(QAction *)));
        
hrchilds's avatar
hrchilds committed
599
    }
whitlocb's avatar
whitlocb committed
600
    insertFunctionButton->setMenu(insertFunctionMenu);
hrchilds's avatar
hrchilds committed
601
602
603
604
    editLayout->addWidget(insertFunctionButton, row, 2);

    // Create a variable button so we can insert variables for the
    // active source.
whitlocb's avatar
whitlocb committed
605
    insertVariableButton = new QvisVariableButton(false, false, false, -1, f2);
hrchilds's avatar
hrchilds committed
606
    insertVariableButton->setChangeTextOnVariableChange(false);
607
    insertVariableButton->setText(tr("Insert Variable..."));
hrchilds's avatar
hrchilds committed
608
609
610
    connect(insertVariableButton, SIGNAL(activated(const QString &)),
            this, SLOT(insertVariable(const QString &)));
    editLayout->addWidget(insertVariableButton, row, 3);
hrchilds's avatar
hrchilds committed
611
    row++;
whitlocb's avatar
whitlocb committed
612
613
    
    mainSplitter->addWidget(f2);
hrchilds's avatar
hrchilds committed
614
615
    // connect signals

whitlocb's avatar
whitlocb committed
616
    connect(exprListBox, SIGNAL(itemSelectionChanged()),
hrchilds's avatar
hrchilds committed
617
618
619
620
621
622
623
624
625
626
627
            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
628
629
    connect(notHidden, SIGNAL(clicked()),
            this, SLOT(notHiddenChanged()));
hrchilds's avatar
hrchilds committed
630
631
    connect(displayAllVars, SIGNAL(clicked()),
            this, SLOT(displayAllVarsChanged()));
hrchilds's avatar
hrchilds committed
632
633
634
635
636
637
638
639
640
641
642
643
}

// ****************************************************************************
// 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
644
//           of whether or not they are selected.  Currently ignored.
hrchilds's avatar
hrchilds committed
645
//
hrchilds's avatar
hrchilds committed
646
647
648
649
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
650
651
652
653
//    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
654
//
655
656
657
//    Jeremy Meredith, Tue Feb 19 14:20:57 EST 2008
//    Don't display expressions that were created by operators.
//
whitlocb's avatar
whitlocb committed
658
659
660
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
661
662
663
664
665
666
667
// ****************************************************************************
void
QvisExpressionsWindow::UpdateWindow(bool)
{
    BlockAllSignals(true);

    exprListBox->clear();
hrchilds's avatar
hrchilds committed
668
669
    indexMap.clear();
    int pos = 0;
hrchilds's avatar
hrchilds committed
670
671
    for (int i=0; i<exprList->GetNumExpressions(); i++)
    {
672
673
        if (exprList->GetExpressions(i).GetFromOperator())
            continue;
hrchilds's avatar
hrchilds committed
674
        if (displayAllVars->isChecked() ||
hrchilds's avatar
hrchilds committed
675
            !exprList->GetExpressions(i).GetFromDB())
hrchilds's avatar
hrchilds committed
676
        {
whitlocb's avatar
whitlocb committed
677
            exprListBox->addItem(exprList->GetExpressions(i).GetName().c_str());
hrchilds's avatar
hrchilds committed
678
            indexMap[pos++] = i;
hrchilds's avatar
hrchilds committed
679
680
681
682
683
684
685
686
687
        }
    }
    BlockAllSignals(false);

    UpdateWindowSingleItem();
}

// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSingleItem
hrchilds's avatar
hrchilds committed
688
//
hrchilds's avatar
hrchilds committed
689
690
//  Purpose:
//    Update the pane of the window where a single expression is being edited.
hrchilds's avatar
hrchilds committed
691
//
hrchilds's avatar
hrchilds committed
692
693
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
hrchilds's avatar
hrchilds committed
694
//
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.
//
whitlocb's avatar
whitlocb committed
701
702
703
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
704
705
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
706
QvisExpressionsWindow::UpdateWindowSingleItem()
hrchilds's avatar
hrchilds committed
707
{
hrchilds's avatar
hrchilds committed
708
    BlockAllSignals(true);
whitlocb's avatar
whitlocb committed
709
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
710
    if (index <  0)
hrchilds's avatar
hrchilds committed
711
712
    {
        nameEdit->setText("");
hrchilds's avatar
hrchilds committed
713
        notHidden->setChecked(true);
hrchilds's avatar
hrchilds committed
714
715
716
        definitionEdit->setText("");
    }
    else
hrchilds's avatar
hrchilds committed
717
    {
hrchilds's avatar
hrchilds committed
718
719
        Expression &e = (*exprList)[indexMap[index]];

hrchilds's avatar
hrchilds committed
720
        nameEdit->setText(e.GetName().c_str());
hrchilds's avatar
hrchilds committed
721
        notHidden->setChecked(! e.GetHidden());
whitlocb's avatar
whitlocb committed
722
723
        int tidx = typeList->findText(Expression::GetTypeString(e.GetType()));
        typeList->setCurrentIndex(tidx);
hrchilds's avatar
hrchilds committed
724
        definitionEdit->setText(e.GetDefinition().c_str());
hrchilds's avatar
hrchilds committed
725
    }
hrchilds's avatar
hrchilds committed
726
727
728
729
    
    UpdateWindowSensitivity();
    BlockAllSignals(false);
}
hrchilds's avatar
hrchilds committed
730

hrchilds's avatar
hrchilds committed
731
732
733
734
735
736
737
738
739
// ****************************************************************************
//  Method:  QvisExpressionsWindow::UpdateWindowSensitivity
//
//  Purpose:
//    Update the sensitivity of any widget needing it.
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
740
741
742
743
744
745
//  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
746
747
748
//    Brad Whitlock, Thu Dec 9 14:04:22 PST 2004
//    Added a button to insert variable names.
//
749
750
751
752
//    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.
//
whitlocb's avatar
whitlocb committed
753
754
755
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
756
// ****************************************************************************
hrchilds's avatar
hrchilds committed
757

hrchilds's avatar
hrchilds committed
758
759
760
761
void
QvisExpressionsWindow::UpdateWindowSensitivity()
{
    bool enable = true;
whitlocb's avatar
whitlocb committed
762
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
763
764

    if (index <  0)
hrchilds's avatar
hrchilds committed
765
    {
hrchilds's avatar
hrchilds committed
766
767
        enable = false;
    }
hrchilds's avatar
hrchilds committed
768
    else if ((*exprList)[indexMap[index]].GetFromDB())
hrchilds's avatar
hrchilds committed
769
770
    {
        enable = false;
hrchilds's avatar
hrchilds committed
771
772
    }

hrchilds's avatar
hrchilds committed
773
774
    nameEdit->setEnabled(enable);
    delButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
775
    notHidden->setEnabled(enable);
hrchilds's avatar
hrchilds committed
776
    typeList->setEnabled(enable);
777
    definitionEdit->setReadOnly(!enable);
hrchilds's avatar
hrchilds committed
778
    insertFunctionButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
779
    insertVariableButton->setEnabled(enable);
hrchilds's avatar
hrchilds committed
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
}

// ****************************************************************************
//  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
801
802
803
804
805
806
807
808
}

// ****************************************************************************
// Method: QvisExpressionsWindow::Apply
//
// Purpose: 
//   This is a Qt slot function that is called when the Apply button is clicked.
//
hrchilds's avatar
hrchilds committed
809
810
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
811
812
813
814
815
816
817
818
819
820
//
// Modifications:
//   
// ****************************************************************************
void
QvisExpressionsWindow::Apply(bool forceUpdate)
{
    exprList->Notify();

    if (AutoUpdate() || forceUpdate)
hrchilds's avatar
hrchilds committed
821
        GetViewerMethods()->ProcessExpressions();
hrchilds's avatar
hrchilds committed
822
823
824
825
826
827
828
829
830
}

// ****************************************************************************
// 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
831
832
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
833
834
//
// Modifications:
whitlocb's avatar
whitlocb committed
835
836
837
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
838
839
840
841
//    Jeremy Meredith, Tue Jun  2 10:40:48 EDT 2009
//    Fix null pointer dereference when there's no current item (e.g. empty
//    window).
//
hrchilds's avatar
hrchilds committed
842
843
844
845
// ****************************************************************************
void
QvisExpressionsWindow::apply()
{
hrchilds's avatar
hrchilds committed
846
847
    // Apply will recreate the window and unselect the current expression.
    // If we have an expression selected, reselect it afterwards.
848
849
850
851
    bool reselect = (exprListBox->currentRow() != -1);
    QString item;
    if (reselect)
        item = exprListBox->currentItem()->text();
whitlocb's avatar
whitlocb committed
852
    
hrchilds's avatar
hrchilds committed
853
    Apply(true);
hrchilds's avatar
hrchilds committed
854
855
856
857
858

    if (reselect)
    {
        for (int i=0; i<exprListBox->count(); i++)
        {
whitlocb's avatar
whitlocb committed
859
860
861
862
863
864
865
            if (exprListBox->item(i)->text() == item)
            {
                exprListBox->item(i)->setSelected(true);
                exprListBox->setCurrentRow(i);
                UpdateWindowSingleItem();
                break;
            }
hrchilds's avatar
hrchilds committed
866
867
        }
    }
hrchilds's avatar
hrchilds committed
868
869
870
871
872
873
874
875
}

// ****************************************************************************
// Method: QvisExpressionsWindow::addExpression
//
// Purpose: 
//   This is a Qt slot function that adds a new expression that is empty.
//
hrchilds's avatar
hrchilds committed
876
877
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
878
879
//
// Modifications:
hrchilds's avatar
hrchilds committed
880
881
882
//    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.
whitlocb's avatar
whitlocb committed
883
884
885
886
//
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
887
888
889
890
// ****************************************************************************
void
QvisExpressionsWindow::addExpression()
{
hrchilds's avatar
hrchilds committed
891
892
893
894
895
896
897
    // Find an unused expression name
    int newid = 1;
    bool okay = false;
    QString newName;
    while (!okay)
    {
        newName.sprintf("unnamed%d", newid);
whitlocb's avatar
whitlocb committed
898
        if ((*exprList)[newName.toStdString().c_str()])
hrchilds's avatar
hrchilds committed
899
900
901
902
            newid++;
        else
            okay = true;
    }
hrchilds's avatar
hrchilds committed
903

hrchilds's avatar
hrchilds committed
904
    Expression e;
whitlocb's avatar
whitlocb committed
905
    e.SetName(newName.toStdString());
hrchilds's avatar
hrchilds committed
906
    e.SetDefinition("");
hrchilds's avatar
hrchilds committed
907
    exprList->AddExpressions(e);
hrchilds's avatar
hrchilds committed
908
909

    exprList->Notify();
hrchilds's avatar
hrchilds committed
910
911
912

    for (int i=0; i<exprListBox->count(); i++)
    {
whitlocb's avatar
whitlocb committed
913
914
915
916
917
918
919
        if (exprListBox->item(i)->text() == newName)
        {
            exprListBox->item(i)->setSelected(true);
            exprListBox->setCurrentRow(i);
            UpdateWindowSingleItem();
            break;
        }
hrchilds's avatar
hrchilds committed
920
    }
hrchilds's avatar
hrchilds committed
921
922
923
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
924
// Method: QvisExpressionsWindow::delExpression
hrchilds's avatar
hrchilds committed
925
926
927
928
//
// Purpose: 
//   This is a Qt slot function that is called to delete an expression.
//
hrchilds's avatar
hrchilds committed
929
930
// Programmer: Jeremy Meredith
// Creation:   October 10, 2004
hrchilds's avatar
hrchilds committed
931
932
//
// Modifications:
hrchilds's avatar
hrchilds committed
933
934
935
936
//    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
937
//   
whitlocb's avatar
whitlocb committed
938
939
940
941
942
943
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
//    Cyrus Harrison, Mon Jul 21 16:22:30 PDT 2008
//    Fixed a crash when last expression was deleted. 
//
hrchilds's avatar
hrchilds committed
944
945
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
946
QvisExpressionsWindow::delExpression()
hrchilds's avatar
hrchilds committed
947
{
whitlocb's avatar
whitlocb committed
948
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
949

hrchilds's avatar
hrchilds committed
950
    if (index <  0)
hrchilds's avatar
hrchilds committed
951
952
        return;

hrchilds's avatar
hrchilds committed
953
    exprList->RemoveExpressions(indexMap[index]);
hrchilds's avatar
hrchilds committed
954
    exprList->Notify();
whitlocb's avatar
whitlocb committed
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
    
    // try to select sensible expression:
    // if del expr was last expr: before 
    // else: after
    
    int nrows = exprListBox->count();
    
    if(nrows > 0)
    {
        if(index == nrows)
            index--;
        exprListBox->item(index)->setSelected(true);
        exprListBox->setCurrentRow(index);
        UpdateWindowSingleItem();
    }
    
hrchilds's avatar
hrchilds committed
971
}
hrchilds's avatar
hrchilds committed
972
973
974
975
976
977
978
979
980
981
982

// ****************************************************************************
//  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
983
984
985
986
987
//  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.
//
whitlocb's avatar
whitlocb committed
988
989
990
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
991
992
993
994
// ****************************************************************************
void
QvisExpressionsWindow::definitionTextChanged()
{
whitlocb's avatar
whitlocb committed
995
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
996

hrchilds's avatar
hrchilds committed
997
    if (index <  0)
hrchilds's avatar
hrchilds committed
998
999
        return;

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

whitlocb's avatar
whitlocb committed
1002
    e.SetDefinition(definitionEdit->toPlainText().toStdString());
hrchilds's avatar
hrchilds committed
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
}

// ****************************************************************************
//  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
1017
1018
1019
1020
1021
//  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
1022
1023
1024
1025
//    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)
//
whitlocb's avatar
whitlocb committed
1026
1027
1028
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
1029
1030
1031
1032
// ****************************************************************************
void
QvisExpressionsWindow::nameTextChanged(const QString &text)
{
whitlocb's avatar
whitlocb committed
1033
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
1034

hrchilds's avatar
hrchilds committed
1035
    if (index <  0)
hrchilds's avatar
hrchilds committed
1036
1037
        return;

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

whitlocb's avatar
whitlocb committed
1040
    QString newname = text.trimmed();
hrchilds's avatar
hrchilds committed
1041
1042
1043
1044
1045
1046
1047
1048

    if (newname.isEmpty())
    {
        int newid = 1;
        bool okay = false;
        while (!okay)
        {
            newname.sprintf("unnamed%d", newid);
whitlocb's avatar
whitlocb committed
1049
            if ((*exprList)[newname.toStdString().c_str()])
hrchilds's avatar
hrchilds committed
1050
1051
1052
1053
1054
1055
                newid++;
            else
                okay = true;
        }
    }

whitlocb's avatar
whitlocb committed
1056
    e.SetName(newname.toStdString());
hrchilds's avatar
hrchilds committed
1057
    BlockAllSignals(true);
whitlocb's avatar
whitlocb committed
1058
    exprListBox->item(index)->setText(newname);
hrchilds's avatar
hrchilds committed
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
    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
1074
1075
1076
1077
1078
//  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.
//
whitlocb's avatar
whitlocb committed
1079
1080
1081
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
1082
1083
1084
1085
// ****************************************************************************
void
QvisExpressionsWindow::typeChanged(int value)
{
whitlocb's avatar
whitlocb committed
1086
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
1087

hrchilds's avatar
hrchilds committed
1088
    if (index <  0)
hrchilds's avatar
hrchilds committed
1089
1090
        return;

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

hrchilds's avatar
hrchilds committed
1093
1094
    // Add one because we skipped index 0 (unknown) when creating the
    // list box originally
hrchilds's avatar
hrchilds committed
1095
    e.SetType(Expression::ExprType(value+1));
hrchilds's avatar
hrchilds committed
1096
1097
1098
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
1099
//  Method:  QvisExpressionsWindow::notHiddenChanged
hrchilds's avatar
hrchilds committed
1100
1101
//
//  Purpose:
hrchilds's avatar
hrchilds committed
1102
1103
//    Slot function for the notHidden toggle.
//    Sets the "notHidden" flag of an expression.
hrchilds's avatar
hrchilds committed
1104
1105
1106
1107
//
//  Programmer:  Jeremy Meredith
//  Creation:    October 10, 2004
//
hrchilds's avatar
hrchilds committed
1108
1109
1110
1111
1112
1113
//  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.
//
whitlocb's avatar
whitlocb committed
1114
1115
1116
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
1117
1118
// ****************************************************************************
void
hrchilds's avatar
hrchilds committed
1119
QvisExpressionsWindow::notHiddenChanged()
hrchilds's avatar
hrchilds committed
1120
{
whitlocb's avatar
whitlocb committed
1121
    int index = exprListBox->currentRow();
hrchilds's avatar
hrchilds committed
1122

hrchilds's avatar
hrchilds committed
1123
    if (index <  0)
hrchilds's avatar
hrchilds committed
1124
1125
        return;

hrchilds's avatar
hrchilds committed
1126
1127
1128
    Expression &e = (*exprList)[indexMap[index]];

    e.SetHidden(!notHidden->isChecked());
hrchilds's avatar
hrchilds committed
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
}

// ****************************************************************************
//  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
1141
1142
1143
1144
//  Modifications:
//    Jeremy Meredith, Mon Oct 25 13:33:35 PDT 2004
//    Made it reselect an expression that was already selected, like Apply.
//
whitlocb's avatar
whitlocb committed
1145
1146
1147
//    Cyrus Harrison, Wed Jun 11 13:49:19 PDT 2008
//    Initial Qt4 Port.
//
1148
1149
1150
1151
//    Cyrus Harrison, Tue Jul 14 16:02:15 PDT 2009
//    Fixed crash when no user expressions are defined and the user clicks
//    show database expressions.
//
hrchilds's avatar
hrchilds committed
1152
1153
1154
1155
// ****************************************************************************
void
QvisExpressionsWindow::displayAllVarsChanged()
{
1156

hrchilds's avatar
hrchilds committed
1157
1158
    // This updates the window, which rebuilds the expression list.
    // If we have an expression selected, reselect it afterwards.
whitlocb's avatar
whitlocb committed
1159
    int reselect = (exprListBox->currentRow() != -1);
1160
1161
1162
1163
1164
1165
    
    QString item ="";
    
    if (reselect)
        item = exprListBox->currentItem()->text();
    
hrchilds's avatar
hrchilds committed
1166
    UpdateWindow(true);
hrchilds's avatar
hrchilds committed
1167
1168
1169

    if (reselect)
    {
1170
1171
        QString item = exprListBox->currentItem()->text();
        
hrchilds's avatar
hrchilds committed
1172
1173