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

Last change on this file since 4315 was 4315, checked in by mervart, 12 years ago
File size: 3.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
25const QwtInterval zenithInterval(0.0, 90.0);
26const QwtInterval azimuthInterval(0.0, 360.0);
27
28// Data Class
29////////////////////////////////////////////////////////////////////////////
30class Data: public QwtSeriesData<QwtPointPolar> {
31 public:
32 Data(const QwtInterval &zenithInterval,
33 const QwtInterval &azimuthInterval, size_t size) :
34 _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
35 _size(size) {}
36
37 virtual size_t size() const {return _size;}
38
39 protected:
40 QwtInterval _zenithInterval;
41 QwtInterval _azimuthInterval;
42 size_t _size;
43};
44
45// Spiral Data Class
46////////////////////////////////////////////////////////////////////////////
47class SpiralData: public Data {
48 public:
49 SpiralData(const QwtInterval &zenithInterval,
50 const QwtInterval &azimuthInterval, size_t size) :
51 Data(zenithInterval, azimuthInterval, size) {}
52
53 virtual QwtPointPolar sample(size_t ii) const {
54 const double stepA = 4 * _azimuthInterval.width() / _size;
55 const double aa = _azimuthInterval.minValue() + ii * stepA;
56
57 const double stepR = _zenithInterval.width() / _size;
58 const double rr = _zenithInterval.minValue() + ii * stepR;
59
60 return QwtPointPolar(aa, rr);
61 }
62
63 virtual QRectF boundingRect() const {
64 if (d_boundingRect.width() < 0.0) {
65 d_boundingRect = qwtBoundingRect(*this);
66 }
67 return d_boundingRect;
68 }
69};
70
71// Constructor
72////////////////////////////////////////////////////////////////////////////
73t_polarPlot::t_polarPlot( QWidget *parent ) :
74QwtPolarPlot(QwtText("Polar Plot"), parent) {
75
76 setPlotBackground(Qt::white);
77
78 // Scales
79 // ------
80 setScale(QwtPolar::Radius,
81 zenithInterval.minValue(), zenithInterval.maxValue());
82
83 setScale(QwtPolar::Azimuth,
84 azimuthInterval.minValue(), azimuthInterval.maxValue(),
85 azimuthInterval.width() / 12);
86
87 // Grids, Axes
88 // -----------
89 QwtPolarGrid* grid = new QwtPolarGrid();
90 grid->setPen(QPen(Qt::black));
91 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
92 grid->showGrid(scaleId);
93 }
94
95 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
96
97 grid->showAxis(QwtPolar::AxisAzimuth, true);
98 grid->showAxis(QwtPolar::AxisTop, true);
99 grid->showAxis(QwtPolar::AxisBottom, false);
100 grid->showAxis(QwtPolar::AxisLeft, false);
101 grid->showAxis(QwtPolar::AxisRight, false);
102
103 grid->showGrid(QwtPolar::Azimuth, true);
104 grid->showGrid(QwtPolar::Radius, true);
105
106 grid->attach(this);
107
108 // Curves
109 // ------
110 QwtPolarCurve* curve = createCurve();
111 curve->attach(this);
112}
113
114// Destructor
115////////////////////////////////////////////////////////////////////////////
116t_polarPlot::~t_polarPlot() {
117}
118
119//
120////////////////////////////////////////////////////////////////////////////
121QwtPolarCurve* t_polarPlot::createCurve() const {
122 const int numPoints = 200;
123 QwtPolarCurve* curve = new QwtPolarCurve();
124 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
125 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
126 QBrush(Qt::red), QPen(Qt::red),
127 QSize(3, 3)));
128 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
129 return curve;
130}
Note: See TracBrowser for help on using the repository browser.