source: ntrip/trunk/BNC/src/rinex/polarplot.cpp@ 4318

Last change on this file since 4318 was 4318, checked in by mervart, 12 years ago
File size: 4.7 KB
Line 
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////////////////////////////////////////////////////////////////////////////
27t_polarCurve::t_polarCurve() {
28}
29
30// Destructor (virtual)
31////////////////////////////////////////////////////////////////////////////
32t_polarCurve::~t_polarCurve() {
33}
34
35// Draw Symbols (virtual) - change symbol's color
36////////////////////////////////////////////////////////////////////////////
37void 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
56const QwtInterval zenithInterval(0.0, 90.0);
57const QwtInterval azimuthInterval(0.0, 360.0);
58
59// Data Class
60////////////////////////////////////////////////////////////////////////////
61class 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////////////////////////////////////////////////////////////////////////////
78class 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////////////////////////////////////////////////////////////////////////////
104t_polarPlot::t_polarPlot( QWidget *parent ) :
105QwtPolarPlot(QwtText("Polar Plot"), parent) {
106
107 setPlotBackground(Qt::white);
108
109 // Scales
110 // ------
111 setScale(QwtPolar::Radius,
112 zenithInterval.minValue(), zenithInterval.maxValue());
113
114 setScale(QwtPolar::Azimuth,
115 azimuthInterval.minValue(), azimuthInterval.maxValue(),
116 azimuthInterval.width() / 12);
117
118 // Grids, Axes
119 // -----------
120 QwtPolarGrid* grid = new QwtPolarGrid();
121 grid->setPen(QPen(Qt::black));
122 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
123 grid->showGrid(scaleId);
124 }
125
126 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
127
128 grid->showAxis(QwtPolar::AxisAzimuth, true);
129 grid->showAxis(QwtPolar::AxisTop, true);
130 grid->showAxis(QwtPolar::AxisBottom, false);
131 grid->showAxis(QwtPolar::AxisLeft, false);
132 grid->showAxis(QwtPolar::AxisRight, false);
133
134 grid->showGrid(QwtPolar::Azimuth, true);
135 grid->showGrid(QwtPolar::Radius, true);
136
137 grid->attach(this);
138
139 // Curves
140 // ------
141 t_polarCurve* curve = createCurve();
142 curve->attach(this);
143}
144
145// Destructor
146////////////////////////////////////////////////////////////////////////////
147t_polarPlot::~t_polarPlot() {
148}
149
150//
151////////////////////////////////////////////////////////////////////////////
152t_polarCurve* t_polarPlot::createCurve() const {
153 const int numPoints = 200;
154 t_polarCurve* curve = new t_polarCurve();
155 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
156 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
157 QBrush(Qt::red), QPen(Qt::red),
158 QSize(3, 3)));
159 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
160 return curve;
161}
Note: See TracBrowser for help on using the repository browser.