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 =========================================================================*/
93 #ifndef vtkWidgetSet_h
94 #define vtkWidgetSet_h
95 
96 #include "vtkInteractionWidgetsModule.h" // For export macro
97 #include "vtkObject.h"
98 #include <vector> // Required for vector
99 
100 class vtkAbstractWidget;
101 
102 //BTX
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 //ETX
111 
113 {
114 public:
116  static vtkWidgetSet *New();
117 
119 
120  vtkTypeMacro(vtkWidgetSet,vtkObject);
121  void PrintSelf(ostream& os, vtkIndent indent);
123 
125 
126  virtual void SetEnabled(int);
127  vtkBooleanMacro(Enabled, int);
129 
131  void AddWidget(vtkAbstractWidget *);
132 
134  void RemoveWidget(vtkAbstractWidget *);
135 
137  unsigned int GetNumberOfWidgets();
138 
140  vtkAbstractWidget *GetNthWidget( unsigned int );
141 
142  //BTX
143  // TODO: Move this to the protected section. The class vtkAbstractWidget
144  // should be a friend of this class.
145  typedef std::vector< vtkAbstractWidget * > WidgetContainerType;
146  typedef WidgetContainerType::iterator WidgetIteratorType;
147  typedef WidgetContainerType::const_iterator WidgetConstIteratorType;
148  WidgetContainerType Widget;
149 
151 
153  template < class TWidget >
154  void DispatchAction(TWidget *caller,
156  {
157  // Dispatch action to the caller first.
158  for (WidgetIteratorType it = this->Widget.begin();
159  it != this->Widget.end() ; ++it)
160  {
161  TWidget *w = static_cast<TWidget *>(*it);
162  if (caller == w)
163  {
164  ((*w).*(action))(caller);
165  break;
166  }
167  }
169 
170  // Dispatch action to all other widgets
171  for (WidgetIteratorType it = this->Widget.begin();
172  it != this->Widget.end() ; ++it)
173  {
174  TWidget *w = static_cast<TWidget *>(*it);
175  if (caller != w) ((*w).*(action))(caller);
176  }
177  }
178  //ETX
179 
180 protected:
181  vtkWidgetSet();
182  ~vtkWidgetSet();
183 
184 private:
185  vtkWidgetSet(const vtkWidgetSet&); //Not implemented
186  void operator=(const vtkWidgetSet&); //Not implemented
187 };
188 
189 #endif
190 
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:108
abstract base class for most VTK objects
Definition: vtkObject.h:61
WidgetContainerType Widget
Definition: vtkWidgetSet.h:148
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Definition: vtkWidgetSet.h:154
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:112
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:146
#define VTKINTERACTIONWIDGETS_EXPORT
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:147
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:38
define the API for widget / widget representation
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:145
static vtkObject * New()