-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathtimeplotcomponentchannel.cpp
More file actions
192 lines (157 loc) · 6.17 KB
/
timeplotcomponentchannel.cpp
File metadata and controls
192 lines (157 loc) · 6.17 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "timeplotcomponentchannel.h"
#include <pluginbase/preferences.h>
#include <gui/widgets/menucollapsesection.h>
#include <gui/widgets/menuplotaxisrangecontrol.h>
#include <gui/widgets/menuplotchannelcurvestylecontrol.h>
#include <gui/widgets/menusectionwidget.h>
using namespace scopy;
using namespace adc;
adc::TimePlotComponentChannel::TimePlotComponentChannel(ChannelComponent *ch, TimePlotComponent *plotComponent,
QObject *parent)
: QObject(parent)
, m_enabled(true)
{
auto timeplot = plotComponent->timePlot();
auto xyplot = plotComponent->xyPlot();
m_ch = ch;
m_plotComponent = nullptr;
initPlotComponent(plotComponent);
m_timePlotYAxis->setInterval(-2048, 2048);
m_xyPlotYAxis->setInterval(-2048, 2048);
}
void adc::TimePlotComponentChannel::deinitPlotComponent()
{
if(m_plotComponent == nullptr)
return;
auto timeplot = m_plotComponent->timePlot();
auto xyplot = m_plotComponent->xyPlot();
timeplot->removePlotAxisHandle(m_timePlotAxisHandle);
timeplot->removePlotChannel(m_timePlotCh);
xyplot->removePlotChannel(m_xyPlotCh);
delete m_timePlotYAxis;
delete m_timePlotCh;
delete m_timePlotAxisHandle;
delete m_xyPlotYAxis;
delete m_xyPlotCh;
}
void adc::TimePlotComponentChannel ::initPlotComponent(PlotComponent *pc)
{
TimePlotComponent *plotComponent = dynamic_cast<TimePlotComponent *>(pc);
auto timeplot = plotComponent->timePlot();
auto xyplot = plotComponent->xyPlot();
if(plotComponent != m_plotComponent) {
deinitPlotComponent();
}
m_plotComponent = plotComponent;
int yPlotAxisPosition = Preferences::get("adc_plot_yaxis_label_position").toInt();
int yPlotAxisHandle = Preferences::get("adc_plot_yaxis_handle_position").toInt();
m_timePlotYAxis = new PlotAxis(yPlotAxisPosition, timeplot, m_ch->pen(), this);
m_timePlotCh = new PlotChannel(m_ch->name(), m_ch->pen(), timeplot->xAxis(), m_timePlotYAxis, this);
m_timePlotAxisHandle = new PlotAxisHandle(timeplot, m_timePlotYAxis);
m_timePlotAxisHandle->handle()->setHandlePos((HandlePos)yPlotAxisHandle);
m_timePlotAxisHandle->handle()->setBarVisibility(BarVisibility::ON_HOVER);
m_timePlotAxisHandle->handle()->setColor(m_ch->pen().color());
connect(m_timePlotAxisHandle, &PlotAxisHandle::scalePosChanged, this, [=](double pos) {
double min = m_timePlotYAxis->min() - pos;
double max = m_timePlotYAxis->max() - pos;
m_timePlotYAxis->setInterval(min, max);
m_plotComponent->replot();
});
m_timePlotCh->setHandle(m_timePlotAxisHandle);
timeplot->addPlotAxisHandle(m_timePlotAxisHandle);
timeplot->addPlotChannel(m_timePlotCh);
m_timePlotCh->setEnabled(true);
m_xyPlotYAxis = new PlotAxis(yPlotAxisPosition, xyplot, m_ch->pen(), this);
m_xyPlotCh = new PlotChannel(m_ch->name(), m_ch->pen(), xyplot->xAxis(), m_xyPlotYAxis, this);
xyplot->addPlotChannel(m_xyPlotCh);
m_xyPlotCh->setEnabled(true);
lockYAxis(m_plotComponent->singleYMode());
m_timePlotYAxis->setInterval(-2048, 2048);
m_xyPlotYAxis->setInterval(-2048, 2048);
refreshData(true);
}
adc::TimePlotComponentChannel ::~TimePlotComponentChannel() {}
void adc::TimePlotComponentChannel ::refreshData(bool copy)
{
auto data = m_ch->chData();
m_timePlotCh->setSamples(data->xData(), data->yData(), data->size(), copy);
if(m_xyXData) {
m_xyPlotCh->setSamples(m_xyXData, data->yData(), data->size(), copy);
}
}
void adc::TimePlotComponentChannel ::onNewData(const float *xData_, const float *yData_, size_t size, bool copy)
{
refreshData(copy);
// Q_EMIT m_plotComponent->timePlot()->newData();
}
void adc::TimePlotComponentChannel ::setXyXData(const float *xyxdata) { m_xyXData = xyxdata; }
void adc::TimePlotComponentChannel ::lockYAxis(bool b)
{
m_singleYMode = b;
if(m_singleYMode) {
PlotAxis *time = m_plotComponent->timePlot()->yAxis();
PlotAxis *xy = m_plotComponent->xyPlot()->yAxis();
m_plotComponent->timePlot()->plotChannelChangeYAxis(m_timePlotCh, time);
m_plotComponent->xyPlot()->plotChannelChangeYAxis(m_xyPlotCh, xy);
} else {
PlotAxis *time = m_timePlotYAxis;
PlotAxis *xy = m_xyPlotYAxis;
m_plotComponent->timePlot()->plotChannelChangeYAxis(m_timePlotCh, time);
m_plotComponent->xyPlot()->plotChannelChangeYAxis(m_xyPlotCh, xy);
}
m_timePlotAxisHandle->handle()->setVisible(!b);
m_plotComponent->refreshXYXAxis();
m_plotComponent->refreshAxisLabels();
m_plotComponent->replot();
}
QWidget *adc::TimePlotComponentChannel ::createCurveMenu(QWidget *parent)
{
MenuSectionCollapseWidget *curve = new MenuSectionCollapseWidget("CURVE", MenuCollapseSection::MHCW_NONE,
MenuCollapseSection::MHW_BASEWIDGET, parent);
MenuPlotChannelCurveStyleControl *curveSettings = new MenuPlotChannelCurveStyleControl(curve);
curveSettings->addChannels(m_timePlotCh);
curve->contentLayout()->addWidget(curveSettings);
return curve;
}
ChannelComponent *adc::TimePlotComponentChannel ::channelComponent() { return m_ch; }
PlotComponent *adc::TimePlotComponentChannel ::plotComponent() { return m_plotComponent; }
PlotChannel *adc::TimePlotComponentChannel ::plotChannel() { return m_timePlotCh; }
void adc::TimePlotComponentChannel ::enable()
{
m_timePlotCh->enable();
m_xyPlotCh->enable();
if(m_timePlotAxisHandle && !m_singleYMode) {
m_timePlotAxisHandle->handle()->setVisible(true);
m_timePlotAxisHandle->handle()->raise();
}
m_enabled = true;
}
void adc::TimePlotComponentChannel ::disable()
{
m_timePlotCh->disable();
m_xyPlotCh->disable();
if(m_timePlotAxisHandle) {
m_timePlotAxisHandle->handle()->setVisible(false);
}
m_enabled = false;
}