source: ntrip/trunk/BNC/src/rinex/availplot.cpp@ 7549

Last change on this file since 7549 was 6542, checked in by mervart, 10 years ago
File size: 6.8 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_availPlot
30 *
31 * Purpose: Plot with satellite availability
32 *
33 * Author: L. Mervart
34 *
35 * Created: 30-Aug-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <qwt_scale_draw.h>
42#include <qwt_text.h>
43#include <qwt_legend.h>
44#include <qwt_plot_canvas.h>
45
46#include "availplot.h"
47#include "reqcanalyze.h"
48
49//
50//////////////////////////////////////////////////////////////////////////////
51class t_scaleDrawTime : public QwtScaleDraw {
52 public:
53 t_scaleDrawTime() {}
54 virtual QwtText label(double mjdX24) const {
55 bncTime epoTime; epoTime.setmjd(mjdX24/24.0);
56 return QwtText(epoTime.timestr(0,':').c_str());
57 }
58};
59
60//
61//////////////////////////////////////////////////////////////////////////////
62class t_scaleDrawPrn : public QwtScaleDraw {
63 public:
64 t_scaleDrawPrn() {}
65 virtual QwtText label(double iPrn) const {
66 return _yLabels[int(iPrn)];
67 }
68 QMap<int, QString> _yLabels;
69};
70
71// Constructor
72//////////////////////////////////////////////////////////////////////////////
73t_availPlot::t_availPlot(QWidget* parent, const QMap<t_prn, t_plotData>& plotDataMap) :
74QwtPlot(parent) {
75
76 setCanvasBackground(QColor(Qt::white));
77 canvas()->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
78
79 // Axes
80 // ----
81 setAxisScaleDraw(QwtPlot::xBottom, new t_scaleDrawTime());
82 setAxisLabelRotation(QwtPlot::xBottom, -10.0);
83 setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
84
85 t_scaleDrawPrn* scaleDrawPrn = new t_scaleDrawPrn();
86 setAxisScaleDraw(QwtPlot::yLeft, scaleDrawPrn);
87
88 // Smaller Font for y-Axis
89 // -----------------------
90 QFont yFont = axisFont(QwtPlot::yLeft);
91 yFont.setPointSize(yFont.pointSize()/2);
92 setAxisFont(QwtPlot::yLeft, yFont);
93
94 // Symbols
95 // -------
96 QColor red(220,20,60);
97 QColor green(150,200,50);
98 QColor blue(60,100,200);
99 QwtSymbol symbRed(QwtSymbol::Rect, QBrush(red), QPen(red), QSize(2,1));
100 QwtSymbol symbGreen(QwtSymbol::Rect, QBrush(green), QPen(green), QSize(2,1));
101 QwtSymbol symbBlue (QwtSymbol::Rect, QBrush(blue), QPen(blue), QSize(2,1));
102
103 // Legend
104 // ------
105 QwtLegend* legend = new QwtLegend;
106 insertLegend(legend, QwtPlot::RightLegend);
107
108 QVector<double> xData0(0);
109 QVector<double> yData0(0);
110 addCurve("OK ", symbGreen, xData0, yData0);
111 addCurve("Gap ", symbBlue, xData0, yData0);
112 addCurve("Slip", symbRed, xData0, yData0);
113
114 // Curves
115 // ------
116 int iC = 0;
117 QMapIterator<t_prn, t_plotData > it(plotDataMap);
118 while (it.hasNext()) {
119 it.next();
120 ++iC;
121 QString prn = QString(it.key().toString().c_str());
122 const t_plotData& plotData = it.value();
123
124 scaleDrawPrn->_yLabels[iC] = prn;
125
126 double eps = 0.1;
127
128 // L1 ok Curve
129 // -----------
130 if (plotData._L1ok.size()) {
131 const QVector<double>& xData = plotData._L1ok;
132 QVector<double> yData(xData.size(), double(iC)+eps);
133 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
134 curve->setItemAttribute(QwtPlotItem::Legend, false);
135 }
136
137 // L2 ok Curve
138 // -----------
139 if (plotData._L2ok.size()) {
140 const QVector<double>& xData = plotData._L2ok;
141 QVector<double> yData(xData.size(), double(iC)-eps);
142 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
143 curve->setItemAttribute(QwtPlotItem::Legend, false);
144 }
145
146 // L1 gaps Curve
147 // -------------
148 if (plotData._L1gap.size()) {
149 const QVector<double>& xData = plotData._L1gap;
150 QVector<double> yData(xData.size(), double(iC)+eps);
151 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
152 curve->setItemAttribute(QwtPlotItem::Legend, false);
153 }
154
155 // L2 gaps Curve
156 // -------------
157 if (plotData._L2gap.size()) {
158 const QVector<double>& xData = plotData._L2gap;
159 QVector<double> yData(xData.size(), double(iC)-eps);
160 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
161 curve->setItemAttribute(QwtPlotItem::Legend, false);
162 }
163
164 // L1 slips Curve
165 // --------------
166 if (plotData._L1slip.size()) {
167 const QVector<double>& xData = plotData._L1slip;
168 QVector<double> yData(xData.size(), double(iC)+eps);
169 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
170 curve->setItemAttribute(QwtPlotItem::Legend, false);
171 }
172
173 // L2 slips Curve
174 // --------------
175 if (plotData._L2slip.size()) {
176 const QVector<double>& xData = plotData._L2slip;
177 QVector<double> yData(xData.size(), double(iC)-eps);
178 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
179 curve->setItemAttribute(QwtPlotItem::Legend, false);
180 }
181 }
182
183 QList<double> ticks[QwtScaleDiv::NTickTypes];
184 QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
185 QMapIterator<int, QString> itT(scaleDrawPrn->_yLabels);
186 while (itT.hasNext()) {
187 itT.next();
188 majorTicks << double(itT.key());
189 }
190 QwtScaleDiv yScaleDiv(majorTicks.first()-0.5, majorTicks.last()+0.5, ticks );
191 setAxisScaleDiv(QwtPlot::yLeft, yScaleDiv);
192
193 // Important !!!
194 // -------------
195 replot();
196}
197
198// Add Curve
199//////////////////////////////////////////////////////////////////////////////
200QwtPlotCurve* t_availPlot::addCurve(const QString& name,
201 const QwtSymbol& symbol,
202 const QVector<double>& xData,
203 const QVector<double>& yData) {
204 QwtPlotCurve* curve = new QwtPlotCurve(name);
205 curve->setSymbol(new QwtSymbol(symbol));
206 curve->setStyle(QwtPlotCurve::NoCurve);
207 curve->setXAxis(QwtPlot::xBottom);
208 curve->setYAxis(QwtPlot::yLeft);
209 curve->setSamples(xData, yData);
210 curve->attach(this);
211 return curve;
212}
Note: See TracBrowser for help on using the repository browser.