QvisEngineWindow.C 26.8 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
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
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
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 <QvisEngineWindow.h>
whitlocb's avatar
whitlocb committed
40 41 42 43 44 45 46
#include <QLabel>
#include <QLayout>
#include <QProgressBar>
#include <QPushButton>
#include <QComboBox>
#include <QGroupBox>
#include <QMessageBox>
hrchilds's avatar
hrchilds committed
47 48

#include <EngineList.h>
49
#include <EngineProperties.h>
hrchilds's avatar
hrchilds committed
50
#include <StatusAttributes.h>
51
#include <UnicodeHelper.h>
hrchilds's avatar
hrchilds committed
52
#include <ViewerProxy.h>
hrchilds's avatar
hrchilds committed
53 54 55 56
#include <string>

using std::string;
using std::vector;
hrchilds's avatar
hrchilds committed
57 58 59 60 61 62 63 64 65 66 67

// ****************************************************************************
// Method: QvisEngineWindow::QvisEngineWindow
//
// Purpose: 
//   This is the constructor for the QvisEngineWindow class.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:30:53 PST 2001
//
// Modifications:
68 69 70
//   Brad Whitlock, Wed Apr  9 11:00:55 PDT 2008
//   QString for caption, shortName.
//
hrchilds's avatar
hrchilds committed
71 72 73
// ****************************************************************************

QvisEngineWindow::QvisEngineWindow(EngineList *engineList,
74
    const QString &caption, const QString &shortName, QvisNotepadArea *notepad) :
hrchilds's avatar
hrchilds committed
75 76
    QvisPostableWindowObserver(engineList, caption, shortName, notepad,
                               QvisPostableWindowObserver::NoExtraButtons),
hkrishna's avatar
hkrishna committed
77
    statusMap(), activeEngine("")
hrchilds's avatar
hrchilds committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
{
    engines = engineList;
    caller = engines;
    statusAtts = 0;
}

// ****************************************************************************
// Method: QvisEngineWindow::~QvisEngineWindow
//
// Purpose: 
//   This is the destructor for the QvisEngineWindow class.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:31:22 PST 2001
//
// Modifications:
whitlocb's avatar
whitlocb committed
94 95 96
//   Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//   Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
97 98 99 100 101
// ****************************************************************************

QvisEngineWindow::~QvisEngineWindow()
{
    // Delete the status attributes in the status map.
whitlocb's avatar
whitlocb committed
102 103 104 105
    
    QMapIterator<QString, StatusAttributes*> itr(statusMap);
    
    while(itr.hasNext())
hrchilds's avatar
hrchilds committed
106
    {
whitlocb's avatar
whitlocb committed
107 108
        itr.next();
        delete itr.value();
hrchilds's avatar
hrchilds committed
109
    }
whitlocb's avatar
whitlocb committed
110
    
hrchilds's avatar
hrchilds committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    // Detach from the status atts if they are still around.
    if(statusAtts)
        statusAtts->Detach(this);
}

// ****************************************************************************
// Method: QvisEngineWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:32:48 PST 2001
//
// Modifications:
//    Jeremy Meredith, Fri Jun 29 15:12:08 PDT 2001
//    Separated the single status/progress bar into one which reports
//    total status and one which reports current stage progress.
//
//    Brad Whitlock, Wed Nov 27 13:59:01 PST 2002
//    I added widgets to show engine information.
//
hrchilds's avatar
hrchilds committed
133 134 135
//    Brad Whitlock, Wed Feb 25 09:25:01 PDT 2004
//    I added a button to clear the cache.
//
hrchilds's avatar
hrchilds committed
136 137 138
//    Jeremy Meredith, Tue Mar 30 09:32:57 PST 2004
//    I made the engine area label a class member so it could mutate.
//
hrchilds's avatar
hrchilds committed
139 140 141 142 143
//    Brad Whitlock, Wed Jun 22 09:43:48 PDT 2005
//    I moved the "Clear cache" button so the window is a little more
//    consistent with the simulation window and so it takes less vertical
//    space.
//
whitlocb's avatar
whitlocb committed
144 145 146
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
147 148 149
//    Brad Whitlock, Mon Oct 10 12:55:52 PDT 2011
//    I added some information.
//
hrchilds's avatar
hrchilds committed
150 151 152 153 154 155 156
// ****************************************************************************

