source: ntrip/trunk/BNC/src/bncfigureppp.cpp@ 5881

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