source: ntrip/trunk/BNC/bncfigureppp.cpp@ 2719

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