aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-13 22:04:35 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-11-13 22:04:35 +0200
commit9171be1942bf2368dd9e408e6a51a3c667056ec9 (patch)
treec2d686e384ef59e4dd2c625f23d4f0e882bd635c /Software/Visual_Studio/Utilities
parente76eb4aa4d7e4c4762995144765b5ee6e9532961 (diff)
parent8651169fac81e34685f52f8bb9147115f7ac8765 (diff)
downloadTango-9171be1942bf2368dd9e408e6a51a3c667056ec9.tar.gz
Tango-9171be1942bf2368dd9e408e6a51a3c667056ec9.zip
MERGED FSE configuration to master.
Diffstat (limited to 'Software/Visual_Studio/Utilities')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Converters/EventTypeToStringConverter.cs29
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml25
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml.cs56
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/MainWindow.xaml2
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Tango.MachineEM.UI.csproj10
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs122
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml26
7 files changed, 263 insertions, 7 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Converters/EventTypeToStringConverter.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Converters/EventTypeToStringConverter.cs
new file mode 100644
index 000000000..de771f2a8
--- /dev/null
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Converters/EventTypeToStringConverter.cs
@@ -0,0 +1,29 @@
+using Google.Protobuf.Reflection;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using Tango.PMR.Diagnostics;
+
+namespace Tango.MachineEM.UI.Converters
+{
+ public class EventTypeToStringConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ EventType eventType = (EventType)value;
+ FieldInfo fi = value.GetType().GetField(eventType.ToString());
+ String name = fi.GetCustomAttribute<OriginalNameAttribute>().Name;
+ return $"{(int)eventType} {name}";
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml
new file mode 100644
index 000000000..05a4b33cd
--- /dev/null
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml
@@ -0,0 +1,25 @@
+<Window x:Class="Tango.MachineEM.UI.InputWindow"
+ 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:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
+ xmlns:local="clr-namespace:Tango.MachineEM.UI"
+ mc:Ignorable="d"
+ Title="Input" Height="250" Width="600">
+ <Grid>
+ <DockPanel>
+ <UniformGrid Columns="2" DockPanel.Dock="Bottom" HorizontalAlignment="Right" Height="45">
+ <Button x:Name="btnCancel" Width="150" Margin="5" Style="{StaticResource AccentedSquareButtonStyle}" BorderThickness="0" mahapps:ButtonHelper.PreserveTextCase="True">CANCEL</Button>
+ <Button IsDefault="True" x:Name="btnOK" Width="150" Margin="5" Style="{StaticResource AccentedSquareButtonStyle}" BorderThickness="0" mahapps:ButtonHelper.PreserveTextCase="True">OK</Button>
+ </UniformGrid>
+
+ <Rectangle DockPanel.Dock="Bottom" Stroke="#494949" StrokeThickness="1" />
+
+ <StackPanel Margin="40">
+ <TextBlock x:Name="txtMessage" Text="Please enter a value" Foreground="Gainsboro"></TextBlock>
+ <TextBox x:Name="txtValue" Margin="0 10 120 0"></TextBox>
+ </StackPanel>
+ </DockPanel>
+ </Grid>
+</Window>
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml.cs
new file mode 100644
index 000000000..191b53072
--- /dev/null
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/InputWindow.xaml.cs
@@ -0,0 +1,56 @@
+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 Tango.MachineEM.UI
+{
+ /// <summary>
+ /// Interaction logic for InputWindow.xaml
+ /// </summary>
+ public partial class InputWindow : Window
+ {
+ public String Value { get; set; }
+ public String Message { get; set; }
+
+ public InputWindow()
+ {
+ InitializeComponent();
+
+ btnOK.Click += BtnOK_Click;
+ btnCancel.Click += BtnCancel_Click;
+ Loaded += InputWindow_Loaded;
+ }
+
+ private void InputWindow_Loaded(object sender, RoutedEventArgs e)
+ {
+ txtValue.Text = Value;
+ txtMessage.Text = Message;
+
+ txtValue.Focus();
+ Keyboard.Focus(txtValue);
+ }
+
+ private void BtnCancel_Click(object sender, RoutedEventArgs e)
+ {
+ DialogResult = false;
+ Close();
+ }
+
+ private void BtnOK_Click(object sender, RoutedEventArgs e)
+ {
+ Value = txtValue.Text;
+ DialogResult = true;
+ Close();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/MainWindow.xaml
index 7bfc7f0fd..8f066800e 100644
--- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/MainWindow.xaml
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/MainWindow.xaml
@@ -9,7 +9,7 @@
xmlns:local="clr-namespace:Tango.MachineEM.UI"
xmlns:views="clr-namespace:Tango.MachineEM.UI.Views"
mc:Ignorable="d"
- Title="Tango Embedded Emulator" Height="720" Width="1300" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen" Background="#202020" Foreground="Gainsboro" DataContext="{Binding RelativeSource={RelativeSource Self}}">
+ Title="Tango Embedded Emulator" Height="820" Width="1300" TitleCaps="False" BorderBrush="Gray" BorderThickness="1" WindowStartupLocation="CenterScreen" Background="#202020" Foreground="Gainsboro" DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<views:MainView DataContext="{StaticResource MainViewVM}"></views:MainView>
</Grid>
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Tango.MachineEM.UI.csproj b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Tango.MachineEM.UI.csproj
index 705194057..c6f382afe 100644
--- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Tango.MachineEM.UI.csproj
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Tango.MachineEM.UI.csproj
@@ -83,6 +83,10 @@
<Compile Include="Controls\InkFillingStatusView.xaml.cs">
<DependentUpon>InkFillingStatusView.xaml</DependentUpon>
</Compile>
+ <Compile Include="Converters\EventTypeToStringConverter.cs" />
+ <Compile Include="InputWindow.xaml.cs">
+ <DependentUpon>InputWindow.xaml</DependentUpon>
+ </Compile>
<Compile Include="ViewModels\MainViewVM.cs" />
<Compile Include="Views\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
@@ -91,6 +95,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
+ <Page Include="InputWindow.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -200,7 +208,7 @@
</PropertyGroup>
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
index b46b89a4a..c993be2d7 100644
--- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
@@ -13,6 +13,8 @@ using Tango.Transport.Transporters;
using Tango.Core;
using Tango.Settings;
using Tango.PMR.ThreadLoading;
+using Tango.PMR.DataStore;
+using System.Windows;
namespace Tango.MachineEM.UI.ViewModels
{
@@ -138,6 +140,10 @@ namespace Tango.MachineEM.UI.ViewModels
/// </summary>
public RelayCommand AbortJobCommand { get; set; }
+ public RelayCommand GetDataStoreItemCommand { get; set; }
+
+ public RelayCommand PutDataStoreItemCommand { get; set; }
+
public RelayCommand PerformDataStoreTestCommand { get; set; }
#endregion
@@ -191,6 +197,8 @@ namespace Tango.MachineEM.UI.ViewModels
SelectedPort = Ports.First();
PerformDataStoreTestCommand = new RelayCommand(Emulator.PerformDataStoreTest);
+ GetDataStoreItemCommand = new RelayCommand(GetDataStoreItem);
+ PutDataStoreItemCommand = new RelayCommand(PutDataStoreItem);
}
#endregion
@@ -282,6 +290,120 @@ namespace Tango.MachineEM.UI.ViewModels
InvalidateRelayCommands();
}
+ private void GetDataStoreItem()
+ {
+ try
+ {
+ var result = GetUserInput<String>("Get Data Store Item", "Enter collection name", String.Empty);
+ if (!result.Confirmed) return;
+ var collectionName = result.Value;
+
+ result = GetUserInput<String>("Get Data Store Item", "Enter item key", String.Empty);
+ if (!result.Confirmed) return;
+ var key = result.Value;
+
+ Emulator.GetDataStoreItem(new PMR.DataStore.GetDataStoreItemRequest()
+ {
+ Collection = collectionName,
+ Key = key
+ });
+ }
+ catch { }
+ }
+
+ private void PutDataStoreItem()
+ {
+ try
+ {
+ var result = GetUserInput<String>("Put Data Store Item", "Enter collection name", String.Empty);
+ if (!result.Confirmed) return;
+ var collectionName = result.Value;
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter item key", String.Empty);
+ if (!result.Confirmed) return;
+ var key = result.Value;
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter data type", "Int32");
+ if (!result.Confirmed) return;
+ DataType dataType = (DataType)Enum.Parse(typeof(DataType), result.Value);
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter value", "10");
+ if (!result.Confirmed) return;
+ var value = result.Value;
+
+ DataStoreItem item = new DataStoreItem();
+ item.DataType = dataType;
+
+ switch (dataType)
+ {
+ case DataType.Int32:
+ item.Int32Value = int.Parse(value);
+ break;
+ case DataType.Float:
+ item.FloatValue = float.Parse(value);
+ break;
+ case DataType.Double:
+ item.DoubleValue = double.Parse(value);
+ break;
+ case DataType.Boolean:
+ item.BooleanValue = bool.Parse(value);
+ break;
+ case DataType.String:
+ item.StringValue = value;
+ break;
+ default:
+ LogManager.Log("Data type not supported by this emulator.");
+ throw new NotSupportedException();
+ }
+
+ Emulator.PutDataStoreItem(new PutDataStoreItemRequest()
+ {
+ Collection = collectionName,
+ Key = key,
+ Item = item
+ });
+ }
+ catch { }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private class InputResult<T>
+ {
+ public bool Confirmed { get; set; }
+ public T Value { get; set; }
+ }
+
+ private InputResult<T> GetUserInput<T>(String title, String message, T defaultValue)
+ {
+ InputWindow window = new InputWindow();
+ window.Title = title;
+ window.Message = message;
+ window.Value = defaultValue.ToStringSafe();
+ window.Owner = Application.Current.MainWindow;
+ window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
+ window.WindowStyle = WindowStyle.ToolWindow;
+
+ try
+ {
+ if (window.ShowDialog().Value)
+ {
+ return new InputResult<T>() { Confirmed = true, Value = (T)Convert.ChangeType(window.Value, typeof(T)) };
+ }
+ else
+ {
+ return new InputResult<T>();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error parsing input.");
+ throw ex;
+ }
+ }
+
#endregion
}
}
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml
index f553ec588..c0c4b7b97 100644
--- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/Views/MainView.xaml
@@ -11,13 +11,15 @@
xmlns:vm="clr-namespace:Tango.MachineEM.UI.ViewModels"
xmlns:pmr="clr-namespace:Tango.PMR.MachineStatus;assembly=Tango.PMR"
xmlns:threadLoading="clr-namespace:Tango.PMR.ThreadLoading;assembly=Tango.PMR"
+ xmlns:localConverters="clr-namespace:Tango.MachineEM.UI.Converters"
xmlns:local="clr-namespace:Tango.MachineEM.UI.Views"
mc:Ignorable="d"
- d:DesignHeight="720" d:DesignWidth="1300" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" >
+ d:DesignHeight="780" d:DesignWidth="1300" Foreground="Gainsboro" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" >
<UserControl.Resources>
<converters:BooleanInverseConverter x:Key="BooleanInverseConverter"></converters:BooleanInverseConverter>
<converters:EnumToItemsSourceConverter x:Key="EnumToItemsSourceConverter" />
+ <localConverters:EventTypeToStringConverter x:Key="EventTypeToStringConverter" />
</UserControl.Resources>
<Grid>
<Grid.Background>
@@ -150,14 +152,28 @@
<Button Padding="10 0 0 0" Margin="5" Height="45" HorizontalContentAlignment="Left" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding AbortJobCommand}">
<DockPanel>
<fa:ImageAwesome Icon="ExclamationTriangle" Width="16"></fa:ImageAwesome>
- <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">ABORT JOB</TextBlock>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Center">ABORT JOB</TextBlock>
</DockPanel>
</Button>
- <Button Padding="10 0 0 0" Margin="5" Height="45" HorizontalContentAlignment="Left" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding PerformDataStoreTestCommand}">
+ <Button Padding="10 0 0 0" Margin="5" HorizontalContentAlignment="Left" Height="45" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding PerformDataStoreTestCommand}">
<DockPanel>
<fa:ImageAwesome Icon="Database" Width="16"></fa:ImageAwesome>
- <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">DATASTORE TEST</TextBlock>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Center">DATASTORE TEST</TextBlock>
+ </DockPanel>
+ </Button>
+
+ <Button Padding="10 0 0 0" Margin="5" HorizontalContentAlignment="Left" Height="45" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding GetDataStoreItemCommand}">
+ <DockPanel>
+ <fa:ImageAwesome Icon="Download" Width="16"></fa:ImageAwesome>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Center">GET DATA STORE ITEM</TextBlock>
+ </DockPanel>
+ </Button>
+
+ <Button HorizontalContentAlignment="Left" Padding="10 0 0 0" Margin="5" Height="45" Style="{StaticResource AccentedSquareButtonStyle}" mahapps:ButtonHelper.PreserveTextCase="True" BorderThickness="0" Command="{Binding PutDataStoreItemCommand}">
+ <DockPanel>
+ <fa:ImageAwesome Icon="Upload" Width="16"></fa:ImageAwesome>
+ <TextBlock Margin="10 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Center">PUT DATA STORE ITEM</TextBlock>
</DockPanel>
</Button>
<!--BUTTONS HERE-->
@@ -183,7 +199,7 @@
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
- <CheckBox FontSize="11" Content="{Binding EventType}" IsChecked="{Binding IsActive}" Margin="5"></CheckBox>
+ <CheckBox FontSize="11" Content="{Binding EventType,Converter={StaticResource EventTypeToStringConverter}}" IsChecked="{Binding IsActive}" Margin="5"></CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>