File: pqSGExportStateWizard.cxx

package info (click to toggle)
paraview 5.4.1%2Bdfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 218,616 kB
  • sloc: cpp: 2,331,508; ansic: 322,365; python: 111,051; xml: 79,203; tcl: 47,013; yacc: 4,877; java: 4,438; perl: 3,238; sh: 2,920; lex: 1,908; f90: 748; makefile: 273; pascal: 228; objc: 83; fortran: 31
file content (350 lines) | stat: -rw-r--r-- 12,889 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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
/*=========================================================================

   Program: ParaView
   Module:    pqSGExportStateWizard.cxx

   Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

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 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL 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 "pqSGExportStateWizard.h"

#include "pqApplicationCore.h"
#include "pqContextView.h"
#include "pqImageOutputInfo.h"
#include "pqPipelineFilter.h"
#include "pqRenderViewBase.h"
#include "pqServerManagerModel.h"
#include "vtkPythonInterpreter.h"
#include "vtkSMCoreUtilities.h"
#include "vtkSmartPointer.h"

#include "pqCinemaTrack.h"
#include "pqPipelineFilter.h"
#include "vtkSMDoubleRangeDomain.h"
#include "vtkSMProperty.h"

#include <vtksys/SystemTools.hxx>

#include <QLabel>
#include <QMessageBox>
#include <QPixmap>
#include <QPointer>
#include <QRegExp>
#include <QRegExpValidator>
#include <QSize>

#include <QDebug>

// HACK.
namespace
{
static QPointer<pqSGExportStateWizard> ActiveWizard;
}

pqSGExportStateWizardPage2::pqSGExportStateWizardPage2(QWidget* _parent)
  : QWizardPage(_parent)
{
  this->Internals = ::ActiveWizard->Internals;
}

pqSGExportStateWizardPage3::pqSGExportStateWizardPage3(QWidget* _parent)
  : QWizardPage(_parent)
{
  this->Internals = ::ActiveWizard->Internals;
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizardPage2::initializePage()
{
  this->Internals->simulationInputs->clear();
  this->Internals->allInputs->clear();
  QList<pqPipelineSource*> sources =
    pqApplicationCore::instance()->getServerManagerModel()->findItems<pqPipelineSource*>();
  foreach (pqPipelineSource* source, sources)
  {
    if (qobject_cast<pqPipelineFilter*>(source))
    {
      continue;
    }
    if (this->Internals->showAllSources->isChecked())
    {
      this->Internals->allInputs->addItem(source->getSMName());
    }
    else
    { // determine if the source is a reader or not, only include readers
      if (vtkSMCoreUtilities::GetFileNameProperty(source->getProxy()))
      {
        this->Internals->allInputs->addItem(source->getSMName());
      }
    }
  }
}

//-----------------------------------------------------------------------------
bool pqSGExportStateWizardPage2::isComplete() const
{
  return this->Internals->simulationInputs->count() > 0;
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizardPage3::initializePage()
{
  this->Internals->nameWidget->clearContents();
  this->Internals->nameWidget->setRowCount(this->Internals->simulationInputs->count());
  for (int cc = 0; cc < this->Internals->simulationInputs->count(); cc++)
  {
    QListWidgetItem* item = this->Internals->simulationInputs->item(cc);
    QString text = item->text();
    this->Internals->nameWidget->setItem(cc, 0, new QTableWidgetItem(text));
    // if there is only 1 input then call it input, otherwise
    // use the same name as the filter
    if (this->Internals->simulationInputs->count() == 1)
    {
      this->Internals->nameWidget->setItem(cc, 1, new QTableWidgetItem("input"));
    }
    else
    {
      this->Internals->nameWidget->setItem(cc, 1, new QTableWidgetItem(text));
    }
    QTableWidgetItem* tableItem = this->Internals->nameWidget->item(cc, 1);
    tableItem->setFlags(tableItem->flags() | Qt::ItemIsEditable);

    tableItem = this->Internals->nameWidget->item(cc, 0);
    tableItem->setFlags(tableItem->flags() & ~Qt::ItemIsEditable);
  }
}

//-----------------------------------------------------------------------------
pqSGExportStateWizard::pqSGExportStateWizard(QWidget* parentObject, Qt::WindowFlags parentFlags)
  : Superclass(parentObject, parentFlags)
{
  ::ActiveWizard = this;
  this->Internals = new pqInternals();
  this->Internals->setupUi(this);
  ::ActiveWizard = NULL;
  // this->setWizardStyle(ModernStyle);
  this->setOption(QWizard::NoCancelButton, false);
  this->Internals->wViewSelection->hide();
  this->Internals->fileNamePaddingAmountLabel->hide();
  this->Internals->fileNamePaddingAmountSpinBox->hide();
  this->Internals->rescaleDataRange->hide();
  this->Internals->laRescaleDataRange->hide();

  QObject::connect(this->Internals->allInputs, SIGNAL(itemSelectionChanged()), this,
    SLOT(updateAddRemoveButton()));
  QObject::connect(this->Internals->simulationInputs, SIGNAL(itemSelectionChanged()), this,
    SLOT(updateAddRemoveButton()));
  QObject::connect(
    this->Internals->showAllSources, SIGNAL(toggled(bool)), this, SLOT(onShowAllSources(bool)));
  QObject::connect(this->Internals->addButton, SIGNAL(clicked()), this, SLOT(onAdd()));
  QObject::connect(this->Internals->removeButton, SIGNAL(clicked()), this, SLOT(onRemove()));

  QObject::connect(
    this->Internals->allInputs, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(onAdd()));
  QObject::connect(this->Internals->simulationInputs, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
    this, SLOT(onRemove()));

  QObject::connect(this->Internals->outputRendering, SIGNAL(toggled(bool)),
    this->Internals->wViewSelection, SLOT(setVisible(bool)));

  QObject::connect(this->Internals->outputRendering, SIGNAL(toggled(bool)),
    this->Internals->fileNamePaddingAmountSpinBox, SLOT(setVisible(bool)));
  QObject::connect(this->Internals->outputRendering, SIGNAL(toggled(bool)),
    this->Internals->fileNamePaddingAmountLabel, SLOT(setVisible(bool)));

  QObject::connect(this->Internals->outputRendering, SIGNAL(toggled(bool)),
    this->Internals->rescaleDataRange, SLOT(setVisible(bool)));
  QObject::connect(this->Internals->outputRendering, SIGNAL(toggled(bool)),
    this->Internals->laRescaleDataRange, SLOT(setVisible(bool)));

  this->Internals->wCinemaTrackSelection->hide();

  QObject::connect(this->Internals->outputCinema, SIGNAL(toggled(bool)),
    this->Internals->outputRendering, SLOT(setChecked(bool)));
  QObject::connect(this->Internals->outputCinema, SIGNAL(toggled(bool)),
    this->Internals->wCinemaTrackSelection, SLOT(setVisible(bool)));
  QObject::connect(
    this->Internals->outputCinema, SIGNAL(toggled(bool)), this, SLOT(toggleCinema(bool)));
  QObject::connect(this->Internals->wViewSelection, SIGNAL(arraySelectionEnabledChanged(bool)),
    this->Internals->wCinemaTrackSelection, SLOT(enableArraySelection(bool)));

  pqServerManagerModel* smModel = pqApplicationCore::instance()->getServerManagerModel();

  // populate views in stacked widget
  QList<pqRenderViewBase*> renderViews = smModel->findItems<pqRenderViewBase*>();
  QList<pqContextView*> contextViews = smModel->findItems<pqContextView*>();
  this->Internals->wViewSelection->populateViews(renderViews, contextViews);

  // populate the pipeline browser
  this->Internals->wCinemaTrackSelection->initializePipelineBrowser();

  // a bit of a hack but we name the finish button here since for testing
  // it's having a hard time finding that button otherwise.
  QAbstractButton* finishButton = this->button(FinishButton);
  QString name("finishButton");
  finishButton->setObjectName(name);
}

//-----------------------------------------------------------------------------
pqSGExportStateWizard::~pqSGExportStateWizard()
{
  delete this->Internals;
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizard::updateAddRemoveButton()
{
  this->Internals->addButton->setEnabled(this->Internals->allInputs->selectedItems().size() > 0);
  this->Internals->removeButton->setEnabled(
    this->Internals->simulationInputs->selectedItems().size() > 0);
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizard::onShowAllSources(bool isChecked)
{
  if (isChecked)
  { // add any sources that aren't readers and aren't in simulationInputs
    QList<pqPipelineSource*> sources =
      pqApplicationCore::instance()->getServerManagerModel()->findItems<pqPipelineSource*>();
    foreach (pqPipelineSource* source, sources)
    {
      if (qobject_cast<pqPipelineFilter*>(source))
      {
        continue;
      }
      if (vtkSMCoreUtilities::GetFileNameProperty(source->getProxy()) == NULL)
      {
        // make sure it's not in the list of simulationInputs
        QList<QListWidgetItem*> matchingNames =
          this->Internals->simulationInputs->findItems(source->getSMName(), 0);
        if (matchingNames.isEmpty())
        {
          this->Internals->allInputs->addItem(source->getSMName());
        }
      }
    }
  }
  else
  { // remove any source that aren't readers from allInputs
    for (int i = this->Internals->allInputs->count() - 1; i >= 0; i--)
    {
      QListWidgetItem* item = this->Internals->allInputs->item(i);
      QString text = item->text();
      pqPipelineSource* source =
        pqApplicationCore::instance()->getServerManagerModel()->findItem<pqPipelineSource*>(text);
      if (vtkSMCoreUtilities::GetFileNameProperty(source->getProxy()) == NULL)
      {
        delete this->Internals->allInputs->takeItem(i);
      }
    }
  }
  dynamic_cast<pqSGExportStateWizardPage2*>(this->currentPage())->emitCompleteChanged();
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizard::onAdd()
{
  foreach (QListWidgetItem* item, this->Internals->allInputs->selectedItems())
  {
    QString text = item->text();
    this->Internals->simulationInputs->addItem(text);
    delete this->Internals->allInputs->takeItem(this->Internals->allInputs->row(item));
  }
  dynamic_cast<pqSGExportStateWizardPage2*>(this->currentPage())->emitCompleteChanged();
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizard::onRemove()
{
  foreach (QListWidgetItem* item, this->Internals->simulationInputs->selectedItems())
  {
    QString text = item->text();
    if (this->Internals->showAllSources->isChecked())
    { // we show all sources...
      this->Internals->allInputs->addItem(text);
    }
    else
    { // show only reader sources...
      pqPipelineSource* source =
        pqApplicationCore::instance()->getServerManagerModel()->findItem<pqPipelineSource*>(text);
      if (vtkSMCoreUtilities::GetFileNameProperty(source->getProxy()))
      {
        this->Internals->allInputs->addItem(text);
      }
    }
    delete this->Internals->simulationInputs->takeItem(
      this->Internals->simulationInputs->row(item));
  }
  dynamic_cast<pqSGExportStateWizardPage2*>(this->currentPage())->emitCompleteChanged();
}

//-----------------------------------------------------------------------------
QList<pqImageOutputInfo*> pqSGExportStateWizard::getImageOutputInfos()
{
  return this->Internals->wViewSelection->getImageOutputInfos();
}

//-----------------------------------------------------------------------------
bool pqSGExportStateWizard::validateCurrentPage()
{
  if (!this->Superclass::validateCurrentPage())
  {
    return false;
  }

  if (this->nextId() != -1)
  {
    // not yet done with the wizard.
    return true;
  }

  QString command;
  if (this->getCommandString(command))
  {
    // ensure Python in initialized.
    vtkPythonInterpreter::Initialize();
    vtkPythonInterpreter::RunSimpleString(command.toLocal8Bit().data());
    return true;
  }
  return false;
}

//-----------------------------------------------------------------------------
void pqSGExportStateWizard::toggleCinema(bool state)
{
  if (state)
  {
    // cinema depends on rendering being on (unchecking it should not be possible)
    this->Internals->outputRendering->setEnabled(false);
    // add cinema controls to each view
    this->Internals->wViewSelection->setCinemaVisible(true);
  }
  else
  {
    this->Internals->outputRendering->setEnabled(true);
    this->Internals->wViewSelection->setCinemaVisible(false);
  }
}