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

Last change on this file since 8555 was 8555, checked in by mervart, 19 months ago

Analyze more than two signals

File size: 6.2 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  ((QwtPlotCanvas *)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.0;
127
128    for (QMap<char, t_plotData::t_hlpStatus >::const_iterator it = plotData._status.begin();
129      it != plotData._status.end(); it++) {
130
131      const t_plotData::t_hlpStatus& status = it.value();
132
133      // OK Curve
134      // --------
135      if (status._ok.size()) {
136        const QVector<double>& xData = status._ok;
137        QVector<double>        yData(xData.size(), double(iC)+eps);
138        QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
139        curve->setItemAttribute(QwtPlotItem::Legend, false);
140      }
141 
142      // Gaps Curve
143      // ----------
144      if (status._gap.size()) {
145        const QVector<double>& xData = status._gap;
146        QVector<double>        yData(xData.size(), double(iC)+eps);
147        QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
148        curve->setItemAttribute(QwtPlotItem::Legend, false);
149      }
150 
151      // Slips Curve
152      // -----------
153      if (status._slip.size()) {
154        const QVector<double>& xData = status._slip;
155        QVector<double>        yData(xData.size(), double(iC)+eps);
156        QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
157        curve->setItemAttribute(QwtPlotItem::Legend, false);
158      }
159
160      eps += 0.1;
161    }
162  }
163 
164  QList<double> ticks[QwtScaleDiv::NTickTypes];
165  QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
166  QMapIterator<int, QString> itT(scaleDrawPrn->_yLabels);
167  while (itT.hasNext()) {
168    itT.next();
169    majorTicks << double(itT.key());
170  }
171  QwtScaleDiv yScaleDiv(majorTicks.first()-0.5, majorTicks.last()+0.5, ticks );
172  setAxisScaleDiv(QwtPlot::yLeft, yScaleDiv);
173
174  // Important !!!
175  // -------------
176  replot();
177}
178
179// Add Curve
180//////////////////////////////////////////////////////////////////////////////
181QwtPlotCurve* t_availPlot::addCurve(const QString& name, 
182                                    const QwtSymbol& symbol,
183                                    const QVector<double>& xData,
184                                    const QVector<double>& yData) {
185  QwtPlotCurve* curve = new QwtPlotCurve(name);
186  QwtSymbol *s = new QwtSymbol(symbol.style());
187  s->setSize(symbol.size());
188  s->setBrush(symbol.brush());
189  s->setPen(symbol.pen());
190  curve->setSymbol(s);
191  curve->setStyle(QwtPlotCurve::NoCurve);
192  curve->setXAxis(QwtPlot::xBottom);
193  curve->setYAxis(QwtPlot::yLeft);
194  curve->setSamples(xData, yData);
195  curve->attach(this);
196  return curve;
197}
Note: See TracBrowser for help on using the repository browser.