KWWidgets
vtkKWMaterialPropertyWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Module: $RCSfile: vtkKWMaterialPropertyWidget.h,v $
4 
5  Copyright (c) Kitware, Inc.
6  All rights reserved.
7  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 // .NAME vtkKWMaterialPropertyWidget - widget to control the material property of a volume
15 // .SECTION Description
16 
17 #ifndef __vtkKWMaterialPropertyWidget_h
18 #define __vtkKWMaterialPropertyWidget_h
19 
20 #include "vtkKWCompositeWidget.h"
21 
22 class vtkKWFrame;
23 class vtkKWLabel;
28 class vtkKWPushButton;
30 class vtkKWMaterialPropertyWidgetInternals;
31 
33 {
34 public:
36  void PrintSelf(ostream& os, vtkIndent indent);
37 
38  // Description:
39  // Display the UI as a popup (default is off). The pushbutton will display
40  // a representation of the current properties.
41  // This has to be called before Create().
42  vtkSetMacro(PopupMode, int);
43  vtkGetMacro(PopupMode, int);
44  vtkBooleanMacro(PopupMode, int);
45  vtkGetObjectMacro(PopupButton, vtkKWPopupButtonWithLabel);
46 
47  // Description:
48  // Refresh the interface given the value extracted from the current widget.
49  virtual void Update();
50 
51  // Description:
52  // Update the preview according to current settings
53  virtual void UpdatePreview();
54 
55  // Description:
56  // Set/Get the size of the preview, presets and popup preview images
57  virtual void SetPreviewSize(int);
58  virtual void SetPresetSize(int);
59  virtual void SetPopupPreviewSize(int);
60  vtkGetMacro(PreviewSize, int);
61  vtkGetMacro(PresetSize, int);
62  vtkGetMacro(PopupPreviewSize, int);
63 
64  // Description:
65  // Set/Get the grid opacity in the preview/presets
66  virtual void SetGridOpacity(double);
67  vtkGetMacro(GridOpacity, double);
68 
69  // Description:
70  // Set/Get the color of the preview/presets.
71  vtkGetVector3Macro(MaterialColor, double);
72  void SetMaterialColor(double r, double g, double b);
73  void SetMaterialColor(double color[3])
74  { this->SetMaterialColor(color[0], color[1], color[2]); }
75 
76  // Description:
77  // Set/Get the lighting parameters visibility.
78  // If set to Off, none of the ambient, diffuse, specular (etc.) scales
79  // will be displayed.
80  virtual void SetLightingParametersVisibility(int);
81  vtkBooleanMacro(LightingParametersVisibility, int);
82  vtkGetMacro(LightingParametersVisibility, int);
83 
84  // Description:
85  // Set/Get the event invoked when the property is changed/changing.
86  // Defaults to vtkKWEvent::MaterialPropertyChanged/ingEvent, this default
87  // is likely to change in subclasses to reflect what kind of property
88  // is changed (vtkKWEvent::VolumeMaterialPropertyChangedEvent for example).
89  vtkSetMacro(PropertyChangedEvent, int);
90  vtkGetMacro(PropertyChangedEvent, int);
91  vtkSetMacro(PropertyChangingEvent, int);
92  vtkGetMacro(PropertyChangingEvent, int);
93 
94  // Description:
95  // Specifies commands to associate with the widget.
96  // 'PropertyChangedCommand' is invoked when the property has
97  // changed (i.e. at the end of the user interaction).
98  // 'PropertyChangingCommand' is invoked when the selected color is
99  // changing (i.e. during the user interaction).
100  // The need for a '...ChangedCommand' and '...ChangingCommand' can be
101  // explained as follows: the former can be used to be notified about any
102  // changes made to this widget *after* the corresponding user interaction has
103  // been performed (say, after releasing the mouse button that was dragging
104  // a slider, or after clicking on a checkbutton). The later can be set
105  // *additionally* to be notified about the intermediate changes that
106  // occur *during* the corresponding user interaction (say, *while* dragging
107  // a slider). While setting '...ChangedCommand' is enough to be notified
108  // about any changes, setting '...ChangingCommand' is an application-specific
109  // choice that is likely to depend on how fast you want (or can) answer to
110  // rapid changes occuring during a user interaction, if any.
111  // The 'object' argument is the object that will have the method called on
112  // it. The 'method' argument is the name of the method to be called and any
113  // arguments in string form. If the object is NULL, the method is still
114  // evaluated as a simple command.
115  virtual void SetPropertyChangedCommand(
116  vtkObject *object, const char *method);
117  virtual void SetPropertyChangingCommand(
118  vtkObject *object, const char *method);
119 
120  // Description:
121  // Update the "enable" state of the object and its internal parts.
122  // Depending on different Ivars (this->Enabled, the application's
123  // Limited Edition Mode, etc.), the "enable" state of the object is updated
124  // and propagated to its internal parts/subwidgets. This will, for example,
125  // enable/disable parts of the widget UI, enable/disable the visibility
126  // of 3D widgets, etc.
127  virtual void UpdateEnableState();
128 
129  // Description:
130  // Callbacks. Internal, do not use.
131  virtual void PropertyChangingCallback(double value);
132  virtual void PropertyChangedCallback(double value);
133  virtual void PresetMaterialCallback(int preset_idx);
134 
135 protected:
138 
139  // Description:
140  // Create the widget.
141  virtual void CreateWidget();
142 
143  int PopupMode;
144  int PreviewSize;
145  int PresetSize;
146  int PopupPreviewSize;
147  double GridOpacity;
148  int LightingParametersVisibility;
149 
150  double MaterialColor[3];
151 
152  // Description:
153  // Events
154  int PropertyChangedEvent;
155  int PropertyChangingEvent;
156 
157  // Description:
158  // Commands
159  char *PropertyChangedCommand;
160  char *PropertyChangingCommand;
161 
162  virtual void InvokePropertyChangedCommand();
163  virtual void InvokePropertyChangingCommand();
164 
165  // Presets
166 
167  //BTX
168  class Preset
169  {
170  public:
171  double Ambient;
172  double Diffuse;
173  double Specular;
174  double SpecularPower;
175  char *HelpString;
176 
177  Preset() { this->HelpString = 0; };
178  };
179 
180  // PIMPL Encapsulation for STL containers
181 
182  vtkKWMaterialPropertyWidgetInternals *Internals;
183  friend class vtkKWMaterialPropertyWidgetInternals;
184  //ETX
185 
186  // UI
187 
188  vtkKWPopupButtonWithLabel *PopupButton;
189  vtkKWFrameWithLabel *MaterialPropertiesFrame;
190  vtkKWFrame *ControlFrame;
191  vtkKWFrame *LightingFrame;
192  vtkKWScaleWithEntry *AmbientScale;
193  vtkKWScaleWithEntry *DiffuseScale;
194  vtkKWScaleWithEntry *SpecularScale;
195  vtkKWScaleWithEntry *SpecularPowerScale;
196  vtkKWFrame *PresetsFrame;
197  vtkKWLabelWithLabel *PreviewLabel;
198  vtkKWPushButtonSetWithLabel *PresetPushButtonSet;
199 
200  // Description:
201  // Pack
202  virtual void Pack();
203 
204  // Description:
205  // Create a preview image given some material properties
206  virtual void CreateImage(unsigned char *data,
207  double ambient,
208  double diffuse,
209  double specular,
210  double specular_power,
211  int size);
212 
213  // Description:
214  // Send an event representing the state of the widget
215  virtual void SendStateEvent(int event);
216 
217  // Description:
218  // Add default presets
219  virtual void AddDefaultPresets();
220 
221  // Description:
222  // Create the presets
223  virtual void CreatePresets();
224 
225  // Description:
226  // Update the popup preview according to current settings
227  virtual void UpdatePopupPreview();
228 
229  // Description:
230  // Update the property from the interface values or a preset
231  // Return 1 if the property was modified, 0 otherwise
232  virtual int UpdatePropertyFromInterface() = 0;
233  virtual int UpdatePropertyFromPreset(const Preset *preset) = 0;
234 
235  // Description:
236  // Update the scales from a preset
237  virtual int UpdateScalesFromPreset(const Preset *preset);
238  virtual void UpdateScales(double ambient,
239  double diffuse,
240  double specular,
241  double specular_power);
242 
243  // Description:
244  // Return 1 if the controls should be enabled.
245  virtual int AreControlsEnabled() { return 1; };
246 
247 private:
249  void operator=(const vtkKWMaterialPropertyWidget&); //Not implemented
250 };
251 
252 #endif