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

Last change on this file since 2454 was 2308, checked in by mervart, 15 years ago

* empty log message *

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