KWWidgets
|
00001 /*========================================================================= 00002 00003 Module: $RCSfile: vtkKWRange.h,v $ 00004 00005 Copyright (c) Kitware, Inc. 00006 All rights reserved. 00007 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 // .NAME vtkKWRange - a range widget 00015 // .SECTION Description 00016 // A widget that represents a range within a bigger range. 00017 // Note: As a subclass of vtkKWWidgetWithLabel, it inherits a label and methods 00018 // to set its position and visibility. Note that the default label position 00019 // implemented in this class is on the top of the range if the range 00020 // direction is horizontal, on the left if is is vertical. Specific positions 00021 // listed in vtkKWWidgetWithLabel are supported as well. 00022 // .SECTION See Also 00023 // vtkKWWidgetWithLabel 00024 00025 #ifndef __vtkKWRange_h 00026 #define __vtkKWRange_h 00027 00028 #include "vtkKWWidgetWithLabel.h" 00029 00030 class vtkKWCanvas; 00031 class vtkKWEntry; 00032 class vtkKWFrame; 00033 class vtkKWPushButtonSet; 00034 00035 class KWWidgets_EXPORT vtkKWRange : public vtkKWWidgetWithLabel 00036 { 00037 public: 00038 static vtkKWRange* New(); 00039 vtkTypeRevisionMacro(vtkKWRange,vtkKWWidgetWithLabel); 00040 void PrintSelf(ostream& os, vtkIndent indent); 00041 00042 // Description: 00043 // Set/Get the whole range. 00044 vtkGetVector2Macro(WholeRange, double); 00045 virtual void SetWholeRange(double r0, double r1); 00046 virtual void SetWholeRange(const double range[2]) 00047 { this->SetWholeRange(range[0], range[1]); }; 00048 00049 // Description: 00050 // Set/Get the current (sub-)range. 00051 vtkGetVector2Macro(Range, double); 00052 virtual void SetRange(double r0, double r1); 00053 virtual void SetRange(const double range[2]) 00054 { this->SetRange(range[0], range[1]); }; 00055 00056 // Description: 00057 // Set/Get the current (sub-)range as relative positions in the whole range. 00058 virtual void GetRelativeRange(double &r0, double &r1); 00059 virtual void GetRelativeRange(double range[2]) 00060 { this->GetRelativeRange(range[0], range[1]); }; 00061 virtual void SetRelativeRange(double r0, double r1); 00062 virtual void SetRelativeRange(const double range[2]) 00063 { this->SetRelativeRange(range[0], range[1]); }; 00064 00065 // Description: 00066 // Set/Get the resolution of the slider. 00067 // The whole range and sub range are not snapped to this resolution. 00068 // Both ranges can be set to any floating point number. 00069 // Think of the sliders and the resolution as a way to set the bounds of 00070 // the sub range interactively using nice clean steps (power of 10 for 00071 // example). 00072 // The entries associated to the sub range can be used to set the bounds to 00073 // anything within the whole range, despite the resolution, allowing the user 00074 // to enter precise values that could not be reached given the resolution. 00075 // Of course, given a whole range of 1 to 64, if the resolution is set to 3 00076 // the slider will only snap to values ranging from 3 to 63 (within the 00077 // whole range constraint), but the entries can be used to set accurate 00078 // values out of the resolution (i.e., 1, 2... 64). 00079 virtual void SetResolution(double r); 00080 vtkGetMacro(Resolution, double); 00081 00082 // Description: 00083 // Adjust the resolution automatically (to a power of 10 in this implem) 00084 virtual void SetAdjustResolution(int); 00085 vtkBooleanMacro(AdjustResolution, int); 00086 vtkGetMacro(AdjustResolution, int); 00087 00088 // Description: 00089 // Set/Get the orientation. 00090 //BTX 00091 enum 00092 { 00093 OrientationHorizontal = 0, 00094 OrientationVertical = 1 00095 }; 00096 //ETX 00097 virtual void SetOrientation(int); 00098 vtkGetMacro(Orientation, int); 00099 virtual void SetOrientationToHorizontal() 00100 { this->SetOrientation(vtkKWRange::OrientationHorizontal); }; 00101 virtual void SetOrientationToVertical() 00102 { this->SetOrientation(vtkKWRange::OrientationVertical); }; 00103 00104 // Description: 00105 // Set/Get the order of the sliders (inverted means that the first slider 00106 // will be associated to Range[1], the last to Range[0]) 00107 virtual void SetInverted(int); 00108 vtkBooleanMacro(Inverted, int); 00109 vtkGetMacro(Inverted, int); 00110 00111 // Description: 00112 // Set/Get the desired narrow dimension of the widget. For horizontal widget 00113 // this is the widget height, for vertical this is the width. 00114 // In the current implementation, this controls the sliders narrow dim. 00115 virtual void SetThickness(int); 00116 vtkGetMacro(Thickness, int); 00117 00118 // Description: 00119 // Set/Get the desired narrow dimension of the internal widget as a fraction 00120 // of the thickness of the widget (see Thickness). 00121 // In the current implementation, this controls the range bar narrow dim. 00122 virtual void SetInternalThickness(double); 00123 vtkGetMacro(InternalThickness, double); 00124 00125 // Description: 00126 // Set/Get the long dimension of the widget. For horizontal widget 00127 // this is the widget width, for vertical this is the height. 00128 // Set it to zero (default) to ignore it and let the widget 00129 // resize. 00130 virtual void SetRequestedLength(int); 00131 vtkGetMacro(RequestedLength, int); 00132 00133 // Description: 00134 // Set/Get the slider size. 00135 virtual void SetSliderSize(int); 00136 vtkGetMacro(SliderSize, int); 00137 00138 // Description: 00139 // Set/Get if a slider can push another slider when bumping into it 00140 vtkSetMacro(SliderCanPush, int); 00141 vtkBooleanMacro(SliderCanPush, int); 00142 vtkGetMacro(SliderCanPush, int); 00143 00144 // Description: 00145 // Set/Get the (sub) range scale color. 00146 // Defaults to -1, -1, -1: a shade of the widget background color will 00147 // be used at runtime. 00148 vtkGetVector3Macro(RangeColor, double); 00149 virtual void SetRangeColor(double r, double g, double b); 00150 virtual void SetRangeColor(double rgb[3]) 00151 { this->SetRangeColor(rgb[0], rgb[1], rgb[2]); }; 00152 00153 // Description: 00154 // Set/Get the (sub) range scale interaction color. Used when interaction 00155 // is performed using the sliders. 00156 // IF set to -1, -1, -1: a shade of the widget background color will 00157 // be used at runtime. 00158 vtkGetVector3Macro(RangeInteractionColor, double); 00159 virtual void SetRangeInteractionColor(double r, double g, double b); 00160 virtual void SetRangeInteractionColor(double rgb[3]) 00161 { this->SetRangeInteractionColor(rgb[0], rgb[1], rgb[2]); }; 00162 00163 // Description: 00164 // Set/Get the color of the first slider. 00165 // Defaults to -1, -1, -1: a shade of the widget background color will 00166 // be used at runtime. 00167 vtkGetVector3Macro(Slider1Color, double); 00168 virtual void SetSlider1Color(double r, double g, double b); 00169 virtual void SetSlider1Color(double rgb[3]) 00170 { this->SetSlider1Color(rgb[0], rgb[1], rgb[2]); }; 00171 00172 // Description: 00173 // Set/Get the (sub) slider scale interaction color. Used when interaction 00174 // is performed using the sliders. 00175 // IF set to -1, -1, -1: a shade of the widget background color will 00176 // be used at runtime. 00177 vtkGetVector3Macro(SliderInteractionColor, double); 00178 virtual void SetSliderInteractionColor(double r, double g, double b); 00179 virtual void SetSliderInteractionColor(double rgb[3]) 00180 { this->SetSliderInteractionColor(rgb[0], rgb[1], rgb[2]); }; 00181 00182 // Description: 00183 // Set/Get the color of the second slider. 00184 // Defaults to -1, -1, -1: a shade of the widget background color will 00185 // be used at runtime. 00186 vtkGetVector3Macro(Slider2Color, double); 00187 virtual void SetSlider2Color(double r, double g, double b); 00188 virtual void SetSlider2Color(double rgb[3]) 00189 { this->SetSlider2Color(rgb[0], rgb[1], rgb[2]); }; 00190 00191 // Description: 00192 // Set/Get the entries visibility. 00193 virtual void SetEntriesVisibility(int); 00194 vtkBooleanMacro(EntriesVisibility, int); 00195 vtkGetMacro(EntriesVisibility, int); 00196 00197 // Description: 00198 // Get the entries object. 00199 virtual vtkKWEntry* GetEntry1() 00200 { return this->Entries[0]; }; 00201 virtual vtkKWEntry* GetEntry2() 00202 { return this->Entries[1]; }; 00203 00204 // Description: 00205 // Set/Get the entries width (in chars). 00206 virtual void SetEntriesWidth(int width); 00207 vtkGetMacro(EntriesWidth, int); 00208 00209 // Description: 00210 // Set/Get the position of the entries (Default is top if the range 00211 // direction is horizontal, left if it is vertical). 00212 // Note that you can also set the label position using the superclass 00213 // methods (vtkKWWidgetWithLabel). 00214 //BTX 00215 enum 00216 { 00217 EntryPositionDefault = 0, 00218 EntryPositionTop, 00219 EntryPositionBottom, 00220 EntryPositionLeft, 00221 EntryPositionRight 00222 }; 00223 //ETX 00224 virtual void SetEntry1Position(int); 00225 vtkGetMacro(Entry1Position, int); 00226 virtual void SetEntry1PositionToDefault() 00227 { this->SetEntry1Position(vtkKWRange::EntryPositionDefault); }; 00228 virtual void SetEntry1PositionToTop() 00229 { this->SetEntry1Position(vtkKWRange::EntryPositionTop); }; 00230 virtual void SetEntry1PositionToBottom() 00231 { this->SetEntry1Position(vtkKWRange::EntryPositionBottom); }; 00232 virtual void SetEntry1PositionToLeft() 00233 { this->SetEntry1Position(vtkKWRange::EntryPositionLeft); }; 00234 virtual void SetEntry1PositionToRight() 00235 { this->SetEntry1Position(vtkKWRange::EntryPositionRight); }; 00236 virtual void SetEntry2Position(int); 00237 vtkGetMacro(Entry2Position, int); 00238 virtual void SetEntry2PositionToDefault() 00239 { this->SetEntry2Position(vtkKWRange::EntryPositionDefault); }; 00240 virtual void SetEntry2PositionToTop() 00241 { this->SetEntry2Position(vtkKWRange::EntryPositionTop); }; 00242 virtual void SetEntry2PositionToBottom() 00243 { this->SetEntry2Position(vtkKWRange::EntryPositionBottom); }; 00244 virtual void SetEntry2PositionToLeft() 00245 { this->SetEntry2Position(vtkKWRange::EntryPositionLeft); }; 00246 virtual void SetEntry2PositionToRight() 00247 { this->SetEntry2Position(vtkKWRange::EntryPositionRight); }; 00248 00249 // Description: 00250 // Specifies commands to associate with the widget. 00251 // 'Command' is invoked when the widget value is changing (i.e. during 00252 // user interaction). 00253 // 'StartCommand' is invoked at the beginning of a user interaction with 00254 // the widget (when a mouse button is pressed over the widget for example). 00255 // 'EndCommand' is invoked at the end of the user interaction with the 00256 // widget (when the mouse button is released for example). 00257 // 'EntriesCommand' is invoked when the widget value is changed using 00258 // the text entries. 00259 // The need for a 'Command', 'StartCommand' and 'EndCommand' can be 00260 // explained as follows: 'EndCommand' can be used to be notified about any 00261 // changes made to this widget *after* the corresponding user interaction has 00262 // been performed (say, after releasing the mouse button that was dragging 00263 // a slider, or after clicking on a checkbutton). 'Command' can be set 00264 // *additionally* to be notified about the intermediate changes that 00265 // occur *during* the corresponding user interaction (say, *while* dragging 00266 // a slider). While setting 'EndCommand' is enough to be notified about 00267 // any changes, setting 'Command' is an application-specific choice that 00268 // is likely to depend on how fast you want (or can) answer to rapid changes 00269 // occuring during a user interaction, if any. 'StartCommand' is rarely 00270 // used but provides an opportunity for the application to modify its 00271 // state and prepare itself for user-interaction; in that case, the 00272 // 'EndCommand' is usually set in a symmetric fashion to set the application 00273 // back to its previous state. 00274 // The 'object' argument is the object that will have the method called on 00275 // it. The 'method' argument is the name of the method to be called and any 00276 // arguments in string form. If the object is NULL, the method is still 00277 // evaluated as a simple command. 00278 // The following parameters are also passed to the command: 00279 // - the current range: int, int (if Resolution is integer); double, double 00280 // otherwise. 00281 // Note: the 'int' signature is for convenience, so that the command can 00282 // be set to a callback accepting 'int'. In doubt, implement the callback 00283 // using a 'double' signature that will accept both 'int' and 'double'. 00284 virtual void SetCommand(vtkObject *object, const char *method); 00285 virtual void SetStartCommand(vtkObject *object, const char *method); 00286 virtual void SetEndCommand(vtkObject *object, const char *method); 00287 virtual void SetEntriesCommand(vtkObject *object, const char *method); 00288 00289 // Description: 00290 // Set/Get whether the above commands should be called or not. 00291 // This allow you to disable the commands while you are setting the range 00292 // value for example. 00293 vtkSetMacro(DisableCommands, int); 00294 vtkGetMacro(DisableCommands, int); 00295 vtkBooleanMacro(DisableCommands, int); 00296 00297 // Description: 00298 // Events. The RangeValueChangingEvent is triggered when the widget value 00299 // is changed (i.e., during user interaction on the widget's slider), 00300 // the RangeValueStartChangingEvent is invoked at the beginning of an 00301 // interaction with the widget, the RangeValueChangedEvent is invoked at the 00302 // end of an interaction with the widget (or when the value is changed 00303 // using the entries widget). They are similar in concept as 00304 // the 'Command', 'StartCommand', 'EndCommand' and 'EntriesCommand' callbacks 00305 // but can be used by multiple listeners/observers at a time. 00306 // The following parameters are also passed as client data: 00307 // - the current range: double, double. 00308 //BTX 00309 enum 00310 { 00311 RangeValueChangingEvent = 10000, 00312 RangeValueChangedEvent, 00313 RangeValueStartChangingEvent 00314 }; 00315 //ETX 00316 00317 // Description: 00318 // If set to on, set the interaction to a symmetrical mode, where 00319 // adjusting one slider adjust the other one symmetrically. 00320 vtkBooleanMacro(SymmetricalInteraction, int); 00321 vtkGetMacro(SymmetricalInteraction, int); 00322 vtkSetMacro(SymmetricalInteraction, int); 00323 00324 // Description: 00325 // Set the string that enables balloon help for this widget. 00326 // Override to pass down to children. 00327 virtual void SetBalloonHelpString(const char *str); 00328 00329 // Description: 00330 // Access to the canvas 00331 vtkGetObjectMacro(Canvas, vtkKWCanvas); 00332 00333 // Description: 00334 // Update the "enable" state of the object and its internal parts. 00335 // Depending on different Ivars (this->Enabled, the application's 00336 // Limited Edition Mode, etc.), the "enable" state of the object is updated 00337 // and propagated to its internal parts/subwidgets. This will, for example, 00338 // enable/disable parts of the widget UI, enable/disable the visibility 00339 // of 3D widgets, etc. 00340 virtual void UpdateEnableState(); 00341 00342 // Description: 00343 // Turn on/off the automatic clamping of the end values when the 00344 // user types a value beyond the range. Default is on. 00345 vtkSetMacro(ClampRange, int); 00346 vtkGetMacro(ClampRange, int); 00347 vtkBooleanMacro(ClampRange, int); 00348 00349 // Description: 00350 // Callbacks. Internal, do not use. 00351 //BTX 00352 enum 00353 { 00354 SliderIndex0 = 0, 00355 SliderIndex1 = 1 00356 }; 00357 //ETX 00358 virtual void ConfigureCallback(); 00359 virtual void MaximizeRangeCallback(); 00360 virtual void EnlargeRangeCallback(); 00361 virtual void ShrinkRangeCallback(); 00362 virtual void EntriesUpdateCallback(int i); 00363 virtual void StartRangeInteractionCallback(int x, int y); 00364 virtual void StartSliderInteractionCallback(int slider_idx, int x, int y); 00365 virtual void EndInteractionCallback(); 00366 virtual void SliderMotionCallback( 00367 int slider_idx, int x, int y, int shift, int ctrl); 00368 virtual void RangeMotionCallback(int x, int y, int shift, int ctrl); 00369 00370 protected: 00371 vtkKWRange(); 00372 ~vtkKWRange(); 00373 00374 // Description: 00375 // Create the widget. 00376 virtual void CreateWidget(); 00377 00378 double WholeRange[2]; 00379 double Range[2]; 00380 double WholeRangeAdjusted[2]; 00381 double RangeAdjusted[2]; 00382 double Resolution; 00383 int AdjustResolution; 00384 int SymmetricalInteraction; 00385 int Inverted; 00386 int Thickness; 00387 double InternalThickness; 00388 int RequestedLength; 00389 int Orientation; 00390 int DisableCommands; 00391 int SliderSize; 00392 double RangeColor[3]; 00393 double RangeInteractionColor[3]; 00394 double Slider1Color[3]; 00395 double Slider2Color[3]; 00396 double SliderInteractionColor[3]; 00397 int EntriesVisibility; 00398 int Entry1Position; 00399 int Entry2Position; 00400 int EntriesWidth; 00401 int SliderCanPush; 00402 00403 int ClampRange; 00404 00405 char *Command; 00406 char *StartCommand; 00407 char *EndCommand; 00408 char *EntriesCommand; 00409 00410 virtual void InvokeRangeCommand(const char *command, double r0, double r1); 00411 virtual void InvokeCommand(double r0, double r1); 00412 virtual void InvokeStartCommand(double r0, double r1); 00413 virtual void InvokeEndCommand(double r0, double r1); 00414 virtual void InvokeEntriesCommand(double r0, double r1); 00415 00416 vtkKWFrame *CanvasFrame; 00417 vtkKWCanvas *Canvas; 00418 vtkKWEntry *Entries[2]; 00419 00420 virtual void CreateEntries(); 00421 virtual void UpdateEntriesValue(double range[2]); 00422 virtual void ConstrainResolution(); 00423 00424 // Description: 00425 // Bind/Unbind all components. 00426 virtual void Bind(); 00427 virtual void UnBind(); 00428 00429 // Description: 00430 // Make sure all elements are constrained correctly 00431 virtual void ConstrainRangeToResolution( 00432 double range[2], double res, int adjust = 1); 00433 virtual void ConstrainRangeToWholeRange( 00434 double range[2], double whole_range[2], double *old_range_hint = 0); 00435 virtual void ConstrainWholeRange(); 00436 virtual void ConstrainRange(double *old_range_hint = 0); 00437 virtual void ConstrainRanges(); 00438 00439 // Description: 00440 // Pack the widget 00441 virtual void Pack(); 00442 00443 // Description: 00444 // Get type of interaction 00445 //BTX 00446 enum 00447 { 00448 RangeInteraction, 00449 Slider1Interaction, 00450 Slider2Interaction 00451 }; 00452 00453 // Description: 00454 // Start Interactions with the input interaction type 00455 // (RangeInteraction, Slider1Interaction, Slider2Interaction) 00456 virtual void StartInteraction(int inter_type, int x, int y); 00457 00458 // Description: 00459 // Get element colors (and shades) 00460 //BTX 00461 enum 00462 { 00463 DarkShadowColor, 00464 LightShadowColor, 00465 BackgroundColor, 00466 HighlightColor 00467 }; 00468 //ETX 00469 virtual void GetColorShade( 00470 int type, double rgb[3], double &r, double &g, double &b); 00471 virtual void GetWholeRangeColor(int type, double &r, double &g, double &b); 00472 virtual void GetRangeColor(int type, double &r, double &g, double &b); 00473 virtual void GetSliderColor(int slider_idx, int type, double &r, double &g, double &b); 00474 00475 // Description: 00476 // Redraw elements 00477 virtual void RedrawCanvas(); 00478 virtual void RedrawWholeRange(); 00479 virtual void RedrawRange(); 00480 virtual void RedrawSliders(); 00481 virtual void RedrawSlider(int x, int slider_idx); 00482 virtual void UpdateRangeColors(); 00483 virtual void UpdateSliderColors(int slider_idx); 00484 virtual void UpdateColors(); 00485 00486 // Description: 00487 // Look for a tag 00488 virtual int HasTag(const char *tag, const char *suffix = 0); 00489 00490 // Description: 00491 // Get the current sliders center positions 00492 virtual void GetSlidersPositions(int pos[2]); 00493 00494 private: 00495 00496 int InInteraction; 00497 int StartInteractionPos; 00498 double StartInteractionRange[2]; 00499 00500 vtkKWRange(const vtkKWRange&); // Not implemented 00501 void operator=(const vtkKWRange&); // Not implemented 00502 }; 00503 00504 #endif 00505