Logging.C 80.1 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2011, 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-442911
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
* 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.
*
*****************************************************************************/
whitlocb's avatar
whitlocb committed
38
#include <Python.h>
hrchilds's avatar
hrchilds committed
39

hrchilds's avatar
hrchilds committed
40 41 42 43 44 45
#include <ViewerProxy.h>
#include <ViewerRPC.h>
#include <PlotPluginManager.h>
#include <PlotPluginInfo.h>
#include <OperatorPluginManager.h>
#include <OperatorPluginInfo.h>
hrchilds's avatar
hrchilds committed
46
#include <DebugStream.h>
47
#include <TimingsManager.h>
hrchilds's avatar
hrchilds committed
48 49 50 51
#include <snprintf.h>
#include <visit-config.h>

#include <PyAnnotationAttributes.h>
52
#include <PyConstructDataBinningAttributes.h>
hrchilds's avatar
hrchilds committed
53 54 55 56
#include <PyExportDBAttributes.h>
#include <PyGlobalLineoutAttributes.h>
#include <PyInteractorAttributes.h>
#include <PyKeyframeAttributes.h>
57
#include <PyLaunchProfile.h>
hrchilds's avatar
hrchilds committed
58
#include <PyLightAttributes.h>
59
#include <PyMachineProfile.h>
hrchilds's avatar
hrchilds committed
60 61 62 63 64 65 66 67 68
#include <PyMaterialAttributes.h>
#include <PyMeshManagementAttributes.h>
#include <PyPickAttributes.h>
#include <PyPrinterAttributes.h>
#include <PyProcessAttributes.h>
#include <PyRenderingAttributes.h>
#include <PySaveWindowAttributes.h>
#include <PySILRestriction.h>
#include <PyQueryOverTimeAttributes.h>
69
#include <PyViewAxisArrayAttributes.h>
hrchilds's avatar
hrchilds committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <PyViewCurveAttributes.h>
#include <PyView2DAttributes.h>
#include <PyView3DAttributes.h>
#include <PyWindowInformation.h>

#include <avtSILRestriction.h>
#include <avtSILRestrictionTraverser.h>

#include <AnimationAttributes.h>
#include <Expression.h>
#include <ExpressionList.h>
#include <GlobalAttributes.h>
#include <LightAttributes.h>
#include <LightList.h>
#include <WindowInformation.h>

86 87
#include <string>

hrchilds's avatar
hrchilds committed
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
#define SLEN 5000

//
// Extern data
//
extern ViewerProxy *viewer;

//
// Static data
//
static std::string  macroString;
static bool         macroRecord = false;
static FILE        *logFile;
static bool         logging = false;
static int          logLevel = 0;

//
// Macro functions
//

void
Macro_SetString(const std::string &s)
{
    macroString = s;
}

const std::string &
Macro_GetString()
{
    return macroString;
}

void
Macro_SetRecord(bool val)
{
    macroRecord = val;
}

bool
Macro_GetRecord()
{
    return macroRecord;
}

//
// Log file functions
//

bool
LogFile_Open(const char *filename)
{
hrchilds's avatar
hrchilds committed
139
    logging = true;
hrchilds's avatar
hrchilds committed
140
    logFile = fopen(filename, "wb");
hrchilds's avatar
hrchilds committed
141 142
    if(logFile)
    {
143 144
        fprintf(logFile, "# Visit %s log file\n", VISIT_VERSION);
        fprintf(logFile, "ScriptVersion = \"%s\"\n", VISIT_VERSION);
hrchilds's avatar
hrchilds committed
145 146 147 148 149
        fprintf(logFile, "if ScriptVersion != Version():\n");
        fprintf(logFile, "    print \"This script is for VisIt %%s. "
                "It may not work with version %%s\" %% "
                "(ScriptVersion, Version())\n");
    }
hrchilds's avatar
hrchilds committed
150 151

    return logging;
hrchilds's avatar
hrchilds committed
152 153 154 155 156 157 158 159 160 161 162 163
}

void
LogFile_Close()
{
    if(logFile)
        fclose(logFile);
}

