Push Alpha Version

This commit is contained in:
2026-02-27 16:09:59 +01:00
parent a0ef457995
commit d2665d17fa
209 changed files with 13423 additions and 1034 deletions

View File

@@ -0,0 +1,127 @@
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace InfineonHMI.Common
{
public static class L4ItXmlSerializer
{
/// <summary>
/// Serializes an object.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="serializableObject"></param>
/// <param name="fileName"></param>
/// <param name="encrypt"></param>
/// <param name="rootElementName"></param>
public static void SerializeObject<T>(T serializableObject, string fileName, bool encrypt = false, string rootElementName = null)
{
if (string.IsNullOrEmpty(fileName))
return;
if (serializableObject == null)
return;
XmlSerializer serializer;
if (rootElementName != null)
{
var xmlRoot = new XmlRootAttribute(rootElementName);
serializer = new XmlSerializer(serializableObject.GetType(), xmlRoot);
}
else
{
serializer = new XmlSerializer(serializableObject.GetType());
}
try
{
var dir = new FileInfo(fileName).DirectoryName;
if (dir != null && !Directory.Exists(dir)) // Überprüfen Sie, ob dir nicht null ist, bevor Sie es verwenden
Directory.CreateDirectory(dir);
var xmlDocument = new XmlDocument();
using var stream = new MemoryStream();
serializer.Serialize(stream, serializableObject);
stream.Position = 0;
xmlDocument.Load(stream);
if (encrypt && false)
{
//FileEncryption.SaveEncryptedToFile(fileName, xmlDocument.OuterXml);
return;
}
xmlDocument.Save(fileName);
}
catch (Exception ex)
{
Console.Write(ex);
}
}
/// <summary>
/// Deserializes an xml file into an object list
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="fileName"></param>
/// <param name="decrypt"></param>
/// <param name="rootElementName"></param>
/// <returns></returns>
///
///
public static T DeSerializeObject<T>(string fileName, bool decrypt = false, string rootElementName = null)
{
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) return default!;
T objectOut;
try
{
string xmlString;
if (decrypt && false)
{
//xmlString = FileEncryption.ReadDecryptedFromFile(fileName)!;
}
else
{
var xmlDocument = new XmlDocument();
xmlDocument.Load(fileName);
xmlString = xmlDocument.OuterXml;
}
if (string.IsNullOrEmpty(xmlString))
{
// Handle empty xmlString if necessary
return default!;
}
using var read = new StringReader(xmlString);
var outType = typeof(T);
XmlSerializer serializer;
if (rootElementName != null)
{
var root = new XmlRootAttribute(rootElementName);
serializer = new XmlSerializer(outType, root);
}
else
{
serializer = new XmlSerializer(outType);
}
using XmlReader reader = new XmlTextReader(read);
objectOut = (T)serializer.Deserialize(reader)!;
}
catch (Exception ex)
{
Console.Write(ex);
return default!;
}
return objectOut;
}
}
}

View File

