GUIBase.C 25.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 <DebugStream.h>
hrchilds's avatar
hrchilds committed
40 41
#include <DatabaseCorrelation.h>
#include <DatabaseCorrelationList.h>
hrchilds's avatar
hrchilds committed
42 43 44 45 46 47
#include <GUIBase.h>
#include <MessageAttributes.h>
#include <StatusSubject.h>
#include <ViewerProxy.h>
#include <FileServerList.h>
#include <GetMetaDataException.h>
48
#include <UnicodeHelper.h>
hrchilds's avatar
hrchilds committed
49 50
#include <WindowInformation.h>

hrchilds's avatar
hrchilds committed
51 52
#include <SimpleObserver.h>

53
#include <qobject.h>
hrchilds's avatar
hrchilds committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#include <qapplication.h>
#include <qcursor.h>

// Static member attributes.
MessageAttributes *GUIBase::msgAttr = 0;
ViewerProxy *GUIBase::viewer = 0;
StatusSubject *GUIBase::statusSubject = 0;
bool GUIBase::writeToConsole = true;
bool GUIBase::autoUpdate = false;
bool GUIBase::makeDefaultConfirm = true;
FileServerList *GUIBase::fileServer = 0;

// ****************************************************************************
// Method: GUIBase::GUIBase
//
// Purpose: 
//   Constructor for the GUIBase class.
//
// Programmer: Brad Whitlock
// Creation:   Mon Sep 25 16:43:57 PST 2000
//
// Modifications:
//   
// ****************************************************************************

GUIBase::GUIBase()
{
    // nothing
}

// ****************************************************************************
// Method: GUIBase::~GUIBase
//
// Purpose: 
//   Destructor for the GUIBase class.
//
// Programmer: Brad Whitlock
// Creation:   Mon Sep 25 16:43:57 PST 2000
//
// Modifications:
//   
// ****************************************************************************

GUIBase::~GUIBase()
{
    // nothing
}

hrchilds's avatar
hrchilds committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
// ****************************************************************************
// Method: SetViewerProxy
//
// Purpose: 
//   Set the viewer proxy.
//
// Arguments:
//   p : The viewer proxy.
//
// Note:       We have this method now because I made the proxy private in
//             the base class because I want subclasses to use access methods
//             that would make it easier to combine the gui and viewer in
//             a single process if we ever decide to do that.
//
// Programmer: Brad Whitlock
// Creation:   Tue Feb 13 09:29:47 PDT 2007
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::SetViewerProxy(ViewerProxy *p)
{
    viewer = p;
}

// ****************************************************************************
// Method: GUIBase::GetViewerProxy
//
// Purpose: 
//   Get the ViewerProxy.
//
// Returns:    A pointer to the viewer proxy.
//
// Programmer: Brad Whitlock
// Creation:   Tue Feb 13 09:31:03 PDT 2007
//
// Modifications:
//   
// ****************************************************************************

ViewerProxy *
GUIBase::GetViewerProxy() const
{
    return viewer;
}

// ****************************************************************************
// Method: GUIBase::GetViewerState
//
// Purpose: 
//   Returns the ViewerState object.
//
// Returns:    The viewer proxy's ViewerState object.
//
// Note:       We provide this access method to make it less likely that 
//             subclasses will access ViewerState directly through the proxy.
//             This access pattern would make it easier to combine the gui
//             and viewer.
//
// Programmer: Brad Whitlock
// Creation:   Tue Feb 13 09:31:26 PDT 2007
//
// Modifications:
//   
// ****************************************************************************

ViewerState *
GUIBase::GetViewerState() const
{
    return viewer->GetViewerState();
}

// ****************************************************************************
// Method: GUIBase::GetViewerMethods
//
// Purpose: 
//   Returns the GetViewerMethods object.
//
// Returns:    The viewer proxy's GetViewerMethods object.
//
// Note:       We provide this access method to make it less likely that 
//             subclasses will access GetViewerMethods directly through the .
//             proxy This access pattern would make it easier to combine the 
//             gui and viewer.
//
// Programmer: Brad Whitlock
// Creation:   Tue Feb 13 09:31:26 PDT 2007
//
// Modifications:
//   
// ****************************************************************************