void
QvisEngineWindow::CreateWindowContents()
{
    isCreated = true;

whitlocb's avatar
whitlocb committed
157 158 159
    QGridLayout *grid1 = new QGridLayout();
    topLayout->addLayout(grid1);
    grid1->setColumnStretch(1, 10);
hrchilds's avatar
hrchilds committed
160

whitlocb's avatar
whitlocb committed
161
    engineCombo = new QComboBox(central);
hrchilds's avatar
hrchilds committed
162 163
    connect(engineCombo, SIGNAL(activated(int)), this, SLOT(selectEngine(int)));
    grid1->addWidget(engineCombo, 0, 1);
whitlocb's avatar
whitlocb committed
164
    engineLabel = new QLabel(tr("Engine:"), central);
hrchilds's avatar
hrchilds committed
165 166 167
    grid1->addWidget(engineLabel, 0, 0);

    // Create the widgets needed to show the engine information.
whitlocb's avatar
whitlocb committed
168
    engineInfo = new QGroupBox(central);
169
    engineInfo->setTitle(tr("Engine Information"));
hrchilds's avatar
hrchilds committed
170 171 172
    topLayout->addWidget(engineInfo);
    QVBoxLayout *infoTopLayout = new QVBoxLayout(engineInfo);

whitlocb's avatar
whitlocb committed
173 174 175
    QGridLayout *infoLayout = new QGridLayout();
    infoTopLayout->addLayout(infoLayout);

176
    int row = 0;
whitlocb's avatar
whitlocb committed
177
    engineNN = new QLabel(engineInfo);
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    infoLayout->addWidget(engineNN, row, 1);
    QLabel *engineNNLabel = new QLabel(tr("Nodes:"),engineInfo);
    infoLayout->addWidget(engineNNLabel, row, 0);
    ++row;

    engineNP = new QLabel(engineInfo);
    infoLayout->addWidget(engineNP, row, 1);
    QLabel *engineNPLabel = new QLabel(tr("Processors:"),engineInfo);
    infoLayout->addWidget(engineNPLabel, row, 0);
    ++row;

    QString gpuTxt(tr("The number of processors using GPUs is affected using "
        "the controls of the GPU Acceleration tab in the Host Profiles window."));
    engineNP_GPU = new QLabel(engineInfo);
    engineNP_GPU->setToolTip(gpuTxt);
    infoLayout->addWidget(engineNP_GPU, row, 1);
    QLabel *engineNPGPULabel = new QLabel(tr("Processors using GPUs:"),engineInfo);
    engineNPGPULabel->setToolTip(gpuTxt);
    infoLayout->addWidget(engineNPGPULabel, row, 0);
    ++row;
hrchilds's avatar
hrchilds committed
198

whitlocb's avatar
whitlocb committed
199
    engineLB = new QLabel(engineInfo);
200
    infoLayout->addWidget(engineLB, row, 1);
whitlocb's avatar
whitlocb committed
201
    QLabel *engineLBLabel = new QLabel(tr("Load balancing:"),engineInfo);
202 203 204 205 206 207 208 209
    infoLayout->addWidget(engineLBLabel, row, 0);
    ++row;

    engineLB_Scheme = new QLabel(engineInfo);
    infoLayout->addWidget(engineLB_Scheme, row, 1);
    QLabel *engineLBSLabel = new QLabel(tr("Domain assignment:"),engineInfo);
    infoLayout->addWidget(engineLBSLabel, row, 0);
    ++row;
hrchilds's avatar
hrchilds committed
210 211

    // Create the status bars.
whitlocb's avatar
whitlocb committed
212
    totalStatusLabel = new QLabel(tr("Total status:"), central);
hrchilds's avatar
hrchilds committed
213 214
    topLayout->addWidget(totalStatusLabel);

whitlocb's avatar
whitlocb committed
215 216 217
    totalProgressBar = new QProgressBar(central);
    totalProgressBar->setMinimum(0);
    totalProgressBar->setMaximum(100);
hrchilds's avatar
hrchilds committed
218 219
    topLayout->addWidget(totalProgressBar);

whitlocb's avatar
whitlocb committed
220
    stageStatusLabel = new QLabel(tr("Stage status:"), central);
hrchilds's avatar
hrchilds committed
221 222
    topLayout->addWidget(stageStatusLabel);

whitlocb's avatar
whitlocb committed
223 224 225
    stageProgressBar = new QProgressBar(central);
    stageProgressBar->setMinimum(0);
    stageProgressBar->setMaximum(100);
hrchilds's avatar
hrchilds committed
226 227
    topLayout->addWidget(stageProgressBar);

whitlocb's avatar
whitlocb committed
228 229 230 231
    QHBoxLayout *buttonLayout1 = new QHBoxLayout();
    topLayout->addLayout(buttonLayout1);
    
    interruptEngineButton = new QPushButton(tr("Interrupt"), central);
hrchilds's avatar
hrchilds committed
232 233
    connect(interruptEngineButton, SIGNAL(clicked()), this, SLOT(interruptEngine()));
    interruptEngineButton->setEnabled(false);
hrchilds's avatar
hrchilds committed
234
    buttonLayout1->addWidget(interruptEngineButton);
hrchilds's avatar
hrchilds committed
235

whitlocb's avatar
whitlocb committed
236
    clearCacheButton = new QPushButton(tr("Clear cache"), central);
hrchilds's avatar
hrchilds committed
237 238
    connect(clearCacheButton, SIGNAL(clicked()), this, SLOT(clearCache()));
    clearCacheButton->setEnabled(false);
hrchilds's avatar
hrchilds committed
239 240
    buttonLayout1->addWidget(clearCacheButton);

whitlocb's avatar
whitlocb committed
241
    closeEngineButton = new QPushButton(tr("Close engine"), central);
hrchilds's avatar
hrchilds committed
242 243 244
    connect(closeEngineButton, SIGNAL(clicked()), this, SLOT(closeEngine()));
    closeEngineButton->setEnabled(false);
    buttonLayout1->addWidget(closeEngineButton);
hrchilds's avatar
hrchilds committed
245

hrchilds's avatar
hrchilds committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 314 315 316
    topLayout->addSpacing(10);
}

