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

Last change on this file since 2182 was 2177, checked in by mervart, 16 years ago

* empty log message *

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