QvisMaterialWindow.C 27.4 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 40 41 42 43
#include "QvisMaterialWindow.h"

#include <MaterialAttributes.h>
#include <ViewerProxy.h>

whitlocb's avatar
whitlocb committed
44 45 46 47 48
#include <QComboBox>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QLineEdit>
hrchilds's avatar
hrchilds committed
49
#include <QNarrowLineEdit.h>
whitlocb's avatar
whitlocb committed
50 51 52 53
#include <QSpinBox>
#include <QWidget>
#include <QButtonGroup>
#include <QRadioButton>
hrchilds's avatar
hrchilds committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include <QvisColorTableButton.h>
#include <QvisOpacitySlider.h>
#include <QvisColorButton.h>
#include <QvisLineStyleWidget.h>
#include <QvisLineWidthWidget.h>
#include <stdio.h>
#include <string>

using std::string;

// ****************************************************************************
// Method: QvisMaterialWindow::QvisMaterialWindow
//
// Purpose: 
//   Constructor
//
// Programmer: Jeremy Meredith
// Creation:   October 24, 2002
//
// Modifications:
74 75 76
//   Brad Whitlock, Wed Apr  9 11:45:36 PDT 2008
//   QString for caption, shortName.
//
hrchilds's avatar
hrchilds committed
77 78 79
// ****************************************************************************

QvisMaterialWindow::QvisMaterialWindow(MaterialAttributes *subj,
80 81
                                       const QString &caption,
                                       const QString &shortName,
hrchilds's avatar
hrchilds committed
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 116 117 118
                                       QvisNotepadArea *notepad) :
    QvisPostableWindowObserver(subj, caption, shortName, notepad,
                               QvisPostableWindowObserver::AllExtraButtons,
                               false)
{
    atts = subj;
}


// ****************************************************************************
// Method: QvisMaterialWindow::~QvisMaterialWindow
//
// Purpose: 
//   Destructor
//
// Programmer: xml2window
// Creation:   Thu Oct 24 10:03:40 PDT 2002
//
// Modifications:
//   
// ****************************************************************************

QvisMaterialWindow::~QvisMaterialWindow()
{
}


// ****************************************************************************
// Method: QvisMaterialWindow::CreateWindowContents
//
// Purpose: 
//   Creates the widgets for the window.
//
// Programmer: Jeremy Meredith
// Creation:   October 25, 2002
//
// Modifications:
hrchilds's avatar
hrchilds committed
119 120
//    Jeremy Meredith, Wed Jul 30 10:46:51 PDT 2003
//    Added a toggle for forcing full connectivity.
hrchilds's avatar
hrchilds committed
121
//   
hrchilds's avatar
hrchilds committed
122 123 124
//    Jeremy Meredith, Mon Sep 15 17:16:55 PDT 2003
//    Added a toggle for the new material algorithm.
//
hrchilds's avatar
hrchilds committed
125 126 127
//    Hank Childs, Tue Aug 16 15:36:43 PDT 2005
//    Add a toggle for "simplify heavily mixed zones".
//
hrchilds's avatar
hrchilds committed
128 129 130 131
//    Jeremy Meredith, Thu Aug 18 16:14:59 PDT 2005
//    Changed algorithm selection to a multiple-choice.
//    Added VF for isovolume method.
//
132 133 134
//    Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//    Support for internationalization.
//
135
//    Cyrus Harrison, Tue Jun 10 10:04:26 PDT 2008
136 137
//    Initial Qt4 Port.
//
138 139 140 141 142 143
//    John C. Anderson, Fri Oct 17 16:03:10 2008
//    Added "Discrete" reconstruction option.
//
//    John C. Anderson, Thu Jan 15 10:20:20 2009
//    Added annealing time for Discrete MIR.
//
144 145
//    Jeremy Meredith, Fri Feb 13 12:11:07 EST 2009
//    Added material iteration capability.
whitlocb's avatar
whitlocb committed
146
//
147 148 149 150
//    Jeremy Meredith, Tue Aug  4 10:47:50 EDT 2009
//    Added Youngs algorithm choice.
//    Added hints for algorithm specificity of some options.
//
151 152 153
//    Jeremy Meredith, Thu Mar 25 12:27:49 EDT 2010
//    Renamed some algorithms, added some window hints.
//
154 155 156 157
//    Jeremy Meredith, Wed Mar 30 13:58:59 EDT 2011
//    Re-enable clean-zones-only.  It seems to work fine, so I suspect it
//    was disabled by accident, not intentionally.
//
hrchilds's avatar
hrchilds committed
158 159 160 161 162
// ****************************************************************************

