1 |
|
---|
2 | /* -------------------------------------------------------------------------
|
---|
3 | * RTNet GUI
|
---|
4 | * -------------------------------------------------------------------------
|
---|
5 | *
|
---|
6 | * Class: t_worldPlot
|
---|
7 | *
|
---|
8 | * Purpose: Plot map of stations/satellites
|
---|
9 | *
|
---|
10 | * Author: L. Mervart
|
---|
11 | *
|
---|
12 | * Created: 12-Sep-2013
|
---|
13 | *
|
---|
14 | * Changes:
|
---|
15 | *
|
---|
16 | * -----------------------------------------------------------------------*/
|
---|
17 |
|
---|
18 | #include <iostream>
|
---|
19 | #include <QtSvg>
|
---|
20 |
|
---|
21 | #include <qwt_symbol.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 "worldplot.h"
|
---|
30 |
|
---|
31 | using namespace std;
|
---|
32 | using namespace GnssCenter;
|
---|
33 |
|
---|
34 | // Constructor
|
---|
35 | /////////////////////////////////////////////////////////////////////////////
|
---|
36 | t_worldPlot::t_worldPlot() : QwtPlot() {
|
---|
37 |
|
---|
38 | // Map in Scalable Vector Graphics (svg) Format
|
---|
39 | // --------------------------------------------
|
---|
40 | this->setAxisScale(QwtPlot::xBottom, -180.0, 180.0);
|
---|
41 | this->setAxisScale(QwtPlot::yLeft, -90.0, 90.0);
|
---|
42 |
|
---|
43 | _zoomer = new QwtPlotZoomer(this->canvas());
|
---|
44 |
|
---|
45 | this->canvas()->setFocusPolicy(Qt::WheelFocus);
|
---|
46 |
|
---|
47 | QwtPlotSvgItem* mapItem = new QwtPlotSvgItem();
|
---|
48 | mapItem->loadFile(QRectF(-180.0, -90.0, 360.0, 180.0), ":world.svg");
|
---|
49 | mapItem->attach(this);
|
---|
50 |
|
---|
51 | // Minimal and Maximal Coordinates
|
---|
52 | // -------------------------------
|
---|
53 | _minPointLat = 0.0;
|
---|
54 | _maxPointLat = 0.0;
|
---|
55 | _minPointLon = 0.0;
|
---|
56 | _maxPointLon = 0.0;
|
---|
57 |
|
---|
58 | // Important
|
---|
59 | // ---------
|
---|
60 | this->replot();
|
---|
61 | }
|
---|
62 |
|
---|
63 | // Destructor
|
---|
64 | /////////////////////////////////////////////////////////////////////////////
|
---|
65 | t_worldPlot::~t_worldPlot() {
|
---|
66 | }
|
---|
67 |
|
---|
68 | //
|
---|
69 | /////////////////////////////////////////////////////////////////////////////
|
---|
70 | void t_worldPlot::slotNewPoint(const QString& name, double latDeg, double lonDeg) {
|
---|
71 |
|
---|
72 | if (lonDeg > 180.0) lonDeg -= 360.0;
|
---|
73 |
|
---|
74 | QColor red(220,20,60);
|
---|
75 | QwtSymbol* symbol = new QwtSymbol(QwtSymbol::Rect, QBrush(red),
|
---|
76 | QPen(red), QSize(2,2));
|
---|
77 | QwtPlotMarker* marker = new QwtPlotMarker();
|
---|
78 | marker->setValue(lonDeg, latDeg);
|
---|
79 | if (lonDeg > 170.0) {
|
---|
80 | marker->setLabelAlignment(Qt::AlignLeft);
|
---|
81 | }
|
---|
82 | else {
|
---|
83 | marker->setLabelAlignment(Qt::AlignRight);
|
---|
84 | }
|
---|
85 | QwtText text(name.left(4));
|
---|
86 | QFont font = text.font();
|
---|
87 | font.setPointSize(font.pointSize()*0.8);
|
---|
88 | text.setFont(font);
|
---|
89 | marker->setLabel(text);
|
---|
90 | marker->setSymbol(symbol);
|
---|
91 | marker->attach(this);
|
---|
92 |
|
---|
93 | // Remeber minimal and maximal coordinates
|
---|
94 | // ---------------------------------------
|
---|
95 | if (_minPointLat == 0.0 && _maxPointLat == 0.0 &&
|
---|
96 | _minPointLon == 0.0 && _maxPointLon == 0.0) {
|
---|
97 | _minPointLat = latDeg;
|
---|
98 | _maxPointLat = latDeg;
|
---|
99 | _minPointLon = lonDeg;
|
---|
100 | _maxPointLon = lonDeg;
|
---|
101 | }
|
---|
102 | else {
|
---|
103 | if (_maxPointLat < latDeg) {
|
---|
104 | _maxPointLat = latDeg;
|
---|
105 | }
|
---|
106 | else if (_minPointLat > latDeg) {
|
---|
107 | _minPointLat = latDeg;
|
---|
108 | }
|
---|
109 | if (_maxPointLon < lonDeg) {
|
---|
110 | _maxPointLon = lonDeg;
|
---|
111 | }
|
---|
112 | else if (_minPointLon > lonDeg) {
|
---|
113 | _minPointLon = lonDeg;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | ////
|
---|
119 | //////////////////////////////////////////////////////////////////////////////
|
---|
120 | //void t_worldPlot::showEvent(QShowEvent* event) {
|
---|
121 | // double width = _maxPointLon - _minPointLon;
|
---|
122 | // double height = _maxPointLat - _minPointLat;
|
---|
123 | // if (width > 0 && height > 0) {
|
---|
124 | //
|
---|
125 | // // Extend plot area by 10 percent
|
---|
126 | // // ------------------------------
|
---|
127 | // double eps = 0.1;
|
---|
128 | // double epsLon = eps * (_maxPointLon - _minPointLon);
|
---|
129 | // double epsLat = eps * (_maxPointLat - _minPointLat);
|
---|
130 | // double widthExt = width + 2 * epsLon;
|
---|
131 | // double heightExt = height + 2 * epsLat;
|
---|
132 | // double minLon = _minPointLon - epsLon;
|
---|
133 | // double minLat = _minPointLat - epsLat;
|
---|
134 | //
|
---|
135 | // // Keep lat/lon relations
|
---|
136 | // // ----------------------
|
---|
137 | // double widthBorder = widthExt;
|
---|
138 | // double heightBorder = heightExt;
|
---|
139 | // double scale = widthExt/heightExt/2.;
|
---|
140 | // if ( scale < 1.) {
|
---|
141 | // widthBorder = widthExt / scale;
|
---|
142 | // minLon = minLon - (widthBorder - widthExt)/2.;
|
---|
143 | // }
|
---|
144 | // else {
|
---|
145 | // heightBorder = heightExt * scale;
|
---|
146 | // minLat = minLat - (heightBorder - heightExt)/2.;
|
---|
147 | // }
|
---|
148 | //
|
---|
149 | // // Borders shall not exceed min or max values
|
---|
150 | // // ------------------------------------------
|
---|
151 | // if (minLon < -180.) minLon = -180.;
|
---|
152 | // if (minLat < -90.) minLat = -90.;
|
---|
153 | // double maxLat = minLat + heightBorder;
|
---|
154 | // if ( maxLat > 90) minLat = minLat - (maxLat - 90.);
|
---|
155 | // double maxLon = minLon + widthBorder;
|
---|
156 | // if ( maxLon > 180) minLon = minLon - (maxLon - 180.);
|
---|
157 | //
|
---|
158 | // // Area large enough to justify world map
|
---|
159 | // // --------------------------------------
|
---|
160 | // if (widthBorder < 270.0 && heightBorder < 135.0) {
|
---|
161 | // QRectF rect(minLon, minLat, widthBorder, heightBorder);
|
---|
162 | // _zoomer->zoom(rect);
|
---|
163 | // }
|
---|
164 | // }
|
---|
165 | //}
|
---|
166 |
|
---|
167 | // Print the widget
|
---|
168 | ////////////////////////////////////////////////////////////////////////////
|
---|
169 | void t_worldPlot::slotPrint() {
|
---|
170 |
|
---|
171 | QPrinter printer;
|
---|
172 | QPrintDialog* dialog = new QPrintDialog(&printer, this);
|
---|
173 | dialog->setWindowTitle(tr("Print Map"));
|
---|
174 | if (dialog->exec() != QDialog::Accepted) {
|
---|
175 | return;
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | QwtPlotRenderer renderer;
|
---|
179 | renderer.setDiscardFlag(QwtPlotRenderer::DiscardBackground, false);
|
---|
180 | renderer.setLayoutFlag(QwtPlotRenderer::KeepFrames, true);
|
---|
181 | renderer.renderTo(this, printer);
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|