ViewerMethods *
GUIBase::GetViewerMethods() const
{
    return viewer->GetViewerMethods();
}

hrchilds's avatar
hrchilds committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
// ****************************************************************************
// Method: GUIBase::Error
//
// Purpose: 
//   This method writes an error message into the message state
//   object. This causes the error message to be displayed.
//
// Arguments:
//   msg : The text to put in the message.
//
// Programmer: Brad Whitlock
// Creation:   Wed Aug 30 18:15:49 PST 2000
//
// Modifications:
//   Brad Whitlock, Mon Apr 28 15:49:58 PST 2003
//   Added ability to write to the console.
//
//   Brad Whitlock, Tue May 20 15:12:44 PST 2003
//   Made it work with the regenerated MessageAttributes.
//
222 223 224
//   Brad Whitlock, Tue Apr 29 10:17:36 PDT 2008
//   Added support for sending the unicode string.
//
hrchilds's avatar
hrchilds committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238
// ****************************************************************************

void
GUIBase::Error(const QString &msg)
{
    if(msgAttr == 0)
        return;

    if(writeToConsole)
    {
        cerr << "Error: " << msg.latin1() << endl;
    }
    else
    {
239
        MessageAttributes_SetText(*msgAttr, msg);
hrchilds's avatar
hrchilds committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        msgAttr->SetSeverity(MessageAttributes::Error);
        msgAttr->Notify();
    }

    // Write to the log as well.
    debug1 << "Error: " << msg.latin1() << endl;
}

// ****************************************************************************
// Method: GUIBase::Warning
//
// Purpose: 
//   This method writes a warning message into the message state
//   object. This causes the warning message to be displayed.
//
// Arguments:
//   msg : The text to put in the message.
//
// Programmer: Brad Whitlock
// Creation:   Wed Aug 30 18:15:49 PST 2000
//
// Modifications:
//   Brad Whitlock, Mon Apr 28 15:49:58 PST 2003
//   Added ability to write to the console.
//
//   Brad Whitlock, Tue May 20 15:12:44 PST 2003
//   Made it work with the regenerated MessageAttributes.
//
268 269 270
//   Brad Whitlock, Tue Apr 29 10:17:36 PDT 2008
//   Added support for sending the unicode string.
//
hrchilds's avatar
hrchilds committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284
// ****************************************************************************

void
GUIBase::Warning(const QString &msg)
{
    if(msgAttr == 0)
        return;

    if(writeToConsole)
    {
        cerr << "Warning: " << msg.latin1() << endl;
    }
    else
    {
285
        MessageAttributes_SetText(*msgAttr, msg);
hrchilds's avatar
hrchilds committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        msgAttr->SetSeverity(MessageAttributes::Warning);
        msgAttr->Notify();
    }

    // Write to the log as well.
    debug2 << "Warning: " << msg.latin1() << endl;
}

// ****************************************************************************
// Method: GUIBase::Message
//
// Purpose: 
//   This method writes a message into the message state
//   object. This causes the message to be displayed.
//
// Arguments:
//   msg : The text to put in the message.
//
// Programmer: Brad Whitlock
// Creation:   Wed Aug 30 18:15:49 PST 2000
//
// Modifications:
//   Brad Whitlock, Mon Apr 28 15:49:58 PST 2003
//   Added ability to write to the console.
//
//   Brad Whitlock, Tue May 20 15:12:44 PST 2003
//   Made it work with the regenerated MessageAttributes.
//
314 315 316
//   Brad Whitlock, Tue Apr 29 10:17:36 PDT 2008
//   Added support for sending the unicode string.
//
hrchilds's avatar
hrchilds committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330
// ****************************************************************************

void
GUIBase::Message(const QString &msg)
{
    if(msgAttr == 0)
        return;

    if(writeToConsole)
    {
        cerr << "Message: " << msg.latin1() << endl;
    }
    else
    {
331
        MessageAttributes_SetText(*msgAttr, msg);
hrchilds's avatar
hrchilds committed
332 333 334 335 336 337 338
        msgAttr->SetSeverity(MessageAttributes::Message);
        msgAttr->Notify();
    }

    // Write to the log as well.
    debug3 << "Message: " << msg.latin1() << endl;
}
339

