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

Last change on this file since 5415 was 5415, checked in by mervart, 11 years ago
File size: 7.5 KB
RevLine 
[4836]1
2/* -------------------------------------------------------------------------
3 * RTNet GUI
4 * -------------------------------------------------------------------------
5 *
[5406]6 * Class: t_map_stations
[4836]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
[5406]29#include "map_stations.h"
[4836]30
[4858]31using namespace std;
[5001]32using namespace GnssCenter;
[4858]33
[5406]34Q_EXPORT_PLUGIN2(gnsscenter_map_stations, GnssCenter::t_map_stationsFactory)
[5018]35
[4836]36// Constructor
37/////////////////////////////////////////////////////////////////////////////
[5406]38t_map_stations::t_map_stations() : QDialog() {
[4836]39
40 // Map in Scalable Vector Graphics (svg) Format
41 // --------------------------------------------
42 _mapPlot = new QwtPlot();
43
44 _mapPlot->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
45 _mapPlot->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
46
47 _mapPlotZoomer = new QwtPlotZoomer(_mapPlot->canvas());
48
49 _mapPlot->canvas()->setFocusPolicy(Qt::WheelFocus);
50
51 QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
[4859]52 mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
[4836]53 mapItem->attach(_mapPlot);
54
55 // Buttons
56 // -------
57 int ww = QFontMetrics(font()).width('w');
58
59 _buttonClose = new QPushButton(tr("Close"), this);
60 _buttonClose->setMaximumWidth(10*ww);
61 connect(_buttonClose, SIGNAL(clicked()), this, SLOT(slotClose()));
62
63 _buttonPrint = new QPushButton(tr("Print"), this);
64 _buttonPrint->setMaximumWidth(10*ww);
65 connect(_buttonPrint, SIGNAL(clicked()), this, SLOT(slotPrint()));
66
67 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
68 _buttonWhatsThis->setMaximumWidth(10*ww);
69 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
70
71 // Layout
72 // ------
73 QHBoxLayout* buttonLayout = new QHBoxLayout;
74 buttonLayout->addWidget(_buttonClose);
75 buttonLayout->addWidget(_buttonPrint);
76 buttonLayout->addWidget(_buttonWhatsThis);
77
78 QVBoxLayout* mainLayout = new QVBoxLayout(this);
79 mainLayout->addWidget(_mapPlot);
80 mainLayout->addLayout(buttonLayout);
81
82 // WhatsThis
83 // ---------
84 _buttonClose->setWhatsThis(tr("<p>Close window.</p>"));
85 _buttonPrint->setWhatsThis(tr("<p>Print stream distribution map.</p>"));
86
87 // Minimal and Maximal Coordinates
88 // -------------------------------
89 _minPointLat = 0.0;
90 _maxPointLat = 0.0;
91 _minPointLon = 0.0;
92 _maxPointLon = 0.0;
93
94 // Important
95 // ---------
96 _mapPlot->replot();
[5410]97
98 // Thrift Client;
[5415]99 // --------------
[5410]100 _thriftClient = new t_thriftClient;
[5415]101 connect(_thriftClient, SIGNAL(newThriftResult(t_thriftResult)),
102 this, SLOT(slotNewThriftResult(t_thriftResult)));
[5410]103 _thriftClient->start();
[4836]104}
105
106// Destructor
107/////////////////////////////////////////////////////////////////////////////
[5406]108t_map_stations::~t_map_stations() {
[4836]109 delete _mapPlot;
110 delete _buttonWhatsThis;
[5414]111 _thriftClient->stop();
[4836]112}
113
114//
115/////////////////////////////////////////////////////////////////////////////
[5406]116void t_map_stations::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
[4836]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
[5415]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
[4836]172// Close
173////////////////////////////////////////////////////////////////////////////
[5406]174void t_map_stations::slotClose() {
[4836]175 done(0);
176}
177
178// Close Dialog gracefully
179////////////////////////////////////////////////////////////////////////////
[5406]180void t_map_stations::closeEvent(QCloseEvent* event) {
[4836]181 QDialog::closeEvent(event);
182}
183
184//
185////////////////////////////////////////////////////////////////////////////
[5406]186void t_map_stations::showEvent(QShowEvent* event) {
[4836]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////////////////////////////////////////////////////////////////////////////
[5406]236void t_map_stations::slotPrint() {
[4836]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////////////////////////////////////////////////////////////////////////////
[5406]254void t_map_stations::slotWhatsThis() {
[4858]255 QWhatsThis::enterWhatsThisMode();
[4836]256}
257
Note: See TracBrowser for help on using the repository browser.