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

Last change on this file since 9935 was 9935, checked in by stuerze, 18 months ago

minor changes

File size: 7.8 KB
Line 
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: 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
41#include <QHBoxLayout>
42#include <QPrinter>
43#include <QPrintDialog>
44#include <QPushButton>
45
46#include <qwt_symbol.h>
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>
52#include <qwt_plot_zoomer.h>
53#include <qwt_plot_renderer.h>
54
55#include "bncmap.h"
56
57// Constructor
58/////////////////////////////////////////////////////////////////////////////
59t_bncMap::t_bncMap(QWidget* parent) : QDialog(parent) {
60
61 // Map in Scalable Vector Graphics (svg) Format
62 // --------------------------------------------
63 _mapPlot = new QwtPlot();
64
65 _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
66 _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
67
68 _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas());
69
70 _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
71
72 QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
73 mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
74 mapItem->attach(_mapPlot);
75
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
88 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
89 _buttonWhatsThis->setMaximumWidth(14*ww);
90 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
91
92 // Layout
93 // ------
94 QHBoxLayout* buttonLayout = new QHBoxLayout;
95 buttonLayout->addWidget(_buttonClose);
96 buttonLayout->addWidget(_buttonPrint);
97 buttonLayout->addWidget(_buttonWhatsThis);
98
99 QVBoxLayout* mainLayout = new QVBoxLayout(this);
100 mainLayout->addWidget(_mapPlot);
101 mainLayout->addLayout(buttonLayout);
102
103 // WhatsThis, Map
104 // --------------
105 _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
106 _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>"));
107
108 // Minimal and Maximal Coordinates
109 // -------------------------------
110 _minPointLat = 0.0;
111 _maxPointLat = 0.0;
112 _minPointLon = 0.0;
113 _maxPointLon = 0.0;
114
115 // Important
116 // ---------
117 _mapPlot->replot();
118}
119
120// Destructor
121/////////////////////////////////////////////////////////////////////////////
122t_bncMap::~t_bncMap() {
123 delete _mapPlot;
124 delete _buttonWhatsThis;
125}
126
127//
128/////////////////////////////////////////////////////////////////////////////
129void t_bncMap::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
130
131 if (lonDeg > 180.0) lonDeg -= 360.0;
132
133 QColor red(220,20,60);
134 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
135 QPen(red), QSize(2,2));
136 QwtPlotMarker* marker = new QwtPlotMarker();
137 marker->setValue(lonDeg, latDeg);
138 if (lonDeg > 170.0) {
139 marker->setLabelAlignment(Qt::AlignLeft);
140 }
141 else {
142 marker->setLabelAlignment(Qt::AlignRight);
143 }
144 QwtText text(name.left(9));
145 QFont font = text.font();
146 font.setPointSize(int(font.pointSize()*0.8));
147 text.setFont(font);
148 marker->setLabel(text);
149 marker->setSymbol(symbol);
150 marker->attach(_mapPlot);
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 }
175}
176
177// Close
178////////////////////////////////////////////////////////////////////////////
179void t_bncMap::slotClose() {
180 done(0);
181}
182
183// Close Dialog gracefully
184////////////////////////////////////////////////////////////////////////////
185void t_bncMap::closeEvent(QCloseEvent* event) {
186 QDialog::closeEvent(event);
187}
188
189//
190////////////////////////////////////////////////////////////////////////////
191void t_bncMap::showEvent(QShowEvent* event) {
192 double width = _maxPointLon - _minPointLon;
193 double height = _maxPointLat - _minPointLat;
194 if (width > 0 && height > 0) {
195
196 // Extend plot area by 10 percent
197 // ------------------------------
198 double eps = 0.1;
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;
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);
233 _mapPlotZoomer->zoom(rect);
234 }
235 }
236 QDialog::showEvent(event);
237}
238
239// Print the widget
240////////////////////////////////////////////////////////////////////////////
241void t_bncMap::slotPrint() {
242
243 QPrinter printer;
244 QPrintDialog* dialog = new QPrintDialog(&printer, this);
245 dialog->setWindowTitle(tr("Print Map"));
246 if (dialog->exec() != QDialog::Accepted) {
247 return;
248 }
249 else {
250 QwtPlotRenderer renderer;
251 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
252 //renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
253 renderer.renderTo(_mapPlot, printer);
254 }
255}
256
257// Whats This Help
258////////////////////////////////////////////////////////////////////////////
259void t_bncMap::slotWhatsThis() {
260QWhatsThis::enterWhatsThisMode();
261}
262
Note: See TracBrowser for help on using the repository browser.