[4636] | 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.
|
---|
[4622] | 24 |
|
---|
[4636] | 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: t_bncMap
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Plot map of stations from NTRIP source table
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 02-Sep-2012
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[4622] | 41 | #include <QtSvg>
|
---|
| 42 |
|
---|
[4631] | 43 | #include <qwt_symbol.h>
|
---|
[4622] | 44 | #include <qwt_plot.h>
|
---|
| 45 | #include <qwt_plot_svgitem.h>
|
---|
| 46 | #include <qwt_plot_curve.h>
|
---|
| 47 | #include <qwt_plot_marker.h>
|
---|
| 48 | #include <qwt_plot_canvas.h>
|
---|
[4634] | 49 | #include <qwt_plot_zoomer.h>
|
---|
[4631] | 50 | #include <qwt_plot_renderer.h>
|
---|
[4622] | 51 |
|
---|
| 52 | #include "bncmap.h"
|
---|
| 53 |
|
---|
| 54 | // Constructor
|
---|
| 55 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4626] | 56 | t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
|
---|
[4622] | 57 |
|
---|
[4630] | 58 | // Map in Scalable Vector Graphics (svg) Format
|
---|
| 59 | // --------------------------------------------
|
---|
[4626] | 60 | _mapPlot = new QwtPlot();
|
---|
[4622] | 61 |
|
---|
[4634] | 62 | _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
|
---|
| 63 | _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
|
---|
[4622] | 64 |
|
---|
[4651] | 65 | _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas());
|
---|
[4634] | 66 |
|
---|
[4626] | 67 | _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
|
---|
[4622] | 68 |
|
---|
[4626] | 69 | QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
|
---|
| 70 | mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
|
---|
| 71 | mapItem->attach(_mapPlot);
|
---|
[4622] | 72 |
|
---|
[4630] | 73 | // Buttons
|
---|
| 74 | // -------
|
---|
| 75 | int ww = QFontMetrics(font()).width('w');
|
---|
| 76 |
|
---|
| 77 | _buttonClose = new QPushButton(tr("Close"), this);
|
---|
| 78 | _buttonClose->setMaximumWidth(10*ww);
|
---|
| 79 | connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
|
---|
| 80 |
|
---|
| 81 | _buttonPrint = new QPushButton(tr("Print"), this);
|
---|
| 82 | _buttonPrint->setMaximumWidth(10*ww);
|
---|
| 83 | connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
|
---|
| 84 |
|
---|
[4712] | 85 | _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
|
---|
| 86 | _buttonWhatsThis->setMaximumWidth(10*ww);
|
---|
| 87 | connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
|
---|
| 88 |
|
---|
[4630] | 89 | // Layout
|
---|
| 90 | // ------
|
---|
| 91 | QHBoxLayout* buttonLayout = new QHBoxLayout;
|
---|
| 92 | buttonLayout->addWidget(_buttonClose);
|
---|
| 93 | buttonLayout->addWidget(_buttonPrint);
|
---|
[4712] | 94 | buttonLayout->addWidget(_buttonWhatsThis);
|
---|
[4630] | 95 |
|
---|
[4622] | 96 | QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
---|
[4626] | 97 | mainLayout->addWidget(_mapPlot);
|
---|
[4630] | 98 | mainLayout->addLayout(buttonLayout);
|
---|
[4622] | 99 |
|
---|
[4712] | 100 | // WhatsThis
|
---|
| 101 | // ---------
|
---|
| 102 | _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
|
---|
| 103 | _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>"));
|
---|
| 104 | // _mapPlot->setWhatsThis(tr("<p>Stream distribution map. Use the mouse to zoom in or out.</p><p>Left button: Draw rectangle to zoom in.<br>Right button: Zoom out.<br>Middle button: Zoom back.</p>"));
|
---|
| 105 |
|
---|
[4651] | 106 | // Minimal and Maximal Coordinates
|
---|
| 107 | // -------------------------------
|
---|
| 108 | _minPointLat = 0.0;
|
---|
| 109 | _maxPointLat = 0.0;
|
---|
| 110 | _minPointLon = 0.0;
|
---|
| 111 | _maxPointLon = 0.0;
|
---|
| 112 |
|
---|
[4630] | 113 | // Important
|
---|
| 114 | // ---------
|
---|
[4626] | 115 | _mapPlot->replot();
|
---|
[4622] | 116 | }
|
---|
| 117 |
|
---|
| 118 | // Destructor
|
---|
| 119 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4626] | 120 | t_bncMap::~t_bncMap() {
|
---|
| 121 | delete _mapPlot;
|
---|
[4712] | 122 | delete _buttonWhatsThis;
|
---|
[4622] | 123 | }
|
---|
[4626] | 124 |
|
---|
| 125 | //
|
---|
| 126 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4627] | 127 | void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
[4635] | 128 |
|
---|
| 129 | if (lonDeg > 180.0) lonDeg -= 360.0;
|
---|
| 130 |
|
---|
[4629] | 131 | QColor red(220,20,60);
|
---|
| 132 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
| 133 | QPen(red), QSize(2,2));
|
---|
[4626] | 134 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
[4627] | 135 | marker->setValue(lonDeg, latDeg);
|
---|
[4657] | 136 | if (lonDeg > 170.0) {
|
---|
| 137 | marker->setLabelAlignment(Qt::AlignLeft);
|
---|
| 138 | }
|
---|
| 139 | else {
|
---|
| 140 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
| 141 | }
|
---|
| 142 | QwtText text(name.left(4));
|
---|
| 143 | QFont font = text.font();
|
---|
| 144 | font.setPointSize(font.pointSize()*0.8);
|
---|
| 145 | text.setFont(font);
|
---|
| 146 | marker->setLabel(text);
|
---|
[4629] | 147 | marker->setSymbol(symbol);
|
---|
[4626] | 148 | marker->attach(_mapPlot);
|
---|
[4651] | 149 |
|
---|
| 150 | // Remeber minimal and maximal coordinates
|
---|
| 151 | // ---------------------------------------
|
---|
| 152 | if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
|
---|
| 153 | _minPointLon == 0.0 && _maxPointLon == 0.0) {
|
---|
| 154 | _minPointLat = latDeg;
|
---|
| 155 | _maxPointLat = latDeg;
|
---|
| 156 | _minPointLon = lonDeg;
|
---|
| 157 | _maxPointLon = lonDeg;
|
---|
| 158 | }
|
---|
| 159 | else {
|
---|
| 160 | if (_maxPointLat < latDeg) {
|
---|
| 161 | _maxPointLat = latDeg;
|
---|
| 162 | }
|
---|
| 163 | else if (_minPointLat > latDeg) {
|
---|
| 164 | _minPointLat = latDeg;
|
---|
| 165 | }
|
---|
| 166 | if (_maxPointLon < lonDeg) {
|
---|
| 167 | _maxPointLon = lonDeg;
|
---|
| 168 | }
|
---|
| 169 | else if (_minPointLon > lonDeg) {
|
---|
| 170 | _minPointLon = lonDeg;
|
---|
| 171 | }
|
---|
| 172 | }
|
---|
[4626] | 173 | }
|
---|
| 174 |
|
---|
[4630] | 175 | // Close
|
---|
| 176 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 177 | void t_bncMap::slotClose() {
|
---|
| 178 | done(0);
|
---|
| 179 | }
|
---|
[4626] | 180 |
|
---|
[4630] | 181 | // Close Dialog gracefully
|
---|
| 182 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 183 | void t_bncMap::closeEvent(QCloseEvent* event) {
|
---|
| 184 | QDialog::closeEvent(event);
|
---|
| 185 | }
|
---|
[4626] | 186 |
|
---|
[4651] | 187 | //
|
---|
| 188 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 189 | void t_bncMap::showEvent(QShowEvent* event) {
|
---|
| 190 | double width = _maxPointLon - _minPointLon;
|
---|
| 191 | double height = _maxPointLat - _minPointLat;
|
---|
| 192 | if (width > 0 && height > 0) {
|
---|
[4670] | 193 |
|
---|
| 194 | // Extend plot area by 10 percent
|
---|
| 195 | // ------------------------------
|
---|
[4656] | 196 | double eps = 0.1;
|
---|
[4657] | 197 | double epsLon = eps * (_maxPointLon - _minPointLon);
|
---|
| 198 | double epsLat = eps * (_maxPointLat - _minPointLat);
|
---|
| 199 | double widthExt = width + 2 * epsLon;
|
---|
| 200 | double heightExt = height + 2 * epsLat;
|
---|
| 201 | double minLon = _minPointLon - epsLon;
|
---|
| 202 | double minLat = _minPointLat - epsLat;
|
---|
[4670] | 203 |
|
---|
| 204 | // Keep lat/lon relations
|
---|
| 205 | // ----------------------
|
---|
| 206 | double widthBorder = widthExt;
|
---|
| 207 | double heightBorder = heightExt;
|
---|
| 208 | double scale = widthExt/heightExt/2.;
|
---|
| 209 | if ( scale < 1.) {
|
---|
| 210 | widthBorder = widthExt / scale;
|
---|
| 211 | minLon = minLon - (widthBorder - widthExt)/2.;
|
---|
| 212 | }
|
---|
| 213 | else {
|
---|
| 214 | heightBorder = heightExt * scale;
|
---|
| 215 | minLat = minLat - (heightBorder - heightExt)/2.;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | // Borders shall not exceed min or max values
|
---|
| 219 | // ------------------------------------------
|
---|
| 220 | if (minLon < -180.) minLon = -180.;
|
---|
| 221 | if (minLat < -90.) minLat = -90.;
|
---|
| 222 | double maxLat = minLat + heightBorder;
|
---|
| 223 | if ( maxLat > 90) minLat = minLat - (maxLat - 90.);
|
---|
| 224 | double maxLon = minLon + widthBorder;
|
---|
| 225 | if ( maxLon > 180) minLon = minLon - (maxLon - 180.);
|
---|
| 226 |
|
---|
| 227 | // Area large enough to justify world map
|
---|
| 228 | // --------------------------------------
|
---|
| 229 | if (widthBorder < 270.0 && heightBorder < 135.0) {
|
---|
| 230 | QRectF rect(minLon, minLat, widthBorder, heightBorder);
|
---|
[4656] | 231 | _mapPlotZoomer->zoom(rect);
|
---|
| 232 | }
|
---|
[4651] | 233 | }
|
---|
| 234 | QDialog::showEvent(event);
|
---|
| 235 | }
|
---|
| 236 |
|
---|
[4630] | 237 | // Print the widget
|
---|
| 238 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 239 | void t_bncMap::slotPrint() {
|
---|
| 240 |
|
---|
| 241 | QPrinter printer;
|
---|
| 242 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
[4631] | 243 | dialog->setWindowTitle(tr("Print Map"));
|
---|
[4630] | 244 | if (dialog->exec() != QDialog::Accepted) {
|
---|
| 245 | return;
|
---|
| 246 | }
|
---|
| 247 | else {
|
---|
[4631] | 248 | QwtPlotRenderer renderer;
|
---|
| 249 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
---|
| 250 | renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
---|
| 251 | renderer.renderTo(_mapPlot, printer);
|
---|
[4630] | 252 | }
|
---|
| 253 | }
|
---|
[4712] | 254 |
|
---|
| 255 | // Whats This Help
|
---|
| 256 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 257 | void t_bncMap::slotWhatsThis() {
|
---|
| 258 | QWhatsThis::enterWhatsThisMode();
|
---|
| 259 | }
|
---|
| 260 |
|
---|