[4302] | 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 |
|
---|
[4316] | 25 | // Constructor
|
---|
| 26 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 27 | t_polarCurve::t_polarCurve() {
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | // Destructor (virtual)
|
---|
| 31 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 32 | t_polarCurve::~t_polarCurve() {
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[4317] | 35 | // Draw Symbols (virtual) - change symbol's color
|
---|
[4316] | 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++) {
|
---|
[4317] | 42 | QwtSymbol ss(symbol);
|
---|
| 43 | if (ii % 2 == 0) {
|
---|
[4318] | 44 | ss.setBrush(QBrush(Qt::red));
|
---|
[4317] | 45 | ss.setPen(QPen(Qt::red));
|
---|
| 46 | }
|
---|
| 47 | else {
|
---|
[4318] | 48 | ss.setBrush(QBrush(Qt::blue));
|
---|
[4317] | 49 | ss.setPen(QPen(Qt::blue));
|
---|
| 50 | }
|
---|
| 51 | QwtPolarCurve::drawSymbols(painter, ss, azimuthMap, radialMap, pole, ii,ii);
|
---|
[4316] | 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[4320] | 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 | }
|
---|
[4316] | 64 |
|
---|
[4320] | 65 | // Sample (virtual)
|
---|
[4302] | 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4320] | 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;
|
---|
[4302] | 70 |
|
---|
[4320] | 71 | const double stepR = _zenithInterval.width() / _size;
|
---|
| 72 | const double rr = _zenithInterval.minValue() + ii * stepR;
|
---|
[4302] | 73 |
|
---|
[4320] | 74 | return t_polarPoint(aa, rr);
|
---|
| 75 | }
|
---|
[4302] | 76 |
|
---|
[4320] | 77 | // Bounding Box (virtual)
|
---|
[4302] | 78 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4320] | 79 | QRectF t_polarData::boundingRect() const {
|
---|
| 80 | return d_boundingRect;
|
---|
| 81 | }
|
---|
[4302] | 82 |
|
---|
| 83 | // Constructor
|
---|
| 84 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 85 | t_polarPlot::t_polarPlot( QWidget *parent ) :
|
---|
[4311] | 86 | QwtPolarPlot(QwtText("Polar Plot"), parent) {
|
---|
[4302] | 87 |
|
---|
[4313] | 88 | setPlotBackground(Qt::white);
|
---|
[4302] | 89 |
|
---|
[4319] | 90 | setAzimuthOrigin(M_PI/2.0);
|
---|
| 91 |
|
---|
[4302] | 92 | // Scales
|
---|
| 93 | // ------
|
---|
[4320] | 94 | setScale(QwtPolar::Radius, 0.0, 90.0);
|
---|
| 95 | setScale(QwtPolar::Azimuth, 360.0, 0, 30.0);
|
---|
[4311] | 96 |
|
---|
[4302] | 97 | // Grids, Axes
|
---|
| 98 | // -----------
|
---|
[4314] | 99 | QwtPolarGrid* grid = new QwtPolarGrid();
|
---|
| 100 | grid->setPen(QPen(Qt::black));
|
---|
[4302] | 101 | for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
|
---|
[4314] | 102 | grid->showGrid(scaleId);
|
---|
[4302] | 103 | }
|
---|
| 104 |
|
---|
[4314] | 105 | grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
|
---|
[4302] | 106 |
|
---|
[4314] | 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);
|
---|
[4311] | 112 |
|
---|
[4314] | 113 | grid->showGrid(QwtPolar::Azimuth, true);
|
---|
| 114 | grid->showGrid(QwtPolar::Radius, true);
|
---|
[4311] | 115 |
|
---|
[4314] | 116 | grid->attach(this);
|
---|
[4302] | 117 |
|
---|
| 118 | // Curves
|
---|
| 119 | // ------
|
---|
[4316] | 120 | t_polarCurve* curve = createCurve();
|
---|
[4302] | 121 | curve->attach(this);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[4309] | 124 | // Destructor
|
---|
| 125 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 126 | t_polarPlot::~t_polarPlot() {
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[4302] | 129 | //
|
---|
| 130 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4316] | 131 | t_polarCurve* t_polarPlot::createCurve() const {
|
---|
[4302] | 132 | const int numPoints = 200;
|
---|
[4316] | 133 | t_polarCurve* curve = new t_polarCurve();
|
---|
[4312] | 134 | curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
|
---|
| 135 | curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
|
---|
[4313] | 136 | QBrush(Qt::red), QPen(Qt::red),
|
---|
[4311] | 137 | QSize(3, 3)));
|
---|
[4320] | 138 | QwtSeriesData<t_polarPoint>* data = new t_polarData(numPoints);
|
---|
| 139 | curve->setData((QwtSeriesData<QwtPointPolar>*) data);
|
---|
[4302] | 140 | return curve;
|
---|
| 141 | }
|
---|