QvisTraceHistoryWindow.C 10.9 KB
Newer Older
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-400142
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
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
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
30 31 32 33 34 35 36 37 38 39 40 41 42 43
* 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.
*
*****************************************************************************/

#include "QvisTraceHistoryWindow.h"

#include <TraceHistoryAttributes.h>
#include <ViewerProxy.h>

cyrush's avatar
cyrush committed
44 45 46 47 48 49 50 51
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
#include <QSpinBox>
#include <QButtonGroup>
#include <QRadioButton>

52 53 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
#include <QvisColorTableButton.h>
#include <QvisOpacitySlider.h>
#include <QvisColorButton.h>
#include <QvisLineStyleWidget.h>
#include <QvisLineWidthWidget.h>
#include <QvisVariableButton.h>

#include <stdio.h>
#include <string>

using std::string;

// ****************************************************************************
// Method: QvisTraceHistoryWindow::QvisTraceHistoryWindow
//
// Purpose: 
//   Constructor
//
// Programmer: xml2window
// Creation:   Sun Apr 8 17:04:23 PST 2007
//
// Modifications:
//   
// ****************************************************************************

QvisTraceHistoryWindow::QvisTraceHistoryWindow(const int type,
                         TraceHistoryAttributes *subj,
79 80
                         const QString &caption,
                         const QString &shortName,
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                         QvisNotepadArea *notepad)
    : QvisOperatorWindow(type,subj, caption, shortName, notepad)
{
    atts = subj;
}


// ****************************************************************************
// Method: QvisTraceHistoryWindow::~QvisTraceHistoryWindow
//
// Purpose: 
//   Destructor
//
// Programmer: xml2window
// Creation:   Sun Apr 8 17:04:23 PST 2007
//
// Modifications:
//   
// ****************************************************************************

QvisTraceHistoryWindow::~QvisTraceHistoryWindow()
{
}


// ****************************************************************************
// Method: QvisTraceHistoryWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
// Programmer: xml2window
// Creation:   Sun Apr 8 17:04:23 PST 2007
//
// Modifications:
116 117 118
//   Brad Whitlock, Thu Apr 24 15:56:45 PDT 2008
//   Added tr()'s
//
cyrush's avatar
cyrush committed
119 120 121
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
122 123 124 125 126
// ****************************************************************************

void
QvisTraceHistoryWindow::CreateWindowContents()
{
cyrush's avatar
cyrush committed
127 128
    QGridLayout *mainLayout = new QGridLayout();
    topLayout->addLayout(mainLayout);
129

cyrush's avatar
cyrush committed
130
    varsButton = new QvisVariableButton(true, false, true, -1,central);
131
    varsButton->setText(tr("Variables"));
132 133 134 135 136
    varsButton->setChangeTextOnVariableChange(false);
    connect(varsButton, SIGNAL(activated(const QString &)),
            this, SLOT(addVariable(const QString &)));
    mainLayout->addWidget(varsButton, 0, 0);

cyrush's avatar
cyrush committed
137
    varsLineEdit = new QLineEdit(central);
138 139 140 141 142
    varsLineEdit->setText("");
    connect(varsLineEdit, SIGNAL(returnPressed()),
            this, SLOT(variableProcessText()));
    mainLayout->addWidget(varsLineEdit, 0, 1);

cyrush's avatar
cyrush committed
143
    displacementLabel = new QLabel(tr("Displacement variable"), central);
144 145
    mainLayout->addWidget(displacementLabel,1,0);
    int displacementMask = QvisVariableButton::Vectors;
cyrush's avatar
cyrush committed
146
    displacement = new QvisVariableButton(true, true, true, displacementMask, central);
147 148 149 150
    connect(displacement, SIGNAL(activated(const QString&)),
            this, SLOT(displacementChanged(const QString&)));
    mainLayout->addWidget(displacement, 1,1);

cyrush's avatar
cyrush committed
151
    numiterLabel = new QLabel(tr("Number of iterations"), central);
152
    mainLayout->addWidget(numiterLabel,2,0);
cyrush's avatar
cyrush committed
153
    numiter = new QLineEdit(central);
154 155 156 157
    connect(numiter, SIGNAL(returnPressed()),
            this, SLOT(numiterProcessText()));
    mainLayout->addWidget(numiter, 2,1);

cyrush's avatar
cyrush committed
158
    outputLabel = new QLabel(tr("Output file"), central);
159
    mainLayout->addWidget(outputLabel,3,0);
cyrush's avatar
cyrush committed
160
    output = new QLineEdit(central);
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    connect(output, SIGNAL(returnPressed()),
            this, SLOT(outputProcessText()));
    mainLayout->addWidget(output, 3,1);

}


// ****************************************************************************
// Method: QvisTraceHistoryWindow::UpdateWindow
//
// Purpose: 
//   Updates the widgets in the window when the subject changes.
//
// Programmer: xml2window
// Creation:   Sun Apr 8 17:04:23 PST 2007
//
// Modifications:
178 179 180
//   Kathleen Bonnell, Mon Jun 30 15:16:12 PDT 2008
//   Removed unreferenced variables.
//
cyrush's avatar
cyrush committed
181 182 183
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
// ****************************************************************************

