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