whitlocb's avatar
whitlocb committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353
// ****************************************************************************
// Method: GUIBase::Information
//
// Purpose: 
//   This method writes an informative message into the message state
//   object. This causes the message to be displayed.
//
// Arguments:
//   msg : The text to put in the message.
//
// Programmer: Brad Whitlock
// Creation:   Fri Jan 18 14:40:00 PST 2008
//
// Modifications:
354 355
//   Brad Whitlock, Tue Apr 29 10:17:36 PDT 2008
//   Added support for sending the unicode string.
whitlocb's avatar
whitlocb committed
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
//
// ****************************************************************************

void
GUIBase::Information(const QString &msg)
{
    if(msgAttr == 0)
        return;

    if(writeToConsole)
    {
        cerr << "Message: " << msg.latin1() << endl;
    }
    else
    {
371
        MessageAttributes_SetText(*msgAttr, msg);
whitlocb's avatar
whitlocb committed
372 373 374 375 376 377 378
        msgAttr->SetSeverity(MessageAttributes::Information);
        msgAttr->Notify();
    }

    // Write to the log as well.
    debug3 << "Message: " << msg.latin1() << endl;
}
hrchilds's avatar
hrchilds committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 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 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 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 504 505 506 507 508 509 510 511 512 513 514 515 516 517

// ****************************************************************************
// Method: GUIBase::Status
//
// Purpose: 
//   Sends a status message to the main window that causes it to
//   display the message in its statusbar.
//
// Arguments:
//   msg         : The message to display.
//   millisecond : The number of milliseconds to display the message.
//
// Programmer: Brad Whitlock
// Creation:   Sat Sep 16 14:27:56 PST 2000
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::Status(const QString &msg, int milliseconds)
{
    // Set the status subject's fields and notify its observer,
    // the main window.
    statusSubject->clearing = false;
    statusSubject->text = msg;
    statusSubject->milliseconds = milliseconds;
    statusSubject->Notify();
}

// ****************************************************************************
// Method: GUIBase::ClearStatus
//
// Purpose: 
//   Sends a status message to the main window that causes it to
//   clear the message in its statusbar.
//
// Programmer: Brad Whitlock
// Creation:   Sat Sep 16 14:29:00 PST 2000
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::ClearStatus()
{
    // Set the status subject's fields and notify its observer,
    // the main window.
    statusSubject->clearing = true;
    statusSubject->Notify();
}

// ****************************************************************************
// Method: GUIBase::AutoUpdate
//
// Purpose: 
//   Returns a flag indicating whether or not autoupdate is on.
//
// Programmer: Brad Whitlock
// Creation:   Mon Sep 25 15:04:32 PST 2000
//
// Modifications:
//   
// ****************************************************************************

bool
GUIBase::AutoUpdate() const
{
    return autoUpdate;
}

// ****************************************************************************
// Method: GUIBase::ConnectMessageAttr
//
// Purpose: 
//   Sets the message object that is used to tell the message window
//   that there is a message.
//
// Arguments:
//   attr : A pointer to the message state object that is used to
//          communicate error messages.
//
// Programmer: Brad Whitlock
// Creation:   Wed Aug 30 18:17:48 PST 2000
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::ConnectMessageAttr(MessageAttributes *attr)
{
    msgAttr = attr;
}

// ****************************************************************************
// Method: GUIBase::SetWaitCursor
//
// Purpose: 
//   Sets the cursor to a wait cursor.
//
// Programmer: Brad Whitlock
// Creation:   Wed Mar 13 14:21:34 PST 2002
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::SetWaitCursor()
{
#if QT_VERSION >= 300
    QApplication::setOverrideCursor(Qt::WaitCursor);
#else
    QApplication::setOverrideCursor(WaitCursor);
#endif
}

// ****************************************************************************
// Method: GUIBase::RestoreCursor
//
// Purpose: 
//   Restores the cursor to the last cursor used.
//
// Programmer: Brad Whitlock
// Creation:   Wed Mar 13 14:21:34 PST 2002
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::RestoreCursor()
{
    QApplication::restoreOverrideCursor();
}

