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

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