VTK: Interaction/Widgets/vtkWidgetSet.h Source File

| VTK 9.3.1

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
90 VTK_ABI_NAMESPACE_BEGIN
91 class vtkAbstractWidget;
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.
96 template <class TWidget>
97 struct ActionFunction
98 {
99 typedef void (TWidget::*TActionFunctionPointer)(TWidget* dispatcher);
100 };
101
102 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
103 {
104 public:
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
129 void AddWidget(vtkAbstractWidget*);
130
134 void RemoveWidget(vtkAbstractWidget*);
135
139 unsigned int GetNumberOfWidgets();
140
144 vtkAbstractWidget* GetNthWidget(unsigned int);
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;
151 WidgetContainerType Widget;
152
154
158 template <class TWidget>
159 void DispatchAction(
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
183 protected:
184 vtkWidgetSet();
185 ~vtkWidgetSet() override;
186
187 private:
188 vtkWidgetSet(const vtkWidgetSet&) = delete;
189 void operator=(const vtkWidgetSet&) = delete;
190 };
191
192 VTK_ABI_NAMESPACE_END
193 #endif
vtkAbstractWidget
define the API for widget / widget representation
Definition: vtkAbstractWidget.h:64
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:61
vtkWidgetSet
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:103
vtkWidgetSet::SetEnabled
virtual void SetEnabled(vtkTypeBool)
Method for activating and deactivating all widgets in the group.
vtkWidgetSet::AddWidget
void AddWidget(vtkAbstractWidget *)
Add a widget to the set.
vtkWidgetSet::WidgetContainerType
std::vector< vtkAbstractWidget * > WidgetContainerType
Definition: vtkWidgetSet.h:148
vtkWidgetSet::~vtkWidgetSet
~vtkWidgetSet() override
vtkWidgetSet::Widget
WidgetContainerType Widget
Definition: vtkWidgetSet.h:151
vtkWidgetSet::GetNthWidget
vtkAbstractWidget * GetNthWidget(unsigned int)
Get the Nth widget in the set.
vtkWidgetSet::DispatchAction
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:159
vtkWidgetSet::WidgetConstIteratorType
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:150
vtkWidgetSet::GetNumberOfWidgets
unsigned int GetNumberOfWidgets()
Get number of widgets in the set.
vtkWidgetSet::vtkWidgetSet
vtkWidgetSet()
vtkWidgetSet::New
static vtkWidgetSet * New()
Instantiate this class.
vtkWidgetSet::WidgetIteratorType
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:149
vtkWidgetSet::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for a VTK class.
vtkWidgetSet::RemoveWidget
void RemoveWidget(vtkAbstractWidget *)
Remove a widget from the set.
ActionFunction
Definition: vtkWidgetSet.h:98
ActionFunction::TActionFunctionPointer
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:99
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:64
vtkObject.h