source: ntrip/trunk/GnssCenter/monitor/monitor.cpp@ 5477

Last change on this file since 5477 was 5477, checked in by mervart, 13 years ago
File size: 5.7 KB
RevLine 
[4836]1
2/* -------------------------------------------------------------------------
[5445]3 * RTNet Monitor
[4836]4 * -------------------------------------------------------------------------
5 *
[5445]6 * Class: t_monitor
[4836]7 *
[5445]8 * Purpose: Real-Time Monitoring of RTNet
[4836]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
[5445]30#include "monitor.h"
[5455]31#include "dlgconf.h"
[5438]32#include "utils.h"
[5420]33#include "worldplot.h"
[5416]34#include "thriftclient.h"
[5452]35#include "settings.h"
[4836]36
[4858]37using namespace std;
[5001]38using namespace GnssCenter;
[4858]39
[5447]40Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
[5018]41
[4836]42// Constructor
43/////////////////////////////////////////////////////////////////////////////
[5445]44t_monitor::t_monitor() : QMainWindow() {
[4836]45
[5449]46 _tabWidget = new QTabWidget();
47 setCentralWidget(_tabWidget);
48
[5420]49 // World Plot
50 // ----------
51 _plot = new t_worldPlot();
[5449]52 _tabWidget->addTab(_plot, "Stations");
[4836]53
[5422]54 // Tool Bar
55 // --------
[5445]56 QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
[5422]57 addToolBar(Qt::BottomToolBarArea, toolBar);
[5430]58
[5455]59 _actConfig = new QAction("Config", 0);
60 toolBar->addAction(_actConfig);
61 connect(_actConfig, SIGNAL(triggered()), this, SLOT(slotConfig()));
[5422]62
[5455]63 _actStartThrift = new QAction("Start", 0);
64 toolBar->addAction(_actStartThrift);
65 connect(_actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
[5430]66
[5455]67 _actStopThrift = new QAction("Stop", 0);
68 toolBar->addAction(_actStopThrift);
69 connect(_actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
70
[5410]71 // Thrift Client;
[5415]72 // --------------
[5422]73 _thriftClient = 0;
[5427]74 _results = 0;
[5474]75
76 // Read Settings, Set Title, Enable/Disable Actions
77 // ------------------------------------------------
78 readSettings();
79 setTitle();
80 enableActions();
[4836]81}
82
83// Destructor
84/////////////////////////////////////////////////////////////////////////////
[5445]85t_monitor::~t_monitor() {
[5431]86 slotStopThrift();
[5428]87 if (_results) {
88 while (!_results->empty()) {
89 delete _results->back();
90 _results->pop_back();
91 }
92 delete _results;
93 }
[4836]94}
95
[5474]96// Read Settings
97/////////////////////////////////////////////////////////////////////////////
98void t_monitor::readSettings() {
99 t_settings settings(pluginName);
100 _host = settings.value("host").toString();
101 if (_host.isEmpty()) {
102 _host = "localhost";
103 }
104 _port = settings.value("port").toString();
105}
106
[5457]107// Set title
108/////////////////////////////////////////////////////////////////////////////
109void t_monitor::setTitle() {
[5474]110 if (_port.isEmpty()) {
[5470]111 setWindowTitle(QString(pluginName));
112 }
113 else {
[5474]114 setWindowTitle(QString(pluginName) + " " + _host + ':' + _port);
[5470]115 }
[5457]116}
117
[5474]118// Enable/Disable Actions
119/////////////////////////////////////////////////////////////////////////////
120void t_monitor::enableActions() {
[5475]121 if (_port.isEmpty()) {
122 _actConfig->setEnabled(true);
123 _actStartThrift->setEnabled(false);
124 _actStopThrift->setEnabled(false);
125 }
[5476]126 else if (_thriftClient) {
[5475]127 _actConfig->setEnabled(false);
128 _actStartThrift->setEnabled(false);
129 _actStopThrift->setEnabled(true);
130 }
131 else {
132 _actConfig->setEnabled(true);
133 _actStartThrift->setEnabled(true);
134 _actStopThrift->setEnabled(false);
135 }
[5474]136}
137
[5422]138//
139/////////////////////////////////////////////////////////////////////////////
[5455]140void t_monitor::slotConfig() {
141 t_dlgConf dlg(this);
142 dlg.exec();
[5474]143 readSettings();
[5457]144 setTitle();
[5474]145 enableActions();
[5455]146}
147
148//
149/////////////////////////////////////////////////////////////////////////////
[5445]150void t_monitor::slotStartThrift() {
[5422]151 if (!_thriftClient) {
[5474]152 _thriftClient = new t_thriftClient(this, _host, _port.toInt());
[5431]153 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
[5422]154 _thriftClient->start();
[5429]155 slotPlotResults();
[5422]156 }
[5477]157 enableActions();
[5422]158}
[4836]159
[5415]160//
161/////////////////////////////////////////////////////////////////////////////
[5445]162void t_monitor::slotStopThrift() {
[5431]163 if (_thriftClient) {
164 _thriftClient->stop();
[5430]165 _thriftClient = 0;
166 }
[5477]167 enableActions();
[5430]168}
169
170//
171/////////////////////////////////////////////////////////////////////////////
[5445]172void t_monitor::slotThriftFinished() {
[5431]173 sender()->deleteLater();
174 _thriftClient = 0;
[5477]175 enableActions();
[5431]176}
177
178//
179/////////////////////////////////////////////////////////////////////////////
[5445]180void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
[5429]181 QMutexLocker locker(&_mutex);
[5427]182 if (_results) {
183 while (!_results->empty()) {
184 delete _results->back();
185 _results->pop_back();
186 }
187 delete _results;
188 }
189 _results = results;
[5429]190}
191
192//
193/////////////////////////////////////////////////////////////////////////////
[5445]194void t_monitor::slotPlotResults() {
[5429]195 QMutexLocker locker(&_mutex);
[5436]196
[5429]197 if (_results) {
[5436]198 QList<t_worldPlot::t_point*> points;
[5429]199 for (unsigned ii = 0; ii < _results->size(); ii++) {
200 const t_thriftResult* result = _results->at(ii);
[5438]201
202 double xyz[3];
203 xyz[0] = result->_x;
204 xyz[1] = result->_y;
205 xyz[2] = result->_z;
206
207 double ell[3];
208
[5450]209 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
[5438]210 double latDeg = ell[0] * 180.0 / M_PI;
211 double lonDeg = ell[1] * 180.0 / M_PI;
[5440]212 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
213 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
[5438]214 points.append(point);
215 }
[5429]216 }
[5436]217 _plot->slotNewPoints(points);
[5439]218
219 QListIterator<t_worldPlot::t_point*> it(points);
220 while (it.hasNext()) {
221 delete it.next();
222 }
[5427]223 }
[5436]224
[5430]225 if (_thriftClient) {
226 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
227 }
[5415]228}
Note: See TracBrowser for help on using the repository browser.