VTK
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 =========================================================================*/
94 #ifndef vtkWidgetSet_h
95 #define vtkWidgetSet_h
96 
97 #include "vtkInteractionWidgetsModule.h" // For export macro
98 #include "vtkObject.h"
99 #include <vector> // Required for vector
100 
101 class vtkAbstractWidget;
102 
103 // Pointer to a member function that takes a vtkAbstractWidget (the active
104 // child) and another vtkAbstractWidget (the widget to dispatch an action)
105 // to. All "Action" functions in a widget must conform to this signature.
106 template< class TWidget > struct ActionFunction
107 {
108  typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
109 };
110 
111 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
112 {
113 public:
117  static vtkWidgetSet *New();
118 
120 
123  vtkTypeMacro(vtkWidgetSet,vtkObject);
124  void PrintSelf(ostream& os, vtkIndent indent) override;
126 
128 
131  virtual void SetEnabled(vtkTypeBool);
132  vtkBooleanMacro(Enabled, vtkTypeBool);
134 
138  void AddWidget(vtkAbstractWidget *);
139 
143  void RemoveWidget(vtkAbstractWidget *);
144 
148  unsigned int GetNumberOfWidgets();
149 
153  vtkAbstractWidget *GetNthWidget( unsigned int );
154 
155  // TODO: Move this to the protected section. The class vtkAbstractWidget
156  // should be a friend of this class.
157  typedef std::vector< vtkAbstractWidget * > WidgetContainerType;
158  typedef WidgetContainerType::iterator WidgetIteratorType;
159  typedef WidgetContainerType::const_iterator WidgetConstIteratorType;
160  WidgetContainerType Widget;
161 
163 
167  template < class TWidget >
168  void DispatchAction(TWidget *caller,
170  {
171  // Dispatch action to the caller first.
172  for (WidgetIteratorType it = this->Widget.begin();
173  it != this->Widget.end() ; ++it)
174  {
175  TWidget *w = static_cast<TWidget *>(*it);
176  if (caller == w)
177  {
178  ((*w).*(action))(caller);
179  break;
180  }
181  }
183 
184  // Dispatch action to all other widgets
185  for (WidgetIteratorType it = this->Widget.begin();
186  it != this->Widget.end() ; ++it)
187  {
188  TWidget *w = static_cast<TWidget *>(*it);
189  if (caller != w) ((*w).*(action))(caller);
190  }
191  }
192 
193 protected:
194  vtkWidgetSet();
195  ~vtkWidgetSet() override;
196 
197 private:
198  vtkWidgetSet(const vtkWidgetSet&) = delete;
199  void operator=(const vtkWidgetSet&) = delete;
200 };
201 
202 #endif
203 
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:59
WidgetContainerType Widget
Definition: vtkWidgetSet.h:160
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:168
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:111
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:158
int vtkTypeBool
Definition: vtkABI.h:69
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:159
a simple class to control print indentation
Definition: vtkIndent.h:39
define the API for widget / widget representation
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:157