// ****************************************************************************
// Method: QvisEngineWindow::Update
//
// Purpose: 
//   This method is called when the subjects that the window observes are
//   modified.
//
// Arguments:
//   TheChangedSubject : A pointer to the subject that changed.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:33:06 PST 2001
//
// Modifications:
//   Brad Whitlock, Thu May 3 14:36:08 PST 2001
//   Fixed a crash.
//
// ****************************************************************************

void
QvisEngineWindow::Update(Subject *TheChangedSubject)
{
    caller = TheChangedSubject;

    if(isCreated)
        UpdateWindow(false);
}

// ****************************************************************************
// Method: QvisEngineWindow::SubjectRemoved
//
// Purpose: 
//   This method is called when the subjects observed by the window are
//   destructed.
//
// Arguments:
//   TheRemovedSubject : A pointer to the subject to remove.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:33:44 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisEngineWindow::SubjectRemoved(Subject *TheRemovedSubject)
{
    if(TheRemovedSubject == engines)
        engines = 0;
    else if(TheRemovedSubject == statusAtts)
        statusAtts = 0;
}

// ****************************************************************************
// Method: QvisEngineWindow::UpdateWindow
//
// Purpose: 
//   This method is called to update the window's widgets when the subjects
//   change.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:34:26 PST 2001
//
// Modifications:
//   Brad Whitlock, Wed Nov 27 14:00:24 PST 2002
//   I added widgets to show engine information.
//
hrchilds's avatar
hrchilds committed
317 318 319
//   Brad Whitlock, Wed Feb 25 09:31:17 PDT 2004
//   I added code to set the enabled state for the clearCache button.
//
hrchilds's avatar
hrchilds committed
320 321 322
//   Jeremy Meredith, Tue Mar 30 09:33:25 PST 2004
//   I added support for simulations.
//
hrchilds's avatar
hrchilds committed
323 324 325
//   Jeremy Meredith, Mon Apr  4 16:02:22 PDT 2005
//   I made better names for simulations.
//
hrchilds's avatar
hrchilds committed
326 327 328
//   Kathleen Bonnell, Tue Apr 26 16:42:17 PDT 2005 
//   Don't enable interruptEngineButton until the process has been fixed. 
//
329 330 331
//   Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//   Support for internationalization.
//
whitlocb's avatar
whitlocb committed
332 333 334
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
335 336 337 338 339 340 341
// ****************************************************************************