void
QvisMaterialWindow::CreateWindowContents()
{
whitlocb's avatar
whitlocb committed
163 164 165 166 167 168 169 170 171
    QGridLayout *mainLayout = new QGridLayout();
    topLayout->addLayout(mainLayout);

    QHBoxLayout *algLayout = new QHBoxLayout();
    algorithmLabel = new QLabel(tr("Algorithm:"), central);
    algLayout->setSpacing(10);
    algLayout->addWidget(algorithmLabel);

    algorithm = new QComboBox(central);
172 173
    algorithm->addItem(tr("Equi-T (obsolete)"));
    algorithm->addItem(tr("Equi-Z (default, supports iteration)"));
whitlocb's avatar
whitlocb committed
174
    algorithm->addItem(tr("Isovolume (special-purpose)"));
175
    algorithm->addItem(tr("PLIC (accurate/discontinuous)"));
176
    algorithm->addItem(tr("Discrete (accurate/10X memory footprint/rect. only)"));
whitlocb's avatar
whitlocb committed
177
    algLayout->addWidget(algorithm);
hrchilds's avatar
hrchilds committed
178 179
    connect(algorithm, SIGNAL(activated(int)),
            this, SLOT(algorithmChanged(int)));
whitlocb's avatar
whitlocb committed
180
    mainLayout->addLayout(algLayout, 0,0, 1,2);
hrchilds's avatar
hrchilds committed
181

182
    smoothing = new QCheckBox(tr("Enable interface smoothing (Equi-* only)"), central);
hrchilds's avatar
hrchilds committed
183 184
    connect(smoothing, SIGNAL(toggled(bool)),
            this, SLOT(smoothingChanged(bool)));
hrchilds's avatar
hrchilds committed
185
    mainLayout->addWidget(smoothing, 1,0);
hrchilds's avatar
hrchilds committed
186

187
    forceFullConnectivity = new QCheckBox(tr("Force full connectivity (Equi-T only)"), central);
hrchilds's avatar
hrchilds committed
188 189
    connect(forceFullConnectivity, SIGNAL(toggled(bool)),
            this, SLOT(forceFullConnectivityChanged(bool)));
hrchilds's avatar
hrchilds committed
190
    mainLayout->addWidget(forceFullConnectivity, 2,0);
hrchilds's avatar
hrchilds committed
191

whitlocb's avatar
whitlocb committed
192
    forceMIR = new QCheckBox(tr("Force interface reconstruction"), central);
hrchilds's avatar
hrchilds committed
193 194
    connect(forceMIR, SIGNAL(toggled(bool)),
            this, SLOT(forceMIRChanged(bool)));
hrchilds's avatar
hrchilds committed
195
    mainLayout->addWidget(forceMIR, 3,0);
hrchilds's avatar
hrchilds committed
196

whitlocb's avatar
whitlocb committed
197
    cleanZonesOnly = new QCheckBox(tr("Clean zones only"), central);
hrchilds's avatar
hrchilds committed
198 199
    connect(cleanZonesOnly, SIGNAL(toggled(bool)),
            this, SLOT(cleanZonesOnlyChanged(bool)));
hrchilds's avatar
hrchilds committed
200
    mainLayout->addWidget(cleanZonesOnly, 4,0);
hrchilds's avatar
hrchilds committed
201

202
    simplifyHeavilyMixedZones = new QCheckBox(tr("Simplify heavily mixed zones"), 
whitlocb's avatar
whitlocb committed
203
                                              central);
hrchilds's avatar
hrchilds committed
204 205 206 207
    connect(simplifyHeavilyMixedZones, SIGNAL(toggled(bool)),
            this, SLOT(simplifyHeavilyMixedZonesChanged(bool)));
    mainLayout->addWidget(simplifyHeavilyMixedZones, 5,0);

208
    maxMatsPerZoneLabel = new QLabel(tr("Maximum materials per zone"),
whitlocb's avatar
whitlocb committed
209
                                     central);
hrchilds's avatar
hrchilds committed
210 211
    mainLayout->addWidget(maxMatsPerZoneLabel, 6, 0);

whitlocb's avatar
whitlocb committed
212
    maxMatsPerZone = new QNarrowLineEdit(central);
hrchilds's avatar
hrchilds committed
213 214 215
    connect(maxMatsPerZone, SIGNAL(returnPressed()), this,
            SLOT(maxMatsPerZoneProcessText()));
    mainLayout->addWidget(maxMatsPerZone, 6, 1);
hrchilds's avatar
hrchilds committed
216

whitlocb's avatar
whitlocb committed
217 218
    isoVolumeFractionLabel = new QLabel(tr("Volume Fraction for Isovolume"), 
                                        central);
hrchilds's avatar
hrchilds committed
219
    mainLayout->addWidget(isoVolumeFractionLabel,7,0);
whitlocb's avatar
whitlocb committed
220
    isoVolumeFraction = new QNarrowLineEdit(central);
hrchilds's avatar
hrchilds committed
221 222 223
    connect(isoVolumeFraction, SIGNAL(returnPressed()),
            this, SLOT(isoVolumeFractionProcessText()));
    mainLayout->addWidget(isoVolumeFraction, 7,1);
224 225

    // Iteration options
226
    enableIteration = new QCheckBox(tr("Enable iteration (Equi-Z, Isovolume only)"), 
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
                                              central);
    connect(enableIteration, SIGNAL(toggled(bool)),
            this, SLOT(enableIterationChanged(bool)));
    mainLayout->addWidget(enableIteration, 8,0);

    numIterationsLabel = new QLabel(tr("Number of iterations"), 
                                        central);
    mainLayout->addWidget(numIterationsLabel,9,0);
    numIterations = new QNarrowLineEdit(central);
    connect(numIterations, SIGNAL(returnPressed()),
            this, SLOT(numIterationsProcessText()));
    mainLayout->addWidget(numIterations, 9,1);

    iterationDampingLabel = new QLabel(tr("Convergence rate (>0)"), 
                                        central);
    mainLayout->addWidget(iterationDampingLabel,10,0);
    iterationDamping = new QNarrowLineEdit(central);
    connect(numIterations, SIGNAL(returnPressed()),
            this, SLOT(iterationDampingProcessText()));
    mainLayout->addWidget(iterationDamping, 10,1);
247

248
    annealingTimeLabel = new QLabel(tr("Annealing time (seconds) (Discrete only)"), central);
249 250 251 252 253 254
    mainLayout->addWidget(annealingTimeLabel,11,0);
    annealingTime = new QNarrowLineEdit(central);
    connect(annealingTime, SIGNAL(returnPressed()),
            this, SLOT(annealingTimeProcessText()));
    mainLayout->addWidget(annealingTime, 11,1);

hrchilds's avatar
hrchilds committed
255 256 257 258 259 260 261 262 263 264 265 266 267
}