void
LogFile_SetEnabled(bool val)
{
hrchilds's avatar
hrchilds committed
164
    logging = val;
hrchilds's avatar
hrchilds committed
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
}

bool
LogFile_GetEnabled()
{
    return logging;
}

void
LogFile_IncreaseLevel()
{
    ++logLevel;
}

void
LogFile_DecreaseLevel()
{
    --logLevel;
    if(logLevel < 0)
       logLevel = 0;
}

void
LogFile_Write(const char *str)
{
    if(logging && logLevel == 0)
    {
        // Add the string to the macro string
        if(macroRecord)
            macroString += str;

        // Write to the log
hrchilds's avatar
hrchilds committed
197 198
        if(logFile != NULL)
            fprintf(logFile, "%s", str);
hrchilds's avatar
hrchilds committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    }
}

// ****************************************************************************
//
// State Logging functions
//
// Purpose: The purpose of the log functions is to turn ViewerRPC information
//          into valid Python code for the VisIt module that can be logged or
//          recorded into a macro.
//
// Note:    The logging functions take ViewerRPC data, whose important fields,
//          vary depending on the RPC being executed, and use that data to
//          create the Python code returned in the "str" string. The exact
//          usage of the ViewerRPC fields for a given RPC must match the
//          usage in ViewerProxy.C in order for the logging functions to remain
//          accurate.
//
// Programmer: Brad Whitlock
// Creation:   Tue Jan 10 11:50:15 PDT 2006
//
hrchilds's avatar
hrchilds committed
220 221 222 223
// Modifications:
//   Brad Whitlock, Wed Mar 8 17:05:11 PST 2006
//   Added RedoView.
//
224 225 226 227
//   Jeremy Meredith, Wed Feb  3 15:35:08 EST 2010
//   Removed maintain data; moved maintain view from Global settings
//   (Main window) to per-window Window Information (View window).
//
hrchilds's avatar
hrchilds committed
228 229 230 231 232
// ****************************************************************************

#define MSG_NOT_IMPLEMENTED 0
#define MSG_UNSUPPORTED     1

233
static std::string MESSAGE_COMMENT(const char *name, int reason)
hrchilds's avatar
hrchilds committed
234
{
235 236
    std::string s;

hrchilds's avatar
hrchilds committed
237 238
    if(reason == MSG_NOT_IMPLEMENTED)
    {
239
        s = (std::string("# Logging for ") + name) + " is not implemented yet.\n";
hrchilds's avatar
hrchilds committed
240 241 242
    }
    else if(reason == MSG_UNSUPPORTED)
    {
243 244
        s = (std::string("# The ") + name) + " RPC is not supported in the VisIt module "
                 "so it will not be logged.\n";
hrchilds's avatar
hrchilds committed
245
    }
246
    return s;
hrchilds's avatar
hrchilds committed
247 248 249
}


250
static std::string log_AddWindowRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
251
{
252
    return std::string("AddWindow()\n");
hrchilds's avatar
hrchilds committed
253 254
}

255
static std::string log_DeleteWindowRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
256
{
257
    return std::string("DeleteWindow()\n");
hrchilds's avatar
hrchilds committed
258 259
}

260
static std::string log_SetWindowLayoutRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
261
{
262
    char str[SLEN];
hrchilds's avatar
hrchilds committed
263
    SNPRINTF(str, SLEN, "SetWindowLayout(%d)\n", rpc->GetWindowLayout());
264
    return std::string(str);
hrchilds's avatar
hrchilds committed
265 266
}

267
static std::string log_SetActiveWindowRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
268
{
269
    char str[SLEN];
hrchilds's avatar
hrchilds committed
270
    SNPRINTF(str, SLEN, "SetActiveWindow(%d)\n", rpc->GetWindowId());
271
    return std::string(str);
hrchilds's avatar
hrchilds committed
272 273
}

274
static std::string log_ClearWindowRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
275
{
276
    return std::string("ClearWindow()\n");
hrchilds's avatar
hrchilds committed
277 278
}

279
static std::string log_ClearAllWindowsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
280
{
281
    return std::string("ClearAllWindows()\n");
hrchilds's avatar
hrchilds committed
282 283
}

