Fix ColorSubgraph()

This commit is contained in:
2026-07-14 12:43:39 +02:00
parent da257b3285
commit b0d2bf4bdc
2 changed files with 24 additions and 21 deletions
+22
View File
@@ -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<Valve>? 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);
}
}
}
}
@@ -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<Valve>? 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;