ViewerQueryManager.C 182 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2011, 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-442911
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 40 41 42 43
// ************************************************************************* //
//                          ViewerQueryManager.C                             //
// ************************************************************************* //

#include <ViewerQueryManager.h>
44
#include <snprintf.h>
hrchilds's avatar
hrchilds committed
45 46 47
#include <avtColorTables.h>
#include <avtDatabaseMetaData.h>
#include <avtToolInterface.h>
hrchilds's avatar
hrchilds committed
48
#include <avtSILRestrictionTraverser.h>
hrchilds's avatar
hrchilds committed
49
#include <avtTypes.h>
hrchilds's avatar
hrchilds committed
50 51
#include <DatabaseCorrelation.h>
#include <DatabaseCorrelationList.h>
hrchilds's avatar
hrchilds committed
52
#include <DataNode.h>
hrchilds's avatar
hrchilds committed
53
#include <DebugStream.h>
54
#include <EngineList.h>
hrchilds's avatar
hrchilds committed
55
#include <InvalidVariableException.h>
hrchilds's avatar
hrchilds committed
56
#include <GlobalAttributes.h>
hrchilds's avatar
hrchilds committed
57 58 59 60 61
#include <LineoutListItem.h>
#include <LostConnectionException.h>
#include <NoEngineException.h>
#include <OperatorPluginManager.h>
#include <PickAttributes.h>
hrchilds's avatar
hrchilds committed
62
#include <PickVarInfo.h>
hrchilds's avatar
hrchilds committed
63 64 65
#include <PlotPluginManager.h>
#include <QueryAttributes.h>
#include <QueryList.h>
hrchilds's avatar
hrchilds committed
66
#include <QueryOverTimeAttributes.h>
hrchilds's avatar
hrchilds committed
67 68
#include <ViewerActionManager.h>
#include <ViewerEngineManager.h>
hrchilds's avatar
hrchilds committed
69
#include <ParsingExprList.h>
hrchilds's avatar
hrchilds committed
70 71 72 73 74
#include <ViewerFileServer.h>
#include <ViewerOperator.h>
#include <ViewerOperatorFactory.h>
#include <ViewerPlot.h>
#include <ViewerPlotList.h>
75
#include <ViewerProperties.h>
hrchilds's avatar
hrchilds committed
76 77 78 79 80
#include <ViewerQuery.h>
#include <ViewerWindow.h>
#include <ViewerWindowManager.h>
#include <GlobalLineoutAttributes.h>
#include <VisItException.h>
hrchilds's avatar
hrchilds committed
81 82 83
#include <ViewerSubject.h>
extern ViewerSubject *viewerSubject;

84 85 86 87 88 89 90 91 92 93 94
#include <float.h>
#include <math.h>
#include <stdio.h>

#include <set>
#include <string>
#include <vector>

using std::set;
using std::string;
using std::vector;
hrchilds's avatar
hrchilds committed
95

hrchilds's avatar
hrchilds committed
96 97 98 99 100
// File wide modifications:
//   Brad Whitlock, Tue Jan 27 16:41:32 PST 2004
//   I removed all instances of ViewerAnimation.
//
// ****************************************************************************
hrchilds's avatar
hrchilds committed
101

hrchilds's avatar
hrchilds committed
102 103 104 105 106 107 108 109 110 111

// ****************************************************************************
//  Modifications:
//
//    Hank Childs, Mon Jul 25 08:23:55 PDT 2005
//    I added QUERY_ARRAY_VAR.  Note the ordering of the defines here must 
//    exactly match that in avtTypes.h.
//
// ****************************************************************************

hrchilds's avatar
hrchilds committed
112 113 114 115 116
#define QUERY_MESH_VAR              0x0001
#define QUERY_SCALAR_VAR            0x0002
#define QUERY_VECTOR_VAR            0x0004
#define QUERY_TENSOR_VAR            0x0008
#define QUERY_SYMMETRIC_TENSOR_VAR  0x0010
hrchilds's avatar
hrchilds committed
117 118 119 120 121 122
#define QUERY_ARRAY_VAR             0x0020
#define QUERY_LABEL_VAR             0x0040
#define QUERY_MATERIAL_VAR          0x0080
#define QUERY_MATSPECIES_VAR        0x0100
#define QUERY_CURVE_VAR             0x0200
#define QUERY_UNKNOWN_VAR           0x0400
hrchilds's avatar
hrchilds committed
123 124 125



hrchilds's avatar
hrchilds committed
126 127 128 129 130 131 132 133
//
// Storage for static data elements.
//

ViewerQueryManager *ViewerQueryManager::instance = 0;   

QueryAttributes *ViewerQueryManager::queryClientAtts=0;
PickAttributes *ViewerQueryManager::pickAtts=0;
hrchilds's avatar
hrchilds committed
134
PickAttributes *ViewerQueryManager::pickDefaultAtts=0;
hrchilds's avatar
hrchilds committed
135
PickAttributes *ViewerQueryManager::pickClientAtts=0;
hrchilds's avatar
hrchilds committed
136 137
GlobalLineoutAttributes *ViewerQueryManager::globalLineoutAtts=0;
GlobalLineoutAttributes *ViewerQueryManager::globalLineoutClientAtts=0;
hrchilds's avatar
hrchilds committed
138 139 140
QueryOverTimeAttributes *ViewerQueryManager::timeQueryAtts=0;
QueryOverTimeAttributes *ViewerQueryManager::timeQueryDefaultAtts=0;
QueryOverTimeAttributes *ViewerQueryManager::timeQueryClientAtts=0;
hrchilds's avatar
hrchilds committed
141

hrchilds's avatar
hrchilds committed
142 143
void
GetUniqueVars(const stringVector &vars, const string &activeVar, 
hrchilds's avatar
hrchilds committed
144 145
              stringVector &uniqueVars,
              const avtDatabaseMetaData *md = NULL);
hrchilds's avatar
hrchilds committed
146
string
147 148 149 150
CreateExtentsString(const double * extents, 
                    const int dim,
                    const char *type,
                    const string &float_format);
hrchilds's avatar
hrchilds committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179

