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);
}
}
}
}