VTK
dox/Interaction/Widgets/vtkWidgetSet.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkWidgetSet.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00093 #ifndef __vtkWidgetSet_h
00094 #define __vtkWidgetSet_h
00095 
00096 #include "vtkInteractionWidgetsModule.h" // For export macro
00097 #include "vtkObject.h"
00098 #include <vector> // Required for vector
00099 
00100 class vtkAbstractWidget;
00101 
00102 //BTX
00103 // Pointer to a member function that takes a vtkAbstractWidget (the active
00104 // child) and another vtkAbstractWidget (the widget to dispatch an action)
00105 // to. All "Action" functions in a widget must conform to this signature.
00106 template< class TWidget > struct ActionFunction
00107 {
00108   typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
00109 };
00110 //ETX
00111 
00112 class VTKINTERACTIONWIDGETS_EXPORT vtkWidgetSet : public vtkObject
00113 {
00114 public:
00116   static vtkWidgetSet *New();
00117 
00119 
00120   vtkTypeMacro(vtkWidgetSet,vtkObject);
00121   void PrintSelf(ostream& os, vtkIndent indent);
00123 
00125 
00126   virtual void SetEnabled(int);
00127   vtkBooleanMacro(Enabled, int);
00129 
00131   void AddWidget(vtkAbstractWidget *);
00132 
00134   void RemoveWidget(vtkAbstractWidget *);
00135 
00137   unsigned int GetNumberOfWidgets();
00138 
00140   vtkAbstractWidget *GetNthWidget( unsigned int );
00141 
00142   //BTX
00143   // TODO: Move this to the protected section. The class vtkAbstractWidget
00144   //       should be a friend of this class.
00145   typedef std::vector< vtkAbstractWidget * >   WidgetContainerType;
00146   typedef WidgetContainerType::iterator           WidgetIteratorType;
00147   typedef WidgetContainerType::const_iterator     WidgetConstIteratorType;
00148   WidgetContainerType                             Widget;
00149 
00151 
00153   template < class TWidget >
00154   void DispatchAction(TWidget *caller,
00155                       typename ActionFunction< TWidget >::TActionFunctionPointer action)
00156     {
00157     // Dispatch action to the caller first.
00158     for (WidgetIteratorType it  = this->Widget.begin();
00159                             it != this->Widget.end()  ; ++it)
00160       {
00161       TWidget *w = static_cast<TWidget *>(*it);
00162       if (caller == w)
00163         {
00164         ((*w).*(action))(caller);
00165         break;
00166         }
00167       }
00169 
00170     // Dispatch action to all other widgets
00171     for (WidgetIteratorType it  = this->Widget.begin();
00172                             it != this->Widget.end()  ; ++it)
00173       {
00174       TWidget *w = static_cast<TWidget *>(*it);
00175       if (caller != w) ((*w).*(action))(caller);
00176       }
00177     }
00178   //ETX
00179 
00180 protected:
00181   vtkWidgetSet();
00182   ~vtkWidgetSet();
00183 
00184 private:
00185   vtkWidgetSet(const vtkWidgetSet&);  //Not implemented
00186   void operator=(const vtkWidgetSet&);  //Not implemented
00187 };
00188 
00189 #endif
00190