@@ -0,0 +1,83 @@
<UserControl x:Class="Common.MediaContainer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:common="clr-namespace:Common"
xmlns:HMIToolkit="clr-namespace:HMIToolkit"
d:DataContext="{d:DesignInstance Type=common:MediaContainerVm, IsDesignTimeCreatable=True}"
mc:Ignorable="d"
Width="Auto"
Height="Auto"
MinWidth="200">
<UserControl.Resources>
<HMIToolkit:FeedbackToColorConverter x:Key="feedbackConverter" />
</UserControl.Resources>
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
<!-- Style to see things in the designer-->
<d:DesignerProperties.DesignStyle>
<Style TargetType="UserControl">
<!-- Property="Background" Value="White" /> -->
<Setter Property="Height" Value="300" />
<Setter Property="Width" Value="100" />
</Style>
</d:DesignerProperties.DesignStyle>
<Grid Height="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10*"/>
<RowDefinition Height="30*"/>
<RowDefinition Height="30*"/>
<RowDefinition Height="30*"/>
</Grid.RowDefinitions>
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="2"/>
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding SName, Mode=OneWay }" HorizontalAlignment="Center" FontSize="24"/>
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
<Label Grid.Row="0" VerticalAlignment="Center" Content="Übervoll" HorizontalAlignment="Center" FontSize="16"/>
<RadioButton Margin="5" Grid.Row="1" IsChecked="{Binding Overload}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Column="0" Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
<Label Grid.Row="0" VerticalAlignment="Center" Content="Voll" HorizontalAlignment="Center" FontSize="16"/>
<RadioButton Grid.Row="1" Margin="5" IsChecked="{Binding Full}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Row="3">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
<Label Grid.Row="0" VerticalAlignment="Center" Content="Leer" HorizontalAlignment="Center" FontSize="16"/>
<RadioButton Grid.Row="1" Margin="5" IsChecked="{Binding Empty}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Border Grid.Column="1" Grid.Row="1" Grid.RowSpan="3" BorderBrush="White" BorderThickness="1"></Border>
<Grid Grid.Column="1" Grid.Row="1" Grid.RowSpan="3">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Button x:Name="btnFill" DataContext="{Binding FillButton}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" Grid.Row="0" Grid.Column="0" Content="Füllen" Margin="5" />
<Button x:Name="btnOpen" DataContext="{Binding EmptyButton}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" Grid.Row="1" Grid.Column="0" Content="Leeren" Margin="5" />
</Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,32 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Input;
namespace Common
{
/// <summary>
/// Interaktionslogik für AnalogValue.xaml
/// </summary>
public partial class MediaContainer : UserControl
{
public bool IsReadonly { get; set; }
public MediaContainer()
{
InitializeComponent();
// Unloaded += OnUnloaded;
}
private void OnUnloaded(object? sender, EventArgs e)
{
var disposable = DataContext as IDisposable;
disposable?.Dispose();
}
private void NumberValidation(object sender, TextCompositionEventArgs e)
{
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
e.Handled = regex.IsMatch(e.Text);
}
}
}

View File

@@ -0,0 +1,76 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel.DataAnnotations;
using TwinCAT.TypeSystem;
using Heisig.HMI.AdsManager;
using HMIToolkit;
namespace Common;
public sealed partial class MediaContainerVm : ObservableValidator, IDisposable
{
private IAdsManager? _adsManager;
private string? _variableName;
[ObservableProperty] private string? sName = "No Name";
[ObservableProperty] private bool empty = false;
[ObservableProperty] private bool full = false;
[ObservableProperty] private bool overload = false;
[ObservableProperty] private HMIControlButtonVM? emptyButton;
[ObservableProperty] private HMIControlButtonVM? fillButton;
public MediaContainerVm()
{
sName = "No Name";
EmptyButton = new HMIControlButtonVM();
FillButton = new HMIControlButtonVM();
}
public MediaContainerVm(IAdsManager adsManager, string variableName)
{
_adsManager = adsManager;
_variableName = variableName;
sName = "No Name";
EmptyButton = new HMIControlButtonVM(_adsManager, _variableName + ".stEmptyButton");
FillButton = new HMIControlButtonVM(_adsManager, _variableName + ".stFillButton");
_adsManager.Register(_variableName + ".xEmpty", EmptyChanged);
_adsManager.Register(_variableName + ".xFull", FullChanged);
_adsManager.Register(_variableName + ".xOverload", OverloadChanged);
}
private void EmptyChanged(object? sender, ValueChangedEventArgs e)
{
Empty = (bool)e.Value;
}
private void FullChanged(object? sender, ValueChangedEventArgs e)
{
Full = (bool)e.Value;
}
private void OverloadChanged(object? sender, ValueChangedEventArgs e)
{
Overload = (bool)e.Value;
}
public void Dispose()
{
EmptyButton?.Dispose();
EmptyButton = null;
FillButton?.Dispose();
FillButton = null;
_adsManager?.Deregister(_variableName + ".xEmpty", EmptyChanged);
_adsManager?.Deregister(_variableName + ".xFull", FullChanged);
_adsManager?.Deregister(_variableName + ".xOverload", OverloadChanged);
}
}

