1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * BKG NTRIP Client
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: t_polarPlot
|
---|
7 | *
|
---|
8 | * Purpose: Polar Plot
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 23-Jun-2012
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include <qpen.h>
|
---|
19 | #include <qwt_series_data.h>
|
---|
20 | #include <qwt_symbol.h>
|
---|
21 | #include <qwt_polar_grid.h>
|
---|
22 |
|
---|
23 | #include "polarplot.h"
|
---|
24 |
|
---|
25 | // Constructor
|
---|
26 | ////////////////////////////////////////////////////////////////////////////
|
---|
27 | t_polarCurve::t_polarCurve() {
|
---|
28 | }
|
---|
29 |
|
---|
30 | // Destructor (virtual)
|
---|
31 | ////////////////////////////////////////////////////////////////////////////
|
---|
32 | t_polarCurve::~t_polarCurve() {
|
---|
33 | }
|
---|
34 |
|
---|
35 | // Draw Symbols (virtual) - change symbol's color
|
---|
36 | ////////////////////////////////////////////////////////////////////////////
|
---|
37 | void t_polarCurve::drawSymbols(QPainter* painter, const QwtSymbol& symbol,
|
---|
38 | const QwtScaleMap& azimuthMap,
|
---|
39 | const QwtScaleMap& radialMap,
|
---|
40 | const QPointF& pole, int from, int to) const {
|
---|
41 | for (int ii = from; ii <= to; ii++) {
|
---|
42 | QwtSymbol ss(symbol);
|
---|
43 | if (ii % 2 == 0) {
|
---|
44 | ss.setBrush(QBrush(Qt::red));
|
---|
45 | ss.setPen(QPen(Qt::red));
|
---|
46 | }
|
---|
47 | else {
|
---|
48 | ss.setBrush(QBrush(Qt::blue));
|
---|
49 | ss.setPen(QPen(Qt::blue));
|
---|
50 | }
|
---|
51 | QwtPolarCurve::drawSymbols(painter, ss, azimuthMap, radialMap, pole, ii,ii);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | const QwtInterval zenithInterval(0.0, 90.0);
|
---|
57 | const QwtInterval azimuthInterval(0.0, 360.0);
|
---|
58 |
|
---|
59 | // Data Class
|
---|
60 | ////////////////////////////////////////////////////////////////////////////
|
---|
61 | class Data: public QwtSeriesData<QwtPointPolar> {
|
---|
62 | public:
|
---|
63 | Data(const QwtInterval &zenithInterval,
|
---|
64 | const QwtInterval &azimuthInterval, size_t size) :
|
---|
65 | _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
|
---|
66 | _size(size) {}
|
---|
67 |
|
---|
68 | virtual size_t size() const {return _size;}
|
---|
69 |
|
---|
70 | protected:
|
---|
71 | QwtInterval _zenithInterval;
|
---|
72 | QwtInterval _azimuthInterval;
|
---|
73 | size_t _size;
|
---|
74 | };
|
---|
75 |
|
---|
76 | // Spiral Data Class
|
---|
77 | ////////////////////////////////////////////////////////////////////////////
|
---|
78 | class SpiralData: public Data {
|
---|
79 | public:
|
---|
80 | SpiralData(const QwtInterval &zenithInterval,
|
---|
81 | const QwtInterval &azimuthInterval, size_t size) :
|
---|
82 | Data(zenithInterval, azimuthInterval, size) {}
|
---|
83 |
|
---|
84 | virtual QwtPointPolar sample(size_t ii) const {
|
---|
85 | const double stepA = 4 * _azimuthInterval.width() / _size;
|
---|
86 | const double aa = _azimuthInterval.minValue() + ii * stepA;
|
---|
87 |
|
---|
88 | const double stepR = _zenithInterval.width() / _size;
|
---|
89 | const double rr = _zenithInterval.minValue() + ii * stepR;
|
---|
90 |
|
---|
91 | return QwtPointPolar(aa, rr);
|
---|
92 | }
|
---|
93 |
|
---|
94 | virtual QRectF boundingRect() const {
|
---|
95 | if (d_boundingRect.width() < 0.0) {
|
---|
96 | d_boundingRect = qwtBoundingRect(*this);
|
---|
97 | }
|
---|
98 | return d_boundingRect;
|
---|
99 | }
|
---|
100 | };
|
---|
101 |
|
---|
102 | // Constructor
|
---|
103 | ////////////////////////////////////////////////////////////////////////////
|
---|
104 | t_polarPlot::t_polarPlot( QWidget *parent ) :
|
---|
105 | QwtPolarPlot(QwtText("Polar Plot"), parent) {
|
---|
106 |
|
---|
107 | setPlotBackground(Qt::white);
|
---|
108 |
|
---|
109 | setAzimuthOrigin(M_PI/2.0);
|
---|
110 |
|
---|
111 | // Scales
|
---|
112 | // ------
|
---|
113 | setScale(QwtPolar::Radius,
|
---|
114 | zenithInterval.minValue(), zenithInterval.maxValue());
|
---|
115 |
|
---|
116 | setScale(QwtPolar::Azimuth,
|
---|
117 | azimuthInterval.maxValue(), azimuthInterval.minValue(),
|
---|
118 | azimuthInterval.width() / 12);
|
---|
119 |
|
---|
120 | // Grids, Axes
|
---|
121 | // -----------
|
---|
122 | QwtPolarGrid* grid = new QwtPolarGrid();
|
---|
123 | grid->setPen(QPen(Qt::black));
|
---|
124 | for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
|
---|
125 | grid->showGrid(scaleId);
|
---|
126 | }
|
---|
127 |
|
---|
128 | grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
|
---|
129 |
|
---|
130 | grid->showAxis(QwtPolar::AxisAzimuth, true);
|
---|
131 | grid->showAxis(QwtPolar::AxisTop, true);
|
---|
132 | grid->showAxis(QwtPolar::AxisBottom, false);
|
---|
133 | grid->showAxis(QwtPolar::AxisLeft, false);
|
---|
134 | grid->showAxis(QwtPolar::AxisRight, false);
|
---|
135 |
|
---|
136 | grid->showGrid(QwtPolar::Azimuth, true);
|
---|
137 | grid->showGrid(QwtPolar::Radius, true);
|
---|
138 |
|
---|
139 | grid->attach(this);
|
---|
140 |
|
---|
141 | // Curves
|
---|
142 | // ------
|
---|
143 | t_polarCurve* curve = createCurve();
|
---|
144 | curve->attach(this);
|
---|
145 | }
|
---|
146 |
|
---|
147 | // Destructor
|
---|
148 | ////////////////////////////////////////////////////////////////////////////
|
---|
149 | t_polarPlot::~t_polarPlot() {
|
---|
150 | }
|
---|
151 |
|
---|
152 | //
|
---|
153 | ////////////////////////////////////////////////////////////////////////////
|
---|
154 | t_polarCurve* t_polarPlot::createCurve() const {
|
---|
155 | const int numPoints = 200;
|
---|
156 | t_polarCurve* curve = new t_polarCurve();
|
---|
157 | curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
|
---|
158 | curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
|
---|
159 | QBrush(Qt::red), QPen(Qt::red),
|
---|
160 | QSize(3, 3)));
|
---|
161 | curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
|
---|
162 | return curve;
|
---|
163 | }
|
---|