| 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_picker_machine.h> | 
|---|
| 14 | #include <qwt_scale_engine.h> | 
|---|
| 15 | #include <qwt_analog_clock.h> | 
|---|
| 16 | #include <qwt_scale_widget.h> | 
|---|
| 17 | #include <qwt_plot_layout.h> | 
|---|
| 18 | #include <qwt_legend.h> | 
|---|
| 19 | #include <qwt_legend_label.h> | 
|---|
| 20 | #include <qwt_symbol.h> | 
|---|
| 21 | #include <qwt_plot_marker.h> | 
|---|
| 22 | #include <qwt_color_map.h> | 
|---|
| 23 | #include <qwt_date_scale_draw.h> | 
|---|
| 24 |  | 
|---|
| 25 | #include <limits> | 
|---|
| 26 | #include <float.h> | 
|---|
| 27 | #include <limits> | 
|---|
| 28 |  | 
|---|
| 29 | #include "dic.hxx" | 
|---|
| 30 | #include "Evidence.h" | 
|---|
| 31 |  | 
|---|
| 32 | const QColor EddPlotBackgroundColor(Qt::yellow); | 
|---|
| 33 |  | 
|---|
| 34 | void OpenHistory(char *, int, int=-1); | 
|---|
| 35 | bool SetStatus(QWidget *, QString, int, QString, int = -1); | 
|---|
| 36 |  | 
|---|
| 37 | // General Edd Widget: has Update() method called by DIM interface | 
|---|
| 38 | class EddWidget { | 
|---|
| 39 |  | 
|---|
| 40 | public: | 
|---|
| 41 | virtual void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int=-1) = 0; | 
|---|
| 42 | }; | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | // Base class for Edd plot | 
|---|
| 46 | // RemoveService() is pure virtual and needs to be implemented in the application class, | 
|---|
| 47 | // it will be called through signal by context menu of legend entries | 
|---|
| 48 | class EddBasePlot: public QwtPlot { | 
|---|
| 49 | Q_OBJECT | 
|---|
| 50 |  | 
|---|
| 51 | protected: | 
|---|
| 52 | QMenu *Menu; | 
|---|
| 53 | QAction *StripAction; | 
|---|
| 54 |  | 
|---|
| 55 | private: | 
|---|
| 56 | struct PlotItem { | 
|---|
| 57 | QwtPlotCurve *Signal; | 
|---|
| 58 | QVector<double> x; | 
|---|
| 59 | QVector<double> y; | 
|---|
| 60 | double Smallest; | 
|---|
| 61 | double Largest; | 
|---|
| 62 | double Mean; | 
|---|
| 63 | double Sigma; | 
|---|
| 64 | }; | 
|---|
| 65 | QList<struct PlotItem> Items; | 
|---|
| 66 |  | 
|---|
| 67 | QAction *YLogAction; | 
|---|
| 68 | QAction *NormAction; | 
|---|
| 69 | QAction *StyleAction; | 
|---|
| 70 | QAction *StatisticsAction; | 
|---|
| 71 |  | 
|---|
| 72 | QwtPlotPanner *Panner; | 
|---|
| 73 | QwtPlotGrid *Grid; | 
|---|
| 74 | QwtPlotZoomer *Zoomer; | 
|---|
| 75 | QwtPlotMagnifier *Magnifier; | 
|---|
| 76 | QwtPicker *Picker; | 
|---|
| 77 | QRectF BBox; | 
|---|
| 78 | QwtPlotMarker *Stats; | 
|---|
| 79 | class EddLegend *Legend; | 
|---|
| 80 | bool MouseMoved; | 
|---|
| 81 |  | 
|---|
| 82 | public: | 
|---|
| 83 | EddBasePlot(QWidget * = NULL); | 
|---|
| 84 | ~EddBasePlot(); | 
|---|
| 85 |  | 
|---|
| 86 | QTimer *Timer; | 
|---|
| 87 | bool NewData; | 
|---|
| 88 | QwtPlotCurve *NewCurve(QwtText); | 
|---|
| 89 | virtual void RemoveService(QwtPlotCurve *) = 0; | 
|---|
| 90 | void DeleteCurve(QwtPlotCurve *); | 
|---|
| 91 | void ClearCurve(unsigned int); | 
|---|
| 92 | void AddPoint(unsigned int, double, double); | 
|---|
| 93 |  | 
|---|
| 94 | protected slots: | 
|---|
| 95 | void UpdatePlot(); | 
|---|
| 96 |  | 
|---|
| 97 | private slots: | 
|---|
| 98 | void ReDoStats(); | 
|---|
| 99 | void HandleZoom(const QRectF &); | 
|---|
| 100 | void MouseSelection(const QPolygon &); | 
|---|
| 101 | void mousePressEvent(QMouseEvent *); | 
|---|
| 102 | void mouseReleaseEvent(QMouseEvent *); | 
|---|
| 103 | void mouseMoveEvent(QMouseEvent *); | 
|---|
| 104 | void contextMenuEvent(QContextMenuEvent *); | 
|---|
| 105 | void MenuSetUpdateRate(); | 
|---|
| 106 | void MenuZoomOut(); | 
|---|
| 107 | void MenuSaveASCII(); | 
|---|
| 108 | void MenuSave(); | 
|---|
| 109 | void MenuPrint(); | 
|---|
| 110 | void MenuPlotHelp(); | 
|---|
| 111 | }; | 
|---|
| 112 |  | 
|---|
| 113 | // General indicator for DIM service | 
|---|
| 114 | class EddLineDisplay: public QLineEdit, public EddWidget { | 
|---|
| 115 | Q_OBJECT | 
|---|
| 116 |  | 
|---|
| 117 | QMenu *Menu; | 
|---|
| 118 | QPoint dragStart; | 
|---|
| 119 | QWidget *LastHist; | 
|---|
| 120 |  | 
|---|
| 121 | QString ServiceName; | 
|---|
| 122 | int Index; | 
|---|
| 123 |  | 
|---|
| 124 | void mousePressEvent(QMouseEvent *); | 
|---|
| 125 | void mouseReleaseEvent(QMouseEvent *); | 
|---|
| 126 | void mouseMoveEvent(QMouseEvent *); | 
|---|
| 127 |  | 
|---|
| 128 | public: | 
|---|
| 129 | EddLineDisplay(QString, int=-1, QWidget * = NULL); | 
|---|
| 130 | ~EddLineDisplay(); | 
|---|
| 131 | void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1); | 
|---|
| 132 |  | 
|---|
| 133 | bool ShowAsTime; | 
|---|
| 134 |  | 
|---|
| 135 | private slots: | 
|---|
| 136 | void contextMenuEvent(QContextMenuEvent *); | 
|---|
| 137 | void MenuOpenHistory(); | 
|---|
| 138 | void MenuCopyService(); | 
|---|
| 139 | void MenuCopyData(); | 
|---|
| 140 | }; | 
|---|
| 141 |  | 
|---|
| 142 | // Sending command to DIM server | 
|---|
| 143 | class EddCommand: public QLineEdit { | 
|---|
| 144 | Q_OBJECT | 
|---|
| 145 |  | 
|---|
| 146 | QString Name; | 
|---|
| 147 |  | 
|---|
| 148 | QString GetFormat(); | 
|---|
| 149 |  | 
|---|
| 150 | public: | 
|---|
| 151 | EddCommand(QString, QWidget * = NULL); | 
|---|
| 152 |  | 
|---|
| 153 | private slots: | 
|---|
| 154 | void SendCommand(); | 
|---|
| 155 | void contextMenuEvent(QContextMenuEvent *); | 
|---|
| 156 | void MenuCommandHelp(); | 
|---|
| 157 | }; | 
|---|
| 158 |  | 
|---|
| 159 | // Graph class for history display | 
|---|
| 160 | class EddPlot: public EddBasePlot, public EddWidget { | 
|---|
| 161 | Q_OBJECT | 
|---|
| 162 |  | 
|---|
| 163 | struct ItemDetails { | 
|---|
| 164 | QString Name; | 
|---|
| 165 | int Index; | 
|---|
| 166 | QwtPlotCurve *Curve; | 
|---|
| 167 | }; | 
|---|
| 168 | QList<struct ItemDetails> List; | 
|---|
| 169 |  | 
|---|
| 170 | private: | 
|---|
| 171 | QwtLegend *Legend; | 
|---|
| 172 | QTimer *SingleShot; | 
|---|
| 173 | QPoint dragStart; | 
|---|
| 174 |  | 
|---|
| 175 | void dragEnterEvent(QDragEnterEvent *); | 
|---|
| 176 | void dropEvent(QDropEvent *); | 
|---|
| 177 |  | 
|---|
| 178 | public: | 
|---|
| 179 | EddPlot(QString = QString(), int = 0, QWidget * = NULL); | 
|---|
| 180 | ~EddPlot(); | 
|---|
| 181 | void AddService(QString, int = 0); | 
|---|
| 182 | void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1); | 
|---|
| 183 |  | 
|---|
| 184 | public slots: | 
|---|
| 185 | void RemoveService(QwtPlotCurve *); | 
|---|
| 186 | void borderPath(QRect) {}; //Dummy method for qwtPicker, prevents QMetaObject::invokeMethod: No such method EddPlot::borderPath(QRect) | 
|---|
| 187 |  | 
|---|
| 188 | private slots: | 
|---|
| 189 | void MenuPasteService(); | 
|---|
| 190 | void MenuShowLastHour(); | 
|---|
| 191 | void MenuShowLastDay(); | 
|---|
| 192 | void MenuAllAsText(); | 
|---|
| 193 | }; | 
|---|
| 194 |  | 
|---|
| 195 | // Scale showing date and time | 
|---|
| 196 | class EddDateScale: public QwtDateScaleDraw { | 
|---|
| 197 |  | 
|---|
| 198 | public: | 
|---|
| 199 | QwtText label(double) const; | 
|---|
| 200 | }; | 
|---|
| 201 |  | 
|---|
| 202 | // Legend and legend label with protected methods implemented | 
|---|
| 203 | class EddLegend: public QwtLegend { | 
|---|
| 204 |  | 
|---|
| 205 | protected: | 
|---|
| 206 | QWidget *createWidget(const QwtLegendData &) const; | 
|---|
| 207 | }; | 
|---|
| 208 |  | 
|---|
| 209 | class EddLegendLabel: public QwtLegendLabel { | 
|---|
| 210 | Q_OBJECT | 
|---|
| 211 |  | 
|---|
| 212 | QMenu *Menu; | 
|---|
| 213 | QPoint dragStart; | 
|---|
| 214 |  | 
|---|
| 215 | public: | 
|---|
| 216 | EddLegendLabel(); | 
|---|
| 217 |  | 
|---|
| 218 | void contextMenuEvent(QContextMenuEvent *); | 
|---|
| 219 | void mousePressEvent(QMouseEvent *); | 
|---|
| 220 | void mouseReleaseEvent(QMouseEvent *); | 
|---|
| 221 | void mouseMoveEvent(QMouseEvent *); | 
|---|
| 222 |  | 
|---|
| 223 | QwtPlotCurve *Curve; | 
|---|
| 224 | QAction *ThickLineAction; | 
|---|
| 225 |  | 
|---|
| 226 | private slots: | 
|---|
| 227 | void MenuOpenHistory(); | 
|---|
| 228 | void MenuCopyService(); | 
|---|
| 229 | void MenuThickLine(bool); | 
|---|
| 230 | void MenuRemove(); | 
|---|
| 231 |  | 
|---|
| 232 | signals: | 
|---|
| 233 | void DeleteCurve(QwtPlotCurve *); | 
|---|
| 234 | }; | 
|---|
| 235 |  | 
|---|
| 236 | // Text history and output class | 
|---|
| 237 | class EddText: public QTextEdit, public EddWidget { | 
|---|
| 238 | Q_OBJECT | 
|---|
| 239 |  | 
|---|
| 240 | private: | 
|---|
| 241 | QString Name; | 
|---|
| 242 | bool Pure; | 
|---|
| 243 |  | 
|---|
| 244 | public: | 
|---|
| 245 | EddText(QString, bool = false, QWidget * = NULL); | 
|---|
| 246 | ~EddText(); | 
|---|
| 247 | void Update(const QString &, int, const QByteArray &, const QString &, const QString &, int = -1); | 
|---|
| 248 |  | 
|---|
| 249 | bool Accumulate; | 
|---|
| 250 | }; | 
|---|
| 251 |  | 
|---|
| 252 |  | 
|---|
| 253 | // Interface to DIM system | 
|---|
| 254 | class EddDim: public QObject, public DimInfo { | 
|---|
| 255 | Q_OBJECT | 
|---|
| 256 |  | 
|---|
| 257 | public: | 
|---|
| 258 | struct HistItem { | 
|---|
| 259 | int Time; | 
|---|
| 260 | QVector<QPair<int, QByteArray> > DataRaw; | 
|---|
| 261 | QVector<QPair<int, QStringList> > DataText; | 
|---|
| 262 | QString Format; | 
|---|
| 263 | }; | 
|---|
| 264 |  | 
|---|
| 265 | private: | 
|---|
| 266 | struct Item { | 
|---|
| 267 | DimStampedInfo *DIMService; | 
|---|
| 268 | QList<QPair<class EddWidget *, int> > Subscribers; | 
|---|
| 269 | int TimeStamp; | 
|---|
| 270 | QByteArray ByteArray; | 
|---|
| 271 | QString Format; | 
|---|
| 272 | QString Text; | 
|---|
| 273 | QStringList Items; | 
|---|
| 274 | }; | 
|---|
| 275 |  | 
|---|
| 276 | QMap<QString, struct Item> ServiceList; | 
|---|
| 277 | QMap<QString, bool> IgnoreMap; | 
|---|
| 278 | QMutex *Mutex, IgnoreMutex; | 
|---|
| 279 | QMap<QString, struct HistItem> HistoryList; | 
|---|
| 280 |  | 
|---|
| 281 | unsigned int Period; | 
|---|
| 282 | long long Volume; | 
|---|
| 283 |  | 
|---|
| 284 | void infoHandler(); | 
|---|
| 285 |  | 
|---|
| 286 | private slots: | 
|---|
| 287 | void Update(QString, int, QByteArray, QString); | 
|---|
| 288 | void UpdateStatistics(); | 
|---|
| 289 |  | 
|---|
| 290 | public: | 
|---|
| 291 | EddDim(); | 
|---|
| 292 | ~EddDim(); | 
|---|
| 293 |  | 
|---|
| 294 | void Subscribe(QString, class EddWidget *, int = -1); | 
|---|
| 295 | void Unsubscribe (QString, class EddWidget *, int = -1); | 
|---|
| 296 | void Ignore (QString, bool); | 
|---|
| 297 | struct HistItem GetHistory(QString); | 
|---|
| 298 |  | 
|---|
| 299 | signals: | 
|---|
| 300 | void INT(QString, int, QByteArray = QByteArray(), QString = QString()); | 
|---|
| 301 | }; | 
|---|
| 302 |  | 
|---|
| 303 | // Open new window | 
|---|
| 304 | class EddWindow: public QPushButton { | 
|---|
| 305 | Q_OBJECT | 
|---|
| 306 |  | 
|---|
| 307 | QMainWindow *M; | 
|---|
| 308 | QGridLayout *L; | 
|---|
| 309 |  | 
|---|
| 310 | public: | 
|---|
| 311 | EddWindow(QString, QString); | 
|---|
| 312 | QGridLayout *Layout(); | 
|---|
| 313 | QMainWindow *Window(); | 
|---|
| 314 | }; | 
|---|
| 315 |  | 
|---|
| 316 | #endif | 
|---|