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

Last change on this file since 2201 was 2201, checked in by mervart, 14 years ago

* empty log message *

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