VTK  9.3.20240424
vtkWidgetSet.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
83#ifndef vtkWidgetSet_h
84#define vtkWidgetSet_h
85
86#include "vtkInteractionWidgetsModule.h" // For export macro
87#include "vtkObject.h"
88#include <vector> // Required for vector
89
90VTK_ABI_NAMESPACE_BEGIN
92
93// Pointer to a member function that takes a vtkAbstractWidget (the active
94// child) and another vtkAbstractWidget (the widget to dispatch an action)
95// to. All "Action" functions in a widget must conform to this signature.
96template <class TWidget>
98{
99 typedef void (TWidget::*TActionFunctionPointer)(TWidget* dispatcher);
100};
101
102class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
103{
104public:
108 static vtkWidgetSet* New();
109
111
114 vtkTypeMacro(vtkWidgetSet, vtkObject);
115 void PrintSelf(ostream& os, vtkIndent indent) override;
117
119
122 virtual void SetEnabled(vtkTypeBool);
123 vtkBooleanMacro(Enabled, vtkTypeBool);
125
130
135
139 unsigned int GetNumberOfWidgets();
140
145
146 // TODO: Move this to the protected section. The class vtkAbstractWidget
147 // should be a friend of this class.
148 typedef std::vector<vtkAbstractWidget*> WidgetContainerType;
149 typedef WidgetContainerType::iterator WidgetIteratorType;
150 typedef WidgetContainerType::const_iterator WidgetConstIteratorType;
152
154
158 template <class TWidget>
160 TWidget* caller, typename ActionFunction<TWidget>::TActionFunctionPointer action)
161 {
162 // Dispatch action to the caller first.
163 for (WidgetIteratorType it = this->Widget.begin(); it != this->Widget.end(); ++it)
164 {
165 TWidget* w = static_cast<TWidget*>(*it);
166 if (caller == w)
167 {
168 ((*w).*(action))(caller);
169 break;
170 }
171 }
173
174 // Dispatch action to all other widgets
175 for (WidgetIteratorType it = this->Widget.begin(); it != this->Widget.end(); ++it)
176 {
177 TWidget* w = static_cast<TWidget*>(*it);
178 if (caller != w)
179 ((*w).*(action))(caller);
180 }
181 }
182
183protected:
185 ~vtkWidgetSet() override;
186
187private:
188 vtkWidgetSet(const vtkWidgetSet&) = delete;
189 void operator=(const vtkWidgetSet&) = delete;
190};
191
192VTK_ABI_NAMESPACE_END
193#endif
define the API for widget / widget representation
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
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
~vtkWidgetSet() override
WidgetContainerType Widget
static vtkWidgetSet * New()
Instantiate this class.
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
WidgetContainerType::const_iterator WidgetConstIteratorType
unsigned int GetNumberOfWidgets()
Get number of widgets in the set.
WidgetContainerType::iterator WidgetIteratorType
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for a VTK class.
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)
int vtkTypeBool
Definition vtkABI.h:64