-
Notifications
You must be signed in to change notification settings - Fork 0
/
expstripchartitem.cpp
99 lines (81 loc) · 2.19 KB
/
expstripchartitem.cpp
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
#include <QtMath>
#include <QPainter>
#include "expstripchartitem.h"
#include "anserglobal.h"
ExpStripChartItem::ExpStripChartItem(QQuickPaintedItem *parent):
BaseChartItem(parent),
m_expTp(0),
m_xComponent(false)
{
}
bool ExpStripChartItem::transform()
{
if(m_data.empty() || m_expTp < 0) return false;
int k;
short base;
int a,b,c,vxavg,vyavg,cent;
int vx,vy,pnt;
int x1, y1;
if(height() < 2)
return false;
m_points.clear();
const int spacing = 20;
int dataIdx = 0;
LissDataMap::iterator dataIt = m_data.begin();
for (; dataIt != m_data.end(); dataIt++) {
Channel* channel = dataIt.value();
if(m_expTp > channel->getData().count()) return false;
ChannelParam& cp = channel->getCp();
if(cp.xavg == 0){
AnserGlobal::calAvgXY(channel, cp.xavg, cp.yavg);
}
vxavg = cp.xavg;
vyavg = cp.yavg;
/* get transformation coefficients */
const int FACTOR = 100;
float theta = M_PI * cp.rot/180.0;
a = FACTOR * width() * qCos(theta);
b = FACTOR * width() * qSin(theta);
c = FACTOR * cp.span;
cent = width()/2 + dataIdx*spacing;
dataIdx++;
if (c==0) c=1;
/* setup y coordinates */
base = (height()-1);
pnt = m_expTp;
QVector<QPointF>& points = m_points[dataIt.key()];
points.clear();
for(k = 0; k < height(); ++k){
y1 = base--;
vx = channel->at(pnt).x() - vxavg;
vy = channel->at(pnt).y() - vyavg;
if(m_xComponent){
x1 = cent + (-b*vx + a*vy)/c;
}else {
x1 = cent + (a*vx + b*vy)/c;
}
points.push_back(QPoint(x1, y1));
if(++pnt >= channel->getRawNpt()) pnt = 0;
}
}
return true;
}
bool ExpStripChartItem::xComponent() const
{
return m_xComponent;
}
void ExpStripChartItem::setXComponent(bool xComponent)
{
m_xComponent = xComponent;
}
int ExpStripChartItem::expTp() const
{
return m_expTp;
}
void ExpStripChartItem::setExpTp(int expTp)
{
if(m_expTp != expTp){
m_expTp = expTp;
Q_EMIT expTpChanged();
}
}