Skip to content

Commit

Permalink
Fixed broken FlushConfigCache() toolbar item
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Nov 25, 2023
1 parent 8527d7d commit 57f151d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 1 files
+17 −17 scopehal/RigolOscilloscope.h
45 changes: 36 additions & 9 deletions src/ngscopeclient/FilterGraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ FilterGraphEditor::FilterGraphEditor(Session& session, MainWindow* parent)
m_parent->GetTextureManager()->LoadTexture("input-sma", FindDataFile("icons/filters/input-sma.png"));

//DEBUG: make a group
/*
auto group = make_shared<FilterGraphGroup>();
auto id = GetID(group);
group->m_name = string("Group ") + to_string((intptr_t)id.AsPointer());
m_groups.emplace(group, id);
*/
}

FilterGraphEditor::~FilterGraphEditor()
Expand Down Expand Up @@ -265,10 +267,13 @@ bool FilterGraphEditor::DoRender()
HandleNodeProperties();
HandleBackgroundContextMenu();

ax::NodeEditor::End();

//Look for and avoid overlaps
//Must be after End() call which draws node boundaries, so everything is consistent.
//If we don't do that, node content and frames can get one frame out of sync
HandleOverlaps();

ax::NodeEditor::End();
ax::NodeEditor::SetCurrentEditor(nullptr);

//If any filters were reconfigured, dispatch events accordingly
Expand Down Expand Up @@ -416,24 +421,25 @@ void FilterGraphEditor::OutputPortTooltip(StreamDescriptor stream)
*/
void FilterGraphEditor::HandleOverlaps()
{
//Early out: if left mouse button is down we are probably dragging an item
//Do nothing
if(ImGui::IsMouseDown(ImGuiMouseButton_Left))
return;

//Get all of the node IDs
int nnodes = ax::NodeEditor::GetNodeCount();
vector<ax::NodeEditor::NodeId> nodes;
nodes.resize(nnodes);
ax::NodeEditor::GetOrderedNodeIds(&nodes[0], nnodes);

LogDebug("FilterGraphEditor::HandleOverlaps (%d nodes)\n", nnodes);
LogIndenter li;

//Loop over all nodes and find potential collisions
for(int i=0; i<nnodes; i++)
{
auto nodeA = nodes[i];
auto posA = ax::NodeEditor::GetNodePosition(nodeA);
auto sizeA = ax::NodeEditor::GetNodeSize(nodeA);

bool groupA = m_groups.HasEntry(nodeA);
bool selA = ax::NodeEditor::IsNodeSelected(nodeA);

for(int j=0; j<nnodes; j++)
{
//Don't check for self intersection
Expand All @@ -444,12 +450,33 @@ void FilterGraphEditor::HandleOverlaps()
auto posB = ax::NodeEditor::GetNodePosition(nodeB);
auto sizeB = ax::NodeEditor::GetNodeSize(nodeB);

//Groups are allowed to overlap non-group nodes - but not each other
bool groupA = m_groups.HasEntry(nodeA);
bool groupB = m_groups.HasEntry(nodeB);
if( (groupA && !groupB) || (!groupA && groupB) )
bool selB = ax::NodeEditor::IsNodeSelected(nodeB);

//If node B is selected, don't move it (but it can push other stuff)
if(selB)
continue;

//Check for node-group collisions
//Node-node is normal code path, group-group also repels
if( (groupA && !groupB) || (!groupA && groupB) )
{
//If neither is selected, don't repel (once a node is in a group, it should stay there)
if(!selA && !selB)
continue;

LogDebug("potential node-group repel\n");

/*
//If dragging a group, it should push away nodes.
//But nodes can be dragged into groups
if(groupA && IsNodeSelected(nodeA))
continue;
if(groupB && IsNodeSelected(nodeB))
continue;
*/
}

//If no overlap, no action required
if(!RectIntersect(posA, sizeA, posB, sizeB))
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ void MainWindow::ToolbarButtons()
//Refresh scope settings
ImGui::SameLine();
if(ImGui::ImageButton("refresh-settings", GetTexture("refresh-settings"), buttonsize))
LogDebug("refresh settings\n");
m_session.FlushConfigCache();
Dialog::Tooltip(
"Flush PC-side cached instrument state and reload configuration from the instrument.\n\n"
"This will cause a brief slowdown of the application, but can be used to re-sync when\n"
Expand Down
10 changes: 10 additions & 0 deletions src/ngscopeclient/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ void Session::ClearBackgroundThreads()
m_shuttingDown = false;
}

void Session::FlushConfigCache()
{
LogTrace("Flushing cache\n");
LogIndenter li;

lock_guard<mutex> lock(m_scopeMutex);
for(auto scope : m_oscilloscopes)
scope->FlushConfigCache();
}

/**
@brief Clears all session state and returns the object to an empty state
*/
Expand Down
1 change: 1 addition & 0 deletions src/ngscopeclient/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class Session
void RefreshAllFiltersNonblocking();
void RefreshDirtyFiltersNonblocking();
bool RefreshDirtyFilters();
void FlushConfigCache();

void MarkChannelDirty(InstrumentChannel* chan);

Expand Down

0 comments on commit 57f151d

Please sign in to comment.