SimCommandSlots.C 13.9 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2013, 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 "SimCommandSlots.h"
whitlocb's avatar
whitlocb committed
40 41 42 43 44 45

#include <QDateTime>
#include <QDateTimeEdit>
#include <QMessageBox>
#include <QString>
#include <QTableWidget>
hrchilds's avatar
hrchilds committed
46 47 48 49 50 51 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 79 80 81 82 83 84 85 86 87

#include <EngineList.h>
#include <StatusAttributes.h>
#include <ViewerProxy.h>
#include <string>
#include <DebugStream.h>


using std::string;

// ****************************************************************************
// Method: SimCommandSlots::SimCommandSlots
//
// Purpose:
//   This is the constructor for the SimCommandSlots class.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

SimCommandSlots::SimCommandSlots(ViewerProxy *theViewer,
    EngineList *engineList, int index)
{
    viewer = theViewer;
    simIndex = index;
    engines = engineList;
}

// ****************************************************************************
// Method: SimCommandSlots::SendCMD
//
// Purpose:
//   This is the main function called to send a Visit UI signal to
//   the remote running simulation program.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
88 89
//   Brad Whitlock, Tue Apr  8 16:29:55 PDT 2008
//   Support for internationalization.
hrchilds's avatar
hrchilds committed
90
//
whitlocb's avatar
whitlocb committed
91 92 93
//   Brad Whitlock, Tue Jul  8 11:16:09 PDT 2008
//   Qt 4.
//
94 95 96
//   Brad Whitlock, Sun Feb 27 14:08:32 PST 2011
//   Reorder command string.
//
hrchilds's avatar
hrchilds committed
97 98 99 100 101
// ****************************************************************************

int SimCommandSlots::SendCMD(QString sig, const QObject *ui, QString value)
{
    if (ui)
whitlocb's avatar
whitlocb committed
102 103
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
104
    else
105 106
        QMessageBox::warning(0, "VisIt", tr("Invalid ui component"),
                             tr("Ok"), 0, 0, 0, 1 );
hrchilds's avatar
hrchilds committed
107 108 109
    if (simIndex < 0)
    {
        QMessageBox::warning(0, "VisIt",
110 111
                             tr("Invalid index encountered for Sim engine access"),
                             tr("Ok"), 0, 0, 0, 1 );
hrchilds's avatar
hrchilds committed
112 113 114
        return -1;
    }

115
    string host = engines->GetEngineName()[simIndex];
hrchilds's avatar
hrchilds committed
116 117
    string sim  = engines->GetSimulationName()[simIndex];

118 119 120 121 122
    QString cmd = QString("UI;%1;%2;%3;%4").arg(ui->objectName())
                                     .arg(ui->metaObject()->className())
                                     .arg(sig)
                                     .arg(value);

whitlocb's avatar
whitlocb committed
123
    viewer->GetViewerMethods()->SendSimulationCommand(host, sim, cmd.toStdString());
124

hrchilds's avatar
hrchilds committed
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
    return 0;
}

// ****************************************************************************
// Method: SimCommandSlots::ClickedHandler
//
// Purpose:
//   This is the clicked signal handler function. It is generated when
//   the users clicks on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::ClickedHandler()
{
    const QObject *ui = sender();
    debug5 << "inside clicked signal" << endl;
    SendCMD("clicked()", ui, "NONE");
}

// ****************************************************************************
// Method: SimCommandSlots::ValueChangedHandler
//
// Purpose:
//   This is the ValueChangedHandler signal handler function. It is generated
//   when the users changes a value on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
whitlocb's avatar
whitlocb committed
160 161
//   Brad Whitlock, Tue Jul  8 11:17:38 PDT 2008
//   Qt 4.
hrchilds's avatar
hrchilds committed
162 163 164 165 166 167 168 169 170
//
// ****************************************************************************

void SimCommandSlots::ValueChangedHandler(int index)
{
    const QObject *ui = sender();
    debug5 << "inside ValueChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
171 172
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
173 174 175 176 177
        debug5 << "New Value = " << index << endl;
    }
    else
        debug5 << "unknown signaler" << endl;
    QString value = QString::number(index);
178
    SendCMD("valueChanged(int)", ui, value);
hrchilds's avatar
hrchilds committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
}

// ****************************************************************************
// Method: SimCommandSlots::ValueChangedHandler
//
// Purpose:
//   This is the ValueChangedHandler signal handler function. It is generated
//   when the users changes a value on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::ValueChangedHandler(const QTime &theTime)
{
    const QObject *ui = sender();
    debug5 << "inside ValueChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
201 202
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
203 204 205 206
    }
    else
        debug5 << "unknown signaler" << endl;
    QString value = theTime.toString();
207
    SendCMD("valueChanged(QTime)", ui, value);
hrchilds's avatar
hrchilds committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
}

// ****************************************************************************
// Method: SimCommandSlots::ValueChangedHandler
//
// Purpose:
//   This is the ValueChangedHandler signal handler function. It is generated
//   when the users changes a value on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::ValueChangedHandler(const QDate &theDate)
{
    const QObject *ui = sender();
    debug5 << "inside ValueChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
230 231
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
232 233 234 235
    }
    else
        debug5 << "unknown signaler" << endl;
    QString value = theDate.toString();
236
    SendCMD("valueChanged(QDate)", ui, value);
hrchilds's avatar
hrchilds committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
}