// ****************************************************************************
// Method: QvisMaterialWindow::UpdateWindow
//
// Purpose: 
//   Updates the widgets in the window when the subject changes.
//
// Programmer: Jeremy Meredith
// Creation:   October 24, 2002
//
// Modifications:
hrchilds's avatar
hrchilds committed
268 269
//    Jeremy Meredith, Wed Jul 30 10:46:51 PDT 2003
//    Added a toggle for forcing full connectivity.
hrchilds's avatar
hrchilds committed
270
//   
hrchilds's avatar
hrchilds committed
271 272 273
//    Jeremy Meredith, Mon Sep 15 17:20:57 PDT 2003
//    Added a toggle for the new MIR algorithm.
//
hrchilds's avatar
hrchilds committed
274 275 276
//    Hank Childs, Tue Aug 16 15:36:43 PDT 2005
//    Add a toggle for "simplify heavily mixed zones".
//
hrchilds's avatar
hrchilds committed
277 278 279 280
//    Jeremy Meredith, Thu Aug 18 16:14:59 PDT 2005
//    Changed algorithm selection to a multiple-choice.
//    Added VF for isovolume method.
//
whitlocb's avatar
whitlocb committed
281 282 283
//    Brad Whitlock, Fri Dec 14 17:38:49 PST 2007
//    Made it use ids.
//
284 285 286
//    John C. Anderson, Thu Jan 15 10:20:20 2009
//    Added annealing time for Discrete MIR.
//
287 288 289
//    Jeremy Meredith, Fri Feb 13 12:11:07 EST 2009
//    Added material iteration capability.
//
290 291 292
//    Jeremy Meredith, Tue Aug  4 13:49:49 EDT 2009
//    Added better sensitivity setting based on algorithm.
//
293 294 295
//    Jeremy Meredith, Thu Mar 25 12:27:49 EDT 2010
//    Renamed some algorithms.
//
hrchilds's avatar
hrchilds committed
296 297 298 299 300 301 302 303 304 305
// ****************************************************************************

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

    smoothing->blockSignals(true);
    forceMIR->blockSignals(true);
    cleanZonesOnly->blockSignals(true);
