source: ntrip/trunk/BNC/src/bncmap.cpp@ 4304

Last change on this file since 4304 was 4278, checked in by mervart, 12 years ago
File size: 7.3 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: bncmap
30 *
31 * Purpose: This class plots map from Ntrip source-table meta data
32 *
33 * Author: J. Dousa, Pecny, Czech Republic
34 * Created: 21-may-2012
35 *
36 * Changes:
37 *
38 * -----------------------------------------------------------------------*/
39
40#include <iostream>
41#include "bncmap.h"
42
43// ------------
44bncMap::bncMap(QWidget* parent) : QDialog(parent)
45{
46 _LaOff = 25; // shift longitude
47 _mapScen = new QGraphicsScene();
48 _mapView = new BncMapView();
49 _mapView->setScene(_mapScen);
50 _mapView->resetScale();
51 slotReadMap();
52 slotCreateMap();
53 _mapScen->setSceneRect(QRect(0,-90,360,180));
54
55 setWindowTitle(tr("Source-Table Map [*]"));
56
57 /* close button */
58 QPushButton* buttClose = new QPushButton("Close");
59 connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
60
61 /* rescale button */
62// QPushButton* buttClean = new QPushButton("Clean");
63// connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
64
65 /* zoom button */
66 QPushButton* buttZoomIn = new QPushButton("Zoom +");
67 connect(buttZoomIn, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
68
69 /* zoom button */
70 QPushButton* buttZoomOut = new QPushButton("Zoom -");
71 connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
72
73 /* reset button */
74 QPushButton* buttReset = new QPushButton("World");
75 connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
76
77 /* fit button */
78 QPushButton* buttFit = new QPushButton("Fit Map");
79 connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
80
81 /* font reset button */
82 QPushButton* buttFont = new QPushButton("Fit Font");
83 connect(buttFont, SIGNAL(clicked()), this, SLOT(slotFitFont()));
84
85 /* layout */
86 QVBoxLayout* MapLayout = new QVBoxLayout;
87 QHBoxLayout* ButLayout = new QHBoxLayout;
88
89 ButLayout->addWidget(buttZoomIn);
90 ButLayout->addWidget(buttZoomOut);
91// ButLayout->addWidget(buttClean);
92 ButLayout->addWidget(buttReset);
93 ButLayout->addWidget(buttFit);
94 ButLayout->addWidget(buttFont);
95 ButLayout->addWidget(buttClose);
96
97 MapLayout->addWidget(_mapView);
98 MapLayout->addLayout(ButLayout);
99
100 setLayout(MapLayout);
101
102 this->show();
103}
104
105
106// ------------
107bncMap::~bncMap(){
108 delete _mapView;
109}
110
111
112// ------------
113void bncMap::slotReadMap()
114{
115 QFile world(":worldmap.dat");
116 float fi, la;
117
118 world.open(QIODevice::ReadOnly | QIODevice::Text);
119
120 QTextStream in(&world);
121 in.setRealNumberNotation(QTextStream::FixedNotation);
122
123 while( ! in.atEnd() ){
124
125 in >> la >> fi;
126
127 // la = 0-360
128 while( la < 0 ){ la += 360; }
129 while( la >= 360 ){ la -= 360; }
130
131 // fi opposite
132 _worldMap << QPointF( la, -fi );
133
134 }
135 world.close();
136}
137
138
139// ------------
140void bncMap::slotCreateMap()
141{
142 // _mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
143
144 int begIdx = 0;
145 int endIdx = 0;
146 for( int i=0; i < _worldMap.size(); i++ ){
147 if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
148 if( i > 0 ){
149 endIdx = i-1;
150 while( begIdx < endIdx ){
151
152 int l1 = 0;
153 int l2 = 0;
154
155 float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
156 float fi1 = _worldMap.at(begIdx+0).y();
157 float la2 = _worldMap.at(begIdx+1).x() + _LaOff;
158 float fi2 = _worldMap.at(begIdx+1).y();
159 begIdx++;
160
161 while( la1 < 0 ){ la1 += 360; l1++; }
162 while( la1 >= 360 ){ la1 -= 360; l1--; }
163 while( la2 < 0 ){ la2 += 360; l2++; }
164 while( la2 >= 360 ){ la2 -= 360; l2--; }
165
166 if( l1 != 0 and l2 == 0 ){ continue; } // break this line
167 if( l2 != 0 and l1 == 0 ){ continue; } // break this line
168
169 _mapScen->addLine(la1, fi1, la2, fi2, QPen(QBrush(Qt::gray),0.3));
170 }
171 }
172 if( i+1 < _worldMap.size() ) begIdx = i+1;
173 }
174 }
175}
176
177
178// ------------
179void bncMap::slotCleanMap()
180{
181 QMutexLocker locker(&_mutexMap);
182 _mapScen->clear();
183 slotCreateMap();
184 slotResetMap();
185 slotFitFont();
186}
187
188
189// ------------
190void bncMap::slotResetMap()
191{
192 _mapView->resetScale();
193}
194
195
196// ------------
197void bncMap::slotFitMap()
198{
199 QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10);
200
201 _mapView->resetScale();
202 _mapView->updateSceneRect(reg);
203 _mapView->centerOn(reg.center());
204 _mapView->fitInView(reg,Qt::KeepAspectRatio);
205
206 slotFitFont();
207}
208
209
210// ------------
211void bncMap::slotFitFont()
212{
213 _mapScen->clear();
214 slotCreateMap();
215
216 float fontrate = _mapView->scale_rate();
217 float pointrate = _mapView->scale_rate();
218
219 QMapIterator<QString, QList<QVariant> > it(_allNames);
220 while( it.hasNext() ){
221
222 it.next();
223 QString name = it.key();
224 QList<QVariant> tmp = it.value();
225
226 double la = tmp.at(0).toPointF().x();
227 double fi = tmp.at(0).toPointF().y();
228 QPen pen = tmp.at(1).value<QPen>();
229 double basPT = tmp.at(2).toDouble();
230 double basFT = tmp.at(3).toDouble();
231
232 float tmpPT = pointrate * basPT;
233 float tmpFT = fontrate * basFT;
234
235 if( fontrate > 1 ){
236 tmpPT = basPT;
237 tmpFT = basFT;
238 }
239
240 QFont font(QFont("Arial",2));
241 font.setPointSizeF( tmpFT );
242 font.setStretch(QFont::Unstretched);
243 font.setCapitalization(QFont::Capitalize);
244
245 QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
246 nameItem->setFont( font );
247
248 nameItem->setPos( la - basFT, fi - basFT );
249
250 if( tmpPT < 0.15 ) tmpPT = 0.15;
251 pen.setWidthF(tmpPT);
252
253 _mapScen->addItem( nameItem );
254 _mapScen->addEllipse( la, fi, tmpPT, tmpPT, pen );
255 }
256 _mapView->zoom( 1.0 );
257}
258
259
260// ------------
261void bncMap::slotZoomIn()
262{
263 _mapView->zoom( 1.2 );
264 slotFitFont();
265}
266
267
268// ------------
269void bncMap::slotZoomOut()
270{
271 _mapView->zoom( 1/1.2 );
272 slotFitFont();
273}
274
275
276// ------------
277void bncMap::slotNewPoint(QPointF point, QString name, QPen pen, double size)
278{
279 float la = point.x() + _LaOff;
280 float fi = - point.y();
281
282 while( la < 0 ){ la += 360; }
283 while( la >= 360 ){ la -= 360; }
284
285 QPointF tmppoint(la,fi);
286 _allPoints << tmppoint;
287
288 if( ! name.isEmpty() ){
289
290 QList<QVariant> tmp;
291 tmp << tmppoint // QPoint
292 << pen // QPen
293 << size << 4.5; // base pointsize, fontrate
294 _allNames.insert( name, tmp );
295 }
296}
Note: See TracBrowser for help on using the repository browser.