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

Last change on this file since 4317 was 4317, checked in by mervart, 12 years ago
File size: 4.6 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.setPen(QPen(Qt::red));
45 }
46 else {
47 ss.setPen(QPen(Qt::blue));
48 }
49 QwtPolarCurve::drawSymbols(painter, ss, azimuthMap, radialMap, pole, ii,ii);
50 }
51}
52
53
54const QwtInterval zenithInterval(0.0, 90.0);
55const QwtInterval azimuthInterval(0.0, 360.0);
56
57// Data Class
58////////////////////////////////////////////////////////////////////////////
59class Data: public QwtSeriesData<QwtPointPolar> {
60 public:
61 Data(const QwtInterval &zenithInterval,
62 const QwtInterval &azimuthInterval, size_t size) :
63 _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
64 _size(size) {}
65
66 virtual size_t size() const {return _size;}
67
68 protected:
69 QwtInterval _zenithInterval;
70 QwtInterval _azimuthInterval;
71 size_t _size;
72};
73
74// Spiral Data Class
75////////////////////////////////////////////////////////////////////////////
76class SpiralData: public Data {
77 public:
78 SpiralData(const QwtInterval &zenithInterval,
79 const QwtInterval &azimuthInterval, size_t size) :
80 Data(zenithInterval, azimuthInterval, size) {}
81
82 virtual QwtPointPolar sample(size_t ii) const {
83 const double stepA = 4 * _azimuthInterval.width() / _size;
84 const double aa = _azimuthInterval.minValue() + ii * stepA;
85
86 const double stepR = _zenithInterval.width() / _size;
87 const double rr = _zenithInterval.minValue() + ii * stepR;
88
89 return QwtPointPolar(aa, rr);
90 }
91
92 virtual QRectF boundingRect() const {
93 if (d_boundingRect.width() < 0.0) {
94 d_boundingRect = qwtBoundingRect(*this);
95 }
96 return d_boundingRect;
97 }
98};
99
100// Constructor
101////////////////////////////////////////////////////////////////////////////
102t_polarPlot::t_polarPlot( QWidget *parent ) :
103QwtPolarPlot(QwtText("Polar Plot"), parent) {
104
105 setPlotBackground(Qt::white);
106
107 // Scales
108 // ------
109 setScale(QwtPolar::Radius,
110 zenithInterval.minValue(), zenithInterval.maxValue());
111
112 setScale(QwtPolar::Azimuth,
113 azimuthInterval.minValue(), azimuthInterval.maxValue(),
114 azimuthInterval.width() / 12);
115
116 // Grids, Axes
117 // -----------
118 QwtPolarGrid* grid = new QwtPolarGrid();
119 grid->setPen(QPen(Qt::black));
120 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
121 grid->showGrid(scaleId);
122 }
123
124 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
125
126 grid->showAxis(QwtPolar::AxisAzimuth, true);
127 grid->showAxis(QwtPolar::AxisTop, true);
128 grid->showAxis(QwtPolar::AxisBottom, false);
129 grid->showAxis(QwtPolar::AxisLeft, false);
130 grid->showAxis(QwtPolar::AxisRight, false);
131
132 grid->showGrid(QwtPolar::Azimuth, true);
133 grid->showGrid(QwtPolar::Radius, true);
134
135 grid->attach(this);
136
137 // Curves
138 // ------
139 t_polarCurve* curve = createCurve();
140 curve->attach(this);
141}
142
143// Destructor
144////////////////////////////////////////////////////////////////////////////
145t_polarPlot::~t_polarPlot() {
146}
147
148//
149////////////////////////////////////////////////////////////////////////////
150t_polarCurve* t_polarPlot::createCurve() const {
151 const int numPoints = 200;
152 t_polarCurve* curve = new t_polarCurve();
153 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
154 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
155 QBrush(Qt::red), QPen(Qt::red),
156 QSize(3, 3)));
157 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
158 return curve;
159}
Note: See TracBrowser for help on using the repository browser.