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

Last change on this file since 5416 was 5416, 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 <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 // Thrift Client;
100 // --------------
101 _thriftClient = new t_thriftClient(this);
102 _thriftClient->start();
103}
104
105// Destructor
106/////////////////////////////////////////////////////////////////////////////
107t_map_stations::~t_map_stations() {
108 delete _mapPlot;
109 delete _buttonWhatsThis;
110 _thriftClient->stop();
111}
112
113//
114/////////////////////////////////////////////////////////////////////////////
115void t_map_stations::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
116
117 if (lonDeg > 180.0) lonDeg -= 360.0;
118
119 QColor red(220,20,60);
120 QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
121 QPen(red), QSize(2,2));
122 QwtPlotMarker* marker = new QwtPlotMarker();
123 marker->setValue(lonDeg, latDeg);
124 if (lonDeg > 170.0) {
125 marker->setLabelAlignment(Qt::AlignLeft);
126 }
127 else {
128 marker->setLabelAlignment(Qt::AlignRight);
129 }
130 QwtText text(name.left(4));
131 QFont font = text.font();
132 font.setPointSize(font.pointSize()*0.8);
133 text.setFont(font);
134 marker->setLabel(text);
135 marker->setSymbol(symbol);
136 marker->attach(_mapPlot);
137
138 // Remeber minimal and maximal coordinates
139 // ---------------------------------------
140 if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
141 _minPointLon == 0.0 && _maxPointLon == 0.0) {
142 _minPointLat = latDeg;
143 _maxPointLat = latDeg;
144 _minPointLon = lonDeg;
145 _maxPointLon = lonDeg;
146 }
147 else {
148 if (_maxPointLat < latDeg) {
149 _maxPointLat = latDeg;
150 }
151 else if (_minPointLat > latDeg) {
152 _minPointLat = latDeg;
153 }
154 if (_maxPointLon < lonDeg) {
155 _maxPointLon = lonDeg;
156 }
157 else if (_minPointLon > lonDeg) {
158 _minPointLon = lonDeg;
159 }
160 }
161}
162
163//
164/////////////////////////////////////////////////////////////////////////////
165void t_map_stations::slotNewThriftResult(t_thriftResult* result) {
166 cout << result->_name << ' '
167 << result->_nGPS << ' ' << result->_nGLO << ' '
168 << result->_x << ' ' << result->_y << ' ' << result->_z << endl;
169}
170
171// Close
172////////////////////////////////////////////////////////////////////////////
173void t_map_stations::slotClose() {
174 done(0);
175}
176
177// Close Dialog gracefully
178////////////////////////////////////////////////////////////////////////////
179void t_map_stations::closeEvent(QCloseEvent* event) {
180 QDialog::closeEvent(event);
181}
182
183//
184////////////////////////////////////////////////////////////////////////////
185void t_map_stations::showEvent(QShowEvent* event) {
186 double width = _maxPointLon - _minPointLon;
187 double height = _maxPointLat - _minPointLat;
188 if (width > 0 && height > 0) {
189
190 // Extend plot area by 10 percent
191 // ------------------------------
192 double eps = 0.1;
193 double epsLon = eps * (_maxPointLon - _minPointLon);
194 double epsLat = eps * (_maxPointLat - _minPointLat);
195 double widthExt = width + 2 * epsLon;
196 double heightExt = height + 2 * epsLat;
197 double minLon = _minPointLon - epsLon;
198 double minLat = _minPointLat - epsLat;
199
200 // Keep lat/lon relations
201 // ----------------------
202 double widthBorder = widthExt;
203 double heightBorder = heightExt;
204 double scale = widthExt/heightExt/2.;
205 if ( scale < 1.) {
206 widthBorder = widthExt / scale;
207 minLon = minLon - (widthBorder - widthExt)/2.;
208 }
209 else {
210 heightBorder = heightExt * scale;
211 minLat = minLat - (heightBorder - heightExt)/2.;
212 }
213
214 // Borders shall not exceed min or max values
215 // ------------------------------------------
216 if (minLon < -180.) minLon = -180.;
217 if (minLat < -90.) minLat = -90.;
218 double maxLat = minLat + heightBorder;
219 if ( maxLat > 90) minLat = minLat - (maxLat - 90.);
220 double maxLon = minLon + widthBorder;
221 if ( maxLon > 180) minLon = minLon - (maxLon - 180.);
222
223 // Area large enough to justify world map
224 // --------------------------------------
225 if (widthBorder < 270.0 && heightBorder < 135.0) {
226 QRectF rect(minLon, minLat, widthBorder, heightBorder);
227 _mapPlotZoomer->zoom(rect);
228 }
229 }
230 QDialog::showEvent(event);
231}
232
233// Print the widget
234////////////////////////////////////////////////////////////////////////////
235void t_map_stations::slotPrint() {
236
237 QPrinter printer;
238 QPrintDialog* dialog = new QPrintDialog(&printer, this);
239 dialog->setWindowTitle(tr("Print Map"));
240 if (dialog->exec() != QDialog::Accepted) {
241 return;
242 }
243 else {
244 QwtPlotRenderer renderer;
245 renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
246 renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
247 renderer.renderTo(_mapPlot, printer);
248 }
249}
250
251// Whats This Help
252////////////////////////////////////////////////////////////////////////////
253void t_map_stations::slotWhatsThis() {
254 QWhatsThis::enterWhatsThisMode();
255}
256
Note: See TracBrowser for help on using the repository browser.