284
static std::string log_OpenDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
285
{
286
    char str[SLEN];
hrchilds's avatar
hrchilds committed
287 288 289
    SNPRINTF(str, SLEN, "OpenDatabase(\"%s\", %d)\n",
             rpc->GetDatabase().c_str(),
             rpc->GetIntArg1());
290
    return std::string(str);
hrchilds's avatar
hrchilds committed
291 292
}

293
static std::string log_CloseDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
294
{
295
    char str[SLEN];
hrchilds's avatar
hrchilds committed
296 297
    SNPRINTF(str, SLEN, "OpenDatabase(\"%s\")\n",
             rpc->GetDatabase().c_str());
298
    return std::string(str);
hrchilds's avatar
hrchilds committed
299 300
}

301
static std::string log_ActivateDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
302
{
303
    char str[SLEN];
hrchilds's avatar
hrchilds committed
304 305
    SNPRINTF(str, SLEN, "ActivateDatabase(\"%s\")\n",
             rpc->GetDatabase().c_str());
306
    return std::string(str);
hrchilds's avatar
hrchilds committed
307 308
}

309
static std::string log_CheckForNewStatesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
310
{
311
    char str[SLEN];
hrchilds's avatar
hrchilds committed
312 313
    SNPRINTF(str, SLEN, "CheckForNewStates(\"%s\")\n",
             rpc->GetDatabase().c_str());
314
    return std::string(str);
hrchilds's avatar
hrchilds committed
315 316
}

317
static std::string log_CreateDatabaseCorrelationRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
318
{
319 320 321 322 323 324 325 326 327 328 329 330 331
    char str[SLEN];
    std::string s("CreateDatabaseCorrelation(\"");
    s += rpc->GetDatabase();
    s += "\",(";
    const stringVector &dbs = rpc->GetProgramOptions();
    for(unsigned int i = 0; i < dbs.size(); ++i)
    {
        s += dbs[i];
        if(i < dbs.size() - 1)
            s += ", ";
    }
    SNPRINTF(str, SLEN, "%s), %d)\n", s.c_str(), rpc->GetIntArg1());
    return std::string(str);     
hrchilds's avatar
hrchilds committed
332 333
}

334
static std::string log_AlterDatabaseCorrelationRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
335
{
336
     char str[SLEN];
hrchilds's avatar
hrchilds committed
337 338 339 340
     std::string s("AlterDatabaseCorrelation(\"");
     s += rpc->GetDatabase();
     s += "\",(";
     const stringVector &dbs = rpc->GetProgramOptions();
341
     for(unsigned int i = 0; i < dbs.size(); ++i)
hrchilds's avatar
hrchilds committed
342 343 344 345 346 347
     {
         s += dbs[i];
         if(i < dbs.size() - 1)
             s += ", ";
     }
     SNPRINTF(str, SLEN, "%s), %d)\n", s.c_str(), rpc->GetIntArg1());
348
     return std::string(str);
hrchilds's avatar
hrchilds committed
349 350
}

351
static std::string log_DeleteDatabaseCorrelationRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
352
{
353
    char str[SLEN];
hrchilds's avatar
hrchilds committed
354 355
    SNPRINTF(str, SLEN, "DeleteDatabaseCorrelation(\"%s\")\n", 
             rpc->GetDatabase().c_str());
356
    return std::string(str);
hrchilds's avatar
hrchilds committed
357 358
}

359
static std::string log_ReOpenDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
360
{
361
    char str[SLEN];
hrchilds's avatar
hrchilds committed
362 363 364
    SNPRINTF(str, SLEN, "OpenDatabase(\"%s\", %d)\n",
             rpc->GetDatabase().c_str(),
             rpc->GetIntArg1());
365
    return std::string(str);
hrchilds's avatar
hrchilds committed
366 367
}

368
static std::string log_ReplaceDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
369
{
370
    char str[SLEN];
hrchilds's avatar
hrchilds committed
371 372 373
    SNPRINTF(str, SLEN, "ReplaceDatabase(\"%s\", %d)\n",
             rpc->GetDatabase().c_str(),
             rpc->GetIntArg1());
374
    return std::string(str);
hrchilds's avatar
hrchilds committed
375 376
}

