Skip to content

Commit f348f34

Browse files
authored
Merge pull request #959 from fredzo/stream-browser-dialog-upgrade
Stream browser dialog upgrade
2 parents dd7413d + d43f827 commit f348f34

6 files changed

Lines changed: 287 additions & 29 deletions

File tree

src/ngscopeclient/MainWindow.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,14 +1283,39 @@ void MainWindow::DockingArea()
12831283
}
12841284
ImGui::DockBuilderDockWindow(group->GetID().c_str(), node->ID);
12851285

1286-
//Add a new waveform area for our stream to the new group
1287-
LogTrace("Making new area for %s in %s\n",
1288-
request.m_stream.GetName().c_str(),
1289-
group->GetID().c_str());
1290-
auto area = make_shared<WaveformArea>(request.m_stream, group, this);
1291-
if(request.m_ramp != "")
1292-
area->GetDisplayedChannel(0)->m_colorRamp = request.m_ramp;
1293-
group->AddArea(area);
1286+
//Add a new waveform area for our stream/streamGroup to the new group
1287+
if(request.m_stream)
1288+
{
1289+
LogTrace("Making new area for %s in %s\n",
1290+
request.m_stream.GetName().c_str(),
1291+
group->GetID().c_str());
1292+
auto area = make_shared<WaveformArea>(request.m_stream, group, this);
1293+
if(request.m_ramp != "")
1294+
area->GetDisplayedChannel(0)->m_colorRamp = request.m_ramp;
1295+
group->AddArea(area);
1296+
}
1297+
else if(request.m_streamGroup)
1298+
{
1299+
std::shared_ptr<WaveformArea> area;
1300+
bool first = true;
1301+
for(auto channel : request.m_streamGroup->m_channels)
1302+
{
1303+
StreamDescriptor s(channel, 0);
1304+
LogTrace("Making new area for %s in %s\n",
1305+
s.GetName().c_str(),
1306+
group->GetID().c_str());
1307+
if(first || !request.m_singleArea)
1308+
{
1309+
area = make_shared<WaveformArea>(s, group, this);
1310+
group->AddArea(area);
1311+
first = false;
1312+
}
1313+
else
1314+
{
1315+
area->AddStream(s);
1316+
}
1317+
}
1318+
}
12941319
}
12951320

12961321
//Finish up

src/ngscopeclient/MainWindow.h

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,68 @@ class SplitGroupRequest
7070
, m_direction(direction)
7171
, m_stream(stream)
7272
, m_ramp(ramp)
73+
, m_streamGroup(nullptr)
7374
{
7475
auto schan = dynamic_cast<OscilloscopeChannel*>(stream.m_channel);
7576
if(schan)
7677
schan->AddRef();
7778
}
7879

80+
SplitGroupRequest(std::shared_ptr<WaveformGroup> group, ImGuiDir direction, std::shared_ptr<StreamGroupDescriptor> streamGroup, bool singleArea)
81+
: m_group(group)
82+
, m_direction(direction)
83+
, m_streamGroup(streamGroup)
84+
, m_singleArea(singleArea)
85+
{
86+
if(streamGroup)
87+
{
88+
for(auto chan : streamGroup->m_channels)
89+
{
90+
chan->AddRef();
91+
}
92+
}
93+
}
94+
7995
SplitGroupRequest(const SplitGroupRequest& rhs)
8096
: m_group(rhs.m_group)
8197
, m_direction(rhs.m_direction)
8298
, m_stream(rhs.m_stream)
8399
, m_ramp(rhs.m_ramp)
100+
, m_streamGroup(rhs.m_streamGroup)
101+
, m_singleArea(rhs.m_singleArea)
84102
{
85-
auto schan = dynamic_cast<OscilloscopeChannel*>(rhs.m_stream.m_channel);
86-
if(schan)
87-
schan->AddRef();
103+
if(rhs.m_stream)
104+
{
105+
auto schan = dynamic_cast<OscilloscopeChannel*>(rhs.m_stream.m_channel);
106+
if(schan)
107+
schan->AddRef();
108+
}
109+
else if(rhs.m_streamGroup)
110+
{
111+
for(auto chan : rhs.m_streamGroup->m_channels)
112+
{
113+
chan->AddRef();
114+
}
115+
}
88116
}
89117

