File: plotbase.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (108 lines) | stat: -rw-r--r-- 3,145 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef PLOT_PLOTBASE_H
#define PLOT_PLOTBASE_H

#include "horizontalplotscale.h"
#include "verticalplotscale.h"

class PlotBase {
 public:
  PlotBase();

  virtual ~PlotBase() { UnlinkHorizontally(); }

  void Draw(const Cairo::RefPtr<Cairo::Context>& cairo, size_t width,
            size_t height) {
    _width = width;
    _height = height;
    Draw(cairo);
  }

  void LinkHorizontally(PlotBase& other) {
    _horizontalScale.Link(other._horizontalScale);
    _horiScale2.Link(other._horiScale2);
  }

  void UnlinkHorizontally() { _horizontalScale.Unlink(); }

  void LinkVertically(PlotBase& other) {
    _verticalScale.Link(other._verticalScale);
    _vertScale2.Link(other._vertScale2);
  }

  sigc::signal<void>& SignalLinkedRedraw() { return _signalLinkedRedraw; }

  virtual bool ConvertToPlot(double screenX, double screenY, double& posX,
                             double& posY) const = 0;
  virtual bool ConvertToScreen(double posX, double posY, double& screenX,
                               double& screenY) const = 0;

  void ZoomFit();
  void ZoomIn();
  /**
   * Zoom in to a given position, as done when zooming with the scroll wheel.
   * The position is in plot units.
   */
  void ZoomInOn(double x, double y);
  void ZoomOut();
  /**
   * Zoom in to a given rectangle. The positions are in plot units.
   */
  void ZoomTo(double x1, double y1, double x2, double y2);
  /**
   * Move the view by the given displacement. The displacement are in
   * display units.
   */
  void Pan(double xDisplacement, double yDisplacement);
  bool IsZoomedOut() const {
    return _xZoomStart == 0.0 && _xZoomEnd == 1.0 && _yZoomStart == 0.0 &&
           _yZoomEnd == 1.0;
  }
  sigc::signal<void>& OnZoomChanged() { return _onZoomChanged; }

  double XZoomStart() const { return _xZoomStart; }
  double XZoomEnd() const { return _xZoomEnd; }
  double YZoomStart() const { return _yZoomStart; }
  double YZoomEnd() const { return _yZoomEnd; }

  virtual void SavePdf(const std::string& filename, size_t width,
                       size_t height) = 0;
  virtual void SaveSvg(const std::string& filename, size_t width,
                       size_t height) = 0;
  virtual void SavePng(const std::string& filename, size_t width,
                       size_t height) = 0;

  size_t Width() const { return _width; }
  size_t Height() const { return _height; }

 protected:
  struct Rectangle {
    double x, y;
    double width, height;
  };

  virtual Rectangle getPlotArea(size_t width, size_t height) const = 0;

  HorizontalPlotScale _horizontalScale;
  VerticalPlotScale _verticalScale;
  HorizontalPlotScale _horiScale2;
  VerticalPlotScale _vertScale2;

 protected:
  virtual void Draw(const Cairo::RefPtr<Cairo::Context>& cairo) = 0;

 private:
  std::shared_ptr<std::vector<PlotBase*>> _verticallyLinked;
  sigc::signal<void> _signalLinkedRedraw;
  sigc::signal<void> _onZoomChanged;

  /**
   * Values between 0.0 and 1.0 indicating the zoom.
   * @{
   */
  double _xZoomStart = 0.0, _xZoomEnd = 1.0;
  double _yZoomStart = 0.0, _yZoomEnd = 1.0;
  /** @} */
  size_t _width = 0, _height = 0;
};

#endif  // PLOT_PLOTBASE_H