Initial Push
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<UserControl x:Class="HMIToolkit.IntlkDetails"
|
||||
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:HMIToolkit"
|
||||
d:DataContext="{d:DesignInstance Type=local:IntlkDetailsVM, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
MinWidth="500" MinHeight="300"
|
||||
d:DesignHeight="300" d:DesignWidth="500"
|
||||
>
|
||||
<UserControl.Resources>
|
||||
<local:BoolToBrushConverter x:Key="myBoolConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid Margin="5" ShowGridLines="True" >
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Row 0 -->
|
||||
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding InterlockName}" />
|
||||
|
||||
|
||||
<!-- Row 1 -->
|
||||
<!-- <ListBox Grid.Column="0" Grid.Row="1" ItemsSource="{Binding ListBoxItemsLeft}"/> -->
|
||||
|
||||
<!-- <ListBox Grid.Column="1" Grid.Row="1" ItemsSource="{Binding ListBoxItemsRight}" /> -->
|
||||
<Grid Grid.Column="0" Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Row 0 -->
|
||||
<Rectangle Grid.Row="0" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[0], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="0" Grid.Column="1" Content="{Binding InterlockNames[0]}" />
|
||||
|
||||
<!-- Row 1 -->
|
||||
<Rectangle Grid.Row="1" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[1], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="1" Grid.Column="1" Content="{Binding InterlockNames[1]}" />
|
||||
|
||||
<!-- Row 2 -->
|
||||
<Rectangle Grid.Row="2" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[2], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="2" Grid.Column="1" Content="{Binding InterlockNames[2]}" />
|
||||
|
||||
<!-- Row 3 -->
|
||||
<Rectangle Grid.Row="3" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[3], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="3" Grid.Column="1" Content="{Binding InterlockNames[3]}" />
|
||||
|
||||
<!-- Row 4 -->
|
||||
<Rectangle Grid.Row="4" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[4], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="4" Grid.Column="1" Content="{Binding InterlockNames[4]}" />
|
||||
|
||||
<!-- Row 5 -->
|
||||
<Rectangle Grid.Row="5" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[5], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="5" Grid.Column="1" Content="{Binding InterlockNames[5]}" />
|
||||
|
||||
<!-- Row 6 -->
|
||||
<Rectangle Grid.Row="6" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[6], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="6" Grid.Column="1" Content="{Binding InterlockNames[6]}" />
|
||||
|
||||
<!-- Row 7 -->
|
||||
<Rectangle Grid.Row="7" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[7], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="7" Grid.Column="1" Content="{Binding InterlockNames[7]}" />
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Column="1" Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Row 0 -->
|
||||
<Rectangle Grid.Row="0" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[8], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="0" Grid.Column="1" Content="{Binding InterlockNames[8]}" />
|
||||
|
||||
<!-- Row 1 -->
|
||||
<Rectangle Grid.Row="1" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[9], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="1" Grid.Column="1" Content="{Binding InterlockNames[9]}" />
|
||||
|
||||
<!-- Row 2 -->
|
||||
<Rectangle Grid.Row="2" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[10], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="2" Grid.Column="1" Content="{Binding InterlockNames[10]}" />
|
||||
|
||||
<!-- Row 3 -->
|
||||
<Rectangle Grid.Row="3" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[11], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="3" Grid.Column="1" Content="{Binding InterlockNames[11]}" />
|
||||
|
||||
<!-- Row 4 -->
|
||||
<Rectangle Grid.Row="4" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[12], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="4" Grid.Column="1" Content="{Binding InterlockNames[12]}" />
|
||||
|
||||
<!-- Row 5 -->
|
||||
<Rectangle Grid.Row="5" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[13], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="5" Grid.Column="1" Content="{Binding InterlockNames[13]}" />
|
||||
|
||||
<!-- Row 6 -->
|
||||
<Rectangle Grid.Row="6" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[14], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="6" Grid.Column="1" Content="{Binding InterlockNames[14]}" />
|
||||
|
||||
<!-- Row 7 -->
|
||||
<Rectangle Grid.Row="7" Grid.Column="0" Width="10" Height="10" Fill="{Binding Path=InterlockStatus[15], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
<Label Grid.Row="7" Grid.Column="1" Content="{Binding InterlockNames[15]}" />
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetails.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetails : UserControl
|
||||
{
|
||||
public IntlkDetails()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Collections;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
public sealed partial class IntlkDetailsVM : ObservableObject, IDisposable
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string interlockName;
|
||||
|
||||
[ObservableProperty]
|
||||
private BitArray interlockStatus;
|
||||
|
||||
[ObservableProperty]
|
||||
private string[] interlockNames;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsLeft;
|
||||
|
||||
[ObservableProperty]
|
||||
private ListBoxItem[] listBoxItemsRight;
|
||||
|
||||
[ObservableProperty]
|
||||
private Visibility isVisible;
|
||||
|
||||
private readonly BoolToBrushConverter boolToBrushConverter = new();
|
||||
|
||||
private readonly int numIntlksLeftSide;
|
||||
private readonly int numIntlksRightSide;
|
||||
|
||||
private readonly string _variableNameStatus;
|
||||
private readonly string _variableNameNames;
|
||||
|
||||
private IAdsManager? _adsManager;
|
||||
|
||||
public IntlkDetailsVM()
|
||||
{
|
||||
interlockName = "Interlocks";
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
Array.Fill(interlockNames, "Not used");
|
||||
|
||||
// Split all interlocks into two parts
|
||||
numIntlksLeftSide = (int)Math.Ceiling(HMIConstants.NumInterlocks * 0.5);
|
||||
numIntlksRightSide = HMIConstants.NumInterlocks - numIntlksLeftSide;
|
||||
|
||||
listBoxItemsLeft = new ListBoxItem[numIntlksLeftSide];
|
||||
listBoxItemsRight = new ListBoxItem[numIntlksRightSide];
|
||||
|
||||
_variableNameStatus = System.String.Empty;
|
||||
_variableNameNames = System.String.Empty;
|
||||
|
||||
// CreateContent();
|
||||
}
|
||||
|
||||
public IntlkDetailsVM(IAdsManager adsManager, string variableNameStatus, string variableNameNames, string intlkName) : this()
|
||||
{
|
||||
interlockName = intlkName;
|
||||
_variableNameStatus = variableNameStatus;
|
||||
_variableNameNames = variableNameNames;
|
||||
_adsManager = adsManager;
|
||||
|
||||
interlockStatus = new BitArray(HMIConstants.NumInterlocks);
|
||||
interlockNames = new string[HMIConstants.NumInterlocks];
|
||||
|
||||
_adsManager.Register(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager.Register(_variableNameNames, InterlockNamesChanged);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_adsManager?.Deregister(_variableNameStatus, InterlockStatusChanged);
|
||||
_adsManager?.Deregister(_variableNameNames, InterlockNamesChanged);
|
||||
|
||||
_adsManager = null;
|
||||
}
|
||||
|
||||
/*private void CreateContent()
|
||||
{
|
||||
// Create left side
|
||||
for (int i = 0; i < HMIConstants.NumInterlocks; i++)
|
||||
{
|
||||
// Create the stack panel
|
||||
StackPanel stackPanel = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Horizontal
|
||||
};
|
||||
|
||||
// Create the box
|
||||
// <Rectangle Width="10" Height="10" Fill="{Binding Path=InterlockStatus[10], Converter={StaticResource myBoolConverter}}" RadiusX="2" RadiusY="2" Margin="0,2,0,0"/>
|
||||
Rectangle rectangle = new Rectangle
|
||||
{
|
||||
Width = 10,
|
||||
Height = 10,
|
||||
RadiusX = 2,
|
||||
RadiusY = 2
|
||||
};
|
||||
|
||||
// Create binding
|
||||
Binding binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockStatus[" + i + "]"),
|
||||
Converter = boolToBrushConverter,
|
||||
};
|
||||
|
||||
// Set binding
|
||||
rectangle.SetBinding(Rectangle.FillProperty, binding);
|
||||
|
||||
// Create label
|
||||
Label label = new();
|
||||
binding = new()
|
||||
{
|
||||
Source = this,
|
||||
Path = new PropertyPath("InterlockNames[" + i + "]")
|
||||
};
|
||||
label.SetBinding(Label.ContentProperty, binding);
|
||||
|
||||
// Add items to stack panel
|
||||
stackPanel.Children.Add(rectangle);
|
||||
stackPanel.Children.Add(label);
|
||||
|
||||
// Add stack panel to listbox items
|
||||
ListBoxItem tempListBoxItem = new()
|
||||
{
|
||||
Content = stackPanel
|
||||
};
|
||||
if (i < numIntlksLeftSide)
|
||||
ListBoxItemsLeft[i] = tempListBoxItem;
|
||||
else
|
||||
ListBoxItemsRight[i - numIntlksLeftSide] = tempListBoxItem;
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
private void InterlockStatusChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
ushort temp = (ushort)e.Value;
|
||||
InterlockStatus = new BitArray(BitConverter.GetBytes(temp));
|
||||
}
|
||||
|
||||
private void InterlockNamesChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
InterlockNames = (string[])e.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Window xmlns:AdsSessionTest="clr-namespace:HMIToolkit" x:Class="HMIToolkit.IntlkDetailsWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:HMIToolkit"
|
||||
mc:Ignorable="d"
|
||||
SizeToContent="WidthAndHeight"
|
||||
Title="IntlkDetailsWindow" Height="450" Width="800">
|
||||
<Grid>
|
||||
<AdsSessionTest:IntlkDetails />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace HMIToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für IntlkDetailsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class IntlkDetailsWindow : Window
|
||||
{
|
||||
public IntlkDetailsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user