This commit is contained in:
@@ -18,7 +18,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
|
||||
public Path? HoveringPath {
|
||||
get {
|
||||
foreach (var b in FastSelectButtons.Where(b => b.Key.IsMouseOver)) {
|
||||
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);
|
||||
@@ -38,13 +38,13 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
protected Dictionary<Button, (ISource Source, Pump Pump, ISink Sink)> FastSelectButtons;
|
||||
protected Dictionary<Button, (ISource Source, Pump Pump, ISink Sink)> FastSelectPaths;
|
||||
|
||||
public PlantSchemeWindow() {
|
||||
InitializeComponent();
|
||||
Graph = new();
|
||||
Graph.Draw(SchemeCanvas);
|
||||
FastSelectButtons = new Dictionary<Button, (ISource, Pump, ISink)> {
|
||||
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),
|
||||
@@ -117,6 +117,70 @@ 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);
|
||||
}
|
||||
@@ -126,7 +190,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
|
||||
private void FastSelectButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (sender is not Button b || !FastSelectButtons.TryGetValue(b, out var val))
|
||||
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) {
|
||||
@@ -278,7 +342,7 @@ namespace PamhagenSysCtrl.Windows {
|
||||
UpdateScheme(pos, evt.LeftButton == MouseButtonState.Pressed);
|
||||
}
|
||||
|
||||
private static void SetFastSelectButton(Button b, int m, bool disabled) {
|
||||
private static void SetFastSelectButton(Button b, int m, bool disabled = false) {
|
||||
b.IsEnabled = !disabled;
|
||||
if (m == 1) {
|
||||
b.Background = Brushes.MintCream;
|
||||
@@ -295,8 +359,8 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFastSelectButton(IEnumerable<Path> paths, Path? hoverPathDeactivate, Button b) {
|
||||
var e = FastSelectButtons[b];
|
||||
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);
|
||||
@@ -313,17 +377,29 @@ namespace PamhagenSysCtrl.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var b in FastSelectButtons) {
|
||||
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 = FastSelectButtons.Where(b => b.Key.IsMouseOver).ToDictionary();
|
||||
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);
|
||||
@@ -357,12 +433,31 @@ namespace PamhagenSysCtrl.Windows {
|
||||
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 FastSelectButtons.Keys) {
|
||||
UpdateFastSelectButton(paths, hoverPathDeactivate, b);
|
||||
foreach (var b in FastSelectPaths.Keys) {
|
||||
UpdateFastSelectPathButton(paths, hoverPathDeactivate, b);
|
||||
}
|
||||
|
||||
Graph.Update(_hover, down);
|
||||
|
||||
Reference in New Issue
Block a user