Skip to content

Commit

Permalink
#39 Simple digital signal UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Chmelar ml committed May 5, 2021
1 parent 3e94484 commit 5b2062f
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 31 deletions.
31 changes: 31 additions & 0 deletions src/TcoCore/src/TcoCore.Wpf/Converters/SignalToBrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using Vortex.Presentation.Wpf.Converters;

namespace TcoCore
{
public class SignalToBrushConverter : BaseConverter
{
public override object ToConvert(object value, Type targetType, object parameter, CultureInfo culture)
{
try
{
var signal = (bool)value;
if (signal)
{
return Application.Current.TryFindResource("SignalOnBrush") ?? Brushes.GreenYellow;
}
else
{
return Application.Current.TryFindResource("SignalOffBrush") ?? Brushes.DimGray;
}
}
catch (Exception e)
{
return Brushes.DarkGray;
}
}
}
}
4 changes: 2 additions & 2 deletions src/TcoElements/src/TcoElementsConnector/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace TcoElements
{
public static class Entry
{
const string AmdId = "172.20.10.2.1.1";
readonly static string AmdId = Environment.GetEnvironmentVariable("Tc3Target");

public static TcoElements.TcoElementsTwinController TcoElementsPlc
public static TcoElementsTwinController TcoElementsPlc
= new TcoElementsTwinController(Tc3ConnectorAdapter.Create(AmdId, 851, true));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<UserControl
x:Class="TcoElements.TcoDigitalSensorManualView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TcoElements="clr-namespace:TcoElements;assembly=TcoElementsConnector"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TcoElements"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tcoCore="clr-namespace:TcoCore;assembly=TcoCore.Wpf"
d:DesignWidth="800"
mc:Ignorable="d">
<d:UserControl.DataContext>
<TcoElements:TcoDigitalSensor />
</d:UserControl.DataContext>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.6*" SharedSizeGroup="Name" />
<ColumnDefinition Width="0.4*" />
</Grid.ColumnDefinitions>
<TextBlock Style="{DynamicResource MaterialDesignBody2TextBlock}" Text="{Binding ., Converter={tcoCore:NameOrSymbolConverter}}" />
<Border
Grid.Column="1"
Margin="5,0,5,0"
Background="{Binding Signal.Cyclic, Converter={tcoCore:SignalToBrushConverter}}"
CornerRadius="2" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.ComponentModel;
using System.Windows.Controls;

namespace TcoElements
{
/// <summary>
/// Interaction logic for TcoDigitalSensorManualView.xaml
/// </summary>
public partial class TcoDigitalSensorManualView : UserControl
{
public TcoDigitalSensorManualView()
{
if (DesignerProperties.GetIsInDesignMode(this))
{
this.DataContext = new TcoDigitalSensor();
}

InitializeComponent();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
<ProjectReference Include="..\..\TcoElementsConnector\TcoElementsConnector.csproj" />
</ItemGroup>

<ItemGroup>
<Page Update="Digital\TcoDigitalSensorManualView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
</Page>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
x:Class="TcoElements.SampleComponentManualView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:TcoElements="clr-namespace:TcoElements;assembly=TcoElementsConnector"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:TcoElements"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:TcoElements="clr-namespace:TcoElements;assembly=TcoElementsConnector"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.DataContext>
<TcoElements:SampleComponent />
</UserControl.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand All @@ -36,8 +33,14 @@
Minimum="{Binding InstanceMinValue}"
Value="{Binding Cyclic}" />
</GroupBox>
<GroupBox Grid.Row="2" Header="{Binding AttributeName}" DataContext="{Binding _addResult}">
<TextBlock Text="{Binding Cyclic}" HorizontalAlignment="Center" FontSize="20" />
<GroupBox
Grid.Row="2"
DataContext="{Binding _addResult}"
Header="{Binding AttributeName}">
<TextBlock
HorizontalAlignment="Center"
FontSize="20"
Text="{Binding Cyclic}" />
</GroupBox>
</Grid>
</UserControl>
2 changes: 1 addition & 1 deletion src/TcoElements/tests/Sandbox.TcoElements.Wpf/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ResourceDictionary.MergedDictionaries>
<materialDesign:BundledTheme
BaseTheme="Light"
PrimaryColor="DeepPurple"
PrimaryColor="DeepPurple"
SecondaryColor="Lime" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
Expand Down
3 changes: 2 additions & 1 deletion src/TcoElements/tests/Sandbox.TcoElements.Wpf/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public partial class App : Application
public App()
{
TcoCore.Threading.Dispatcher.SetDispatcher(TcoCore.Wpf.Threading.Dispatcher.Get);
Entry.TcoElementsPlc.Connector.BuildAndStart().ReadWriteCycleDelay = 75;
TcoElementsTests.Entry.TcoElementsTests.Connector.BuildAndStart().ReadWriteCycleDelay = 75;
//Entry.TcoElementsPlc.Connector.BuildAndStart().ReadWriteCycleDelay = 75;
}
}
}
58 changes: 47 additions & 11 deletions src/TcoElements/tests/Sandbox.TcoElements.Wpf/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,58 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Sandbox.TcoElements.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vortex="http://vortex.mts/xaml"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d"
Title="MainWindow">
mc:Ignorable="d">
<Window.DataContext>
<local:MainWindowViewModel />
</Window.DataContext>
<Grid Grid.Row="0" DataContext="{Binding TcoElementsPlc.MAIN._sampleContext, Mode=OneWay}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<vortex:RenderableContentControl Grid.Row="0" DataContext="{Binding _sampleComponent._sampleTask, Mode=OneWay}" PresentationType="Base" />
<vortex:RenderableContentControl Grid.Row="1" DataContext="{Binding _sampleComponent._sampleTask, Mode=OneWay}" PresentationType="ControlSlim" />
</Grid>
<TabControl>
<TabItem DataContext="{Binding TcoElementsTestsPlc.MAIN}" Header="Tests elemnts">
<StackPanel>
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _tcoDigitalSensorTests._sut}"
PresentationType="Manual" />
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _tcoDigitalSensorTests._sut}"
PresentationType="Manual" />
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _tcoDigitalSensorTests._sut}"
PresentationType="Manual" />
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _tcoDigitalSensorTests._sut}"
PresentationType="Manual" />
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _tcoDigitalSensorTests._sut}"
PresentationType="Manual" />
</StackPanel>

