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

Last change on this file since 4553 was 4553, checked in by weber, 12 years ago

PPP time series design modified

File size: 9.7 KB
RevLine 
[2140]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 *
[2163]33 * Author: Mervart
[2140]34 *
35 * Created: 11-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bncfigureppp.h"
44#include "bncsettings.h"
[2158]45#include "bncutils.h"
[2140]46
47using namespace std;
48
49// Constructor
50////////////////////////////////////////////////////////////////////////////
51bncFigurePPP::bncFigurePPP(QWidget *parent) : QWidget(parent) {
[2177]52 reset();
53}
[2163]54
[2177]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
[2164]69 bncSettings settings;
[2163]70
[2730]71 if (settings.value("pppRefCrdX").toString() != "" &&
72 settings.value("pppRefCrdY").toString() != "" &&
73 settings.value("pppRefCrdZ").toString() != "") {
[2305]74 _xyzRef[0] = settings.value("pppRefCrdX").toDouble();
75 _xyzRef[1] = settings.value("pppRefCrdY").toDouble();
76 _xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
77 }
[2721]78 else {
[2305]79 _xyzRef[0] = 0.0;
80 _xyzRef[1] = 0.0;
81 _xyzRef[2] = 0.0;
82 }
83
[4550]84 if (settings.value("pppRefCrdX").toString() != "" &&
85 settings.value("pppRefCrdY").toString() != "" &&
86 settings.value("pppRefCrdZ").toString() != "" &&
87 settings.value("pppQuickStart").toString() != "" &&
88 settings.value("pppAudioResponse").toString() != "" ) {
89 _pppAudioResponse = settings.value("pppAudioResponse").toDouble();
90 }
91 else {
[4551]92 _pppAudioResponse = 0.0;
[4550]93 }
94
95 _pppMount = settings.value("pppMount").toString();
96
[2140]97 for (int ii = 0; ii < _pos.size(); ++ii) {
98 delete _pos[ii];
99 }
[2177]100 _pos.clear();
101
102 update();
[2140]103}
104
105//
106////////////////////////////////////////////////////////////////////////////
[2145]107void bncFigurePPP::slotNewPosition(bncTime time, double x, double y, double z){
[2140]108
109 QMutexLocker locker(&_mutex);
110
[2142]111 pppPos* newPos = new pppPos;
[2140]112
[2142]113 newPos->time = time;
[2145]114 newPos->xyz[0] = x;
115 newPos->xyz[1] = y;
116 newPos->xyz[2] = z;
[2140]117
118 _pos.push_back(newPos);
119
[2177]120 if (_pos.size() == 1) {
121 _startTime = time;
122 }
123
[2204]124 QMutableVectorIterator<pppPos*> it(_pos);
125 while (it.hasNext()) {
126 pppPos* pp = it.next();
127 if ( (time - pp->time) > _tRange ) {
128 delete pp;
129 it.remove();
130 }
[2140]131 }
132
[2148]133 update();
[2140]134}
135
[2157]136// Coordinate Transformation
[2140]137////////////////////////////////////////////////////////////////////////////
[2156]138QPoint bncFigurePPP::pltPoint(double tt, double yy) {
139
[2165]140 double tScale = 0.90 * _width / _tRange;
[2163]141 double yScale = 0.90 * _height / (2.0 * _neuMax);
[2165]142 double tOffset = _tRange / 13.0;
[2158]143 double yOffset = _neuMax / 10.0;
[2156]144
[2162]145 int tNew = int( ( tt - _tMin + tOffset) * tScale );
146 int yNew = int( (-yy + _neuMax + yOffset) * yScale );
[2156]147
148 return QPoint(tNew, yNew);
149}
150
151//
152////////////////////////////////////////////////////////////////////////////
[2140]153void bncFigurePPP::paintEvent(QPaintEvent *) {
154
155 QPainter painter(this);
[2165]156
[2156]157 _width = painter.viewport().width();
158 _height = painter.viewport().height();
[2140]159
[2177]160 QFont font = this->font();
161 font.setPointSize(int(this->font().pointSize()*0.9));
[2165]162 painter.setFont(font);
163
[2148]164 // Plot X-coordinates as a function of time (in seconds)
165 // -----------------------------------------------------
166 if (_pos.size() > 1) {
[2156]167 _tMin = _pos[0]->time.gpssec();
[2140]168
[2159]169 // Reference Coordinates
170 // ---------------------
[2163]171 if (_xyzRef[0] == 0.0 && _xyzRef[1] == 0.0 && _xyzRef[2] == 0.0) {
172 _xyzRef[0] = _pos[0]->xyz[0];
173 _xyzRef[1] = _pos[0]->xyz[1];
174 _xyzRef[2] = _pos[0]->xyz[2];
175 }
[2158]176 double ellRef[3];
[2163]177 xyz2ell(_xyzRef, ellRef);
[2158]178
179 // North, East and Up differences wrt Reference Coordinates
180 // --------------------------------------------------------
[2159]181 _neuMax = 0.0;
[2156]182 double neu[_pos.size()][3];
[2152]183 for (int ii = 0; ii < _pos.size(); ++ii) {
[2158]184 double dXYZ[3];
[2156]185 for (int ic = 0; ic < 3; ++ic) {
[2163]186 dXYZ[ic] = _pos[ii]->xyz[ic] - _xyzRef[ic];
[2158]187 }
188 xyz2neu(ellRef, dXYZ, neu[ii]);
189 for (int ic = 0; ic < 3; ++ic) {
190 if (fabs(neu[ii][ic]) > _neuMax) {
191 _neuMax = fabs(neu[ii][ic]);
[2156]192 }
[2146]193 }
194 }
195
[2204]196 if (_neuMax > 0.0) {
[2149]197
[2220]198 if (_neuMax < 0.151) {
199 _neuMax = 0.151;
[2161]200 }
[2163]201
[2201]202 unsigned hour, minute;
203 double second;
204 int ww = QFontMetrics(this->font()).width('w');
205
206 // neu components
207 // --------------
208 for (int ii = 1; ii < _pos.size(); ++ii) {
209 double t1 = _tMin + (_pos[ii-1]->time - _pos[0]->time);
210 double t2 = _tMin + (_pos[ii]->time - _pos[0]->time);
211
[4550]212 // Audio response
213 // --------------
[4551]214 if ( ii == _pos.size()-1) {
215 if ( _pppAudioResponse > 0.0 &&
216 (fabs(neu[ii-1][0]) > _pppAudioResponse ||
217 fabs(neu[ii-1][1]) > _pppAudioResponse) ) {
218 QApplication::beep();
[4550]219 }
220 }
[2201]221
222 // dots
223 // ----
[2205]224 painter.setPen(QColor(Qt::gray));
225 painter.drawLine(pltPoint(t1, neu[ii-1][0]), pltPoint(t2, neu[ii][0]));
[2201]226 painter.setPen(QColor(Qt::red));
227 painter.setBrush(QColor(Qt::red));
[2209]228 painter.drawEllipse(pltPoint(t1,neu[ii-1][0]), ww/6, ww/6);
[2201]229
[2205]230 painter.setPen(QColor(Qt::gray));
231 painter.drawLine(pltPoint(t1, neu[ii-1][1]), pltPoint(t2, neu[ii][1]));
[2201]232 painter.setPen(QColor(Qt::green));
233 painter.setBrush(QColor(Qt::green));
[2209]234 painter.drawEllipse(pltPoint(t1,neu[ii-1][1]), ww/6, ww/6);
[2201]235
[2205]236 painter.setPen(QColor(Qt::gray));
237 painter.drawLine(pltPoint(t1, neu[ii-1][2]), pltPoint(t2, neu[ii][2]));
[2201]238 painter.setPen(QColor(Qt::blue));
239 painter.setBrush(QColor(Qt::blue));
[2209]240 painter.drawEllipse(pltPoint(t1,neu[ii-1][2]), ww/6, ww/6);
[2201]241
242 // time-tics
243 // ---------
244 if ( fmod(_pos[ii-1]->time.daysec(), 60.0) == 0 ) {
245 _pos[ii-1]->time.civil_time(hour, minute, second);
246 QPoint pntTic = pltPoint(t1, 0.0);
247 QString strTic = QString("%1:%2").arg(hour, 2, 10, QChar('0'))
248 .arg(minute, 2, 10, QChar('0'));
249 double xFirstCharTic = pntTic.x() - ww * 1.2;
250 if ( xFirstCharTic > pltPoint(_tMin, 0.0).x()) {
251 painter.setPen(QColor(Qt::black));
252 painter.drawText(int(xFirstCharTic), int(pntTic.y() + ww * 1.7),
253 strTic);
254 painter.drawLine(pntTic.x(), pntTic.y(),
255 pntTic.x(), pntTic.y()+ww/2);
256 }
257 }
258 }
259
[2163]260 // time-axis
261 // ---------
[2201]262 painter.setPen(QColor(Qt::black));
[2156]263 painter.drawLine(pltPoint(_tMin, 0.0), pltPoint(_tMin+_tRange, 0.0));
[2148]264
[2163]265 // neu-axis
266 // --------
[2158]267 painter.drawLine(pltPoint(_tMin, -_neuMax), pltPoint(_tMin, _neuMax));
[2148]268
[2163]269 // neu-tics
270 // --------
[2201]271 double tic = floor(20.0 * (_neuMax - 0.05)) / 20.0;
[2163]272 QString strP = QString("%1 m").arg( tic,0,'f',2);
273 QString strM = QString("%1 m").arg(-tic,0,'f',2);
[2165]274 QString strZ = QString("%1 m").arg(0.0,0,'f',2);
[2159]275
[2163]276 QPoint pntP = pltPoint(_tMin, tic);
277 QPoint pntM = pltPoint(_tMin,-tic);
[2165]278 QPoint pntZ = pltPoint(_tMin, 0.0);
[2163]279
[2167]280 painter.setPen(QColor(Qt::red));
[2177]281 painter.drawText(0, ww, pntP.x() + 3*ww, pntP.x(), Qt::AlignRight, "N");
282 painter.setPen(QColor(Qt::green));
283 painter.drawText(0, ww, pntP.x() + 4*ww, pntP.x(), Qt::AlignRight, "E");
[2167]284 painter.setPen(QColor(Qt::blue));
[2177]285 painter.drawText(0, ww, pntP.x() + 5*ww, pntP.x(), Qt::AlignRight, "U");
286
[2167]287 painter.setPen(QColor(Qt::black));
[2177]288 painter.drawText(0, pntP.y()-ww/2, pntP.x()- ww/4, pntP.x(),
289 Qt::AlignRight, strP);
290 painter.drawText(0, pntM.y()-ww/2, pntM.x()- ww/4, pntM.x(),
291 Qt::AlignRight, strM);
292 painter.drawText(0, pntZ.y()-ww/2, pntZ.x()- ww/4, pntZ.x(),
293 Qt::AlignRight, strZ);
[2163]294
295 painter.drawLine(pntP.x(), pntP.y(), pntP.x()+ww, pntP.y());
296 painter.drawLine(pntM.x(), pntM.y(), pntM.x()+ww, pntM.y());
297
[2177]298 // Start Time
299 // ----------
300 _startTime.civil_time(hour, minute, second);
[4550]301 QString startStr = QString("%4 Start %1:%2:%3")
[2177]302 .arg(hour, 2, 10, QChar('0'))
303 .arg(minute, 2, 10, QChar('0'))
[4550]304 .arg(int(second), 2, 10, QChar('0'))
305 .arg(_pppMount);
[2177]306 painter.setPen(QColor(Qt::black));
[4553]307 painter.drawText(0, ww, pntP.x() + 21*ww, pntP.x(),
[2177]308 Qt::AlignRight, startStr);
[2146]309 }
310 }
[2140]311}
312
Note: See TracBrowser for help on using the repository browser.