377
static std::string log_OverlayDatabaseRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
378
{
379
    char str[SLEN];
hrchilds's avatar
hrchilds committed
380 381
    SNPRINTF(str, SLEN, "OverlayDatabase(\"%s\")\n", 
             rpc->GetDatabase().c_str());
382
    return std::string(str);
hrchilds's avatar
hrchilds committed
383 384
}

385
static std::string log_OpenComponentHelper(ViewerRPC *rpc, const char *mName)
hrchilds's avatar
hrchilds committed
386 387
{
    const stringVector &argv = rpc->GetProgramOptions();
388
    char str[SLEN];
hrchilds's avatar
hrchilds committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402

    if(argv.size() == 0)
    {
        SNPRINTF(str, SLEN, "%s(\"%s\")\n",
                 mName, rpc->GetProgramHost().c_str());
    }
    else if(argv.size() == 1)
    {
        SNPRINTF(str, SLEN, "%s(\"%s\", \"%s\")\n",
                mName, rpc->GetProgramHost().c_str(), argv[0].c_str());
    }
    else
    {
        std::string tmp("launchArguments = (");
403
        for(unsigned int i = 0; i < argv.size(); ++i)
hrchilds's avatar
hrchilds committed
404 405 406 407 408 409 410 411 412 413 414
        {
            tmp += "\"";
            tmp += argv[i];
            tmp += "\"";
            if(i < argv.size() - 1)
                tmp += ", ";
        }
        tmp += ")\n";
        SNPRINTF(str, SLEN, "%s%s(\"%s\", launchArguments)\n",
                 tmp.c_str(), mName, rpc->GetProgramHost().c_str());
    }
415
    return std::string(str);
hrchilds's avatar
hrchilds committed
416 417
}

418
static std::string log_OpenComputeEngineRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
419
{
420
    return log_OpenComponentHelper(rpc, "OpenComputeEngine");
hrchilds's avatar
hrchilds committed
421 422
}

423
static std::string log_OpenMDServerRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
424
{
425
    return log_OpenComponentHelper(rpc, "OpenMDServer");
hrchilds's avatar
hrchilds committed
426 427
}

428
static std::string log_CloseComputeEngineRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
429
{
430
    char str[SLEN];
hrchilds's avatar
hrchilds committed
431 432 433
    SNPRINTF(str, SLEN, "CloseComputeEngine(\"%s\", \"%s\")\n",
             rpc->GetProgramHost().c_str(),
             rpc->GetProgramSim().c_str());
434
    return std::string(str);
hrchilds's avatar
hrchilds committed
435 436
}

437
static std::string log_AnimationSetNFramesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
438
{
439
    char str[SLEN];
hrchilds's avatar
hrchilds committed
440
    SNPRINTF(str, SLEN, "AnimationSetNFrames(%d)\n", rpc->GetNFrames());
441
    return std::string(str);
hrchilds's avatar
hrchilds committed
442 443
}

444
static std::string log_AnimationPlayRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
445
{
446
    return MESSAGE_COMMENT("AnimationPlay", MSG_UNSUPPORTED);
hrchilds's avatar
hrchilds committed
447 448
}

449
static std::string log_AnimationReversePlayRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
450
{
451
    return MESSAGE_COMMENT("AnimationReversePlay", MSG_UNSUPPORTED);
hrchilds's avatar
hrchilds committed
452 453
}

454
static std::string log_AnimationStopRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
455
{
456
    return MESSAGE_COMMENT("AnimationStop", MSG_UNSUPPORTED);
hrchilds's avatar
hrchilds committed
457 458
}

459
static std::string log_TimeSliderNextStateRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
460
{
461
    return std::string("TimeSliderNextState()\n");
hrchilds's avatar
hrchilds committed
462 463
}

464
static std::string log_TimeSliderPreviousStateRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
465
{
466
    return std::string("TimeSliderPreviousState()\n");
hrchilds's avatar
hrchilds committed
467 468
}

