source: ntrip/trunk/BNC/src/bncmap_svg.cpp@ 10269

Last change on this file since 10269 was 9935, checked in by stuerze, 2 years ago

minor changes

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