VTK  9.3.20240328
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>
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 
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 
183 protected:
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
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:161
Synchronize a collection on vtkWidgets drawn on different renderwindows using the Callback - Dispatch...
Definition: vtkWidgetSet.h:103
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
Definition: vtkWidgetSet.h:148
~vtkWidgetSet() override
WidgetContainerType Widget
Definition: vtkWidgetSet.h:151
vtkAbstractWidget * GetNthWidget(unsigned int)
Get the Nth widget in the set.
void DispatchAction(TWidget *caller, typename ActionFunction< TWidget >::TActionFunctionPointer action)
Dispatch an "Action" to every widget in this set.
Definition: vtkWidgetSet.h:159
WidgetContainerType::const_iterator WidgetConstIteratorType
Definition: vtkWidgetSet.h:150
unsigned int GetNumberOfWidgets()
Get number of widgets in the set.
static vtkWidgetSet * New()
Instantiate this class.
WidgetContainerType::iterator WidgetIteratorType
Definition: vtkWidgetSet.h:149
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for a VTK class.
void RemoveWidget(vtkAbstractWidget *)
Remove a widget from the set.
void(TWidget::* TActionFunctionPointer)(TWidget *dispatcher)
Definition: vtkWidgetSet.h:99
int vtkTypeBool
Definition: vtkABI.h:64