Push Changes from Techcrafters Repo

This commit is contained in:
2026-03-05 14:37:43 +01:00
parent d2665d17fa
commit 9636ff0457
215 changed files with 5052 additions and 14150 deletions

View File

@@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:local="clr-namespace:InfineonHMI"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"

View File

@@ -1,22 +1,21 @@
using System.Windows.Controls;
namespace InfineonHMI
{
/// <summary>
/// Interaktionslogik für SettingsPageView.xaml
/// </summary>
public partial class SettingsPage : Page
{
public SettingsPage()
{
InitializeComponent();
Unloaded += OnUnloaded;
}
namespace InfineonHMI;
private void OnUnloaded(object? sender, EventArgs e)
{
var disposable = DataContext as IDisposable;
disposable?.Dispose();
}
}
}
/// <summary>
/// Interaktionslogik für SettingsPageView.xaml
/// </summary>
public partial class SettingsPage : Page
{
public SettingsPage()
{
InitializeComponent();
Unloaded += OnUnloaded;
}
private void OnUnloaded(object? sender, EventArgs e)
{
var disposable = DataContext as IDisposable;
disposable?.Dispose();
}
}

View File

@@ -7,119 +7,118 @@ using TwinCAT.Ads.TypeSystem;
using TwinCAT.TypeSystem;
using Heisig.HMI.AdsManager;
namespace InfineonHMI
namespace InfineonHMI;
public partial class SettingsEntry : ObservableObject
{
public partial class SettingsEntry : ObservableObject
{
[ObservableProperty]
private string name = "";
[ObservableProperty]
private string name = "";
[ObservableProperty]
private string instancePath = "";
[ObservableProperty]
private string instancePath = "";
[ObservableProperty]
private string? dataType;
[ObservableProperty]
private string? dataType;
[ObservableProperty]
private Object? value;
[ObservableProperty]
private Object? value;
public ObservableCollection<SettingsEntry> SubEntries { get; set; } = [];
public ObservableCollection<SettingsEntry> SubEntries { get; set; } = [];
[ObservableProperty]
private Visibility visibility = Visibility.Collapsed;
[ObservableProperty]
private Visibility visibility = Visibility.Collapsed;
private readonly IAdsManager _adsManager;
private readonly IAdsManager _adsManager;
public SettingsEntry(IAdsManager adsManager)
{
_adsManager = adsManager;
}
public SettingsEntry(IAdsManager adsManager)
{
_adsManager = adsManager;
}
partial void OnValueChanging(object? oldValue, object? newValue)
{
if (newValue == null)
{
newValue = oldValue;
return;
}
partial void OnValueChanging(object? oldValue, object? newValue)
{
if (newValue == null)
{
newValue = oldValue;
return;
}
try
{
_adsManager.WriteValue(InstancePath, newValue);
}
catch (Exception)
{
newValue = oldValue;
Debug.WriteLine("Value {0} could not be written to {1}", newValue, InstancePath);
}
}
}
public partial class SettingsPageVM : ObservableObject, IDisposable
{
public ObservableCollection<SettingsEntry> RootItem { get; private set; } = [];
private readonly IAdsManager _adsManager;
private readonly string _variableName;
public SettingsPageVM(IAdsManager adsManager, string variableName)
{
_adsManager = adsManager;
_variableName = variableName;
_adsManager.Register(_variableName, ConfigChangedEvent);
}
private void ConfigChangedEvent(object? sender, ValueChangedEventArgs e)
{
App.Current.Invoke(CreateSettingsTree);
}
private void CreateSettingsTree()
{
ISymbolLoader? symbolLoader = _adsManager.GetSymbolLoader();
if (symbolLoader == null)
return;
Symbol configSymbol = (Symbol)symbolLoader.Symbols[_variableName];
SettingsEntry entry = GetSymbol(configSymbol);
RootItem.Add(entry);
}
private SettingsEntry GetSymbol(Symbol symbol)
{
// Create Symbol
SettingsEntry entry = new(_adsManager)
{
Name = symbol.InstanceName,
InstancePath = symbol.InstancePath,
DataType = symbol.DataType?.Name
};
// Check if symbol has sub symbols
if (!symbol.IsPrimitiveType)
{
foreach (Symbol subSymbol in symbol.SubSymbols.Cast<Symbol>())
{
entry.SubEntries.Add(GetSymbol(subSymbol));
}
}
else
{
entry.Visibility = Visibility.Visible;
entry.Value = symbol.ReadValue();
}
return entry;
}
public void Dispose()
{
_adsManager?.Deregister(_variableName, ConfigChangedEvent);
}
}
try
{
_adsManager.WriteValue(InstancePath, newValue);
}
catch (Exception)
{
newValue = oldValue;
Debug.WriteLine("Value {0} could not be written to {1}", newValue, InstancePath);
}
}
}
public partial class SettingsPageVM : ObservableObject, IDisposable
{
public ObservableCollection<SettingsEntry> RootItem { get; private set; } = [];
private readonly IAdsManager _adsManager;
private readonly string _variableName;
public SettingsPageVM(IAdsManager adsManager, string variableName)
{
_adsManager = adsManager;
_variableName = variableName;
_adsManager.Register(_variableName, ConfigChangedEvent);
}
private void ConfigChangedEvent(object? sender, ValueChangedEventArgs e)
{
App.Current.Invoke(CreateSettingsTree);
}
private void CreateSettingsTree()
{
ISymbolLoader? symbolLoader = _adsManager.GetSymbolLoader();
if (symbolLoader == null)
return;
Symbol configSymbol = (Symbol)symbolLoader.Symbols[_variableName];
SettingsEntry entry = GetSymbol(configSymbol);
RootItem.Add(entry);
}
private SettingsEntry GetSymbol(Symbol symbol)
{
// Create Symbol
SettingsEntry entry = new(_adsManager)
{
Name = symbol.InstanceName,
InstancePath = symbol.InstancePath,
DataType = symbol.DataType?.Name
};
// Check if symbol has sub symbols
if (!symbol.IsPrimitiveType)
{
foreach (Symbol subSymbol in symbol.SubSymbols.Cast<Symbol>())
{
entry.SubEntries.Add(GetSymbol(subSymbol));
}
}
else
{
entry.Visibility = Visibility.Visible;
entry.Value = symbol.ReadValue();
}
return entry;
}
public void Dispose()
{
_adsManager?.Deregister(_variableName, ConfigChangedEvent);
}
}