void
QvisEngineWindow::UpdateWindow(bool doAll)
{
    if(caller == engines || doAll)
    {
342
        const stringVector &host = engines->GetEngineName();
hrchilds's avatar
hrchilds committed
343
        const stringVector &sim  = engines->GetSimulationName();
hrchilds's avatar
hrchilds committed
344 345 346 347 348

        // Add the engines to the widget.
        engineCombo->blockSignals(true);
        engineCombo->clear();
        int current = -1;
hkrishna's avatar
hkrishna committed
349
        for(size_t i = 0; i < host.size(); ++i)
hrchilds's avatar
hrchilds committed
350
        {
hrchilds's avatar
hrchilds committed
351 352 353
            QString temp(host[i].c_str());
            if (!sim[i].empty())
            {
whitlocb's avatar
whitlocb committed
354
                int lastSlashPos = QString(sim[i].c_str()).lastIndexOf('/');
hrchilds's avatar
hrchilds committed
355
                QString newsim(sim[i].substr(lastSlashPos+1).c_str());
whitlocb's avatar
whitlocb committed
356 357
                int lastDotPos =  newsim.lastIndexOf('.');
                int firstDotPos =  newsim.indexOf('.');
hrchilds's avatar
hrchilds committed
358 359 360 361

                QString name = newsim.mid(firstDotPos+1,
                                          lastDotPos-firstDotPos-1);

362
                temp = name + tr(" on ") + QString(host[i].c_str());
hrchilds's avatar
hrchilds committed
363
            }
whitlocb's avatar
whitlocb committed
364
            engineCombo->addItem(temp);
hrchilds's avatar
hrchilds committed
365 366 367 368 369 370 371 372

            if(temp == activeEngine)
                current = i;
        }

        if(current == -1)
        {
            // Update the activeEngine string.
hrchilds's avatar
hrchilds committed
373
            if(engineCombo->count() > 0)
hrchilds's avatar
hrchilds committed
374 375
            {
                current = 0;
whitlocb's avatar
whitlocb committed
376
                engineCombo->setCurrentIndex(0);
hrchilds's avatar
hrchilds committed
377 378 379 380 381
                if (sim[0]=="")
                    activeEngine = QString().sprintf("%s",host[0].c_str());
                else
                    activeEngine = QString().sprintf("%s:%s",host[0].c_str(),
                                                     sim[0].c_str());
hrchilds's avatar
hrchilds committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395

                // Add an entry if needed.
                AddStatusEntry(activeEngine);
            }
            else
            {
                // The active engine was not in the list of engines returned
                // by the viewer. Remove the entry from the list.
                RemoveStatusEntry(activeEngine);
                activeEngine = QString("");
            }
        }
        else
        {
whitlocb's avatar
whitlocb committed
396
            engineCombo->setCurrentIndex(current);
hrchilds's avatar
hrchilds committed
397 398 399 400 401 402 403
        }
        engineCombo->blockSignals(false);

        // Update the engine information.
        UpdateInformation(current);

        // Set the enabled state of the various widgets.
hrchilds's avatar
hrchilds committed
404 405
        // KSB: When INTERRUPT ENGINE has been fixed, uncomment the next line.
        //interruptEngineButton->setEnabled(host.size() > 0);
hrchilds's avatar
hrchilds committed
406 407 408
        closeEngineButton->setEnabled(host.size() > 0);
        clearCacheButton->setEnabled(host.size() > 0);
        engineCombo->setEnabled(host.size() > 0);
hrchilds's avatar
hrchilds committed
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
    }

    if(caller == statusAtts || doAll)
    {
        QString key(statusAtts->GetSender().c_str());

        if(key != QString("viewer"))
        {    
            UpdateStatusEntry(key);

            // If the sender of the status message is the engine that we're
            // currently looking at, update the status widgets.
            if(key == activeEngine)
            {
                UpdateStatusArea();
            }
        }
    }
}

