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

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

update buffering (gcs part)
seems to work!

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,bool big_endian) {
79 setEnabled(IsEnabled());
80 if (IsEnabled() == false || RefreshRate_ms() != period || NbBuffering()!=nb_buffering) return;
81 double *datas = (double *)malloc(datas_type.count() * sizeof(double));
82
83 for (int i = 0; i < datas_type.count(); i++) {
84 if (datas_type.at(i) == "float") {
85 uint32_t data_raw;
86 float *data = (float *)&data_raw;
87 memcpy((void *)&data_raw, *buf, sizeof(uint32_t));
88 *buf += sizeof(uint32_t);
89 if (big_endian == true) data_raw = qFromBigEndian(data_raw);
90 datas[i] = *data;
91 } else if (datas_type.at(i) == "int8_t") {
92 int8_t data;
93 memcpy((void *)&data, *buf, sizeof(data));
94 *buf += sizeof(data);
95 datas[i] = data;
96 } else if (datas_type.at(i) == "int16_t") {
97 int16_t data;
98 memcpy((void *)&data, *buf, sizeof(data));
99 *buf += sizeof(data);
100 if (big_endian == true) data = qFromBigEndian(data);
101 datas[i] = data;
102 } else {
103 fprintf(stderr,"DataPlot1D::BufEvent unknown type %s\n",datas_type.at(i).toLocal8Bit().constData());
104 }
105 }
106
107 step_s = period / 1000.;
108 plot(datas);
109 free(datas);
110}
111
112// context menu
113bool DataPlot1D::mouseEvent(QMouseEvent *event) {
114 if (event->button() == Qt::RightButton) {
115 QMenu *menu = new QMenu("nom", (QwtPlot *)this);
116 QAction *resetX, *resetY, *clear,*action;
117
118 resetX = menu->addAction("reset time view");
119 resetY = menu->addAction("reset y view");
120 menu->addSeparator();
121
122 appendmenu(menu);
123
124 menu->addSeparator();
125 clear = menu->addAction("clear graph");
126
127 action = execmenu((QwtPlot *)this, menu, event->globalPos());
128 delete menu;
129
130 if (action == resetX)
131 resetXView();
132 if (action == resetY)
133 resetYView();
134
135 if (action == clear)
136 clearCurves();
137
138 return true;
139 }
140 return false;
141}
Note: See TracBrowser for help on using the repository browser.