// ****************************************************************************
//  Method: ViewerQueryManager constructor
//
//  Programmer: Kathleen Bonnell 
//  Creation:   June 10, 2002 
//
//  Modifications:
//    Brad Whitlock, Fri Sep 6 14:06:57 PST 2002
//    I added the queryTypes member.
//
//    Kathleen Bonnell, Mon Sep 30 14:38:33 PDT 2002 
//    Add Revolved volume to query list, comment out currently unsupported
//    queries WorldPick, WorldLineout and MinMax. 
//
//    Kathleen Bonnell, Fri Nov 15 17:44:44 PST 2002  
//    Add Eulerian to query list. 
//
//    Kathleen Bonnell, Fri Dec 20 09:48:48 PST 2002  
//    Enable WorldLineout in the query list.  Initialize new members
//    baseDesignator, cycleDesignator, designator.
//
//    Kathleen Bonnell, Mon Dec 23 13:19:38 PST 2002
//    Removed ScreenSpace designation from Lineout query.  Removed WorldLineout
//    from query list.
//
//    Kathleen Bonnell, Tue Feb 25 17:11:18 PST 2003
//    Check for loaded Curve and Lineout plugins before adding Lineout to the
//    query list. 
hrchilds's avatar
hrchilds committed
180
//
hrchilds's avatar
hrchilds committed
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
//    Jeremy Meredith, Fri Feb 28 12:36:21 PST 2003
//    Made it use PluginAvailable instead of PluginLoaded so that it could
//    attempt to load the plugins on demand.
//
//    Kathleen Bonnell, Thu Mar  6 15:21:45 PST 2003  
//    Store Lineout queries (ViewerQuery) in LineoutListItem.
//
//    Brad Whitlock, Wed Mar 12 14:41:24 PST 2003
//    I initialized the operatorFactory member.
//
//    Hank Childs, Tue Mar 18 21:33:09 PST 2003
//    Added revolved surface area.
//
//    Kathleen Bonnell, Wed Mar 26 14:37:23 PST 2003 
//    Initialize preparingPick, handlingCache, initialPick. 
//
//    Jeremy Meredith, Sat Apr 12 11:31:53 PDT 2003
//    Added compactness queries.
//
hrchilds's avatar
hrchilds committed
200 201 202 203
//    Kathleen Bonnell, Fri Jun 27 15:54:30 PDT 2003
//    Renamed Pick query to ZonePick, added NodePick query. 
//    Initialize pickAtts. 
//
hrchilds's avatar
hrchilds committed
204 205 206
//    Kathleen Bonnell, Wed Jul 23 16:26:34 PDT 2003 
//    Added 'Variable by Zone', 'WorldPick' and 'WorldNodePick'. 
//
hrchilds's avatar
hrchilds committed
207 208 209 210
//    Kathleen Bonnell, Mon Sep 15 13:09:19 PDT 2003 
//    Moved initialization of queryTypes to its own method, so that it can
//    be called after plugins are loaded (lineout dependent upon plugins). 
//
hrchilds's avatar
hrchilds committed
211 212 213
//    Kathleen Bonnell, Thu Jul 22 15:43:56 PDT 2004 
//    Initialize globalLineoutAtts, initialize resWinId in lineoutCache.
//
hrchilds's avatar
hrchilds committed
214 215 216
//    Kathleen Bonnell, Wed Jul 27 15:47:34 PDT 2005 
//    Added suppressQueryOutput. 
//
hrchilds's avatar
hrchilds committed
217 218 219
//    Kathleen Bonnell, Wed Aug 10 16:46:17 PDT 2005 
//    Added activePlotsChanged. 
//
hrchilds's avatar
hrchilds committed
220 221 222
//    Brad Whitlock, Mon Feb 12 17:45:24 PST 2007
//    Added ViewerBase base class.
//
223 224 225
//    Cyrus Harrison, Tue Sep 18 11:01:57 PDT 2007
//    Added init of floatFormat.
//
hrchilds's avatar
hrchilds committed
226 227
// ****************************************************************************

whitlocb's avatar
whitlocb committed
228
ViewerQueryManager::ViewerQueryManager() : ViewerBase(0)
hrchilds's avatar
hrchilds committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
{
    lineoutList    = 0;
    nLineouts      = 0;
    nLineoutsAlloc = 0;
    colorIndex     = 0;

    baseDesignator = 'A';
    cycleDesignator = false;
    designator = new char[4];
    SNPRINTF(designator, 4, "%c", baseDesignator);

    // Create the query list.
    queryTypes = new QueryList;

    operatorFactory = 0;


    initialPick = false;
    preparingPick = false;
    handlingCache = false;
hrchilds's avatar
hrchilds committed
249
    pickAtts = new PickAttributes();
hrchilds's avatar
hrchilds committed
250
    timeQueryAtts = new QueryOverTimeAttributes();
hrchilds's avatar
hrchilds committed
251
    globalLineoutAtts = new GlobalLineoutAttributes();
hrchilds's avatar
hrchilds committed
252 253

    lineoutCache.origWin = NULL;
hrchilds's avatar
hrchilds committed
254
    lineoutCache.resWinId = -1;
hrchilds's avatar
hrchilds committed
255 256

    suppressQueryOutput = false;
hrchilds's avatar
hrchilds committed
257
    activePlotsChanged = true;
258
    floatFormat = "%g";
hrchilds's avatar
hrchilds committed
259 260 261 262 263 264 265 266 267 268 269 270 271
}


// ****************************************************************************
//  Method: ViewerQueryManager::Instance
//
//  Purpose:
//    Return a pointer to the sole instance of the ViewerQueryManager
//    class.
//
//  Returns:    A pointer to the sole instance of the ViewerQueryManager
//              class.
//
hrchilds's avatar
hrchilds committed
272 273
//  Programmer: Kathleen Bonnell
//  Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
274 275
//
// ****************************************************************************
hrchilds's avatar
hrchilds committed
276

hrchilds's avatar
hrchilds committed
277 278 279 280 281 282 283 284 285 286
ViewerQueryManager *
ViewerQueryManager::Instance()
{
    //
    // If the sole instance hasn't been instantiated, then instantiate it.
    //
    if (instance == 0)
    {
        instance = new ViewerQueryManager;
    }
hrchilds's avatar
hrchilds committed
287

hrchilds's avatar
hrchilds committed
288 289 290 291 292 293 294
    return instance;
}


// ****************************************************************************
//  Method: ViewerQueryManager destructor
//
hrchilds's avatar
hrchilds committed
295 296
//  Programmer: Kathleen Bonnell
//  Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
297 298 299 300 301
//
//  Modifications:
//    Brad Whitlock, Fri Sep 6 14:10:42 PST 2002
//    I added the queryTypes member.
//
hrchilds's avatar
hrchilds committed
302 303
//    Kathleen Bonnell, Fri Dec 20 09:48:48 PST 2002
//    Delete designator.
hrchilds's avatar
hrchilds committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
//
// ****************************************************************************

ViewerQueryManager::~ViewerQueryManager()
{
    int i;
    //
    // Delete the list and any queries in the queries list.
    //
    if (nLineoutsAlloc > 0)
    {
        for (i = 0; i < nLineouts; i++)
        {
            delete lineoutList[i];
        }
        delete [] lineoutList;
    }

    delete queryTypes;
    delete [] designator;
}

// ****************************************************************************
// Method: ViewerQueryManager::SetOperatorFactory
//
hrchilds's avatar
hrchilds committed
329
// Purpose:
hrchilds's avatar
hrchilds committed
330 331 332 333 334 335 336 337 338
//   Sets the query manager's operator factory pointer.
//
// Arguments:
//   factory : A pointer to the operator factory.
//
// Programmer: Brad Whitlock
// Creation:   Wed Mar 12 15:33:58 PST 2003
//
// Modifications:
hrchilds's avatar
hrchilds committed
339
//
hrchilds's avatar
hrchilds committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
// ****************************************************************************