469
static std::string log_SetTimeSliderStateRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
470
{
471
    char str[SLEN];
hrchilds's avatar
hrchilds committed
472
    SNPRINTF(str, SLEN, "SetTimeSliderState(%d)\n", rpc->GetStateNumber());
473
    return std::string(str);
hrchilds's avatar
hrchilds committed
474 475
}

476
static std::string log_SetActiveTimeSliderRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
477
{
478
    char str[SLEN];
hrchilds's avatar
hrchilds committed
479 480
    SNPRINTF(str, SLEN, "SetActiveTimeSlider(\"%s\")\n",
             rpc->GetDatabase().c_str());
481
    return std::string(str);
hrchilds's avatar
hrchilds committed
482 483
}

484
static std::string log_AddPlotRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
485
{
486
    char str[SLEN];
hrchilds's avatar
hrchilds committed
487
    std::string plotName("?");
488
    PlotPluginManager *pluginManager = viewer->GetPlotPluginManager();
hrchilds's avatar
hrchilds committed
489 490 491 492 493 494
    std::string id(pluginManager->GetEnabledID(rpc->GetPlotType()));
    ScriptingPlotPluginInfo *info = pluginManager->
        GetScriptingPluginInfo(id);
    if(info != 0)
        plotName = info->GetName();
 
495 496 497
    int  inheritSILRestriction = viewer->GetViewerState()->GetGlobalAttributes()->GetNewPlotsInheritSILRestriction();
    int  applyOperator = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1: 0;
    SNPRINTF(str, SLEN, "AddPlot(\"%s\", \"%s\", %d, %d)\n",
hrchilds's avatar
hrchilds committed
498
             plotName.c_str(),
499 500 501
             rpc->GetVariable().c_str(),
             inheritSILRestriction,
             applyOperator);
502
    return std::string(str);
hrchilds's avatar
hrchilds committed
503 504
}

505
static std::string log_SetPlotFrameRangeRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
506
{
507
    char str[SLEN];
hrchilds's avatar
hrchilds committed
508 509
    SNPRINTF(str, SLEN, "SetPlotFrameRange(%d, %d, %d)\n", 
             rpc->GetIntArg1(), rpc->GetIntArg2(), rpc->GetIntArg3());
510
    return std::string(str);
hrchilds's avatar
hrchilds committed
511 512
}

513
static std::string log_DeletePlotKeyframeRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
514
{
515
    char str[SLEN];
hrchilds's avatar
hrchilds committed
516 517
    SNPRINTF(str, SLEN, "DeletePlotKeyframe(%d, %d)\n", 
             rpc->GetIntArg1(), rpc->GetIntArg2());
518
    return std::string(str);
hrchilds's avatar
hrchilds committed
519 520
}

521
static std::string log_MovePlotKeyframeRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
522
{
523
    char str[SLEN];
hrchilds's avatar
hrchilds committed
524 525
    SNPRINTF(str, SLEN, "MovePlotKeyframe(%d, %d, %d)\n", 
             rpc->GetIntArg1(), rpc->GetIntArg2(), rpc->GetIntArg3());
526
    return std::string(str);
hrchilds's avatar
hrchilds committed
527 528
}

529
static std::string log_DeleteActivePlotsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
530
{
531
    return std::string("DeleteActivePlots()\n");
hrchilds's avatar
hrchilds committed
532 533
}

534
static std::string log_HideActivePlotsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
535
{
536
    return std::string("HideActivePlots()\n");
hrchilds's avatar
hrchilds committed
537 538
}

539
static std::string log_DrawPlotsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
540
{
541
    return std::string("DrawPlots()\n");
hrchilds's avatar
hrchilds committed
542 543
}

544
static std::string log_DisableRedrawRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
545
{
546
    return std::string("DisableRedraw()\n");
hrchilds's avatar
hrchilds committed
547 548
}

549
static std::string log_RedrawRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
550
{
551
    return std::string("RedrawWindow()\n");
hrchilds's avatar
hrchilds committed
552 553
}

