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