ngscopeclient v0.3
Loading...
Searching...
No Matches
FilterGraphEditor.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef FilterGraphEditor_h
36#define FilterGraphEditor_h
37
38#include "Dialog.h"
39#include "Session.h"
40#include "Bijection.h"
43
44#include <imgui_node_editor.h>
45#include <imgui_node_editor_internal.h>
46
47#include <typeinfo>
48#include <typeindex>
49
50template<class T>
51class lessID
52{
53public:
54 bool operator()(const T& a, const T& b) const
55 { return a.AsPointer() < b.AsPointer(); }
56};
57
59{
60public:
61 bool operator()(
62 const std::pair<ax::NodeEditor::PinId, ax::NodeEditor::PinId>& a,
63 const std::pair<ax::NodeEditor::PinId, ax::NodeEditor::PinId>& b) const
64 {
65 auto fpa = a.first.AsPointer();
66 auto fpb = b.first.AsPointer();
67 if(fpa < fpb)
68 return true;
69 else if(fpa > fpb)
70 return false;
71 else
72 return a.second.AsPointer() < b.second.AsPointer();
73 }
74};
75
77
79{
80public:
81
83
85 std::string m_name;
86
88 ax::NodeEditor::NodeId m_id;
89
91 ax::NodeEditor::NodeId m_outputId;
92
94 ax::NodeEditor::NodeId m_inputId;
95
97 std::set<ax::NodeEditor::NodeId, lessID<ax::NodeEditor::NodeId> > m_children;
98
100 std::set<ax::NodeEditor::PinId, lessID<ax::NodeEditor::PinId> > m_childSourcePins;
101
103 std::set<ax::NodeEditor::PinId, lessID<ax::NodeEditor::PinId> > m_childSinkPins;
104
106 Bijection<
108 ax::NodeEditor::PinId,
109 std::less<StreamDescriptor>,
111
113 Bijection<
115 ax::NodeEditor::PinId,
116 std::less<StreamDescriptor>,
118
120 Bijection<
122 ax::NodeEditor::LinkId,
123 std::less<StreamDescriptor>,
125
127 Bijection<
128 std::pair<FlowGraphNode*, int>,
129 ax::NodeEditor::PinId,
130 std::less< std::pair<FlowGraphNode*, int> >,
132
134 Bijection<
135 std::pair<FlowGraphNode*, int>,
136 ax::NodeEditor::PinId,
137 std::less< std::pair<FlowGraphNode*, int> >,
139
141 Bijection<
142 std::pair<FlowGraphNode*, int>,
143 ax::NodeEditor::LinkId,
144 std::less< std::pair<FlowGraphNode*, int> >,
146
147 void RefreshChildren();
148 void RefreshLinks();
150
151protected:
152 FilterGraphEditor& m_parent;
153};
154
156{
157public:
159 virtual ~FilterGraphEditor();
160
161 virtual bool Render();
162 virtual bool DoRender();
163
164 std::map<uintptr_t, std::string> GetGroupIDs();
165
167
168 FilterGraphErrorWindow& GetErrorWindow()
169 { return m_errorWindow; }
170
171protected:
172
173 friend class FilterGraphGroup;
174
175 std::map<std::shared_ptr<Instrument>, std::vector<InstrumentChannel*> > GetAllVisibleChannels();
176 std::vector<FlowGraphNode*> GetAllNodes();
177
178 void RefreshGroupPorts();
179
180 ax::NodeEditor::PinId CanonicalizePin(ax::NodeEditor::PinId port);
181
182 void InputPortTooltip(FlowGraphNode* node, size_t idx);
184 void DoNodeForGroup(std::shared_ptr<FilterGraphGroup> group);
185 void DoInternalLinksForGroup(std::shared_ptr<FilterGraphGroup> group);
186 void DoNodeForGroupOutputs(std::shared_ptr<FilterGraphGroup> group);
187 void DoNodeForGroupInputs(std::shared_ptr<FilterGraphGroup> group);
188 void DoNodeForChannel(
190 std::shared_ptr<Instrument> inst,
191 bool multiInst,
195 void HandleDoubleClicks();
201 void DoAddMenu();
202
203 void HandleOverlaps();
205 const std::vector<ax::NodeEditor::NodeId>& nodes,
206 const std::vector<bool>& isgroup,
207 const std::vector<bool>& dragging,
208 const std::vector<bool>& nocollide,
209 const std::vector<ImVec2>& positions,
210 const std::vector<ImVec2>& sizes,
211 std::vector<ImVec2>& forces);
212 void ApplyNodeForces(
213 const std::vector<ax::NodeEditor::NodeId>& nodes,
214 const std::vector<bool>& isgroup,
215 const std::vector<bool>& dragging,
216 const std::vector<ImVec2>& positions,
217 std::vector<ImVec2>& forces);
218
219 void SetCanvasManagedDPI();
220 void SetImGuiManagedDPI();
221
223
225
227 void FilterSubmenu(StreamDescriptor src, const std::string& name, Filter::Category cat);
228 void CreateChannelMenu();
229
231 ax::NodeEditor::Config m_config;
232
234 ax::NodeEditor::EditorContext* m_context;
235
237 Bijection<
239 ax::NodeEditor::PinId,
240 std::less<StreamDescriptor>,
242
244 Bijection<
245 std::pair<FlowGraphNode*, int>,
246 ax::NodeEditor::PinId,
247 std::less< std::pair<FlowGraphNode*, int> >,
249
251 Bijection<
252 std::pair<ax::NodeEditor::PinId, ax::NodeEditor::PinId>,
253 ax::NodeEditor::LinkId,
256
259
262
263 ax::NodeEditor::NodeId GetID(FlowGraphNode* node);
264
265 ax::NodeEditor::NodeId GetID(InstrumentChannel* chan)
266 { return m_session->m_idtable.emplace(chan); }
267
268 ax::NodeEditor::NodeId GetID(Trigger* trig)
269 { return m_session->m_idtable.emplace(trig); }
270
271 ax::NodeEditor::NodeId GetID(std::shared_ptr<FilterGraphGroup> group)
272 { return m_session->m_idtable.emplace(group.get()); }
273
275 ax::NodeEditor::PinId GetID(StreamDescriptor stream);
276 ax::NodeEditor::PinId GetID(std::pair<FlowGraphNode*, size_t> input);
277 ax::NodeEditor::LinkId GetID(std::pair<ax::NodeEditor::PinId, ax::NodeEditor::PinId> link);
278
280 ax::NodeEditor::PinId GetSinkPinForLink(StreamDescriptor source, std::pair<FlowGraphNode*, int> sink);
281
284
286 std::map<
287 ax::NodeEditor::NodeId,
288 std::shared_ptr<EmbeddableDialog>,
290
292 ax::NodeEditor::NodeId m_selectedProperties;
293
294 ImVec2 m_createMousePos;
295
297 std::pair<FlowGraphNode*, int> m_createInput;
298
300 Bijection<
301 std::shared_ptr<FilterGraphGroup>,
302 ax::NodeEditor::NodeId,
303 std::less< std::shared_ptr<FilterGraphGroup> >,
306
307 //DEBUG: forces for display
308 std::map<
309 ax::NodeEditor::NodeId,
310 ImVec2,
312 > m_nodeForces;
313
314 //DEBUG: render vector for force
315 void RenderForceVector(ImDrawList* list, ImVec2 pos, ImVec2 size, ImVec2 vec);
316
318 // Serialization
319
320 static bool SaveSettingsCallback(
321 const char* data,
322 size_t size,
323 ax::NodeEditor::SaveReasonFlags flags,
324 void* pThis);
325
326 static size_t LoadSettingsCallback(char* data, void* pThis);
327
328 //Error message window
329 FilterGraphErrorWindow m_errorWindow;
330};
331
332#endif
Declaration of Bijection.
Declaration of Dialog.
Declaration of FilterGraphErrorWindow.
Declaration of Session.
Definition AcceleratorBuffer.h:204
A strict one-to-one mapping from objects of type T1 to type T2 (which must be different types).
Definition Bijection.h:48
Generic dialog box or other popup window.
Definition Dialog.h:46
Session * m_session
optional reference to session
Definition Dialog.h:121
Definition EmbeddableDialog.h:41
Definition FilterGraphEditor.h:156
void DoNodeForChannel(InstrumentChannel *channel, std::shared_ptr< Instrument > inst, bool multiInst, int64_t runtime)
Make a node for a single channel, of any type.
Definition FilterGraphEditor.cpp:2249
void InputPortTooltip(FlowGraphNode *node, size_t idx)
Display tooltips when mousing over an input port.
Definition FilterGraphEditor.cpp:1110
void HandleBackgroundContextMenu(bool windowHovered)
Show add menu when background is right clicked.
Definition FilterGraphEditor.cpp:2839
ax::NodeEditor::Config m_config
Graph editor setup.
Definition FilterGraphEditor.h:231
ax::NodeEditor::EditorContext * m_context
Context containing current state of the graph editor.
Definition FilterGraphEditor.h:234
Bijection< std::shared_ptr< FilterGraphGroup >, ax::NodeEditor::NodeId, std::less< std::shared_ptr< FilterGraphGroup > >, lessID< ax::NodeEditor::NodeId > > m_groups
Groups.
Definition FilterGraphEditor.h:305
void CreateChannelMenu()
Runs the "add input" menu.
Definition FilterGraphEditor.cpp:1773
void HandleDeletionRequests(Filter *&fReconfigure)
Handle requests to delete a link or node.
Definition FilterGraphEditor.cpp:1970
std::map< std::shared_ptr< Instrument >, std::vector< InstrumentChannel * > > GetAllVisibleChannels()
Get a list of all channels that we are displaying nodes for.
Definition FilterGraphEditor.cpp:256
void NodeIcon(InstrumentChannel *chan, ImVec2 iconpos, ImVec2 iconsize, ImDrawList *list)
Draws an icon showing the function of a node.
Definition FilterGraphEditor.cpp:2632
Bijection< std::pair< FlowGraphNode *, int >, ax::NodeEditor::PinId, std::less< std::pair< FlowGraphNode *, int > >, lessID< ax::NodeEditor::PinId > > m_inputIDMap
Map of (channel, input number) to input port IDs.
Definition FilterGraphEditor.h:248
virtual bool Render()
Renders the dialog and handles UI events.
Definition FilterGraphEditor.cpp:236
std::pair< FlowGraphNode *, int > m_createInput
Input we're considering hooking a new channel up to.
Definition FilterGraphEditor.h:297
void SetCanvasManagedDPI()
Use 1.0 as the DPI since the canvas scales independently.
Definition FilterGraphEditor.cpp:1726
ax::NodeEditor::NodeId GetID(FlowGraphNode *node)
Gets the ID for an arbitrary node.
Definition FilterGraphEditor.cpp:730
ax::NodeEditor::PinId CanonicalizePin(ax::NodeEditor::PinId port)
Gets the actual source/sink pin given a pin which might be a hierarchical port.
Definition FilterGraphEditor.cpp:1505
bool OnFilterDeleted(Filter *node)
Handle deletion requests for filters in particular.
Definition FilterGraphEditor.cpp:2100
uintptr_t AllocateID()
Allocate an ID, avoiding collisions with the session IDTable.
Definition FilterGraphEditor.cpp:2956
std::map< ax::NodeEditor::NodeId, std::shared_ptr< EmbeddableDialog >, lessID< ax::NodeEditor::NodeId > > m_propertiesDialogs
Properties dialogs for channels to be displayed inside nodes.
Definition FilterGraphEditor.h:289
void DoNodeForTrigger(Trigger *trig)
Make a node for a trigger.
Definition FilterGraphEditor.cpp:2159
void OutputPortTooltip(StreamDescriptor stream)
Display tooltips when mousing over an output port.
Definition FilterGraphEditor.cpp:1131
void ApplyNodeForces(const std::vector< ax::NodeEditor::NodeId > &nodes, const std::vector< bool > &isgroup, const std::vector< bool > &dragging, const std::vector< ImVec2 > &positions, std::vector< ImVec2 > &forces)
Once forces are calculated, actually move the nodes (unless being dragged)
Definition FilterGraphEditor.cpp:1324
virtual bool DoRender()
Renders the dialog and handles UI events.
Definition FilterGraphEditor.cpp:432
static bool IsBackEdge(FlowGraphNode *src, FlowGraphNode *dst)
Determine if a proposed edge in the filter graph is a back edge (one whose creation would lead to a c...
Definition FilterGraphEditor.cpp:1751
std::map< uintptr_t, std::string > GetGroupIDs()
Return a list of group IDs and names.
Definition FilterGraphEditor.cpp:3046
ax::NodeEditor::NodeId m_selectedProperties
Node whose properties we're currently interacting with.
Definition FilterGraphEditor.h:292
static size_t LoadSettingsCallback(char *data, void *pThis)
Definition FilterGraphEditor.cpp:3030
StreamDescriptor m_newFilterSourceStream
Source stream of the newly created filter.
Definition FilterGraphEditor.h:283
void DoAddMenu()
Implement the add menu.
Definition FilterGraphEditor.cpp:2863
void SetImGuiManagedDPI()
Use the ImGui viewport scale as the DPI scale.
Definition FilterGraphEditor.cpp:1736
uintptr_t m_nextID
Next link/port ID to be allocated.
Definition FilterGraphEditor.h:261
void ClearOldPropertiesDialogs()
Delete old properties dialogs for no-longer-extant nodes.
Definition FilterGraphEditor.cpp:1080
bool OnNodeDeleted(FlowGraphNode *node)
Handle node deletion requests.
Definition FilterGraphEditor.cpp:2075
void RefreshGroupPorts()
Figure out which source/sink ports are within each group.
Definition FilterGraphEditor.cpp:746
std::vector< FlowGraphNode * > GetAllNodes()
Get a list of all objects we're displaying nodes for (channels, filters, triggers,...
Definition FilterGraphEditor.cpp:337
void FilterSubmenu(StreamDescriptor src, const std::string &name, Filter::Category cat)
Run the submenu for a single filter category.
Definition FilterGraphEditor.cpp:1919
void FilterMenu(StreamDescriptor src)
Runs the "create filter" menu.
Definition FilterGraphEditor.cpp:1878
void CalculateNodeForces(const std::vector< ax::NodeEditor::NodeId > &nodes, const std::vector< bool > &isgroup, const std::vector< bool > &dragging, const std::vector< bool > &nocollide, const std::vector< ImVec2 > &positions, const std::vector< ImVec2 > &sizes, std::vector< ImVec2 > &forces)
Calculates the forces applied to each node in the graph based on interaction physics.
Definition FilterGraphEditor.cpp:1241
ax::NodeEditor::PinId GetSourcePinForLink(StreamDescriptor source, FlowGraphNode *sink)
Gets the source pin we should use for drawing a connection.
Definition FilterGraphEditor.cpp:375
Bijection< std::pair< ax::NodeEditor::PinId, ax::NodeEditor::PinId >, ax::NodeEditor::LinkId, lessIDPair, lessID< ax::NodeEditor::LinkId > > m_linkMap
Map of (ID, ID) to link IDs.
Definition FilterGraphEditor.h:255
bool HandleNodeProperties()
Open the properties window when a node is right clicked.
Definition FilterGraphEditor.cpp:2727
ax::NodeEditor::PinId GetSinkPinForLink(StreamDescriptor source, std::pair< FlowGraphNode *, int > sink)
Gets the sink pin we should use for drawing a connection.
Definition FilterGraphEditor.cpp:403
void DoInternalLinksForGroup(std::shared_ptr< FilterGraphGroup > group)
Handle links between nodes in a group and the hierarchical ports.
Definition FilterGraphEditor.cpp:1031
void HandleLinkCreationRequests(Filter *&fReconfigure)
Handle requests to create a new link.
Definition FilterGraphEditor.cpp:1536
Bijection< FlowGraphNode *, std::shared_ptr< FilterGraphGroup > > m_nodeGroupMap
Map of signal sources to the group the source node is in (if there is one)
Definition FilterGraphEditor.h:258
void HandleOverlaps()
Find nodes that are intersecting, and apply forces to resolve collisions.
Definition FilterGraphEditor.cpp:1416
void HandleDoubleClicks()
Opens a persistent properties window when a node is double clicked.
Definition FilterGraphEditor.cpp:2687
Bijection< StreamDescriptor, ax::NodeEditor::PinId, std::less< StreamDescriptor >, lessID< ax::NodeEditor::PinId > > m_streamIDMap
Map of streams to output port IDs.
Definition FilterGraphEditor.h:241
Definition FilterGraphErrorWindow.h:41
Definition FilterGraphEditor.h:79
void MoveBy(ImVec2 displacement)
Moves this node and all of its child nodes.
Definition FilterGraphEditor.cpp:184
Bijection< StreamDescriptor, ax::NodeEditor::PinId, std::less< StreamDescriptor >, lessID< ax::NodeEditor::PinId > > m_hierOutputMap
Map of streams to hierarchial output port IDs.
Definition FilterGraphEditor.h:110
void RefreshChildren()
Refreshes the list of child nodes within this node.
Definition FilterGraphEditor.cpp:65
ax::NodeEditor::NodeId m_id
ID of the group.
Definition FilterGraphEditor.h:88
ax::NodeEditor::NodeId m_inputId
ID of the dummy node for input ports.
Definition FilterGraphEditor.h:94
std::string m_name
Display name of the group.
Definition FilterGraphEditor.h:85
Bijection< std::pair< FlowGraphNode *, int >, ax::NodeEditor::PinId, std::less< std::pair< FlowGraphNode *, int > >, lessID< ax::NodeEditor::PinId > > m_hierInputMap
Map of streams to hierarchial input port IDs.
Definition FilterGraphEditor.h:131
std::set< ax::NodeEditor::PinId, lessID< ax::NodeEditor::PinId > > m_childSourcePins
List of output pins we contain on our child nodes.
Definition FilterGraphEditor.h:100
std::set< ax::NodeEditor::PinId, lessID< ax::NodeEditor::PinId > > m_childSinkPins
List of input pins we contain on our child nodes.
Definition FilterGraphEditor.h:103
void RefreshLinks()
Refreshes the list of links between this group and the outside world.
Definition FilterGraphEditor.cpp:90
Bijection< std::pair< FlowGraphNode *, int >, ax::NodeEditor::LinkId, std::less< std::pair< FlowGraphNode *, int > >, lessID< ax::NodeEditor::LinkId > > m_hierInputLinkMap
Map of streams to internal link IDs.
Definition FilterGraphEditor.h:145
Bijection< std::pair< FlowGraphNode *, int >, ax::NodeEditor::PinId, std::less< std::pair< FlowGraphNode *, int > >, lessID< ax::NodeEditor::PinId > > m_hierInputInternalMap
Map of streams to hierarchial input port internal-facing port IDs.
Definition FilterGraphEditor.h:138
ax::NodeEditor::NodeId m_outputId
ID of the dummy node for output ports.
Definition FilterGraphEditor.h:91
Bijection< StreamDescriptor, ax::NodeEditor::LinkId, std::less< StreamDescriptor >, lessID< ax::NodeEditor::LinkId > > m_hierOutputLinkMap
Map of streams to internal link IDs.
Definition FilterGraphEditor.h:124
Bijection< StreamDescriptor, ax::NodeEditor::PinId, std::less< StreamDescriptor >, lessID< ax::NodeEditor::PinId > > m_hierOutputInternalMap
Map of streams to hierarchial output port internal-facing port IDs.
Definition FilterGraphEditor.h:117
std::set< ax::NodeEditor::NodeId, lessID< ax::NodeEditor::NodeId > > m_children
List of nodes we contain (by ID)
Definition FilterGraphEditor.h:97
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition Filter.h:105
Category
Category the filter should be displayed under in the GUI.
Definition Filter.h:118
Abstract base class for a node in the signal flow graph.
Definition FlowGraphNode.h:81
uintptr_t emplace(SerializableObject *p)
Store a new object in the table.
Definition IDTable.h:80
A single channel of an instrument.
Definition InstrumentChannel.h:63
Top level application window.
Definition MainWindow.h:168
Definition SerializableObject.h:40
A Session stores all of the instrument configuration and other state the user has open.
Definition Session.h:126
IDTable m_idtable
ID mapping used for serialization.
Definition Session.h:364
Descriptor for a single stream coming off a channel.
Definition StreamDescriptor.h:47
Abstract base class for oscilloscope / logic analyzer trigger inputs.
Definition Trigger.h:46
Definition FilterGraphEditor.h:59
Definition FilterGraphEditor.h:52