VTK  9.0.20201019
vtkWidgetSet.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkWidgetSet.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 =========================================================================*/
95 #ifndef vtkWidgetSet_h
96 #define vtkWidgetSet_h
97 
98 #include "vtkInteractionWidgetsModule.h" // For export macro
99 #include "vtkObject.h"
100 #include <vector> // Required for vector
101 
102 class vtkAbstractWidget;
103 
104 // Pointer to a member function that takes a vtkAbstractWidget (the active
105 // child) and another vtkAbstractWidget (the widget to dispatch an action)
106 // to. All "Action" functions in a widget must conform to this signature.
107 template <class TWidget>
109 {
110  typedef void (TWidget::*TActionFunctionPointer)(TWidget* dispatcher);
111 };
112 
113 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
114 {
115 public:
119  static vtkWidgetSet* New();
120 
122 
125  vtkTypeMacro(vtkWidgetSet, vtkObject);
126  void PrintSelf(ostream& os, vtkIndent indent) override;
128 
130 
133  virtual void SetEnabled(vtkTypeBool);
134  vtkBooleanMacro(Enabled, vtkTypeBool);
136 
140  void AddWidget(vtkAbstractWidget*);
141 
145  void RemoveWidget(vtkAbstractWidget*);
146 
150  unsigned int GetNumberOfWidgets();
151 
155  vtkAbstractWidget* GetNthWidget(unsigned int);
156 
157  // TODO: Move this to the protected section. The class vtkAbstractWidget
158  // should be a friend of this class.
159  typedef std::vector<vtkAbstractWidget*> WidgetContainerType;
160  typedef WidgetContainerType::iterator WidgetIteratorType;
161  typedef WidgetContainerType::const_iterator WidgetConstIteratorType;
163 
165 
169  template <class TWidget>
171  TWidget* caller, typename ActionFunction<TWidget>::TActionFunctionPointer action)
172  {
173  // Dispatch action to the caller first.
174  for (WidgetIteratorType it = this->Widget.begin(); it != this->Widget.end(); ++it)
175  {
176  TWidget* w = static_cast<TWidget*>(*it);
177  if (caller == w)
178  {
179  ((*w).*(action))(caller);
180  break;
181  }
182  }
184 
185  // Dispatch action to all other widgets
186  for (WidgetIteratorType it = this->Widget.begin(); it != this->Widget.end(); ++it)
187  {
188  TWidget* w = static_cast<TWidget*>(*it);
189  if (caller != w)
190  ((*w).*(action))(caller);
191  }
192  }
193 
194 protected:
195  vtkWidgetSet();
196  ~vtkWidgetSet() override;
197 
198 private:
199  vtkWidgetSet(const vtkWidgetSet&) = delete;
200  void operator=(const vtkWidgetSet&) = delete;
201 };
202 
203 #endif
vtkWidgetSet::DispatchAction
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:170
vtkWidgetSet::WidgetConstIteratorType
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:161
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkAbstractWidget
define the API for widget / widget representation
Definition: vtkAbstractWidget.h:65
vtkWidgetSet
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:113
vtkWidgetSet::WidgetContainerType
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:159
vtkWidgetSet::Widget
WidgetContainerType Widget
Definition: vtkWidgetSet.h:162
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkWidgetSet::WidgetIteratorType
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:160
vtkObject.h
ActionFunction
Definition: vtkWidgetSet.h:108
ActionFunction::TActionFunctionPointer
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:110
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69