554
static std::string log_SetActivePlotsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
555
{
556
    char str[SLEN];
hrchilds's avatar
hrchilds committed
557 558 559 560 561 562 563 564 565 566
    int slen = SLEN;
    const intVector &ids = rpc->GetActivePlotIds();
    char *sptr = str;
    int L = SNPRINTF(sptr, slen, "SetActivePlots(");
    sptr += L, slen -= L;
    if(ids.size() > 1)
    {
        L = SNPRINTF(sptr, slen, "(");
        sptr += L, slen -= L;
    }
567
    for(unsigned int i = 0; i < ids.size(); ++i)
hrchilds's avatar
hrchilds committed
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
    {
        L = SNPRINTF(sptr, slen, "%d", ids[i]);
        sptr += L, slen -= L;
        if(i < ids.size() - 1)
        {
            L = SNPRINTF(sptr, slen, ", ");
            sptr += L, slen -= L;
        }
    }
    if(ids.size() > 1)
    {
        L = SNPRINTF(sptr, slen, ")");
        sptr += L, slen -= L;
    }
    SNPRINTF(sptr, slen, ")\n");
583
    return std::string(str);
hrchilds's avatar
hrchilds committed
584 585
}

586
static std::string log_ChangeActivePlotsVarRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
587
{
588
    char str[SLEN];
hrchilds's avatar
hrchilds committed
589 590
    SNPRINTF(str, SLEN, "ChangeActivePlotsVar(\"%s\")\n",
             rpc->GetVariable().c_str());
591
    return std::string(str);
hrchilds's avatar
hrchilds committed
592 593
}

594
static std::string log_AddOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
595
{
596
    char str[SLEN];
hrchilds's avatar
hrchilds committed
597
    std::string operatorName("?");
598
    OperatorPluginManager *pluginManager = viewer->GetOperatorPluginManager();
hrchilds's avatar
hrchilds committed
599 600 601 602 603 604
    std::string id(pluginManager->GetEnabledID(rpc->GetOperatorType()));
    ScriptingOperatorPluginInfo *info = pluginManager->
        GetScriptingPluginInfo(id);
    if(info != 0)
        operatorName = info->GetName();
 
605 606 607 608
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
    SNPRINTF(str, SLEN, "AddOperator(\"%s\", %d)\n",
             operatorName.c_str(),
             applyAll);
609
    return std::string(str);
hrchilds's avatar
hrchilds committed
610 611
}

612
static std::string log_PromoteOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
613
{
614
    char str[SLEN];
hrchilds's avatar
hrchilds committed
615
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
hrchilds's avatar
hrchilds committed
616 617
    SNPRINTF(str, SLEN, "PromoteOperator(%d, %d)\n", rpc->GetOperatorType(),
             applyAll);
618
    return std::string(str);
hrchilds's avatar
hrchilds committed
619 620
}

621
static std::string log_DemoteOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
622
{
623
    char str[SLEN];
hrchilds's avatar
hrchilds committed
624
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
hrchilds's avatar
hrchilds committed
625 626
    SNPRINTF(str, SLEN, "DemoteOperator(%d, %d)\n", rpc->GetOperatorType(),
             applyAll);
627
    return std::string(str);
hrchilds's avatar
hrchilds committed
628 629
}

630
static std::string log_RemoveOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
631
{
632
    char str[SLEN];
hrchilds's avatar
hrchilds committed
633
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
hrchilds's avatar
hrchilds committed
634 635
    SNPRINTF(str, SLEN, "RemoveOperator(%d, %d)\n", rpc->GetOperatorType(),
             applyAll);
636
    return std::string(str);
hrchilds's avatar
hrchilds committed
637 638
}

639
static std::string log_RemoveLastOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
640
{
641
    char str[SLEN];
hrchilds's avatar
hrchilds committed
642
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
hrchilds's avatar
hrchilds committed
643
    SNPRINTF(str, SLEN, "RemoveLastOperator(%d)\n", applyAll);
644
    return std::string(str);
hrchilds's avatar
hrchilds committed
645 646
}

647
static std::string log_RemoveAllOperatorsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
648
{
649
    char str[SLEN];
hrchilds's avatar
hrchilds committed
650
    int applyAll = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator() ? 1 : 0;
hrchilds's avatar
hrchilds committed
651
    SNPRINTF(str, SLEN, "RemoveAllOperators(%d)\n", applyAll);
652
    return std::string(str);
hrchilds's avatar
hrchilds committed
653 654
}

