Skip to content

Commit d0699bf

Browse files
committed
Allow opening session files from command line args
1 parent bc30931 commit d0699bf

3 files changed

Lines changed: 86 additions & 3 deletions

File tree

src/ngscopeclient/MainWindow.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ void MainWindow::RenderUI()
755755
}
756756
}
757757

758-
//Handle error messages
758+
//Handle error messages and other blocking notifications
759+
RenderReconnectPopup();
759760
RenderErrorPopup();
760761
RenderLoadWarningPopup();
761762

@@ -1677,6 +1678,47 @@ void MainWindow::ShowErrorPopup(const string& title, const string& msg)
16771678
m_errorPopupMessage = msg;
16781679
}
16791680

1681+
/**
1682+
@brief Popup message when reconnecting to a session
1683+
*/
1684+
void MainWindow::RenderReconnectPopup()
1685+
{
1686+
const char* title = "Open Session";
1687+
1688+
if(!m_startupSession.empty())
1689+
ImGui::OpenPopup(title);
1690+
1691+
if(ImGui::BeginPopupModal(title, nullptr, ImGuiWindowFlags_AlwaysAutoResize))
1692+
{
1693+
ImGui::TextUnformatted("Do you want to reconnect to the lab instruments or load session data for offline analysis?\n");
1694+
ImGui::Separator();
1695+
1696+
if(ImGui::Button("Reconnect"))
1697+
{
1698+
DoOpenFile(m_startupSession, true);
1699+
m_startupSession = "";
1700+
ImGui::CloseCurrentPopup();
1701+
}
1702+
1703+
ImGui::SameLine();
1704+
if(ImGui::Button("Load Offline"))
1705+
{
1706+
DoOpenFile(m_startupSession, false);
1707+
m_startupSession = "";
1708+
ImGui::CloseCurrentPopup();
1709+
}
1710+
1711+
ImGui::SameLine();
1712+
if(ImGui::Button("Cancel"))
1713+
{
1714+
m_startupSession = "";
1715+
ImGui::CloseCurrentPopup();
1716+
}
1717+
1718+
ImGui::EndPopup();
1719+
}
1720+
}
1721+
16801722
/**
16811723
@brief Popup message when something big goes wrong
16821724
*/

src/ngscopeclient/MainWindow.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class MainWindow : public VulkanWindow
220220
std::map<uintptr_t, std::string> GetGraphEditorGroups()
221221
{ return m_graphEditorGroups; }
222222

223+
void SetStartupSession(const std::string& path)
224+
{ m_startupSession = path; }
225+
223226
protected:
224227
virtual void DoRender(vk::raii::CommandBuffer& cmdBuf);
225228

@@ -398,6 +401,9 @@ class MainWindow : public VulkanWindow
398401
///@brief Pending requests to display a channel in a waveform area (from CreateFilter())
399402
std::set< std::pair<OscilloscopeChannel*, WaveformArea*> > m_pendingChannelDisplayRequests;
400403

404+
///@brief Pending request to open a session
405+
std::string m_startupSession;
406+
401407
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
402408
// Session state
403409

@@ -506,6 +512,7 @@ class MainWindow : public VulkanWindow
506512
bool m_showingLoadWarnings;
507513
bool m_loadConfirmationChecked;
508514

515+
void RenderReconnectPopup();
509516
void RenderErrorPopup();
510517
void RenderLoadWarningPopup();
511518
public:

src/ngscopeclient/main.cpp

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ int main(int argc, char* argv[])
5353
//Global settings
5454
Severity console_verbosity = Severity::NOTICE;
5555

56+
string sessionToOpen;
57+
vector<string> instrumentConnectionStrings;
5658
for(int i=1; i<argc; i++)
5759
{
5860
string s(argv[i]);
@@ -61,8 +63,21 @@ int main(int argc, char* argv[])
6163
if(ParseLoggerArguments(i, argc, argv, console_verbosity))
6264
continue;
6365

64-
//TODO: other arguments
66+
//Other switch (unrecognized)
67+
else if(s.find("-") == 0)
68+
{
69+
//Don't know what it is
70+
fprintf(stderr, "Unrecognized argument \"%s\"\n", s.c_str());
71+
return 1;
72+
}
6573

74+
//If it ends in .scopesession assume it's a session file
75+
else if(s.find(".scopesession") != string::npos)
76+
sessionToOpen = s;
77+
78+
//Assume it's an instrument
79+
else
80+
instrumentConnectionStrings.push_back(s);
6681
}
6782

6883
//Set up logging to the GUI
@@ -105,6 +120,13 @@ int main(int argc, char* argv[])
105120
}
106121
#endif
107122

123+
//Can't load a session and reconnect to an instrument, has to be one or the other
124+
if( !sessionToOpen.empty() && !instrumentConnectionStrings.empty())
125+
{
126+
LogError("Cannot load a session and connect to an instrument simultaneously\n");
127+
return 1;
128+
}
129+
108130
//Complain if the OpenMP wait policy isn't set right
109131
const char* policy = getenv("OMP_WAIT_POLICY");
110132
#ifndef _WIN32
@@ -154,8 +176,20 @@ int main(int argc, char* argv[])
154176
shared_ptr<QueueHandle> queue(g_vkQueueManager->GetRenderQueue("g_mainWindow.render"));
155177
g_mainWindow = make_unique<MainWindow>(queue);
156178

157-
//Main event loop
158179
auto& session = g_mainWindow->GetSession();
180+
181+
//Load a session on startup if requested
182+
if(!sessionToOpen.empty())
183+
g_mainWindow->SetStartupSession(sessionToOpen);
184+
185+
//Initialize the session with the requested arguments
186+
//TODO: support connecting to things other than scopes
187+
//(this will make more sense when we unify our driver model)
188+
/*
189+
vector<string> instrumentConnectionStrings;
190+
*/
191+
192+
//Main event loop
159193
while(!glfwWindowShouldClose(g_mainWindow->GetWindow()))
160194
{
161195
//Check which event loop model to use

0 commit comments

Comments
 (0)