// ****************************************************************************
hrchilds's avatar
hrchilds committed
518
// Method: GUIBase::SetOpenDataFile
hrchilds's avatar
hrchilds committed
519 520 521 522 523
//
// Purpose: 
//   Opens the specified data file using the file server.
//
// Arguments:
hrchilds's avatar
hrchilds committed
524 525 526 527 528
//   qf              : The qualified file name that we want to open.
//   timeState       : The time state that we want to open.
//   sob             : The caller of this method. We pass it if we do not want
//                     the caller to update as a result of calling this method.
//   reOpen          : Whether we should reopen the database instead of opening.
hrchilds's avatar
hrchilds committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
//
// Returns:    True if the operation is a success.
//
// Programmer: Brad Whitlock
// Creation:   Thu May 9 16:29:48 PST 2002
//
// Modifications:
//   Brad Whitlock, Mon Jul 29 14:39:54 PST 2002
//   I added the reOpen argument to tell the file server to re-open the
//   file and clear anything that it knows about the file.
//
//   Brad Whitlock, Mon Aug 19 17:02:00 PST 2002
//   I removed the code to tell the viewer the number of time steps that
//   are in the animation because the viewer now knows that information and
//   it was causing plots to recalculate when viewer pipeline caching was
//   turned off.
//
//   Eric Brugger, Mon Dec 16 12:32:14 PST 2002
//   I removed the code that sets the number of states and the current state
//   in the global attributes.  This was unnecessary since the viewer is
//   responsible for doing that.
//
//   Brad Whitlock, Wed May 14 13:02:50 PST 2003
//   I added support for reopening a file at a later time state.
//
//   Brad Whitlock, Thu May 15 12:34:06 PDT 2003
//   I added support for opening a file at a later time state.
//
hrchilds's avatar
hrchilds committed
557 558 559 560
//   Brad Whitlock, Wed Oct 22 12:16:43 PDT 2003
//   I added support for telling the viewer that we don't want to add
//   default plots when we open a database.
//
hrchilds's avatar
hrchilds committed
561 562 563 564 565
//   Brad Whitlock, Mon Nov 3 09:34:03 PDT 2003
//   I added code to prevent the file panel from updating prematurely. I also
//   renamed the method and ripped out the code that told the viewer to
//   open the database. I removed the addDefaultPlots argument.
//
hrchilds's avatar
hrchilds committed
566 567 568
//   Brad Whitlock, Tue Apr 6 08:26:37 PDT 2004
//   I removed some code that set globalAtts.
//
hrchilds's avatar
hrchilds committed
569 570 571 572
//   Hank Childs, Fri Jan 12 09:56:29 PST 2007
//   Do not issue an error if you can't open a file ... the viewer will do this
//   for us.
//
hrchilds's avatar
hrchilds committed
573 574 575
// ****************************************************************************

bool
hrchilds's avatar
hrchilds committed
576 577
GUIBase::SetOpenDataFile(const QualifiedFilename &qf, int timeState,
    SimpleObserver *sob, bool reOpen)