655
static std::string log_SaveWindowRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
656 657 658
{
    std::string s(PySaveWindowAttributes_GetLogString());
    s += "SetSaveWindowAttributes(SaveWindowAtts)\n";
659
    return s;
hrchilds's avatar
hrchilds committed
660 661 662 663 664
}

static void log_SetPlotOptionsHelper(ViewerRPC *rpc, std::string &atts, 
    std::string &plotName)
{
665
    PlotPluginManager *pluginManager = viewer->GetPlotPluginManager();
hrchilds's avatar
hrchilds committed
666 667 668 669 670 671 672 673 674 675 676 677 678
    std::string id(pluginManager->GetEnabledID(rpc->GetPlotType()));
    ScriptingPlotPluginInfo *info = pluginManager->
        GetScriptingPluginInfo(id);
    if(info != 0)
    {
        char *s = info->GetLogString();
        atts = s;
        delete [] s;
        plotName = info->GetName();
        plotName += "Atts";
    }
}

679
static std::string log_SetDefaultPlotOptionsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
680 681 682 683 684 685
{
    std::string atts(""), plotName("");
    log_SetPlotOptionsHelper(rpc, atts, plotName);
    atts += "SetDefaultPlotOptions(";
    atts += plotName;
    atts += ")\n";
686
    return atts;
hrchilds's avatar
hrchilds committed
687 688
}

689
static std::string log_SetPlotOptionsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
690 691 692 693 694 695
{
    std::string atts(""), plotName("");
    log_SetPlotOptionsHelper(rpc, atts, plotName);
    atts += "SetPlotOptions(";
    atts += plotName;
    atts += ")\n";
696
    return atts;
hrchilds's avatar
hrchilds committed
697 698 699 700 701
}

static void log_SetOperatorOptionsHelper(ViewerRPC *rpc, std::string &atts, 
    std::string &operatorName)
{
702
    OperatorPluginManager *pluginManager = viewer->GetOperatorPluginManager();
hrchilds's avatar
hrchilds committed
703 704 705 706 707 708 709 710 711 712 713 714 715
    std::string id(pluginManager->GetEnabledID(rpc->GetOperatorType()));
    ScriptingOperatorPluginInfo *info = pluginManager->
        GetScriptingPluginInfo(id);
    if(info != 0)
    {
        char *s = info->GetLogString();
        atts = s;
        delete [] s;
        operatorName = info->GetName();
        operatorName += "Atts";
    }
}

716
static std::string log_SetDefaultOperatorOptionsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
717 718 719 720 721 722
{
    std::string atts(""), operatorName("");
    log_SetOperatorOptionsHelper(rpc, atts, operatorName);
    atts += "SetDefaultOperatorOptions(";
    atts += operatorName;
    atts += ")\n";
723
    return atts;
hrchilds's avatar
hrchilds committed
724 725
}

726
static std::string log_SetOperatorOptionsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
727 728
{
    std::string atts(""), operatorName("");
729
    bool  applyOperator = viewer->GetViewerState()->GetGlobalAttributes()->GetApplyOperator();
hrchilds's avatar
hrchilds committed
730 731 732
    log_SetOperatorOptionsHelper(rpc, atts, operatorName);
    atts += "SetOperatorOptions(";
    atts += operatorName;
733 734
    atts += ", ";
    atts += (applyOperator ? "1" : "0");
hrchilds's avatar
hrchilds committed
735
    atts += ")\n";
736
    return atts;
hrchilds's avatar
hrchilds committed
737 738
}

739
static std::string log_AddInitializedOperatorRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
740
{
741 742 743 744
    std::string s;
    s = log_AddOperatorRPC(rpc);
    s += log_SetOperatorOptionsRPC(rpc);
    return s;
hrchilds's avatar
hrchilds committed
745 746
}

747
static std::string log_WriteConfigFileRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
748
{
749
    return std::string("WriteConfigFile()\n");
hrchilds's avatar
hrchilds committed
750 751
}

