VTK  9.0.3
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 
141 
146 
150  unsigned int GetNumberOfWidgets();
151 
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:
196  ~vtkWidgetSet() override;
197 
198 private:
199  vtkWidgetSet(const vtkWidgetSet&) = delete;
200  void operator=(const vtkWidgetSet&) = delete;
201 };
202 
203 #endif
define the API for widget / widget representation
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:114
virtual void SetEnabled(vtkTypeBool)
Method for activating and deactivating all widgets in the group.
void AddWidget(vtkAbstractWidget *)
Add a widget to the set.
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:159
~vtkWidgetSet() override
WidgetContainerType Widget
Definition: vtkWidgetSet.h:162
vtkAbstractWidget * GetNthWidget(unsigned int)
Get the Nth widget in the set.
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:170
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:161
unsigned int GetNumberOfWidgets()
Get number of widgets in the set.
static vtkWidgetSet * New()
Instantiate this class.
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:160
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void RemoveWidget(vtkAbstractWidget *)
Remove a widget from the set.
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:110
int vtkTypeBool
Definition: vtkABI.h:69