// ****************************************************************************
// Method: QvisEngineWindow::UpdateInformation
//
// Purpose: 
//   Updates the engine information.
//
// Arguments:
//   index : The index of the engine to update.
//
// Programmer: Brad Whitlock
// Creation:   Wed Nov 27 14:46:52 PST 2002
//
// Modifications:
hrchilds's avatar
hrchilds committed
442 443 444
//    Jeremy Meredith, Tue Mar 30 09:34:03 PST 2004
//    I added support for simulations.
//
445 446 447
//    Brad Whitlock, Mon Oct 10 12:49:25 PDT 2011
//    I added more information.
//
hrchilds's avatar
hrchilds committed
448 449 450 451 452
// ****************************************************************************

void
QvisEngineWindow::UpdateInformation(int index)
{
453
    const stringVector &s = engines->GetEngineName();
hrchilds's avatar
hrchilds committed
454 455 456 457

    // Set the values of the engine information widgets.
    if(index == -1 || s.size() < 1)
    {
458
        engineLabel->setText(tr("Engine:"));
hrchilds's avatar
hrchilds committed
459
        engineNN->setText("");
460 461
        engineNP->setText("");
        engineNP_GPU->setText("");
hrchilds's avatar
hrchilds committed
462
        engineLB->setText("");
463
        engineLB_Scheme->setText("");
hrchilds's avatar
hrchilds committed
464 465 466 467
        engineInfo->setEnabled(false);
    }
    else
    {
hrchilds's avatar
hrchilds committed
468
        if (engines->GetSimulationName()[index] != "")
hrchilds's avatar
hrchilds committed
469
        {
470
            engineLabel->setText(tr("Simulation:"));
whitlocb's avatar
whitlocb committed
471
            closeEngineButton->setText(tr("Disconnect"));
hrchilds's avatar
hrchilds committed
472
        }
hrchilds's avatar
hrchilds committed
473
        else
hrchilds's avatar
hrchilds committed
474
        {
475 476
            engineLabel->setText(tr("Engine:"));
            closeEngineButton->setText(tr("Close engine"));
hrchilds's avatar
hrchilds committed
477
        }
hrchilds's avatar
hrchilds committed
478

479
        const EngineProperties &props = engines->GetProperties(index);
hrchilds's avatar
hrchilds committed
480

481
        if(props.GetNumNodes() == -1)
482
            engineNN->setText(tr("Default"));
hrchilds's avatar
hrchilds committed
483
        else 
484 485 486 487 488 489
            engineNN->setText(QString("%1").arg(props.GetNumNodes()));

        engineNP->setText(QString("%1").arg(props.GetNumProcessors()));
        engineNP_GPU->setText(QString("%1").arg(props.GetNumProcessorsUsingGPUs()));

        if(props.GetDynamicLoadBalancing())
hrchilds's avatar
hrchilds committed
490
        {
491 492
            engineLB->setText(tr("Dynamic"));
            engineLB_Scheme->setText(tr("Dynamic"));
hrchilds's avatar
hrchilds committed
493 494
        }
        else
495 496 497 498
        {
            engineLB->setText(tr("Static"));
            engineLB_Scheme->setText(props.GetLoadBalancingScheme().c_str());
        }
hrchilds's avatar
hrchilds committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521

        engineInfo->setEnabled(true);
    }
}

// ****************************************************************************
// Method: QvisEngineWindow::UpdateStatusArea
//
// Purpose: 
//   Updates the window so it reflects the status information for the 
//   currently selected engine.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:35:12 PST 2001
//
// Modifications:
//    Jeremy Meredith, Fri Jun 29 15:12:08 PDT 2001
//    Separated the single status/progress bar into one which reports
//    total status and one which reports current stage progress.
//   
//    Jeremy Meredith, Thu Jul  5 12:40:30 PDT 2001
//    Added an explicit cast to avoid a warning.
//
522
//    Brad Whitlock, Tue Apr 29 10:45:23 PDT 2008
523 524
//    Support for internationalization.
//
whitlocb's avatar
whitlocb committed
525 526 527
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
528 529 530 531 532
// ****************************************************************************