void
ViewerQueryManager::SetOperatorFactory(ViewerOperatorFactory *factory)
{
    operatorFactory = factory;
}

// ****************************************************************************
//  Method: ViewerQueryManager::AddQuery
//
//  Purpose:
//    Add a query to the query list.
//
//  Arguments:
hrchilds's avatar
hrchilds committed
355
//    origWin   A pointer to the window that originated the query.
hrchilds's avatar
hrchilds committed
356 357
//    lineAtts  The Line attributes to be used for the query.
//
hrchilds's avatar
hrchilds committed
358 359
//  Programmer: Kathleen Bonnell
//  Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
360 361
//
//  Modifications:
hrchilds's avatar
hrchilds committed
362
//    Kathleen Bonnell, Fri Jul 12 18:42:11 PDT 2002
hrchilds's avatar
hrchilds committed
363 364
//    Added call to UpdateScaleFactor.
//
hrchilds's avatar
hrchilds committed
365
//    Kathleen Bonnell, Tue Oct  1 16:25:50 PDT 2002
hrchilds's avatar
hrchilds committed
366
//    Changed argument to ValidateQuery from color to Line*, to convey more
hrchilds's avatar
hrchilds committed
367
//    information.
hrchilds's avatar
hrchilds committed
368 369 370 371
//
//    Brad Whitlock, Wed Nov 20 13:28:18 PST 2002
//    Changed how colors are selected.
//
hrchilds's avatar
hrchilds committed
372
//    Kathleen Bonnell, Fri Dec 20 09:48:48 PST 2002
hrchilds's avatar
hrchilds committed
373 374 375 376 377 378 379
//    Added calls to set the designator for lineAtts, and to UpdateDesignator.
//    Added argument to ValidateQuery call.
//
//    Brad Whitlock, Thu Feb 27 14:55:42 PST 2003
//    I added code to update the actions so the toolbars and menus in the
//    new window get updated properly.
//
hrchilds's avatar
hrchilds committed
380 381
//    Kathleen Bonnell, Thu Mar  6 15:21:45 PST 2003
//    Updated to use ViewerQuery_p, added more args to SimpleAddQuery.
hrchilds's avatar
hrchilds committed
382
//    Removed call to ValidateQuery, now handled in ViewerQuery.
hrchilds's avatar
hrchilds committed
383 384 385 386 387 388 389
//
//    Kathleen Bonnell, Fri Mar 14 17:11:42 PST 2003
//    Added test of variable passed in LineAtts.
//
//    Kathleen Bonnell, Wed Apr 23 11:38:47 PDT 2003
//    Allow MATSPECIES var type.
//
hrchilds's avatar
hrchilds committed
390 391 392
//    Eric Brugger, Wed Aug 20 11:05:54 PDT 2003
//    I removed a call to UpdateScaleFactor since it no longer exists.
//
hrchilds's avatar
hrchilds committed
393
//    Kathleen Bonnell, Thu Sep 11 12:04:26 PDT 2003
hrchilds's avatar
hrchilds committed
394 395 396
//    Added optional bool arg that indicates if lineout should be initialized
//    with its default atts or its client atts.
//
hrchilds's avatar
hrchilds committed
397 398 399
//    Hank Childs, Thu Oct  2 14:22:16 PDT 2003
//    Account for multiple active plots.
//
hrchilds's avatar
hrchilds committed
400 401 402
//    Brad Whitlock, Fri Mar 26 08:42:11 PDT 2004
//    I made it use strings.
//
hrchilds's avatar
hrchilds committed
403 404 405
//    Mark C. Miller, Mon Jul 12 19:46:32 PDT 2004
//    Made call to GetLineoutWindow fail if the window doesn't already exist
//
hrchilds's avatar
hrchilds committed
406 407 408 409 410
//    Kathleen Bonnell, Thu Jul 22 15:38:39 PDT 2004
//    Change call from GetLineoutWindow to GetWindow, as the needed window
//    for Lineout should already exist at this point, and its ID is stored
//    in lineoutCache.
//
hrchilds's avatar
hrchilds committed
411 412 413
//    Kathleen Bonnell, Tue May 15 14:04:22 PDT 2007 
//    Added optional bool arg forceSampling. 
//
414 415 416
//    Brad Whitlock, Tue Apr 29 16:29:13 PDT 2008
//    Support for internationalization.
//
hrchilds's avatar
hrchilds committed
417 418 419
// ****************************************************************************

void
hrchilds's avatar
hrchilds committed
420
ViewerQueryManager::AddQuery(ViewerWindow *origWin, Line *lineAtts,
hrchilds's avatar
hrchilds committed
421
                             const bool fromDefault, const bool forceSampling)
hrchilds's avatar
hrchilds committed
422
{
hrchilds's avatar
hrchilds committed
423 424
    intVector plotIDs;
    origWin->GetPlotList()->GetActivePlotIDs(plotIDs);
hrchilds's avatar
hrchilds committed
425
    //
hrchilds's avatar
hrchilds committed
426
    // Is there an active non-hidden plot in the originating window?
hrchilds's avatar
hrchilds committed
427
    //
hrchilds's avatar
hrchilds committed
428
    if (plotIDs.size() == 0)
hrchilds's avatar
hrchilds committed
429
    {
430 431 432
        QString msg = tr("Lineout requires an active non-hidden plot. "
                         "Please select a plot and try again.");
        Error(msg);
hrchilds's avatar
hrchilds committed
433 434
        return;
    }
hrchilds's avatar
hrchilds committed
435 436 437
    // Use the first plot.
    int plotId = plotIDs[0];

hrchilds's avatar
hrchilds committed
438
    //
hrchilds's avatar
hrchilds committed
439
    // Is there a valid variable?
hrchilds's avatar
hrchilds committed
440
    //
hrchilds's avatar
hrchilds committed
441
    ViewerPlot *oplot = origWin->GetPlotList()->GetPlot(plotId);
hrchilds's avatar
hrchilds committed
442
    string vname(lineAtts->GetVarName());
hrchilds's avatar
hrchilds committed
443
    if (vname == "default")
hrchilds's avatar
hrchilds committed
444
        vname = oplot->GetVariableName();
hrchilds's avatar
hrchilds committed
445
    avtVarType varType = oplot->GetVarType(vname);
hrchilds's avatar
hrchilds committed
446
    if (varType != AVT_SCALAR_VAR &&
hrchilds's avatar
hrchilds committed
447
        varType != AVT_MATSPECIES)
hrchilds's avatar
hrchilds committed
448
    {
449 450
        QString message = tr("Lineout requires scalar variable.  "
                             "%1 is not scalar.").arg(vname.c_str());
hrchilds's avatar
hrchilds committed
451 452 453
        Error(message);
        return;
    }
hrchilds's avatar
hrchilds committed
454

hrchilds's avatar
hrchilds committed
455
    //
hrchilds's avatar
hrchilds committed
456
    // Can we get a lineout window?
hrchilds's avatar
hrchilds committed
457
    //
hrchilds's avatar
hrchilds committed
458
    ViewerWindow *resWin = ViewerWindowManager::Instance()->
hrchilds's avatar
hrchilds committed
459
        GetWindow(lineoutCache.resWinId);
hrchilds's avatar
hrchilds committed
460 461
    if (resWin == NULL)
    {
hrchilds's avatar
hrchilds committed
462
        ResetLineoutCache();
hrchilds's avatar
hrchilds committed
463 464 465 466 467 468 469 470 471 472
        return;
    }

    //
    // Set the color to use for the query.
    //
    lineAtts->SetColor(GetColor());
    lineAtts->SetDesignator(designator);


hrchilds's avatar
hrchilds committed
473 474
    ViewerQuery_p newQuery = new ViewerQuery(origWin, resWin, lineAtts, 
        fromDefault, forceSampling);
hrchilds's avatar
hrchilds committed
475 476
    if(*newQuery == NULL)
    {
477
        Error(tr("VisIt could not create the desired plot."));
hrchilds's avatar
hrchilds committed
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
        return;
    }

    //
    // Add the new query to the lineout list.
    //
    SimpleAddQuery(newQuery, oplot, origWin, resWin);

    UpdateDesignator();

    //
    // Update the actions so the menus and the toolbars have the right state.
    //
    ViewerWindowManager::Instance()->UpdateActions();

    // Brad Whitlock, Fri Apr 4 15:24:28 PST 2003
    // Do it again because for some reason, even though the curve vis window
    // gets the right values, the actual toolbar and popup menu are not
    // updating. If we ever figure out the problem, remove this code.
    resWin->GetActionManager()->UpdateSingleWindow();
}


