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
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[9]5#include "DataPlot1D.h"
6#include "Layout.h"
7#include <QMouseEvent>
8#include <QMenu>
9#include <QGridLayout>
10#include <qendian.h>
11
[15]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) {
[9]16
[15]17 setEnabled(enabled);
18 parent->addWidget(this, row, col);
19 visible_widget = this;
[9]20}
21
22DataPlot1D::~DataPlot1D() {
[15]23 visible_widget = NULL; // because otherwise xmlwidget will delete it
[9]24}
25
26void DataPlot1D::XmlEvent(QDomElement dom) {
[15]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);
[9]41 } else {
[15]42 printf("MyDataPlot1D::addCurve unknown type %s\n",
43 type.toLocal8Bit().constData());
[9]44 }
[15]45 } else {
46 XmlSetup(dom);
47 }
[9]48}
49
50bool DataPlot1D::eventFilter(QObject *o, QEvent *e) {
[15]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 }
[9]62
[15]63 default:
64 break;
[9]65 }
[15]66 }
67 return Scope::eventFilter(o, e);
[9]68}
69
[15]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));
[9]76
[15]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());
[9]101 }
[15]102 }
[9]103
[15]104 step_s = period / 1000.;
105 plot(datas);
[9]106}
107
[15]108// context menu
[9]109bool DataPlot1D::mouseEvent(QMouseEvent *event) {
[15]110 if (event->button() == Qt::RightButton) {
111 QMenu *menu = new QMenu("nom", (QwtPlot *)this);
112 QAction *a, *b, *z;
[9]113
[15]114 a = menu->addAction("reset time view");
115 b = menu->addAction("reset y view");
116 menu->addSeparator();
[9]117
[15]118 appendmenu(menu);
119 z = execmenu((QwtPlot *)this, menu, event->globalPos());
120 delete menu;
[9]121
[15]122 if (z == a)
123 resetXView();
124 if (z == b)
125 resetYView();
[9]126
[15]127 return true;
128 }
129 return false;
[9]130}
Note: See TracBrowser for help on using the repository browser.