source: ntrip/trunk/BNC/src/bncfigureppp.cpp@ 6483

Last change on this file since 6483 was 5954, checked in by mervart, 10 years ago
File size: 7.9 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: bncFigurePPP
30 *
31 * Purpose:
32 *
33 * Author: Mervart
34 *
35 * Created: 11-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bncfigureppp.h"
44#include "bncsettings.h"
45#include "bncutils.h"
46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncFigurePPP::bncFigurePPP(QWidget *parent) : QWidget(parent) {
52 reset();
53}
54
55
56// Destructor
57////////////////////////////////////////////////////////////////////////////
58bncFigurePPP::~bncFigurePPP() {
59 for (int ii = 0; ii < _pos.size(); ++ii) {
60 delete _pos[ii];
61 }
62}
63
64//
65////////////////////////////////////////////////////////////////////////////
66void bncFigurePPP::reset() {
67 QMutexLocker locker(&_mutex);
68 for (int ii = 0; ii < _pos.size(); ++ii) {
69 delete _pos[ii];
70 }
71 _pos.clear();
72 update();
73}
74
75//
76////////////////////////////////////////////////////////////////////////////
77void bncFigurePPP::slotNewPosition(QByteArray staID, bncTime time, QVector<double> xx){
78
79 QMutexLocker locker(&_mutex);
80
81 bncSettings settings;
82 if (settings.value("PPP/plotCoordinates").toByteArray() != staID) {
83 return;
84 }
85
86 pppPos* newPos = new pppPos;
87
88 newPos->time = time;
89 newPos->neu[0] = xx.data()[3];
90 newPos->neu[1] = xx.data()[4];
91 newPos->neu[2] = xx.data()[5];
92
93 _pos.push_back(newPos);
94
95 if (_pos.size() == 1) {
96 _startTime = time;
97 }
98
99 QMutableVectorIterator<pppPos*> it(_pos);
100 while (it.hasNext()) {
101 pppPos* pp = it.next();
102 if ( (time - pp->time) > _tRange ) {
103 delete pp;
104 it.remove();
105 }
106 }
107
108 update();
109}
110
111// Coordinate Transformation
112////////////////////////////////////////////////////////////////////////////
113QPoint bncFigurePPP::pltPoint(double tt, double yy) {
114
115 double tScale = 0.90 * _width / _tRange;
116 double yScale = 0.90 * _height / (2.0 * _neuMax);
117 double tOffset = _tRange / 13.0;
118 double yOffset = _neuMax / 10.0;
119
120 int tNew = int( ( tt - _tMin + tOffset) * tScale );
121 int yNew = int( (-yy + _neuMax + yOffset) * yScale );
122
123 return QPoint(tNew, yNew);
124}
125
126//
127////////////////////////////////////////////////////////////////////////////
128void bncFigurePPP::paintEvent(QPaintEvent *) {
129
130 QPainter painter(this);
131
132 _width = painter.viewport().width();
133 _height = painter.viewport().height();
134
135 QFont font = this->font();
136 font.setPointSize(int(this->font().pointSize()*0.9));
137 painter.setFont(font);
138
139 // Plot X-coordinates as a function of time (in seconds)
140 // -----------------------------------------------------
141 if (_pos.size() > 1) {
142 _tMin = _pos[0]->time.gpssec();
143
144 // North, East and Up differences wrt Reference Coordinates
145 // --------------------------------------------------------
146 _neuMax = 0.0;
147 double neu[_pos.size()][3];
148 for (int ii = 0; ii < _pos.size(); ++ii) {
149 for (int ic = 0; ic < 3; ++ic) {
150 neu[ii][ic] = _pos[ii]->neu[ic];
151 if (fabs(neu[ii][ic]) > _neuMax) {
152 _neuMax = fabs(neu[ii][ic]);
153 }
154 }
155 }
156
157 if (_neuMax > 0.0) {
158
159 if (_neuMax < 0.151) {
160 _neuMax = 0.151;
161 }
162
163 unsigned hour, minute;
164 double second;
165 int ww = QFontMetrics(this->font()).width('w');
166
167 // neu components
168 // --------------
169 for (int ii = 1; ii < _pos.size(); ++ii) {
170 double t1 = _tMin + (_pos[ii-1]->time - _pos[0]->time);
171 double t2 = _tMin + (_pos[ii]->time - _pos[0]->time);
172
173 // dots
174 // ----
175 painter.setPen(QColor(Qt::gray));
176 painter.drawLine(pltPoint(t1, neu[ii-1][0]), pltPoint(t2, neu[ii][0]));
177 painter.setPen(QColor(Qt::red));
178 painter.setBrush(QColor(Qt::red));
179 painter.drawEllipse(pltPoint(t1,neu[ii-1][0]), ww/6, ww/6);
180
181 painter.setPen(QColor(Qt::gray));
182 painter.drawLine(pltPoint(t1, neu[ii-1][1]), pltPoint(t2, neu[ii][1]));
183 painter.setPen(QColor(Qt::green));
184 painter.setBrush(QColor(Qt::green));
185 painter.drawEllipse(pltPoint(t1,neu[ii-1][1]), ww/6, ww/6);
186
187 painter.setPen(QColor(Qt::gray));
188 painter.drawLine(pltPoint(t1, neu[ii-1][2]), pltPoint(t2, neu[ii][2]));
189 painter.setPen(QColor(Qt::blue));
190 painter.setBrush(QColor(Qt::blue));
191 painter.drawEllipse(pltPoint(t1,neu[ii-1][2]), ww/6, ww/6);
192
193 // time-tics
194 // ---------
195 if ( fmod(_pos[ii-1]->time.daysec(), 60.0) == 0 ) {
196 _pos[ii-1]->time.civil_time(hour, minute, second);
197 QPoint pntTic = pltPoint(t1, 0.0);
198 QString strTic = QString("%1:%2").arg(hour, 2, 10, QChar('0'))
199 .arg(minute, 2, 10, QChar('0'));
200 double xFirstCharTic = pntTic.x() - ww * 1.2;
201 if ( xFirstCharTic > pltPoint(_tMin, 0.0).x()) {
202 painter.setPen(QColor(Qt::black));
203 painter.drawText(int(xFirstCharTic), int(pntTic.y() + ww * 1.7),
204 strTic);
205 painter.drawLine(pntTic.x(), pntTic.y(),
206 pntTic.x(), pntTic.y()+ww/2);
207 }
208 }
209 }
210
211 // time-axis
212 // ---------
213 painter.setPen(QColor(Qt::black));
214 painter.drawLine(pltPoint(_tMin, 0.0), pltPoint(_tMin+_tRange, 0.0));
215
216 // neu-axis
217 // --------
218 painter.drawLine(pltPoint(_tMin, -_neuMax), pltPoint(_tMin, _neuMax));
219
220 // neu-tics
221 // --------
222 double tic = floor(20.0 * (_neuMax - 0.05)) / 20.0;
223 QString strP = QString("%1 m").arg( tic,0,'f',2);
224 QString strM = QString("%1 m").arg(-tic,0,'f',2);
225 QString strZ = QString("%1 m").arg(0.0,0,'f',2);
226
227 QPoint pntP = pltPoint(_tMin, tic);
228 QPoint pntM = pltPoint(_tMin,-tic);
229 QPoint pntZ = pltPoint(_tMin, 0.0);
230
231 painter.setPen(QColor(Qt::red));
232 painter.drawText(0, ww, pntP.x() + 3*ww, pntP.x(), Qt::AlignRight, "N");
233 painter.setPen(QColor(Qt::green));
234 painter.drawText(0, ww, pntP.x() + 4*ww, pntP.x(), Qt::AlignRight, "E");
235 painter.setPen(QColor(Qt::blue));
236 painter.drawText(0, ww, pntP.x() + 5*ww, pntP.x(), Qt::AlignRight, "U");
237
238 painter.setPen(QColor(Qt::black));
239 painter.drawText(0, pntP.y()-ww/2, pntP.x()- ww/4, pntP.x(),
240 Qt::AlignRight, strP);
241 painter.drawText(0, pntM.y()-ww/2, pntM.x()- ww/4, pntM.x(),
242 Qt::AlignRight, strM);
243 painter.drawText(0, pntZ.y()-ww/2, pntZ.x()- ww/4, pntZ.x(),
244 Qt::AlignRight, strZ);
245
246 painter.drawLine(pntP.x(), pntP.y(), pntP.x()+ww, pntP.y());
247 painter.drawLine(pntM.x(), pntM.y(), pntM.x()+ww, pntM.y());
248
249 // Start Time
250 // ----------
251 QString startStr = QString(_startTime.timestr(0).c_str());
252 painter.setPen(QColor(Qt::black));
253 painter.drawText(0, ww, pntP.x() + 31*ww, pntP.x(), Qt::AlignRight, startStr);
254 }
255 }
256}
257
Note: See TracBrowser for help on using the repository browser.