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

Last change on this file since 10 was 10, checked in by Sanahuja Guillaume, 6 years ago

lic

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