hrchilds's avatar
hrchilds committed
578
{
579
    const char *mName = "GUIBase::SetOpenDataFile";
hrchilds's avatar
hrchilds committed
580
    bool retval = true;
hrchilds's avatar
hrchilds committed
581

hrchilds's avatar
hrchilds committed
582 583 584 585 586 587 588 589
    //
    // Clears any information about the specified file and causes it to be
    // read again from the mdserver.
    //
    if(reOpen)
    {
        fileServer->ClearFile(qf);
        fileServer->CloseFile();
hrchilds's avatar
hrchilds committed
590 591
        if(sob)
            sob->SetUpdate(false);
hrchilds's avatar
hrchilds committed
592 593 594 595 596 597 598 599 600 601 602 603
        fileServer->Notify();
    }

    //
    // If the file is not already open, read it in and tell the observers.
    //
    if(fileServer->GetOpenFile() != qf)
    {
        TRY
        {
            // Display a message while we open the file.
            QString msg;
hrchilds's avatar
hrchilds committed
604 605
            if(reOpen)
            {
606 607
                msg = QObject::tr("Reopening ",mName) + QString(qf.filename.c_str())
                    + QObject::tr(" on ", mName) + QString(qf.host.c_str());
hrchilds's avatar
hrchilds committed
608 609 610
            }
            else
            {
611 612
                msg = QObject::tr("Opening ", mName) + QString(qf.filename.c_str())
                    + QObject::tr(" on ", mName) + QString(qf.host.c_str());
hrchilds's avatar
hrchilds committed
613
            }
hrchilds's avatar
hrchilds committed
614 615 616 617 618
            Status(msg);

            // Tell the fileServer to open the file specified by filename.
            // This will cause it to read the file's MetaData.
            fileServer->OpenFile(qf, timeState);
hrchilds's avatar
hrchilds committed
619 620 621 622 623 624 625
            // Prevent the file panel from updating because the globalAtts
            // from the viewer, that the file panel uses to display the right
            // database highlight, do not yet contain the right timeState and
            // updating the file panel now causes it to switch to the wrong
            // time state for a moment.
            if(sob)
                sob->SetUpdate(false);
hrchilds's avatar
hrchilds committed
626 627 628 629 630 631 632 633 634
            fileServer->Notify();
            ClearStatus();
        }
        CATCH2(GetMetaDataException, gmde)
        {
            // Clear the status bar.
            ClearStatus();

            // Tell the user about the error.
635 636 637 638 639
            QString msg = QObject::tr("VisIt could not open the file %1.\n\n"
                                      "The metadata server returned the "
                                      "following message:\n\n%2", mName).
                          arg(QString(qf.FullName().c_str())).
                          arg(QString(gmde.Message().c_str()));
640
            debug1 << msg.ascii() << endl;
hrchilds's avatar
hrchilds committed
641 642 643
            debug1 << "Not issuing an error message because the viewer will "
                   << "cover that." << endl;
            //Error(msg);
hrchilds's avatar
hrchilds committed
644 645 646 647 648 649 650
            retval = false;
        }
        ENDTRY
    }

    return retval;
}
hrchilds's avatar
hrchilds committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677

// ****************************************************************************
// Method: GUIBase::GetStateForSource
//
// Purpose: 
//   Returns the state for the specified source taking into account the
//   active time slider and the correlations that exist.
//
// Arguments:
//   source : The name of the source whose state we want.
//
// Returns:    The current state for the specified source.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Tue Jan 27 21:16:59 PST 2004
//
// Modifications:
//   
// ****************************************************************************

int
GUIBase::GetStateForSource(const QualifiedFilename &source) const
{
    int retval = 0;

hrchilds's avatar
hrchilds committed
678
    WindowInformation *windowInfo = GetViewerState()->GetWindowInformation();
hrchilds's avatar
hrchilds committed
679 680 681 682 683 684 685 686
    int activeTS = windowInfo->GetActiveTimeSlider();

    if(activeTS >= 0)
    {
        // Try and find a correlation for the active time slider so we
        // can get the number of states in the correlation.
        const stringVector &tsNames = windowInfo->GetTimeSliders();
        const std::string &activeTSName = tsNames[activeTS];
hrchilds's avatar
hrchilds committed
687
        DatabaseCorrelationList *cL = GetViewerState()->GetDatabaseCorrelationList();
hrchilds's avatar
hrchilds committed
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
        DatabaseCorrelation *correlation = cL->FindCorrelation(activeTSName);
 
        //
        // We found a correlation for the active time slider.
        //
        if(correlation != 0)
        {
            //
            // See if the correlation for the active time slider involves
            // the source that we're interested in. If so, return the
            // correlated time state using the active time slider's state.
            //
            std::string sourceStr(source.FullName());
            const intVector &currentStates = windowInfo->GetTimeSliderCurrentStates();
            int activeTSState = currentStates[activeTS];
            int cts = correlation->GetCorrelatedTimeState(sourceStr, activeTSState);
            if(cts >= 0)
            {
                retval = cts;
            }
            else if((correlation = cL->FindCorrelation(sourceStr)) != 0)
            {
                //
                // The correlation did not involve the desired source but
                // we were able to find the simple correlation for the
                // desired source. Return its correlated time state using
                // the correlation that we just found and the active time
                // state for that correlation.
                //
                for(int i = 0; i < windowInfo->GetTimeSliders().size(); ++i)
                {
                    if(tsNames[i] == sourceStr)
                    {
                        cts = correlation->GetCorrelatedTimeState(sourceStr,
                                            currentStates[i]);
                        if(cts >= 0)
                            retval = cts;
                        break;
                    }
                }
            }
        }
    }

    return retval;
}

