VTK
dox/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 "vtkObject.h"
00097 #include <vector> // Required for vector
00098 
00099 class vtkAbstractWidget;
00100 
00101 //BTX
00102 // Pointer to a member function that takes a vtkAbstractWidget (the active
00103 // child) and another vtkAbstractWidget (the widget to dispatch an action)
00104 // to. All "Action" functions in a widget must conform to this signature.
00105 template< class TWidget > struct ActionFunction
00106 {
00107   typedef void (TWidget::*TActionFunctionPointer)(TWidget *dispatcher);
00108 };
00109 //ETX
00110 
00111 class VTK_WIDGETS_EXPORT vtkWidgetSet : public vtkObject
00112 {
00113 public:
00115   static vtkWidgetSet *New();
00116 
00118 
00119   vtkTypeMacro(vtkWidgetSet,vtkObject);
00120   void PrintSelf(ostream& os, vtkIndent indent);
00122 
00124 
00125   virtual void SetEnabled(int);
00126   vtkBooleanMacro(Enabled, int);
00128 
00130   void AddWidget(vtkAbstractWidget *);
00131 
00133   void RemoveWidget(vtkAbstractWidget *);
00134 
00136   unsigned int GetNumberOfWidgets();
00137 
00139   vtkAbstractWidget *GetNthWidget( unsigned int );
00140 
00141   //BTX
00142   // TODO: Move this to the protected section. The class vtkAbstractWidget 
00143   //       should be a friend of this class. 
00144   typedef std::vector< vtkAbstractWidget * >   WidgetContainerType;
00145   typedef WidgetContainerType::iterator           WidgetIteratorType;
00146   typedef WidgetContainerType::const_iterator     WidgetConstIteratorType;
00147   WidgetContainerType                             Widget;
00148  
00150 
00152   template < class TWidget >
00153   void DispatchAction(TWidget *caller, 
00154                       typename ActionFunction< TWidget >::TActionFunctionPointer action)
00155     {
00156     // Dispatch action to the caller first.
00157     for (WidgetIteratorType it  = this->Widget.begin(); 
00158                             it != this->Widget.end()  ; ++it)
00159       {
00160       TWidget *w = static_cast<TWidget *>(*it);
00161       if (caller == w)
00162         {
00163         ((*w).*(action))(caller); 
00164         break;
00165         }
00166       }
00168     
00169     // Dispatch action to all other widgets
00170     for (WidgetIteratorType it  = this->Widget.begin(); 
00171                             it != this->Widget.end()  ; ++it)
00172       {
00173       TWidget *w = static_cast<TWidget *>(*it);
00174       if (caller != w) ((*w).*(action))(caller);
00175       }
00176     }
00177   //ETX
00178 
00179 protected:
00180   vtkWidgetSet();
00181   ~vtkWidgetSet();
00182 
00183 private:
00184   vtkWidgetSet(const vtkWidgetSet&);  //Not implemented
00185   void operator=(const vtkWidgetSet&);  //Not implemented
00186 };
00187 
00188 #endif
00189