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 <iostream>
|
---|
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 |
|
---|
30 | #include "map_stations.h"
|
---|
31 | #include "utils.h"
|
---|
32 | #include "worldplot.h"
|
---|
33 | #include "thriftclient.h"
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 | using namespace GnssCenter;
|
---|
37 |
|
---|
38 | Q_EXPORT_PLUGIN2(gnsscenter_map_stations, GnssCenter::t_map_stationsFactory)
|
---|
39 |
|
---|
40 | // Constructor
|
---|
41 | /////////////////////////////////////////////////////////////////////////////
|
---|
42 | t_map_stations::t_map_stations() : QMainWindow() {
|
---|
43 |
|
---|
44 | // World Plot
|
---|
45 | // ----------
|
---|
46 | _plot = new t_worldPlot();
|
---|
47 | setCentralWidget(_plot);
|
---|
48 |
|
---|
49 | // Tool Bar
|
---|
50 | // --------
|
---|
51 | QToolBar* toolBar = new QToolBar("t_map_stations_ToolBar");
|
---|
52 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
53 |
|
---|
54 | QAction* actStartThrift = new QAction("Start Thrift", 0);
|
---|
55 | toolBar->addAction(actStartThrift);
|
---|
56 | connect(actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
|
---|
57 |
|
---|
58 | QAction* actStopThrift = new QAction("Stop Thrift", 0);
|
---|
59 | toolBar->addAction(actStopThrift);
|
---|
60 | connect(actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
|
---|
61 |
|
---|
62 | // Thrift Client;
|
---|
63 | // --------------
|
---|
64 | _thriftClient = 0;
|
---|
65 | _results = 0;
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Destructor
|
---|
69 | /////////////////////////////////////////////////////////////////////////////
|
---|
70 | t_map_stations::~t_map_stations() {
|
---|
71 | slotStopThrift();
|
---|
72 | if (_results) {
|
---|
73 | while (!_results->empty()) {
|
---|
74 | delete _results->back();
|
---|
75 | _results->pop_back();
|
---|
76 | }
|
---|
77 | delete _results;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | //
|
---|
82 | /////////////////////////////////////////////////////////////////////////////
|
---|
83 | void t_map_stations::slotStartThrift() {
|
---|
84 | if (!_thriftClient) {
|
---|
85 | _thriftClient = new t_thriftClient(this);
|
---|
86 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
---|
87 | _thriftClient->start();
|
---|
88 | slotPlotResults();
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | //
|
---|
93 | /////////////////////////////////////////////////////////////////////////////
|
---|
94 | void t_map_stations::slotStopThrift() {
|
---|
95 | if (_thriftClient) {
|
---|
96 | _thriftClient->stop();
|
---|
97 | _thriftClient = 0;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | //
|
---|
102 | /////////////////////////////////////////////////////////////////////////////
|
---|
103 | void t_map_stations::slotThriftFinished() {
|
---|
104 | sender()->deleteLater();
|
---|
105 | _thriftClient = 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | //
|
---|
109 | /////////////////////////////////////////////////////////////////////////////
|
---|
110 | void t_map_stations::putThriftResults(std::vector<t_thriftResult*>* results) {
|
---|
111 | QMutexLocker locker(&_mutex);
|
---|
112 | if (_results) {
|
---|
113 | while (!_results->empty()) {
|
---|
114 | delete _results->back();
|
---|
115 | _results->pop_back();
|
---|
116 | }
|
---|
117 | delete _results;
|
---|
118 | }
|
---|
119 | _results = results;
|
---|
120 | }
|
---|
121 |
|
---|
122 | //
|
---|
123 | /////////////////////////////////////////////////////////////////////////////
|
---|
124 | void t_map_stations::slotPlotResults() {
|
---|
125 | QMutexLocker locker(&_mutex);
|
---|
126 |
|
---|
127 | if (_results) {
|
---|
128 | QList<t_worldPlot::t_point*> points;
|
---|
129 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
---|
130 | const t_thriftResult* result = _results->at(ii);
|
---|
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;
|
---|
142 | t_worldPlot::t_point* point = new t_worldPlot::t_point(result->_name.c_str(),
|
---|
143 | latDeg, lonDeg);
|
---|
144 | points.append(point);
|
---|
145 | }
|
---|
146 | }
|
---|
147 | _plot->slotNewPoints(points);
|
---|
148 |
|
---|
149 | QListIterator<t_worldPlot::t_point*> it(points);
|
---|
150 | while (it.hasNext()) {
|
---|
151 | delete it.next();
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (_thriftClient) {
|
---|
156 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
---|
157 | }
|
---|
158 | }
|
---|