752
static std::string log_IconifyAllWindowsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
753
{
754
    return std::string("IconifyAllWindows()\n");
hrchilds's avatar
hrchilds committed
755 756
}

757
static std::string log_DeIconifyAllWindowsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
758
{
759
    return std::string("DeIconifyAllWindows()\n");
hrchilds's avatar
hrchilds committed
760 761
}

762
static std::string log_ShowAllWindowsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
763
{
764
    return std::string("ShowAllWindows()\n");
hrchilds's avatar
hrchilds committed
765 766
}

767
static std::string log_HideAllWindowsRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
768
{
769
    return std::string("HideAllWindows()\n");
hrchilds's avatar
hrchilds committed
770 771
}

772
static std::string log_SetAnnotationAttributesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
773 774
{
    std::string s(PyAnnotationAttributes_GetLogString());
775 776
    s += std::string("SetAnnotationAttributes(AnnotationAtts)\n");
    return s;
hrchilds's avatar
hrchilds committed
777 778
}

779
static std::string log_SetDefaultAnnotationAttributesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
780 781
{
    std::string s(PyAnnotationAttributes_GetLogString());
782 783
    s += std::string("SetDefaultAnnotationAttributes(AnnotationAtts)\n");
    return s;
hrchilds's avatar
hrchilds committed
784 785
}

786
static std::string log_ResetAnnotationAttributesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
787
{
788
    return MESSAGE_COMMENT("ResetAnnotationAttributes", MSG_UNSUPPORTED);
hrchilds's avatar
hrchilds committed
789 790
}

791
static std::string log_SetKeyframeAttributesRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
792 793
{
    std::string s(PyKeyframeAttributes_GetLogString());
794 795
    s += std::string("SetKeyframeAttributes(KeyframeAtts)\n");
    return s;
hrchilds's avatar
hrchilds committed
796 797
}

hrchilds's avatar
hrchilds committed
798 799 800 801 802 803 804 805 806 807 808 809 810 811
// ****************************************************************************
// Method: log_SetPlotSILRestrictionRPC
//
// Purpose: 
//   Logs changes to the SIL restriction.
//
// Programmer: Brad Whitlock
// Creation:   Wed Jan 11 09:55:18 PDT 2006
//
// Modifications:
//   Brad Whitlock, Wed Jan 11 09:55:42 PDT 2006
//   I removed a call to the SIL traverser's UsesAllData method because it
//   was causing a crash sometimes.
//
812 813 814 815 816
//   Hank Childs, Mon Dec 14 13:12:58 PST 2009
//   Reverse ordering for two conditions in an if test.  One is cheap, the
//   other expensive.  By reversing them, the overall time is much faster
//   (because of short circuiting).
//
hrchilds's avatar
hrchilds committed
817 818
// ****************************************************************************

819
static std::string log_SetPlotSILRestrictionRPC(ViewerRPC *rpc)
hrchilds's avatar
hrchilds committed
820
{
821
    int t1 = visitTimer->StartTimer();
hrchilds's avatar
hrchilds committed
822 823 824 825 826 827 828 829 830 831
    std::string s("silr = SILRestriction()\n");
    int nsets[2] = {0,0};
    avtSILRestriction_p restriction = viewer->GetPlotSILRestriction();
    avtSILRestrictionTraverser trav(restriction);
    int setid;
    for(setid = 0; setid < restriction->GetNumSets(); ++setid)
    {
        nsets[trav.UsesData(setid)?1:0]++;
    }

hrchilds's avatar
hrchilds committed
832
    if(nsets[1] == restriction->GetNumSets())
hrchilds's avatar
hrchilds committed
833 834 835 836 837 838 839 840 841 842
    {
        s += "silr.TurnOnAll()\n";
    }
    else if(nsets[0] < nsets[1])
    {
        // More sets were on so we'll turn them all on and then turn off sets
        // that were off.
        intVector sets;
        for(setid = 0; setid < restriction->GetNumSets(); ++setid)
        {
843 844
            if(!trav.UsesData(setid) &&
               restriction->GetSILSet(setid)->GetMapsOut().size() == 0)
hrchilds's avatar
hrchilds committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860