90118
SplitGroupRequest& operator=(const SplitGroupRequest& /*rhs*/) =delete;
91119

92120
~SplitGroupRequest()
93121
{
94-
auto schan = dynamic_cast<OscilloscopeChannel*>(m_stream.m_channel);
95-
if(schan)
96-
schan->Release();
122+
if(m_stream)
123+
{
124+
auto schan = dynamic_cast<OscilloscopeChannel*>(m_stream.m_channel);
125+
if(schan)
126+
schan->Release();
127+
}
128+
else if(m_streamGroup)
129+
{
130+
for(auto chan : m_streamGroup->m_channels)
131+
{
132+
chan->Release();
133+
}
134+
}
97135
}
98136

99137
std::shared_ptr<WaveformGroup> m_group;
@@ -102,6 +140,9 @@ class SplitGroupRequest
102140

103141
///@brief Color ramp request (may be blank if unspecified)
104142
std::string m_ramp;
143+
144+
std::shared_ptr<StreamGroupDescriptor> m_streamGroup;
145+
bool m_singleArea;
105146
};
106147

107148
/**
@@ -142,6 +183,9 @@ class MainWindow : public VulkanWindow
142183
std::string colorRamp)
143184
{ m_splitRequests.push_back(SplitGroupRequest(group, direction, stream, colorRamp)); }
144185

186+
void QueueSplitGroup(std::shared_ptr<WaveformGroup> group, ImGuiDir direction, std::shared_ptr<StreamGroupDescriptor> streamGroup, bool singleArea)
187+
{ m_splitRequests.push_back(SplitGroupRequest(group, direction, streamGroup, singleArea)); }
188+
145189
void ShowChannelProperties(OscilloscopeChannel* channel);
146190
void ShowInstrumentProperties(std::shared_ptr<Instrument> instrument);
147191
void ShowTriggerProperties();

src/ngscopeclient/StreamBrowserDialog.cpp

Lines changed: 112 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ bool StreamBrowserDialog::renderOnOffToggle(const char* label, bool alignRight,
416416
@param inst the instrument to render the progress channel for
417417
@param chan the channel to render the progress for
418418
@param isLast true if it is the last channel of the instrument
419+
420+
@return Returns true if the progress bar has been rendered
419421
*/
420-
void StreamBrowserDialog::renderDownloadProgress(std::shared_ptr<Instrument> inst, InstrumentChannel *chan, bool isLast)
422+
bool StreamBrowserDialog::renderDownloadProgress(std::shared_ptr<Instrument> inst, InstrumentChannel *chan, bool isLast)
421423
{
422424
static const char* const download[] = {"DOWNLOADING", "DOWNLOAD" ,"DL","D", NULL};
423425

@@ -516,7 +518,7 @@ void StreamBrowserDialog::renderDownloadProgress(std::shared_ptr<Instrument> ins
516518
}
517519

518520
if (!shouldRender)
519-
return;
521+
return false;
520522

521523
/// @brief Width used to display progress bars (e.g. download progress bar)
522524
#define PROGRESS_BAR_WIDTH 80
@@ -548,10 +550,11 @@ void StreamBrowserDialog::renderDownloadProgress(std::shared_ptr<Instrument> ins
548550
ImGui::ProgressBar(chan->GetDownloadProgress(), ImVec2(PROGRESS_BAR_WIDTH, ImGui::GetFontSize()));
549551
}
550552

551-
return;
553+
return true;
552554
}
553555
}
554556
// well, shoot -- I guess there wasn't enough room to do *anything* useful!
557+
return true;
555558
}
556559

