VTK
dox/Charts/Core/vtkChart.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkChart.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00029 #ifndef __vtkChart_h
00030 #define __vtkChart_h
00031 
00032 #include "vtkChartsCoreModule.h" // For export macro
00033 #include "vtkContextItem.h"
00034 #include "vtkRect.h"         // For vtkRectf
00035 #include "vtkStdString.h"    // For vtkStdString ivars
00036 #include "vtkSmartPointer.h" // For SP ivars
00037 
00038 class vtkTransform2D;
00039 class vtkContextScene;
00040 class vtkPlot;
00041 class vtkAxis;
00042 class vtkBrush;
00043 class vtkTextProperty;
00044 class vtkChartLegend;
00045 
00046 class vtkInteractorStyle;
00047 class vtkAnnotationLink;
00048 
00049 class VTKCHARTSCORE_EXPORT vtkChart : public vtkContextItem
00050 {
00051 public:
00052   vtkTypeMacro(vtkChart, vtkContextItem);
00053   virtual void PrintSelf(ostream &os, vtkIndent indent);
00054 
00055 //BTX
00057 
00058   enum {
00059     LINE,
00060     POINTS,
00061     BAR,
00062     STACKED,
00063     BAG,
00064     FUNCTIONALBAG};
00066 
00068 
00074   enum {
00075     PAN = 0,
00076     ZOOM,
00077     ZOOM_AXIS,
00078     SELECT,
00079     SELECT_RECTANGLE = SELECT,
00080     SELECT_POLYGON,
00081     NOTIFY
00082     };
00084 
00086 
00087   enum EventIds {
00088     UpdateRange = 1002
00089   };
00090 //ETX
00092 
00095   virtual bool Paint(vtkContext2D *painter) = 0;
00096 
00098   virtual vtkPlot* AddPlot(int type);
00099 
00102   virtual vtkIdType AddPlot(vtkPlot* plot);
00103 
00106   virtual bool RemovePlot(vtkIdType index);
00107 
00111   virtual bool RemovePlotInstance(vtkPlot* plot);
00112 
00114   virtual void ClearPlots();
00115 
00118   virtual vtkPlot* GetPlot(vtkIdType index);
00119 
00121   virtual vtkIdType GetNumberOfPlots();
00122 
00126   virtual vtkAxis* GetAxis(int axisIndex);
00127 
00129   virtual vtkIdType GetNumberOfAxes();
00130 
00134   virtual void RecalculateBounds();
00135 
00137 
00142   enum {
00143     SELECTION_ROWS,
00144     SELECTION_PLOTS
00145   };
00147 
00149 
00154   virtual void SetSelectionMethod(int method);
00155   virtual int GetSelectionMethod();
00157 
00159   virtual void SetAnnotationLink(vtkAnnotationLink *link);
00160 
00162 
00163   vtkGetObjectMacro(AnnotationLink, vtkAnnotationLink);
00165 
00167 
00168   vtkSetVector2Macro(Geometry, int);
00169   vtkGetVector2Macro(Geometry, int);
00171 
00173 
00174   vtkSetVector2Macro(Point1, int);
00175   vtkGetVector2Macro(Point1, int);
00177 
00179 
00180   vtkSetVector2Macro(Point2, int);
00181   vtkGetVector2Macro(Point2, int);
00183 
00185 
00186   virtual void SetShowLegend(bool visible);
00187   virtual bool GetShowLegend();
00189 
00192   virtual vtkChartLegend * GetLegend();
00193 
00195 
00196   virtual void SetTitle(const vtkStdString &title);
00197   virtual vtkStdString GetTitle();
00199 
00201 
00203   vtkGetObjectMacro(TitleProperties, vtkTextProperty);
00205 
00207 
00208   void SetBottomBorder(int border);
00209   void SetTopBorder(int border);
00210   void SetLeftBorder(int border);
00211   void SetRightBorder(int border);
00213 
00215   void SetBorders(int left, int bottom, int right, int top);
00216 
00220   void SetSize(const vtkRectf &rect);
00221 
00223   vtkRectf GetSize();
00224 
00226 
00227   enum {
00228     FILL_SCENE,  // Attempt to fill the entire scene.
00229     FILL_RECT,   // Attempt to supply the supplied vtkRectf in Size.
00230     AXES_TO_RECT // Put the corners of the axes on the vtkRectf in Size.
00231   };
00233 
00235 
00238   vtkSetMacro(LayoutStrategy, int);
00239   vtkGetMacro(LayoutStrategy, int);
00241 
00243 
00245   virtual void SetAutoSize(bool isAutoSized)
00246   {
00247     this->LayoutStrategy = isAutoSized ? vtkChart::FILL_SCENE :
00248                                          vtkChart::FILL_RECT;
00249   }
00250   virtual bool GetAutoSize()
00251   {
00252     return this->LayoutStrategy == vtkChart::FILL_SCENE ? true : false;
00253   }
00255 
00257 
00262   vtkSetMacro(RenderEmpty, bool);
00263   vtkGetMacro(RenderEmpty, bool);
00265 
00273   virtual void SetActionToButton(int action, int button);
00274 
00278   virtual int GetActionToButton(int action);
00279 
00283   virtual void SetClickActionToButton(int action, int button);
00284 
00288   virtual int GetClickActionToButton(int action);
00289 
00291 
00292   void SetBackgroundBrush(vtkBrush *brush);
00293   vtkBrush* GetBackgroundBrush();
00295 
00297 
00301   virtual void SetSelectionMode(int);
00302   vtkGetMacro(SelectionMode, int);
00304 
00305 protected:
00306   vtkChart();
00307   ~vtkChart();
00308 
00310 
00314   bool CalculatePlotTransform(vtkAxis *x, vtkAxis *y,
00315                               vtkTransform2D *transform);
00317 
00319 
00321   bool CalculateUnscaledPlotTransform(vtkAxis *x, vtkAxis *y,
00322                                       vtkTransform2D *transform);
00324 
00327   void AttachAxisRangeListener(vtkAxis*);
00328 
00329   void AxisRangeForwarderCallback(vtkObject*,unsigned long, void*);
00330 
00332   vtkAnnotationLink *AnnotationLink;
00333 
00335   int Geometry[2];
00336 
00338   int Point1[2];
00339 
00341   int Point2[2];
00342 
00344   bool ShowLegend;
00345 
00347   vtkStdString Title;
00348 
00350   vtkTextProperty* TitleProperties;
00351 
00352   vtkRectf Size;
00353   // The layout strategy to employ when fitting the chart into the space.
00354   int LayoutStrategy;
00355   bool RenderEmpty;
00356 
00358   vtkSmartPointer<vtkBrush> BackgroundBrush;
00359 
00360   // The mode when the chart is doing selection.
00361   int SelectionMode;
00362 
00363   // How plot selections are handled, SELECTION_ROWS (default) or
00364   // SELECTION_PLOTS - based on the plot that created the selection.
00365   int SelectionMethod;
00366 
00368 
00369   class MouseActions
00370     {
00371   public:
00372     MouseActions();
00373     enum { MaxAction = 5 };
00374     short& Pan() { return Data[0]; }
00375     short& Zoom() { return Data[1]; }
00376     short& ZoomAxis() { return Data[2]; }
00377     short& Select() { return Data[3]; }
00378     short& SelectPolygon() { return Data[4]; }
00379     short& operator[](int index) { return Data[index]; }
00380     short Data[MaxAction];
00381     };
00382   class MouseClickActions
00383     {
00384   public:
00385     MouseClickActions();
00386     short& Notify() { return Data[0]; }
00387     short& Select() { return Data[1]; }
00388     short& operator[](int index) { return Data[index]; }
00389     short Data[2];
00390     };
00392 
00393   MouseActions Actions;
00394   MouseClickActions ActionsClick;
00395 
00396 private:
00397   vtkChart(const vtkChart &); // Not implemented.
00398   void operator=(const vtkChart &);   // Not implemented.
00399 };
00400 
00401 #endif //__vtkChart_h