[4198] | 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 | * -----------------------------------------------------------------------*/
|
---|
[2753] | 39 |
|
---|
| 40 | #include <iostream>
|
---|
| 41 | #include "bncmap.h"
|
---|
| 42 |
|
---|
| 43 | // ------------
|
---|
| 44 | bncMap::bncMap(QWidget* parent) : QDialog(parent)
|
---|
| 45 | {
|
---|
[3288] | 46 | _LaOff = 25; // shift longitude
|
---|
[2753] | 47 | _mapScen = new QGraphicsScene();
|
---|
[2796] | 48 | _mapView = new BncMapView();
|
---|
[2753] | 49 | _mapView->setScene(_mapScen);
|
---|
[3288] | 50 | _mapView->resetScale();
|
---|
[2753] | 51 | slotReadMap();
|
---|
| 52 | slotCreateMap();
|
---|
[2796] | 53 | _mapScen->setSceneRect(QRect(0,-90,360,180));
|
---|
[2753] | 54 |
|
---|
[2796] | 55 | setWindowTitle(tr("Source-Table Map [*]"));
|
---|
[2753] | 56 |
|
---|
| 57 | /* close button */
|
---|
| 58 | QPushButton* buttClose = new QPushButton("Close");
|
---|
| 59 | connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
|
---|
[2796] | 60 |
|
---|
| 61 | /* rescale button */
|
---|
[3288] | 62 | // QPushButton* buttClean = new QPushButton("Clean");
|
---|
| 63 | // connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
|
---|
[2753] | 64 |
|
---|
[2796] | 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 |
|
---|
[3288] | 73 | /* reset button */
|
---|
| 74 | QPushButton* buttReset = new QPushButton("World");
|
---|
| 75 | connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
|
---|
| 76 |
|
---|
[2796] | 77 | /* fit button */
|
---|
[3288] | 78 | QPushButton* buttFit = new QPushButton("Fit Map");
|
---|
[2796] | 79 | connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
|
---|
| 80 |
|
---|
[3288] | 81 | /* font reset button */
|
---|
| 82 | QPushButton* buttFont = new QPushButton("Fit Font");
|
---|
| 83 | connect(buttFont, SIGNAL(clicked()), this, SLOT(slotFitFont()));
|
---|
| 84 |
|
---|
[2753] | 85 | /* layout */
|
---|
[2796] | 86 | QVBoxLayout* MapLayout = new QVBoxLayout;
|
---|
| 87 | QHBoxLayout* ButLayout = new QHBoxLayout;
|
---|
| 88 |
|
---|
| 89 | ButLayout->addWidget(buttZoomIn);
|
---|
| 90 | ButLayout->addWidget(buttZoomOut);
|
---|
[3288] | 91 | // ButLayout->addWidget(buttClean);
|
---|
[2796] | 92 | ButLayout->addWidget(buttReset);
|
---|
| 93 | ButLayout->addWidget(buttFit);
|
---|
[3288] | 94 | ButLayout->addWidget(buttFont);
|
---|
[2796] | 95 | ButLayout->addWidget(buttClose);
|
---|
| 96 |
|
---|
| 97 | MapLayout->addWidget(_mapView);
|
---|
| 98 | MapLayout->addLayout(ButLayout);
|
---|
| 99 |
|
---|
| 100 | setLayout(MapLayout);
|
---|
| 101 |
|
---|
[2753] | 102 | this->show();
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | // ------------
|
---|
| 107 | bncMap::~bncMap(){
|
---|
| 108 | delete _mapView;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | // ------------
|
---|
| 113 | void bncMap::slotReadMap()
|
---|
| 114 | {
|
---|
[2754] | 115 | QFile world(":worldmap.dat");
|
---|
[2753] | 116 | float fi, la;
|
---|
| 117 |
|
---|
[2754] | 118 | world.open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
[2753] | 119 |
|
---|
[2754] | 120 | QTextStream in(&world);
|
---|
| 121 | in.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
[2753] | 122 |
|
---|
[2754] | 123 | while( ! in.atEnd() ){
|
---|
[2753] | 124 |
|
---|
[2754] | 125 | in >> la >> fi;
|
---|
[2796] | 126 |
|
---|
| 127 | // la = 0-360
|
---|
| 128 | while( la < 0 ){ la += 360; }
|
---|
| 129 | while( la >= 360 ){ la -= 360; }
|
---|
| 130 |
|
---|
| 131 | // fi opposite
|
---|
[2754] | 132 | _worldMap << QPointF( la, -fi );
|
---|
[2796] | 133 |
|
---|
[2753] | 134 | }
|
---|
| 135 | world.close();
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | // ------------
|
---|
| 140 | void bncMap::slotCreateMap()
|
---|
| 141 | {
|
---|
[2796] | 142 | // _mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern)); // grid
|
---|
[2753] | 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 ){
|
---|
[2796] | 149 | endIdx = i-1;
|
---|
[2753] | 150 | while( begIdx < endIdx ){
|
---|
| 151 |
|
---|
[2796] | 152 | int l1 = 0;
|
---|
| 153 | int l2 = 0;
|
---|
[2753] | 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++;
|
---|
[2796] | 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--; }
|
---|
[2753] | 165 |
|
---|
[2796] | 166 | if( l1 != 0 and l2 == 0 ){ continue; } // break this line
|
---|
| 167 | if( l2 != 0 and l1 == 0 ){ continue; } // break this line
|
---|
[2753] | 168 |
|
---|
[2796] | 169 | _mapScen->addLine(la1, fi1, la2, fi2, QPen(QBrush(Qt::gray),0.3));
|
---|
[2753] | 170 | }
|
---|
| 171 | }
|
---|
| 172 | if( i+1 < _worldMap.size() ) begIdx = i+1;
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 |
|
---|
| 178 | // ------------
|
---|
[2796] | 179 | void bncMap::slotCleanMap()
|
---|
[2753] | 180 | {
|
---|
| 181 | QMutexLocker locker(&_mutexMap);
|
---|
| 182 | _mapScen->clear();
|
---|
| 183 | slotCreateMap();
|
---|
[2796] | 184 | slotResetMap();
|
---|
[3288] | 185 | slotFitFont();
|
---|
[2753] | 186 | }
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | // ------------
|
---|
[2796] | 190 | void bncMap::slotResetMap()
|
---|
| 191 | {
|
---|
[3288] | 192 | _mapView->resetScale();
|
---|
[2796] | 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | // ------------
|
---|
[3288] | 197 | void bncMap::slotFitMap()
|
---|
[2796] | 198 | {
|
---|
[3288] | 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();
|
---|
[2796] | 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | // ------------
|
---|
[3288] | 211 | void bncMap::slotFitFont()
|
---|
[2796] | 212 | {
|
---|
[3288] | 213 | _mapScen->clear();
|
---|
| 214 | slotCreateMap();
|
---|
| 215 |
|
---|
[4198] | 216 | float fontrate = _mapView->scale_rate();
|
---|
| 217 | float pointrate = _mapView->scale_rate();
|
---|
[3288] | 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 |
|
---|
[4198] | 232 | float tmpPT = pointrate * basPT;
|
---|
| 233 | float tmpFT = fontrate * basFT;
|
---|
[3288] | 234 |
|
---|
[4198] | 235 | if( fontrate > 1 ){
|
---|
| 236 | tmpPT = basPT;
|
---|
| 237 | tmpFT = basFT;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | QFont font(QFont("Arial",2));
|
---|
[3288] | 241 | font.setPointSizeF( tmpFT );
|
---|
[4198] | 242 | font.setStretch(QFont::Unstretched);
|
---|
| 243 | font.setCapitalization(QFont::Capitalize);
|
---|
[3288] | 244 |
|
---|
| 245 | QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
|
---|
| 246 | nameItem->setFont( font );
|
---|
[4198] | 247 |
|
---|
| 248 | nameItem->setPos( la - basFT, fi - basFT );
|
---|
[3288] | 249 |
|
---|
[4198] | 250 | if( tmpPT < 0.15 ) tmpPT = 0.15;
|
---|
[3288] | 251 | pen.setWidthF(tmpPT);
|
---|
| 252 |
|
---|
| 253 | _mapScen->addItem( nameItem );
|
---|
| 254 | _mapScen->addEllipse( la, fi, tmpPT, tmpPT, pen );
|
---|
| 255 | }
|
---|
| 256 | _mapView->zoom( 1.0 );
|
---|
[2796] | 257 | }
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | // ------------
|
---|
[3288] | 261 | void bncMap::slotZoomIn()
|
---|
[2796] | 262 | {
|
---|
[3288] | 263 | _mapView->zoom( 1.2 );
|
---|
[4198] | 264 | slotFitFont();
|
---|
[2796] | 265 | }
|
---|
| 266 |
|
---|
| 267 |
|
---|
| 268 | // ------------
|
---|
[3288] | 269 | void bncMap::slotZoomOut()
|
---|
| 270 | {
|
---|
| 271 | _mapView->zoom( 1/1.2 );
|
---|
[4198] | 272 | slotFitFont();
|
---|
[3288] | 273 | }
|
---|
| 274 |
|
---|
| 275 |
|
---|
| 276 | // ------------
|
---|
| 277 | void bncMap::slotNewPoint(QPointF point, QString name, QPen pen, double size)
|
---|
[2753] | 278 | {
|
---|
[2796] | 279 | float la = point.x() + _LaOff;
|
---|
| 280 | float fi = - point.y();
|
---|
[2753] | 281 |
|
---|
| 282 | while( la < 0 ){ la += 360; }
|
---|
| 283 | while( la >= 360 ){ la -= 360; }
|
---|
[2796] | 284 |
|
---|
[3288] | 285 | QPointF tmppoint(la,fi);
|
---|
| 286 | _allPoints << tmppoint;
|
---|
[2753] | 287 |
|
---|
| 288 | if( ! name.isEmpty() ){
|
---|
| 289 |
|
---|
[3288] | 290 | QList<QVariant> tmp;
|
---|
| 291 | tmp << tmppoint // QPoint
|
---|
| 292 | << pen // QPen
|
---|
[4198] | 293 | << size << 4.5; // base pointsize, fontrate
|
---|
[3288] | 294 | _allNames.insert( name, tmp );
|
---|
[2753] | 295 | }
|
---|
[2805] | 296 | }
|
---|