557560
/**
@@ -1058,10 +1061,11 @@ void StreamBrowserDialog::renderInstrumentNode(shared_ptr<Instrument> instrument
10581061
}
10591062
}
10601063
bool result;
1064+
bool changed;
10611065
if(allOn || someOn)
10621066
{
10631067
result = true;
1064-
renderToggle(
1068+
changed = renderToggle(
10651069
"###psuon",
10661070
true,
10671071
allOn ?
@@ -1071,9 +1075,9 @@ void StreamBrowserDialog::renderInstrumentNode(shared_ptr<Instrument> instrument
10711075
else
10721076
{
10731077
result = false;
1074-
renderOnOffToggle("###psuon", true, result);
1078+
changed = renderOnOffToggle("###psuon", true, result);
10751079
}
1076-
if(result != allOn)
1080+
if(changed)
10771081
{
10781082
if(psu->SupportsMasterOutputSwitching())
10791083
psu->SetMasterPowerEnable(result);
@@ -1135,12 +1139,74 @@ void StreamBrowserDialog::renderInstrumentNode(shared_ptr<Instrument> instrument
11351139
renderChannelNode(instrument,i,(i == lastEnabledChannelIndex));
11361140
}
11371141
int bankNumber = 1;
1142+
bool bankIsOpen;
11381143
for(auto bank : digitalBanks)
11391144
{ // Iterate on digital banks
11401145
if(bank.size() > 1)
11411146
{ // Only show Digital Bank node if there is more than on channel in the bank
11421147
string nodeName = "Digital Bank " + to_string(bankNumber);
1143-
if(ImGui::TreeNodeEx(nodeName.c_str()))
1148+
bankIsOpen = ImGui::TreeNodeEx(nodeName.c_str());
1149+
1150+
// Add dragdrop source for this bank
1151+
if(ImGui::BeginDragDropSource())
1152+
{
1153+
m_streamGroupDesciptor = make_shared<StreamGroupDescriptor>(nodeName, bank);
1154+
auto ptr = m_streamGroupDesciptor.get();
1155+
ImGui::SetDragDropPayload("StreamGroup", &ptr, sizeof(m_streamGroupDesciptor));
1156+
ImGui::TextUnformatted(m_streamGroupDesciptor->GetName().c_str());
1157+
ImGui::EndDragDropSource();
1158+
}
1159+
else
1160+
DoItemHelp();
1161+
/* Currently, enable/disable state is coupled to node reference counting, so we can't let the user manually enable/disable channels
1162+
// Add Banck on/off toggle
1163+
startBadgeLine();
1164+
bool allOn = true;
1165+
bool someOn = false;
1166+
for(auto channel : bank)
1167+
{ // Iterate on bank's channel
1168+
size_t i = channel->GetIndex();
1169+
if(scope->IsChannelEnabled(i))
1170+
{
1171+
someOn = true;
1172+
}
1173+
else
1174+
{
1175+
allOn = false;
1176+
}
1177+
}
1178+
bool result;
1179+
bool changed;
1180+
string toggleId = "###"+nodeName+"on";
1181+
if(allOn || someOn)
1182+
{
1183+
result = true;
1184+
changed = renderToggle(
1185+
toggleId.c_str(),
1186+
true,
1187+
allOn ?
1188+
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_on_badge_color")) :
1189+
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_partial_badge_color")), result,"DISABLE","ENABLED",3);
1190+
}
1191+
else
1192+
{
1193+
result = false;
1194+
changed = renderToggle(
1195+
toggleId.c_str(),
1196+
true,
1197+
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_off_badge_color")),
1198+
result,"DISABLED","ENABLE",3);
1199+
}
1200+
if(changed)
1201+
{
1202+
for(auto channel : bank)
1203+
{ // Iterate on bank's channel
1204+
size_t i = channel->GetIndex();
1205+
result ? scope->EnableChannel(i) : scope->DisableChannel(i);
1206+
}
1207+
}
1208+
*/
1209+
if(bankIsOpen)
11441210
{
11451211
ImGui::Unindent(ImGui::GetTreeNodeToLabelSpacing());
11461212
for(auto channel : bank)
@@ -1525,17 +1591,53 @@ void StreamBrowserDialog::renderChannelNode(shared_ptr<Instrument> instrument, s
15251591
startBadgeLine();
15261592
if (scopechan)
15271593
{
1594+
bool chanEnabled = scopechan->IsEnabled();
1595+
15281596
//"trigger" badge on trigger inputs to show they're not displayable channels
15291597
if(scopechan->GetType(0) == Stream::STREAM_TYPE_TRIGGER)
15301598
renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_disabled_badge_color")), "TRIG ONLY", "TRIG","--", nullptr);
15311599

1600+
/* Currently, enable/disable state is coupled to node reference counting, so we can't let the user manually enable/disable channels
15321601
// Scope channel
1533-
else if (!scopechan->IsEnabled())
1534-
renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_disabled_badge_color")), "DISABLED", "DISA","--", nullptr);
1602+
else if (!chanEnabled)
1603+
{
1604+
if(renderToggle(
1605+
"###scopeChanEnable",
1606+
true,
1607+
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_disabled_badge_color")),
1608+
chanEnabled,
1609+
"DISABLED",
1610+
"ENABLE",
1611+
3))
1612+
{
1613+
if(chanEnabled)
1614+
scope->EnableChannel(channelIndex);
1615+
}
1616+
//renderBadge(ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_disabled_badge_color")), "DISABLED", "DISA","--", nullptr);
1617+
}
1618+
*/
15351619

15361620
//Download in progress
15371621
else
1538-
renderDownloadProgress(instrument, channel, isLast);
1622+
{
1623+
if(!renderDownloadProgress(instrument, channel, isLast))
1624+
{ // No download in progress, we can show the ENABLE/DISABLE toggle
1625+
/* Currently, enable/disable state is coupled to node reference counting, so we can't let the user manually enable/disable channels
1626+
if(renderToggle(
1627+
"###scopeChanEnable",
1628+
true,
1629+
ImGui::ColorConvertU32ToFloat4(prefs.GetColor("Appearance.Stream Browser.instrument_on_badge_color")),
1630+
chanEnabled,
1631+
"DISABLE",
1632+
"ENABLED",
1633+
3))
1634+
{
1635+
if(!chanEnabled)
1636+
scope->DisableChannel(channelIndex);
1637+
}
1638+
*/
1639+
}
1640+
}
15391641
}
15401642
else if(psu)
15411643
{

src/ngscopeclient/StreamBrowserDialog.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class StreamBrowserDialog : public Dialog
155155
uint8_t cropTextTo = 0,
156156
float paddingRight = 0);
157157
bool renderOnOffToggle(const char* label, bool alignRight, bool& curValue, const char* valueOff = "OFF", const char* valueOn = "ON", uint8_t cropTextTo = 0, float paddingRight = 0);
158-
void renderDownloadProgress(std::shared_ptr<Instrument> inst, InstrumentChannel *chan, bool isLast);
158+
bool renderDownloadProgress(std::shared_ptr<Instrument> inst, InstrumentChannel *chan, bool isLast);
159159
bool renderPsuRows(bool isVoltage, bool cc, PowerSupplyChannel* chan, std::string& currentValue, float& committedValue, std::string& measuredValue, bool &clicked, bool &hovered);
160160
void renderAwgProperties(std::shared_ptr<FunctionGenerator> awg, FunctionGeneratorChannel* awgchan);
161161
void renderDmmProperties(std::shared_ptr<Multimeter> dmm, MultimeterChannel* dmmchan, bool isMain, bool &clicked, bool &hovered);
@@ -189,6 +189,9 @@ class StreamBrowserDialog : public Dialog
189189
///@brief Map of instruments to timebase settings
190190
std::map<std::shared_ptr<Instrument>, std::shared_ptr<StreamBrowserTimebaseInfo> > m_timebaseConfig;
191191

192+
///@brief Reference to currently dragged StreamGroupDesciptor
193+
std::shared_ptr<StreamGroupDescriptor> m_streamGroupDesciptor;
194+
192195
///@brief Helper to render a small button that's non-interactive
193196
void SmallDisabledButton(const char* label)
194197
{

0 commit comments

Comments
 (0)