// ****************************************************************************
// Method: ViewerQueryManager::SimpleAddQuery
//
hrchilds's avatar
hrchilds committed
504
// Purpose:
hrchilds's avatar
hrchilds committed
505 506 507 508
//   Adds the query to the lineout list.  Expand the list if necessary.
//
// Arguments:
//   query     The created query.
hrchilds's avatar
hrchilds committed
509 510 511
//   oplot     The plot that originated the query.
//   owin      The window that originated the query.
//   rwin      The window where the results will be drawn.
hrchilds's avatar
hrchilds committed
512
//
hrchilds's avatar
hrchilds committed
513 514
// Programmer: Kathleen Bonnell
// Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
515 516
//
// Modifications:
hrchilds's avatar
hrchilds committed
517
//   Kathleen Bonnell, Wed Jul 31 16:43:43 PDT 2002
hrchilds's avatar
hrchilds committed
518 519
//   Fix bad argument to sizeof for memcpy.
//
hrchilds's avatar
hrchilds committed
520
//   Kathleen Bonnell, Thu Mar  6 15:21:45 PST 2003
hrchilds's avatar
hrchilds committed
521 522
//   Reworked to reflect that lineout queries stored in LineoutList.
//
hrchilds's avatar
hrchilds committed
523
//   Kathleen Bonnell, Fri Feb  4 07:10:27 PST 2005
hrchilds's avatar
hrchilds committed
524
//   Tell the lineouts whether or not to follow time, and whether or not to
hrchilds's avatar
hrchilds committed
525
//   use a time slider.
hrchilds's avatar
hrchilds committed
526
//
hrchilds's avatar
hrchilds committed
527 528 529
//   Kathleen Bonnell, Tue Jan 17 11:30:15 PST 2006
//   Removed call to SetTimeSlider.
//
hrchilds's avatar
hrchilds committed
530
//   Kathleen Bonnell, Thu Nov  2 13:52:00 PST 2006
hrchilds's avatar
hrchilds committed
531 532
//   Added test for FreezeInTime when determining if lineout FollwowsTime.
//
hrchilds's avatar
hrchilds committed
533 534 535
// ****************************************************************************

void
hrchilds's avatar
hrchilds committed
536
ViewerQueryManager::SimpleAddQuery(ViewerQuery_p query, ViewerPlot *oplot,
hrchilds's avatar
hrchilds committed
537 538 539 540
                                   ViewerWindow *owin, ViewerWindow *rwin)
{
    int i, index = -1;

hrchilds's avatar
hrchilds committed
541
    GlobalLineoutAttributes *gla = GetGlobalLineoutAtts();
hrchilds's avatar
hrchilds committed
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
    //
    //  Determine the correct list.
    //
    for (i = 0; i < nLineouts && index == -1; i++)
    {
        if (lineoutList[i]->Matches(oplot, owin, rwin))
        {
            index = i;
        }
    }
    if (index == -1)
    {
        if (nLineouts >= nLineoutsAlloc)
        {
            //
            // Expand the lineout list if necessary.
            //
            LineoutListItem **lineoutsNew=0;

            nLineoutsAlloc += 2;
            lineoutsNew= new LineoutListItem*[nLineoutsAlloc];
            for (i = 0; i < nLineoutsAlloc; i++)
            {
hrchilds's avatar
hrchilds committed
565
                lineoutsNew[i] = NULL;
hrchilds's avatar
hrchilds committed
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
            }

            if (nLineouts > 0)
            {
                for (i = 0; i < nLineouts; i++)
                {
                    lineoutsNew[i] = new LineoutListItem(*(lineoutList[i]));
                    delete lineoutList[i];
                }
                delete [] lineoutList;
            }

            lineoutList = lineoutsNew;
        }
        index = nLineouts;
        LineoutListItem loli(oplot, owin, rwin);
        if (lineoutList[index] == NULL)
        {
            lineoutList[index] = new LineoutListItem(loli);
        }
        else
        {
            *(lineoutList[index]) = loli;
        }
        //
hrchilds's avatar
hrchilds committed
591
        // Observe the originating plot if necessary.
hrchilds's avatar
hrchilds committed
592
        //
hrchilds's avatar
hrchilds committed
593
        if (gla->GetDynamic())
hrchilds's avatar
hrchilds committed
594 595 596 597 598 599 600 601 602 603
        {
            lineoutList[index]->ObserveOriginatingPlot();
        }
        nLineouts++;
    }

    //
    // Add the query to the correct list.
    //
    lineoutList[index]->AddQuery(query);
hrchilds's avatar
hrchilds committed
604 605 606 607

    //
    // Tell it whether or not to follow time.
    //
hrchilds's avatar
hrchilds committed
608
    if (gla->GetDynamic() &&
hrchilds's avatar
hrchilds committed
609 610 611 612
        gla->GetCurveOption() == GlobalLineoutAttributes::CreateCurve)
    {
        lineoutList[index]->SetLineoutsFollowTime(false);
    }
hrchilds's avatar
hrchilds committed
613 614 615 616
    else if (gla->GetFreezeInTime())
    {
        lineoutList[index]->SetLineoutsFollowTime(false);
    }
hrchilds's avatar
hrchilds committed
617 618 619 620
    else
    {
        lineoutList[index]->SetLineoutsFollowTime(true);
    }
hrchilds's avatar
hrchilds committed
621 622 623 624 625 626 627
}