</TabItem>
<TabItem Header="Tasks">
<Grid Grid.Row="0" DataContext="{Binding TcoElementsPlc.MAIN._sampleContext, Mode=OneWay}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<vortex:RenderableContentControl
Grid.Row="0"
DataContext="{Binding _sampleComponent._sampleTask, Mode=OneWay}"
PresentationType="Base" />
<vortex:RenderableContentControl
Grid.Row="1"
DataContext="{Binding _sampleComponent._sampleTask, Mode=OneWay}"
PresentationType="ControlSlim" />
</Grid>

</TabItem>
</TabControl>

</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();

}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
using TcoElements;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Vortex.Connector;
using Vortex.Connector.ValueTypes;
using System.Linq;

namespace Sandbox.TcoElements.Wpf
{
{
public class MainWindowViewModel
{
public MainWindowViewModel()
{

}

public TcoElementsTwinController TcoElementsPlc { get; } = Entry.TcoElementsPlc;
public TcoElementsTests.TcoElementsTestsTwinController TcoElementsTestsPlc { get; } = TcoElementsTests.Entry.TcoElementsTests;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Wpf\TcoElements.Wpf\TcoElements.Wpf.csproj" />
<ProjectReference Include="..\TcoElementsTestsConnector\TcoElementsTestsConnector.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/TcoElements/tests/TcoElementsTestsConnector/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TcoElementsTests
{
public static class Entry
{
const string AmdId = "172.20.10.2.1.1";
readonly static string AmdId = Environment.GetEnvironmentVariable("Tc3Target");

public static TcoElementsTestsTwinController TcoElementsTests
= new TcoElementsTestsTwinController(Tc3ConnectorAdapter.Create(AmdId, 852, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
<LastGenOutput>Localizations.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>Sandbox.TcoElements.Wpf</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>

0 comments on commit 5b2062f

Please sign in to comment.