void
QvisTraceHistoryWindow::UpdateWindow(bool doAll)
{
    QString temp;
    char str[1024];

    for(int i = 0; i < atts->NumAttributes(); ++i)
    {
        if(!doAll)
        {
            if(!atts->IsSelected(i))
            {
                continue;
            }
        }

        switch(i)
        {
cyrush's avatar
cyrush committed
204
            case 0: //vars
205
            {
cyrush's avatar
cyrush committed
206 207 208 209
                temp = "";
                for (int j = 0 ; j < atts->GetVars().size() ; j++)
                    temp += QString(atts->GetVars()[j].c_str()) + QString(" ");
                varsLineEdit->setText(temp);
210 211
            }
            break;
cyrush's avatar
cyrush committed
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
            case 1: //displacement
                displacement->blockSignals(true);
                displacement->setText(atts->GetDisplacement().c_str());
                displacement->blockSignals(false);
                break;
            case 2: //numiter
                numiter->blockSignals(true);
                temp.sprintf("%d", atts->GetNumiter());
                numiter->setText(temp);
                numiter->blockSignals(false);
                break;
            case 3: //output
                temp = atts->GetOutput().c_str();
                output->blockSignals(true);
                output->setText(temp);
                output->blockSignals(false);
                break;
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
        }
    }
}


// ****************************************************************************
// Method: QvisTraceHistoryWindow::GetCurrentValues
//
// Purpose: 
//   Gets values from certain widgets and stores them in the subject.
//
// Programmer: xml2window
// Creation:   Sun Apr 8 17:04:23 PST 2007
//
// Modifications:
cyrush's avatar
cyrush committed
244 245 246
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
247 248 249 250 251 252 253 254 255 256 257 258
// ****************************************************************************

void
QvisTraceHistoryWindow::GetCurrentValues(int which_widget)
{
    bool okay, doAll = (which_widget == -1);
    QString msg, temp;

    // Do exprs
    if(which_widget == 0 || doAll)
    {
        stringVector userVars;
cyrush's avatar
cyrush committed
259 260
        temp = varsLineEdit->text().simplified();
        QStringList lst = temp.split(" ",QString::SkipEmptyParts);
261

cyrush's avatar
cyrush committed
262 263 264
        QStringListIterator it(lst);
        while(it.hasNext())
            userVars.push_back(it.next().toStdString());
265 266 267 268 269 270 271 272 273 274 275 276
        atts->SetVars(userVars);
    }

    // Do displacement
    if(which_widget == 1 || doAll)
    {
        // Nothing for displacement
    }

    // Do numiter
    if(which_widget == 2 || doAll)
    {
cyrush's avatar
cyrush committed
277 278 279 280 281
    
        int val;
        if(LineEditGetInt(numiter, val))
            atts->SetNumiter(val);
        else
282
        {
cyrush's avatar
cyrush committed
283 284
            ResettingError(tr("number of iterations"),
                           IntToQString(atts->GetNumiter()));
285 286 287 288 289 290 291
            atts->SetNumiter(atts->GetNumiter());
        }
    }

    // Do output
    if(which_widget == 3 || doAll)
    {
cyrush's avatar
cyrush committed
292 293
        temp = output->text();
        if(!temp.isEmpty())
294
        {
cyrush's avatar
cyrush committed
295
            atts->SetOutput(temp.toStdString());
296
        }
cyrush's avatar
cyrush committed
297
        else
298
        {
cyrush's avatar
cyrush committed
299 300
            ResettingError(tr("output"),
                           atts->GetOutput().c_str());
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
            atts->SetOutput(atts->GetOutput());
        }
    }

}


//
// Qt Slot functions
//


//writeSourceCallback unknown for stringVector (variable exprs)


void
QvisTraceHistoryWindow::displacementChanged(const QString &varName)
{
cyrush's avatar
cyrush committed
319
    atts->SetDisplacement(varName.toStdString());
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    SetUpdate(false);
    Apply();
}


void
QvisTraceHistoryWindow::numiterProcessText()
{
    GetCurrentValues(2);
    Apply();
}


void
QvisTraceHistoryWindow::outputProcessText()
{
    GetCurrentValues(3);
    Apply();
}

//
// Qt Slot functions
//
void
QvisTraceHistoryWindow::variableProcessText()
{
    GetCurrentValues(0);
    Apply();
}



// ****************************************************************************
// Method: QvisTraceHistoryWindow::addVariable
//
// Purpose:
//   This is a Qt slot function that is called when the user selects a new
//   pick variable.
//
// Arguments:
//   var : The pick variable to add.
//
// Programmer: Hank Childs
// Creation:   April 8, 2007
//
// Modifications:
cyrush's avatar
cyrush committed
366 367
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
368 369 370 371 372 373 374
//
// ****************************************************************************

void
QvisTraceHistoryWindow::addVariable(const QString &var)
{
    // Add the new variable to the pick variable line edit.
cyrush's avatar
cyrush committed
375
    QString varString(varsLineEdit->text());
376 377 378 379 380 381 382 383 384 385 386
    if(varString.length() > 0)
        varString += " ";
    varString += var;
    varsLineEdit->setText(varString);

    // Process the list of pick vars.
    variableProcessText();
}