// ****************************************************************************
//  Method: ViewerQueryManager::Delete
//
//  Purpose:
hrchilds's avatar
hrchilds committed
628 629
//    Handles pointer-referencing issues when the originating or
//    results plot of a query are deleted.
hrchilds's avatar
hrchilds committed
630 631 632 633
//
//  Arguments:
//    vp        A pointer to the ViewerPlot about to be deleted.
//
hrchilds's avatar
hrchilds committed
634 635
//  Programmer: Kathleen Bonnell
//  Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
636 637
//
//  Modifications:
hrchilds's avatar
hrchilds committed
638
//    Kathleen Bonnell, Fri Jul 12 18:42:11 PDT 2002
hrchilds's avatar
hrchilds committed
639 640
//    Added call to UpdateScaleFactor.
//
hrchilds's avatar
hrchilds committed
641
//    Kathleen Bonnell, Thu Mar  6 15:21:45 PST 2003
hrchilds's avatar
hrchilds committed
642 643 644 645
//    Reworked to reflect that lineout queries stored in LineoutList.
//
//    Eric Brugger, Wed Aug 20 11:05:54 PDT 2003
//    I removed a call to UpdateScaleFactor since it no longer exists.
hrchilds's avatar
hrchilds committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
//
// ****************************************************************************

void
ViewerQueryManager::Delete(ViewerPlot *vp)
{
    if (nLineouts == 0)
    {
        return;
    }

    bool needPhysicalDelete = true;
    int i;
    for (i = 0; i < nLineouts; i++)
    {
        if (lineoutList[i]->MatchOriginatingPlot(vp))
        {
            lineoutList[i]->DeleteOriginatingPlot();
            needPhysicalDelete = false;
        }
    }
hrchilds's avatar
hrchilds committed
667

hrchilds's avatar
hrchilds committed
668 669 670 671 672 673
    if (!needPhysicalDelete)
    {
        return;
    }

    //
hrchilds's avatar
hrchilds committed
674
    // Delete the query whose resultsPlot == vp;
hrchilds's avatar
hrchilds committed
675 676
    //
    int nLineoutsNew = nLineouts;
hrchilds's avatar
hrchilds committed
677
    ViewerWindow *resWin = 0;
hrchilds's avatar
hrchilds committed
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
    //
    //  There should be only one match, so stop once we found it.
    //
    for (i = 0;  i < nLineouts && resWin == 0; ++i)
    {
        if (lineoutList[i]->DeleteResultsPlot(vp))
        {
            resWin = lineoutList[i]->GetResultsWindow();
            if (lineoutList[i]->IsEmpty())
            {
                nLineoutsNew--;
                if (nLineoutsNew > 0 )
                {
                    *(lineoutList[i]) = *(lineoutList[nLineoutsNew]);
                }
                delete lineoutList[nLineoutsNew];
                lineoutList[nLineoutsNew] = NULL;
            }
        }
    }
    nLineouts = nLineoutsNew;
hrchilds's avatar
hrchilds committed
699
}
hrchilds's avatar
hrchilds committed
700 701 702 703 704 705


// ****************************************************************************
//  Method: ViewerQueryManager::Delete
//
//  Purpose:
hrchilds's avatar
hrchilds committed
706 707
//    Handles pointer-referencing issues when the originating or
//    results window of a query are deleted.
hrchilds's avatar
hrchilds committed
708 709 710 711
//
//  Arguments:
//    vw        A pointer to the ViewerWindow about to be deleted.
//
hrchilds's avatar
hrchilds committed
712 713
//  Programmer: Kathleen Bonnell
//  Creation:   June 10, 2002
hrchilds's avatar
hrchilds committed
714
//
hrchilds's avatar
hrchilds committed
715
//   Kathleen Bonnell, Thu Mar  6 15:21:45 PST 2003
hrchilds's avatar
hrchilds committed
716 717
//   Reworked to reflect that lineout queries stored in LineoutList.
//
hrchilds's avatar
hrchilds committed
718
//   Kathleen Bonnell, Fri Mar  7 16:27:04 PST 2003
hrchilds's avatar
hrchilds committed
719 720
//   Removed call to lineoutList->DeleteResultsWindow (redundant since
//   the list item will be deleted anyway).  Set lineoutList[i] to NULL
hrchilds's avatar
hrchilds committed
721
//   after delete.
hrchilds's avatar
hrchilds committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
//
// ****************************************************************************

void
ViewerQueryManager::Delete(ViewerWindow *vw)
{
    if (nLineouts == 0)
    {
        return;
    }

    bool needPhysicalDelete = true;
    int i;
    for (i = 0; i < nLineouts; i++)
    {
        if (lineoutList[i]->MatchOriginatingWindow(vw))
        {
            lineoutList[i]->DeleteOriginatingWindow();
            needPhysicalDelete = false;
        }
    }
hrchilds's avatar
hrchilds committed
743

hrchilds's avatar
hrchilds committed
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
    if (!needPhysicalDelete)
    {
        return;
    }

    //
    // Delete the query whose resultsWindow == vw; 
    //
    int nLineoutsNew = 0;
    for (i = 0;  i < nLineouts; i++)
    {
        if (!(lineoutList[i]->MatchResultsWindow(vw)))
        {
            lineoutList[nLineoutsNew] = lineoutList[i];
            nLineoutsNew++;
        }
    }
    for (i = nLineoutsNew; i < nLineouts; i++)
    {
        delete lineoutList[i];
        lineoutList[i] = NULL;
    }
    nLineouts = nLineoutsNew;
} 


// ****************************************************************************
//  Method: ViewerQueryManager::HandleTool
//
//  Purpose:
//    Handles a request by a tool to change plot attributes.
//
//  Arguments:
//    ow : The window where the tool is active. 
//    ti : A reference to a tool interface object.
//
//  Programmer: Kathleen Bonnell 
//  Creation:   July 13, 2002
//
//  Modifications:
//    Kathleen Bonnell, Tue Mar  4 13:36:54 PST 2003  
//    Have lineout lists handle the tool.
//
hrchilds's avatar
hrchilds committed
787 788 789
//    Hank Childs, Thu Oct  2 14:22:16 PDT 2003
//    Account for multiple active plots.
//
hrchilds's avatar
hrchilds committed
790 791 792 793 794
// ****************************************************************************
 
void
ViewerQueryManager::HandleTool(ViewerWindow *oWin, const avtToolInterface &ti)
{
hrchilds's avatar
hrchilds committed
795 796
    intVector plotIDs;
    oWin->GetPlotList()->GetActivePlotIDs(plotIDs);
hrchilds's avatar
hrchilds committed
797
    if ((nLineouts == 0) || (plotIDs.size() == 0)) 
hrchilds's avatar
hrchilds committed
798 799 800
    {
        return;
    }
hrchilds's avatar
hrchilds committed
801 802
    // Use the first plot.
    int plotId = plotIDs[0];
hrchilds's avatar
hrchilds committed
803
    
hrchilds's avatar
hrchilds committed
804
    ViewerPlot *oPlot = oWin->GetPlotList()->GetPlot(plotId);
hrchilds's avatar
hrchilds committed
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
    for (int i = 0; i < nLineouts; i++)
    {
        if (lineoutList[i]->MatchOriginatingPlot(oPlot))
        {
            lineoutList[i]->HandleTool(ti);
        }
    }
}


