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
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.
106template< class TWidget > struct ActionFunction
107{
108 typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
109};
110
111class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
112{
113public:
117 static vtkWidgetSet *New();
118
120
123 vtkTypeMacro(vtkWidgetSet,vtkObject);
124 void PrintSelf(ostream& os, vtkIndent indent);
126
128
131 virtual void SetEnabled(int);
132 vtkBooleanMacro(Enabled, int);
134
139
144
148 unsigned int GetNumberOfWidgets();
149
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;
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
193protected:
196
197private:
198 vtkWidgetSet(const vtkWidgetSet&) VTK_DELETE_FUNCTION;
199 void operator=(const vtkWidgetSet&) VTK_DELETE_FUNCTION;
200};
201
202#endif
203
define the API for widget / widget representation
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:112
void AddWidget(vtkAbstractWidget *)
Add a widget to the set.
WidgetContainerType Widget
Definition: vtkWidgetSet.h:160
virtual void SetEnabled(int)
Method for activating and deactivating all widgets in the group.
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:157
static vtkWidgetSet * New()
Instantiate this class.
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:168
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:159
unsigned int GetNumberOfWidgets()
Get number of widgets in the set.
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:158
vtkAbstractWidget * GetNthWidget(unsigned int)
Get the Nth widget in the set.
void RemoveWidget(vtkAbstractWidget *)
Remove a widget from the set.
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:108
vtkBooleanMacro(IgnoreDriverBugs, bool)
Updates the extensions string.