View File

@@ -0,0 +1,33 @@
<UserControl x:Class="Common.ParamControlFloat"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:local="clr-namespace:Common"
d:DataContext="{d:DesignInstance Type=local:ParamControlFloatVm, IsDesignTimeCreatable=True}"
mc:Ignorable="d"
Width="Auto"
Height="Auto">
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
<!-- Style to see things in the designer-->
<d:DesignerProperties.DesignStyle>
<Style TargetType="UserControl">
<!-- Property="Background" Value="White" /> -->
<Setter Property="Height" Value="40" />
<Setter Property="Width" Value="280" />
</Style>
</d:DesignerProperties.DesignStyle>
<Grid Height="Auto">
<Grid.ColumnDefinitions>
<!-- <ColumnDefinition Width="Auto" /> -->
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" Width="200"/>
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay, StringFormat=N2}" Grid.Column="1" MaxLines="1" Width="80" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,32 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Input;
namespace Common
{
/// <summary>
/// Interaktionslogik für AnalogValue.xaml
/// </summary>
public partial class ParamControlFloat : UserControl
{
public bool IsReadonly { get; set; }
public ParamControlFloat()
{
InitializeComponent();
// Unloaded += OnUnloaded;
}
private void OnUnloaded(object? sender, EventArgs e)
{
var disposable = DataContext as IDisposable;
disposable?.Dispose();
}
private void NumberValidation(object sender, TextCompositionEventArgs e)
{
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
e.Handled = regex.IsMatch(e.Text);
}
}
}

View File

@@ -0,0 +1,27 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel.DataAnnotations;
using TwinCAT.TypeSystem;
using Heisig.HMI.AdsManager;
namespace Common;
public sealed partial class ParamControlFloatVm : ObservableValidator, IDisposable
{
[ObservableProperty]
private string sName;
[ObservableProperty]
private float value;
public ParamControlFloatVm()
{
SName = "No Name:";
Value = 0.0f;
}
public void Dispose()
{
}
}

View File

@@ -0,0 +1,33 @@
<UserControl x:Class="Common.ParamControlInt"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:common="clr-namespace:Common"
d:DataContext="{d:DesignInstance Type=common:ParamControlIntVm, IsDesignTimeCreatable=True}"
mc:Ignorable="d"
Width="Auto"
Height="Auto">
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
<!-- Style to see things in the designer-->
<d:DesignerProperties.DesignStyle>
<Style TargetType="UserControl">
<!-- Property="Background" Value="White" /> -->
<Setter Property="Height" Value="40" />
<Setter Property="Width" Value="280" />
</Style>
</d:DesignerProperties.DesignStyle>
<Grid Height="Auto">
<Grid.ColumnDefinitions>
<!-- <ColumnDefinition Width="Auto" /> -->
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" Width="200"/>
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay}" Grid.Column="1" MaxLines="1" Width="80" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
</Grid>
</UserControl>

View File

@@ -0,0 +1,32 @@
using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Input;
namespace Common
{
/// <summary>
/// Interaktionslogik für AnalogValue.xaml
/// </summary>
public partial class ParamControlInt : UserControl
{
public bool IsReadonly { get; set; }
public ParamControlInt()
{
InitializeComponent();
// Unloaded += OnUnloaded;
}
private void OnUnloaded(object? sender, EventArgs e)
{
var disposable = DataContext as IDisposable;
disposable?.Dispose();
}
private void NumberValidation(object sender, TextCompositionEventArgs e)
{
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
e.Handled = regex.IsMatch(e.Text);
}
}
}

View File

@@ -0,0 +1,28 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System.ComponentModel.DataAnnotations;
using TwinCAT.TypeSystem;
using Heisig.HMI.AdsManager;
namespace Common;
public sealed partial class ParamControlIntVm : ObservableValidator, IDisposable
{
[ObservableProperty]
private string sName;
[ObservableProperty]
private int value;
public ParamControlIntVm()
{
SName = "No Name:";
Value = 0;
}
public void Dispose()
{
}
}