// ****************************************************************************
// Method: ViewerQueryManager::InitializeTool
//
// Purpose:
//   Initializes a tool as it is being turned on.
//
// Arguments:
//   ow : The window where the tool is being turned on. 
//   ti : The tool interface that we're going to use for initialization.
//
// Returns: Whether or not the tool was initialized.
//
// Programmer: Kathleen Bonnell 
// Creation:   June 20, 2002 
//
// Modifications:
//    Kathleen Bonnell, Tue Mar  4 13:36:54 PST 2003  
//    Have lineout lists handle the tool.
//
hrchilds's avatar
hrchilds committed
834 835 836
//    Hank Childs, Thu Oct  2 14:22:16 PDT 200
//    Account for multiple plots.
//
hrchilds's avatar
hrchilds committed
837 838 839 840 841 842 843 844 845 846
// ****************************************************************************
 
bool
ViewerQueryManager::InitializeTool(ViewerWindow *oWin, avtToolInterface &ti)
{
    if (ti.GetAttributes()->TypeName() != "Line")
    {
        return false;
    }

hrchilds's avatar
hrchilds committed
847 848
    intVector plotIDs;
    oWin->GetPlotList()->GetActivePlotIDs(plotIDs);
hrchilds's avatar
hrchilds committed
849
    if ((nLineouts == 0) || (plotIDs.size() == 0))
hrchilds's avatar
hrchilds committed
850 851 852
    {
        return false;
    }
hrchilds's avatar
hrchilds committed
853 854
    // Use the first plot.
    int plotId = plotIDs[0];
hrchilds's avatar
hrchilds committed
855 856

    bool retval = false;
hrchilds's avatar
hrchilds committed
857
    ViewerPlot *oPlot = oWin->GetPlotList()->GetPlot(plotId);
hrchilds's avatar
hrchilds committed
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
    for (int i = 0; i < nLineouts; i++)
    {
        if (lineoutList[i]->MatchOriginatingPlot(oPlot)) 
        {
            retval = lineoutList[i]->InitializeTool(ti);
            break;
        }
    }

    return retval;
}


// ****************************************************************************
// Method: ViewerQueryManager::DisableTool
//
// Purpose:
//   Tell the queries that the tool has been turned off.
//
// Arguments:
//   ow : The window where the tool was active. 
//   ti : The tool interface from the tool that is being turned off, 
//
// Programmer: Kathleen Bonnell 
// Creation:   July 13, 2002 
//
// Modifications:
//    Kathleen Bonnell, Tue Mar  4 13:36:54 PST 2003  
//    Have lineout lists handle the tool.
//
// ****************************************************************************
 
void
ViewerQueryManager::DisableTool(ViewerWindow *oWin, avtToolInterface &ti)
{
    if (ti.GetAttributes()->TypeName() != "Line")
    {
        return;
    }

    for (int i = 0; i < nLineouts; i++)
    {
        if (lineoutList[i]->MatchOriginatingWindow(oWin)) 
        {
            lineoutList[i]->DisableTool();
        }
    }
}

 
// ****************************************************************************
//  Method: ViewerQueryManager::GetQueryClientAtts
//
//  Purpose:
//    Returns a pointer to the query attributes.
//
//  Returns:    A pointer to the query attributes.
//
//  Programmer: Kathleen Bonnell
hrchilds's avatar
hrchilds committed
917
//  Creation:   September 16, 2002
hrchilds's avatar
hrchilds committed
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
//
// ****************************************************************************
 
QueryAttributes *
ViewerQueryManager::GetQueryClientAtts()
{
    //
    // If the client attributes haven't been allocated then do so.
    //
    if (queryClientAtts == 0)
    {
        queryClientAtts = new QueryAttributes;
    }
 
    return queryClientAtts;
}


