00001 //============================================================================= 00002 // This file is part of VTKEdge. See vtkedge.org for more information. 00003 // 00004 // Copyright (c) 2010 Kitware, Inc. 00005 // 00006 // VTKEdge may be used under the terms of the BSD License 00007 // Please see the file Copyright.txt in the root directory of 00008 // VTKEdge for further information. 00009 // 00010 // Alternatively, you may see: 00011 // 00012 // http://www.vtkedge.org/vtkedge/project/license.html 00013 // 00014 // 00015 // For custom extensions, consulting services, or training for 00016 // this or any other Kitware supported open source project, please 00017 // contact Kitware at sales@kitware.com. 00018 // 00019 // 00020 //============================================================================= 00102 #ifndef __vtkKWEWidgetGroup_h 00103 #define __vtkKWEWidgetGroup_h 00104 00105 #include "VTKEdgeConfigure.h" // needed for export symbols directives 00106 #include "vtkObject.h" 00107 #include <vtkstd/vector> 00108 00109 class vtkAbstractWidget; 00110 00111 class VTKEdge_WIDGETS_EXPORT vtkKWEWidgetGroup : public vtkObject 00112 { 00113 public: 00115 static vtkKWEWidgetGroup *New(); 00116 00118 00119 vtkTypeRevisionMacro(vtkKWEWidgetGroup,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 vtkstd::vector< vtkAbstractWidget * > WidgetContainerType; 00145 typedef WidgetContainerType::iterator WidgetIteratorType; 00146 typedef WidgetContainerType::const_iterator WidgetConstIteratorType; 00147 WidgetContainerType Widget; 00148 00150 00156 template< class TWidget > struct ActionFunction 00157 { 00158 typedef int (TWidget::*TActionFunctionPointer)(TWidget *dispatcher); 00159 }; 00161 00163 00165 template < class TWidget > 00166 void DispatchAction(TWidget *caller, 00167 typename ActionFunction< TWidget >::TActionFunctionPointer action) 00168 { 00169 // Dispatch action to the caller first. 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) 00175 { 00176 if (((*w).*(action))(caller) == 0) return; 00177 break; 00178 } 00179 } 00181 00182 // Dispatch action to all other widgets 00183 for (WidgetIteratorType it = this->Widget.begin(); 00184 it != this->Widget.end() ; ++it) 00185 { 00186 TWidget *w = static_cast<TWidget *>(*it); 00187 if (caller != w) ((*w).*(action))(caller); 00188 } 00189 } 00190 //ETX 00191 00193 00195 virtual void Register(vtkObjectBase* o); 00196 virtual void UnRegister(vtkObjectBase* o); 00198 00200 int HasWidget( vtkAbstractWidget * ); 00201 00203 void Render(); 00204 00205 protected: 00206 vtkKWEWidgetGroup(); 00207 ~vtkKWEWidgetGroup(); 00208 00209 // We need to break reference count loops. The widgets held by us refcount us 00210 // too 00211 virtual void ReportReferences(vtkGarbageCollector* collector); 00212 00213 private: 00214 vtkKWEWidgetGroup(const vtkKWEWidgetGroup&); //Not implemented 00215 void operator=(const vtkKWEWidgetGroup&); //Not implemented 00216 }; 00217 00218 #endif 00219
1.7.1