source: fact/Evidence/GUI.h@ 11552

Last change on this file since 11552 was 11360, checked in by ogrimm, 13 years ago
Updates to make Edd more responsive with high incoming event rate
  • Property svn:keywords set to Revision
File size: 6.2 KB
Line 
1#ifndef GUI_H_SEEN
2#define GUI_H_SEEN
3
4#include <QtGui>
5#include <QtConcurrentRun>
6
7#include <qwt_plot.h>
8#include <qwt_plot_curve.h>
9#include <qwt_plot_grid.h>
10#include <qwt_plot_zoomer.h>
11#include <qwt_plot_magnifier.h>
12#include <qwt_plot_panner.h>
13#include <qwt_scale_engine.h>
14#include <qwt_analog_clock.h>
15#include <qwt_scale_widget.h>
16#include <qwt_plot_layout.h>
17#include <qwt_legend.h>
18#include <qwt_legend_item.h>
19#include <qwt_symbol.h>
20#include <qwt_plot_marker.h>
21#include <qwt_data.h>
22#include <qwt_color_map.h>
23
24#include <limits>
25#include <float.h>
26#include <limits>
27
28#include "dic.hxx"
29#include "Evidence.h"
30
31const QColor EddPlotBackgroundColor(Qt::yellow);
32
33void OpenHistory(char *, int);
34bool SetStatus(QWidget *, QString, int, QString, int = -1);
35
36// General Edd Widget: has Update() method called by DIM interface
37class EddWidget {
38
39 public:
40 virtual void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int=-1) = 0;
41};
42
43// Base class for Edd plot
44// DeleteCurve() is pure virtual and needs to be implemented iin the application class
45class EddBasePlot: public QwtPlot {
46 Q_OBJECT
47
48 protected:
49 QMenu *Menu;
50 QAction *StripAction;
51
52 private:
53 struct PlotItem {
54 QwtPlotCurve *Signal;
55 QVector<double> x;
56 QVector<double> y;
57 double Smallest;
58 double Largest;
59 double Mean;
60 double Sigma;
61 };
62 QList<struct PlotItem> Items;
63
64 QAction *YLogAction;
65 QAction *NormAction;
66 QAction *StyleAction;
67 QAction *StatisticsAction;
68
69 QwtPlotPanner *Panner;
70 QwtPlotGrid *Grid;
71 QwtPlotZoomer *Zoomer;
72 QwtPlotMagnifier *Magnifier;
73 QwtPicker *Picker;
74 QwtDoubleRect BBox;
75 QwtPlotMarker *Stats;
76
77 public:
78 EddBasePlot(QWidget * = NULL);
79 ~EddBasePlot();
80
81 QTimer *Timer;
82 bool NewData;
83 QwtPlotCurve *NewCurve(QwtText);
84 void ClearCurve(unsigned int);
85 void AddPoint(unsigned int, double, double);
86 virtual void DeleteCurve(QwtPlotCurve *) = 0;
87
88 protected slots:
89 void UpdatePlot();
90
91 private slots:
92 void ReDoStats();
93 void HandleZoom(const QwtDoubleRect &);
94 void MouseSelection(const QwtPolygon &);
95 void contextMenuEvent(QContextMenuEvent *);
96 void MenuSingleTrace();
97 void MenuSetUpdateRate();
98 void MenuZoomOut();
99 void MenuSaveASCII();
100 void MenuSave();
101 void MenuPrint();
102 void MenuPlotHelp();
103};
104
105// General indicator for DIM service
106class EddLineDisplay: public QLineEdit, public EddWidget {
107 Q_OBJECT
108
109 QMenu *Menu;
110 QPoint dragStart;
111 QWidget *LastHist;
112
113 QString ServiceName;
114 int Index;
115
116 void mousePressEvent(QMouseEvent *);
117 void mouseReleaseEvent(QMouseEvent *);
118 void mouseMoveEvent(QMouseEvent *);
119
120 public:
121 EddLineDisplay(QString, int=-1, QWidget * = NULL);
122 ~EddLineDisplay();
123 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
124
125 bool ShowAsTime;
126
127 private slots:
128 void contextMenuEvent(QContextMenuEvent *);
129 void MenuOpenHistory();
130 void MenuCopyService();
131 void MenuCopyData();
132};
133
134// Sending command to DIM server
135class EddCommand: public QLineEdit {
136 Q_OBJECT
137
138 QString Name;
139
140 QString GetFormat();
141
142 public:
143 EddCommand(QString, QWidget * = NULL);
144
145 private slots:
146 void SendCommand();
147 void contextMenuEvent(QContextMenuEvent *);
148 void MenuCommandHelp();
149};
150
151// Graph class for history display
152class EddPlot: public EddBasePlot, public EddWidget {
153 Q_OBJECT
154
155 // Time scale for axis
156 class EddTimeScale: public QwtScaleDraw {
157
158 public:
159 EddTimeScale() {}
160
161 virtual QwtText label(double v) const {
162 // Adapt text format to time span
163 QString Format;
164 if (scaleDiv().range() < 60*60) Format = "hh' h\n'mm:ss";
165 else if (scaleDiv().range() < 24*60*60) Format = "hh:mm";
166 else if (scaleDiv().range() < 30*24*60*60) Format = "h' h\n'd-MMM";
167 else Format = "d-MMM'\n'yyyy";
168
169 // Generate text
170 QwtText Text = QDateTime::fromTime_t((int) v).toString(Format);
171 QFont Font = Text.font();
172 Font.setPointSize(7);
173 Text.setFont(Font);
174
175 return Text;
176 }
177 };
178
179 struct ItemDetails {
180 QString Name;
181 int Index;
182 QwtPlotCurve *Signal;
183 };
184 QList<struct ItemDetails> List;
185
186 private:
187 QwtLegend *Legend;
188 QTimer *SingleShot;
189
190 void dragEnterEvent(QDragEnterEvent *);
191 void dropEvent(QDropEvent *);
192 void paintEvent(QPaintEvent *);
193
194 public:
195 EddPlot(QString = QString(), int = 0, QWidget * = NULL);
196 ~EddPlot();
197 void AddService(QString, int = 0);
198 void DeleteCurve(QwtPlotCurve *);
199 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
200
201 private slots:
202 void LegendClicked(QwtPlotItem *);
203 void MenuPasteService();
204 void MenuShowLastHour();
205 void MenuShowLastDay();
206};
207
208
209// Text history and output class
210class EddText: public QTextEdit, public EddWidget {
211 Q_OBJECT
212
213 private:
214 QString Name;
215 bool Pure;
216
217 public:
218 EddText(QString, bool = false, QWidget * = NULL);
219 ~EddText();
220 void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1);
221
222 bool Accumulate;
223};
224
225
226// Interface to DIM system
227class EddDim: public QObject, public DimInfo {
228 Q_OBJECT
229
230 private:
231 struct Item {
232 DimStampedInfo *DIMService;
233 QMap<class EddWidget *, int> Subscribers;
234 int TimeStamp;
235 QByteArray ByteArray;
236 QString Format;
237 QString Text;
238 QStringList Items;
239 };
240 QMap<QString, struct Item> ServiceList;
241 QMap<QString, bool> IgnoreMap;
242 QMutex *Mutex, IgnoreMutex;
243
244 struct HistItem {
245 int Count;
246 int LastUpdate;
247 class EvidenceHistory *HistClass;
248 };
249 QMap<QString, struct HistItem> HistoryList;
250
251 unsigned int Period;
252 long long Volume;
253
254 void infoHandler();
255
256 private slots:
257 void Update(QString, int, QByteArray, QString);
258 void UpdateStatistics();
259
260 public:
261 EddDim();
262 ~EddDim();
263
264 void Subscribe(QString, class EddWidget *, int = -1);
265 void Unsubscribe (QString, class EddWidget *);
266 void Ignore (QString, bool);
267 class EvidenceHistory *GetHistory(QString);
268 void DropHistory(QString);
269
270 signals:
271 void INT(QString, int, QByteArray = QByteArray(), QString = QString());
272};
273
274// Open new window
275class EddWindow: public QPushButton {
276 Q_OBJECT
277
278 QMainWindow *M;
279 QGridLayout *L;
280
281 public:
282 EddWindow(QString, QString);
283 QGridLayout *Layout();
284 QMainWindow *Window();
285};
286
287#endif
Note: See TracBrowser for help on using the repository browser.