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

Last change on this file since 6261 was 6261, checked in by mervart, 5 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[iPrn];
67  }
68  QMap<int, QString> _yLabels;
69};
70
71// Constructor
72//////////////////////////////////////////////////////////////////////////////
73t_availPlot::t_availPlot(QWidget* parent, 
74                        QMap<QString, t_availData>* availDataMap) 
75: QwtPlot(parent) {
76
77  setCanvasBackground(QColor(Qt::white));
78  canvas()->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
79
80  // Axes
81  // ----
82  setAxisScaleDraw(QwtPlot::xBottom, new t_scaleDrawTime());
83  setAxisLabelRotation(QwtPlot::xBottom, -10.0);
84  setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
85
86  t_scaleDrawPrn* scaleDrawPrn = new t_scaleDrawPrn();
87  setAxisScaleDraw(QwtPlot::yLeft, scaleDrawPrn);
88
89  // Smaller Font for y-Axis
90  // -----------------------
91  QFont yFont = axisFont(QwtPlot::yLeft);
92  yFont.setPointSize(yFont.pointSize()/2);
93  setAxisFont(QwtPlot::yLeft, yFont);
94
95  // Symbols
96  // -------
97  QColor red(220,20,60);
98  QColor green(150,200,50);
99  QColor blue(60,100,200);
100  QwtSymbol symbRed(QwtSymbol::Rect, QBrush(red), QPen(red), QSize(2,1));
101  QwtSymbol symbGreen(QwtSymbol::Rect, QBrush(green), QPen(green), QSize(2,1));
102  QwtSymbol symbBlue (QwtSymbol::Rect, QBrush(blue), QPen(blue), QSize(2,1));
103
104  // Legend
105  // ------
106  QwtLegend* legend = new QwtLegend;
107  insertLegend(legend, QwtPlot::RightLegend);
108
109  QVector<double> xData0(0);
110  QVector<double> yData0(0);
111  addCurve("OK  ", symbGreen, xData0, yData0);
112  addCurve("Gap ", symbBlue,  xData0, yData0);
113  addCurve("Slip", symbRed,   xData0, yData0);
114 
115  // Curves
116  // ------
117  int iC = 0;
118  QMapIterator<QString, t_availData > it(*availDataMap);
119  while (it.hasNext()) {
120    it.next();
121    ++iC;
122    const QString&         prn       = it.key();
123    const t_availData&     availData = it.value();
124
125    scaleDrawPrn->_yLabels[iC] = prn;
126
127    double eps = 0.1;
128
129    // L1 ok Curve
130    // -----------
131    if (availData._L1ok.size()) {
132      const QVector<double>& xData = availData._L1ok;
133      QVector<double>        yData(xData.size(), double(iC)+eps);
134      QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
135      curve->setItemAttribute(QwtPlotItem::Legend, false);
136    }
137
138    // L2 ok Curve
139    // -----------
140    if (availData._L2ok.size()) {
141      const QVector<double>& xData = availData._L2ok;
142      QVector<double>        yData(xData.size(), double(iC)-eps);
143      QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
144      curve->setItemAttribute(QwtPlotItem::Legend, false);
145    }
146
147    // L1 gaps Curve
148    // -------------
149    if (availData._L1gap.size()) {
150      const QVector<double>& xData = availData._L1gap;
151      QVector<double>        yData(xData.size(), double(iC)+eps);
152      QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
153      curve->setItemAttribute(QwtPlotItem::Legend, false);
154    }
155
156    // L2 gaps Curve
157    // -------------
158    if (availData._L2gap.size()) {
159      const QVector<double>& xData = availData._L2gap;
160      QVector<double>        yData(xData.size(), double(iC)-eps);
161      QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
162      curve->setItemAttribute(QwtPlotItem::Legend, false);
163    }
164
165    // L1 slips Curve
166    // --------------
167    if (availData._L1slip.size()) {
168      const QVector<double>& xData = availData._L1slip;
169      QVector<double>        yData(xData.size(), double(iC)+eps);
170      QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
171      curve->setItemAttribute(QwtPlotItem::Legend, false);
172    }
173
174    // L2 slips Curve
175    // --------------
176    if (availData._L2slip.size()) {
177      const QVector<double>& xData = availData._L2slip;
178      QVector<double>        yData(xData.size(), double(iC)-eps);
179      QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
180      curve->setItemAttribute(QwtPlotItem::Legend, false);
181    }
182  }
183 
184  QList<double> ticks[QwtScaleDiv::NTickTypes];
185  QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
186  QMapIterator<int, QString> itT(scaleDrawPrn->_yLabels);
187  while (itT.hasNext()) {
188    itT.next();
189    majorTicks << double(itT.key());
190  }
191  QwtScaleDiv yScaleDiv(majorTicks.first()-0.5, majorTicks.last()+0.5, ticks );
192  setAxisScaleDiv(QwtPlot::yLeft, yScaleDiv);
193
194  // Important !!!
195  // -------------
196  replot();
197}
198
199// Add Curve
200//////////////////////////////////////////////////////////////////////////////
201QwtPlotCurve* t_availPlot::addCurve(const QString& name, 
202                                    const QwtSymbol& symbol,
203                                    const QVector<double>& xData,
204                                    const QVector<double>& yData) {
205  QwtPlotCurve* curve = new QwtPlotCurve(name);
206  curve->setSymbol(new QwtSymbol(symbol));
207  curve->setStyle(QwtPlotCurve::NoCurve);
208  curve->setXAxis(QwtPlot::xBottom);
209  curve->setYAxis(QwtPlot::yLeft);
210  curve->setSamples(xData, yData);
211  curve->attach(this);
212  return curve;
213}
Note: See TracBrowser for help on using the repository browser.