[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);
|
---|
[7667] | 86 | _buttonWhatsThis->setMaximumWidth(14*ww);
|
---|
[4712] | 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 |
|
---|
[7667] | 100 | // WhatsThis, Map
|
---|
| 101 | // --------------
|
---|
[4712] | 102 | _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
|
---|
| 103 | _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>"));
|
---|
| 104 |
|
---|
[4651] | 105 | // Minimal and Maximal Coordinates
|
---|
| 106 | // -------------------------------
|
---|
| 107 | _minPointLat = 0.0;
|
---|
| 108 | _maxPointLat = 0.0;
|
---|
| 109 | _minPointLon = 0.0;
|
---|
| 110 | _maxPointLon = 0.0;
|
---|
| 111 |
|
---|
[4630] | 112 | // Important
|
---|
| 113 | // ---------
|
---|
[4626] | 114 | _mapPlot->replot();
|
---|
[4622] | 115 | }
|
---|
| 116 |
|
---|
| 117 | // Destructor
|
---|
| 118 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4626] | 119 | t_bncMap::~t_bncMap() {
|
---|
| 120 | delete _mapPlot;
|
---|
[4712] | 121 | delete _buttonWhatsThis;
|
---|
[4622] | 122 | }
|
---|
[4626] | 123 |
|
---|
| 124 | //
|
---|
| 125 | /////////////////////////////////////////////////////////////////////////////
|
---|
[4627] | 126 | void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
[4635] | 127 |
|
---|
| 128 | if (lonDeg > 180.0) lonDeg -= 360.0;
|
---|
| 129 |
|
---|
[4629] | 130 | QColor red(220,20,60);
|
---|
| 131 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
| 132 | QPen(red), QSize(2,2));
|
---|
[4626] | 133 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
[4627] | 134 | marker->setValue(lonDeg, latDeg);
|
---|
[4657] | 135 | if (lonDeg > 170.0) {
|
---|
| 136 | marker->setLabelAlignment(Qt::AlignLeft);
|
---|
| 137 | }
|
---|
| 138 | else {
|
---|
| 139 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
| 140 | }
|
---|
| 141 | QwtText text(name.left(4));
|
---|
| 142 | QFont font = text.font();
|
---|
[6537] | 143 | font.setPointSize(int(font.pointSize()*0.8));
|
---|
[4657] | 144 | text.setFont(font);
|
---|
| 145 | marker->setLabel(text);
|
---|
[4629] | 146 | marker->setSymbol(symbol);
|
---|
[4626] | 147 | marker->attach(_mapPlot);
|
---|
[4651] | 148 |
|
---|
| 149 | // Remeber minimal and maximal coordinates
|
---|
| 150 | // ---------------------------------------
|
---|
| 151 | if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
|
---|
| 152 | _minPointLon == 0.0 && _maxPointLon == 0.0) {
|
---|
| 153 | _minPointLat = latDeg;
|
---|
| 154 | _maxPointLat = latDeg;
|
---|
| 155 | _minPointLon = lonDeg;
|
---|
| 156 | _maxPointLon = lonDeg;
|
---|
| 157 | }
|
---|
| 158 | else {
|
---|
| 159 | if (_maxPointLat < latDeg) {
|
---|
| 160 | _maxPointLat = latDeg;
|
---|
| 161 | }
|
---|
| 162 | else if (_minPointLat > latDeg) {
|
---|
| 163 | _minPointLat = latDeg;
|
---|
| 164 | }
|
---|
| 165 | if (_maxPointLon < lonDeg) {
|
---|
| 166 | _maxPointLon = lonDeg;
|
---|
| 167 | }
|
---|
| 168 | else if (_minPointLon > lonDeg) {
|
---|
| 169 | _minPointLon = lonDeg;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
[4626] | 172 | }
|
---|
| 173 |
|
---|
[4630] | 174 | // Close
|
---|
| 175 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 176 | void t_bncMap::slotClose() {
|
---|
| 177 | done(0);
|
---|
| 178 | }
|
---|
[4626] | 179 |
|
---|
[4630] | 180 | // Close Dialog gracefully
|
---|
| 181 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 182 | void t_bncMap::closeEvent(QCloseEvent* event) {
|
---|
| 183 | QDialog::closeEvent(event);
|
---|
| 184 | }
|
---|
[4626] | 185 |
|
---|
[4651] | 186 | //
|
---|
| 187 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 188 | void t_bncMap::showEvent(QShowEvent* event) {
|
---|
| 189 | double width = _maxPointLon - _minPointLon;
|
---|
| 190 | double height = _maxPointLat - _minPointLat;
|
---|
| 191 | if (width > 0 && height > 0) {
|
---|
[4670] | 192 |
|
---|
| 193 | // Extend plot area by 10 percent
|
---|
| 194 | // ------------------------------
|
---|
[4656] | 195 | double eps = 0.1;
|
---|
[4657] | 196 | double epsLon = eps * (_maxPointLon - _minPointLon);
|
---|
| 197 | double epsLat = eps * (_maxPointLat - _minPointLat);
|
---|
| 198 | double widthExt = width + 2 * epsLon;
|
---|
| 199 | double heightExt = height + 2 * epsLat;
|
---|
| 200 | double minLon = _minPointLon - epsLon;
|
---|
| 201 | double minLat = _minPointLat - epsLat;
|
---|
[4670] | 202 |
|
---|
| 203 | // Keep lat/lon relations
|
---|
| 204 | // ----------------------
|
---|
| 205 | double widthBorder = widthExt;
|
---|
| 206 | double heightBorder = heightExt;
|
---|
| 207 | double scale = widthExt/heightExt/2.;
|
---|
| 208 | if ( scale < 1.) {
|
---|
| 209 | widthBorder = widthExt / scale;
|
---|
| 210 | minLon = minLon - (widthBorder - widthExt)/2.;
|
---|
| 211 | }
|
---|
| 212 | else {
|
---|
| 213 | heightBorder = heightExt * scale;
|
---|
| 214 | minLat = minLat - (heightBorder - heightExt)/2.;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | // Borders shall not exceed min or max values
|
---|
| 218 | // ------------------------------------------
|
---|
| 219 | if (minLon < -180.) minLon = -180.;
|
---|
| 220 | if (minLat < -90.) minLat = -90.;
|
---|
| 221 | double maxLat = minLat + heightBorder;
|
---|
| 222 | if ( maxLat > 90) minLat = minLat - (maxLat - 90.);
|
---|
| 223 | double maxLon = minLon + widthBorder;
|
---|
| 224 | if ( maxLon > 180) minLon = minLon - (maxLon - 180.);
|
---|
| 225 |
|
---|
| 226 | // Area large enough to justify world map
|
---|
| 227 | // --------------------------------------
|
---|
| 228 | if (widthBorder < 270.0 && heightBorder < 135.0) {
|
---|
| 229 | QRectF rect(minLon, minLat, widthBorder, heightBorder);
|
---|
[4656] | 230 | _mapPlotZoomer->zoom(rect);
|
---|
| 231 | }
|
---|
[4651] | 232 | }
|
---|
| 233 | QDialog::showEvent(event);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[4630] | 236 | // Print the widget
|
---|
| 237 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 238 | void t_bncMap::slotPrint() {
|
---|
| 239 |
|
---|
| 240 | QPrinter printer;
|
---|
| 241 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
[4631] | 242 | dialog->setWindowTitle(tr("Print Map"));
|
---|
[4630] | 243 | if (dialog->exec() != QDialog::Accepted) {
|
---|
| 244 | return;
|
---|
| 245 | }
|
---|
| 246 | else {
|
---|
[4631] | 247 | QwtPlotRenderer renderer;
|
---|
| 248 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
---|
| 249 | renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
---|
| 250 | renderer.renderTo(_mapPlot, printer);
|
---|
[4630] | 251 | }
|
---|
| 252 | }
|
---|
[4712] | 253 |
|
---|
| 254 | // Whats This Help
|
---|
| 255 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 256 | void t_bncMap::slotWhatsThis() {
|
---|
| 257 | QWhatsThis::enterWhatsThisMode();
|
---|
| 258 | }
|
---|
| 259 |
|
---|