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

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

* empty log message *

File size: 6.2 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
53 bncSettings settings;
54
55 _xyzRef[0] = 0.0;
56 _xyzRef[1] = 0.0;
57 _xyzRef[2] = 0.0;
58
59 QString refCrdStr = settings.value("pppRefCrd").toString();
60 if (!refCrdStr.isEmpty()) {
61 QStringList refCrdStrList = refCrdStr.split(' ', QString::SkipEmptyParts);
62 if (refCrdStrList.size() == 3) {
63 _xyzRef[0] = refCrdStrList[0].toDouble();
64 _xyzRef[1] = refCrdStrList[1].toDouble();
65 _xyzRef[2] = refCrdStrList[2].toDouble();
66 }
67 }
68}
69
70// Destructor
71////////////////////////////////////////////////////////////////////////////
72bncFigurePPP::~bncFigurePPP() {
73 for (int ii = 0; ii < _pos.size(); ++ii) {
74 delete _pos[ii];
75 }
76}
77
78//
79////////////////////////////////////////////////////////////////////////////
80void bncFigurePPP::slotNewPosition(bncTime time, double x, double y, double z){
81
82 const static int MAXNUMPOS = 300;
83
84 QMutexLocker locker(&_mutex);
85
86 pppPos* newPos = new pppPos;
87
88 newPos->time = time;
89 newPos->xyz[0] = x;
90 newPos->xyz[1] = y;
91 newPos->xyz[2] = z;
92
93 _pos.push_back(newPos);
94
95 if (_pos.size() > MAXNUMPOS) {
96 delete _pos[0];
97 _pos.pop_front();
98 }
99
100 update();
101}
102
103// Coordinate Transformation
104////////////////////////////////////////////////////////////////////////////
105QPoint bncFigurePPP::pltPoint(double tt, double yy) {
106
107 double tScale = 0.85 * _width / _tRange;
108 double yScale = 0.90 * _height / (2.0 * _neuMax);
109 double tOffset = _tRange / 10.0;
110 double yOffset = _neuMax / 10.0;
111
112 int tNew = int( ( tt - _tMin + tOffset) * tScale );
113 int yNew = int( (-yy + _neuMax + yOffset) * yScale );
114
115 return QPoint(tNew, yNew);
116}
117
118//
119////////////////////////////////////////////////////////////////////////////
120void bncFigurePPP::paintEvent(QPaintEvent *) {
121
122 QPainter painter(this);
123 _width = painter.viewport().width();
124 _height = painter.viewport().height();
125
126 // Plot X-coordinates as a function of time (in seconds)
127 // -----------------------------------------------------
128 if (_pos.size() > 1) {
129
130 _tRange = _pos[_pos.size()-1]->time - _pos[0]->time; // in sec
131 _tMin = _pos[0]->time.gpssec();
132
133 // Reference Coordinates
134 // ---------------------
135 if (_xyzRef[0] == 0.0 && _xyzRef[1] == 0.0 && _xyzRef[2] == 0.0) {
136 _xyzRef[0] = _pos[0]->xyz[0];
137 _xyzRef[1] = _pos[0]->xyz[1];
138 _xyzRef[2] = _pos[0]->xyz[2];
139 }
140 double ellRef[3];
141 xyz2ell(_xyzRef, ellRef);
142
143 // North, East and Up differences wrt Reference Coordinates
144 // --------------------------------------------------------
145 _neuMax = 0.0;
146 double neu[_pos.size()][3];
147 for (int ii = 0; ii < _pos.size(); ++ii) {
148 double dXYZ[3];
149 for (int ic = 0; ic < 3; ++ic) {
150 dXYZ[ic] = _pos[ii]->xyz[ic] - _xyzRef[ic];
151 }
152 xyz2neu(ellRef, dXYZ, neu[ii]);
153 for (int ic = 0; ic < 3; ++ic) {
154 if (fabs(neu[ii][ic]) > _neuMax) {
155 _neuMax = fabs(neu[ii][ic]);
156 }
157 }
158 }
159
160 if (_neuMax > 0.0 && _tRange > 0.0) {
161
162 if (_neuMax < 0.15) {
163 _neuMax = 0.15;
164 }
165
166 // time-axis
167 // ---------
168 painter.drawLine(pltPoint(_tMin, 0.0), pltPoint(_tMin+_tRange, 0.0));
169
170 // neu-axis
171 // --------
172 painter.drawLine(pltPoint(_tMin, -_neuMax), pltPoint(_tMin, _neuMax));
173
174 // neu-tics
175 // --------
176 double tic = floor(20.0 * (_neuMax - 0.05)) / 20.0;
177 QString strP = QString("%1 m").arg( tic,0,'f',2);
178 QString strM = QString("%1 m").arg(-tic,0,'f',2);
179
180 QPoint pntP = pltPoint(_tMin, tic);
181 QPoint pntM = pltPoint(_tMin,-tic);
182
183 int ww = QFontMetrics(this->font()).width('w');
184
185 painter.drawText(pntP.x() - ww * strP.length(), pntP.y()+ww, strP);
186 painter.drawText(pntM.x() - ww * strM.length(), pntM.y(), strM);
187
188 painter.drawLine(pntP.x(), pntP.y(), pntP.x()+ww, pntP.y());
189 painter.drawLine(pntM.x(), pntM.y(), pntM.x()+ww, pntM.y());
190
191 // time-tic
192 // --------
193 painter.drawText(pltPoint(_tMin+_tRange,0.0),
194 QString(" %1 s").arg(_tRange));
195
196 // neu components
197 // --------------
198 for (int ii = 1; ii < _pos.size(); ++ii) {
199 double t1 = _tMin + (_pos[ii-1]->time - _pos[0]->time);
200 double t2 = _tMin + (_pos[ii]->time - _pos[0]->time);
201 painter.setPen(QColor(Qt::red));
202 painter.drawLine(pltPoint(t1, neu[ii-1][0]), pltPoint(t2, neu[ii][0]));
203 painter.setPen(QColor(Qt::green));
204 painter.drawLine(pltPoint(t1, neu[ii-1][1]), pltPoint(t2, neu[ii][1]));
205 painter.setPen(QColor(Qt::blue));
206 painter.drawLine(pltPoint(t1, neu[ii-1][2]), pltPoint(t2, neu[ii][2]));
207 }
208 }
209 }
210}
211
Note: See TracBrowser for help on using the repository browser.