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 | // Constructor
|
---|
56 | ////////////////////////////////////////////////////////////////////////////
|
---|
57 | t_polarData::t_polarData(size_t size) {
|
---|
58 | _zenithInterval.setMinValue(0.0);
|
---|
59 | _zenithInterval.setMaxValue(90.0);
|
---|
60 | _azimuthInterval.setMinValue(0.0);
|
---|
61 | _azimuthInterval.setMaxValue(360.0);
|
---|
62 | _size = size;
|
---|
63 | }
|
---|
64 |
|
---|
65 | // Sample (virtual)
|
---|
66 | ////////////////////////////////////////////////////////////////////////////
|
---|
67 | t_polarPoint t_polarData::sample(size_t ii) const {
|
---|
68 | const double stepA = 4 * _azimuthInterval.width() / _size;
|
---|
69 | const double aa = _azimuthInterval.minValue() + ii * stepA;
|
---|
70 |
|
---|
71 | const double stepR = _zenithInterval.width() / _size;
|
---|
72 | const double rr = _zenithInterval.minValue() + ii * stepR;
|
---|
73 |
|
---|
74 | return t_polarPoint(aa, rr);
|
---|
75 | }
|
---|
76 |
|
---|
77 | // Bounding Box (virtual)
|
---|
78 | ////////////////////////////////////////////////////////////////////////////
|
---|
79 | QRectF t_polarData::boundingRect() const {
|
---|
80 | return d_boundingRect;
|
---|
81 | }
|
---|
82 |
|
---|
83 | // Constructor
|
---|
84 | ////////////////////////////////////////////////////////////////////////////
|
---|
85 | t_polarPlot::t_polarPlot( QWidget *parent ) :
|
---|
86 | QwtPolarPlot(QwtText("Polar Plot"), parent) {
|
---|
87 |
|
---|
88 | setPlotBackground(Qt::white);
|
---|
89 |
|
---|
90 | setAzimuthOrigin(M_PI/2.0);
|
---|
91 |
|
---|
92 | // Scales
|
---|
93 | // ------
|
---|
94 | setScale(QwtPolar::Radius, 0.0, 90.0);
|
---|
95 | setScale(QwtPolar::Azimuth, 360.0, 0, 30.0);
|
---|
96 |
|
---|
97 | // Grids, Axes
|
---|
98 | // -----------
|
---|
99 | QwtPolarGrid* grid = new QwtPolarGrid();
|
---|
100 | grid->setPen(QPen(Qt::black));
|
---|
101 | for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
|
---|
102 | grid->showGrid(scaleId);
|
---|
103 | }
|
---|
104 |
|
---|
105 | grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
|
---|
106 |
|
---|
107 | grid->showAxis(QwtPolar::AxisAzimuth, true);
|
---|
108 | grid->showAxis(QwtPolar::AxisTop, true);
|
---|
109 | grid->showAxis(QwtPolar::AxisBottom, false);
|
---|
110 | grid->showAxis(QwtPolar::AxisLeft, false);
|
---|
111 | grid->showAxis(QwtPolar::AxisRight, false);
|
---|
112 |
|
---|
113 | grid->showGrid(QwtPolar::Azimuth, true);
|
---|
114 | grid->showGrid(QwtPolar::Radius, true);
|
---|
115 |
|
---|
116 | grid->attach(this);
|
---|
117 |
|
---|
118 | // Curves
|
---|
119 | // ------
|
---|
120 | t_polarCurve* curve = createCurve();
|
---|
121 | curve->attach(this);
|
---|
122 | }
|
---|
123 |
|
---|
124 | // Destructor
|
---|
125 | ////////////////////////////////////////////////////////////////////////////
|
---|
126 | t_polarPlot::~t_polarPlot() {
|
---|
127 | }
|
---|
128 |
|
---|
129 | //
|
---|
130 | ////////////////////////////////////////////////////////////////////////////
|
---|
131 | t_polarCurve* t_polarPlot::createCurve() const {
|
---|
132 | const int numPoints = 200;
|
---|
133 | t_polarCurve* curve = new t_polarCurve();
|
---|
134 | curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
|
---|
135 | curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
|
---|
136 | QBrush(Qt::red), QPen(Qt::red),
|
---|
137 | QSize(3, 3)));
|
---|
138 | QwtSeriesData<t_polarPoint>* data = new t_polarData(numPoints);
|
---|
139 | curve->setData((QwtSeriesData<QwtPointPolar>*) data);
|
---|
140 | return curve;
|
---|
141 | }
|
---|