source: flair-src/trunk/tools/FlairGCS/src/DataPlot1D.cpp@ 443

Last change on this file since 443 was 443, checked in by Sanahuja Guillaume, 3 years ago

update buffering (gcs part)

File size: 4.2 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5#include "DataPlot1D.h"
6#include "ConnectionLayout.h"
7#include "Layout.h"
8#include <QMouseEvent>
9#include <QMenu>
10#include <QGridLayout>
11#include <QTime>
12#include <qendian.h>
13
14DataPlot1D::DataPlot1D(Layout *parent, int row, int col, QString title,
15 float ymin, float ymax, bool enabled, uint16_t period, uint16_t nb_buffering)
16 : ScopeFixedStep(title, ymin, ymax, period / 1000.),
17 DataRemote(title, "DataPlot1D", parent, enabled, period, nb_buffering) {
18
19 setEnabled(enabled);
20 ResetElapsedTime((float)connectionLayout()->GetStartTime().msecsTo(QTime::currentTime())/1000.);
21 parent->addWidget(this, row, col);
22 visible_widget = this;
23}
24
25DataPlot1D::~DataPlot1D() {
26 visible_widget = NULL; // because otherwise xmlwidget will delete it
27}
28
29void DataPlot1D::XmlEvent(QDomElement *dom) {
30 bool previouslyEnabled=IsEnabled();
31
32 if (dom->attribute("curve") != "") {
33 QString type = dom->attribute("type");
34 int r = dom->attribute("r").toInt();
35 int g = dom->attribute("g").toInt();
36 int b = dom->attribute("b").toInt();
37 QString name = dom->attribute("curve");
38 addCurve(QPen(QColor(r, g, b, 255)), name);
39 datas_type.append(type);
40 if (type == "float") {
41 receivesize += sizeof(float);
42 } else if (type == "int8_t") {
43 receivesize += sizeof(int8_t);
44 } else if (type == "int16_t") {
45 receivesize += sizeof(int16_t);
46 } else {
47 fprintf(stderr,"MyDataPlot1D::addCurve unknown type %s\n",
48 type.toLocal8Bit().constData());
49 }
50 } else {
51 XmlSetup(dom);
52 }
53
54 if(previouslyEnabled!=IsEnabled() && IsEnabled())
55 ResetElapsedTime((float)connectionLayout()->GetStartTime().msecsTo(QTime::currentTime())/1000.);
56}
57
58bool DataPlot1D::eventFilter(QObject *o, QEvent *e) {
59 if (o == canvas()) {
60 switch (e->type()) {
61 case QEvent::Resize: {
62 // resolution bug taille widgets:
63 setMaximumHeight(parentWidget()->height() /
64 ((QGridLayout *)(parentWidget()->layout()))->rowCount());
65 break;
66 }
67 case QEvent::MouseButtonPress: {
68 return mouseEvent((QMouseEvent *)e);
69 }
70
71 default:
72 break;
73 }
74 }
75 return Scope::eventFilter(o, e);
76}
77
78void DataPlot1D::BufEvent(char **buf, int *buf_size, uint16_t period,uint16_t nb_buffering,
79 bool big_endian) {
80 setEnabled(IsEnabled());
81 if (IsEnabled() == false || RefreshRate_ms() != period) return;
82 double *datas = (double *)malloc(datas_type.count() * sizeof(double));
83
84 for (int i = 0; i < datas_type.count(); i++) {
85 if (datas_type.at(i) == "float") {
86 uint32_t data_raw;
87 float *data = (float *)&data_raw;
88 memcpy((void *)&data_raw, *buf, sizeof(uint32_t));
89 *buf += sizeof(uint32_t);
90 if (big_endian == true) data_raw = qFromBigEndian(data_raw);
91 datas[i] = *data;
92 } else if (datas_type.at(i) == "int8_t") {
93 int8_t data;
94 memcpy((void *)&data, *buf, sizeof(data));
95 *buf += sizeof(data);
96 datas[i] = data;
97 } else if (datas_type.at(i) == "int16_t") {
98 int16_t data;
99 memcpy((void *)&data, *buf, sizeof(data));
100 *buf += sizeof(data);
101 if (big_endian == true) data = qFromBigEndian(data);
102 datas[i] = data;
103 } else {
104 fprintf(stderr,"DataPlot1D::BufEvent unknown type %s\n",datas_type.at(i).toLocal8Bit().constData());
105 }
106 }
107
108 step_s = period / 1000.;
109 plot(datas);
110 free(datas);
111}
112
113// context menu
114bool DataPlot1D::mouseEvent(QMouseEvent *event) {
115 if (event->button() == Qt::RightButton) {
116 QMenu *menu = new QMenu("nom", (QwtPlot *)this);
117 QAction *resetX, *resetY, *clear,*action;
118
119 resetX = menu->addAction("reset time view");
120 resetY = menu->addAction("reset y view");
121 menu->addSeparator();
122
123 appendmenu(menu);
124
125 menu->addSeparator();
126 clear = menu->addAction("clear graph");
127
128 action = execmenu((QwtPlot *)this, menu, event->globalPos());
129 delete menu;
130
131 if (action == resetX)
132 resetXView();
133 if (action == resetY)
134 resetYView();
135
136 if (action == clear)
137 clearCurves();
138
139 return true;
140 }
141 return false;
142}
Note: See TracBrowser for help on using the repository browser.