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

Last change on this file since 8822 was 8252, checked in by stoecker, 7 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

File size: 8.5 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
[8252]43#include <QApplication>
44#include <QPainter>
45#include <QVariant>
46
47#include "bncfigureppp.h"
[2140]48#include "bncsettings.h"
[2158]49#include "bncutils.h"
[2140]50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55bncFigurePPP::bncFigurePPP(QWidget *parent) : QWidget(parent) {
[2177]56 reset();
57}
[2163]58
[2177]59
60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncFigurePPP::~bncFigurePPP() {
63 for (int ii = 0; ii < _pos.size(); ++ii) {
64 delete _pos[ii];
65 }
66}
67
68//
69////////////////////////////////////////////////////////////////////////////
70void bncFigurePPP::reset() {
71 QMutexLocker locker(&_mutex);
[2140]72 for (int ii = 0; ii < _pos.size(); ++ii) {
73 delete _pos[ii];
74 }
[2177]75 _pos.clear();
76 update();
[2140]77}
78
79//
80////////////////////////////////////////////////////////////////////////////
[5954]81void bncFigurePPP::slotNewPosition(QByteArray staID, bncTime time, QVector<double> xx){
[2140]82
83 QMutexLocker locker(&_mutex);
84
[5954]85 bncSettings settings;
[6731]86
[6734]87 if (settings.value("PPP/audioResponse").toString() != "" ) {
88 _audioResponseThreshold = settings.value("PPP/audioResponse").toDouble();
89 }
90 else {
91 _audioResponseThreshold = 0.0;
92 }
[6731]93
[5954]94 if (settings.value("PPP/plotCoordinates").toByteArray() != staID) {
95 return;
96 }
97
[2142]98 pppPos* newPos = new pppPos;
[2140]99
[2142]100 newPos->time = time;
[5881]101 newPos->neu[0] = xx.data()[3];
102 newPos->neu[1] = xx.data()[4];
103 newPos->neu[2] = xx.data()[5];
[2140]104
105 _pos.push_back(newPos);
106
[2177]107 if (_pos.size() == 1) {
108 _startTime = time;
109 }
110
[2204]111 QMutableVectorIterator<pppPos*> it(_pos);
112 while (it.hasNext()) {
113 pppPos* pp = it.next();
114 if ( (time - pp->time) > _tRange ) {
115 delete pp;
116 it.remove();
117 }
[2140]118 }
119
[2148]120 update();
[2140]121}
122
[2157]123// Coordinate Transformation
[2140]124////////////////////////////////////////////////////////////////////////////
[2156]125QPoint bncFigurePPP::pltPoint(double tt, double yy) {
126
[2165]127 double tScale = 0.90 * _width / _tRange;
[2163]128 double yScale = 0.90 * _height / (2.0 * _neuMax);
[2165]129 double tOffset = _tRange / 13.0;
[2158]130 double yOffset = _neuMax / 10.0;
[2156]131
[2162]132 int tNew = int( ( tt - _tMin + tOffset) * tScale );
133 int yNew = int( (-yy + _neuMax + yOffset) * yScale );
[2156]134
135 return QPoint(tNew, yNew);
136}
137
138//
139////////////////////////////////////////////////////////////////////////////
[2140]140void bncFigurePPP::paintEvent(QPaintEvent *) {
141
142 QPainter painter(this);
[2165]143
[2156]144 _width = painter.viewport().width();
145 _height = painter.viewport().height();
[2140]146
[2177]147 QFont font = this->font();
148 font.setPointSize(int(this->font().pointSize()*0.9));
[2165]149 painter.setFont(font);
150
[2148]151 // Plot X-coordinates as a function of time (in seconds)
152 // -----------------------------------------------------
153 if (_pos.size() > 1) {
[2156]154 _tMin = _pos[0]->time.gpssec();
[2140]155
[2158]156 // North, East and Up differences wrt Reference Coordinates
157 // --------------------------------------------------------
[2159]158 _neuMax = 0.0;
[2156]159 double neu[_pos.size()][3];
[2152]160 for (int ii = 0; ii < _pos.size(); ++ii) {
[2156]161 for (int ic = 0; ic < 3; ++ic) {
[5881]162 neu[ii][ic] = _pos[ii]->neu[ic];
[2158]163 if (fabs(neu[ii][ic]) > _neuMax) {
164 _neuMax = fabs(neu[ii][ic]);
[2156]165 }
[2146]166 }
167 }
168
[2204]169 if (_neuMax > 0.0) {
[2149]170
[2220]171 if (_neuMax < 0.151) {
172 _neuMax = 0.151;
[2161]173 }
[2163]174
[2201]175 unsigned hour, minute;
176 double second;
177 int ww = QFontMetrics(this->font()).width('w');
178
179 // neu components
180 // --------------
181 for (int ii = 1; ii < _pos.size(); ++ii) {
182 double t1 = _tMin + (_pos[ii-1]->time - _pos[0]->time);
183 double t2 = _tMin + (_pos[ii]->time - _pos[0]->time);
184
[6731]185 // Audio response
186 // --------------
187 if ( ii == _pos.size()-1) {
188 if ( _audioResponseThreshold > 0.0 &&
189 (fabs(neu[ii-1][0]) > _audioResponseThreshold ||
190 fabs(neu[ii-1][1]) > _audioResponseThreshold) ) {
191 QApplication::beep();
192 }
193 }
194
[2201]195 // dots
196 // ----
[2205]197 painter.setPen(QColor(Qt::gray));
198 painter.drawLine(pltPoint(t1, neu[ii-1][0]), pltPoint(t2, neu[ii][0]));
[2201]199 painter.setPen(QColor(Qt::red));
200 painter.setBrush(QColor(Qt::red));
[2209]201 painter.drawEllipse(pltPoint(t1,neu[ii-1][0]), ww/6, ww/6);
[2201]202
[2205]203 painter.setPen(QColor(Qt::gray));
204 painter.drawLine(pltPoint(t1, neu[ii-1][1]), pltPoint(t2, neu[ii][1]));
[2201]205 painter.setPen(QColor(Qt::green));
206 painter.setBrush(QColor(Qt::green));
[2209]207 painter.drawEllipse(pltPoint(t1,neu[ii-1][1]), ww/6, ww/6);
[2201]208
[2205]209 painter.setPen(QColor(Qt::gray));
210 painter.drawLine(pltPoint(t1, neu[ii-1][2]), pltPoint(t2, neu[ii][2]));
[2201]211 painter.setPen(QColor(Qt::blue));
212 painter.setBrush(QColor(Qt::blue));
[2209]213 painter.drawEllipse(pltPoint(t1,neu[ii-1][2]), ww/6, ww/6);
[2201]214
215 // time-tics
216 // ---------
217 if ( fmod(_pos[ii-1]->time.daysec(), 60.0) == 0 ) {
218 _pos[ii-1]->time.civil_time(hour, minute, second);
219 QPoint pntTic = pltPoint(t1, 0.0);
220 QString strTic = QString("%1:%2").arg(hour, 2, 10, QChar('0'))
221 .arg(minute, 2, 10, QChar('0'));
222 double xFirstCharTic = pntTic.x() - ww * 1.2;
223 if ( xFirstCharTic > pltPoint(_tMin, 0.0).x()) {
224 painter.setPen(QColor(Qt::black));
225 painter.drawText(int(xFirstCharTic), int(pntTic.y() + ww * 1.7),
226 strTic);
227 painter.drawLine(pntTic.x(), pntTic.y(),
228 pntTic.x(), pntTic.y()+ww/2);
229 }
230 }
231 }
232
[2163]233 // time-axis
234 // ---------
[2201]235 painter.setPen(QColor(Qt::black));
[2156]236 painter.drawLine(pltPoint(_tMin, 0.0), pltPoint(_tMin+_tRange, 0.0));
[2148]237
[2163]238 // neu-axis
239 // --------
[2158]240 painter.drawLine(pltPoint(_tMin, -_neuMax), pltPoint(_tMin, _neuMax));
[2148]241
[2163]242 // neu-tics
243 // --------
[2201]244 double tic = floor(20.0 * (_neuMax - 0.05)) / 20.0;
[2163]245 QString strP = QString("%1 m").arg( tic,0,'f',2);
246 QString strM = QString("%1 m").arg(-tic,0,'f',2);
[2165]247 QString strZ = QString("%1 m").arg(0.0,0,'f',2);
[2159]248
[2163]249 QPoint pntP = pltPoint(_tMin, tic);
250 QPoint pntM = pltPoint(_tMin,-tic);
[2165]251 QPoint pntZ = pltPoint(_tMin, 0.0);
[2163]252
[2167]253 painter.setPen(QColor(Qt::red));
[2177]254 painter.drawText(0, ww, pntP.x() + 3*ww, pntP.x(), Qt::AlignRight, "N");
255 painter.setPen(QColor(Qt::green));
256 painter.drawText(0, ww, pntP.x() + 4*ww, pntP.x(), Qt::AlignRight, "E");
[2167]257 painter.setPen(QColor(Qt::blue));
[2177]258 painter.drawText(0, ww, pntP.x() + 5*ww, pntP.x(), Qt::AlignRight, "U");
259
[2167]260 painter.setPen(QColor(Qt::black));
[2177]261 painter.drawText(0, pntP.y()-ww/2, pntP.x()- ww/4, pntP.x(),
262 Qt::AlignRight, strP);
263 painter.drawText(0, pntM.y()-ww/2, pntM.x()- ww/4, pntM.x(),
264 Qt::AlignRight, strM);
265 painter.drawText(0, pntZ.y()-ww/2, pntZ.x()- ww/4, pntZ.x(),
266 Qt::AlignRight, strZ);
[2163]267
268 painter.drawLine(pntP.x(), pntP.y(), pntP.x()+ww, pntP.y());
269 painter.drawLine(pntM.x(), pntM.y(), pntM.x()+ww, pntM.y());
270
[2177]271 // Start Time
272 // ----------
[5882]273 QString startStr = QString(_startTime.timestr(0).c_str());
[7684]274 startStr = "Start " + startStr;
[2177]275 painter.setPen(QColor(Qt::black));
[5881]276 painter.drawText(0, ww, pntP.x() + 31*ww, pntP.x(), Qt::AlignRight, startStr);
[2146]277 }
278 }
[2140]279}
280
Note: See TracBrowser for help on using the repository browser.