File: pqChangeInputDialog.cxx

package info (click to toggle)
paraview 5.4.1+dfsg4-3.1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • 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 (299 lines) | stat: -rw-r--r-- 10,631 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
/*=========================================================================

   Program: ParaView
   Module:    pqChangeInputDialog.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 "pqChangeInputDialog.h"
#include "ui_pqChangeInputDialog.h"

#include "pqActiveObjects.h"
#include "pqApplicationCore.h"
#include "pqOutputPort.h"
#include "pqPipelineFilter.h"
#include "pqPipelineModel.h"
#include "pqServer.h"
#include "pqServerManagerModel.h"
#include "vtkSMDocumentation.h"
#include "vtkSMInputProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxy.h"
#include "vtkSmartPointer.h"

#include <QHeaderView>
#include <QItemSelectionModel>
#include <QLineEdit>
#include <QRadioButton>

class pqChangeInputDialog::pqInternals : public Ui::pqChangeInputDialog
{
public:
  pqPipelineModel* PipelineModel;
  vtkSmartPointer<vtkSMProxy> Proxy;

  QString ActiveInputProperty;
  bool BlockSelectionChanged;
  QMap<QString, QList<pqOutputPort*> > Inputs;
  QMap<QString, bool> AcceptsMultipleConnections;
};

//-----------------------------------------------------------------------------
pqChangeInputDialog::pqChangeInputDialog(vtkSMProxy* filterProxy, QWidget* parentObject)
  : Superclass(parentObject)
{
  Q_ASSERT(filterProxy != NULL);

  this->Internals = new pqInternals();
  this->Internals->Proxy = filterProxy;
  this->Internals->BlockSelectionChanged = false;

  this->Internals->setupUi(this);

  pqServerManagerModel* smModel = pqApplicationCore::instance()->getServerManagerModel();
  this->Internals->PipelineModel = new pqPipelineModel(*smModel, this);
  this->Internals->PipelineModel->setEditable(false);
  this->Internals->pipelineView->setModel(this->Internals->PipelineModel);

  this->Internals->pipelineView->getHeader()->hide();
  // don't show the visibility icons.
  this->Internals->pipelineView->getHeader()->hideSection(1);
  this->Internals->pipelineView->setRootIndex(
    this->Internals->PipelineModel->getIndexFor(pqActiveObjects::instance().activeServer()));
  this->Internals->pipelineView->expandAll();

  QObject::connect(this->Internals->pipelineView->getSelectionModel(),
    SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this,
    SLOT(selectionChanged()));

  // build current input list.
  QList<const char*> input_property_names = pqPipelineFilter::getInputPorts(filterProxy);
  foreach (const char* property_name, input_property_names)
  {
    QList<pqOutputPort*>& list = this->Internals->Inputs[property_name];

    vtkSMPropertyHelper helper(filterProxy, property_name);
    unsigned int numProxies = helper.GetNumberOfElements();
    for (unsigned int cc = 0; cc < numProxies; cc++)
    {
      pqPipelineSource* source = smModel->findItem<pqPipelineSource*>(helper.GetAsProxy(cc));
      if (source == NULL)
      {
        qDebug("Not all current inputs to this filter are know to the ProxyManager");
        continue;
      }
      pqOutputPort* port = source->getOutputPort(helper.GetOutputPort(cc));
      list.push_back(port);
    }

    // check if multiple connections are accepted by this input property.
    vtkSMInputProperty* ip =
      vtkSMInputProperty::SafeDownCast(filterProxy->GetProperty(property_name));
    if (ip && ip->GetMultipleInput())
    {
      this->Internals->AcceptsMultipleConnections[property_name] = true;
    }
    else
    {
      this->Internals->AcceptsMultipleConnections[property_name] = false;
    }
  }

  this->buildPortWidgets();
}

//-----------------------------------------------------------------------------
pqChangeInputDialog::~pqChangeInputDialog()
{
  delete this->Internals;
  this->Internals = 0;
}

//-----------------------------------------------------------------------------
const QMap<QString, QList<pqOutputPort*> >& pqChangeInputDialog::selectedInputs() const
{
  return this->Internals->Inputs;
}

//-----------------------------------------------------------------------------
void pqChangeInputDialog::buildPortWidgets()
{
  QVBoxLayout* vbox = qobject_cast<QVBoxLayout*>(this->Internals->buttonFrame->layout());

  // we use this since it returns a nice ordered list of the input port names
  // rather than an alphabetically sorted one.
  QList<const char*> input_property_names = pqPipelineFilter::getInputPorts(this->Internals->Proxy);
  QRadioButton* firstButton = 0;
  for (int cc = 0; cc < input_property_names.size(); cc++)
  {
    const char* input_prop_name = input_property_names[cc];
    vtkSMProperty* smproperty = this->Internals->Proxy->GetProperty(input_prop_name);
    QRadioButton* rb = new QRadioButton(this->Internals->buttonFrame);
    rb->setObjectName(input_prop_name);
    rb->setText(smproperty->GetXMLLabel());
    if (smproperty->GetDocumentation())
    {
      rb->setToolTip(QString(smproperty->GetDocumentation()->GetDescription()).trimmed());
    }
    vbox->addWidget(rb);

    QObject::connect(rb, SIGNAL(toggled(bool)), this, SLOT(inputPortToggled(bool)));

    firstButton = firstButton ? firstButton : rb;
  }
  vbox->addStretch();

  if (firstButton)
  {
    firstButton->setChecked(true);
  }

  if (this->Internals->Inputs.size() <= 1)
  {
    // no need to show the radio buttons when there's only 1 input port.
    this->Internals->buttonFrame->hide();
    this->Internals->line->hide();
    this->layout()->removeWidget(this->Internals->buttonFrame);
    this->layout()->removeWidget(this->Internals->line);
  }
}

//-----------------------------------------------------------------------------
void pqChangeInputDialog::inputPortToggled(bool checked)
{
  if (!checked)
  {
    return;
  }

  QRadioButton* radioButton = qobject_cast<QRadioButton*>(this->sender());
  this->Internals->selectInputLabel->setText(QString("Select <b>%1</b>").arg(radioButton->text()));

  QModelIndexList selected_indexes;
  QString input_prop_name = radioButton->objectName();
  this->Internals->ActiveInputProperty = input_prop_name;

  QList<pqOutputPort*>& list = this->Internals->Inputs[input_prop_name];
  foreach (pqOutputPort* port, list)
  {
    selected_indexes.push_back(this->Internals->PipelineModel->getIndexFor(port));
  }

  // update selectability i.e. what sources in the pipelines are acceptable as
  // inputs for the current input port.
  pqServerManagerModel* smModel = pqApplicationCore::instance()->getServerManagerModel();
  this->Internals->PipelineModel->setSubtreeSelectable(
    pqActiveObjects::instance().activeServer(), true);
  pqPipelineSource* pqproxy = smModel->findItem<pqPipelineSource*>(this->Internals->Proxy);
  if (pqproxy)
  {
    this->Internals->PipelineModel->setSubtreeSelectable(pqproxy, false);
  }

  vtkSMInputProperty* inputProp = vtkSMInputProperty::SafeDownCast(
    this->Internals->Proxy->GetProperty(input_prop_name.toLocal8Bit().data()));

  QModelIndex root = this->Internals->pipelineView->getRootIndex();
  QModelIndex index = this->Internals->PipelineModel->getNextIndex(root, root);
  while (index.isValid())
  {
    if (this->Internals->PipelineModel->isSelectable(index))
    {
      pqServerManagerModelItem* item = this->Internals->PipelineModel->getItemFor(index);
      pqPipelineSource* source = qobject_cast<pqPipelineSource*>(item);
      pqOutputPort* port = qobject_cast<pqOutputPort*>(item);
      if (source)
      {
        port = source->getOutputPort(0);
      }
      if (source && source->getNumberOfOutputPorts() > 1)
      {
        this->Internals->PipelineModel->setSelectable(index, false);
      }
      else if (port)
      {
        inputProp->RemoveAllUncheckedProxies();
        inputProp->AddUncheckedInputConnection(
          port->getSource()->getProxy(), port->getPortNumber());
        this->Internals->PipelineModel->setSelectable(index, inputProp->IsInDomains() > 0);
        inputProp->RemoveAllUncheckedProxies();
      }
      else
      {
        this->Internals->PipelineModel->setSelectable(index, false);
      }
    }
    index = this->Internals->PipelineModel->getNextIndex(index, root);
  }

  // update selection mode.
  if (this->Internals->AcceptsMultipleConnections[input_prop_name])
  {
    this->Internals->pipelineView->setSelectionMode(pqFlatTreeView::ExtendedSelection);
  }
  else
  {
    this->Internals->pipelineView->setSelectionMode(pqFlatTreeView::SingleSelection);
  }

  // update current selection.
  this->Internals->BlockSelectionChanged = true;
  QItemSelectionModel* selModel = this->Internals->pipelineView->getSelectionModel();
  selModel->clear();
  foreach (QModelIndex idx, selected_indexes)
  {
    selModel->select(idx, QItemSelectionModel::Select);
  }
  this->Internals->BlockSelectionChanged = false;
  this->selectionChanged();
}

//-----------------------------------------------------------------------------
void pqChangeInputDialog::selectionChanged()
{
  if (this->Internals->BlockSelectionChanged)
  {
    return;
  }

  QList<pqOutputPort*>& list = this->Internals->Inputs[this->Internals->ActiveInputProperty];
  list.clear();

  QItemSelectionModel* selModel = this->Internals->pipelineView->getSelectionModel();
  QModelIndexList indexes = selModel->selectedIndexes();
  foreach (QModelIndex idx, indexes)
  {
    pqServerManagerModelItem* item = this->Internals->PipelineModel->getItemFor(idx);
    pqOutputPort* port = qobject_cast<pqOutputPort*>(item);
    pqPipelineSource* source = qobject_cast<pqPipelineSource*>(item);
    if (source)
    {
      port = source->getOutputPort(0);
    }
    list.push_back(port);
  }
}