source: ntrip/trunk/GnssCenter/map_stations/map_stations.cpp@ 5409

Last change on this file since 5409 was 5407, checked in by mervart, 11 years ago
File size: 7.0 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_map_stations
7 *
8 * Purpose: Plot map of stations/satellites
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <QtSvg>
19
20#include <qwt_symbol.h>
21#include <qwt_plot.h>
22#include <qwt_plot_svgitem.h>
23#include <qwt_plot_curve.h>
24#include <qwt_plot_marker.h>
25#include <qwt_plot_canvas.h>
26#include <qwt_plot_zoomer.h>
27#include <qwt_plot_renderer.h>
28
29#include "map_stations.h"
30#include "thriftclient.h"
31
32using namespace std;
33using namespace GnssCenter;
34
35Q_EXPORT_PLUGIN2(gnsscenter_map_stations, GnssCenter::t_map_stationsFactory)
36
37// Constructor
38/////////////////////////////////////////////////////////////////////////////
39t_map_stations::t_map_stations() : QDialog() {
40
41 // Map in Scalable Vector Graphics (svg) Format
42 // --------------------------------------------
43 _mapPlot = new QwtPlot();
44
45 _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
46 _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
47
48 _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas());
49
50 _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
51
52 QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
53 mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
54 mapItem->attach(_mapPlot);
55
56 // Buttons
57 // -------
58 int ww = QFontMetrics(font()).width('w');
59
60 _buttonClose = new QPushButton(tr("Close"), this);
61 _buttonClose->setMaximumWidth(10*ww);
62 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
63
64 _buttonPrint = new QPushButton(tr("Print"), this);
65 _buttonPrint->setMaximumWidth(10*ww);
66 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
67
68 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
69 _buttonWhatsThis->setMaximumWidth(10*ww);
70 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
71
72 // Layout
73 // ------
74 QHBoxLayout* buttonLayout = new QHBoxLayout;
75 buttonLayout->addWidget(_buttonClose);
76 buttonLayout->addWidget(_buttonPrint);
77 buttonLayout->addWidget(_buttonWhatsThis);
78
79 QVBoxLayout* mainLayout = new QVBoxLayout(this);
80 mainLayout->addWidget(_mapPlot);
81 mainLayout->addLayout(buttonLayout);
82
83 // WhatsThis
84 // ---------
85 _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
86 _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>"));
87
88 // Minimal and Maximal Coordinates
89 // -------------------------------
90 _minPointLat = 0.0;
91 _maxPointLat = 0.0;
92 _minPointLon = 0.0;
93 _maxPointLon = 0.0;
94
95 // Important
96 // ---------
97 _mapPlot->replot();
98}
99
100// Destructor
101/////////////////////////////////////////////////////////////////////////////
102t_map_stations::~t_map_stations() {
103 delete _mapPlot;
104 delete _buttonWhatsThis;
105}
106
107//
108/////////////////////////////////////////////////////////////////////////////
109void t_map_stations::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
110
111 if (lonDeg > 180.0) lonDeg -= 360.0;
112
113 QColor red(220,20,60);
114 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
115 QPen(red), QSize(2,2));
116 QwtPlotMarker* marker = new QwtPlotMarker();
117 marker->setValue(lonDeg, latDeg);
118 if (lonDeg > 170.0) {
119 marker->setLabelAlignment(Qt::AlignLeft);
120 }
121 else {
122 marker->setLabelAlignment(Qt::AlignRight);
123 }
124 QwtText text(name.left(4));
125 QFont font = text.font();
126 font.setPointSize(font.pointSize()*0.8);
127 text.setFont(font);
128 marker->setLabel(text);
129 marker->setSymbol(symbol);
130 marker->attach(_mapPlot);
131
132 // Remeber minimal and maximal coordinates
133 // ---------------------------------------
134 if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
135 _minPointLon == 0.0 && _maxPointLon == 0.0) {
136 _minPointLat = latDeg;
137 _maxPointLat = latDeg;
138 _minPointLon = lonDeg;
139 _maxPointLon = lonDeg;
140 }
141 else {
142 if (_maxPointLat < latDeg) {
143 _maxPointLat = latDeg;
144 }
145 else if (_minPointLat > latDeg) {
146 _minPointLat = latDeg;
147 }
148 if (_maxPointLon < lonDeg) {
149 _maxPointLon = lonDeg;
150 }
151 else if (_minPointLon > lonDeg) {
152 _minPointLon = lonDeg;
153 }
154 }
155}
156
157// Close
158////////////////////////////////////////////////////////////////////////////
159void t_map_stations::slotClose() {
160 done(0);
161}
162
163// Close Dialog gracefully
164////////////////////////////////////////////////////////////////////////////
165void t_map_stations::closeEvent(QCloseEvent* event) {
166 QDialog::closeEvent(event);
167}
168
169//
170////////////////////////////////////////////////////////////////////////////
171void t_map_stations::showEvent(QShowEvent* event) {
172 double width = _maxPointLon - _minPointLon;
173 double height = _maxPointLat - _minPointLat;
174 if (width > 0 && height > 0) {
175
176 // Extend plot area by 10 percent
177 // ------------------------------
178 double eps = 0.1;
179 double epsLon = eps * (_maxPointLon - _minPointLon);
180 double epsLat = eps * (_maxPointLat - _minPointLat);
181 double widthExt = width + 2 * epsLon;
182 double heightExt = height + 2 * epsLat;
183 double minLon = _minPointLon - epsLon;
184 double minLat = _minPointLat - epsLat;
185
186 // Keep lat/lon relations
187 // ----------------------
188 double widthBorder = widthExt;
189 double heightBorder = heightExt;
190 double scale = widthExt/heightExt/2.;
191 if ( scale < 1.) {
192 widthBorder = widthExt / scale;
193 minLon = minLon - (widthBorder - widthExt)/2.;
194 }
195 else {
196 heightBorder = heightExt * scale;
197 minLat = minLat - (heightBorder - heightExt)/2.;
198 }
199
200 // Borders shall not exceed min or max values
201 // ------------------------------------------
202 if (minLon < -180.) minLon = -180.;
203 if (minLat < -90.) minLat = -90.;
204 double maxLat = minLat + heightBorder;
205 if ( maxLat > 90) minLat = minLat - (maxLat - 90.);
206 double maxLon = minLon + widthBorder;
207 if ( maxLon > 180) minLon = minLon - (maxLon - 180.);
208
209 // Area large enough to justify world map
210 // --------------------------------------
211 if (widthBorder < 270.0 && heightBorder < 135.0) {
212 QRectF rect(minLon, minLat, widthBorder, heightBorder);
213 _mapPlotZoomer->zoom(rect);
214 }
215 }
216 QDialog::showEvent(event);
217}
218
219// Print the widget
220////////////////////////////////////////////////////////////////////////////
221void t_map_stations::slotPrint() {
222
223 QPrinter printer;
224 QPrintDialog* dialog = new QPrintDialog(&printer, this);
225 dialog->setWindowTitle(tr("Print Map"));
226 if (dialog->exec() != QDialog::Accepted) {
227 return;
228 }
229 else {
230 QwtPlotRenderer renderer;
231 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
232 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
233 renderer.renderTo(_mapPlot, printer);
234 }
235}
236
237// Whats This Help
238////////////////////////////////////////////////////////////////////////////
239void t_map_stations::slotWhatsThis() {
240 QWhatsThis::enterWhatsThisMode();
241}
242
Note: See TracBrowser for help on using the repository browser.