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

Last change on this file since 4617 was 4617, checked in by mervart, 12 years ago
File size: 5.2 KB
Line 
1
2#include <qwt_scale_draw.h>
3#include <qwt_text.h>
4#include <qwt_legend.h>
5
6#include "availplot.h"
7#include "reqcanalyze.h"
8
9//
10//////////////////////////////////////////////////////////////////////////////
11class t_scaleDrawTime : public QwtScaleDraw {
12 public:
13 t_scaleDrawTime() {}
14 virtual QwtText label(double mjdX24) const {
15 bncTime epoTime; epoTime.setmjd(mjdX24/24.0);
16 return QwtText(epoTime.timestr(0,':').c_str());
17 }
18};
19
20//
21//////////////////////////////////////////////////////////////////////////////
22class t_scaleDrawPrn : public QwtScaleDraw {
23 public:
24 t_scaleDrawPrn() {}
25 virtual QwtText label(double iPrn) const {
26 return _yLabels[iPrn];
27 }
28 QMap<int, QString> _yLabels;
29};
30
31// Constructor
32//////////////////////////////////////////////////////////////////////////////
33t_availPlot::t_availPlot(QWidget* parent,
34 QMap<QString, t_availData>* availDataMap)
35: QwtPlot(parent) {
36
37 setCanvasBackground(QColor(Qt::white));
38
39 // Axes
40 // ----
41 setAxisScaleDraw(QwtPlot::xBottom, new t_scaleDrawTime());
42 setAxisLabelRotation(QwtPlot::xBottom, -10.0);
43 setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
44
45 t_scaleDrawPrn* scaleDrawPrn = new t_scaleDrawPrn();
46 setAxisScaleDraw(QwtPlot::yLeft, scaleDrawPrn);
47
48 // Symbols
49 // -------
50 QColor red(220,20,60);
51 QColor green(150,200,50);
52 QColor blue(60,100,200);
53 QwtSymbol symbRed(QwtSymbol::Rect, QBrush(red), QPen(red), QSize(2,1));
54 QwtSymbol symbGreen(QwtSymbol::Rect, QBrush(green), QPen(green), QSize(2,1));
55 QwtSymbol symbBlue (QwtSymbol::Rect, QBrush(blue), QPen(blue), QSize(2,1));
56
57 // Legend
58 // ------
59 QwtLegend* legend = new QwtLegend;
60 insertLegend(legend, QwtPlot::RightLegend);
61
62 QVector<double> xData0(0);
63 QVector<double> yData0(0);
64 addCurve("OK ", symbGreen, xData0, yData0);
65 addCurve("Gap ", symbBlue, xData0, yData0);
66 addCurve("Slip", symbRed, xData0, yData0);
67
68 // Curves
69 // ------
70 int iC = 0;
71 QMapIterator<QString, t_availData > it(*availDataMap);
72 while (it.hasNext()) {
73 it.next();
74 ++iC;
75 const QString& prn = it.key();
76 const t_availData& availData = it.value();
77
78 scaleDrawPrn->_yLabels[iC] = prn;
79
80 double eps = 0.1;
81
82 // L1 ok Curve
83 // -----------
84 if (availData._L1ok.size()) {
85 const QVector<double>& xData = availData._L1ok;
86 QVector<double> yData(xData.size(), double(iC)+eps);
87 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
88 curve->setItemAttribute(QwtPlotItem::Legend, false);
89 }
90
91 // L2 ok Curve
92 // -----------
93 if (availData._L2ok.size()) {
94 const QVector<double>& xData = availData._L2ok;
95 QVector<double> yData(xData.size(), double(iC)-eps);
96 QwtPlotCurve* curve = addCurve(prn, symbGreen, xData, yData);
97 curve->setItemAttribute(QwtPlotItem::Legend, false);
98 }
99
100 // L1 gaps Curve
101 // -------------
102 if (availData._L1gap.size()) {
103 const QVector<double>& xData = availData._L1gap;
104 QVector<double> yData(xData.size(), double(iC)+eps);
105 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
106 curve->setItemAttribute(QwtPlotItem::Legend, false);
107 }
108
109 // L2 gaps Curve
110 // -------------
111 if (availData._L2gap.size()) {
112 const QVector<double>& xData = availData._L2gap;
113 QVector<double> yData(xData.size(), double(iC)-eps);
114 QwtPlotCurve* curve = addCurve(prn, symbBlue, xData, yData);
115 curve->setItemAttribute(QwtPlotItem::Legend, false);
116 }
117
118 // L1 slips Curve
119 // --------------
120 if (availData._L1slip.size()) {
121 const QVector<double>& xData = availData._L1slip;
122 QVector<double> yData(xData.size(), double(iC)+eps);
123 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
124 curve->setItemAttribute(QwtPlotItem::Legend, false);
125 }
126
127 // L2 slips Curve
128 // --------------
129 if (availData._L2slip.size()) {
130 const QVector<double>& xData = availData._L2slip;
131 QVector<double> yData(xData.size(), double(iC)-eps);
132 QwtPlotCurve* curve = addCurve(prn, symbRed, xData, yData);
133 curve->setItemAttribute(QwtPlotItem::Legend, false);
134 }
135 }
136
137 QList<double> ticks[QwtScaleDiv::NTickTypes];
138 QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
139 QMapIterator<int, QString> itT(scaleDrawPrn->_yLabels);
140 while (itT.hasNext()) {
141 itT.next();
142 majorTicks << double(itT.key());
143 }
144 QwtScaleDiv yScaleDiv(majorTicks.first()-0.5, majorTicks.last()+0.5, ticks );
145 setAxisScaleDiv(QwtPlot::yLeft, yScaleDiv);
146
147 // Important !!!
148 // -------------
149 replot();
150}
151
152// Add Curve
153//////////////////////////////////////////////////////////////////////////////
154QwtPlotCurve* t_availPlot::addCurve(const QString& name,
155 const QwtSymbol& symbol,
156 const QVector<double>& xData,
157 const QVector<double>& yData) {
158 QwtPlotCurve* curve = new QwtPlotCurve(name);
159 curve->setSymbol(new QwtSymbol(symbol));
160 curve->setStyle(QwtPlotCurve::NoCurve);
161 curve->setXAxis(QwtPlot::xBottom);
162 curve->setYAxis(QwtPlot::yLeft);
163 curve->setSamples(xData, yData);
164 curve->attach(this);
165 return curve;
166}
Note: See TracBrowser for help on using the repository browser.