Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2dee3a9ae9 | ||
|
|
4e82f164c9 | ||
|
|
77f9ae167c | ||
|
|
eb0ec60ed2 | ||
|
|
9d4ae11de8 | ||
|
|
d507a7486e | ||
|
|
ece46846b4 | ||
|
|
03c91fb55a | ||
|
|
f0accc8df8 |
@@ -1,3 +1,7 @@
|
||||
|
||||
[plc]
|
||||
port = COM1
|
||||
|
||||
[update]
|
||||
url = https://elwig.at/files/pamhagen-sysctrl/latest
|
||||
auto = true
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using PamhagenSysCtrl.Dialogs;
|
||||
using PamhagenSysCtrl.Helpers;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
@@ -10,6 +11,8 @@ namespace PamhagenSysCtrl {
|
||||
public static PamhagenPlant? Plant;
|
||||
public static Dispatcher? MainDispatcher;
|
||||
|
||||
private readonly DispatcherTimer AutoUpdateTimer = new() { Interval = TimeSpan.FromHours(1) };
|
||||
|
||||
public static readonly string DataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Anlagensteuerung Pamhagen");
|
||||
public static readonly string ConfigPath = Path.Combine(DataPath, "config.ini");
|
||||
public static readonly string InstallPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Anlagensteuerung Pamhagen");
|
||||
@@ -45,6 +48,51 @@ namespace PamhagenSysCtrl {
|
||||
}
|
||||
|
||||
base.OnStartup(evt);
|
||||
|
||||
if (Config.UpdateUrl != null && Config.UpdateAuto) {
|
||||
AutoUpdateTimer.Tick += async (_, _) => {
|
||||
try {
|
||||
await CheckForUpdates();
|
||||
} catch { }
|
||||
};
|
||||
AutoUpdateTimer.Start();
|
||||
await Dispatcher.BeginInvoke(async () => {
|
||||
await Task.Delay(1500);
|
||||
try {
|
||||
await CheckForUpdates();
|
||||
} catch { }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task CheckForUpdates(bool showResult = false) {
|
||||
if (Config.UpdateUrl == null) return;
|
||||
|
||||
try {
|
||||
var latest = await UpdateService.GetLatestInstallerUrl(Config.UpdateUrl);
|
||||
if (latest.HasValue && new Version(latest.Value.Version) > Version) {
|
||||
var dialog = new UpdateDialog(latest.Value.Version, latest.Value.Url, latest.Value.Size) {
|
||||
Owner = Current.MainWindow,
|
||||
};
|
||||
if (dialog.ShowDialog() == true) {
|
||||
Current.Shutdown();
|
||||
}
|
||||
} else if (showResult) {
|
||||
MessageBox.Show($"Die Anlagensteuerung ist auf dem aktuellen Stand.\n(Version {Version})", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
} catch (OperationCanceledException) {
|
||||
if (showResult) {
|
||||
MessageBox.Show("Zeitüberschreitung beim Abrufen der Update-Informationen.", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
if (showResult) {
|
||||
MessageBox.Show($"Die Update-Informationen konnten nicht abgerufen werden:\n\n{exc.Message}", "Nach Updates suchen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async void Application_Exit(object sender, ExitEventArgs evt) {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<Window x:Class="PamhagenSysCtrl.Dialogs.UpdateDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
ResizeMode="NoResize" ShowInTaskbar="False" Topmost="True"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
Title="Update verfügbar - Anlagensteuerung Pamhagen"
|
||||
Height="220" Width="480"
|
||||
Closed="OnClosed">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock x:Name="Description" FontSize="14" TextAlignment="Center"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
Version <Run x:Name="VersionText" FontWeight="Bold">0.0.0</Run> ist verfügbar.<LineBreak/>
|
||||
Soll das Update heruntergeladen und installiert werden?<LineBreak/>
|
||||
(ca. <Run x:Name="SizeText">0</Run> MB)<LineBreak/><LineBreak/>
|
||||
<Run FontWeight="Bold">Hinweis:</Run> Die Anlagensteuerung wird für die Installation geschlossen.
|
||||
</TextBlock>
|
||||
|
||||
<StackPanel x:Name="DownloadPanel" Grid.Row="0" VerticalAlignment="Center" Visibility="Collapsed">
|
||||
<TextBlock x:Name="StatusText" Text="Update wird heruntergeladen..."
|
||||
FontSize="14" TextAlignment="Center" Margin="0,0,0,10"/>
|
||||
<ProgressBar x:Name="DownloadProgress" Height="24" Minimum="0" Maximum="100"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,18,0,0">
|
||||
<Button x:Name="InstallButton" Content="Installieren" IsDefault="True"
|
||||
Width="110" Height="30" Margin="0,0,12,0" Click="InstallButton_Click"/>
|
||||
<Button x:Name="CancelButton" Content="Abbrechen" IsCancel="True"
|
||||
Width="110" Height="30"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,45 @@
|
||||
using PamhagenSysCtrl.Helpers;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace PamhagenSysCtrl.Dialogs {
|
||||
public partial class UpdateDialog : Window {
|
||||
|
||||
private readonly string Url;
|
||||
private readonly CancellationTokenSource Cancellation = new();
|
||||
|
||||
public UpdateDialog(string version, string url, long size) {
|
||||
Url = url;
|
||||
InitializeComponent();
|
||||
VersionText.Text = version;
|
||||
SizeText.Text = Math.Ceiling(size / 1024d / 1024d).ToString("N0");
|
||||
}
|
||||
|
||||
private void OnClosed(object? sender, EventArgs evt) {
|
||||
Cancellation.Cancel();
|
||||
Cancellation.Dispose();
|
||||
}
|
||||
|
||||
private async void InstallButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Description.Visibility = Visibility.Collapsed;
|
||||
DownloadPanel.Visibility = Visibility.Visible;
|
||||
InstallButton.IsEnabled = false;
|
||||
|
||||
try {
|
||||
var progress = new Progress<double>(value => DownloadProgress.Value = value * 100);
|
||||
var filename = Path.Combine(App.TempPath, $"PamhagenSysCtrl-{VersionText.Text}.msi");
|
||||
await UpdateService.DownloadInstaller(Url, filename, progress, Cancellation.Token);
|
||||
StatusText.Text = "Installer wird gestartet...";
|
||||
UpdateService.StartInstaller(filename);
|
||||
DialogResult = true;
|
||||
} catch (OperationCanceledException) {
|
||||
// Closing the dialog cancels an active download.
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show($"Das Update konnte nicht installiert werden:\n\n{exc.Message}", "Update installieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Description.Visibility = Visibility.Visible;
|
||||
DownloadPanel.Visibility = Visibility.Collapsed;
|
||||
InstallButton.IsEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
private readonly string FileName;
|
||||
|
||||
public string PlcPort = "COM1";
|
||||
public string? UpdateUrl;
|
||||
public bool UpdateAuto;
|
||||
|
||||
public Config(string filename) {
|
||||
FileName = filename;
|
||||
@@ -19,6 +21,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
try {
|
||||
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
||||
PlcPort = config["plc:port"] ?? "COM1";
|
||||
UpdateUrl = config["update:url"];
|
||||
UpdateAuto = TrueValues.Contains(config["update:auto"]?.ToLower());
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show($"Die Konfigurationsdatei konnte nicht gelesen werden:\n\n{exc.Message}", "Konfigurationsdatei lesen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
Application.Current.Shutdown();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -43,31 +43,28 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected static FillState Int3ToFillState(int n) {
|
||||
return n switch {
|
||||
7 => FillState.Full,
|
||||
6 => FillState.Half,
|
||||
4 => FillState.Filled,
|
||||
0 => FillState.Empty,
|
||||
_ => FillState.Invalid,
|
||||
};
|
||||
protected static FillState Int3ToFillState(int n, bool bigEndian = true) {
|
||||
return
|
||||
(bigEndian && (n & 0x4) != 0) || (!bigEndian && (n & 0x1) != 0) ? FillState.Full :
|
||||
(bigEndian && (n & 0x2) != 0) || (!bigEndian && (n & 0x2) != 0) ? FillState.Half :
|
||||
(bigEndian && (n & 0x1) != 0) || (!bigEndian && (n & 0x4) != 0) ? FillState.Filled :
|
||||
n == 0 ? FillState.Empty :
|
||||
FillState.Invalid;
|
||||
}
|
||||
|
||||
protected static FillState Int2ToFillState(int n) {
|
||||
return n switch {
|
||||
2 => FillState.Full,
|
||||
0 => FillState.Filled,
|
||||
1 => FillState.Empty,
|
||||
_ => FillState.Invalid,
|
||||
};
|
||||
protected static FillState Int2ToFillState(int n, bool bigEndian = true) {
|
||||
return
|
||||
(bigEndian && (n & 0x2) != 0) || (!bigEndian && (n & 0x1) != 0) ? FillState.Full :
|
||||
(bigEndian && (n & 0x1) != 0) || (!bigEndian && (n & 0x2) != 0) ? FillState.Filled :
|
||||
n == 0 ? FillState.Empty :
|
||||
FillState.Invalid;
|
||||
}
|
||||
|
||||
protected static FillState Int1ToFillState(int n) {
|
||||
return n switch {
|
||||
1 => FillState.Full,
|
||||
0 => FillState.Unknown,
|
||||
_ => FillState.Invalid,
|
||||
};
|
||||
return
|
||||
n == 1 ? FillState.Full :
|
||||
n == 0 ? FillState.Unknown :
|
||||
FillState.Invalid;
|
||||
}
|
||||
|
||||
protected static MotorState Int2ToPumpState(int n, bool inverse) {
|
||||
@@ -110,8 +107,8 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
long pressure = (long)r1 | ((long)r2 << 16) | ((long)r3 << 32) | ((long)r4 << 48);
|
||||
pressure = (pressure & 0x01FFFFFFFFFFFFFF) | ((pressure & 0x0600000000000000) << 1);
|
||||
|
||||
var mw1 = Int3ToFillState((f1 ) & 0x7); // 111 011 001 000
|
||||
var mw2 = Int3ToFillState((f1 >> 3) & 0x7); // 111 011 001 000
|
||||
var mw1 = Int3ToFillState((f1 ) & 0x7, false); // 111 011 001 000
|
||||
var mw2 = Int3ToFillState((f1 >> 3) & 0x7, false); // 111 011 001 000
|
||||
var p1 = ((f1 >> 6) & 0x1) == 0; // 1 0
|
||||
var p2 = ((f1 >> 7) & 0x1) == 0; // 1 0
|
||||
var wp = ((f1 >> 8) & 0x3); // 10 01
|
||||
@@ -129,11 +126,11 @@ namespace PamhagenSysCtrl.Helpers {
|
||||
// -> factor: 0,03125 + (offset) 25 Oe
|
||||
double oe = v * 0.03125 + 25;
|
||||
|
||||
var t1 = Int2ToFillState((f2 ) & 0x3); // 10 01 00
|
||||
var t2 = Int2ToFillState((f2 >> 2) & 0x3); // 10 01 00
|
||||
var t3 = Int2ToFillState((f2 >> 4) & 0x3); // 10 01 00
|
||||
var t4 = Int2ToFillState((f2 >> 6) & 0x3); // 10 01 00
|
||||
var t5 = Int2ToFillState((f2 >> 8) & 0x3); // 10 01 00
|
||||
var t1 = Int1ToFillState(((f2 ) & 0x3) >> 1); // 1X 0X
|
||||
var t2 = Int1ToFillState(((f2 >> 2) & 0x3) >> 1); // 1X 0X
|
||||
var t3 = Int1ToFillState(((f2 >> 4) & 0x3) >> 1); // 1X 0X
|
||||
var t4 = Int1ToFillState(((f2 >> 6) & 0x3) >> 1); // 1X 0X
|
||||
var t5 = Int1ToFillState(((f2 >> 8) & 0x3) >> 1); // 1X 0X
|
||||
var t6 = Int1ToFillState((f2 >> 10) & 0x1); // 1 0
|
||||
var t7 = Int1ToFillState((f2 >> 11) & 0x1); // 1 0
|
||||
var t8 = Int1ToFillState((f2 >> 12) & 0x1); // 1 0
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public static class UpdateService {
|
||||
|
||||
public static async Task<(string Version, string Url, long Size)?> GetLatestInstallerUrl(string feedUrl) {
|
||||
try {
|
||||
using var client = new HttpClient() {
|
||||
Timeout = TimeSpan.FromSeconds(5),
|
||||
};
|
||||
client.DefaultRequestHeaders.UserAgent.Clear();
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd($"PamhagenSysCtrl/{App.Version} ({Environment.MachineName}, {Environment.OSVersion})");
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
client.DefaultRequestHeaders.Accept.Add(new("application/json"));
|
||||
using var res = await client.GetAsync(feedUrl);
|
||||
if (!res.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var json = JsonNode.Parse(await res.Content.ReadAsStringAsync());
|
||||
var latest = json!["data"]!.AsArray()[^1]!;
|
||||
return ((string)latest["version"]!, (string)latest["url"]!, (long)latest["size"]!);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task DownloadInstaller(string url, string filename, IProgress<double>? progress = null, CancellationToken cancellationToken = default) {
|
||||
try {
|
||||
using var client = new HttpClient() {
|
||||
Timeout = TimeSpan.FromSeconds(5),
|
||||
};
|
||||
client.DefaultRequestHeaders.UserAgent.Clear();
|
||||
client.DefaultRequestHeaders.UserAgent.ParseAdd($"PamhagenSysCtrl/{App.Version} ({Environment.MachineName}, {Environment.OSVersion})");
|
||||
client.DefaultRequestHeaders.Accept.Clear();
|
||||
using var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
var contentLength = response.Content.Headers.ContentLength;
|
||||
|
||||
await using (var destination = new FileStream(filename, FileMode.Create)) {
|
||||
await using var source = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||
var buffer = new byte[81920];
|
||||
long downloaded = 0;
|
||||
int read;
|
||||
while ((read = await source.ReadAsync(buffer, cancellationToken)) != 0) {
|
||||
await destination.WriteAsync(buffer.AsMemory(0, read), cancellationToken);
|
||||
downloaded += read;
|
||||
if (contentLength.HasValue) {
|
||||
progress?.Report((double)downloaded / contentLength.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
progress?.Report(1);
|
||||
} catch {
|
||||
File.Delete(filename);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void StartInstaller(string fileName) {
|
||||
var startInfo = new ProcessStartInfo {
|
||||
FileName = "msiexec.exe",
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
};
|
||||
startInfo.ArgumentList.Add("/i");
|
||||
startInfo.ArgumentList.Add(Path.GetFullPath(fileName));
|
||||
|
||||
if (Process.Start(startInfo) == null) {
|
||||
throw new InvalidOperationException("Der Installer konnte nicht gestartet werden.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<Window x:Class="PamhagenSysCtrl.Windows.AboutWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Title="Über - Anlagensteuerung Pamhagen"
|
||||
Height="340" Width="560" ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterOwner">
|
||||
<Grid>
|
||||
<TextBlock Margin="20,10" FontSize="12">
|
||||
<Bold>Produkt:</Bold> Anlagensteuerung Pamhagen<LineBreak/>
|
||||
<Bold>Beschreibung:</Bold> Schnittstelle zu einer SPS und grafische Benutzeroberfläche für die<LineBreak/>
|
||||
<Bold Foreground="Transparent">Beschreibung:</Bold> Steuerung der Anlage<LineBreak/>
|
||||
<Bold>Typ:</Bold> HMI- und SPS-Steuerungssoftware<LineBreak/>
|
||||
<Bold>Version:</Bold> <Run x:Name="VersionText">0.0.0</Run><LineBreak/>
|
||||
<Bold>Lizenz:</Bold> <Hyperlink NavigateUri="https://www.gnu.org/licenses/gpl-3.0.html" RequestNavigate="Hyperlink_RequestNavigate">GNU General Public License 3.0 (GPLv3)</Hyperlink><LineBreak/>
|
||||
<Bold>Entwickler:</Bold> Lorenz Stechauner, Thomas Hilscher<LineBreak/>
|
||||
<Bold>Kontakt:</Bold> <Hyperlink NavigateUri="mailto:lorenz.stechauner@necronda.net" RequestNavigate="Hyperlink_RequestNavigate">lorenz.stechauner@necronda.net</Hyperlink>, <Hyperlink NavigateUri="mailto:thomas.hilscher@gmail.com" RequestNavigate="Hyperlink_RequestNavigate">thomas.hilscher@gmail.com</Hyperlink><LineBreak/>
|
||||
<Bold>Quellcode:</Bold> <Hyperlink NavigateUri="C:\Program Files\Anlagensteuerung Pamhagen\src" RequestNavigate="Hyperlink_RequestNavigate_Explorer">C:\Program Files\Anlagensteuerung Pamhagen\src</Hyperlink>,<LineBreak/>
|
||||
<Bold Foreground="Transparent">Quellcode:</Bold> <Hyperlink NavigateUri="https://git.necronda.net/winzer/pamhagen-sysctrl" RequestNavigate="Hyperlink_RequestNavigate">https://git.necronda.net/winzer/pamhagen-sysctrl</Hyperlink><LineBreak/>
|
||||
<Bold>Entwicklungszeitraum:</Bold> 2026<LineBreak/>
|
||||
<LineBreak/>
|
||||
<Bold>Verwendete Technologien:</Bold><LineBreak/>
|
||||
Programmiersprache: C#<LineBreak/>
|
||||
Framework: Windows Presentation Framework (WPF)<LineBreak/>
|
||||
SPS-Schnittstelle: Serielle Verbindung<LineBreak/>
|
||||
Paketierung: <Hyperlink NavigateUri="https://www.firegiant.com/wixtoolset/" RequestNavigate="Hyperlink_RequestNavigate">WiX Toolset</Hyperlink>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace PamhagenSysCtrl.Windows {
|
||||
public partial class AboutWindow : Window {
|
||||
|
||||
public AboutWindow() {
|
||||
InitializeComponent();
|
||||
VersionText.Text = App.Version.ToString();
|
||||
}
|
||||
|
||||
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs evt) {
|
||||
try {
|
||||
Process.Start(new ProcessStartInfo(evt.Uri.AbsoluteUri) { UseShellExecute = true });
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private void Hyperlink_RequestNavigate_Explorer(object sender, RequestNavigateEventArgs evt) {
|
||||
try {
|
||||
Process.Start("explorer.exe", evt.Uri.AbsoluteUri);
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}
|
||||
|
||||
@@ -45,11 +45,16 @@
|
||||
</MenuItem>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Hilfe">
|
||||
<MenuItem Header="Über">
|
||||
<MenuItem Header="Über" Click="Menu_Help_About_Click">
|
||||
<MenuItem.Icon>
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text=""/>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem x:Name="Menu_Help_CheckForUpdates" Header="Nach Updates suchen..." Click="Menu_Help_CheckForUpdates_Click">
|
||||
<MenuItem.Icon>
|
||||
<TextBlock FontFamily="Segoe MDL2 Assets" FontSize="16" Text=""/>
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
@@ -57,11 +62,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,52 @@ 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;
|
||||
Menu_Help_CheckForUpdates.IsEnabled = App.Config.UpdateUrl != null;
|
||||
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 +118,109 @@ namespace PamhagenSysCtrl.Windows {
|
||||
} catch { }
|
||||
}
|
||||
|
||||
private async void Menu_Help_CheckForUpdates_Click(object sender, RoutedEventArgs evt) {
|
||||
await App.CheckForUpdates(true);
|
||||
}
|
||||
|
||||
private void Menu_Help_About_Click(object sender, RoutedEventArgs evt) {
|
||||
var window = new AboutWindow {
|
||||
Owner = this,
|
||||
};
|
||||
window.Show();
|
||||
}
|
||||
|
||||
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 +247,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 +354,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 +389,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 +442,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;
|
||||
}
|
||||
|
||||
@@ -1,2 +1,42 @@
|
||||
|
||||
# Anlagensteuerung Pamhangen
|
||||
Anlagensteuerung Pamhagen
|
||||
=========================
|
||||
|
||||
Schnittstelle zur SPS und grafische Benutzeroberfläche.
|
||||
Winzerkeller Seewinkel, Pamhagen.
|
||||
|
||||
|
||||
About
|
||||
=====
|
||||
|
||||
**Product:** Anlagensteuerung Pamhagen
|
||||
**Description:** Interface to a LPC and graphical user interface for controlling the plant/system
|
||||
**Type:** HMI and PLC Control Software
|
||||
**Version:** 0.0.3 ([Changelog](./CHANGELOG.md))
|
||||
**License:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Source code:** https://git.necronda.net/winzer/pamhagen-sysctrl
|
||||
**Developement period:** 2026
|
||||
|
||||
**Technology Stack:**
|
||||
Language: C#
|
||||
Framework: Windows Presentation Framework (WPF)
|
||||
LPC-Interface: Serial connection
|
||||
Packaging: [WiX Toolset](https://www.firegiant.com/wixtoolset/)
|
||||
|
||||
|
||||
Über
|
||||
====
|
||||
|
||||
**Produkt:** Anlagensteuerung Pamhagen
|
||||
**Beschreibung:** Schnittstelle zu einer SPS und grafische Benutzeroberfläche für die Steuerung der Anlage
|
||||
**Typ:** HMI- und SPS-Steuerungssoftware
|
||||
**Version:** 0.0.3 ([Änderungsprotokoll](./CHANGELOG.md))
|
||||
**Lizenz:** [GNU General Public License 3.0 (GPLv3)](./LICENSE)
|
||||
**Quellcode:** https://git.necronda.net/winzer/pamhagen-sysctrl
|
||||
**Entwicklungszeitraum:** 2026
|
||||
|
||||
**Verwendete Technologien:**
|
||||
Programmiersprache: C#
|
||||
Framework: Windows Presentation Framework (WPF)
|
||||
SPS-Schnittstelle: Serielle Verbindung
|
||||
Paketierung: [WiX Toolset](https://www.firegiant.com/wixtoolset/)
|
||||
|
||||
Reference in New Issue
Block a user