-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatawave.cpp
More file actions
177 lines (168 loc) · 6.81 KB
/
datawave.cpp
File metadata and controls
177 lines (168 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "datawave.h"
#include <QColor>
#include <qwt_plot_magnifier.h>
#include <qwt_plot_panner.h>
#include <qwt_plot_item.h>
#include <qwt_legend.h>
#ifdef QT_DEBUG
#include <QDebug>
#endif
#include "datahandle.h"
const int DataWave::maxDisplayPoints = 2000;
DataWave::DataWave(QWidget *parent) :
QWidget(parent),
plot(new QwtPlot(this)),
canvas(new QwtPlotCanvas()),
accelerationXCurve(new QwtPlotCurve("accelerationX")),
accelerationYCurve(new QwtPlotCurve("accelerationY")),
accelerationZCurve(new QwtPlotCurve("accelerationZ")),
gyroscopeXCurve(new QwtPlotCurve("gyroscopeX")),
gyroscopeYCurve(new QwtPlotCurve("gyroscopeY")),
gyroscopeZCurve(new QwtPlotCurve("gyroscopeZ")),
rollAngelCurve(new QwtPlotCurve("rollAngel")),
pitchAngelCurve(new QwtPlotCurve("pitchAngel")),
driftAngelCurve(new QwtPlotCurve("driftAngel")),
legend(new QwtLegend(this)),
dataWaveLayout(new QGridLayout(this)),
nowDisplayPoints(0),
nowSocketDescriptor(0),
nowNodeDescriptor(0x7FFFFFFF)
{
//canvas->setPalette(Qt::white);
dataWaveLayout->addWidget(plot, 0, 0, 1, 1);
setLayout(dataWaveLayout);
plot->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
canvas->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
plot->setCanvas(canvas);
plot->setAxisTitle(QwtPlot::xBottom, "time(s)->");
plot->setAxisTitle(QwtPlot::yLeft, "");
plot->setAxisAutoScale(QwtPlot::xBottom, false);
plot->setAxisAutoScale(QwtPlot::yLeft, false);
plot->setAxisScale(QwtPlot::xBottom, 0, 5);
plot->setAxisScale(QwtPlot::yLeft, 0, 100);
//accelerationXPoint << QPoint(1, 1) << QPoint(2, 2);
//accelerationYPoint << QPoint(5, 5) << QPoint(6, 6);
accelerationXCurve->setSamples(accelerationXPoint);
accelerationYCurve->setSamples(accelerationYPoint);
accelerationXCurve->setPen(QColor(0, 0, 255), 2);
accelerationXCurve->attach(plot);
accelerationYCurve->setPen(QColor(0, 245, 255), 2);
accelerationYCurve->attach(plot);
accelerationZCurve->setPen(QColor(0, 255, 0), 2);
accelerationZCurve->attach(plot);
gyroscopeXCurve->setPen(QColor(255, 255, 0), 2);
gyroscopeXCurve->attach(plot);
gyroscopeYCurve->setPen(QColor(255, 106, 106), 2);
gyroscopeYCurve->attach(plot);
gyroscopeZCurve->setPen(QColor(255, 0, 0), 2);
gyroscopeZCurve->attach(plot);
rollAngelCurve->setPen(QColor(148, 0, 211), 2);
rollAngelCurve->attach(plot);
pitchAngelCurve->setPen(QColor(238, 118, 0), 2);
pitchAngelCurve->attach(plot);
driftAngelCurve->setPen(QColor(105, 105, 105), 2);
driftAngelCurve->attach(plot);
[[maybe_unused]] QwtPlotMagnifier *magnifier = new QwtPlotMagnifier(plot->canvas());
//magnifier (rooler zoom)
[[maybe_unused]] QwtPlotPanner *panner = new QwtPlotPanner(plot->canvas());
//panner (drag)
legend->setDefaultItemMode(QwtLegendData::Checkable);
//makes lefend button checkabke
plot->insertLegend(legend, QwtPlot::RightLegend);
plot->setFont(legendFont);
//only legend font, not plot legend
//connect(legend, &QwtLegend::checked, this, &DataWave::showItemChecked);
//void(QwtLegend:: *temp)(const QVariant &, bool, int) = &QwtLegend::checked;
//connect(legend, temp, this, &DataWave::showItemChecked);
QObject::connect(legend, static_cast<void(QwtLegend::*)(const QVariant &, bool, int)>(&QwtLegend::checked), this, &DataWave::showItemChecked);
//QObject::connect(legend, SIGNAL(checked(const QVariant &, bool, int)), this, SLOT(showItemChecked(const QVariant &, bool)));
//QObject::connect(legend, static_cast<void (QwtLegend::*)(const QVariant &, bool, int)>(&QwtLegend::checked), this, &DataWave::showItemChecked);
plot->replot();
plot->setAutoReplot();
/*for(int i = 0; i < plot->itemList().size(); i++)
{
QwtPlotItem *item = plot->itemList()[i]
}*/
}
void DataWave::showItemChecked(const QVariant &itemInfo, bool on)
{
QwtPlotItem *plotItem = plot->infoToItem(itemInfo);
if(plotItem)
plotItem->setVisible(on);
plot->replot();
}
DataWave::~DataWave()
{
}
/**
* @brief DataWave::getData
* get Data from lower computer. Draw Curves. Insert to database
* @param socketDescriptor
* @param data
*/
void DataWave::getData(int socketDescriptor, QString data)
{
DataHandle handler(data);
if(static_cast<int>(handler.getData()[0]) != nowNodeDescriptor)
return;
#ifdef QT_DEBUG
qDebug() << "already recive";
#endif
if(socketDescriptor != nowSocketDescriptor && nowSocketDescriptor != 0)
{
nowSocketDescriptor = socketDescriptor;
clearCurves();
}
nowDisplayPoints += 1;
if(nowDisplayPoints >= maxDisplayPoints)
{
accelerationXPoint.erase(accelerationXPoint.begin());
accelerationYPoint.erase(accelerationYPoint.begin());
accelerationZPoint.erase(accelerationZPoint.begin());
gyroscopeXPoint.erase(gyroscopeXPoint.begin());
gyroscopeYPoint.erase(gyroscopeYPoint.begin());
gyroscopeZPoint.erase(gyroscopeZPoint.begin());
rollAngelPoint.erase(rollAngelPoint.begin());
pitchAngelPoint.erase(pitchAngelPoint.begin());
driftAngelPoint.erase(driftAngelPoint.begin());
}
accelerationXPoint << QPointF(nowDisplayPoints, handler.getData()[1]);
accelerationXCurve->setSamples(accelerationXPoint);
accelerationYPoint << QPointF(nowDisplayPoints, handler.getData()[2]);
accelerationYCurve->setSamples(accelerationXPoint);
accelerationZPoint << QPointF(nowDisplayPoints, handler.getData()[3]);
accelerationZCurve->setSamples(accelerationXPoint);
gyroscopeXPoint << QPointF(nowDisplayPoints, handler.getData()[5]);
gyroscopeXCurve->setSamples(accelerationXPoint);
gyroscopeZPoint << QPointF(nowDisplayPoints, handler.getData()[6]);
gyroscopeZCurve->setSamples(accelerationXPoint);
gyroscopeYPoint << QPointF(nowDisplayPoints, handler.getData()[7]);
gyroscopeYCurve->setSamples(accelerationXPoint);
rollAngelPoint << QPointF(nowDisplayPoints, handler.getData()[8]);
rollAngelCurve->setSamples(rollAngelPoint);
pitchAngelPoint << QPointF(nowDisplayPoints, handler.getData()[9]);
pitchAngelCurve->setSamples(pitchAngelPoint);
driftAngelPoint << QPointF(nowDisplayPoints, handler.getData()[10]);
driftAngelCurve->setSamples(driftAngelPoint);
plot->setAxisScale(QwtPlot::xBottom, 0, nowDisplayPoints + 5);
plot->replot();
}
void DataWave::clearCurves()
{
nowDisplayPoints = 0;
accelerationXPoint.clear();
accelerationYPoint.clear();
accelerationZPoint.clear();
gyroscopeXPoint.clear();
gyroscopeYPoint.clear();
gyroscopeZPoint.clear();
rollAngelPoint.clear();
pitchAngelPoint.clear();
driftAngelPoint.clear();
plot->replot();
}
void DataWave::nodeChanged(int newChanged)
{
nowNodeDescriptor = newChanged;
clearCurves();
}