Skip to content

Commit

Permalink
FilterGraphEditor: correctly maintain stable IDs when changing type o…
Browse files Browse the repository at this point in the history
…f a scope trigger
  • Loading branch information
azonenberg committed Aug 25, 2024
1 parent 1777264 commit 5f3f010
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib
Submodule lib updated 1 files
+13 −2 scopehal/Bijection.h
3 changes: 3 additions & 0 deletions src/ngscopeclient/EmbeddedTriggerPropertiesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class EmbeddedTriggerPropertiesDialog : public EmbeddableDialog

virtual bool DoRender();

std::shared_ptr<Oscilloscope> GetScope()
{ return m_scope; }

protected:
std::unique_ptr<TriggerPropertiesPage> m_page;

Expand Down
35 changes: 31 additions & 4 deletions src/ngscopeclient/FilterGraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ bool FilterGraphEditor::DoRender()
Filter* fReconfigure = nullptr;
HandleLinkCreationRequests(fReconfigure);
HandleLinkDeletionRequests(fReconfigure);
HandleNodeProperties();
bool triggerChanged = HandleNodeProperties();
HandleBackgroundContextMenu();

ax::NodeEditor::End();
Expand All @@ -695,7 +695,10 @@ bool FilterGraphEditor::DoRender()
//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();
//If we changed the type of a trigger, don't do this as we have stale metadata
//TODO: can we dynamically refresh m_nodeGroupMap and anything else impacted?
if(!triggerChanged)
HandleOverlaps();

ax::NodeEditor::SetCurrentEditor(nullptr);

Expand Down Expand Up @@ -2357,8 +2360,10 @@ void FilterGraphEditor::NodeIcon(InstrumentChannel* chan, ImVec2 pos, ImVec2 ico

/**
@brief Open the properties window when a node is right clicked
@return True if a node type changed (for now, only triggers)
*/
void FilterGraphEditor::HandleNodeProperties()
bool FilterGraphEditor::HandleNodeProperties()
{
//Look for context menu
ax::NodeEditor::NodeId id;
Expand Down Expand Up @@ -2421,13 +2426,33 @@ void FilterGraphEditor::HandleNodeProperties()
}
}

bool triggerChanged = false;

//Run the properties dialogs
ax::NodeEditor::Suspend();
if(ImGui::BeginPopup("Node Properties"))
{
auto dlg = m_propertiesDialogs[m_selectedProperties];
if(dlg)
dlg->RenderAsChild();
{
//Special handling for trigger properties dialog
auto prop = dynamic_pointer_cast<EmbeddedTriggerPropertiesDialog>(dlg);
if(prop)
{
auto scope = prop->GetScope();
auto oldTrigger = scope->GetTrigger();
dlg->RenderAsChild();
auto newTrigger = scope->GetTrigger();;

if(oldTrigger != newTrigger)
{
m_session.m_idtable.replace(oldTrigger, newTrigger);
triggerChanged = true;
}
}
else
dlg->RenderAsChild();
}
ImGui::EndPopup();
}
if(ImGui::BeginPopup("Group Properties"))
Expand All @@ -2440,6 +2465,8 @@ void FilterGraphEditor::HandleNodeProperties()
ImGui::EndPopup();
}
ax::NodeEditor::Resume();

return triggerChanged;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ngscopeclient/FilterGraphEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class FilterGraphEditor : public Dialog
void DoNodeForGroupInputs(std::shared_ptr<FilterGraphGroup> group);
void DoNodeForChannel(InstrumentChannel* channel, std::shared_ptr<Instrument> inst);
void DoNodeForTrigger(Trigger* trig);
void HandleNodeProperties();
bool HandleNodeProperties();
void HandleLinkCreationRequests(Filter*& fReconfigure);
void HandleLinkDeletionRequests(Filter*& fReconfigure);
void HandleBackgroundContextMenu();
Expand Down

0 comments on commit 5f3f010

Please sign in to comment.