QvisTraceHistoryWindow.C 10.5 KB
Newer Older
1 2
/*****************************************************************************
*
bonnell's avatar
bonnell committed
3
* Copyright (c) 2000 - 2017, Lawrence Livermore National Security, LLC
4
* Produced at the Lawrence Livermore National Laboratory
5
* LLNL-CODE-442911
6 7
* All rights reserved.
*
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
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
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
* 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>

cyrush's avatar
cyrush committed
43 44 45 46
#include <QLabel>
#include <QLayout>
#include <QLineEdit>

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include <QvisVariableButton.h>


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

QvisTraceHistoryWindow::QvisTraceHistoryWindow(const int type,
                         TraceHistoryAttributes *subj,
65 66
                         const QString &caption,
                         const QString &shortName,
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
                         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:
102 103 104
//   Brad Whitlock, Thu Apr 24 15:56:45 PDT 2008
//   Added tr()'s
//
cyrush's avatar
cyrush committed
105 106 107
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
108 109 110 111 112
// ****************************************************************************

void
QvisTraceHistoryWindow::CreateWindowContents()
{
cyrush's avatar
cyrush committed
113 114
    QGridLayout *mainLayout = new QGridLayout();
    topLayout->addLayout(mainLayout);
115

cyrush's avatar
cyrush committed
116
    varsButton = new QvisVariableButton(true, false, true, -1,central);
117
    varsButton->setText(tr("Variables"));
118 119 120 121 122
    varsButton->setChangeTextOnVariableChange(false);
    connect(varsButton, SIGNAL(activated(const QString &)),
            this, SLOT(addVariable(const QString &)));
    mainLayout->addWidget(varsButton, 0, 0);

cyrush's avatar
cyrush committed
123
    varsLineEdit = new QLineEdit(central);
124 125 126 127 128
    varsLineEdit->setText("");
    connect(varsLineEdit, SIGNAL(returnPressed()),
            this, SLOT(variableProcessText()));
    mainLayout->addWidget(varsLineEdit, 0, 1);

cyrush's avatar
cyrush committed
129
    displacementLabel = new QLabel(tr("Displacement variable"), central);
130 131
    mainLayout->addWidget(displacementLabel,1,0);
    int displacementMask = QvisVariableButton::Vectors;
cyrush's avatar
cyrush committed
132
    displacement = new QvisVariableButton(true, true, true, displacementMask, central);
133 134 135 136
    connect(displacement, SIGNAL(activated(const QString&)),
            this, SLOT(displacementChanged(const QString&)));
    mainLayout->addWidget(displacement, 1,1);

cyrush's avatar
cyrush committed
137
    numiterLabel = new QLabel(tr("Number of iterations"), central);
138
    mainLayout->addWidget(numiterLabel,2,0);
cyrush's avatar
cyrush committed
139
    numiter = new QLineEdit(central);
140 141 142 143
    connect(numiter, SIGNAL(returnPressed()),
            this, SLOT(numiterProcessText()));
    mainLayout->addWidget(numiter, 2,1);

cyrush's avatar
cyrush committed
144
    outputLabel = new QLabel(tr("Output file"), central);
145
    mainLayout->addWidget(outputLabel,3,0);
cyrush's avatar
cyrush committed
146
    output = new QLineEdit(central);
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    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:
164 165 166
//   Kathleen Bonnell, Mon Jun 30 15:16:12 PDT 2008
//   Removed unreferenced variables.
//
cyrush's avatar
cyrush committed
167 168 169
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
// ****************************************************************************

void
QvisTraceHistoryWindow::UpdateWindow(bool doAll)
{
    QString temp;

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

        switch(i)
        {
cyrush's avatar
cyrush committed
189
            case 0: //vars
190
            {
cyrush's avatar
cyrush committed
191 192 193 194
                temp = "";
                for (int j = 0 ; j < atts->GetVars().size() ; j++)
                    temp += QString(atts->GetVars()[j].c_str()) + QString(" ");
                varsLineEdit->setText(temp);
195 196
            }
            break;
cyrush's avatar
cyrush committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
            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;
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
        }
    }
}


// ****************************************************************************
// 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
229 230 231
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
//
232 233 234 235 236
// ****************************************************************************

void
QvisTraceHistoryWindow::GetCurrentValues(int which_widget)
{
237
    bool doAll = (which_widget == -1);
238 239 240 241 242 243
    QString msg, temp;

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

cyrush's avatar
cyrush committed
247 248 249
        QStringListIterator it(lst);
        while(it.hasNext())
            userVars.push_back(it.next().toStdString());
250 251 252 253 254 255 256 257 258 259 260 261
        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
262 263 264 265 266
    
        int val;
        if(LineEditGetInt(numiter, val))
            atts->SetNumiter(val);
        else
267
        {
cyrush's avatar
cyrush committed
268 269
            ResettingError(tr("number of iterations"),
                           IntToQString(atts->GetNumiter()));
270 271 272 273 274 275 276
            atts->SetNumiter(atts->GetNumiter());
        }
    }

    // Do output
    if(which_widget == 3 || doAll)
    {
cyrush's avatar
cyrush committed
277 278
        temp = output->text();
        if(!temp.isEmpty())
279
        {
cyrush's avatar
cyrush committed
280
            atts->SetOutput(temp.toStdString());
281
        }
cyrush's avatar
cyrush committed
282
        else
283
        {
cyrush's avatar
cyrush committed
284 285
            ResettingError(tr("output"),
                           atts->GetOutput().c_str());
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
            atts->SetOutput(atts->GetOutput());
        }
    }

}


//
// Qt Slot functions
//


//writeSourceCallback unknown for stringVector (variable exprs)


void
QvisTraceHistoryWindow::displacementChanged(const QString &varName)
{
cyrush's avatar
cyrush committed
304
    atts->SetDisplacement(varName.toStdString());
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 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
    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
351 352
//   Cyrus Harrison, Fri Dec  5 09:19:42 PST 2008
//   Initial Qt4 Port.
353 354 355 356 357 358 359
//
// ****************************************************************************

void
QvisTraceHistoryWindow::addVariable(const QString &var)
{
    // Add the new variable to the pick variable line edit.
cyrush's avatar
cyrush committed
360
    QString varString(varsLineEdit->text());
361 362 363 364 365 366 367 368 369 370 371
    if(varString.length() > 0)
        varString += " ";
    varString += var;
    varsLineEdit->setText(varString);

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