Add valve open/close logic
This commit is contained in:
@@ -4,6 +4,9 @@ using System.Windows.Media;
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public class PamhagenGraph : Graph {
|
||||
|
||||
private readonly List<Path> _selectedPaths = [];
|
||||
public IEnumerable<Path> SelectedPaths => _selectedPaths;
|
||||
|
||||
public readonly Trough MW1;
|
||||
public readonly Trough MW2;
|
||||
|
||||
@@ -347,7 +350,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
|
||||
protected static Valve CreateValve(int n, double x, double y) {
|
||||
return new($"V{n}", x, y, () => App.Plant?.IsValveOpen(4) ?? false, () => App.Plant?.WantValveOpen(4) ?? false);
|
||||
return new(n, x, y, () => App.Plant?.IsValveOpen(4) ?? false, () => App.Plant?.WantValveOpen(4) ?? false);
|
||||
}
|
||||
|
||||
protected static Tank CreateTank(int n, double x, double y, int capacity) {
|
||||
@@ -377,5 +380,49 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
TraverseSubgraph(o, visited, edgeAction, valveAction);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPath(Path path) {
|
||||
_selectedPaths.Add(path);
|
||||
UpdateValvesAdjacientToPath(path, true);
|
||||
if (App.Plant is PamhagenPlant plant) {
|
||||
foreach (var (edge, _) in path.Hops) {
|
||||
if (edge is Valve v) {
|
||||
plant.OpenV(v.Nr);
|
||||
}
|
||||
}
|
||||
plant.CommitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovePath(Path path) {
|
||||
_selectedPaths.Remove(path);
|
||||
UpdateValvesAdjacientToPath(path, false);
|
||||
foreach (var p in _selectedPaths) UpdateValvesAdjacientToPath(p, true);
|
||||
if (App.Plant is PamhagenPlant plant) {
|
||||
foreach (var (edge, _) in path.Hops) {
|
||||
if (edge is Valve v) {
|
||||
plant.CloseV(v.Nr);
|
||||
}
|
||||
}
|
||||
plant.CommitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateValvesAdjacientToPath(Path path, bool locked) {
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
TraverseSubgraph(node, valveAction: (v) => v.IsLocked = locked);
|
||||
}
|
||||
}
|
||||
|
||||
public void ColorPipesAdjacientToPath(Path path, Brush? color1, Brush? color2) {
|
||||
var color = color1;
|
||||
HashSet<IEdge> visited = [];
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
edge.Highlight = color1;
|
||||
visited.Add(edge);
|
||||
if (node is Pump) color = color2;
|
||||
TraverseSubgraph(node, visited, edgeAction: (e) => e.Highlight = color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
public string Label { get; set; }
|
||||
public int Nr { get; set; }
|
||||
public string Label => $"V{Nr}";
|
||||
public Brush? Highlight { get; set; }
|
||||
|
||||
public bool IsLocked { get; set; }
|
||||
@@ -25,10 +26,10 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
private Shape? _circle;
|
||||
private TextBlock? _text;
|
||||
|
||||
public Valve(string label, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
|
||||
public Valve(int nr, double x, double y, Func<bool> cbOpen, Func<bool> cbWant) {
|
||||
CenterX = x;
|
||||
CenterY = y;
|
||||
Label = label;
|
||||
Nr = nr;
|
||||
CallbackIsOpen = cbOpen;
|
||||
CallbackWantOpen = cbWant;
|
||||
Inputs = new HashSet<IEdge>();
|
||||
@@ -61,7 +62,12 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public bool Update(double x, double y, bool down) {
|
||||
var hover = Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
|
||||
_circle?.Fill = IsLocked ? Brushes.Orange : Highlight ?? (hover ? Brushes.LightGray : Brushes.DarkGray);
|
||||
_circle?.Fill =
|
||||
IsLocked && !WantOpen && !IsOpen ? Brushes.Orange :
|
||||
IsLocked && !WantOpen && IsOpen ? Brushes.Red :
|
||||
IsLocked && WantOpen && !IsOpen ? Brushes.Yellow :
|
||||
IsLocked && WantOpen && IsOpen ? Brushes.Green :
|
||||
Highlight ?? (hover ? Brushes.LightGray : Brushes.DarkGray);
|
||||
return hover;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user