Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 60 additions & 4 deletions src/ngscopeclient/AddInstrumentDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ AddInstrumentDialog::AddInstrumentDialog(
: Dialog(
title,
string("AddInstrument") + to_string_hex(reinterpret_cast<uintptr_t>(this)),
ImVec2(600, 180),
ImVec2(600, 200),
session,
parent)
, m_nickname(nickname)
, m_selectedDriver(0)
, m_selectedTransport(0)
, m_selectedTransportType(SCPITransportType::TRANSPORT_HID)
, m_selectedEndpoint(0)
, m_selectedModel(0)
, m_path(path)
{
Expand Down Expand Up @@ -199,6 +201,19 @@ bool AddInstrumentDialog::DoRender()
else if(dropdownOpen) //suppress further bubbles if dropdown is active
showedBubble = true;

if(!m_endpoints.empty())
{ // Endpoint discovery available: create endpoint combo
if(Combo("Endpoint", m_endpointNames, m_selectedEndpoint, &dropdownOpen))
{
UpdatePath();
}
HelpMarker("Select the transport endpoint from the list and/or edit the path manually.");
ImGui::SameLine();
if(ImGui::Button("⟳"))
{
UpdateCombos();
}
}
if(ImGui::InputText("Path", &m_path))
m_pathEdited = !(m_path.empty() || (m_path == m_defaultPath));
HelpMarker(
Expand Down Expand Up @@ -282,11 +297,27 @@ bool AddInstrumentDialog::DoConnect(SCPITransport* transport)
return m_session->CreateAndAddInstrument(m_drivers[m_selectedDriver], transport, m_nickname);
}

void AddInstrumentDialog::UpdatePath()
{
if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID)
{ // Special handling for HID transport: replace the whole path with endpoint value
m_path = m_endpoints[m_selectedEndpoint].path;
}
else
{
size_t pos = m_path.find(':');
string suffix = (pos == std::string::npos) ? "" : m_path.substr(pos);
m_path = m_endpoints[m_selectedEndpoint].path + suffix;
}
}

void AddInstrumentDialog::UpdateCombos()
{
// Update transoport list according to selected driver an connection string according to transport
string driver = m_drivers[m_selectedDriver];
auto supportedModels = SCPIInstrument::GetSupportedModels(driver);
m_endpoints.clear();
m_endpointNames.clear();
if(!supportedModels.empty())
{
m_models.clear();
Expand Down Expand Up @@ -315,13 +346,19 @@ void AddInstrumentDialog::UpdateCombos()
for(auto transport : selectedModel.supportedTransports)
{
string transportName = to_string(transport.transportType);
// Prepare transport type for default value
if(transportIndex == 0) m_selectedTransportType = transport.transportType;
if(m_supportedTransports.find(transportName) != m_supportedTransports.end())
{
m_transports.push_back(transportName);
if(transportIndex == m_selectedTransport && !m_pathEdited)
if(transportIndex == m_selectedTransport)
{
m_path = transport.connectionString;
m_defaultPath = m_path;
m_selectedTransportType = transport.transportType;
if(!m_pathEdited)
{
m_path = transport.connectionString;
m_defaultPath = m_path;
}
}
transportIndex++;
}
Expand All @@ -332,6 +369,25 @@ void AddInstrumentDialog::UpdateCombos()
if(!m_pathEdited)
m_path = "";
}
// Update endpoint list
auto endpoints = SCPITransport::EnumEndpoints(m_transports[m_selectedTransport]);
int endpointIndex = 0;
for(auto endpoint : endpoints)
{
m_endpoints.push_back(endpoint);
m_endpointNames.push_back(endpoint.path + " ("+ endpoint.description +")");
if(m_selectedTransportType == SCPITransportType::TRANSPORT_HID && (endpoint.path.rfind(m_path) == 0))
{ // Special handling for HID : select the endpoint matching the path provided by the driver
m_selectedEndpoint = endpointIndex;
}
endpointIndex++;
}
if(m_selectedEndpoint >= (int)m_endpoints.size())
{
m_selectedEndpoint = 0;
}
if(m_endpoints.size()>0)
UpdatePath();
}
else
{ // Supported transports not provided => add all transports
Expand Down
7 changes: 7 additions & 0 deletions src/ngscopeclient/AddInstrumentDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AddInstrumentDialog : public Dialog
virtual bool DoConnect(SCPITransport* transport);

void UpdateCombos();

void UpdatePath();

//GUI widget values
std::string m_nickname;
std::string m_originalNickname;
Expand All @@ -69,7 +72,11 @@ class AddInstrumentDialog : public Dialog
int m_selectedDriver;
std::vector<std::string> m_drivers;
int m_selectedTransport;
SCPITransportType m_selectedTransportType;
std::vector<std::string> m_transports;
int m_selectedEndpoint;
std::vector<TransportEndpoint> m_endpoints;
std::vector<std::string> m_endpointNames;
int m_selectedModel;
std::vector<std::string> m_models;
std::unordered_set<std::string> m_supportedTransports;
Expand Down
Loading