-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
330 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Cavern.Filters.Utilities { | ||
/// <summary> | ||
/// Special functions for handling <see cref="FilterGraphNode"/>s. | ||
/// </summary> | ||
public static class FilterGraphNodeUtils { | ||
/// <summary> | ||
/// Get all nodes in a filter graph knowing the root nodes. | ||
/// </summary> | ||
public static HashSet<FilterGraphNode> MapGraph(IEnumerable<FilterGraphNode> rootNodes) { | ||
HashSet<FilterGraphNode> visited = new HashSet<FilterGraphNode>(); | ||
Queue<FilterGraphNode> queue = new Queue<FilterGraphNode>(rootNodes); | ||
while (queue.Count > 0) { | ||
FilterGraphNode currentNode = queue.Dequeue(); | ||
if (visited.Contains(currentNode)) { | ||
continue; | ||
} | ||
|
||
visited.Add(currentNode); | ||
foreach (FilterGraphNode child in currentNode.Children) { | ||
queue.Enqueue(child); | ||
} | ||
} | ||
|
||
return visited; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Cavern.Utilities { | ||
/// <summary> | ||
/// Advanced functions for handling tuples. | ||
/// </summary> | ||
public static class TupleUtils { | ||
/// <summary> | ||
/// From an array of tuples, get only the second "column". | ||
/// </summary> | ||
public static T2[] GetItem2s<T1, T2>(this (T1, T2)[] items) { | ||
T2[] result = new T2[items.Length]; | ||
for (int i = 0; i < items.Length; i++) { | ||
result[i] = items[i].Item2; | ||
} | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Microsoft.Msagl.Drawing; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows; | ||
|
||
using Cavern.Filters.Utilities; | ||
using Cavern.Format.ConfigurationFile; | ||
|
||
using Color = Microsoft.Msagl.Drawing.Color; | ||
|
||
namespace FilterStudio.Graphs { | ||
/// <summary> | ||
/// The layout on which the steps of the filter pipeline can be selected. Each step has all input and output channels, | ||
/// they're just parts cut off the whole filter pipeline for better presentation. Think of them as groups on the full filter graph. | ||
/// The main feature this makes possible is having preset pipeline steps that can be added later with different configurations, | ||
/// such as crossovers. | ||
/// </summary> | ||
public class PipelineEditor : ManipulatableGraph { | ||
/// <summary> | ||
/// Pass the root nodes of the user's selected split. | ||
/// </summary> | ||
public event Action<FilterGraphNode[]> OnSplitChanged; | ||
|
||
/// <summary> | ||
/// Overrides the background color of the graph. | ||
/// </summary> | ||
public Color background; | ||
|
||
/// <summary> | ||
/// Source of language strings. | ||
/// </summary> | ||
public ResourceDictionary language; | ||
|
||
/// <summary> | ||
/// The <see cref="ConfigurationFile"/> of which its split points will be presented. | ||
/// </summary> | ||
public ConfigurationFile Source { | ||
get => source; | ||
set { | ||
source = value; | ||
RecreateGraph(); | ||
SelectNode(source.SplitPoints[0].roots.GetHashCode().ToString()); | ||
OnSplitChanged?.Invoke(source.SplitPoints[0].roots); | ||
} | ||
} | ||
ConfigurationFile source; | ||
|
||
/// <summary> | ||
/// The layout on which the steps of the filter pipeline can be selected. | ||
/// </summary> | ||
public PipelineEditor() { | ||
OnLeftClick += LeftClick; | ||
} | ||
|
||
/// <summary> | ||
/// When the <see cref="Source"/> has changed, display its split points. | ||
/// </summary> | ||
void RecreateGraph() { | ||
IReadOnlyList<(string name, FilterGraphNode[] roots)> splits = source.SplitPoints; | ||
Graph graph = new Graph(); | ||
graph.Attr.BackgroundColor = background; | ||
graph.Attr.LayerDirection = LayerDirection.LR; | ||
|
||
string lastUid = "a"; | ||
graph.AddNode(new StyledNode(lastUid, (string)language["NInpu"])); | ||
for (int i = 0, c = splits.Count; i < c; i++) { | ||
string newUid = splits[i].roots.GetHashCode().ToString(); | ||
graph.AddNode(new StyledNode(newUid, splits[i].name)); | ||
new StyledEdge(graph, lastUid, newUid); | ||
lastUid = newUid; | ||
} | ||
graph.AddNode(new StyledNode("b", (string)language["NOutp"])); | ||
new StyledEdge(graph, lastUid, "b"); | ||
Graph = graph; | ||
} | ||
|
||
/// <summary> | ||
/// Open the split the user selects. | ||
/// </summary> | ||
void LeftClick(object element) { | ||
if (element is not StyledNode node) { | ||
return; | ||
} | ||
|
||
if (int.TryParse(node.Id, out int rootCode)) { | ||
(string _, FilterGraphNode[] roots) = source.SplitPoints.FirstOrDefault(x => x.roots.GetHashCode() == rootCode); | ||
OnSplitChanged?.Invoke(roots); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.