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

Last change on this file since 9 was 9, checked in by Sanahuja Guillaume, 7 years ago

gcs

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