ParaView
pqMultiBlockInspectorPanel.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: pqMultiBlockInspectorPanel.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #ifndef pqMultiBlockInspectorPanel_h
17 #define pqMultiBlockInspectorPanel_h
18 
19 #include "pqComponentsModule.h"
20 
21 #include "pqTimer.h" // needed for pqTimer.
22 #include <QIcon>
23 #include <QMap>
24 #include <QPointer>
25 #include <QWidget>
26 
27 #include <iostream>
28 
29 class QModelIndex;
30 class QTreeWidget;
31 class QTreeWidgetItem;
32 
33 class pqOutputPort;
34 class pqRepresentation;
35 class vtkDiscretizableColorTransferFunction;
36 class vtkEventQtSlotConnect;
37 class vtkPiecewiseFunction;
38 class vtkPVCompositeDataInformation;
39 class vtkSMProxy;
40 
41 class PQCOMPONENTS_EXPORT pqMultiBlockInspectorPanel : public QWidget
42 {
43  Q_OBJECT
44 
45 public:
46  pqMultiBlockInspectorPanel(QWidget *parent = 0);
48 
49  pqOutputPort* getOutputPort() const;
50  pqRepresentation* getRepresentation() const;
51 
52  QString lookupBlockName(unsigned int flatIndex) const;
53 
54 public slots:
56  void onPortChanged(pqOutputPort *port);
57  void onRepresentationChanged(pqRepresentation *representation);
58  void onDataUpdated();
59 
60  void setBlockVisibility(unsigned int index, bool visible);
61  void clearBlockVisibility(unsigned int index);
62  void setBlockVisibility(const QList<unsigned int>& indices, bool visible);
63  void clearBlockVisibility(const QList<unsigned int>& indices);
64 
65  void setBlockColor(unsigned int index, const QColor &color);
66  void clearBlockColor(unsigned int index);
67  void setBlockColor(const QList<unsigned int>& indices, const QColor &color);
68  void clearBlockColor(const QList<unsigned int>& indices);
69 
70  void setBlockOpacity(unsigned int index, double opacity);
71  void clearBlockOpacity(unsigned int index);
72  void setBlockOpacity(const QList<unsigned int> &indices, double opacity);
73  void clearBlockOpacity(const QList<unsigned int> &indices);
74 
75  void promptAndSetBlockOpacity(unsigned int index);
76  void promptAndSetBlockOpacity(const QList<unsigned int> &indices);
77 
78  void showOnlyBlock(unsigned int index);
79  void showOnlyBlocks(const QList<unsigned int>& indices);
80  void showAllBlocks();
81 
82 private slots:
84  void onSelectionChanged(pqOutputPort *port);
85  void onColorArrayNameModified();
86 
87  void onCustomContextMenuRequested(const QPoint &pos);
88  void onItemChanged(QTreeWidgetItem *item, int column);
89  void updateTree();
90  void updateTree(vtkPVCompositeDataInformation *iter,
91  QTreeWidgetItem *parent,
92  int& flatIndex, bool visibility,
93  int inheritedColorIndex,
94  int inheritedOpacityIndex);
95  void onItemSelectionChanged();
96  void onItemDoubleClicked(QTreeWidgetItem * item, int column);
97  void updateBlockVisibilities();
98  void updateBlockColors();
99  void updateBlockOpacities();
100 
101 private:
102  Q_DISABLE_COPY(pqMultiBlockInspectorPanel)
103 
104  enum NodeType
105  {
106  INTERNAL_NODE,
107  LEAF_NODE
108  };
109 
110  void buildTree(vtkPVCompositeDataInformation *iter,
111  QTreeWidgetItem *parent,
112  int& flatIndex, // composite-data id
113  int& leafIndex); // leaf-only index.
114  void unsetChildVisibilities(QTreeWidgetItem *parent);
115  QIcon makeColorIcon(int flatIndex, NodeType nodeType,
116  int inheritedColorIndex, int leafIndex=-1) const;
117  QIcon makeOpacityIcon(int flatIndex, NodeType nodeType,
118  int inheritedOpacityIndex) const;
119  QIcon makeNullIcon() const;
120 
121 
122 
123 private:
124  QTreeWidget *TreeWidget;
125  QPointer<pqOutputPort> OutputPort;
126  QPointer<pqRepresentation> Representation;
127  QMap<unsigned int, bool> BlockVisibilites;
128  QMap<unsigned int, QColor> BlockColors;
129  QMap<unsigned int, double> BlockOpacities;
130  vtkEventQtSlotConnect *PropertyListener;
131  vtkSMProxy *ColorTransferProxy;
132  vtkDiscretizableColorTransferFunction* ColorTransferFunction;
133  vtkPiecewiseFunction* OpacityTransferFunction;
134  unsigned int BlockColorsDistinctValues;
135  int CompositeWrap;
136 
137  pqTimer UpdateUITimer;
138 
139  struct BlockIcon
140  {
141  bool HasColor;
142  bool HasOpacity;
143  QColor Color;
144  double Opacity;
145 
146  bool operator<(const BlockIcon &other) const
147  {
148  QColor c = this->HasColor ? this->Color : QColor();
149  c.setAlphaF(this->HasOpacity ? this->Opacity : 1.0);
150 
151  QColor oc = other.HasColor ? other.Color : QColor();
152  oc.setAlphaF(other.HasOpacity ? other.Opacity : 1.0);
153 
154  return c.rgba() < oc.rgba();
155  }
156  };
157 };
158 
159 #endif // pqMultiBlockInspectorPanel_h
pqOutputPort is a server manager model item for an output port of any pqPipelineSource item...
Definition: pqOutputPort.h:55
This is PQ representation for a single representation.