From b0d2bf4bdcd2f16324317110c8e45194faf04deb Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Tue, 14 Jul 2026 12:43:39 +0200 Subject: [PATCH] Fix ColorSubgraph() --- PamhagenSysCtrl/Helpers/PamhagenGraph.cs | 22 ++++++++++++++++++ .../Windows/PlantSchemeWindow.xaml.cs | 23 ++----------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/PamhagenSysCtrl/Helpers/PamhagenGraph.cs b/PamhagenSysCtrl/Helpers/PamhagenGraph.cs index 189a633..7fd48f4 100644 --- a/PamhagenSysCtrl/Helpers/PamhagenGraph.cs +++ b/PamhagenSysCtrl/Helpers/PamhagenGraph.cs @@ -1,4 +1,5 @@ using PamhagenSysCtrl.Helpers.Pipeline; +using System.Windows.Media; namespace PamhagenSysCtrl.Helpers { public class PamhagenGraph : Graph { @@ -337,5 +338,26 @@ namespace PamhagenSysCtrl.Helpers { protected static Tank CreateTank(int n, double x, double y, int capacity) { return new($"Tank {n}", x, y, capacity, () => App.Plant?.TankFillLevels[n - 1] != FillState.Empty, () => App.Plant?.TankFillLevels[n - 1] != FillState.Full); } + + public void ColorSubgraph(INode start, Brush color, Action? valveAction = null) { + if (start is Valve v) { + valveAction?.Invoke(v); + return; + } else if (start is ISink || start is Pump) { + return; + } + foreach (var edge in start.Inputs) { + if (edge.Highlight != null) continue; + var o = edge.IsTwoWay && edge.Start == start ? edge.End : edge.Start; + edge.Highlight = color; + ColorSubgraph(o, color, valveAction); + } + foreach (var edge in start.Outputs) { + if (edge.Highlight != null) continue; + var o = edge.IsTwoWay && edge.End == start ? edge.Start : edge.End; + edge.Highlight = color; + ColorSubgraph(o, color, valveAction); + } + } } } diff --git a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs index 6c8e021..7479f7e 100644 --- a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs +++ b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs @@ -64,7 +64,7 @@ namespace PamhagenSysCtrl.Windows { foreach (var (edge, node) in p.Hops) { edge.Highlight = Brushes.Green; if (node is Pump) c = Brushes.Orange; - ColorSubgraph(node, c, (v) => v.IsLocked = true); + Graph.ColorSubgraph(node, c, (v) => v.IsLocked = true); } } var hover = Graph.Update(pos.X, pos.Y, down); @@ -75,7 +75,7 @@ namespace PamhagenSysCtrl.Windows { foreach (var (edge, node) in path.Value.Hops) { edge.Highlight = Brushes.Green; if (node is Pump) c = Brushes.Orange; - ColorSubgraph(node, c); + Graph.ColorSubgraph(node, c); } } Graph.Update(pos.X, pos.Y, down); @@ -83,25 +83,6 @@ namespace PamhagenSysCtrl.Windows { return hover; } - private void ColorSubgraph(INode start, Brush color, Action? valveAction = null) { - if (start is Valve v) { - valveAction?.Invoke(v); - return; - } else if (start is ISink || start is Pump) { - return; - } - foreach (var edge in start.Inputs) { - if (edge.Highlight != null) continue; - edge.Highlight = color; - ColorSubgraph(edge.Start, color, valveAction); - } - foreach (var edge in start.Outputs) { - if (edge.Highlight != null) continue; - edge.Highlight = color; - ColorSubgraph(edge.End, color, valveAction); - } - } - public void OnUpdate(object? sender, PlantEventArgs evt) { if (sender is not PamhagenPlant plant) return;