source: ntrip/branches/BNC_2.12/src/bncfigure.cpp@ 9018

Last change on this file since 9018 was 7640, checked in by stuerze, 8 years ago

some code cleanup

File size: 5.9 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: bncFigure
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 "bncfigure.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50bncFigure::bncFigure(QWidget *parent) : QWidget(parent) {
51 updateMountPoints();
52 slotNextAnimationFrame();
53 for (int ii = 0; ii <= 1000; ii++) {
54 _ran[0][ii] = qrand() % 255;
55 _ran[1][ii] = qrand() % 255;
56 _ran[2][ii] = qrand() % 255;
57 }
58}
59
60// Destructor
61////////////////////////////////////////////////////////////////////////////
62bncFigure::~bncFigure() {
63 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
64 while (it.hasNext()) {
65 it.next();
66 delete it.value();
67 }
68}
69
70//
71////////////////////////////////////////////////////////////////////////////
72void bncFigure::updateMountPoints() {
73 QMutexLocker locker(&_mutex);
74
75 _counter = 0;
76 _maxRate = 0;
77
78 QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
79 while (it1.hasNext()) {
80 it1.next();
81 delete it1.value();
82 }
83 _bytes.clear();
84
85 bncSettings settings;
86 QListIterator<QString> it(settings.value("mountPoints").toStringList());
87 while (it.hasNext()) {
88 QStringList hlp = it.next().split(" ");
89 if (hlp.size() <= 1) continue;
90 QUrl url(hlp[0]);
91 QByteArray staID = url.path().mid(1).toAscii();
92 _bytes[staID] = new sumAndMean();
93 }
94}
95
96//
97////////////////////////////////////////////////////////////////////////////
98void bncFigure::slotNewData(const QByteArray staID, double nbyte) {
99 QMutexLocker locker(&_mutex);
100 QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
101 if (it != _bytes.end()) {
102 it.value()->_sum += nbyte*8.;
103 }
104}
105
106//
107////////////////////////////////////////////////////////////////////////////
108void bncFigure::slotNextAnimationFrame() {
109 QMutexLocker locker(&_mutex);
110
111 const static int MAXCOUNTER = 10;
112
113 ++_counter;
114
115 // If counter reaches its maximal value, compute the mean rate
116 // -----------------------------------------------------------
117 if (_counter == MAXCOUNTER) {
118 _maxRate = 0.0;
119 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
120 while (it.hasNext()) {
121 it.next();
122 it.value()->_mean = it.value()->_sum / _counter;
123 it.value()->_sum = 0.0;
124 if (it.value()->_mean > _maxRate) {
125 _maxRate = it.value()->_mean;
126 }
127 }
128 _counter = 0;
129 }
130
131 update();
132
133 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
134}
135
136//
137////////////////////////////////////////////////////////////////////////////
138void bncFigure::paintEvent(QPaintEvent *) {
139
140 int xMin = 0;
141 int xMax = 640;
142 int yMin = 0;
143 int yMax = 140;
144 float xLine = .60;
145
146 QPainter painter(this);
147
148 QFont font;
149 font.setPointSize(int(font.QFont::pointSize()*0.8));
150 painter.setFont(font);
151
152 // y-axis
153 // ------
154 int yLength = int((yMax-yMin)*xLine) - (yMin+10);
155 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
156
157 double maxRateRounded;
158 QString maxRateStr;
159 if (_maxRate < 1e3) {
160 maxRateRounded = int(_maxRate/200)*200 + 300;
161 maxRateStr = QString("%1 bps ").arg(int(maxRateRounded/200)*200);
162 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 bps "));
163 }
164 else if (_maxRate < 1e6) {
165 maxRateRounded = int(_maxRate/1.e3)*1.e3 + 1500;
166 maxRateStr = QString("%1 kbps ").arg(int(maxRateRounded/1.e3));
167 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 kbps "));
168 }
169 else {
170 maxRateRounded = int(_maxRate/1.e6)*1.e6 + 1500000;
171 maxRateStr = QString("%1 Mbps ").arg(int(maxRateRounded/1.e6));
172 painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 Mbps "));
173 }
174
175 if(_maxRate > 0.0) {
176 painter.drawText(0, yMin+20-5, xMin+60,15,Qt::AlignRight,maxRateStr);
177 }
178
179 // x-axis
180 // ------
181 painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
182
183 int anchor = 0;
184 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
185 while (it.hasNext()) {
186 it.next();
187 QByteArray staID = it.key();
188
189 int xx = xMin+80+anchor*12;
190
191 if(_maxRate > 0.0) {
192 int yy = int(yLength * (it.value()->_mean / maxRateRounded));
193 QColor color = QColor::fromRgb(_ran[0][anchor],_ran[1][anchor],_ran[2][anchor],150);
194 painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
195 QBrush(color,Qt::SolidPattern));
196 painter.setPen(Qt::black);
197 if(it.value()->_mean<=0) {
198 painter.setPen(Qt::red);
199 }
200 }
201
202 painter.save();
203 painter.translate(xx-13, int(yMax-yMin)*xLine+65);
204 painter.rotate(-90);
205 painter.drawText(0,0,65,50,Qt::AlignRight,staID.left(5) + " ");
206 painter.restore();
207
208 anchor++;
209 }
210}
211
Note: See TracBrowser for help on using the repository browser.