Skip to content

Commit ecc525e

Browse files
committed
"Manage instruments" dialog now correctly handles offline instruments
1 parent 41e0583 commit ecc525e

File tree

2 files changed

+86
-46
lines changed

2 files changed

+86
-46
lines changed

src/ngscopeclient/ManageInstrumentsDialog.cpp

Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535

3636
#include "ngscopeclient.h"
37+
#include "../scopehal/MockOscilloscope.h"
3738
#include "ManageInstrumentsDialog.h"
3839
#include "MainWindow.h"
3940

@@ -131,7 +132,9 @@ void ManageInstrumentsDialog::TriggerGroupsTable()
131132
//If we have no scopes but are not empty, we're a trend-only group
132133
//Show a dummy root node
133134
bool rootOpen = false;
135+
bool rootIsMock = false;
134136
SCPIOscilloscope* firstScope = nullptr;
137+
MockOscilloscope* mockScope = nullptr;
135138

136139
if(!group->HasScopes())
137140
{
@@ -148,18 +151,36 @@ void ManageInstrumentsDialog::TriggerGroupsTable()
148151
//Normal root node
149152
else
150153
{
154+
//If the first scope is a mock scope, show it differently
151155
firstScope = dynamic_cast<SCPIOscilloscope*>(group->m_primary);
152-
if(!firstScope)
153-
LogFatal("group has secondary but no primary, shouldn't be possible\n");
156+
mockScope = dynamic_cast<MockOscilloscope*>(group->m_primary);
154157

155-
ImGui::PushID(firstScope);
156-
ImGui::TableNextRow(ImGuiTableRowFlags_None);
157-
ImGui::TableSetColumnIndex(0);
158+
if(mockScope)
159+
{
160+
ImGui::PushID(mockScope);
161+
ImGui::TableNextRow(ImGuiTableRowFlags_None);
162+
ImGui::TableSetColumnIndex(0);
158163

159-
//Display the node for the root of the trigger group
160-
rootOpen = ImGui::TreeNodeEx(
161-
group->GetDescription().c_str(),
162-
ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_DefaultOpen );
164+
//Display the node for the root of the trigger group
165+
rootOpen = ImGui::TreeNodeEx(
166+
group->GetDescription().c_str(),
167+
ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_DefaultOpen );
168+
169+
rootIsMock = true;
170+
}
171+
else if(!firstScope)
172+
LogFatal("group has secondary but no primary, shouldn't be possible\n");
173+
else
174+
{
175+
ImGui::PushID(firstScope);
176+
ImGui::TableNextRow(ImGuiTableRowFlags_None);
177+
ImGui::TableSetColumnIndex(0);
178+
179+
//Display the node for the root of the trigger group
180+
rootOpen = ImGui::TreeNodeEx(
181+
group->GetDescription().c_str(),
182+
ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_DefaultOpen );
183+
}
163184
}
164185

165186
//Help tooltip
@@ -175,54 +196,57 @@ void ManageInstrumentsDialog::TriggerGroupsTable()
175196
ImGui::EndTooltip();
176197
}
177198