// ****************************************************************************
// Method: GUIBase::GetTimeSliderStateForDatabaseState
//
// Purpose: 
//   Returns the first state in the current time slider where the database
//   has a specific database index.
//
// Arguments:
hrchilds's avatar
hrchilds committed
743
//   tsName  : The name of the active time slider.
hrchilds's avatar
hrchilds committed
744 745 746 747 748 749 750 751 752 753 754
//   source  : The source that we're interested in.
//   dbState : The database state that we're looking for.
//
// Returns:    The inverted correlation time state that we want.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Tue Feb 3 18:52:44 PST 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
755 756 757 758
//   Brad Whitlock, Mon May 3 16:51:20 PST 2004
//   I made the name of the time slider be passed in so the method can be a
//   little more general.
//
hrchilds's avatar
hrchilds committed
759 760 761
// ****************************************************************************

int
hrchilds's avatar
hrchilds committed
762 763
GUIBase::GetTimeSliderStateForDatabaseState(const std::string &activeTSName,
    const QualifiedFilename &source, int dbState) const
hrchilds's avatar
hrchilds committed
764 765 766
{
    int retval = dbState;

hrchilds's avatar
hrchilds committed
767
    if(activeTSName != "")
hrchilds's avatar
hrchilds committed
768
    {
hrchilds's avatar
hrchilds committed
769
        WindowInformation *windowInfo = GetViewerState()->GetWindowInformation();
hrchilds's avatar
hrchilds committed
770

hrchilds's avatar
hrchilds committed
771 772
        // Try and find a correlation for the active time slider so we
        // can get the number of states in the correlation.
hrchilds's avatar
hrchilds committed
773
        DatabaseCorrelationList *cL = GetViewerState()->GetDatabaseCorrelationList();
hrchilds's avatar
hrchilds committed
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
        DatabaseCorrelation *correlation = cL->FindCorrelation(activeTSName);
 
        //
        // We found a correlation for the active time slider.
        //
        if(correlation != 0)
        {
            //
            // See if the correlation for the active time slider involves
            // the source that we're interested in. If so, return the
            // inverse correlated time state, which is the correlation time
            // state where the specified database has the given dbState.
            //
            std::string sourceStr(source.FullName());
            int cts = correlation->GetInverseCorrelatedTimeState(sourceStr, dbState);
            if(cts >= 0)
                retval = cts;
        }
    }

    return retval;
}

// ****************************************************************************
// Method: GUIBase::OpenActiveSourceInFileServer
//
// Purpose: 
//   This method is called when the file in the file server does not match
//   the active source. When that happens, we make the file server use the
//   active source so existing code that relies on the file server for the
//   open file still works.
//
// Programmer: Brad Whitlock
// Creation:   Fri Jan 30 11:36:42 PDT 2004
//
// Modifications:
//   
// ****************************************************************************

void
GUIBase::OpenActiveSourceInFileServer()
{
hrchilds's avatar
hrchilds committed
816
    WindowInformation *windowInfo = GetViewerState()->GetWindowInformation();
hrchilds's avatar
hrchilds committed
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
    const std::string &activeSource = windowInfo->GetActiveSource();
    QualifiedFilename qf(activeSource);

    if (activeSource == "notset" || activeSource == "")
    {
        debug3 << "OpenFileInFileServer: no active source. Closing file in "
                  "file server list. " << endl;
        fileServer->CloseFile();
        fileServer->Notify();
    }
    else if(fileServer->GetOpenFile() != qf)
    {
        TRY
        {
            // Get the state for the current source taking into account
            // the active time slider and the correlations that exist.
            int state = GetStateForSource(qf);
            debug3 << "OpenFileInFileServer: File server list's open file "
                   << "does not match the active source. Opening "
                   << activeSource.c_str() << ", state=" << state
                   << " in the file server list." << endl;

            fileServer->OpenFile(qf, state);
            fileServer->Notify();
        }
        CATCH(GetMetaDataException)
        {
            ; // Usually, the filename was bad.
        }
        ENDTRY
    }
}