source: ntrip/trunk/BNC/src/bncfigure.cpp@ 7971

Last change on this file since 7971 was 7640, checked in by stuerze, 9 years ago

some code cleanup

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