void
QvisEngineWindow::UpdateStatusArea()
{
whitlocb's avatar
whitlocb committed
533 534
    
    if(!statusMap.contains(activeEngine))
hrchilds's avatar
hrchilds committed
535
        return;
whitlocb's avatar
whitlocb committed
536 537
        
    StatusAttributes *s = statusMap[activeEngine];
hrchilds's avatar
hrchilds committed
538 539
    if(s->GetClearStatus())
    {
hrchilds's avatar
hrchilds committed
540
        s->SetStatusMessage("");
541
        totalStatusLabel->setText(tr("Total Status:"));
hrchilds's avatar
hrchilds committed
542
        totalProgressBar->reset();
543
        stageStatusLabel->setText(tr("Stage Status:"));
hrchilds's avatar
hrchilds committed
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
        stageProgressBar->reset();
    }
    else
    {
        int total;
        if (s->GetMaxStage() > 0)
        {
            float pct0  = float(s->GetPercent()) / 100.;
            float pct1  = float(s->GetCurrentStage()-1) / float(s->GetMaxStage());
            float pct2  = float(s->GetCurrentStage())   / float(s->GetMaxStage());
            total = int(100. * ((pct0 * pct2) + ((1.-pct0) * pct1)));
        }
        else
            total = 0;

        if(s->GetMessageType() == 1)
        {
561
            totalStatusLabel->setText(StatusAttributes_GetStatusMessage(*s));
562
            stageStatusLabel->setText(tr("Stage Status:"));
hrchilds's avatar
hrchilds committed
563 564 565 566
        }
        else if (s->GetMessageType() == 2)
        {
            QString msg;
567 568
            msg.sprintf("%d/%d", s->GetCurrentStage(), s->GetMaxStage());
            msg = tr("Total Status: Stage ") + msg;
hrchilds's avatar
hrchilds committed
569
            totalStatusLabel->setText(msg);
570
            msg = tr("Stage Status: ") + QString(s->GetCurrentStageName().c_str());
hrchilds's avatar
hrchilds committed
571 572 573 574
            stageStatusLabel->setText(msg);
        }

        // Set the progress bar percent done.
whitlocb's avatar
whitlocb committed
575 576
        totalProgressBar->setValue(total);
        stageProgressBar->setValue(s->GetPercent());
hrchilds's avatar
hrchilds committed
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
    }
}

// ****************************************************************************
// Method: QvisEngineWindow::ConnectStatusAttributes
//
// Purpose: 
//   Connects the status attributes subject that the window will observe.
//
// Arguments:
//   s : A pointer to the status attributes that the window will observe.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:31:48 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisEngineWindow::ConnectStatusAttributes(StatusAttributes *s)
{
    if(s)
    {
        statusAtts = s;
        statusAtts->Attach(this);
    }
}

// ****************************************************************************
// Method: QvisEngineWindow::AddStatusEntry
//
// Purpose: 
//   Adds an engine to the internal status map.
//
// Arguments:
//   key : The name of the engine to add to the map.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:35:50 PST 2001
//
// Modifications:
//   
// ****************************************************************************

void
QvisEngineWindow::AddStatusEntry(const QString &key)
{
    // If the entry is in the map, return.
    if(statusMap.contains(key))
        return;

    // Add the entry to the map.
    StatusAttributes *s = new StatusAttributes;
    *s = *statusAtts;
    statusMap.insert(key, s);
}

// ****************************************************************************
// Method: QvisEngineWindow::RemoveStatusEntry
//
// Purpose: 
//   Removes an engine from the internal status map.
//
// Arguments:
//   key : The name of the engine to remove from the map.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:35:50 PST 2001
//
// Modifications:
whitlocb's avatar
whitlocb committed
648 649 650
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
651 652 653 654 655 656
// ****************************************************************************