178-
//Allow dropping
179-
if(ImGui::BeginDragDropTarget())
199+
if(!rootIsMock)
180200
{
181-
auto payload = ImGui::AcceptDragDropPayload("TriggerGroup", 0);
182-
if( (payload != nullptr) && (payload->DataSize == sizeof(TriggerGroupDragDescriptor)) )
201+
//Allow dropping
202+
if(ImGui::BeginDragDropTarget())
183203
{
184-
auto desc = reinterpret_cast<TriggerGroupDragDescriptor*>(payload->Data);
204+
auto payload = ImGui::AcceptDragDropPayload("TriggerGroup", 0);
205+
if( (payload != nullptr) && (payload->DataSize == sizeof(TriggerGroupDragDescriptor)) )
206+
{
207+
auto desc = reinterpret_cast<TriggerGroupDragDescriptor*>(payload->Data);
185208

186-
//Stop the trigger if rearranging trigger groups
187-
m_session.StopTrigger();
209+
//Stop the trigger if rearranging trigger groups
210+
m_session.StopTrigger();
188211

189-
//Dropping from a different group
190-
if(desc->m_group != group.get())
191-
{
192-
if(desc->m_scope)
212+
//Dropping from a different group
213+
if(desc->m_group != group.get())
193214
{
194-
group->AddSecondary(desc->m_scope);
195-
desc->m_group->RemoveScope(desc->m_scope);
215+
if(desc->m_scope)
216+
{
217+
group->AddSecondary(desc->m_scope);
218+
desc->m_group->RemoveScope(desc->m_scope);
219+
}
220+
else
221+
{
222+
group->AddFilter(desc->m_filter);
223+
desc->m_group->RemoveFilter(desc->m_filter);
224+
}
196225
}
226+
227+
//Drop from a child of this group
197228
else
198229
{
199-
group->AddFilter(desc->m_filter);
200-
desc->m_group->RemoveFilter(desc->m_filter);
230+
if(desc->m_scope)
231+
group->MakePrimary(desc->m_scope);
232+
//no hierarchy for filters so do nothing
201233
}
202234
}
203235

204-
//Drop from a child of this group
205-
else
206-
{
207-
if(desc->m_scope)
208-
group->MakePrimary(desc->m_scope);
209-
//no hierarchy for filters so do nothing
210-
}
236+
ImGui::EndDragDropTarget();
211237
}
212238

213-
ImGui::EndDragDropTarget();
214-
}
215-
216-
//Allow dragging
217-
if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_None))
218-
{
219-
TriggerGroupDragDescriptor desc(group.get(), firstScope, nullptr);
220-
ImGui::SetDragDropPayload(
221-
"TriggerGroup",
222-
&desc,
223-
sizeof(desc));
224-
ImGui::TextUnformatted(firstScope->m_nickname.c_str());
225-
ImGui::EndDragDropSource();
239+
//Allow dragging
240+
if(ImGui::BeginDragDropSource(ImGuiDragDropFlags_None))
241+
{
242+
TriggerGroupDragDescriptor desc(group.get(), firstScope, nullptr);
243+
ImGui::SetDragDropPayload(
244+
"TriggerGroup",
245+
&desc,
246+
sizeof(desc));
247+
ImGui::TextUnformatted(firstScope->m_nickname.c_str());
248+
ImGui::EndDragDropSource();
249+
}
226250
}
227251

228252
if(firstScope)
@@ -235,6 +259,16 @@ void ManageInstrumentsDialog::TriggerGroupsTable()
235259
ImGui::TextUnformatted(firstScope->GetSerial().c_str());
236260
}
237261

262+
else if(mockScope)
263+
{
264+
if(ImGui::TableSetColumnIndex(1))
265+
ImGui::TextUnformatted(mockScope->GetVendor().c_str());
266+
if(ImGui::TableSetColumnIndex(2))
267+
ImGui::TextUnformatted(mockScope->GetName().c_str());
268+
if(ImGui::TableSetColumnIndex(3))
269+
ImGui::TextUnformatted(mockScope->GetSerial().c_str());
270+
}
271+
238272
//then put all other nodes under it
239273
if(rootOpen)
240274
{
@@ -359,7 +393,7 @@ void ManageInstrumentsDialog::RowForNewGroup()
359393

360394
void ManageInstrumentsDialog::AllInstrumentsTable()
361395
{
362-
auto insts = m_session.GetSCPIInstruments();
396+
auto insts = m_session.GetInstruments();
363397
float width = ImGui::GetFontSize();
364398
ImGui::TableSetupScrollFreeze(0, 1); //Header row does not scroll
365399
ImGui::TableSetupColumn("Nickname", ImGuiTableColumnFlags_WidthFixed, 6*width);
@@ -384,7 +418,7 @@ void ManageInstrumentsDialog::AllInstrumentsTable()
384418
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowItemOverlap,
385419
ImVec2(0, 0)))
386420
{
387-
m_selection = inst;
421+
m_selection = dynamic_cast<SCPIInstrument*>(inst);
388422
rowIsSelected = true;
389423
}
390424
if(ImGui::TableSetColumnIndex(1))
@@ -401,6 +435,9 @@ void ManageInstrumentsDialog::AllInstrumentsTable()
401435
{
402436
string types = "";
403437

438+
if(dynamic_cast<MockOscilloscope*>(inst) != nullptr)
439+
types += "offline ";
440+
404441
if(itype & Instrument::INST_OSCILLOSCOPE)
405442
types += "oscilloscope ";
406443
if(itype & Instrument::INST_DMM)

src/ngscopeclient/TriggerGroup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class TriggerGroup
8484
bool HasScopes()
8585
{ return !m_secondaries.empty() || (m_primary != nullptr); }
8686

87+
bool HasSecondaries()
88+
{ return !m_secondaries.empty(); }
89+
8790
Oscilloscope* m_primary;
8891
std::vector<Oscilloscope*> m_secondaries;
8992

0 commit comments

Comments
 (0)