@@ -18,6 +18,17 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public readonly Pump P6;
|
||||
public readonly EncasedAuger Auger1;
|
||||
public readonly EncasedAuger Auger3;
|
||||
public readonly Press Press1;
|
||||
public readonly Press Press2;
|
||||
public readonly Tank Tank1;
|
||||
public readonly Tank Tank2;
|
||||
public readonly Tank Tank3;
|
||||
public readonly Tank Tank4;
|
||||
public readonly Tank Tank5;
|
||||
public readonly Tank Tank6;
|
||||
public readonly Tank Tank7;
|
||||
public readonly Tank Tank8;
|
||||
public readonly Tank Tank9;
|
||||
|
||||
public PamhagenGraph() {
|
||||
double mw2X = 180;
|
||||
@@ -180,37 +191,37 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xv23 = new PipeJoin(t1X + 15, ltg6Y);
|
||||
var v22 = CreateValve(22, t1X - 15, tValveY);
|
||||
var v23 = CreateValve(23, t1X + 15, tValveY);
|
||||
var t1 = CreateTank(1, t1X, tanksY, 35000);
|
||||
Tank1 = CreateTank(1, t1X, tanksY, 35000);
|
||||
CreatePipe(xv20, xv22, true, label: "Ltg. 7", labelOffsetX: 50);
|
||||
CreatePipe(xv21, xv23, true, label: "Ltg. 6", labelOffsetX: 20);
|
||||
CreatePipe(xv22, v22);
|
||||
CreatePipe(xv23, v23);
|
||||
CreateInlet(v22, t1);
|
||||
CreateInlet(v23, t1);
|
||||
CreateInlet(v22, Tank1);
|
||||
CreateInlet(v23, Tank1);
|
||||
|
||||
var xv24 = new PipeJoin(t2X - 15, ltg7Y);
|
||||
var xv25 = new PipeJoin(t2X + 15, ltg6Y);
|
||||
var v24 = CreateValve(24, t2X - 15, tValveY);
|
||||
var v25 = CreateValve(25, t2X + 15, tValveY);
|
||||
var t2 = CreateTank(2, t2X, tanksY, 35000);
|
||||
Tank2 = CreateTank(2, t2X, tanksY, 35000);
|
||||
CreatePipe(xv22, xv24);
|
||||
CreatePipe(xv23, xv25);
|
||||
CreatePipe(xv24, v24);
|
||||
CreatePipe(xv25, v25);
|
||||
CreateInlet(v24, t2);
|
||||
CreateInlet(v25, t2);
|
||||
CreateInlet(v24, Tank2);
|
||||
CreateInlet(v25, Tank2);
|
||||
|
||||
var xv26 = new PipeJoin(t3X - 15, ltg7Y);
|
||||
var xv27 = new PipeJoin(t3X + 15, ltg6Y);
|
||||
var v26 = CreateValve(26, t3X - 15, tValveY);
|
||||
var v27 = CreateValve(27, t3X + 15, tValveY);
|
||||
var t3 = CreateTank(3, t3X, tanksY, 35000);
|
||||
Tank3 = CreateTank(3, t3X, tanksY, 35000);
|
||||
CreatePipe(xv24, xv26);
|
||||
CreatePipe(xv25, xv27);
|
||||
CreatePipe(xv26, v26);
|
||||
CreatePipe(xv27, v27);
|
||||
CreateInlet(v26, t3);
|
||||
CreateInlet(v27, t3);
|
||||
CreateInlet(v26, Tank3);
|
||||
CreateInlet(v27, Tank3);
|
||||
|
||||
var v28 = CreateValve(28, (t3X + t4X) / 2, ltg7Y);
|
||||
var v29 = CreateValve(29, (t3X + t4X) / 2, ltg6Y);
|
||||
@@ -221,25 +232,25 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xv31 = new PipeJoin(t4X + 15, ltg6Y);
|
||||
var v30 = CreateValve(30, t4X - 15, tValveY);
|
||||
var v31 = CreateValve(31, t4X + 15, tValveY);
|
||||
var t4 = CreateTank(4, t4X, tanksY, 35000);
|
||||
Tank4 = CreateTank(4, t4X, tanksY, 35000);
|
||||
CreatePipe(v28, xv30);
|
||||
CreatePipe(v29, xv31);
|
||||
CreatePipe(xv30, v30);
|
||||
CreatePipe(xv31, v31);
|
||||
CreateInlet(v30, t4);
|
||||
CreateInlet(v31, t4);
|
||||
CreateInlet(v30, Tank4);
|
||||
CreateInlet(v31, Tank4);
|
||||
|
||||
var xv32 = new PipeJoin(t5X - 15, ltg7Y);
|
||||
var xv33 = new PipeJoin(t5X + 15, ltg6Y);
|
||||
var v32 = CreateValve(32, t5X - 15, tValveY);
|
||||
var v33 = CreateValve(33, t5X + 15, tValveY);
|
||||
var t5 = CreateTank(5, t5X, tanksY, 35000);
|
||||
Tank5 = CreateTank(5, t5X, tanksY, 35000);
|
||||
CreatePipe(xv30, xv32, label: "Ltg. 7", labelOffsetX: 30);
|
||||
CreatePipe(xv31, xv33, label: "Ltg. 6", labelOffsetX: 0);
|
||||
CreatePipe(xv32, v32);
|
||||
CreatePipe(xv33, v33);
|
||||
CreateInlet(v32, t5);
|
||||
CreateInlet(v33, t5);
|
||||
CreateInlet(v32, Tank5);
|
||||
CreateInlet(v33, Tank5);
|
||||
|
||||
var v34 = CreateValve(34, (t5X + t6X) / 2, ltg7Y);
|
||||
var v35 = CreateValve(35, (t5X + t6X) / 2, ltg6Y);
|
||||
@@ -250,58 +261,58 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xv37 = new PipeJoin(t6X - 15, ltg7Y);
|
||||
var v36 = CreateValve(36, t6X + 15, tValveY);
|
||||
var v37 = CreateValve(37, t6X - 15, tValveY);
|
||||
var t6 = CreateTank(6, t6X, tanksY, 35000);
|
||||
Tank6 = CreateTank(6, t6X, tanksY, 35000);
|
||||
CreatePipe(v34, xv37);
|
||||
CreatePipe(v35, xv36);
|
||||
CreatePipe(xv37, v37);
|
||||
CreatePipe(xv36, v36);
|
||||
CreateInlet(v36, t6);
|
||||
CreateInlet(v37, t6);
|
||||
CreateInlet(v36, Tank6);
|
||||
CreateInlet(v37, Tank6);
|
||||
|
||||
var xv38 = new PipeJoin(t7X + 15, ltg6Y);
|
||||
var xv39 = new PipeJoin(t7X - 15, ltg7Y);
|
||||
var v38 = CreateValve(38, t7X + 15, tValveY);
|
||||
var v39 = CreateValve(39, t7X - 15, tValveY);
|
||||
var t7 = CreateTank(7, t7X, tanksY, 35000);
|
||||
Tank7 = CreateTank(7, t7X, tanksY, 35000);
|
||||
CreatePipe(xv37, xv39);
|
||||
CreatePipe(xv36, xv38);
|
||||
CreatePipe(xv38, v38);
|
||||
CreatePipe(xv39, v39);
|
||||
CreateInlet(v38, t7);
|
||||
CreateInlet(v39, t7);
|
||||
CreateInlet(v38, Tank7);
|
||||
CreateInlet(v39, Tank7);
|
||||
|
||||
var xv40 = new PipeJoin(t8X + 15, ltg6Y);
|
||||
var xv41 = new PipeJoin(t8X - 15, ltg7Y);
|
||||
var v40 = CreateValve(40, t8X + 15, tValveY);
|
||||
var v41 = CreateValve(41, t8X - 15, tValveY);
|
||||
var t8 = CreateTank(8, t8X, tanksY, 35000);
|
||||
Tank8 = CreateTank(8, t8X, tanksY, 35000);
|
||||
CreatePipe(xv38, xv40, label: "Ltg. 6", labelOffsetX: 0);
|
||||
CreatePipe(xv39, xv41, label: "Ltg. 7", labelOffsetX: 30);
|
||||
CreatePipe(xv40, v40);
|
||||
CreatePipe(xv41, v41);
|
||||
CreateInlet(v40, t8);
|
||||
CreateInlet(v41, t8);
|
||||
CreateInlet(v40, Tank8);
|
||||
CreateInlet(v41, Tank8);
|
||||
|
||||
var v42 = CreateValve(42, t9X + 15, tValveY);
|
||||
var v43 = CreateValve(43, t9X - 15, tValveY);
|
||||
var t9 = CreateTank(9, t9X, tanksY, 35000);
|
||||
Tank9 = CreateTank(9, t9X, tanksY, 35000);
|
||||
CreatePipe(xv40, v42);
|
||||
CreatePipe(xv41, v43);
|
||||
CreateInlet(v42, t9);
|
||||
CreateInlet(v43, t9);
|
||||
CreateInlet(v42, Tank9);
|
||||
CreateInlet(v43, Tank9);
|
||||
|
||||
var xp12 = new PipeJoin((t1X + t2X) / 2, tanksY + 80);
|
||||
P12 = new Pump("P1/2", (t1X + t2X) / 2, tanksY + 110, () => App.Plant?.P12 ?? default, () => App.Plant?.P12HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
CreateOutlet(t1, xp12);
|
||||
CreateOutlet(t2, xp12);
|
||||
CreateOutlet(Tank1, xp12);
|
||||
CreateOutlet(Tank2, xp12);
|
||||
CreatePipe(xp12, P12);
|
||||
|
||||
P3 = new Pump("P3", t3X, tanksY + 110, () => App.Plant?.P3 ?? default, () => App.Plant?.P3HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P4 = new Pump("P4", t4X, tanksY + 110, () => App.Plant?.P4 ?? default, () => App.Plant?.P4HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
P5 = new Pump("P5", t5X, tanksY + 110, () => App.Plant?.P5 ?? default, () => App.Plant?.P5HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
CreateOutlet(t3, P3);
|
||||
CreateOutlet(t4, P4);
|
||||
CreateOutlet(t5, P5);
|
||||
CreateOutlet(Tank3, P3);
|
||||
CreateOutlet(Tank4, P4);
|
||||
CreateOutlet(Tank5, P5);
|
||||
|
||||
var v44 = CreateValve(44, (t1X + t2X) / 2, tanksY + 150);
|
||||
var v45 = CreateValve(45, t3X, tanksY + 150);
|
||||
@@ -329,10 +340,10 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var xt7 = new PipeJoin(t7X, tanksY + 110);
|
||||
var xt8 = new PipeJoin(t8X, tanksY + 110);
|
||||
P6 = new Pump("P6", t6X, tanksY + 150, () => App.Plant?.P6 ?? default, () => App.Plant?.P6HasClearance ?? false, (x) => SelectedPaths.Any(p => p.Hops.Any(h => h.Node == x)));
|
||||
CreateOutlet(t6, xt6);
|
||||
CreateOutlet(t7, xt7);
|
||||
CreateOutlet(t8, xt8);
|
||||
CreateOutlet(t9, xt8);
|
||||
CreateOutlet(Tank6, xt6);
|
||||
CreateOutlet(Tank7, xt7);
|
||||
CreateOutlet(Tank8, xt8);
|
||||
CreateOutlet(Tank9, xt8);
|
||||
CreatePipe(xt8, xt7);
|
||||
CreatePipe(xt7, xt6);
|
||||
CreatePipe(xt6, P6);
|
||||
@@ -343,8 +354,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var prX = (pr1X + pr2X) / 2;
|
||||
var pr1cX = prX - 15;
|
||||
var pr2cX = prX + 15;
|
||||
var press1 = new Press("Presse 1", pr1X, prY, 20000, () => FillState.Unknown);
|
||||
var press2 = new Press("Presse 2", pr2X, prY, 15000, () => FillState.Unknown);
|
||||
Press1 = new Press("Presse 1", pr1X, prY, 20000, () => FillState.Unknown);
|
||||
Press2 = new Press("Presse 2", pr2X, prY, 15000, () => FillState.Unknown);
|
||||
var v50 = CreateValve(50, pr2cX + 30, 580);
|
||||
var v51 = CreateValve(51, pr1cX - 30, 580);
|
||||
var v52 = CreateValve(52, pr1cX - 30, 610);
|
||||
@@ -390,8 +401,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
var zv2 = new CenterValve("ZV2", pr2cX, prY - 40, () => App.Plant?.Press2HasClearance ?? false);
|
||||
CreatePipe(xp6, zv1, true);
|
||||
CreatePipe(xp8, zv2, true);
|
||||
CreateInlet(zv1, press1, true);
|
||||
CreateInlet(zv2, press2, true);
|
||||
CreateInlet(zv1, Press1, true);
|
||||
CreateInlet(zv2, Press2, true);
|
||||
}
|
||||
|
||||
protected Valve CreateValve(int n, double x, double y) {
|
||||
@@ -455,7 +466,11 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
private void UpdateValvesAdjacientToPath(Path path, bool locked, bool? wantOpen = null) {
|
||||
foreach (var (edge, node) in path.Hops) {
|
||||
TraverseSubgraph(node, (n) => n is Valve || n is ISink || n is Pump, valveAction: (v) => {
|
||||
v.IsLocked = locked;
|
||||
if (locked) {
|
||||
v.LockedForPaths.Add(path);
|
||||
} else {
|
||||
v.LockedForPaths.Remove(path);
|
||||
}
|
||||
if (wantOpen.HasValue) {
|
||||
if (wantOpen.Value) {
|
||||
App.Plant?.OpenV(v.Nr);
|
||||
|
||||
@@ -54,6 +54,14 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Path? GetFreePath(IEnumerable<INode> points, bool overrideStart = false) {
|
||||
if (overrideStart) {
|
||||
return GetPath(points, (n) => n is not ISink && (n is not Valve v || !v.LockedForPaths.Any(p => p.Start != points.First())));
|
||||
} else {
|
||||
return GetPath(points, (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
}
|
||||
}
|
||||
|
||||
public Path? GetPath(IEnumerable<INode> points, Func<INode, bool>? valid = null) {
|
||||
if (points.Count() < 2) return null;
|
||||
var start = points.First();
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public string Label => $"V{Nr}";
|
||||
public Brush? Highlight { get; set; }
|
||||
|
||||
public bool IsLocked { get; set; }
|
||||
public readonly ISet<Path> LockedForPaths = new HashSet<Path>();
|
||||
|
||||
public bool IsLocked => LockedForPaths.Any();
|
||||
public bool IsOpen => CallbackIsOpen();
|
||||
public bool WantOpen => CallbackWantOpen(this);
|
||||
public ISet<IEdge> Inputs { get; init; }
|
||||
|
||||
@@ -57,11 +57,96 @@
|
||||
<Canvas x:Name="SchemeCanvas" Width="1550" Height="900" VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True"
|
||||
MouseMove="SchemeCanvas_MouseMove" MouseLeftButtonDown="SchemeCanvas_MouseLeftButtonDown" MouseLeftButtonUp="SchemeCanvas_MouseLeftButtonUp" Grid.ColumnSpan="2" Margin="25,0,0,0">
|
||||
</Canvas>
|
||||
|
||||
<Grid Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="160"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="160"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Press1" Grid.Column="0" Grid.Row="0"
|
||||
Content="MW1 ⮞ Presse 1" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Press1" Grid.Column="2" Grid.Row="0"
|
||||
Content="MW2 ⮞ Presse 1" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Press2" Grid.Column="0" Grid.Row="2"
|
||||
Content="MW1 ⮞ Presse 2" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Press2" Grid.Column="2" Grid.Row="2"
|
||||
Content="MW2 ⮞ Presse 2" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Tank1" Grid.Column="0" Grid.Row="4"
|
||||
Content="MW1 ⮞ Tank 1" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Tank1" Grid.Column="2" Grid.Row="4"
|
||||
Content="MW2 ⮞ Tank 1" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Tank2" Grid.Column="0" Grid.Row="6"
|
||||
Content="MW1 ⮞ Tank 2" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Tank2" Grid.Column="2" Grid.Row="6"
|
||||
Content="MW2 ⮞ Tank 2" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Tank3" Grid.Column="0" Grid.Row="8"
|
||||
Content="MW1 ⮞ Tank 3" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Tank3" Grid.Column="2" Grid.Row="8"
|
||||
Content="MW2 ⮞ Tank 3" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Tank4" Grid.Column="0" Grid.Row="10"
|
||||
Content="MW1 ⮞ Tank 4" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Tank4" Grid.Column="2" Grid.Row="10"
|
||||
Content="MW2 ⮞ Tank 4" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MW1_Tank5" Grid.Column="0" Grid.Row="12"
|
||||
Content="MW1 ⮞ Tank 5" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW2_Tank5" Grid.Column="2" Grid.Row="12"
|
||||
Content="MW2 ⮞ Tank 5" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<StatusBar Grid.Row="2" BorderThickness="0,1,0,0" BorderBrush="Gray">
|
||||
|
||||
</StatusBar>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -2,7 +2,9 @@ using PamhagenSysCtrl.Helpers;
|
||||
using PamhagenSysCtrl.Helpers.Pipeline;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace PamhagenSysCtrl.Windows {
|
||||
public partial class PlantSchemeWindow : Window {
|
||||
@@ -14,11 +16,51 @@ namespace PamhagenSysCtrl.Windows {
|
||||
private ISet<INode>? _lastSelected;
|
||||
private ISet<INode>? _hover;
|
||||
|
||||
public Path? HoveringPath {
|
||||
get {
|
||||
foreach (var b in FastSelectButtons.Where(b => b.Key.IsMouseOver)) {
|
||||
if (Graph.SelectedPaths.Any(p => p.Start == b.Value.Source && p.Hops.Last().Node == b.Value.Sink))
|
||||
continue;
|
||||
return Graph.GetFreePath([b.Value.Source, b.Value.Sink], true);
|
||||
}
|
||||
|
||||
if (_lastSource == null || _hover == null || !(_hover.Count > 0 || _path.Count > 0))
|
||||
return null;
|
||||
List<INode> points = [_lastSource, .. _path];
|
||||
if (_hover.Count > 0 && !points.Contains(_hover.First())) {
|
||||
points.Add(_hover.First());
|
||||
}
|
||||
if (points.Count >= 2) {
|
||||
return Graph.GetFreePath(points);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Dictionary<Button, (ISource Source, Pump Pump, ISink Sink)> FastSelectButtons;
|
||||
|
||||
public PlantSchemeWindow() {
|
||||
InitializeComponent();
|
||||
App.Plant?.Update += OnUpdate;
|
||||
Graph = new();
|
||||
Graph.Draw(SchemeCanvas);
|
||||
FastSelectButtons = 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),
|
||||
};
|
||||
App.Plant?.Update += OnUpdate;
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, EventArgs evt) {
|
||||
@@ -75,13 +117,34 @@ namespace PamhagenSysCtrl.Windows {
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private void FastSelectButton_Enter(object sender, MouseEventArgs evt) {
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private void FastSelectButton_Leave(object sender, MouseEventArgs evt) {
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (sender is not Button b || !FastSelectButtons.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;
|
||||
}
|
||||
}
|
||||
|
||||
private void SchemeCanvas_MouseMove(object sender, MouseEventArgs evt) {
|
||||
var p = evt.GetPosition(SchemeCanvas);
|
||||
UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private void SchemeCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs evt) {
|
||||
var p = evt.GetPosition(SchemeCanvas);
|
||||
_lastSelected = UpdateScheme(evt.GetPosition(SchemeCanvas), evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
@@ -108,13 +171,12 @@ namespace PamhagenSysCtrl.Windows {
|
||||
Graph.RemovePath(path);
|
||||
}
|
||||
} else if (_lastSource != null && c is ISink sink) {
|
||||
var res = Graph.GetPath([_lastSource, .. _path, sink], (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (res is Path path) {
|
||||
if (Graph.GetFreePath([_lastSource, .. _path, sink]) is Path path) {
|
||||
Graph.AddPath(path);
|
||||
_lastSource = null;
|
||||
}
|
||||
} else if (_lastSource != null) {
|
||||
var path = Graph.GetPath([_lastSource, .. _path, c], (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
var path = Graph.GetFreePath([_lastSource, .. _path, c]);
|
||||
if (path != null) {
|
||||
_path.Add(c);
|
||||
}
|
||||
@@ -216,6 +278,30 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private static void SetFastSelectButton(Button b, int m, bool disabled) {
|
||||
b.IsEnabled = !disabled;
|
||||
if (m == 1) {
|
||||
b.Background = Brushes.MintCream;
|
||||
b.BorderBrush = Brushes.DarkGreen;
|
||||
b.Foreground = Brushes.DarkGreen;
|
||||
} else if (m == 2) {
|
||||
b.Background = Brushes.MistyRose;
|
||||
b.BorderBrush = Brushes.DarkRed;
|
||||
b.Foreground = Brushes.DarkRed;
|
||||
} else {
|
||||
b.Background = Brushes.LightGray;
|
||||
b.BorderBrush = Brushes.DimGray;
|
||||
b.Foreground = Brushes.Black;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFastSelectButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b) {
|
||||
var e = FastSelectButtons[b];
|
||||
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) {
|
||||
foreach (var e in Graph.Edges) {
|
||||
e.Highlight = null;
|
||||
@@ -227,7 +313,13 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var b in FastSelectButtons) {
|
||||
SetFastSelectButton(b.Key, 0, false);
|
||||
}
|
||||
|
||||
_hover = Graph.GetHover(pos.X, pos.Y);
|
||||
var hoverButtons = FastSelectButtons.Where(b => b.Key.IsMouseOver).ToDictionary();
|
||||
Path? hoverPathDeactivate = null;
|
||||
if (App.Plant?.ManualControlMode ?? false) {
|
||||
foreach (var src in Graph.Nodes.Where(n => n is Pump)) {
|
||||
Graph.ColorPipesByValves(src, PamhagenBrushes.Green, (src as Pump)?.State ?? default, PamhagenBrushes.DimOrange);
|
||||
@@ -236,26 +328,25 @@ namespace PamhagenSysCtrl.Windows {
|
||||
foreach (var p in Graph.SelectedPaths) {
|
||||
Graph.ColorPipesAdjacientToPath(p, PamhagenBrushes.Green, p.Hops.Select(h => (h.Node as Pump)?.State ?? default).FirstOrDefault(n => n != MotorState.Halt), PamhagenBrushes.DimOrange);
|
||||
}
|
||||
if (_lastSource != null && (_hover.Count > 0 || _path.Count > 0)) {
|
||||
List<INode> points = [_lastSource, .. _path];
|
||||
if (_hover.Count > 0 && !points.Contains(_hover.First())) {
|
||||
points.Add(_hover.First());
|
||||
}
|
||||
if (points.Count >= 2) {
|
||||
var res = Graph.GetPath(points, (n) => n is not ISink && (n is not Valve v || !v.IsLocked));
|
||||
if (res is Path path) {
|
||||
Graph.ColorPipesAdjacientToPath(path, PamhagenBrushes.Green, default, PamhagenBrushes.DimOrange);
|
||||
}
|
||||
}
|
||||
} else if (_lastSource == null && _hover.Count > 0 && Graph.SelectedPaths.Any(p => p.Start == _hover.First())) {
|
||||
var path = Graph.SelectedPaths.First(p => p.Start == _hover.First());
|
||||
var pumpActive = path.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false);
|
||||
if (_lastSource == null && _hover.Count > 0 && Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == _hover.First()) is Path path1) {
|
||||
var pumpActive = path1.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false);
|
||||
if (pumpActive) {
|
||||
foreach (var pump in path.Hops.Select(h => h.Node as Pump).Where(p => p != null)) {
|
||||
foreach (var pump in path1.Hops.Select(h => h.Node as Pump).Where(p => p != null)) {
|
||||
pump?.Highlight = PamhagenBrushes.Red;
|
||||
}
|
||||
} else {
|
||||
Graph.ColorPipesAdjacientToPath(path, PamhagenBrushes.Red, default, null);
|
||||
hoverPathDeactivate = path1;
|
||||
Graph.ColorPipesAdjacientToPath(path1, PamhagenBrushes.Red, default, null);
|
||||
}
|
||||
} else if (hoverButtons.Count != 0 && Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == hoverButtons.First().Value.Source) is Path path2) {
|
||||
var pumpActive = path2.Hops.Any(h => (h.Node as Pump)?.IsActive ?? false);
|
||||
if (pumpActive) {
|
||||
foreach (var pump in path2.Hops.Select(h => h.Node as Pump).Where(p => p != null)) {
|
||||
pump?.Highlight = PamhagenBrushes.Red;
|
||||
}
|
||||
} else {
|
||||
hoverPathDeactivate = path2;
|
||||
Graph.ColorPipesAdjacientToPath(path2, PamhagenBrushes.Red, default, null);
|
||||
}
|
||||
}
|
||||
if (_lastSource != null) {
|
||||
@@ -263,7 +354,17 @@ namespace PamhagenSysCtrl.Windows {
|
||||
edge.Highlight = PamhagenBrushes.Green;
|
||||
}
|
||||
}
|
||||
if (HoveringPath is Path hoveringPath) {
|
||||
Graph.ColorPipesAdjacientToPath(hoveringPath, PamhagenBrushes.Green, default, PamhagenBrushes.DimOrange);
|
||||
}
|
||||
}
|
||||
|
||||
var paths = Graph.SelectedPaths;
|
||||
if (HoveringPath is Path hp) paths = paths.Append(hp);
|
||||
foreach (var b in FastSelectButtons.Keys) {
|
||||
UpdateFastSelectButton(paths, hoverPathDeactivate, b);
|
||||
}
|
||||
|
||||
Graph.Update(_hover, down);
|
||||
return _hover;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user