void
QvisEngineWindow::RemoveStatusEntry(const QString &key)
{
    // If the entry is not in the map, return.
whitlocb's avatar
whitlocb committed
657 658
    if(!statusMap.contains(key))
        return;    
hrchilds's avatar
hrchilds committed
659 660

    // Delete the status attributes that are in the map.
whitlocb's avatar
whitlocb committed
661
    delete statusMap[key];
hrchilds's avatar
hrchilds committed
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
    // Remove the key from the map.
    statusMap.remove(key);
}

// ****************************************************************************
// Method: QvisEngineWindow::UpdateStatusEntry
//
// Purpose: 
//   Makes the specified entry in the status map update to the current status
//   in the status attributes.
//
// Arguments:
//   key : The name of the engine whose status entry we want to update.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:36:43 PST 2001
//
// Modifications:
whitlocb's avatar
whitlocb committed
680 681 682 683
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
//
hrchilds's avatar
hrchilds committed
684 685 686 687 688 689 690
// ****************************************************************************

void
QvisEngineWindow::UpdateStatusEntry(const QString &key)
{
    // If the sender is in the status map, copy the status into the map entry.
    // If the sender is not in the map, add it.
whitlocb's avatar
whitlocb committed
691 692 693
    QMapIterator<QString, StatusAttributes*> itr(statusMap);
    
    if(statusMap.contains(activeEngine))
hrchilds's avatar
hrchilds committed
694
    {
whitlocb's avatar
whitlocb committed
695
        *statusMap[activeEngine] = *statusAtts;
hrchilds's avatar
hrchilds committed
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
    }
    else
        AddStatusEntry(key);
}

//
// Qt slots
//

// ****************************************************************************
// Method: QvisEngineWindow::closeEngine
//
// Purpose: 
//   This is a Qt slot function that is called when the "Close engine" button
//   is clicked. Its job is to tell the viewer to close the engine being
//   displayed by the window.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:37:35 PST 2001
//
// Modifications:
717 718 719 720 721
//   Jeremy Meredith, Tue Mar 30 09:34:33 PST 2004
//   I added support for simulations.
//
//   Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//   Support for internationalization.
hrchilds's avatar
hrchilds committed
722
//
whitlocb's avatar
whitlocb committed
723 724 725
//   Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//   Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
726 727 728 729 730
// ****************************************************************************

void
QvisEngineWindow::closeEngine()
{
whitlocb's avatar
whitlocb committed
731
    int index = engineCombo->currentIndex();
hrchilds's avatar
hrchilds committed
732 733 734
    if (index < 0)
        return;

735
    string host = engines->GetEngineName()[index];
hrchilds's avatar
hrchilds committed
736 737
    string sim  = engines->GetSimulationName()[index];

hrchilds's avatar
hrchilds committed
738 739
    // Create a prompt for the user.
    QString msg;
hrchilds's avatar
hrchilds committed
740 741
    if (sim == "")
    {
742 743
        msg = tr("Really close the compute engine on host \"%1\"?\n\n").
              arg(host.c_str());
hrchilds's avatar
hrchilds committed
744 745 746
    }
    else
    {
747
        msg = tr("Really disconnect from the simulation \"%1\" on "
748 749 750
                 "host \"%2\"?\n\n").
              arg(sim.c_str()).
              arg(host.c_str());
hrchilds's avatar
hrchilds committed
751
    }
hrchilds's avatar
hrchilds committed
752 753 754

    // Ask the user if he really wants to close the engine.
    if(QMessageBox::warning( this, "VisIt",
755
                             msg,
756
                             tr("Ok"), tr("Cancel"), 0,
hrchilds's avatar
hrchilds committed
757 758 759
                             0, 1 ) == 0)
    {
        // The user actually chose to close the engine.
hrchilds's avatar
hrchilds committed
760
        GetViewerMethods()->CloseComputeEngine(host, sim);
hrchilds's avatar
hrchilds committed
761 762 763 764 765 766 767 768 769 770 771 772 773 774
    }
}

