diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-01-24 18:30:53 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-01-24 18:30:53 +0200 |
| commit | 11e64f69d00d84974bb09bef6f921c7eeab7c47e (patch) | |
| tree | 4981a4e079bb4d4c669901ffad6387fcfc9ed1ff /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common | |
| parent | e82bd25172095f1a521a95179b35cb01db7e8a62 (diff) | |
| download | Tango-11e64f69d00d84974bb09bef6f921c7eeab7c47e.tar.gz Tango-11e64f69d00d84974bb09bef6f921c7eeab7c47e.zip | |
Added Graphs Drag & Drop to Developer Module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common')
6 files changed, 359 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml new file mode 100644 index 000000000..687bc6030 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml @@ -0,0 +1,90 @@ +<UserControl x:Class="Tango.MachineStudio.Common.Controls.RealTimeGraphControl" + 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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:graphEx="clr-namespace:RealTimeGraphEx.FastGraphs;assembly=RealTimeGraphEx" + xmlns:components="clr-namespace:RealTimeGraphEx.Components;assembly=RealTimeGraphEx" + xmlns:converters="clr-namespace:Tango.MachineStudio.Common.Converters" + xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls" + mc:Ignorable="d" + d:DesignHeight="150" d:DesignWidth="300"> + + <UserControl.Resources> + <ResourceDictionary> + <ResourceDictionary.MergedDictionaries> + <!--RealTimeGraphEx--> + <ResourceDictionary Source="pack://application:,,,/RealTimeGraphEx;component/Resources/Resources.xaml"></ResourceDictionary> + <ResourceDictionary Source="../Resources/MaterialDesign.xaml"></ResourceDictionary> + + <ResourceDictionary> + <Style TargetType="ContentControl" x:Key="graphContent"> + <Style.Setters> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <Grid MouseEnter="Graph_MouseEnter" MouseLeave="Graph_MouseLeave" ClipToBounds="True"> + <ContentControl Content="{Binding}"></ContentControl> + <Grid Opacity="0.8" HorizontalAlignment="Stretch" VerticalAlignment="Top" ClipToBounds="True" Height="35" Margin="0 -35 0 0"> + <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Top"> + <Button Margin="0 0 5 0" Click="OnGraphFullScreen" ToolTip="Full Screen" Width="24" Height="24" BorderBrush="Transparent" Background="{StaticResource AccentColorBrush}" Style="{StaticResource MaterialDesignFloatingActionAccentButton}" > + <materialDesign:PackIcon Kind="Fullscreen" HorizontalAlignment="Right" Width="20" Height="20" Foreground="{StaticResource WhiteBrush}" /> + </Button> + <Button Click="OnGraphRemove" ToolTip="Remove" Width="24" Height="24" BorderBrush="Transparent" Background="#FF7777" Style="{StaticResource MaterialDesignFloatingActionAccentButton}" > + <materialDesign:PackIcon Kind="CloseCircle" HorizontalAlignment="Right" Width="20" Height="20" Foreground="{StaticResource WhiteBrush}" /> + </Button> + </StackPanel> + </Grid> + </Grid> + </DataTemplate> + </Setter.Value> + </Setter> + </Style.Setters> + </Style> + </ResourceDictionary> + + <ResourceDictionary> + <converters:SecondsToGraphPointsConverter x:Key="secondsToPoints"></converters:SecondsToGraphPointsConverter> + </ResourceDictionary> + </ResourceDictionary.MergedDictionaries> + </ResourceDictionary> + </UserControl.Resources> + + <Grid> + <!--Temperature--> + <ContentControl Style="{StaticResource graphContent}" Margin="0 0 5 5" MinHeight="5"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="40"/> + <ColumnDefinition Width="438*"/> + </Grid.ColumnDefinitions> + + <Border BorderBrush="{StaticResource AccentColorBrush}" BorderThickness="1 1 0 1"> + <StackPanel Orientation="Horizontal"> + <components:YAxisScroll Interval="6" Graph="{Binding ElementName=Graph}" Width="35" Foreground="{StaticResource MaterialDesignLightForeground}" VerticalOffset="-5" FontSize="8" StringFormat="#0.0"></components:YAxisScroll> + <components:YAxisTicks SmallTickTemplate="{StaticResource graphTicksTemplate}" Width="5" SmallTicks="6" Foreground="{StaticResource MaterialDesignLightForeground}" BigTicks="10" Graph="{Binding ElementName=Graph}"></components:YAxisTicks> + </StackPanel> + </Border> + <Border Grid.Column="1" BorderThickness="1" BorderBrush="{StaticResource borderBrush}" Background="{DynamicResource graphBackground}" Margin="5 0 0 0"> + <graphEx:RealTimeGraphExLineErase x:Name="Graph" x:FieldModifier="public" Antialiased="True" RefreshRate="30" MarkerColor="{StaticResource graphsMarkerColor}" FillGraph="False" Stroke="DodgerBlue"> + <graphEx:RealTimeGraphExLineErase.Components> + <components:MouseValueToolTip ToolTipTemplate="{StaticResource graphTooltipTemplate}" /> + <components:GridLines Rows="4" Columns="6" GridBrush="{DynamicResource graphGridLinesBrush}"></components:GridLines> + </graphEx:RealTimeGraphExLineErase.Components> + <graphEx:RealTimeGraphExLineErase.InnerContent> + <Grid> + <Label Style="{StaticResource graphLabel}"> + <StackPanel Orientation="Horizontal"> + <TextBlock VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl,AncestorLevel=2},Path=SensorName,FallbackValue='Dispenser Motor'}"></TextBlock> + <TextBlock Foreground="Gray" Margin="10 0 0 0" FontFamily="Sylfaen Regular" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl,AncestorLevel=2},Path=SensorUnits,FallbackValue='(hz)'}"></TextBlock> + </StackPanel> + </Label> + </Grid> + </graphEx:RealTimeGraphExLineErase.InnerContent> + </graphEx:RealTimeGraphExLineErase> + </Border> + </Grid> + </ContentControl> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs new file mode 100644 index 000000000..6396ab91a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Common.Controls +{ + /// <summary> + /// Interaction logic for RealTimeGraphControl.xaml + /// </summary> + public partial class RealTimeGraphControl : UserControl + { + #region Properties + + /// <summary> + /// Gets or sets the name of the sensor. + /// </summary> + public String SensorName + { + get { return (String)GetValue(SensorNameProperty); } + set { SetValue(SensorNameProperty, value); } + } + public static readonly DependencyProperty SensorNameProperty = + DependencyProperty.Register("SensorName", typeof(String), typeof(RealTimeGraphControl), new PropertyMetadata(null)); + + /// <summary> + /// Gets or sets the sensor units. + /// </summary> + public String SensorUnits + { + get { return (String)GetValue(SensorUnitsProperty); } + set { SetValue(SensorUnitsProperty, value); } + } + public static readonly DependencyProperty SensorUnitsProperty = + DependencyProperty.Register("SensorUnits", typeof(String), typeof(RealTimeGraphControl), new PropertyMetadata(null)); + + + #endregion + + #region Events + + public event EventHandler GraphRemoveButtonPressed; + public event EventHandler GraphFullScreenButtonPressed; + + #endregion + + public RealTimeGraphControl() + { + InitializeComponent(); + } + + private void OnGraphFullScreen(object sender, RoutedEventArgs e) + { + GraphFullScreenButtonPressed?.Invoke(this, new EventArgs()); + } + + private void Graph_MouseEnter(object sender, MouseEventArgs e) + { + Grid mainGrid = sender as Grid; + var headerGrid = mainGrid.Children.OfType<Grid>().ToList().First(); + ThicknessAnimation ani = new ThicknessAnimation(); + ani.To = new Thickness(0, 0, 0, 0); + ani.Duration = TimeSpan.FromSeconds(0.2); + headerGrid.BeginAnimation(Grid.MarginProperty, ani); + } + + private void Graph_MouseLeave(object sender, MouseEventArgs e) + { + Grid mainGrid = sender as Grid; + var headerGrid = mainGrid.Children.OfType<Grid>().ToList().First(); + ThicknessAnimation ani = new ThicknessAnimation(); + ani.To = new Thickness(0, -35, 0, 0); + ani.Duration = TimeSpan.FromSeconds(0.2); + headerGrid.BeginAnimation(Grid.MarginProperty, ani); + } + + private void OnGraphRemove(object sender, RoutedEventArgs e) + { + GraphRemoveButtonPressed?.Invoke(this, new EventArgs()); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/SecondsToGraphPointsConverter.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/SecondsToGraphPointsConverter.cs new file mode 100644 index 000000000..17df7b9d5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/SecondsToGraphPointsConverter.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.MachineStudio.Common.Converters +{ + /// <summary> + /// Converts number of seconds to graph FIFO capacity. + /// </summary> + /// <seealso cref="System.Windows.Data.IValueConverter" /> + public class SecondsToGraphPointsConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + double arrLength = double.Parse(parameter.ToString()); + return Helpers.GraphsHelper.GetMaxPoints(arrLength); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + return value; + } + } +}
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Helpers/GraphsHelper.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Helpers/GraphsHelper.cs new file mode 100644 index 000000000..53e832eb5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Helpers/GraphsHelper.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; + +namespace Tango.MachineStudio.Common.Helpers +{ + /// <summary> + /// Contains RealTimeGraphEx helper methods. + /// </summary> + public static class GraphsHelper + { + /// <summary> + /// Gets the maximum points graph points by correlating between seconds duration from settings and expected graph points per frame. + /// </summary> + /// <param name="pointsPerFrame">Length of graph points per frame.</param> + /// <returns></returns> + public static int GetMaxPoints(double pointsPerFrame) + { + try + { + double seconds = SettingsManager.Default.MachineStudio.TechnicianModule.GraphsDuration; + double pullRate = SettingsManager.Default.MachineStudio.TechnicianModule.GraphsPullingInterval; + return (int)(((pullRate * pointsPerFrame * 10 * seconds) * (10 / pullRate)) * 0.65); + } + catch (Exception) + { + return 300; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index 58bb9ef34..cc18c31c5 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -2,6 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf" xmlns:editors="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" + xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Tango.MachineStudio.Common.Resources"> <ResourceDictionary.MergedDictionaries> <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> @@ -172,6 +173,102 @@ </Setter.Value> </Setter> </Style> + + + <!--Extensions--> + + <FontFamily x:Key="FontName">Segoe UI</FontFamily> + <FontFamily x:Key="NotesFont">Lucida Console</FontFamily> + + <sys:Double x:Key="ExtraExtraLargeFontSize">28</sys:Double> + <sys:Double x:Key="ExtraLargeFontSize">26</sys:Double> + <sys:Double x:Key="LargeFontSize">20</sys:Double> + <sys:Double x:Key="MediumFontSize">16</sys:Double> + <sys:Double x:Key="SmallFontSize">14</sys:Double> + <sys:Double x:Key="MiniFontSize">12</sys:Double> + <sys:Double x:Key="TinyFontSize">9</sys:Double> + + <!--Colors--> + <Color x:Key="borderColor">Silver</Color> + <Color x:Key="graphGridLinesColor">#FFE9E9E9</Color> + <Color x:Key="graphsMarkerColor">Gray</Color> + <Color x:Key="materialColor">#03A9F4</Color> + + <!--Brushes--> + <SolidColorBrush x:Key="borderBrush" Color="{StaticResource borderColor}"></SolidColorBrush> + <SolidColorBrush x:Key="graphGridLinesBrush" Color="{StaticResource graphGridLinesColor}"></SolidColorBrush> + <SolidColorBrush x:Key="BlackBrush" Color="#545454"></SolidColorBrush> + + <SolidColorBrush x:Key="graphGridLinesLightBrush" Color="{StaticResource graphGridLinesColor}"></SolidColorBrush> + <SolidColorBrush x:Key="graphGridLinesDarkBrush" Color="#FF2E2E2E"></SolidColorBrush> + + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="graphBackgroundLight"> + <GradientStop Color="White"/> + <GradientStop Color="#FFE9E9E9" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="graphBackgroundDark"> + <GradientStop Color="Black"/> + <GradientStop Color="#FF333333" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="graphBackground"> + <GradientStop Color="White"/> + <GradientStop Color="#FFE9E9E9" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="graphLabelBackground" Opacity="0.7"> + <GradientStop Color="White"/> + <GradientStop Color="#FFD9D9D9" Offset="1"/> + </LinearGradientBrush> + + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" x:Key="graphLegendBackground" Opacity="0.7"> + <GradientStop Color="#FFE9E9E9"/> + <GradientStop Color="#FFBDBDBD" Offset="1"/> + </LinearGradientBrush> + + <SolidColorBrush Color="#FFF1F1F1" x:Key="topBarBackgroundBrush"></SolidColorBrush> + <!--Brushes--> + + <!--Graph Label--> + <Style x:Key="graphLabel" TargetType="Label"> + <Style.Setters> + <Setter Property="IsHitTestVisible" Value="False"></Setter> + <Setter Property="Margin" Value="-1 -1 0 0"></Setter> + <Setter Property="HorizontalAlignment" Value="Left"></Setter> + <Setter Property="VerticalAlignment" Value="Top"></Setter> + <Setter Property="Padding" Value="0"></Setter> + <Setter Property="ContentTemplate"> + <Setter.Value> + <DataTemplate> + <Border Width="Auto" Padding="0 0 20 0" Height="25" BorderBrush="{StaticResource AccentColorBrush}" BorderThickness="1" CornerRadius="0 0 30 0" Background="{StaticResource graphLabelBackground}" > + <Label Margin="5 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="{StaticResource TinyFontSize}" Content="{Binding}"></Label> + </Border> + </DataTemplate> + </Setter.Value> + </Setter> + </Style.Setters> + </Style> + <!--Graph Label--> + + + <!--Graph Ticks Template--> + <DataTemplate x:Key="graphTicksTemplate"> + <Ellipse Width="3" Height="3" Margin="0 0 0 0" Fill="{StaticResource AccentColorBrush}"></Ellipse> + </DataTemplate> + <!--Graph Ticks Template--> + + <DataTemplate x:Key="graphTooltipTemplate"> + <Border CornerRadius="5" BorderThickness="1" BorderBrush="White" Padding="8" MinWidth="50" Margin="20 0 20 0"> + <Border.Background> + <SolidColorBrush Color="Black" Opacity="0.5"></SolidColorBrush> + </Border.Background> + <TextBlock Foreground="White" FontSize="10" HorizontalAlignment="Center" TextAlignment="Center" Text="{Binding StringFormat='0.000'}"></TextBlock> + </Border> + </DataTemplate> + + <!--Extensions--> + </ResourceDictionary> </ResourceDictionary.MergedDictionaries> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index e16703cfa..b89ec2e09 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -71,7 +71,12 @@ <Reference Include="PresentationFramework" /> </ItemGroup> <ItemGroup> + <Compile Include="Controls\RealTimeGraphControl.xaml.cs"> + <DependentUpon>RealTimeGraphControl.xaml</DependentUpon> + </Compile> <Compile Include="Controls\TableGrid.cs" /> + <Compile Include="Converters\SecondsToGraphPointsConverter.cs" /> + <Compile Include="Helpers\GraphsHelper.cs" /> <Compile Include="Notifications\DialogViewVM.cs" /> <Compile Include="StudioApplication\IModuleRequestListener.cs" /> <Compile Include="StudioApplication\IStudioApplicationManager.cs" /> @@ -98,6 +103,10 @@ <Compile Include="Navigation\INavigationManager.cs" /> <Compile Include="Navigation\NavigationView.cs" /> <Compile Include="Notifications\INotificationProvider.cs" /> + <Page Include="Controls\RealTimeGraphControl.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="Resources\MaterialDesign.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -129,6 +138,10 @@ </None> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\SideChains\RealTimeGraphEx\RealTimeGraphEx.csproj"> + <Project>{b9ae25d6-be35-492f-9079-21a7f3e6f7cc}</Project> + <Name>RealTimeGraphEx</Name> + </ProjectReference> <ProjectReference Include="..\..\SideChains\Tango.AutoComplete\Tango.AutoComplete.csproj"> <Project>{bb2abb74-ba58-4812-83aa-ec8171f42df4}</Project> <Name>Tango.AutoComplete</Name> @@ -149,6 +162,10 @@ <Project>{4206ac58-3b57-4699-8835-90bf6db01a61}</Project> <Name>Tango.Integration</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.Settings\Tango.Settings.csproj"> + <Project>{d8f1ad85-526a-4f50-b6dc-d437af63d8d8}</Project> + <Name>Tango.Settings</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> <Name>Tango.SharedUI</Name> |