// ****************************************************************************
// Method: SimCommandSlots::SimCommandSlots
//
// Purpose:
//   This is the StateChangedHandler signal handler function. It is generated
//   when the users changes a value on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::StateChangedHandler(int OnOff)
{                    
    const QObject *ui = sender();
    debug5 << "inside StateChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
259 260
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
261 262 263
    }
    else
        debug5 << "unknown signaler" << endl;
264 265
    QString value(QString::number(OnOff ? 1 : 0));
    SendCMD("stateChanged(int)", ui, value);
hrchilds's avatar
hrchilds committed
266 267 268 269 270 271 272 273 274 275 276 277 278
}

// ****************************************************************************
// Method: SimCommandSlots::CurrentChangedHandler
//
// Purpose:
//   This is the CurrentChangedHandler signal handler function. It is generated
//   when the users changes a text value inside a text custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
whitlocb's avatar
whitlocb committed
279 280
//   Brad Whitlock, Tue Jul  8 11:28:04 PDT 2008
//   Qt 4.
hrchilds's avatar
hrchilds committed
281 282 283 284 285 286
//
// ****************************************************************************

void SimCommandSlots::CurrentChangedHandler(int row, int col)
{
    const QObject *ui = sender();
287
    debug5 << "inside CurrentChangedHandler signal" << endl;
whitlocb's avatar
whitlocb committed
288
    QString tvalue;
hrchilds's avatar
hrchilds committed
289 290
    if (ui)
    {
whitlocb's avatar
whitlocb committed
291 292 293
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
        tvalue = ((QTableWidget *)ui)->item(row, col)->text();
hrchilds's avatar
hrchilds committed
294
        debug5 << "New Value row,col,text = " << row << ", " << col << ", "
whitlocb's avatar
whitlocb committed
295
               << tvalue.toStdString() << endl;
hrchilds's avatar
hrchilds committed
296 297 298
    }
    else
        debug5 << "unknown signaler" << endl;
whitlocb's avatar
whitlocb committed
299
    QString value = QString::number(row) + ";" + QString::number(col) + ";" + tvalue;
300
    SendCMD("currentChanged(int,int)", ui, value);
hrchilds's avatar
hrchilds committed
301 302
}

303 304 305 306 307 308 309 310 311 312 313 314

// ****************************************************************************
// Method: SimCommandSlots::ValueChangedHandler
//
// Purpose:
//   This is the CurrentChangedHandler signal handler function. It is generated
//   when the users changes a text value inside a text custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Mon Jun 18 16:56:13 PDT 2007
//
// Modifications:
whitlocb's avatar
whitlocb committed
315 316
//   Brad Whitlock, Tue Jul  8 11:28:04 PDT 2008
//   Qt 4.
317 318 319 320 321 322 323
//
// ****************************************************************************

void SimCommandSlots::ValueChangedHandler(int row, int col)
{
    const QObject *ui = sender();
    debug5 << "inside ValueChangedHandler signal" << endl;
whitlocb's avatar
whitlocb committed
324
    QString tvalue;
325 326
    if (ui)
    {
whitlocb's avatar
whitlocb committed
327 328 329
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
        tvalue = ((QTableWidget *)ui)->item(row, col)->text();
330
        debug5 << "New Value row,col,text = " << row << ", " << col << ", "
whitlocb's avatar
whitlocb committed
331
               << tvalue.toStdString() << endl;
332 333 334
    }
    else
        debug5 << "unknown signaler" << endl;
whitlocb's avatar
whitlocb committed
335
    QString value = QString::number(row) + ";" + QString::number(col) + ";" + tvalue;
336
    SendCMD("valueChanged(int,int)", ui, value);
337 338
}

hrchilds's avatar
hrchilds committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
// ****************************************************************************
// Method: SimCommandSlots::ActivatedHandler
//
// Purpose:
//   This is the ActivatedHandler signal handler function. It is generated when
//   the users action cause a value change on a custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::ActivatedHandler(int index)
{
    const QObject *ui = sender();
    debug5 << "inside ValueChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
359 360
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
hrchilds's avatar
hrchilds committed
361 362 363 364 365
        debug5 << "New Value = " << index << endl;
    }
    else
        debug5 << "unknown signaler" << endl;
    QString value = QString::number(index);
366
    SendCMD("activated(int)", ui, value);
hrchilds's avatar
hrchilds committed
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
}

// ****************************************************************************
// Method: SimCommandSlots::TextChangedHandler
//
// Purpose:
//   This is the TextChangedHandler signal handler function. It is generated
//   when the users changes the text in a line edit type custom UI widget.
//
// Programmer: Shelly Prevost
// Creation:   Jan 6, 2006
//
// Modifications:
//
// ****************************************************************************

void SimCommandSlots::TextChangedHandler(const QString &newText)
{
    const QObject *ui = sender();
    debug5 << "inside TextChangedHandler signal" << endl;
    if (ui)
    {
whitlocb's avatar
whitlocb committed
389 390 391
        debug5 << "signal sender is type " << ui->metaObject()->className() << " named "
               << ui->objectName().toStdString().c_str() << " parent " << ui->parent()->objectName().toStdString().c_str() << endl;
        debug5 << "New Text Value = " << newText.toStdString() << endl;
hrchilds's avatar
hrchilds committed
392 393 394
    }
    else
        debug5 << "unknown signaler" << endl;
395
    SendCMD("textChanged(QString)", ui, newText);
hrchilds's avatar
hrchilds committed
396
}