// ****************************************************************************
// Method: QvisEngineWindow::interruptEngine
//
// Purpose: 
//   This is a Qt slot function that is called to interrupt the engine that's
//   displayed in the window.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:38:41 PST 2001
//
// Modifications:
hrchilds's avatar
hrchilds committed
775 776
//    Jeremy Meredith, Tue Mar 30 09:34:33 PST 2004
//    I added support for simulations.
hrchilds's avatar
hrchilds committed
777
//   
whitlocb's avatar
whitlocb committed
778 779 780
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
781 782 783 784 785
// ****************************************************************************

void
QvisEngineWindow::interruptEngine()
{
whitlocb's avatar
whitlocb committed
786
    int index = engineCombo->currentIndex();
hrchilds's avatar
hrchilds committed
787 788
    if (index < 0)
        return;
789
    string host = engines->GetEngineName()[index];
hrchilds's avatar
hrchilds committed
790 791
    string sim  = engines->GetSimulationName()[index];

hrchilds's avatar
hrchilds committed
792
    GetViewerProxy()->InterruptComputeEngine(host, sim);
hrchilds's avatar
hrchilds committed
793 794
}

hrchilds's avatar
hrchilds committed
795 796 797 798 799 800 801 802 803 804 805
// ****************************************************************************
// Method: QvisEngineWindow::clearCache
//
// Purpose: 
//   This is a Qt slot function that is called to tell the current engine
//   to clear its cache.
//
// Programmer: Brad Whitlock
// Creation:   Thu Feb 26 14:16:39 PST 2004
//
// Modifications:
hrchilds's avatar
hrchilds committed
806 807 808
//    Jeremy Meredith, Tue Mar 30 09:34:33 PST 2004
//    I added support for simulations.
//
whitlocb's avatar
whitlocb committed
809 810 811
//    Cyrus Harrison, Tue Jun 24 11:15:28 PDT 2008
//    Initial Qt4 Port.
//
hrchilds's avatar
hrchilds committed
812 813 814 815 816
// ****************************************************************************

void
QvisEngineWindow::clearCache()
{
whitlocb's avatar
whitlocb committed
817
    int index = engineCombo->currentIndex();
hrchilds's avatar
hrchilds committed
818 819
    if (index < 0)
        return;
820
    string host = engines->GetEngineName()[index];
hrchilds's avatar
hrchilds committed
821 822
    string sim  = engines->GetSimulationName()[index];

hrchilds's avatar
hrchilds committed
823 824
    if(GetViewerProxy()->GetLocalHostName() == host)
        GetViewerMethods()->ClearCache("localhost", sim);
hrchilds's avatar
hrchilds committed
825
    else
hrchilds's avatar
hrchilds committed
826
        GetViewerMethods()->ClearCache(host, sim);
hrchilds's avatar
hrchilds committed
827 828
}

hrchilds's avatar
hrchilds committed
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
// ****************************************************************************
// Method: QvisEngineWindow::selectEngine
//
// Purpose: 
//   This is a Qt slot function that is called when selecting a new engine
//   to display.
//
// Arguments:
//   index : The index to use for the next active engine.
//
// Programmer: Brad Whitlock
// Creation:   Wed May 2 16:39:26 PST 2001
//
// Modifications:
//   Brad Whitlock, Wed Nov 27 14:47:32 PST 2002
//   I added code to update the engine.
//
hrchilds's avatar
hrchilds committed
846 847 848
//   Jeremy Meredith, Tue Mar 30 09:34:33 PST 2004
//   I added support for simulations.
//
hrchilds's avatar
hrchilds committed
849 850 851 852 853
// ****************************************************************************

void
QvisEngineWindow::selectEngine(int index)
{
hrchilds's avatar
hrchilds committed
854 855
    if (engines->GetSimulationName()[index]=="")
        activeEngine = QString().sprintf("%s",
856
                                         engines->GetEngineName()[index].c_str());
hrchilds's avatar
hrchilds committed
857 858
    else
        activeEngine = QString().sprintf("%s:%s",
859
                                  engines->GetEngineName()[index].c_str(),
hrchilds's avatar
hrchilds committed
860
                                  engines->GetSimulationName()[index].c_str());
hrchilds's avatar
hrchilds committed
861 862 863 864 865 866 867

    // Update the rest of the widgets using the information for the
    // active engine.
    UpdateStatusArea();
    // Update the engine information.
    UpdateInformation(index);
}