@@ -11,7 +11,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
|
||||
private const double _minMove = 50;
|
||||
|
||||
private readonly PamhagenGraph Graph;
|
||||
private static PamhagenGraph Graph => App.Plant!.Graph;
|
||||
|
||||
private Point? _lastMousePos;
|
||||
private bool _mouseDragging;
|
||||
@@ -50,26 +50,25 @@ namespace PamhagenSysCtrl.Windows {
|
||||
public PlantSchemeWindow() {
|
||||
InitializeComponent();
|
||||
Menu_Help_CheckForUpdates.IsEnabled = App.Config.UpdateUrl != null;
|
||||
Graph = new();
|
||||
Graph.Draw(SchemeCanvas, RoundedScale);
|
||||
FastSelectPaths = new Dictionary<Button, (ISource, Pump, ISink)> {
|
||||
[FastSelectButton_MW1_Press1] = (Graph.MW1, Graph.MP1, Graph.Press1),
|
||||
[FastSelectButton_MW2_Press1] = (Graph.MW2, Graph.MP2, Graph.Press1),
|
||||
[FastSelectButton_MW1_Press2] = (Graph.MW1, Graph.MP1, Graph.Press2),
|
||||
[FastSelectButton_MW2_Press2] = (Graph.MW2, Graph.MP2, Graph.Press2),
|
||||
[FastSelectButton_MW1_Tank1] = (Graph.MW1, Graph.MP1, Graph.Tank1),
|
||||
[FastSelectButton_MW2_Tank1] = (Graph.MW2, Graph.MP2, Graph.Tank1),
|
||||
[FastSelectButton_MW1_Tank2] = (Graph.MW1, Graph.MP1, Graph.Tank2),
|
||||
[FastSelectButton_MW2_Tank2] = (Graph.MW2, Graph.MP2, Graph.Tank2),
|
||||
[FastSelectButton_MW1_Tank3] = (Graph.MW1, Graph.MP1, Graph.Tank3),
|
||||
[FastSelectButton_MW2_Tank3] = (Graph.MW2, Graph.MP2, Graph.Tank3),
|
||||
[FastSelectButton_MW1_Tank4] = (Graph.MW1, Graph.MP1, Graph.Tank4),
|
||||
[FastSelectButton_MW2_Tank4] = (Graph.MW2, Graph.MP2, Graph.Tank4),
|
||||
[FastSelectButton_MW1_Tank5] = (Graph.MW1, Graph.MP1, Graph.Tank5),
|
||||
[FastSelectButton_MW2_Tank5] = (Graph.MW2, Graph.MP2, Graph.Tank5),
|
||||
[FastSelectButton_MW1_Tank1] = (Graph.MW1, Graph.MP1, Graph.Tank1),
|
||||
[FastSelectButton_MW2_Tank1] = (Graph.MW2, Graph.MP2, Graph.Tank1),
|
||||
[FastSelectButton_MW1_Tank2] = (Graph.MW1, Graph.MP1, Graph.Tank2),
|
||||
[FastSelectButton_MW2_Tank2] = (Graph.MW2, Graph.MP2, Graph.Tank2),
|
||||
[FastSelectButton_MW1_Tank3] = (Graph.MW1, Graph.MP1, Graph.Tank3),
|
||||
[FastSelectButton_MW2_Tank3] = (Graph.MW2, Graph.MP2, Graph.Tank3),
|
||||
[FastSelectButton_MW1_Tank4] = (Graph.MW1, Graph.MP1, Graph.Tank4),
|
||||
[FastSelectButton_MW2_Tank4] = (Graph.MW2, Graph.MP2, Graph.Tank4),
|
||||
[FastSelectButton_MW1_Tank5] = (Graph.MW1, Graph.MP1, Graph.Tank5),
|
||||
[FastSelectButton_MW2_Tank5] = (Graph.MW2, Graph.MP2, Graph.Tank5),
|
||||
};
|
||||
App.Plant?.Update += OnUpdate;
|
||||
InitializePaths();
|
||||
App.Plant?.InitializePaths();
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, EventArgs evt) {
|
||||
@@ -96,7 +95,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
Menu_Settings_OverridePathClearances.IsChecked = false;
|
||||
Menu_Settings_OverrideDryRunClearances.IsChecked = false;
|
||||
|
||||
InitializePaths();
|
||||
App.Plant?.InitializePaths();
|
||||
}
|
||||
OnUpdate(null, null);
|
||||
}
|
||||
@@ -211,19 +210,12 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs evt) {
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs? evt) {
|
||||
if (sender is not Button b || !FastSelectPaths.TryGetValue(b, out var val))
|
||||
return;
|
||||
|
||||
if (Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == val.Source, null) is Path p1) {
|
||||
Graph.RemovePath(p1);
|
||||
if (p1.Hops.Last().Node == val.Sink)
|
||||
return;
|
||||
}
|
||||
if (Graph.GetFreePath([val.Source, val.Sink]) is Path p2) {
|
||||
Graph.AddPath(p2);
|
||||
_lastSource = null;
|
||||
}
|
||||
App.Plant?.FastSelect(val.Source, val.Sink);
|
||||
OnUpdate(null, null);
|
||||
_lastSource = null;
|
||||
}
|
||||
|
||||
private void OnSizeChanged(object sender, SizeChangedEventArgs evt) {
|
||||
@@ -492,6 +484,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
SetFastSelectButton(b,
|
||||
paths.Any(p => p.Start == e.Source && p.Hops.Last().Node == e.Sink) ? (hoverPathDeactivate?.Start == e.Source && hoverPathDeactivate?.Hops.Last().Node == e.Sink) ? 2 : 1 : 0,
|
||||
e.Pump.IsActive || Graph.GetFreePath([e.Source, e.Sink], overrideStart: true) == null);
|
||||
|
||||
}
|
||||
|
||||
private ISet<INode> UpdateScheme(Point pos, bool down) {
|
||||
@@ -511,13 +504,12 @@ namespace PamhagenSysCtrl.Windows {
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Stop, App.Plant?.IsTroughAugerActive ?? false ? 0 : 2);
|
||||
SetFastSelectButton(FastSelectButton_MW1, App.Plant?.IsMW1Selected ?? false ? 1 : 0);
|
||||
SetFastSelectButton(FastSelectButton_MW2, App.Plant?.IsMW2Selected ?? false ? 1 : 0);
|
||||
|
||||
SetFastSelectButton(FastSelectButton_MP1_Forward, App.Plant?.MP1 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP1HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP1_Stop, App.Plant?.MP1 == MotorState.Halt ? 2 : 0);
|
||||
|
||||
SetFastSelectButton(FastSelectButton_MP2_Forward, App.Plant?.MP2 == MotorState.Forward ? 1 : 0, !(App.Plant?.MP2HasClearance ?? false));
|
||||
SetFastSelectButton(FastSelectButton_MP2_Stop, App.Plant?.MP2 == MotorState.Halt ? 2 : 0);
|
||||
foreach (var b in FastSelectPaths) {
|
||||
SetFastSelectButton(b.Key, 0, false);
|
||||
}
|
||||
|
||||
_hover = Graph.GetHover(pos.X, pos.Y, RoundedScale);
|
||||
var hoverButtons = FastSelectPaths.Where(b => b.Key.IsMouseOver).ToDictionary();
|
||||
@@ -586,8 +578,8 @@ namespace PamhagenSysCtrl.Windows {
|
||||
|
||||
var paths = Graph.SelectedPaths;
|
||||
if (HoveringPath is Path hp) paths = paths.Append(hp);
|
||||
foreach (var b in FastSelectPaths.Keys) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b);
|
||||
foreach (var b in FastSelectPaths) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b.Key);
|
||||
}
|
||||
|
||||
Graph.Update(_hover, down);
|
||||
@@ -603,32 +595,5 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
UpdateScheme(Mouse.GetPosition(SchemeCanvas), Mouse.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
public void InitializePaths() {
|
||||
var add = ReconstructSelectedPaths().ToList();
|
||||
var remove = Graph.SelectedPaths.ToList();
|
||||
foreach (var p in remove) Graph.RemovePath(p);
|
||||
for (int i = 1; i <= 57; i++) {
|
||||
App.Plant?.CloseV(i);
|
||||
}
|
||||
foreach (var p in add) {
|
||||
if (p.Hops.Any(h => h.Node is Valve v && v.IsLocked)) continue;
|
||||
Graph.AddPath(p);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Path> ReconstructSelectedPaths() {
|
||||
if (App.Plant is not PamhagenPlant p) yield break;
|
||||
var sources = Graph.Nodes.Where(n => n is ISource).ToList();
|
||||
var sinks = Graph.Nodes.Where(n => n is ISink).ToList();
|
||||
foreach (var src in sources) {
|
||||
var paths = new List<Path>();
|
||||
foreach (var sink in sinks) {
|
||||
paths.AddRange(Graph.GetPaths(src, sink, null, (n) => n is not ISink && (n is not Valve v || p.WantValveOpen(v.Nr))));
|
||||
}
|
||||
if (paths.Count == 1)
|
||||
yield return paths.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user