diff --git a/PamhagenSysCtrl/Helpers/PamhagenPlant.cs b/PamhagenSysCtrl/Helpers/PamhagenPlant.cs index c843434..f1bd8cd 100644 --- a/PamhagenSysCtrl/Helpers/PamhagenPlant.cs +++ b/PamhagenSysCtrl/Helpers/PamhagenPlant.cs @@ -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; diff --git a/PamhagenSysCtrl/Windows/ManualControlWindow.xaml.cs b/PamhagenSysCtrl/Windows/ManualControlWindow.xaml.cs index 0c98965..a000cc1 100644 --- a/PamhagenSysCtrl/Windows/ManualControlWindow.xaml.cs +++ b/PamhagenSysCtrl/Windows/ManualControlWindow.xaml.cs @@ -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} diff --git a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml index ef4c2c8..5016e44 100644 --- a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml +++ b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml @@ -58,91 +58,165 @@ MouseMove="SchemeCanvas_MouseMove" MouseLeftButtonDown="SchemeCanvas_MouseLeftButtonDown" MouseLeftButtonUp="SchemeCanvas_MouseLeftButtonUp" Grid.ColumnSpan="2" Margin="25,0,0,0"> - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + diff --git a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs index 250018c..e46076c 100644 --- a/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs +++ b/PamhagenSysCtrl/Windows/PlantSchemeWindow.xaml.cs @@ -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 FastSelectButtons; + protected Dictionary FastSelectPaths; public PlantSchemeWindow() { InitializeComponent(); Graph = new(); Graph.Draw(SchemeCanvas); - FastSelectButtons = new Dictionary { + FastSelectPaths = new Dictionary { [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 paths, Path? hoverPathDeactivate, Button b) { - var e = FastSelectButtons[b]; + private void UpdateFastSelectPathButton(IEnumerable 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);