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