vtkChartMatrix.h 4.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkChartMatrix.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

16 17 18 19 20 21 22 23 24
/**
 * @class   vtkChartMatrix
 * @brief   container for a matrix of charts.
 *
 *
 * This class contains a matrix of charts. These charts will be of type
 * vtkChartXY by default, but this can be overridden. The class will manage
 * their layout and object lifetime.
*/
25

26 27
#ifndef vtkChartMatrix_h
#define vtkChartMatrix_h
28

29
#include "vtkChartsCoreModule.h" // For export macro
30 31 32
#include "vtkAbstractContextItem.h"
#include "vtkVector.h" // For ivars

33 34 35
#include <map> // For specific gutter
#include <utility> // For specific gutter

36 37
class vtkChart;

38
class VTKCHARTSCORE_EXPORT vtkChartMatrix : public vtkAbstractContextItem
39 40 41
{
public:
  vtkTypeMacro(vtkChartMatrix, vtkAbstractContextItem);
42
  void PrintSelf(ostream &os, vtkIndent indent) override;
43

44 45 46
  /**
   * Creates a new object.
   */
47 48
  static vtkChartMatrix *New();

49 50 51
  /**
   * Perform any updates to the item that may be necessary before rendering.
   */
52
  void Update() override;
53

54 55 56
  /**
   * Paint event for the chart matrix.
   */
57
  bool Paint(vtkContext2D *painter) override;
58

59 60 61 62 63
  /**
   * Set the width and height of the chart matrix. This will cause an immediate
   * resize of the chart matrix, the default size is 0x0 (no charts). No chart
   * objects are created until Allocate is called.
   */
64 65
  virtual void SetSize(const vtkVector2i& size);

66 67 68
  /**
   * Get the width and height of the chart matrix.
   */
69 70
  virtual vtkVector2i GetSize() const { return this->Size; }

71 72 73 74
  //@{
  /**
   * Set/get the borders of the chart matrix (space in pixels around each chart).
   */
75
  virtual void SetBorders(int left, int bottom, int right, int top);
76 77 78 79
  void SetBorderLeft(int value);
  void SetBorderBottom(int value);
  void SetBorderRight(int value);
  void SetBorderTop(int value);
80 81 82
  virtual void GetBorders(int borders[4])
  {
    for(int i=0;i<4;i++)
83
    {
84
      borders[i]=this->Borders[i];
85
    }
86
  }
87
  //@}
88

89 90 91 92
  //@{
  /**
   * Set the gutter that should be left between the charts in the matrix.
   */
93
  virtual void SetGutter(const vtkVector2f& gutter);
94 95
  void SetGutterX(float value);
  void SetGutterY(float value);
96
  //@}
97

98 99 100 101
  //@{
  /**
   * Set a specific resize that will move the bottom left point of a chart.
   */
102 103
  virtual void SetSpecificResize(const vtkVector2i& index, const vtkVector2f& resize);
  virtual void ClearSpecificResizes();
104
  //@}
105

106 107 108
  /**
   * Get the gutter that should be left between the charts in the matrix.
   */
109 110
  virtual vtkVector2f GetGutter() const { return this->Gutter; }

111 112 113
  /**
   * Allocate the charts, this will cause any null chart to be allocated.
   */
114 115
  virtual void Allocate();

116 117 118 119 120 121
  /**
   * Set the chart element, note that the chart matrix must be large enough to
   * accommodate the element being set. Note that this class will take ownership
   * of the chart object.
   * \return false if the element cannot be set.
   */
122 123
  virtual bool SetChart(const vtkVector2i& position, vtkChart* chart);

124
  /**
125
   * Get the specified chart element, if the element does not exist nullptr will be
126 127 128
   * returned. If the chart element has not yet been allocated it will be at
   * this point.
   */
129 130
  virtual vtkChart* GetChart(const vtkVector2i& position);

131 132 133 134 135
  /**
   * Set the span of a chart in the matrix. This defaults to 1x1, and cannot
   * exceed the remaining space in x or y.
   * \return false If the span is not possible.
   */
136 137 138
  virtual bool SetChartSpan(const vtkVector2i& position,
                            const vtkVector2i& span);

139 140 141
  /**
   * Get the span of the specified chart.
   */
142 143
  virtual vtkVector2i GetChartSpan(const vtkVector2i& position);

144 145 146 147
  /**
   * Get the position of the chart in the matrix at the specified location.
   * The position should be specified in scene coordinates.
   */
148 149
  virtual vtkVector2i GetChartIndex(const vtkVector2f& position);

150 151
protected:
  vtkChartMatrix();
152
  ~vtkChartMatrix() override;
153

154
  // The number of charts in x and y.
155 156
  vtkVector2i Size;

157 158
  // The gutter between each chart.
  vtkVector2f Gutter;
159
  std::map<vtkVector2i, vtkVector2f> SpecificResize;
160
  int Borders[4];
161
  bool LayoutIsDirty;
162

163
private:
164 165
  vtkChartMatrix(const vtkChartMatrix &) = delete;
  void operator=(const vtkChartMatrix &) = delete;
166 167 168

  class PIMPL;
  PIMPL *Private;
169 170
};

171
#endif //vtkChartMatrix_h