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

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