// ****************************************************************************
//  Method: ViewerQueryManager::DatabaseQuery
//
//  Purpose:
//    Perform a one-off query, one that does not need to be stored in the
//    query list.
//
//  Programmer: Kathleen Bonnell
//  Creation:   September 16, 2002 
//
//  Modifications:
//    Kathleen Bonnell, Wed Oct 23 18:10:26 PDT 2002     
//    Add specific handling of certain exceptions.
// 
//    Kathleen Bonnell, Wed Feb 26 12:47:55 PST 2003 
//    Catch NoEngine and LostConnection Exceptions, and retry the query
//    after the queried plot re-executes. 
//    
hrchilds's avatar
hrchilds committed
954 955 956
//    Kathleen Bonnell, Fri Jul 11 10:16:34 PDT 2003 
//    Verify query exists before sending request to engine. 
// 
hrchilds's avatar
hrchilds committed
957 958 959 960 961
//    Kathleen Bonnell, Wed Jul 23 16:26:34 PDT 2003 
//    Added call to GetUniqueVars, so that 'default' will get set to
//    the active var, and no duplicates will be in the list when passed
//    to queryAtts.
// 
hrchilds's avatar
hrchilds committed
962 963 964
//    Hank Childs, Thu Oct  2 13:51:31 PDT 2003
//    Add support for queries with multiple inputs.
//
hrchilds's avatar
hrchilds committed
965 966 967 968 969 970 971 972
//    Kathleen Bonnell, Wed Oct 29 16:06:23 PST 2003 
//    Rework code around GetUniqueVars to ensure the vars are truly
//    unique and the "default" gets translated to the active variable. 
//
//    Kathleen Bonnell, Wed Nov 19 15:41:11 PST 2003
//    Added logic to verify that all variables the named query will process
//    are allowed by the query. 
//
hrchilds's avatar
hrchilds committed
973 974
//    Kathleen Bonnell, Wed Nov 26 16:08:29 PST 2003 
//    Added logic to handle SpatialExtents query.
hrchilds's avatar
hrchilds committed
975
//
hrchilds's avatar
hrchilds committed
976 977 978
//    Kathleen Bonnell, Tue Feb  3 17:43:12 PST 2004 
//    Use arg1 to set queryAtts.CurrentPlotOnly var. 
// 
hrchilds's avatar
hrchilds committed
979 980 981
//    Kathleen Bonnell, Fri Mar  5 15:48:44 PST 2004 
//    Only DetermineVarTypes if necessary, and added more TRY-CATCH blocks. 
// 
hrchilds's avatar
hrchilds committed
982 983 984
//    Brad Whitlock, Wed Mar 10 10:06:36 PDT 2004
//    Changed to match other viewer changes related to plots and time.
//
hrchilds's avatar
hrchilds committed
985 986 987 988 989
//    Kathleen Bonnell, Tue Mar 23 15:31:32 PST 2004 
//    Restructured try-catch block around actual query execution, to catch
//    ImproperUseException which can occur if engine has been closed prior
//    to initiation of query.  
//
hrchilds's avatar
hrchilds committed
990 991 992
//    Jeremy Meredith, Tue Mar 30 10:39:20 PST 2004
//    Added an engine key to map plots to the engine used to create them.
//
hrchilds's avatar
hrchilds committed
993 994 995
//    Kathleen Bonnell, Thu Apr  1 19:13:59 PST 2004
//    Added bool arg to support queries-over-time. 
//
hrchilds's avatar
hrchilds committed
996 997 998 999
//    Jeremy Meredith, Mon Apr  5 14:15:56 PDT 2004
//    Added a line to clear out status in case of an exception occuring
//    during a query.
//
hrchilds's avatar
hrchilds committed
1000 1001 1002 1003
//    Kathleen Bonnell, Tue May 25 16:09:15 PDT 2004 
//    Made arg1 be Element and arg2 Domain, to be consistent with Pick'
//    default ordering (domain can be left out, so should be second arg). 
//  
hrchilds's avatar
hrchilds committed
1004 1005 1006 1007 1008
//    Kathleen Bonnell, Thu Jun  3 14:40:47 PDT 2004 
//    Split verification of query info into SingleInput and MultipleInput,
//    added calls to DoSpatialExtentsQuery, VerifySingleInputQuery,
//    and VerifyMultipleInputQuery.
//   
hrchilds's avatar
hrchilds committed
1009 1010 1011
//    Kathleen Bonnell, Fri Sep  3 09:59:25 PDT 2004 
//    Modified handling of 'NonQueryableInputException'. 
//
hrchilds's avatar
hrchilds committed
1012 1013 1014 1015
//    Kathleen Bonnell, Thu Dec 16 17:32:49 PST 2004 
//    Added 'elmentIsGlobal' arg, use it to set new QueryAttriubte 
//    'useGlobalId'.
//
hrchilds's avatar
hrchilds committed
1016 1017 1018
//    Eric Brugger, Thu Jan  6 08:58:28 PST 2005
//    Corrected a misuse of the CATCH_RETURN macro.
//
hrchilds's avatar
hrchilds committed
1019 1020 1021
//    Hank Childs, Fri Jan 28 11:55:12 PST 2005
//    Make sure returns inside 'try' are wrapped.
//
hrchilds's avatar
hrchilds committed
1022 1023 1024 1025
//    Hank Childs, Wed Mar  2 11:56:35 PST 2005
//    If we have plots that were generated dynamically, regenerate them before
//    performing our query.
//
hrchilds's avatar
hrchilds committed
1026 1027 1028 1029
//    Kathleen Bonnell, Tue Mar 15 17:39:33 PST 2005 
//    Only set 'DataType' from arg1 if the named query is an 'actual/original'
//    type of query, otherwise set DataType to 'Actual'.
//
hrchilds's avatar
hrchilds committed
1030 1031 1032
//    Kathleen Bonnell, Thu Jul 14 09:16:22 PDT 2005 
//    Test for existence of engine before proceeding. 
//    
hrchilds's avatar
hrchilds committed
1033
//    Kathleen Bonnell, Wed Jul 27 15:47:34 PDT 2005
hrchilds's avatar
hrchilds committed
1034 1035
//    Don't send message if QueryOutput is suppressed. 
//
hrchilds's avatar
hrchilds committed
1036 1037 1038 1039
//    Kathleen Bonnell, Tue Aug 16 10:03:27 PDT 2005
//    Moved warning/error condition detection code to beginning of method.
//    Check for non-hidden active plot before checking if EngineExists. 
//
hrchilds's avatar
hrchilds committed
1040 1041 1042 1043
//    Kathleen Bonnell, Tue Jan 31 15:45:23 PST 2006
//    If points were transformed, perform OrignalData SpatialExtents query
//    like other queries. 
//
hrchilds's avatar
hrchilds committed
1044 1045 1046
//    Hank Childs, Wed May 10 09:52:54 PDT 2006
//    Don't crash if we can't get the query to complete ('7092).
//
hrchilds's avatar
hrchilds committed
1047 1048 1049
//    Hank Childs, Tue Jul 11 14:34:06 PDT 2006
//    Added double arguments.
//
1050 1051 1052 1053 1054 1055 1056
//    Dave Bremer, Fri Dec  8 17:52:22 PST 2006
//    Changed the double arguments to vectors of doubles.
//
//    Hank Childs, Tue Feb 19 19:45:43 PST 2008
//    Rename "dynamic" to "streaming", since we really care about whether we
//    are streaming, not about whether we are doing dynamic load balancing.
//    And the two are no longer synonymous.
hrchilds's avatar
hrchilds committed
1057
//
1058 1059 1060
//    Brad Whitlock, Tue Apr 29 16:31:58 PDT 2008
//    Support for internationalization.
//
whitlocb's avatar
whitlocb committed
1061 1062 1063 1064 1065
//    Brad Whitlock, Fri Apr 17 09:58:52 PDT 2009
//    Send updated expressions to the engine before we execute the query in
//    case the query involves expressions that have not been sent to the engine
//    yet.
//
1066 1067 1068
//    Dave Pugmire, Tue Nov  9 16:08:30 EST 2010
//    Add dumpSteps for streamline info query.
//
1069 1070 1071 1072 1073 1074 1075 1076 1077
//    Kathleen Biagas, Fri Jun 10 13:53:10 PDT 2011
//    Send the 'suppressQueryOutput' flag to QueryAtts.
//
//    Kathleen Biagas, Tue Jun 21 11:05:15 PDT 2011
//    Changed arg to MapNode, modifications within to reflect this change.
//    Culled modification notes to last couple of years.
//    Moved test for non-hiddend active plot and running engine to generic
//    'Query' method (which calls this one).
//
1078 1079
//    Brad Whitlock, Fri Aug 19 10:01:13 PDT 2011
//    I changed the UpdateExpressions call on the engine manager.
pugmire's avatar
pugmire committed
1080
//
hrchilds's avatar
hrchilds committed
1081 1082
// ****************************************************************************

