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

Last change on this file since 2648 was 2648, checked in by mervart, 13 years ago
File size: 8.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
69 bncSettings settings;
70
71 if (settings.value("pppOrigin").toString() == "Plot - X Y Z" ||
72 settings.value("pppOrigin").toString() == "QuickStart - Static") {
73 _xyzRef[0] = settings.value("pppRefCrdX").toDouble();
74 _xyzRef[1] = settings.value("pppRefCrdY").toDouble();
75 _xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
76 }
77 else if (settings.value("pppOrigin").toString() == "Plot - Start position") {
78 _xyzRef[0] = 0.0;
79 _xyzRef[1] = 0.0;
80 _xyzRef[2] = 0.0;
81 }
82
83 for (int ii = 0; ii < _pos.size(); ++ii) {
84 delete _pos[ii];
85 }
86 _pos.clear();
87
88 update();
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void bncFigurePPP::slotNewPosition(bncTime time, double x, double y, double z){
94
95 QMutexLocker locker(&_mutex);
96
97 pppPos* newPos = new pppPos;
98
99 newPos->time = time;
100 newPos->xyz[0] = x;
101 newPos->xyz[1] = y;
102 newPos->xyz[2] = z;
103
104 _pos.push_back(newPos);
105
106 if (_pos.size() == 1) {
107 _startTime = time;
108 }
109
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 }
117 }
118
119 update();
120}
121
122// Coordinate Transformation
123////////////////////////////////////////////////////////////////////////////
124QPoint bncFigurePPP::pltPoint(double tt, double yy) {
125
126 double tScale = 0.90 * _width / _tRange;
127 double yScale = 0.90 * _height / (2.0 * _neuMax);
128 double tOffset = _tRange / 13.0;
129 double yOffset = _neuMax / 10.0;
130
131 int tNew = int( ( tt - _tMin + tOffset) * tScale );
132 int yNew = int( (-yy + _neuMax + yOffset) * yScale );
133
134 return QPoint(tNew, yNew);
135}
136
137//
138////////////////////////////////////////////////////////////////////////////
139void bncFigurePPP::paintEvent(QPaintEvent *) {
140
141 QPainter painter(this);
142
143 _width = painter.viewport().width();
144 _height = painter.viewport().height();
145
146 QFont font = this->font();
147 font.setPointSize(int(this->font().pointSize()*0.9));
148 painter.setFont(font);
149
150 // Plot X-coordinates as a function of time (in seconds)
151 // -----------------------------------------------------
152 if (_pos.size() > 1) {
153 _tMin = _pos[0]->time.gpssec();
154
155 // Reference Coordinates
156 // ---------------------
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 }
162 double ellRef[3];
163 xyz2ell(_xyzRef, ellRef);
164
165 // North, East and Up differences wrt Reference Coordinates
166 // --------------------------------------------------------
167 _neuMax = 0.0;
168 double neu[_pos.size()][3];
169 for (int ii = 0; ii < _pos.size(); ++ii) {
170 double dXYZ[3];
171 for (int ic = 0; ic < 3; ++ic) {
172 dXYZ[ic] = _pos[ii]->xyz[ic] - _xyzRef[ic];
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]);
178 }
179 }
180 }
181
182 if (_neuMax > 0.0) {
183
184 if (_neuMax < 0.151) {
185 _neuMax = 0.151;
186 }
187
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 // ----
201 painter.setPen(QColor(Qt::gray));
202 painter.drawLine(pltPoint(t1, neu[ii-1][0]), pltPoint(t2, neu[ii][0]));
203 painter.setPen(QColor(Qt::red));
204 painter.setBrush(QColor(Qt::red));
205 painter.drawEllipse(pltPoint(t1,neu[ii-1][0]), ww/6, ww/6);
206
207 painter.setPen(QColor(Qt::gray));
208 painter.drawLine(pltPoint(t1, neu[ii-1][1]), pltPoint(t2, neu[ii][1]));
209 painter.setPen(QColor(Qt::green));
210 painter.setBrush(QColor(Qt::green));
211 painter.drawEllipse(pltPoint(t1,neu[ii-1][1]), ww/6, ww/6);
212
213 painter.setPen(QColor(Qt::gray));
214 painter.drawLine(pltPoint(t1, neu[ii-1][2]), pltPoint(t2, neu[ii][2]));
215 painter.setPen(QColor(Qt::blue));
216 painter.setBrush(QColor(Qt::blue));
217 painter.drawEllipse(pltPoint(t1,neu[ii-1][2]), ww/6, ww/6);
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
237 // time-axis
238 // ---------
239 painter.setPen(QColor(Qt::black));
240 painter.drawLine(pltPoint(_tMin, 0.0), pltPoint(_tMin+_tRange, 0.0));
241
242 // neu-axis
243 // --------
244 painter.drawLine(pltPoint(_tMin, -_neuMax), pltPoint(_tMin, _neuMax));
245
246 // neu-tics
247 // --------
248 double tic = floor(20.0 * (_neuMax - 0.05)) / 20.0;
249 QString strP = QString("%1 m").arg( tic,0,'f',2);
250 QString strM = QString("%1 m").arg(-tic,0,'f',2);
251 QString strZ = QString("%1 m").arg(0.0,0,'f',2);
252
253 QPoint pntP = pltPoint(_tMin, tic);
254 QPoint pntM = pltPoint(_tMin,-tic);
255 QPoint pntZ = pltPoint(_tMin, 0.0);
256
257 painter.setPen(QColor(Qt::red));
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");
261 painter.setPen(QColor(Qt::blue));
262 painter.drawText(0, ww, pntP.x() + 5*ww, pntP.x(), Qt::AlignRight, "U");
263
264 painter.setPen(QColor(Qt::black));
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);
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
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));
283 painter.drawText(0, ww, pntP.x() + 16*ww, pntP.x(),
284 Qt::AlignRight, startStr);
285 }
286 }
287}
288
Note: See TracBrowser for help on using the repository browser.