KWWidgets
vtkKWMaterialPropertyWidget.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Module:    $RCSfile: vtkKWMaterialPropertyWidget.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 vtkKWMaterialPropertyWidget - widget to control the material property of a volume
00015 // .SECTION Description
00016 
00017 #ifndef __vtkKWMaterialPropertyWidget_h
00018 #define __vtkKWMaterialPropertyWidget_h
00019 
00020 #include "vtkKWCompositeWidget.h"
00021 
00022 class vtkKWFrame;
00023 class vtkKWLabel;
00024 class vtkKWFrameWithLabel;
00025 class vtkKWLabelWithLabel;
00026 class vtkKWPushButtonSetWithLabel;
00027 class vtkKWPopupButtonWithLabel;
00028 class vtkKWPushButton;
00029 class vtkKWScaleWithEntry;
00030 class vtkKWMaterialPropertyWidgetInternals;
00031 
00032 class KWWidgets_EXPORT vtkKWMaterialPropertyWidget : public vtkKWCompositeWidget
00033 {
00034 public:
00035   vtkTypeRevisionMacro(vtkKWMaterialPropertyWidget, vtkKWCompositeWidget);
00036   void PrintSelf(ostream& os, vtkIndent indent);
00037   
00038   // Description:
00039   // Display the UI as a popup (default is off). The pushbutton will display
00040   // a representation of the current properties.
00041   // This has to be called before Create().
00042   vtkSetMacro(PopupMode, int);
00043   vtkGetMacro(PopupMode, int);
00044   vtkBooleanMacro(PopupMode, int);
00045   vtkGetObjectMacro(PopupButton, vtkKWPopupButtonWithLabel);
00046   
00047   // Description:
00048   // Refresh the interface given the value extracted from the current widget.
00049   virtual void Update();
00050 
00051   // Description:
00052   // Update the preview according to current settings
00053   virtual void UpdatePreview();
00054 
00055   // Description:
00056   // Set/Get the size of the preview, presets and popup preview images
00057   virtual void SetPreviewSize(int);
00058   virtual void SetPresetSize(int);
00059   virtual void SetPopupPreviewSize(int);
00060   vtkGetMacro(PreviewSize, int);
00061   vtkGetMacro(PresetSize, int);
00062   vtkGetMacro(PopupPreviewSize, int);
00063 
00064   // Description:
00065   // Set/Get the grid opacity in the preview/presets
00066   virtual void SetGridOpacity(double);
00067   vtkGetMacro(GridOpacity, double);
00068   
00069   // Description:
00070   // Set/Get the color of the preview/presets.
00071   vtkGetVector3Macro(MaterialColor, double);
00072   void SetMaterialColor(double r, double g, double b);
00073   void SetMaterialColor(double color[3])
00074     { this->SetMaterialColor(color[0], color[1], color[2]); }
00075 
00076   // Description:
00077   // Set/Get the lighting parameters visibility.
00078   // If set to Off, none of the ambient, diffuse, specular (etc.) scales
00079   // will be displayed.
00080   virtual void SetLightingParametersVisibility(int);
00081   vtkBooleanMacro(LightingParametersVisibility, int);
00082   vtkGetMacro(LightingParametersVisibility, int);
00083 
00084   // Description:
00085   // Set/Get the event invoked when the property is changed/changing.
00086   // Defaults to vtkKWEvent::MaterialPropertyChanged/ingEvent, this default
00087   // is likely to change in subclasses to reflect what kind of property
00088   // is changed  (vtkKWEvent::VolumeMaterialPropertyChangedEvent for example).
00089   vtkSetMacro(PropertyChangedEvent, int);
00090   vtkGetMacro(PropertyChangedEvent, int);
00091   vtkSetMacro(PropertyChangingEvent, int);
00092   vtkGetMacro(PropertyChangingEvent, int);
00093 
00094   // Description:
00095   // Specifies commands to associate with the widget. 
00096   // 'PropertyChangedCommand' is invoked when the property has
00097   // changed (i.e. at the end of the user interaction).
00098   // 'PropertyChangingCommand' is invoked when the selected color is
00099   // changing (i.e. during the user interaction).
00100   // The need for a '...ChangedCommand' and '...ChangingCommand' can be
00101   // explained as follows: the former can be used to be notified about any
00102   // changes made to this widget *after* the corresponding user interaction has
00103   // been performed (say, after releasing the mouse button that was dragging
00104   // a slider, or after clicking on a checkbutton). The later can be set
00105   // *additionally* to be notified about the intermediate changes that
00106   // occur *during* the corresponding user interaction (say, *while* dragging
00107   // a slider). While setting '...ChangedCommand' is enough to be notified
00108   // about any changes, setting '...ChangingCommand' is an application-specific
00109   // choice that is likely to depend on how fast you want (or can) answer to
00110   // rapid changes occuring during a user interaction, if any.
00111   // The 'object' argument is the object that will have the method called on
00112   // it. The 'method' argument is the name of the method to be called and any
00113   // arguments in string form. If the object is NULL, the method is still
00114   // evaluated as a simple command. 
00115   virtual void SetPropertyChangedCommand(
00116     vtkObject *object, const char *method);
00117   virtual void SetPropertyChangingCommand(
00118     vtkObject *object, const char *method);
00119 
00120   // Description:
00121   // Update the "enable" state of the object and its internal parts.
00122   // Depending on different Ivars (this->Enabled, the application's 
00123   // Limited Edition Mode, etc.), the "enable" state of the object is updated
00124   // and propagated to its internal parts/subwidgets. This will, for example,
00125   // enable/disable parts of the widget UI, enable/disable the visibility
00126   // of 3D widgets, etc.
00127   virtual void UpdateEnableState();
00128 
00129   // Description:
00130   // Callbacks. Internal, do not use.
00131   virtual void PropertyChangingCallback(double value);
00132   virtual void PropertyChangedCallback(double value);
00133   virtual void PresetMaterialCallback(int preset_idx);
00134 
00135 protected:
00136   vtkKWMaterialPropertyWidget();
00137   ~vtkKWMaterialPropertyWidget();
00138   
00139   // Description:
00140   // Create the widget.
00141   virtual void CreateWidget();
00142   
00143   int   PopupMode;
00144   int   PreviewSize;
00145   int   PresetSize;
00146   int   PopupPreviewSize;
00147   double GridOpacity;
00148   int LightingParametersVisibility;
00149 
00150   double MaterialColor[3];
00151 
00152   // Description:
00153   // Events
00154   int   PropertyChangedEvent;
00155   int   PropertyChangingEvent;
00156 
00157   // Description:
00158   // Commands
00159   char  *PropertyChangedCommand;
00160   char  *PropertyChangingCommand;
00161 
00162   virtual void InvokePropertyChangedCommand();
00163   virtual void InvokePropertyChangingCommand();
00164 
00165   // Presets
00166 
00167   //BTX
00168   class Preset
00169   {
00170   public:
00171     double Ambient;
00172     double Diffuse;
00173     double Specular;
00174     double SpecularPower;
00175     char *HelpString;
00176 
00177     Preset() { this->HelpString = 0; };
00178   };
00179 
00180   // PIMPL Encapsulation for STL containers
00181 
00182   vtkKWMaterialPropertyWidgetInternals *Internals;
00183   friend class vtkKWMaterialPropertyWidgetInternals;
00184   //ETX
00185 
00186   // UI
00187 
00188   vtkKWPopupButtonWithLabel   *PopupButton;
00189   vtkKWFrameWithLabel         *MaterialPropertiesFrame;
00190   vtkKWFrame                  *ControlFrame;
00191   vtkKWFrame                  *LightingFrame;
00192   vtkKWScaleWithEntry         *AmbientScale;
00193   vtkKWScaleWithEntry         *DiffuseScale;
00194   vtkKWScaleWithEntry         *SpecularScale;
00195   vtkKWScaleWithEntry         *SpecularPowerScale;
00196   vtkKWFrame                  *PresetsFrame;
00197   vtkKWLabelWithLabel         *PreviewLabel;
00198   vtkKWPushButtonSetWithLabel *PresetPushButtonSet;
00199 
00200   // Description:
00201   // Pack
00202   virtual void Pack();
00203 
00204   // Description:
00205   // Create a preview image given some material properties
00206   virtual void CreateImage(unsigned char *data, 
00207                            double ambient, 
00208                            double diffuse,
00209                            double specular, 
00210                            double specular_power, 
00211                            int size);
00212   
00213   // Description:
00214   // Send an event representing the state of the widget
00215   virtual void SendStateEvent(int event);
00216 
00217   // Description:
00218   // Add default presets
00219   virtual void AddDefaultPresets();
00220 
00221   // Description:
00222   // Create the presets
00223   virtual void CreatePresets();
00224 
00225   // Description:
00226   // Update the popup preview according to current settings
00227   virtual void UpdatePopupPreview();
00228 
00229   // Description:
00230   // Update the property from the interface values or a preset
00231   // Return 1 if the property was modified, 0 otherwise
00232   virtual int UpdatePropertyFromInterface() = 0;
00233   virtual int UpdatePropertyFromPreset(const Preset *preset) = 0;
00234 
00235   // Description:
00236   // Update the scales from a preset
00237   virtual int UpdateScalesFromPreset(const Preset *preset);
00238   virtual void UpdateScales(double ambient, 
00239                             double diffuse,
00240                             double specular, 
00241                             double specular_power);
00242 
00243   // Description:
00244   // Return 1 if the controls should be enabled.
00245   virtual int AreControlsEnabled() { return 1; };
00246 
00247 private:
00248   vtkKWMaterialPropertyWidget(const vtkKWMaterialPropertyWidget&);  //Not implemented
00249   void operator=(const vtkKWMaterialPropertyWidget&);  //Not implemented
00250 };
00251 
00252 #endif