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

Last change on this file since 5456 was 5456, checked in by mervart, 11 years ago
File size: 4.6 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
[5452]71 // Host and Port
72 // -------------
[5453]73 t_settings settings(pluginName);
[5452]74
[5410]75 // Thrift Client;
[5415]76 // --------------
[5422]77 _thriftClient = 0;
[5427]78 _results = 0;
[4836]79}
80
81// Destructor
82/////////////////////////////////////////////////////////////////////////////
[5445]83t_monitor::~t_monitor() {
[5431]84 slotStopThrift();
[5428]85 if (_results) {
86 while (!_results->empty()) {
87 delete _results->back();
88 _results->pop_back();
89 }
90 delete _results;
91 }
[4836]92}
93
[5422]94//
95/////////////////////////////////////////////////////////////////////////////
[5455]96void t_monitor::slotConfig() {
97 t_dlgConf dlg(this);
98 dlg.exec();
99}
100
101//
102/////////////////////////////////////////////////////////////////////////////
[5445]103void t_monitor::slotStartThrift() {
[5422]104 if (!_thriftClient) {
[5453]105 t_settings settings(pluginName);
[5452]106 QString host = settings.value("host").toString();
107 int port = settings.value("port").toInt();
108 _thriftClient = new t_thriftClient(this, host, port);
[5431]109 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
[5422]110 _thriftClient->start();
[5429]111 slotPlotResults();
[5422]112 }
113}
[4836]114
[5415]115//
116/////////////////////////////////////////////////////////////////////////////
[5445]117void t_monitor::slotStopThrift() {
[5431]118 if (_thriftClient) {
119 _thriftClient->stop();
[5430]120 _thriftClient = 0;
121 }
122}
123
124//
125/////////////////////////////////////////////////////////////////////////////
[5445]126void t_monitor::slotThriftFinished() {
[5431]127 sender()->deleteLater();
128 _thriftClient = 0;
129}
130
131//
132/////////////////////////////////////////////////////////////////////////////
[5445]133void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
[5429]134 QMutexLocker locker(&_mutex);
[5427]135 if (_results) {
136 while (!_results->empty()) {
137 delete _results->back();
138 _results->pop_back();
139 }
140 delete _results;
141 }
142 _results = results;
[5429]143}
144
145//
146/////////////////////////////////////////////////////////////////////////////
[5445]147void t_monitor::slotPlotResults() {
[5429]148 QMutexLocker locker(&_mutex);
[5436]149
[5429]150 if (_results) {
[5436]151 QList<t_worldPlot::t_point*> points;
[5429]152 for (unsigned ii = 0; ii < _results->size(); ii++) {
153 const t_thriftResult* result = _results->at(ii);
[5438]154
155 double xyz[3];
156 xyz[0] = result->_x;
157 xyz[1] = result->_y;
158 xyz[2] = result->_z;
159
160 double ell[3];
161
[5450]162 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
[5438]163 double latDeg = ell[0] * 180.0 / M_PI;
164 double lonDeg = ell[1] * 180.0 / M_PI;
[5440]165 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
166 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
[5438]167 points.append(point);
168 }
[5429]169 }
[5436]170 _plot->slotNewPoints(points);
[5439]171
172 QListIterator<t_worldPlot::t_point*> it(points);
173 while (it.hasNext()) {
174 delete it.next();
175 }
[5427]176 }
[5436]177
[5430]178 if (_thriftClient) {
179 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
180 }
[5415]181}
Note: See TracBrowser for help on using the repository browser.