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 "vtkObject.h"
97 #include <vtkstd/vector> // Required for vector
98 
99 class vtkAbstractWidget;
100 
101 //BTX
102 // Pointer to a member function that takes a vtkAbstractWidget (the active
103 // child) and another vtkAbstractWidget (the widget to dispatch an action)
104 // to. All "Action" funtions in a widget must conform to this signature.
105 template< class TWidget > struct ActionFunction
106 {
107  typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
108 };
109 //ETX
110 
112 {
113 public:
115  static vtkWidgetSet *New();
116 
118 
119  vtkTypeMacro(vtkWidgetSet,vtkObject);
120  void PrintSelf(ostream& os, vtkIndent indent);
122 
124 
125  virtual void SetEnabled(int);
126  vtkBooleanMacro(Enabled, int);
128 
130  void AddWidget(vtkAbstractWidget *);
131 
133  void RemoveWidget(vtkAbstractWidget *);
134 
136  unsigned int GetNumberOfWidgets();
137 
139  vtkAbstractWidget *GetNthWidget( unsigned int );
140 
141  //BTX
142  // TODO: Move this to the protected section. The class vtkAbstractWidget
143  // should be a friend of this class.
144  typedef vtkstd::vector< vtkAbstractWidget * > WidgetContainerType;
145  typedef WidgetContainerType::iterator WidgetIteratorType;
146  typedef WidgetContainerType::const_iterator WidgetConstIteratorType;
147  WidgetContainerType Widget;
148 
150 
152  template < class TWidget >
153  void DispatchAction(TWidget *caller,
155  {
156  // Dispatch action to the caller first.
157  for (WidgetIteratorType it = this->Widget.begin();
158  it != this->Widget.end() ; ++it)
159  {
160  TWidget *w = static_cast<TWidget *>(*it);
161  if (caller == w)
162  {
163  ((*w).*(action))(caller);
164  break;
165  }
166  }
168 
169  // Dispatch action to all other widgets
170  for (WidgetIteratorType it = this->Widget.begin();
171  it != this->Widget.end() ; ++it)
172  {
173  TWidget *w = static_cast<TWidget *>(*it);
174  if (caller != w) ((*w).*(action))(caller);
175  }
176  }
177  //ETX
178 
179 protected:
180  vtkWidgetSet();
181  ~vtkWidgetSet();
182 
183 private:
184  vtkWidgetSet(const vtkWidgetSet&); //Not implemented
185  void operator=(const vtkWidgetSet&); //Not implemented
186 };
187 
188 #endif
189 
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:107
abstract base class for most VTK objects
Definition: vtkObject.h:60
WidgetContainerType Widget
Definition: vtkWidgetSet.h:147
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Definition: vtkWidgetSet.h:153
vtkstd::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:144
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:111
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:145
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:146
virtual void PrintSelf(ostream &os, vtkIndent indent)
a simple class to control print indentation
Definition: vtkIndent.h:37
#define VTK_WIDGETS_EXPORT
define the API for widget / widget representation
static vtkObject * New()