Changeset 15 in flair-src for trunk/tools/FlairGCS/src/DataPlot1D.cpp
- Timestamp:
- 04/08/16 15:40:57 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/DataPlot1D.cpp
r10 r15 10 10 #include <qendian.h> 11 11 12 DataPlot1D::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) { 12 DataPlot1D::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) { 14 16 15 16 parent->addWidget(this,row,col);17 visible_widget=this;17 setEnabled(enabled); 18 parent->addWidget(this, row, col); 19 visible_widget = this; 18 20 } 19 21 20 22 DataPlot1D::~DataPlot1D() { 21 visible_widget=NULL;//because otherwise xmlwidget will delete it23 visible_widget = NULL; // because otherwise xmlwidget will delete it 22 24 } 23 25 24 26 void 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 } 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); 42 41 } else { 43 XmlSetup(dom); 42 printf("MyDataPlot1D::addCurve unknown type %s\n", 43 type.toLocal8Bit().constData()); 44 44 } 45 } else { 46 XmlSetup(dom); 47 } 45 48 } 46 49 47 50 bool 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 } 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 } 58 62 59 default: 60 break; 61 } 63 default: 64 break; 62 65 } 63 return Scope::eventFilter(o, e); 66 } 67 return Scope::eventFilter(o, e); 64 68 } 65 69 66 void 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)); 70 void 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)); 71 76 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 } 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()); 94 101 } 102 } 95 103 96 step_s=period/1000.;97 104 step_s = period / 1000.; 105 plot(datas); 98 106 } 99 107 100 // context menu108 // context menu 101 109 bool DataPlot1D::mouseEvent(QMouseEvent *event) { 102 103 QMenu *menu = new QMenu("nom", (QwtPlot*)this);104 QAction *a,*b,*z;110 if (event->button() == Qt::RightButton) { 111 QMenu *menu = new QMenu("nom", (QwtPlot *)this); 112 QAction *a, *b, *z; 105 113 106 a=menu->addAction("reset time view");107 b=menu->addAction("reset y view");108 114 a = menu->addAction("reset time view"); 115 b = menu->addAction("reset y view"); 116 menu->addSeparator(); 109 117 110 111 z=execmenu((QwtPlot*)this,menu,event->globalPos());112 118 appendmenu(menu); 119 z = execmenu((QwtPlot *)this, menu, event->globalPos()); 120 delete menu; 113 121 114 if(z==a) resetXView(); 115 if(z==b) resetYView(); 122 if (z == a) 123 resetXView(); 124 if (z == b) 125 resetYView(); 116 126 117 118 119 127 return true; 128 } 129 return false; 120 130 }
Note:
See TracChangeset
for help on using the changeset viewer.