hrchilds's avatar
hrchilds committed
306
    forceFullConnectivity->blockSignals(true);
hrchilds's avatar
hrchilds committed
307
    algorithm->blockSignals(true);
hrchilds's avatar
hrchilds committed
308 309
    simplifyHeavilyMixedZones->blockSignals(true);
    maxMatsPerZone->blockSignals(true);
hrchilds's avatar
hrchilds committed
310
    isoVolumeFraction->blockSignals(true);
311 312 313
    enableIteration->blockSignals(true);
    numIterations->blockSignals(true);
    iterationDamping->blockSignals(true);
314
    annealingTime->blockSignals(true);
hrchilds's avatar
hrchilds committed
315 316 317 318 319 320 321 322 323 324 325 326 327

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

        switch(i)
        {
whitlocb's avatar
whitlocb committed
328
          case MaterialAttributes::ID_smoothing:
hrchilds's avatar
hrchilds committed
329 330
            smoothing->setChecked(atts->GetSmoothing());
            break;
whitlocb's avatar
whitlocb committed
331
          case MaterialAttributes::ID_forceMIR:
hrchilds's avatar
hrchilds committed
332 333
            forceMIR->setChecked(atts->GetForceMIR());
            break;
whitlocb's avatar
whitlocb committed
334
          case MaterialAttributes::ID_cleanZonesOnly:
hrchilds's avatar
hrchilds committed
335 336
            cleanZonesOnly->setChecked(atts->GetCleanZonesOnly());
            break;
whitlocb's avatar
whitlocb committed
337
          case MaterialAttributes::ID_needValidConnectivity:
hrchilds's avatar
hrchilds committed
338 339
            forceFullConnectivity->setChecked(atts->GetNeedValidConnectivity());
            break;
whitlocb's avatar
whitlocb committed
340
          case MaterialAttributes::ID_algorithm:
hrchilds's avatar
hrchilds committed
341 342 343 344 345 346 347 348 349 350
            if (atts->GetAlgorithm() == MaterialAttributes::Isovolume)
            {
                isoVolumeFraction->setEnabled(true);
                isoVolumeFractionLabel->setEnabled(true);
            }
            else
            {
                isoVolumeFraction->setEnabled(false);
                isoVolumeFractionLabel->setEnabled(false);
            }
351 352 353
            annealingTime->setEnabled(atts->GetAlgorithm() == MaterialAttributes::Discrete);
            annealingTimeLabel->setEnabled(atts->GetAlgorithm() == MaterialAttributes::Discrete);
                
354
            smoothing->setEnabled(
355 356
                   atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
                   atts->GetAlgorithm()==MaterialAttributes::EquiT);
357
            forceFullConnectivity->setEnabled(
358
                   atts->GetAlgorithm()==MaterialAttributes::EquiT);
359
            enableIteration->setEnabled(
360
                   atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
361 362
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume);
            iterationDamping->setEnabled(
363
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
364 365 366
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            iterationDampingLabel->setEnabled(
367
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
368 369 370
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            numIterations->setEnabled(
371
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
372 373 374
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            numIterationsLabel->setEnabled(
375
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
376 377
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
whitlocb's avatar
whitlocb committed
378
            algorithm->setCurrentIndex(atts->GetAlgorithm());
hrchilds's avatar
hrchilds committed
379
            break;
whitlocb's avatar
whitlocb committed
380
          case MaterialAttributes::ID_simplifyHeavilyMixedZones:
hrchilds's avatar
hrchilds committed
381 382 383 384 385
            simplifyHeavilyMixedZones->setChecked(
                                         atts->GetSimplifyHeavilyMixedZones());
            maxMatsPerZone->setEnabled(atts->GetSimplifyHeavilyMixedZones());
            maxMatsPerZoneLabel->setEnabled(atts->GetSimplifyHeavilyMixedZones());
            break;
whitlocb's avatar
whitlocb committed
386
          case MaterialAttributes::ID_maxMaterialsPerZone:
hrchilds's avatar
hrchilds committed
387 388 389
            temp.sprintf("%d", atts->GetMaxMaterialsPerZone());
            maxMatsPerZone->setText(temp);
            break;
whitlocb's avatar
whitlocb committed
390
          case MaterialAttributes::ID_isoVolumeFraction:
hrchilds's avatar
hrchilds committed
391 392 393
            temp.setNum(atts->GetIsoVolumeFraction());
            isoVolumeFraction->setText(temp);
            break;
394 395 396
          case MaterialAttributes::ID_iterationEnabled:
            enableIteration->setChecked(atts->GetIterationEnabled());
            iterationDamping->setEnabled(
397
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
398 399 400
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            iterationDampingLabel->setEnabled(
401
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
402 403 404
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            numIterations->setEnabled(
405
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
406 407 408
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            numIterationsLabel->setEnabled(
409
                  (atts->GetAlgorithm()==MaterialAttributes::EquiZ ||
410 411 412 413 414 415 416 417 418 419 420
                   atts->GetAlgorithm()==MaterialAttributes::Isovolume) &&
                  atts->GetIterationEnabled());
            break;
          case MaterialAttributes::ID_numIterations:
            temp.setNum(atts->GetNumIterations());
            numIterations->setText(temp);
            break;
          case MaterialAttributes::ID_iterationDamping:
            temp.setNum(atts->GetIterationDamping());
            iterationDamping->setText(temp);
            break;
421 422 423 424
          case MaterialAttributes::ID_annealingTime:
            temp.setNum(atts->GetAnnealingTime());
            annealingTime->setText(temp);
            break;
hrchilds's avatar
hrchilds committed
425 426 427 428 429 430
        }
    }

    smoothing->blockSignals(false);
    forceMIR->blockSignals(false);
    cleanZonesOnly->blockSignals(false);
hrchilds's avatar
hrchilds committed
431
    forceFullConnectivity->blockSignals(false);
hrchilds's avatar
hrchilds committed
432
    algorithm->blockSignals(false);
hrchilds's avatar
hrchilds committed
433 434
    simplifyHeavilyMixedZones->blockSignals(false);
    maxMatsPerZone->blockSignals(false);
hrchilds's avatar
hrchilds committed
435
    isoVolumeFraction->blockSignals(false);
436 437 438
    enableIteration->blockSignals(false);
    numIterations->blockSignals(false);
    iterationDamping->blockSignals(false);
439
    annealingTime->blockSignals(false);
hrchilds's avatar
hrchilds committed
440 441 442 443 444 445 446 447 448 449 450 451 452
}


// ****************************************************************************
// Method: QvisMaterialWindow::GetCurrentValues
//
// Purpose: 
//   Gets values from certain widgets and stores them in the subject.
//
// Programmer: xml2window
// Creation:   Thu Oct 24 10:03:40 PDT 2002
//
// Modifications:
hrchilds's avatar
hrchilds committed
453 454
//    Jeremy Meredith, Wed Jul 30 10:46:51 PDT 2003
//    Added a toggle for forcing full connectivity.
hrchilds's avatar
hrchilds committed
455
//   
hrchilds's avatar
hrchilds committed
456 457 458
//    Jeremy Meredith, Mon Sep 15 17:17:12 PDT 2003
//    Added the toggle for the new MIR algorithm.
//
hrchilds's avatar
hrchilds committed
459 460 461
//    Hank Childs, Tue Aug 16 15:36:43 PDT 2005
//    Add a toggle for "simplify heavily mixed zones".
//
hrchilds's avatar
hrchilds committed
462 463 464 465
//    Jeremy Meredith, Thu Aug 18 16:14:59 PDT 2005
//    Changed algorithm selection to a multiple-choice.
//    Added VF for isovolume method.
//
whitlocb's avatar
whitlocb committed
466 467 468
//    Brad Whitlock, Fri Dec 14 17:40:16 PST 2007
//    Made it use ids.
//
469 470 471
//    Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//    Support for internationalization.
//
472 473 474
//    John C. Anderson, Thu Jan 15 10:20:20 2009
//    Added annealing time for Discrete MIR.
//
475 476 477
//    Jeremy Meredith, Fri Feb 13 12:11:07 EST 2009
//    Added material iteration capability.
//
hrchilds's avatar
hrchilds committed
478 479 480 481 482 483
// ****************************************************************************

void
QvisMaterialWindow::GetCurrentValues(int which_widget)
{
    bool doAll = (which_widget == -1);
hrchilds's avatar
hrchilds committed
484
    QString msg, temp;
hrchilds's avatar
hrchilds committed
485 486

    // Do smoothing
whitlocb's avatar
whitlocb committed
487
    if(which_widget == MaterialAttributes::ID_smoothing || doAll)
hrchilds's avatar
hrchilds committed
488 489 490 491 492
    {
        // Nothing for smoothing
    }

    // Do forceMIR
whitlocb's avatar
whitlocb committed
493
    if(which_widget == MaterialAttributes::ID_forceMIR || doAll)
hrchilds's avatar
hrchilds committed
494 495 496 497 498
    {
        // Nothing for forceMIR
    }

    // Do cleanZonesOnly
whitlocb's avatar
whitlocb committed
499
    if(which_widget == MaterialAttributes::ID_cleanZonesOnly || doAll)
hrchilds's avatar
hrchilds committed
500 501 502 503
    {
        // Nothing for cleanZonesOnly
    }

whitlocb's avatar
whitlocb committed
504 505
    // Do needValidConnectivity
    if(which_widget == MaterialAttributes::ID_needValidConnectivity || doAll)
hrchilds's avatar
hrchilds committed
506
    {
whitlocb's avatar
whitlocb committed
507
        // Nothing for needValidConnectivity
hrchilds's avatar
hrchilds committed
508 509
    }

hrchilds's avatar
hrchilds committed
510
    // Do algorithm
whitlocb's avatar
whitlocb committed
511
    if(which_widget == MaterialAttributes::ID_algorithm || doAll)
hrchilds's avatar
hrchilds committed
512
    {
hrchilds's avatar
hrchilds committed
513
        // Nothing for algorithm
hrchilds's avatar
hrchilds committed
514 515
    }

hrchilds's avatar
hrchilds committed
516
    // Do simplifyHeavilyMixedZones
whitlocb's avatar
whitlocb committed
517
    if(which_widget == MaterialAttributes::ID_simplifyHeavilyMixedZones || doAll)
hrchilds's avatar
hrchilds committed
518
    {
whitlocb's avatar
whitlocb committed
519
        // Nothing for simplifyHeavilyMixedZones
hrchilds's avatar
hrchilds committed
520 521 522
    }

    // Do maxMatsPerZone
whitlocb's avatar
whitlocb committed
523
    if(which_widget == MaterialAttributes::ID_maxMaterialsPerZone || doAll)
hrchilds's avatar
hrchilds committed
524
    {
whitlocb's avatar
whitlocb committed
525
        temp = maxMatsPerZone->displayText().simplified();
hrchilds's avatar
hrchilds committed
526 527 528 529 530 531 532 533 534 535 536 537
        bool okay = !temp.isEmpty();
        if(okay)
        {
            int val = temp.toInt(&okay);
            if (val < 1)
                okay = false;
            else
                atts->SetMaxMaterialsPerZone(val);
        }

        if(!okay)
        {
538
            msg = tr("Max mats per zone must be at least 1."
539 540
                     "Resetting to the last good value of %1.").
                  arg(atts->GetMaxMaterialsPerZone());
hrchilds's avatar
hrchilds committed
541 542 543 544 545
            Message(msg);
            atts->SetMaxMaterialsPerZone(atts->GetMaxMaterialsPerZone());
        }
    }

hrchilds's avatar
hrchilds committed
546
    // Do isoVolumeFraction
whitlocb's avatar
whitlocb committed
547
    if(which_widget == MaterialAttributes::ID_isoVolumeFraction || doAll)
hrchilds's avatar
hrchilds committed
548
    {
whitlocb's avatar
whitlocb committed
549
        temp = isoVolumeFraction->displayText().simplified();
hrchilds's avatar
hrchilds committed
550 551 552 553 554 555 556 557 558 559 560 561
        bool okay = !temp.isEmpty();
        if (okay)
        {
            float val = temp.toFloat(&okay);
            if (val < 0 || val > 1)
                okay = false;
            else
                atts->SetIsoVolumeFraction(val);
        }

        if (!okay)
        {
562
            msg = tr("The value of isoVolumeFraction was invalid. "
563 564
                     "Resetting to the last good value of %1.").
                  arg(atts->GetIsoVolumeFraction());
hrchilds's avatar
hrchilds committed
565 566 567 568
            Message(msg);
            atts->SetIsoVolumeFraction(atts->GetIsoVolumeFraction());
        }
    }
569 570 571 572 573 574 575 576 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

    // Do numIterations
    if(which_widget == MaterialAttributes::ID_numIterations || doAll)
    {
        temp = numIterations->displayText().simplified();
        bool okay = !temp.isEmpty();
        if (okay)
        {
            int val = temp.toInt(&okay);
            if (val < 0 || val > 1000)
                okay = false;
            else
                atts->SetNumIterations(val);
        }

        if (!okay)
        {
            msg = tr("The value of numIterations was invalid. "
                     "Resetting to the last good value of %1.").
                  arg(atts->GetNumIterations());
            Message(msg);
            atts->SetNumIterations(atts->GetNumIterations());
        }
    }

    // Do iterationDamping
    if(which_widget == MaterialAttributes::ID_iterationDamping || doAll)
    {
        temp = iterationDamping->displayText().simplified();
        bool okay = !temp.isEmpty();
        if (okay)
        {
            float val = temp.toFloat(&okay);
            if (val <= 0 || val > 10)
                okay = false;
            else
                atts->SetIterationDamping(val);
        }

        if (!okay)
        {
            msg = tr("The value of iterationDamping was invalid. "
                     "Resetting to the last good value of %1.").
                  arg(atts->GetIterationDamping());
            Message(msg);
            atts->SetIterationDamping(atts->GetIterationDamping());
        }
    }

618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
    // Do annealingTime
    if(which_widget == MaterialAttributes::ID_annealingTime || doAll)
    {
        temp = annealingTime->displayText().simplified();
        bool okay = !temp.isEmpty();
        if (okay)
        {
            int val = temp.toInt(&okay);
            if (val < 0)
                okay = false;
            else
                atts->SetAnnealingTime(val);
        }

        if (!okay)
        {
            msg = tr("The value of annealingTime was invalid. "
                     "Resetting to the last good value of %1.").
                  arg(atts->GetAnnealingTime());
            Message(msg);
            atts->SetAnnealingTime(atts->GetAnnealingTime());
        }
    }
hrchilds's avatar
hrchilds committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
}


// ****************************************************************************
// Method: QvisMaterialWindow::Apply
//
// Purpose: 
//   Called to apply changes in the subject.
//
// Programmer: xml2window
// Creation:   Thu Oct 24 10:03:40 PDT 2002
//
// Modifications:
//    Jeremy Meredith, Fri Jan 24 11:05:28 PST 2003
//    Added a message so as not to confuse users.
//
657 658 659
//    Hank Childs, Mon Jun 11 21:33:42 PDT 2007
//    Only issue the warning a few times.
//
660 661 662
//    Brad Whitlock, Tue Apr  8 09:27:26 PDT 2008
//    Support for internationalization.
//
hrchilds's avatar
hrchilds committed
663 664 665 666 667 668 669 670 671 672
// ****************************************************************************

void
QvisMaterialWindow::Apply(bool ignore)
{
    if(AutoUpdate() || ignore)
    {
        GetCurrentValues(-1);
        atts->Notify();

hrchilds's avatar
hrchilds committed
673
        GetViewerMethods()->SetMaterialAttributes();
674 675
        static int timesIssued = 0;
        if (timesIssued == 0)
676 677
            GUIBase::Warning(tr("Note:  These settings only apply to new plots.  "
                         "To apply them to current plots, re-open the file."));
678
        else if (timesIssued == 1)
679
            GUIBase::Warning(tr("Note:  These settings only apply to new plots.  "
680 681 682
                      "To apply them to current plots, re-open the file.  "
                      "VisIt will NOT issue this message any further times "
                      "for this session, but keep in mind that you must "
683
                      "re-open each time you change the material attributes."));
684
        timesIssued++;
hrchilds's avatar
hrchilds committed
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733
    }
    else
        atts->Notify();
}


//
// Qt Slot functions
//


// ****************************************************************************
// Method: QvisMaterialWindow::apply
//
// Purpose: 
//   Qt slot function called when apply button is clicked.
//
// Programmer: xml2window
// Creation:   Thu Oct 24 10:03:40 PDT 2002
//
// Modifications:
//   
// ****************************************************************************

void
QvisMaterialWindow::apply()
{
    Apply(true);
}


// ****************************************************************************
// Method: QvisMaterialWindow::makeDefault
//
// Purpose: 
//   Qt slot function called when "Make default" button is clicked.
//
// Programmer: xml2window
// Creation:   Thu Oct 24 10:03:40 PDT 2002
//
// Modifications:
//   
// ****************************************************************************

void
QvisMaterialWindow::makeDefault()
{
    GetCurrentValues(-1);
    atts->Notify();
hrchilds's avatar
hrchilds committed
734
    GetViewerMethods()->SetDefaultMaterialAttributes();
hrchilds's avatar
hrchilds committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
}


// ****************************************************************************
// Method: QvisMaterialWindow::reset
//
// Purpose: 
//   Qt slot function called when reset button is clicked.
//
// Programmer: Jeremy Meredith
// Creation:   October 24, 2002
//
// Modifications:
//   
// ****************************************************************************

void
QvisMaterialWindow::reset()
{
hrchilds's avatar
hrchilds committed
754
    GetViewerMethods()->ResetMaterialAttributes();
hrchilds's avatar
hrchilds committed
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
}


void
QvisMaterialWindow::smoothingChanged(bool val)
{
    atts->SetSmoothing(val);
    Apply();
}


void
QvisMaterialWindow::forceMIRChanged(bool val)
{
    atts->SetForceMIR(val);
    Apply();
}


hrchilds's avatar
hrchilds committed
774 775 776 777 778 779 780 781
void
QvisMaterialWindow::forceFullConnectivityChanged(bool val)
{
    atts->SetNeedValidConnectivity(val);
    Apply();
}


hrchilds's avatar
hrchilds committed
782 783 784 785 786 787 788 789
void
QvisMaterialWindow::cleanZonesOnlyChanged(bool val)
{
    atts->SetCleanZonesOnly(val);
    Apply();
}


hrchilds's avatar
hrchilds committed
790
void
hrchilds's avatar
hrchilds committed
791
QvisMaterialWindow::simplifyHeavilyMixedZonesChanged(bool val)
hrchilds's avatar
hrchilds committed
792
{
hrchilds's avatar
hrchilds committed
793
    atts->SetSimplifyHeavilyMixedZones(val);
hrchilds's avatar
hrchilds committed
794 795 796 797
    Apply();
}


hrchilds's avatar
hrchilds committed
798
void
hrchilds's avatar
hrchilds committed
799
QvisMaterialWindow::maxMatsPerZoneProcessText()
hrchilds's avatar
hrchilds committed
800
{
whitlocb's avatar
whitlocb committed
801
    GetCurrentValues(MaterialAttributes::ID_maxMaterialsPerZone);
hrchilds's avatar
hrchilds committed
802 803 804 805 806
    Apply();
}


void
hrchilds's avatar
hrchilds committed
807
QvisMaterialWindow::algorithmChanged(int val)
hrchilds's avatar
hrchilds committed
808
{
hrchilds's avatar
hrchilds committed
809 810 811 812 813
    if(val != atts->GetAlgorithm())
    {
        atts->SetAlgorithm(MaterialAttributes::Algorithm(val));
        Apply();
    }
hrchilds's avatar
hrchilds committed
814 815
}

hrchilds's avatar
hrchilds committed
816 817 818
void
QvisMaterialWindow::isoVolumeFractionProcessText()
{
whitlocb's avatar
whitlocb committed
819
    GetCurrentValues(MaterialAttributes::ID_isoVolumeFraction);
hrchilds's avatar
hrchilds committed
820 821
    Apply();
}
hrchilds's avatar
hrchilds committed
822

823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
void
QvisMaterialWindow::enableIterationChanged(bool val)
{
    atts->SetIterationEnabled(val);
    Apply();
}


void
QvisMaterialWindow::numIterationsProcessText()
{
    GetCurrentValues(MaterialAttributes::ID_numIterations);
    Apply();
}

void
QvisMaterialWindow::iterationDampingProcessText()
{
    GetCurrentValues(MaterialAttributes::ID_iterationDamping);
    Apply();
}

845 846 847 848 849 850
void
QvisMaterialWindow::annealingTimeProcessText()
{
    GetCurrentValues(MaterialAttributes::ID_annealingTime);
    Apply();
}