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

Last change on this file since 218 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

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