Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d507a7486e | ||
|
|
ece46846b4 | ||
|
|
03c91fb55a | ||
|
|
f0accc8df8 |
@@ -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;
|
||||
@@ -76,19 +87,19 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
CreatePipe(MP1, x1);
|
||||
CreatePipe(MP2, x2);
|
||||
|
||||
var v1 = CreateValve(1, mw1X, mpY + 70);
|
||||
var v2 = CreateValve(2, mw2X, mpY + 70);
|
||||
var v3 = CreateValve(3, mw2X + 30, mpY + 70);
|
||||
var v4 = CreateValve(4, mw1X - 30, mpY + 70);
|
||||
var v1 = CreateValve(1, mw1X, mpY + 80);
|
||||
var v2 = CreateValve(2, mw2X, mpY + 80);
|
||||
var v3 = CreateValve(3, mw2X + 30, mpY + 80);
|
||||
var v4 = CreateValve(4, mw1X - 30, mpY + 80);
|
||||
|
||||
CreatePipe(x1, v1);
|
||||
CreatePipe(x1, v4);
|
||||
CreatePipe(x2, v2);
|
||||
CreatePipe(x2, v3);
|
||||
|
||||
var x3 = new PipeJoin(mw1X, mpY + 100);
|
||||
var x3 = new PipeJoin(mw1X, ltg1Y);
|
||||
var x4 = new PipeJoin(x1X, ltg1Y);
|
||||
var x5 = new PipeJoin(mw2X, mpY + 130);
|
||||
var x5 = new PipeJoin(mw1X - 30, ltg2Y);
|
||||
var x6 = new PipeJoin(x1X - 30, ltg2Y);
|
||||
|
||||
CreatePipe(v1, x3, true);
|
||||
@@ -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) {
|
||||
@@ -402,6 +413,23 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
return new($"Tank {n}", x, y, capacity, () => App.Plant?.TankFillLevels[n - 1] ?? FillState.Unknown);
|
||||
}
|
||||
|
||||
private int PathCost(Path p) {
|
||||
return
|
||||
1000 * p.Hops.Count(h => h.Node is Valve) +
|
||||
(p.Hops.Any(h => h.Node is Valve v && v.Nr == 15) && !p.Hops.Any(h => h.Node is Valve v && (v.Nr == 16 || v.Nr == 20)) ? 10 : 0) +
|
||||
(p.Hops.Any(h => h.Node is Valve v && v.Nr == 11) && !p.Hops.Any(h => h.Node is Valve v && (v.Nr == 14 || v.Nr == 21)) ? 10 : 0) +
|
||||
(p.Hops.Any(h => h.Node is Valve v && v.Nr == 6) ? 10 : 0) +
|
||||
p.Bends;
|
||||
}
|
||||
|
||||
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())), PathCost);
|
||||
} else {
|
||||
return GetPath(points, (n) => n is not ISink && (n is not Valve v || !v.IsLocked), PathCost);
|
||||
}
|
||||
}
|
||||
|
||||
public void TraverseSubgraph(INode start, Func<INode, bool> invalid, HashSet<IEdge>? _visited = null, Action<INode, bool, IEdge>? edgeAction = null, Action<Valve>? valveAction = null, bool reverse = false) {
|
||||
var visited = _visited ?? [];
|
||||
if (start is Valve v) {
|
||||
@@ -455,7 +483,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);
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public bool AreValvesClosed(params int[] ns) => ns.All(IsValveClosed) && ns.All(WantValveClosed);
|
||||
|
||||
public int TroughSelector => Sensors.TroughSelector;
|
||||
public bool IsMWSelected => Sensors.TroughSelector == 1;
|
||||
public bool IsMW1Selected => Sensors.TroughSelector == 1;
|
||||
public bool IsMW2Selected => Sensors.TroughSelector == 2;
|
||||
public FillState FillLevelMW1 => Sensors.FillingLevelMW1;
|
||||
public FillState FillLevelMW2 => Sensors.FillingLevelMW2;
|
||||
@@ -54,6 +54,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
public bool WantMW2Selected => !Actuators.GetV(58);
|
||||
|
||||
public bool IsTroughAugerActive => Actuators.TroughAuger;
|
||||
public bool TroughAugerHasClearance => IsReblerActive && !(IsMW1Selected && FillLevelMW1 == FillState.Full) && !(IsMW2Selected && FillLevelMW2 == FillState.Full);
|
||||
public bool IsReblerActive => Actuators.Rebler;
|
||||
public bool IsStirrerMW1Active => Actuators.StirrerMW1;
|
||||
public bool IsStirrerMW2Active => Actuators.StirrerMW2;
|
||||
@@ -88,7 +89,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
if (p.IsReblerActive && !p.IsAuger1Active) p.StartAuger1();
|
||||
if (p.IsAuger1Active && !p.IsAuger2Active) p.StartAuger2();
|
||||
if (p.IsAuger2Active && !p.IsAuger3Active) p.StartAuger3();
|
||||
if (p.IsTroughAugerActive && (!p.IsReblerActive || (p.IsMWSelected && p.FillLevelMW1 == FillState.Full) || (p.IsMW2Selected && p.FillLevelMW2 == FillState.Full)))
|
||||
if (p.IsTroughAugerActive && !p.TroughAugerHasClearance)
|
||||
p.StopTroughAuger();
|
||||
}
|
||||
|
||||
@@ -410,7 +411,7 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
}
|
||||
|
||||
public void StartTroughAuger() {
|
||||
if (!ManualControlMode && (!IsReblerActive || (IsMWSelected && FillLevelMW1 == FillState.Full) || (IsMW2Selected && FillLevelMW2 == FillState.Full)))
|
||||
if (!ManualControlMode && !TroughAugerHasClearance)
|
||||
throw new NoClearanceException("Schnecke Auffangwanne hat keine Freigabe");
|
||||
Actuators.TroughAuger = true;
|
||||
ActuatorsChanged = true;
|
||||
|
||||
@@ -54,46 +54,52 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
return p;
|
||||
}
|
||||
|
||||
public Path? GetPath(IEnumerable<INode> points, Func<INode, bool>? valid = null) {
|
||||
public Path? GetPath(IEnumerable<INode> points, Func<INode, bool>? valid = null, Func<Path, int>? cost = null) {
|
||||
if (points.Count() < 2) return null;
|
||||
var start = points.First();
|
||||
var path = new Path(start, []);
|
||||
List<Path> paths = [new(start, [])];
|
||||
foreach (var end in points.Skip(1)) {
|
||||
if (valid != null && start != points.First() && !valid(start)) {
|
||||
if (valid != null && start != points.First() && !valid(start))
|
||||
return null;
|
||||
} else if (GetPath(start, end, valid, visited: [.. path.Hops.Select(h => h.Node)]) is not Path p) {
|
||||
return null;
|
||||
} else {
|
||||
path.Hops = [.. path.Hops, .. p.Hops];
|
||||
start = end;
|
||||
|
||||
var newPaths = new List<Path>();
|
||||
foreach (var path in paths) {
|
||||
foreach (var subPath in GetPaths(start, end, visited: [.. path.Hops.Select(h => h.Node)], valid)) {
|
||||
newPaths.Add(new(path.Start, [.. path.Hops, .. subPath.Hops]));
|
||||
}
|
||||
}
|
||||
if (newPaths.Count == 0)
|
||||
return null;
|
||||
|
||||
paths = newPaths;
|
||||
start = end;
|
||||
}
|
||||
if (paths.Count == 0) {
|
||||
return null;
|
||||
} else {
|
||||
cost ??= p => 0;
|
||||
return paths.OrderBy(cost).First();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public Path? GetPath(INode start, INode end, Func<INode, bool>? valid = null, HashSet<INode>? visited = null) {
|
||||
public IEnumerable<Path> GetPaths(INode start, INode end, HashSet<INode>? visited = null, Func<INode, bool>? valid = null) {
|
||||
if (!Nodes.Contains(start) || !Nodes.Contains(end)) throw new ArgumentException("Start/end node not contained in graph");
|
||||
valid ??= a => true;
|
||||
visited = [.. visited ?? [], start];
|
||||
List<(IEdge, INode)> hops = [];
|
||||
Path? path = null;
|
||||
foreach (var o in start.Outputs) {
|
||||
var e = o.IsTwoWay && o.End == start ? o.Start : o.End;
|
||||
if (e == end) {
|
||||
return new(start, [(o, e)]);
|
||||
yield return new(start, [(o, e)]);
|
||||
continue;
|
||||
} else if (!valid(e) || visited.Contains(e)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var p = GetPath(e, end, valid, visited);
|
||||
if (p != null) {
|
||||
var p2 = new Path(start, [(o, e), .. p.Value.Hops]);
|
||||
if (path == null || p2.Bends < path.Value.Bends || (p2.Bends == path.Value.Bends && p2.Length < path.Value.Length)) {
|
||||
path = p2;
|
||||
}
|
||||
foreach (var p in GetPaths(e, end, visited, valid)) {
|
||||
yield return new(start, [(o, e), .. p.Hops]);
|
||||
}
|
||||
}
|
||||
return path != null ? new(start, path.Value.Hops) : null;
|
||||
}
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
|
||||
@@ -3,7 +3,7 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
INode Start,
|
||||
IEnumerable<(IEdge Edge, INode Node)> Hops)
|
||||
{
|
||||
public readonly double Bends => Hops.Sum(h => (h.Node is not Valve && h.Node is not PipeJoin ? 1 : 0) + (h.Edge.Start.CenterX != h.Edge.End.CenterX && h.Edge.Start.CenterY != h.Edge.End.CenterY ? 1 : 0));
|
||||
public readonly int Bends => Hops.Sum(h => (h.Node is not Valve && h.Node is not PipeJoin ? 1 : 0) + (h.Edge.Start.CenterX != h.Edge.End.CenterX && h.Edge.Start.CenterY != h.Edge.End.CenterY ? 1 : 0));
|
||||
public readonly double Length => Hops.Sum(h => Math.Abs(h.Edge.Start.CenterX - h.Edge.End.CenterX) + Math.Abs(h.Edge.Start.CenterY - h.Edge.End.CenterY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net10.0-windows</TargetFramework>
|
||||
<Version>0.0.2</Version>
|
||||
<Version>0.0.3</Version>
|
||||
<Product>Anlagensteuerung Pamhagen</Product>
|
||||
<AssemblyTitle>Anlagensteuerung Pamhagen</AssemblyTitle>
|
||||
<AssemblyName>PamhagenSysCtrl</AssemblyName>
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace PamhagenSysCtrl {
|
||||
Gradation °Oe: {plant.GradationOe:N2}
|
||||
Presse Querschnecke: {plant.PresseQuerSchnecke}
|
||||
Füllstände:
|
||||
Maischewanne 1: {plant.FillLevelMW1} (ausgewählt: {plant.WantMW1Selected}, Status: {plant.IsMWSelected})
|
||||
Maischewanne 1: {plant.FillLevelMW1} (ausgewählt: {plant.WantMW1Selected}, Status: {plant.IsMW1Selected})
|
||||
Maischewanne 2: {plant.FillLevelMW2} (ausgewählt: {plant.WantMW2Selected}, Status: {plant.IsMW2Selected})
|
||||
Presse 1: {plant.Press1HasClearance}
|
||||
Presse 2: {plant.Press2HasClearance}
|
||||
|
||||
@@ -57,11 +57,170 @@
|
||||
<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>
|
||||
|
||||
<Border Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Padding="10,10,20,20" Margin="0,0,-11,-11"
|
||||
Background="WhiteSmoke"
|
||||
BorderBrush="Gray" BorderThickness="1" CornerRadius="10">
|
||||
<Grid>
|
||||
<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>
|
||||
</Border>
|
||||
|
||||
<Border HorizontalAlignment="Left" VerticalAlignment="Bottom" Padding="60,15,15,30" Margin="-11,0,0,-11"
|
||||
Background="WhiteSmoke"
|
||||
BorderBrush="Gray" BorderThickness="1" CornerRadius="10">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="160"/>
|
||||
<ColumnDefinition Width="2.5"/>
|
||||
<ColumnDefinition Width="2.5"/>
|
||||
<ColumnDefinition Width="160"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="60"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="50"/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition Height="80"/>
|
||||
<RowDefinition Height="80"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button x:Name="FastSelectButton_EntryTrough_Start" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
|
||||
FontSize="14" FontWeight="Bold"
|
||||
Click="FastSelectButton_EntryTroughStart_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center">Auffangwanne<LineBreak/><Run FontSize="18">Schnecke Start</Run></TextBlock>
|
||||
</Button>
|
||||
<Button x:Name="FastSelectButton_EntryTrough_Stop" Grid.Column="2" Grid.Row="0" Grid.ColumnSpan="2"
|
||||
FontSize="14" FontWeight="Bold"
|
||||
Click="FastSelectButton_EntryTroughStop_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center">Auffangwanne<LineBreak/><Run FontSize="18">Schnecke Stop</Run></TextBlock>
|
||||
</Button>
|
||||
|
||||
|
||||
<Button x:Name="FastSelectButton_MW2" Grid.Column="0" Grid.Row="2"
|
||||
Content="MW2 ⮜" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MW2_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
<Button x:Name="FastSelectButton_MW1" Grid.Column="3" Grid.Row="2"
|
||||
Content="⮞ MW1" FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MW1_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2"/>
|
||||
|
||||
<Button x:Name="FastSelectButton_MP2_Stop" Grid.Column="0" Grid.Row="4"
|
||||
FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MP2_Stop_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center"><Run FontSize="24">MP2</Run><LineBreak/>Stop</TextBlock>
|
||||
</Button>
|
||||
<Button x:Name="FastSelectButton_MP2_Forward" Grid.Column="0" Grid.Row="5"
|
||||
FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MP2_Forward_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center"><Run FontSize="24">MP2</Run><LineBreak/><Run x:Name="MP2_Target">Vor</Run></TextBlock>
|
||||
</Button>
|
||||
|
||||
<Button x:Name="FastSelectButton_MP1_Stop" Grid.Column="3" Grid.Row="4"
|
||||
FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MP1_Stop_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center"><Run FontSize="24">MP1</Run><LineBreak/>Stop</TextBlock>
|
||||
</Button>
|
||||
<Button x:Name="FastSelectButton_MP1_Forward" Grid.Column="3" Grid.Row="5"
|
||||
FontSize="16" FontWeight="Bold"
|
||||
Click="FastSelectButton_MP1_Forward_Click" MouseEnter="FastSelectButton_Enter" MouseLeave="FastSelectButton_Leave"
|
||||
BorderThickness="2">
|
||||
<TextBlock TextAlignment="Center"><Run FontSize="24">MP1</Run><LineBreak/><Run x:Name="MP1_Target">Vor</Run></TextBlock>
|
||||
</Button>
|
||||
</Grid>
|
||||
</Border>
|
||||
</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 FastSelectPaths.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)> FastSelectPaths;
|
||||
|
||||
public PlantSchemeWindow() {
|
||||
InitializeComponent();
|
||||
App.Plant?.Update += OnUpdate;
|
||||
Graph = new();
|
||||
Graph.Draw(SchemeCanvas);
|
||||
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),
|
||||
};
|
||||
App.Plant?.Update += OnUpdate;
|
||||
}
|
||||
|
||||
private void OnClosed(object sender, EventArgs evt) {
|
||||
@@ -75,13 +117,98 @@ namespace PamhagenSysCtrl.Windows {
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private void FastSelectButton_EntryTroughStart_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StartTroughAuger();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_EntryTroughStop_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StopTroughAuger();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MW1_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.SelectMW1();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MW2_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.SelectMW2();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MP1_Forward_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StartMP1Forward();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MP1_Stop_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StopMP1();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MP2_Forward_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StartMP2Forward();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FastSelectButton_MP2_Stop_Click(object sender, RoutedEventArgs evt) {
|
||||
try {
|
||||
App.Plant?.StopMP2();
|
||||
} catch (NoClearanceException exc) {
|
||||
MessageBox.Show($"{exc.Message}", "Keine Freigabe", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
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 || !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;
|
||||
}
|
||||
}
|
||||
|
||||
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 +235,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 +342,30 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private static void SetFastSelectButton(Button b, int m, bool disabled = false) {
|
||||
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 UpdateFastSelectPathButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b) {
|
||||
var e = FastSelectPaths[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,35 +377,52 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
SetFastSelectButton(FastSelectButton_EntryTrough_Start, App.Plant?.IsTroughAugerActive ?? false ? 1 : 0, !(App.Plant?.TroughAugerHasClearance ?? false));
|
||||
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);
|
||||
var hoverButtons = FastSelectPaths.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);
|
||||
}
|
||||
MP1_Target.Text = "Vor";
|
||||
MP2_Target.Text = "Vor";
|
||||
MP1_Target.FontSize = 16;
|
||||
MP2_Target.FontSize = 16;
|
||||
} else {
|
||||
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 +430,36 @@ namespace PamhagenSysCtrl.Windows {
|
||||
edge.Highlight = PamhagenBrushes.Green;
|
||||
}
|
||||
}
|
||||
if (HoveringPath is Path hoveringPath) {
|
||||
Graph.ColorPipesAdjacientToPath(hoveringPath, PamhagenBrushes.Green, default, PamhagenBrushes.DimOrange);
|
||||
}
|
||||
|
||||
if (Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == Graph.MW1) is Path pmw1) {
|
||||
MP1_Target.Text = "\u2b9e " + string.Join(" \u2b9e ", pmw1.Hops
|
||||
.Select(h => h.Node is Valve || h.Node is Pump || h.Node is CenterValve ? null : h.Node.Label)
|
||||
.Where(l => !string.IsNullOrWhiteSpace(l)));
|
||||
} else {
|
||||
MP1_Target.Text = "Vor";
|
||||
}
|
||||
if (Graph.SelectedPaths.Select(p => (Path?)p).FirstOrDefault(p => p?.Start == Graph.MW2) is Path pmw2) {
|
||||
MP2_Target.Text = "\u2b9e " + string.Join(" \u2b9e ", pmw2.Hops
|
||||
.Select(h => h.Node is Valve || h.Node is Pump || h.Node is CenterValve ? null : h.Node.Label)
|
||||
.Where(l => !string.IsNullOrWhiteSpace(l)));
|
||||
} else {
|
||||
MP2_Target.Text = "Vor";
|
||||
}
|
||||
var len1 = MP1_Target.Text.Length;
|
||||
var len2 = MP2_Target.Text.Length;
|
||||
MP1_Target.FontSize = len1 > 24 ? 8 : len1 > 20 ? 10 : len1 > 16 ? 12 : len1 > 12 ? 14 : 16;
|
||||
MP2_Target.FontSize = len2 > 24 ? 8 : len2 > 20 ? 10 : len2 > 16 ? 12 : len2 > 12 ? 14 : 16;
|
||||
}
|
||||
|
||||
var paths = Graph.SelectedPaths;
|
||||
if (HoveringPath is Path hp) paths = paths.Append(hp);
|
||||
foreach (var b in FastSelectPaths.Keys) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b);
|
||||
}
|
||||
|
||||
Graph.Update(_hover, down);
|
||||
return _hover;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user