KWWidgets
|
00001 /*========================================================================= 00002 00003 Copyright (c) 1998-2003 Kitware Inc. 469 Clifton Corporate Parkway, 00004 Clifton Park, NY, 12065, USA. 00005 00006 All rights reserved. No part of this software may be reproduced, distributed, 00007 or modified, in any form or by any means, without permission in writing from 00008 Kitware Inc. 00009 00010 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR 00011 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00012 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF, 00013 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00014 00015 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, 00016 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 00017 PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN 00018 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 00019 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 00020 00021 =========================================================================*/ 00022 // .NAME vtkKWSelectionFrameLayoutManager - a MxN layout manager for a set of vtkKWSelectionFrame 00023 // .SECTION Description 00024 // This class is a layout manager for vtkKWSelectionFrame. It will grid them 00025 // according to a given MxN resolution, allocate new ones, handle 00026 // print/screenshots, etc. 00027 // Note that the selection frame can be given any position, the resolution 00028 // and the origin of the layout manager are actually the parameters that 00029 // specify which one are visible. For example, one can set 4 widgets on 00030 // a 2x2 grid, set the resolution to 1x1, but set the origin at (0,0) or 00031 // (1,1) to zoom on a specific widget. 00032 00033 #ifndef __vtkKWSelectionFrameLayoutManager_h 00034 #define __vtkKWSelectionFrameLayoutManager_h 00035 00036 #include "vtkKWCompositeWidget.h" 00037 00038 class vtkKWSelectionFrame; 00039 class vtkKWSelectionFrameLayoutManagerInternals; 00040 class vtkKWRenderWidget; 00041 class vtkImageData; 00042 class vtkKWMenu; 00043 class vtkKWToolbar; 00044 class vtkKWFrame; 00045 00046 class KWWidgets_EXPORT vtkKWSelectionFrameLayoutManager : public vtkKWCompositeWidget 00047 { 00048 public: 00049 static vtkKWSelectionFrameLayoutManager* New(); 00050 vtkTypeRevisionMacro(vtkKWSelectionFrameLayoutManager, vtkKWCompositeWidget); 00051 void PrintSelf(ostream& os, vtkIndent indent); 00052 00053 // Description: 00054 // Set/Get the resolution of the layout (number of columns, number of rows). 00055 virtual void SetResolution(int nb_cols, int nb_rows); 00056 virtual void SetResolution(int res[2]) 00057 { this->SetResolution(res[0], res[1]); }; 00058 vtkGetVector2Macro(Resolution, int); 00059 00060 // Description: 00061 // Set/Get the origin of the layout (column, row), i.e. where to start 00062 // displaying widget from in the virtual grid on which they are set. 00063 virtual void SetOrigin(int col, int row); 00064 virtual void SetOrigin(int origin[2]) 00065 { this->SetOrigin(origin[0], origin[1]); }; 00066 vtkGetVector2Macro(Origin, int); 00067 00068 // Description: 00069 // Add a new selection frame to the pool 00070 // This will call Register() on the widget (increasing its ref count). 00071 // Return 1 on success, 0 otherwise 00072 virtual int AddWidget(vtkKWSelectionFrame *widget); 00073 virtual int AddWidgetWithTagAndGroup( 00074 vtkKWSelectionFrame *widget, const char *tag, const char *group); 00075 00076 // Description: 00077 // Allocate a new selection frame and add it to the pool. 00078 // Return the allocated widget, or NULL on error 00079 virtual vtkKWSelectionFrame* AllocateAndAddWidget(); 00080 00081 // Description: 00082 // Set the widget's tag in the pool. 00083 // This provide an alternate way of accessing the widget in the pool. 00084 // Note that this is *not* the title of the frame, as set using the 00085 // vtkKWSelectionFrame::SetTitle method. 00086 // If several widgets have the same tag, the first one is usually 00087 // retrieved. No constraints is put on the uniqueness of the tag. 00088 // Return 1 on success, 0 on error 00089 virtual int SetWidgetTag(vtkKWSelectionFrame*, const char *tag); 00090 virtual const char* GetWidgetTag(vtkKWSelectionFrame*); 00091 00092 // Description: 00093 // Set the widget's group in the pool. 00094 // This provide an way of grouping widgets logicaly in the pool. 00095 // Return 1 on success, 0 on error 00096 virtual int SetWidgetGroup(vtkKWSelectionFrame*, const char *group); 00097 virtual const char* GetWidgetGroup(vtkKWSelectionFrame*); 00098 00099 // Description: 00100 // Get the number of widgets in the pool 00101 virtual int GetNumberOfWidgets(); 00102 virtual int GetNumberOfWidgetsWithTag(const char *tag); 00103 virtual int GetNumberOfWidgetsWithGroup(const char *group); 00104 00105 // Description: 00106 // Query if widget is in the pool 00107 virtual int HasWidget(vtkKWSelectionFrame *widget); 00108 virtual int HasWidgetWithTag(const char *tag); 00109 virtual int HasWidgetWithTagAndGroup(const char *tag, const char *group); 00110 00111 // Description: 00112 // Retrieve a widget given its tag (as set using SetWidgetTag()), its 00113 // tag and group, its title (as set using vtkKWSelectionFrame::SetTitle), 00114 // its rank in the pool (n-th widget), or its rank (n-th widget) but not 00115 // matching another widget 'avoid'. 00116 // Return the widget, or NULL if not found 00117 virtual vtkKWSelectionFrame* GetWidgetWithTag(const char *tag); 00118 virtual vtkKWSelectionFrame* GetWidgetWithTagAndGroup( 00119 const char *tag, const char *group); 00120 virtual vtkKWSelectionFrame* GetWidgetWithTitle(const char *title); 00121 virtual vtkKWSelectionFrame* GetNthWidget(int index); 00122 virtual vtkKWSelectionFrame* GetNthWidgetNotMatching( 00123 int index, vtkKWSelectionFrame *avoid); 00124 virtual vtkKWSelectionFrame* GetNthWidgetWithGroup( 00125 int index, const char *group); 00126 00127 // Description: 00128 // Set/Get position of widget. 00129 // Note that the position is independent of the resolution, you can 00130 // still set the position of a widget anywhere while displaying only 00131 // a subset of the largest grid encompassing all widgets (i.e. you can 00132 // set a widget at (2, 3), i.e. third column, fourth row, but set the 00133 // resolution to (1, 1) to display only the first column and first row: the 00134 // next time the resolution is set to, say, (4, 4), the widget at (2, 3) 00135 // will be shown). 00136 // Changing the position of a widget will repack the layout (call to Pack()). 00137 // If you need to change the position of a lot of widgets without repacking 00138 // each time, try SetImmediateWidgetPosition(), and Pack(). 00139 // Return 1 (or widget) on success (and if the position was really changed), 00140 // 0 (or NULL) on error. 00141 virtual int GetWidgetPosition(vtkKWSelectionFrame *w, int *col, int *row); 00142 virtual int GetWidgetPosition(vtkKWSelectionFrame *w, int pos[2]) 00143 { return this->GetWidgetPosition(w, pos, pos + 1); } 00144 virtual int SetWidgetPosition(vtkKWSelectionFrame *w, int col, int row); 00145 virtual int SetWidgetPosition(vtkKWSelectionFrame *w, int pos[2]) 00146 { return this->SetWidgetPosition(w, pos[0], pos[1]); } 00147 virtual vtkKWSelectionFrame* GetWidgetAtPosition(int col, int row); 00148 virtual vtkKWSelectionFrame* GetWidgetAtPosition(int pos[2]) 00149 { return this->GetWidgetAtPosition(pos[0], pos[1]); } 00150 00151 // Description: 00152 // Switch widgets position (set the position of two widgets) 00153 // Return 1 (or widget) on success, 0 (or NULL) on error 00154 virtual int SwitchWidgetsPosition( 00155 vtkKWSelectionFrame *w1, vtkKWSelectionFrame *w2); 00156 00157 // Description: 00158 // Reorganize the widgets position automatically (for example, to try 00159 // to avoid empty spaces). 00160 vtkBooleanMacro(ReorganizeWidgetPositionsAutomatically, int); 00161 virtual void SetReorganizeWidgetPositionsAutomatically(int); 00162 vtkGetMacro(ReorganizeWidgetPositionsAutomatically, int); 00163 00164 // Description: 00165 // Set/Get the maximum resolution of the layout 00166 // (number of columns, number of rows). 00167 virtual void SetMaximumResolution(int nb_cols, int nb_rows); 00168 virtual void SetMaximumResolution(int res[2]) 00169 { this->SetMaximumResolution(res[0], res[1]); }; 00170 vtkGetVector2Macro(MaximumResolution, int); 00171 00172 // Description: 00173 // Return if a specific widget is visible at this point, i.e. mapped 00174 // on screen at a specific position given the current resolution. 00175 virtual int GetWidgetVisibility(vtkKWSelectionFrame *w); 00176 00177 // Description: 00178 // Check if a widget is maximized, i.e. at position (0,0) in a (1,1) 00179 // resolution. Maximize it (this will save the old resolution and position) 00180 // or undo maximize (this will restore old resolution and position). 00181 // Toggle maximize will maximize if widget is not maximized already or undo 00182 // the maximize 00183 // Return 1 on success, 0 on error 00184 virtual int IsWidgetMaximized(vtkKWSelectionFrame *w); 00185 virtual int MaximizeWidget(vtkKWSelectionFrame *w); 00186 virtual int UndoMaximizeWidget(); 00187 virtual int ToggleMaximizeWidget(vtkKWSelectionFrame *w); 00188 00189 // Description: 00190 // Select a a widget. 00191 // If arg is NULL, nothing is selected (all others are deselected) 00192 virtual void SelectWidget(vtkKWSelectionFrame *widget); 00193 00194 // Description: 00195 // Get the selected widget. 00196 // Return the widget, or NULL if none is selected 00197 virtual vtkKWSelectionFrame* GetSelectedWidget(); 00198 00199 // Description: 00200 // Specifies a command to associate with the widget. This command is 00201 // typically invoked when the selection is changed. 00202 // The 'object' argument is the object that will have the method called on 00203 // it. The 'method' argument is the name of the method to be called and any 00204 // arguments in string form. If the object is NULL, the method is still 00205 // evaluated as a simple command. 00206 virtual void SetSelectionChangedCommand( 00207 vtkObject *object, const char *method); 00208 vtkGetStringMacro(SelectionChangedCommand); 00209 00210 // Description: 00211 // Remove a widget, or all of them, or all of the widgets in a group. 00212 // This will call each widget's Close() method, and UnRegister() it. 00213 // Return 1 on success, 0 on error 00214 virtual int RemoveWidget(vtkKWSelectionFrame *widget); 00215 virtual int RemoveAllWidgets(); 00216 virtual int RemoveAllWidgetsWithGroup(const char *group); 00217 00218 // Description: 00219 // Try to show all the widgets belonging to a specific group. 00220 // This method will check if the visible widgets belong to the group, 00221 // and exchange change if this is not the case. 00222 // Return 1 on success, 0 on error 00223 virtual int ShowWidgetsWithGroup(const char *group); 00224 00225 // Description: 00226 // Save all widgets into an image (as a screenshot) or into the 00227 // clipboard (win32). If no filename, the user is prompted for one 00228 // (provided that this widget is part of a window). 00229 // Return 1 on success, 0 otherwise 00230 // GetRenderWidget() need to be implemented accordingly. 00231 virtual int SaveScreenshotAllWidgets(); 00232 virtual int SaveScreenshotAllWidgetsToFile(const char* fileName); 00233 virtual int CopyScreenshotAllWidgetsToClipboard(); 00234 00235 // Description: 00236 // Append widgets to image data. 00237 // The 'Fast' version of each method does not set the render widget to 00238 // Offscreen rendering (unless OnScreenRendering is 1) 00239 // and re-render them, the backbuffer of the render widget is taken as-is 00240 // (this is useful for lower quality screenshot or thumbnails). 00241 // Return 1 on success, 0 otherwise 00242 // GetRenderWidget() need to be implemented accordingly. 00243 virtual int AppendAllWidgetsToImageData(vtkImageData *image, 00244 int OnScreenRendering = 0); 00245 virtual int AppendAllWidgetsToImageDataFast(vtkImageData *image); 00246 virtual int AppendSelectedWidgetToImageData(vtkImageData *image); 00247 virtual int AppendSelectedWidgetToImageDataFast(vtkImageData *image); 00248 00249 // Description: 00250 // Use the alpha channel in screenshots (which will save a transparent 00251 // image). 00252 vtkBooleanMacro(UseAlphaChannelInScreenshot, int); 00253 vtkGetMacro(UseAlphaChannelInScreenshot, int); 00254 vtkSetMacro(UseAlphaChannelInScreenshot, int); 00255 00256 // Description: 00257 // Print all widgets or the selected one. 00258 // If no DPI is provided, the DPI settings of the Window ivar is used. 00259 // Return 1 on success, 0 otherwise 00260 // GetRenderWidget() need to be implemented accordingly. 00261 virtual int PrintAllWidgets(); 00262 virtual int PrintAllWidgetsAtResolution(double dpi); 00263 virtual int PrintSelectedWidget(); 00264 virtual int PrintSelectedWidgetAtResolution(double dpi); 00265 00266 // Description: 00267 // Create a resolution entries menu (specifies its parent). 00268 // Get the menu (so that it can be added as a cascade). 00269 // Update the menu entries state, given the number of widgets. 00270 // If the resolution is changed using a menu entry, a 00271 // ResolutionChangedEvent event is sent. 00272 virtual void CreateResolutionEntriesMenu(vtkKWMenu *parent); 00273 vtkGetObjectMacro(ResolutionEntriesMenu, vtkKWMenu); 00274 virtual void UpdateResolutionEntriesMenu(); 00275 00276 // Description: 00277 // Create a resolution entries toolbar (specifies its parent). 00278 // Get the toolbar. 00279 // Update the menu entries state, given the number of widgets. 00280 // If the resolution is changed using a toolbar button, a 00281 // ResolutionChangedEvent event is sent. 00282 virtual void CreateResolutionEntriesToolbar(vtkKWWidget *parent); 00283 vtkGetObjectMacro(ResolutionEntriesToolbar, vtkKWToolbar); 00284 virtual void UpdateResolutionEntriesToolbar(); 00285 00286 // Description: 00287 // Events. The SelectionChangedEvent is triggered when the selection 00288 // is changed. It is similar in concept as the 'SelectionChangedCommand' 00289 // callbacks but can be used by multiple listeners/observers at a time. 00290 //BTX 00291 enum 00292 { 00293 SelectionChangedEvent = 10000, 00294 ResolutionChangedEvent 00295 }; 00296 //ETX 00297 00298 // Description: 00299 // The command is invoked when the user double-clicks on the layout frame, 00300 // i.e. any region of the frame that is not occupied by one selection frame. 00301 virtual void SetDoubleClickOnLayoutFrameCommand( 00302 vtkObject *object, const char *method); 00303 00304 // Description: 00305 // Update the "enable" state of the object and its internal parts. 00306 // Depending on different Ivars (this->Enabled, the application's 00307 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00308 // and propagated to its internal parts/subwidgets. This will, for example, 00309 // enable/disable parts of the widget UI, enable/disable the visibility 00310 // of 3D widgets, etc. 00311 virtual void UpdateEnableState(); 00312 00313 // Description: 00314 // Update the selection lists 00315 virtual void UpdateSelectionLists(); 00316 00317 // Description: 00318 // Callbacks. Internal, do not use. 00319 virtual void SelectWidgetCallback(vtkKWSelectionFrame*); 00320 virtual void SelectAndMaximizeWidgetCallback(vtkKWSelectionFrame*); 00321 virtual void CloseWidgetCallback(vtkKWSelectionFrame*); 00322 virtual int ChangeWidgetTitleCallback(vtkKWSelectionFrame*); 00323 virtual void WidgetTitleChangedCallback(vtkKWSelectionFrame*); 00324 virtual void SwitchWidgetCallback( 00325 const char *title, vtkKWSelectionFrame *widget); 00326 virtual void ResolutionCallback(int i, int j); 00327 virtual void NumberOfWidgetsHasChangedCallback(); 00328 virtual void DoubleClickOnLayoutFrameCallback(); 00329 00330 // Description: 00331 // Pack all widgets. You shouldn't have to call this method, as it is called 00332 // automatically each time the position of a widget is changed through 00333 // SetWidgetPosition, or the resolution/origin is changed, or a widget 00334 // is added. But sometimes you may want to trigger packing yourself if 00335 // you need to set the positions of a lot of widgets simultaneously through 00336 // SetImmediateWidgetPosition. 00337 virtual void Pack(); 00338 00339 // Description: 00340 // Set the widget position without repacking. 00341 // Return 1 if the position was changed, 0 otherwise. 00342 virtual int SetImmediateWidgetPosition(vtkKWSelectionFrame *w, int pos[2]) 00343 { return this->SetImmediateWidgetPosition(w, pos[0], pos[1]); } 00344 virtual int SetImmediateWidgetPosition( 00345 vtkKWSelectionFrame *w, int col, int row); 00346 00347 // Description: 00348 // Adjust the resolution so that all widgets are shown 00349 virtual void AdjustResolution(); 00350 00351 // Description: 00352 // Set resolution and origin at the same time, to minimize redraw 00353 virtual void SetResolutionAndOrigin(int res[2], int origin[2]) 00354 { this->SetResolutionAndOrigin(res[0], res[1], origin[0], origin[1]); }; 00355 virtual void SetResolutionAndOrigin( 00356 int nb_cols, int nb_rows, int col, int row); 00357 00358 protected: 00359 vtkKWSelectionFrameLayoutManager(); 00360 ~vtkKWSelectionFrameLayoutManager(); 00361 00362 // Description: 00363 // Get if a specific position is inside the layout defined by the 00364 // current resolution and origin. 00365 virtual int IsPositionInLayout(int col, int row); 00366 virtual int IsPositionInLayout(int pos[2]) 00367 { return this->IsPositionInLayout(pos[0], pos[1]); }; 00368 00369 // Description: 00370 // Create the widget. 00371 virtual void CreateWidget(); 00372 00373 int Resolution[2]; 00374 int MaximumResolution[2]; 00375 int Origin[2]; 00376 int ReorganizeWidgetPositionsAutomatically; 00377 int UseAlphaChannelInScreenshot; 00378 00379 vtkKWMenu *ResolutionEntriesMenu; 00380 vtkKWToolbar *ResolutionEntriesToolbar; 00381 00382 virtual void InvokeSelectionChangedCommand(); 00383 char *SelectionChangedCommand; 00384 00385 char *DoubleClickOnLayoutFrameCommand; 00386 virtual void InvokeDoubleClickOnLayoutFrameCommand(); 00387 00388 vtkKWFrame *LayoutFrame; 00389 00390 // Description: 00391 // Allocate a new widget. 00392 virtual vtkKWSelectionFrame* AllocateWidget(); 00393 00394 // Description: 00395 // Create a widget (i.e., create the underlying Tk widget) and configure it. 00396 // If the layout manager has not been created, the widget won't be 00397 // created either, since it is used as parent. 00398 virtual void CreateWidget(vtkKWSelectionFrame*); 00399 virtual void ConfigureWidget(vtkKWSelectionFrame*); 00400 00401 // Description: 00402 // Get the render widget (if any) associated to the selection 00403 // frame at that point. 00404 // Used to Print, Save/Copy screenshot, etc. 00405 // This should be reimplemented by subclasses. 00406 // This implementation searches for a vtkKWRenderWidget in the children 00407 // of the frame. 00408 virtual vtkKWRenderWidget* GetRenderWidget(vtkKWSelectionFrame*); 00409 00410 // Description: 00411 // Print widgets (if selection_only is true, only the selected 00412 // widget is printed, otherwise all of them). 00413 // Return 1 on success, 0 otherwise 00414 virtual int PrintWidgets(double dpi, int selection_only); 00415 00416 // Description: 00417 // Append dataset widgets to image data. 00418 // If selection_only is true, onlythe selected dataset widget is printed, 00419 // otherwise all of them. If direct is true, the renderwidgets are not 00420 // set to Offscreen rendering and re-rendered, the backbuffer of the 00421 // window is taken as-is (this is useful for lower quality screenshot or 00422 // thumbnails). 00423 // If direct is true and ForceUpdateOnScreenRendering is 1, the render 00424 // widgets are forcibly re-rendererd prior to grabbing the screenshot. 00425 // Return 1 on success, 0 otherwise 00426 virtual int AppendWidgetsToImageData( 00427 vtkImageData *image,int selection_only, int direct = 0, 00428 int ForceUpdateOnScreenRendering = 0); 00429 00430 // Description: 00431 // Called when the number of widgets has changed 00432 virtual void NumberOfWidgetsHasChanged(); 00433 virtual void ScheduleNumberOfWidgetsHasChanged(); 00434 00435 // Description: 00436 // Reorganize positions of widgets so that the grid defined 00437 // by the current resolution is filled. 00438 // Return the number of reorganized widgets (number of widgets which 00439 // position was changed). 00440 virtual int ReorganizeWidgetPositions(); 00441 00442 // Description: 00443 // Can a given widget's title be changed to a new one 00444 // It is used by ChangeWidgetTitleCallback and is likely to be overriden 00445 // in subclasses. 00446 virtual int CanWidgetTitleBeChanged( 00447 vtkKWSelectionFrame *widget, const char *new_title); 00448 00449 // PIMPL Encapsulation for STL containers 00450 00451 vtkKWSelectionFrameLayoutManagerInternals *Internals; 00452 00453 // Description: 00454 // Add/Remove callbacks on a selection frame 00455 virtual void AddCallbacksToWidget(vtkKWSelectionFrame *widget); 00456 virtual void RemoveCallbacksFromWidget(vtkKWSelectionFrame *widget); 00457 00458 // Description: 00459 // Delete a widget, i.e. Close and UnRegister it. Internal use only, as 00460 // a helper to the public RemoveWidget methods. 00461 virtual void DeleteWidget(vtkKWSelectionFrame *widget); 00462 00463 // Description: 00464 // Automatically move the selection inside the visible layout, i.e. if 00465 // the selected widget is not visible, select a visible one. 00466 // If pos_hint is non-null, use it as a hint regarding where the most 00467 // likely selection could be (array of 2 ints). 00468 virtual void MoveSelectionInsideVisibleLayout(int *pos_hint); 00469 00470 // Description: 00471 // Push/Pop resolutions or origins on a stack 00472 // Is used by the maximize/minimize code. 00473 virtual int PushResolution(int nb_cols, int nb_rows); 00474 virtual int PushResolution(int res[2]) 00475 { return this->PushResolution(res[0], res[1]); }; 00476 virtual int PopResolution(int *nb_cols, int *nb_rows); 00477 virtual int PopResolution(int res[2]) 00478 { return this->PopResolution(&res[0], &res[1]); }; 00479 virtual int PushPosition(int col, int row); 00480 virtual int PushPosition(int origin[2]) 00481 { return this->PushPosition(origin[0], origin[1]); }; 00482 virtual int PopPosition(int *col, int *row); 00483 virtual int PopPosition(int origin[2]) 00484 { return this->PopPosition(&origin[0], &origin[1]); }; 00485 00486 // Description: 00487 // Save/Restore layout before maximize/minimize. 00488 // Return 1 on success, 0 otherwise 00489 virtual int SaveLayoutBeforeMaximize(); 00490 virtual int RestoreLayoutBeforeMaximize(); 00491 00492 private: 00493 00494 vtkKWSelectionFrameLayoutManager(const vtkKWSelectionFrameLayoutManager&); // Not implemented 00495 void operator=(const vtkKWSelectionFrameLayoutManager&); // Not implemented 00496 }; 00497 00498 #endif