[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 |
|
---|
[5418] | 18 | #include <iostream>
|
---|
[4836] | 19 | #include <QtSvg>
|
---|
| 20 |
|
---|
| 21 | #include <qwt_symbol.h>
|
---|
| 22 | #include <qwt_plot.h>
|
---|
| 23 | #include <qwt_plot_svgitem.h>
|
---|
| 24 | #include <qwt_plot_curve.h>
|
---|
| 25 | #include <qwt_plot_marker.h>
|
---|
| 26 | #include <qwt_plot_canvas.h>
|
---|
| 27 | #include <qwt_plot_zoomer.h>
|
---|
| 28 | #include <qwt_plot_renderer.h>
|
---|
| 29 |
|
---|
[5406] | 30 | #include "map_stations.h"
|
---|
[5438] | 31 | #include "utils.h"
|
---|
[5420] | 32 | #include "worldplot.h"
|
---|
[5416] | 33 | #include "thriftclient.h"
|
---|
[4836] | 34 |
|
---|
[4858] | 35 | using namespace std;
|
---|
[5001] | 36 | using namespace GnssCenter;
|
---|
[4858] | 37 |
|
---|
[5406] | 38 | Q_EXPORT_PLUGIN2(gnsscenter_map_stations, GnssCenter::t_map_stationsFactory)
|
---|
[5018] | 39 |
|
---|
[4836] | 40 | // Constructor
|
---|
| 41 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5420] | 42 | t_map_stations::t_map_stations() : QMainWindow() {
|
---|
[4836] | 43 |
|
---|
[5420] | 44 | // World Plot
|
---|
| 45 | // ----------
|
---|
| 46 | _plot = new t_worldPlot();
|
---|
| 47 | setCentralWidget(_plot);
|
---|
[4836] | 48 |
|
---|
[5422] | 49 | // Tool Bar
|
---|
| 50 | // --------
|
---|
| 51 | QToolBar* toolBar = new QToolBar("t_map_stations_ToolBar");
|
---|
| 52 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
[5430] | 53 |
|
---|
[5422] | 54 | QAction* actStartThrift = new QAction("Start Thrift", 0);
|
---|
| 55 | toolBar->addAction(actStartThrift);
|
---|
| 56 | connect(actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
|
---|
| 57 |
|
---|
[5430] | 58 | QAction* actStopThrift = new QAction("Stop Thrift", 0);
|
---|
| 59 | toolBar->addAction(actStopThrift);
|
---|
| 60 | connect(actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
|
---|
| 61 |
|
---|
[5410] | 62 | // Thrift Client;
|
---|
[5415] | 63 | // --------------
|
---|
[5422] | 64 | _thriftClient = 0;
|
---|
[5427] | 65 | _results = 0;
|
---|
[4836] | 66 | }
|
---|
| 67 |
|
---|
| 68 | // Destructor
|
---|
| 69 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5422] | 70 | t_map_stations::~t_map_stations() {
|
---|
[5431] | 71 | slotStopThrift();
|
---|
[5428] | 72 | if (_results) {
|
---|
| 73 | while (!_results->empty()) {
|
---|
| 74 | delete _results->back();
|
---|
| 75 | _results->pop_back();
|
---|
| 76 | }
|
---|
| 77 | delete _results;
|
---|
| 78 | }
|
---|
[4836] | 79 | }
|
---|
| 80 |
|
---|
[5422] | 81 | //
|
---|
| 82 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 83 | void t_map_stations::slotStartThrift() {
|
---|
| 84 | if (!_thriftClient) {
|
---|
| 85 | _thriftClient = new t_thriftClient(this);
|
---|
[5431] | 86 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
---|
[5422] | 87 | _thriftClient->start();
|
---|
[5429] | 88 | slotPlotResults();
|
---|
[5422] | 89 | }
|
---|
| 90 | }
|
---|
[4836] | 91 |
|
---|
[5415] | 92 | //
|
---|
| 93 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5430] | 94 | void t_map_stations::slotStopThrift() {
|
---|
[5431] | 95 | if (_thriftClient) {
|
---|
| 96 | _thriftClient->stop();
|
---|
[5430] | 97 | _thriftClient = 0;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | //
|
---|
| 102 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5431] | 103 | void t_map_stations::slotThriftFinished() {
|
---|
| 104 | sender()->deleteLater();
|
---|
| 105 | _thriftClient = 0;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | //
|
---|
| 109 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5427] | 110 | void t_map_stations::putThriftResults(std::vector<t_thriftResult*>* results) {
|
---|
[5429] | 111 | QMutexLocker locker(&_mutex);
|
---|
[5427] | 112 | if (_results) {
|
---|
| 113 | while (!_results->empty()) {
|
---|
| 114 | delete _results->back();
|
---|
| 115 | _results->pop_back();
|
---|
| 116 | }
|
---|
| 117 | delete _results;
|
---|
| 118 | }
|
---|
| 119 | _results = results;
|
---|
[5429] | 120 | }
|
---|
| 121 |
|
---|
| 122 | //
|
---|
| 123 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 124 | void t_map_stations::slotPlotResults() {
|
---|
| 125 | QMutexLocker locker(&_mutex);
|
---|
[5436] | 126 |
|
---|
[5429] | 127 | if (_results) {
|
---|
[5436] | 128 | QList<t_worldPlot::t_point*> points;
|
---|
[5429] | 129 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
---|
| 130 | const t_thriftResult* result = _results->at(ii);
|
---|
[5438] | 131 |
|
---|
| 132 | double xyz[3];
|
---|
| 133 | xyz[0] = result->_x;
|
---|
| 134 | xyz[1] = result->_y;
|
---|
| 135 | xyz[2] = result->_z;
|
---|
| 136 |
|
---|
| 137 | double ell[3];
|
---|
| 138 |
|
---|
| 139 | if (xyz2ell(xyz, ell) == success) {
|
---|
| 140 | double latDeg = ell[0] * 180.0 / M_PI;
|
---|
| 141 | double lonDeg = ell[1] * 180.0 / M_PI;
|
---|
[5440] | 142 | QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
|
---|
| 143 | t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
|
---|
[5438] | 144 | points.append(point);
|
---|
| 145 | }
|
---|
[5429] | 146 | }
|
---|
[5436] | 147 | _plot->slotNewPoints(points);
|
---|
[5439] | 148 |
|
---|
| 149 | QListIterator<t_worldPlot::t_point*> it(points);
|
---|
| 150 | while (it.hasNext()) {
|
---|
| 151 | delete it.next();
|
---|
| 152 | }
|
---|
[5427] | 153 | }
|
---|
[5436] | 154 |
|
---|
[5430] | 155 | if (_thriftClient) {
|
---|
| 156 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
---|
| 157 | }
|
---|
[5415] | 158 | }
|
---|