source: ntrip/trunk/BNC/src/bncfigurelate.cpp@ 7908

Last change on this file since 7908 was 7182, checked in by stuerze, 9 years ago

minor changes to prevent crash because of chenaged mountPoint entries

File size: 5.3 KB
RevLine 
[1972]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: bncFigureLate
30 *
31 * Purpose:
32 *
33 * Author: Perlt, Mervart
34 *
35 * Created: 11-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bncfigurelate.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50bncFigureLate::bncFigureLate(QWidget *parent) : QWidget(parent) {
51 updateMountPoints();
52 slotNextAnimationFrame();
53 for (int ii = 0; ii <= 1000; ii++) {
[1993]54 _ran[0][ii] = qrand() % 255;
55 _ran[1][ii] = qrand() % 255;
56 _ran[2][ii] = qrand() % 100;
[1972]57 }
58}
59
60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncFigureLate::~bncFigureLate() {
63}
64
65//
66////////////////////////////////////////////////////////////////////////////
67void bncFigureLate::updateMountPoints() {
68 QMutexLocker locker(&_mutex);
69
[1981]70 _latency.clear();
[1972]71
72 bncSettings settings;
73 QListIterator<QString> it(settings.value("mountPoints").toStringList());
74 while (it.hasNext()) {
75 QStringList hlp = it.next().split(" ");
[7182]76 if (hlp.size() <= 1) continue;
[1972]77 QUrl url(hlp[0]);
78 QByteArray staID = url.path().mid(1).toAscii();
[1981]79 _latency[staID] = 0.0;
[1972]80 }
81}
82
83//
84////////////////////////////////////////////////////////////////////////////
[1975]85void bncFigureLate::slotNewLatency(const QByteArray staID, double clate) {
[1972]86 QMutexLocker locker(&_mutex);
[1981]87 if (_latency.find(staID) != _latency.end()) {
[1982]88 _latency[staID] = fabs(clate)*1000.0;
[1972]89 }
90}
91
92//
93////////////////////////////////////////////////////////////////////////////
94void bncFigureLate::slotNextAnimationFrame() {
95 QMutexLocker locker(&_mutex);
96 update();
97 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
98}
99
100//
101////////////////////////////////////////////////////////////////////////////
102void bncFigureLate::paintEvent(QPaintEvent *) {
103
104 int xMin = 0;
105 int xMax = 640;
106 int yMin = 0;
107 int yMax = 140;
108 float xLine = .60;
109
110 QPainter painter(this);
111
112 QFont font;
113 font.setPointSize(int(font.QFont::pointSize()*0.8));
114 painter.setFont(font);
115
116 // y-axis
117 // ------
118 int yLength = int((yMax-yMin)*xLine) - (yMin+10);
[1989]119 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
[1972]120
[1982]121 double maxLate = 0.0;
122 QMapIterator<QByteArray, double> it1(_latency);
123 while (it1.hasNext()) {
124 it1.next();
125 if (it1.value() > maxLate) {
126 maxLate = it1.value();
127 }
128 }
129
[2007]130 double maxLateRounded;
[1991]131 QString maxLateStr;
132 if(maxLate < 1e3) {
[2007]133 maxLateRounded = int(maxLate/200)*200 + 300;
134 maxLateStr = QString("%1 ms ").arg(int(maxLateRounded/200)*200);
[1991]135 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 ms "));
136 }
[1996]137 else if (maxLate < 6e4) {
[2007]138 maxLateRounded = int(maxLate/1.e3)*1.e3 + 1500;
139 maxLateStr = QString("%1 sec ").arg(int(maxLateRounded/1.e3));
[1991]140 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 sec "));
141 }
[1996]142 else {
[2007]143 maxLateRounded = int(maxLate / 6.e4)*6.e4 + 90000;
144 maxLateStr = QString("%1 min ").arg(int(maxLateRounded/6.e4));
[1996]145 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 min "));
146 }
[1991]147
[1982]148 if(maxLate > 0.0) {
[2007]149 painter.drawText(0, yMin+20-5, xMin+60,15,Qt::AlignRight,maxLateStr);
[1972]150 }
151
152 // x-axis
153 // ------
[1989]154 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
[1972]155
156 int anchor = 0;
[1981]157 QMapIterator<QByteArray, double> it(_latency);
[1972]158 while (it.hasNext()) {
159 it.next();
160 QByteArray staID = it.key();
161
[1989]162 int xx = xMin+80+anchor*12;
[1972]163
[1982]164 if(maxLate > 0.0) {
[2007]165 int yy = int(yLength * (it.value() / maxLateRounded));
[1993]166 QColor color = QColor::fromHsv(180,200,120+_ran[2][anchor]);
[1972]167 painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
168 QBrush(color,Qt::SolidPattern));
[1990]169 painter.setPen(Qt::black);
170 if(it.value()<=0) {
171 painter.setPen(Qt::red);
172 }
[1972]173 }
174
[1990]175 painter.save();
176 painter.translate(xx-13, int(yMax-yMin)*xLine+65);
177 painter.rotate(-90);
178 painter.drawText(0,0,65,50,Qt::AlignRight,staID.left(5) + " ");
179 painter.restore();
180
[1972]181 anchor++;
182 }
183}
184
Note: See TracBrowser for help on using the repository browser.