1083 1084
void
ViewerQueryManager::DatabaseQuery(const MapNode &queryParams)
hrchilds's avatar
hrchilds committed
1085
{
1086
    string qName = queryParams.GetEntry("query_name")->AsString();
1087
    int doTimeQuery = 0;
1088
    if (queryParams.HasEntry("do_time"))
1089
        doTimeQuery = queryParams.GetEntry("do_time")->AsInt();
1090

hrchilds's avatar
hrchilds committed
1091 1092
    queryClientAtts->SetResultsMessage("");
    queryClientAtts->SetResultsValue(0.);
hrchilds's avatar
hrchilds committed
1093 1094 1095 1096
    if (!queryTypes->QueryExists(qName, QueryList::DatabaseQuery))
    {
        // we've reset some values, notify clients
        queryClientAtts->Notify();
1097 1098
        QString msg = tr("%1 is not a valid query name.\n").arg(qName.c_str());
        Error(msg);
hrchilds's avatar
hrchilds committed
1099 1100 1101 1102
        return;
    }
    if (!doTimeQuery && !queryTypes->RegularQueryAvailable(qName))
    {
1103 1104 1105
        QString msg = tr("Regular (non-time) query is not available for %1.").
                      arg(qName.c_str());
        Error(msg);
hrchilds's avatar
hrchilds committed
1106 1107
        return;
    }
hrchilds's avatar
hrchilds committed
1108 1109 1110 1111 1112 1113

    int numInputs = queryTypes->NumberOfInputsForQuery(qName);
    if (numInputs <= 0)
    {
        // we've reset some values, notify clients
        queryClientAtts->Notify();
1114 1115 1116
        QString msg = tr("%1 has had an internal error when processing.\n").
                      arg(qName.c_str());
        Error(msg);
hrchilds's avatar
hrchilds committed
1117 1118 1119
        return;
    }

1120 1121 1122 1123 1124
    ViewerWindow *win = ViewerWindowManager::Instance()->GetActiveWindow();
    ViewerPlotList *plist = win->GetPlotList();
    intVector plotIds;
    plist->GetActivePlotIDs(plotIds);

hrchilds's avatar
hrchilds committed
1125 1126 1127 1128 1129 1130 1131 1132
    bool canBeDLBPlots = true;
    if (canBeDLBPlots)
    {
        //
        // If we have plots generated by DLB, then they won't be suitable
        // for queries.  Regenerate them with SLB.
        //
        bool clearedActor = false;
hrchilds's avatar
hrchilds committed
1133
        for (int i = 0 ; i < plotIds.size() ; i++)
hrchilds's avatar
hrchilds committed
1134
        {
hrchilds's avatar
hrchilds committed
1135
            int plotId = plotIds[i];
hrchilds's avatar
hrchilds committed
1136 1137 1138 1139 1140
            ViewerPlot *plot = plist->GetPlot(plotId);
            const EngineKey   &engineKey = plot->GetEngineKey();
            int networkId = plot->GetNetworkID();
            avtDataObjectReader_p rdr = plot->GetReader();
            avtDataObject_p dob = rdr->GetOutput();
1141
            bool isDyn = dob->GetInfo().GetValidity().AreWeStreaming();
hrchilds's avatar
hrchilds committed
1142 1143
            if (isDyn)
            {
hrchilds's avatar
hrchilds committed
1144
                ViewerEngineManager::Instance()->StartQuery(engineKey, true,
hrchilds's avatar
hrchilds committed
1145 1146 1147 1148 1149 1150 1151
                                                            networkId);
                plot->ClearCurrentActor();
                clearedActor = true;
            }
        }
        if (clearedActor)
        {
hrchilds's avatar
hrchilds committed
1152 1153
            plist->UpdatePlotList();
            plist->UpdateFrame();
hrchilds's avatar
hrchilds committed
1154 1155 1156
        }
    }

1157 1158 1159 1160
    int useActualData = 0;
    if (queryParams.HasEntry("use_actual_data"))
        useActualData = queryParams.GetEntry("use_actual_data")->AsInt();

hrchilds's avatar
hrchilds committed
1161
    if (qName == "SpatialExtents")
hrchilds's avatar
hrchilds committed
1162
    {
hrchilds's avatar
hrchilds committed
1163
        //
hrchilds's avatar
hrchilds committed
1164 1165
        // NO NEED TO GO TO THE ENGINE FOR THIS INFORMATION, AS
        // IT IS AVAILABLE FROM THE PLOT
hrchilds's avatar
hrchilds committed
1166
        //
1167
        if (!useActualData)
hrchilds's avatar
hrchilds committed
1168
        {
hrchilds's avatar
hrchilds committed
1169

hrchilds's avatar
hrchilds committed
1170 1171 1172 1173
            avtDataObjectReader_p rdr = plist->GetPlot(plotIds[0])->GetReader();
            avtDataObject_p dob = rdr->GetOutput();
            if (!dob->GetInfo().GetValidity().GetPointsWereTransformed())
            {
1174
                DoSpatialExtentsQuery(plist->GetPlot(plotIds[0]),useActualData);
hrchilds's avatar
hrchilds committed
1175 1176 1177 1178 1179
                return;
            }
        }
        else
        {
1180
            DoSpatialExtentsQuery(plist->GetPlot(plotIds[0]), useActualData);
hrchilds's avatar
hrchilds committed
1181 1182
            return;
        }
hrchilds's avatar
hrchilds committed
1183
    }
hrchilds's avatar
hrchilds committed
1184

1185 1186 1187 1188
    stringVector vars;
    if (queryParams.HasEntry("vars"))
        vars = queryParams.GetEntry("vars")->AsStringVector();

hrchilds's avatar
hrchilds committed
1189
    QueryAttributes qa;
1190
    qa.SetFloatFormat(floatFormat);
1191 1192
    qa.SetSuppressOutput(suppressQueryOutput);
    qa.SetQueryInputParams(queryParams);
hrchilds's avatar
hrchilds committed
1193

hrchilds's avatar
hrchilds committed
1194
    if (numInputs == 1)
hrchilds's avatar
hrchilds committed
1195
    {
hrchilds's avatar
hrchilds committed
1196
        //
hrchilds's avatar
hrchilds committed
1197 1198 1199
        // We have a convention of just using the first active plot
        // when there are multiple active plots selected for a single
        // input query.  BY CONVENTION, THIS IS NOT AN ERROR.
hrchilds's avatar
hrchilds committed
1200
        //
hrchilds's avatar
hrchilds committed
1201 1202 1203
        int firstPlot = plotIds[0];
        plotIds.clear();  
        plotIds.push_back(firstPlot);
hrchilds's avatar
hrchilds committed
1204
        if (!VerifySingleInputQuery(plist, firstPlot, qName, vars, qa))
hrchilds's avatar
hrchilds committed
1205
            return;
hrchilds's avatar
hrchilds committed
1206
    }
hrchilds's avatar
hrchilds committed
1207 1208
    else 
    {
hrchilds's avatar
hrchilds committed
1209
        if (!VerifyMultipleInputQuery(plist, numInputs, qName, vars, qa))
hrchilds's avatar
hrchilds committed
1210 1211 1212 1213 1214 1215 1216 1217
            return;
    }

    //
    //  Single input queries need only one engineKey, multiple input
    //  queries currently require all inputs to be on same host,
    //  so go ahead and grab engineKey from first active plot.
    //
hrchilds's avatar
hrchilds committed
1218
    EngineKey engineKey = plist->GetPlot(plotIds[0])->GetEngineKey();
hrchilds's avatar
hrchilds committed
1219

hrchilds's avatar
hrchilds committed
1220
    bool retry; 
hrchilds's avatar
hrchilds committed
1221
    int numAttempts = 0;
hrchilds's avatar
hrchilds committed
1222
    bool success = false;
hrchilds's avatar
hrchilds committed
1223

hrchilds's avatar
hrchilds committed
1224 1225 1226
    do
    {
        retry = false;
hrchilds's avatar