diff options
| author | Roy <roy.mail.net@gmail.com> | 2018-02-12 09:40:08 +0200 |
|---|---|---|
| committer | Roy <roy.mail.net@gmail.com> | 2018-02-12 09:40:08 +0200 |
| commit | 2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2 (patch) | |
| tree | 53ff9fc86a9e56d5cd54a53ecddf85aa4656dd6a /Software/Visual_Studio/MachineStudio | |
| parent | a84ca3e4bee123600c08f8897eca5be83b3ffcf8 (diff) | |
| download | Tango-2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2.tar.gz Tango-2bef1ef7fb1d5cd57e2af3f47a648e512cfcd4f2.zip | |
Implemented motor group.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
11 files changed, 817 insertions, 1 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml new file mode 100644 index 000000000..64ed5bb43 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml @@ -0,0 +1,270 @@ +<local:ElementEditor x:Class="Tango.MachineStudio.Technician.Editors.MotorGroupElementEditor" + 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:items="clr-namespace:Tango.MachineStudio.Technician.TechItems" + xmlns:gif="http://wpfanimatedgif.codeplex.com" + xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:converters="clr-namespace:Tango.Editors.Converters;assembly=Tango.Editors" + xmlns:visuals="clr-namespace:Tango.Visuals;assembly=Tango.Visuals" + xmlns:local="clr-namespace:Tango.Editors;assembly=Tango.Editors" + mc:Ignorable="d" + d:DesignHeight="164.393" d:DesignWidth="224.65" Background="Transparent" ClipToBounds="False" BorderThickness="0" MinWidth="1" MinHeight="1" RenderTransformOrigin="0.5,0.5" d:DataContext="{d:DesignInstance Type=items:MotorGroupItem, IsDesignTimeCreatable=False}"> + + <UserControl.Resources> + <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"></converters:BoolToVisibilityConverter> + <sharedConverters:BooleanInverseConverter x:Key="BooleanInverseConverter" /> + + <!--Theme--> + <SolidColorBrush x:Key="BorderBrush" Color="Transparent"></SolidColorBrush> + <SolidColorBrush x:Key="CornersBrush" Color="Red"></SolidColorBrush> + + <Grid x:Key="gridHoming"> + <DockPanel> + <Button Click="OnHomingStopped" DockPanel.Dock="Right" Padding="0" Style="{StaticResource MaterialDesignFlatButton}" VerticalAlignment="Center" Margin="0 0 5 0" ToolTip="Stop Homing"> + <materialDesign:PackIcon Kind="Stop" Foreground="#FF5F5F" HorizontalAlignment="Center" VerticalAlignment="Center" Width="32" Height="32" /> + </Button> + <ProgressBar Foreground="DimGray" BorderBrush="DimGray" Maximum="{Binding HomingMaximumProgress}" BorderThickness="1" Value="{Binding HomingProgress}" VerticalAlignment="Center" Height="10" Margin="5 0 5 0" Background="Transparent"> + + </ProgressBar> + </DockPanel> + </Grid> + + <Grid x:Key="gridDefault"> + <Viewbox Stretch="Fill"> + <materialDesign:PackIcon Kind="Home" Margin="25 0" HorizontalAlignment="Center" VerticalAlignment="Center" Width="24" Height="24" Foreground="#202020" /> + </Viewbox> + + <Button Click="OnHomingStarted" Style="{StaticResource emptyButton}" Background="Transparent" BorderThickness="0"></Button> + </Grid> + </UserControl.Resources> + + <UserControl.RenderTransform> + <RotateTransform Angle="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=Angle}"></RotateTransform> + </UserControl.RenderTransform> + + <Grid> + + <Grid Margin="5" IsHitTestVisible="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=IsEditable,Converter={StaticResource BooleanInverseConverter}}"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="20*"/> + <ColumnDefinition Width="100*"/> + <ColumnDefinition Width="20*"/> + </Grid.ColumnDefinitions> + + <Grid.RowDefinitions> + <RowDefinition Height="100*" /> + <RowDefinition Height="30*" /> + </Grid.RowDefinitions> + + <Grid Grid.Column="1"> + <Border BorderThickness="1" BorderBrush="Gray" CornerRadius="5"> + <Border.Background> + <ImageBrush ImageSource="../Images/black-screen.jpg" Opacity="0.1" /> + </Border.Background> + + <Grid> + <Image x:Name="image" Margin="5" gif:ImageBehavior.AnimatedSource="../Images/motor-group.gif" RenderOptions.BitmapScalingMode="Fant" gif:ImageBehavior.AutoStart="False" gif:ImageBehavior.AnimateInDesignMode="True" gif:ImageBehavior.RepeatBehavior="Forever"></Image> + </Grid> + </Border> + </Grid> + + <Grid> + <Border BorderBrush="Gray" BorderThickness="1 1 0 1" Margin="0 10" CornerRadius="5 0 0 5" PreviewMouseDown="OnBackwardPressed" PreviewMouseUp="OnBackwardReleased"> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="Background"> + <Setter.Value> + <LinearGradientBrush EndPoint="1,0"> + <GradientStop Color="#AAAAAA" Offset="1" /> + <GradientStop Color="#FFEEEEEE" Offset="0"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Style.Triggers> + <EventTrigger RoutedEvent="PreviewMouseDown"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFCECECE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + <EventTrigger RoutedEvent="PreviewMouseUp"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFEEEEEE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + </Style.Triggers> + </Style> + </Border.Style> + + <Viewbox Stretch="Fill" Margin="-10 20"> + <materialDesign:PackIcon Kind="ChevronLeft" HorizontalAlignment="Center" VerticalAlignment="Center" Width="24" Height="24" Foreground="#202020" /> + </Viewbox> + </Border> + </Grid> + + <Grid Grid.Column="2"> + <Border BorderBrush="Gray" BorderThickness="0 1 1 1" Margin="0 10" CornerRadius="0 10 10 0" PreviewMouseDown="OnForwardPressed" PreviewMouseUp="OnForwardReleased"> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="Background"> + <Setter.Value> + <LinearGradientBrush EndPoint="1,0"> + <GradientStop Color="#AAAAAA" Offset="0" /> + <GradientStop Color="#FFEEEEEE" Offset="1"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Style.Triggers> + <EventTrigger RoutedEvent="PreviewMouseDown"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFCECECE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + <EventTrigger RoutedEvent="PreviewMouseUp"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFEEEEEE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + </Style.Triggers> + </Style> + </Border.Style> + + <Viewbox Stretch="Fill" Margin="-10 20"> + <materialDesign:PackIcon Kind="ChevronRight" HorizontalAlignment="Center" VerticalAlignment="Center" Width="24" Height="24" Foreground="#202020" /> + </Viewbox> + </Border> + </Grid> + + <Grid Grid.Column="1" Grid.Row="1"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="20*"/> + <ColumnDefinition Width="115*"/> + <ColumnDefinition Width="20*"/> + </Grid.ColumnDefinitions> + + <Grid Grid.Column="1"> + <Border BorderBrush="Gray" BorderThickness="1 0 1 1" CornerRadius="0 0 20 20"> + <Border.Style> + <Style TargetType="Border"> + <Setter Property="Background"> + <Setter.Value> + <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> + <GradientStop Color="#979797" Offset="1" /> + <GradientStop Color="#FFEEEEEE" Offset="0"/> + </LinearGradientBrush> + </Setter.Value> + </Setter> + <Style.Triggers> + <EventTrigger RoutedEvent="PreviewMouseDown"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFCECECE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + <EventTrigger RoutedEvent="PreviewMouseUp"> + <EventTrigger.Actions> + <BeginStoryboard> + <Storyboard> + <ColorAnimation Storyboard.TargetProperty="Background.GradientStops[1].Color" To="#FFEEEEEE" Duration="00:00:0.1" /> + </Storyboard> + </BeginStoryboard> + </EventTrigger.Actions> + </EventTrigger> + </Style.Triggers> + </Style> + </Border.Style> + + <Grid> + <ContentControl> + <ContentControl.Style> + <Style TargetType="ContentControl"> + <Setter Property="Content" Value="{StaticResource gridDefault}"> + + </Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsHoming}" Value="True"> + <Setter Property="Content" Value="{StaticResource gridHoming}"> + </Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </ContentControl.Style> + + </ContentControl> + </Grid> + </Border> + </Grid> + </Grid> + + + </Grid> + + <!--Content--> + <Grid> + <Border Margin="0 0 0 -23" VerticalAlignment="Bottom"> + <TextBlock Text="{Binding GroupName}" FontSize="14" Foreground="DimGray" HorizontalAlignment="Center"></TextBlock> + </Border> + </Grid> + <!--Content--> + + + <Border BorderThickness="1" BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=BorderBrush,TargetNullValue={StaticResource BorderBrush},FallbackValue={StaticResource BorderBrush}}" Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=(local:ElementsEditor.IsSelected),Converter={StaticResource BoolToVisibilityConverter}}"> + <Grid> + <ContentPresenter Content="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=InnerContent}"></ContentPresenter> + + <Thumb Opacity="0" DragDelta="MoveDrag" DragStarted="DragStarted" DragCompleted="OnDragEnded"></Thumb> + <Thumb HorizontalAlignment="Left" Cursor="SizeWE" Opacity="0" DragDelta="DragLeft" DragStarted="DragStarted" DragCompleted="OnDragEnded"></Thumb> + <Thumb HorizontalAlignment="Right" Cursor="SizeWE" Opacity="0" DragDelta="DragRight" DragStarted="DragStarted" DragCompleted="OnDragEnded"></Thumb> + <Thumb VerticalAlignment="Top" Cursor="SizeNS" Opacity="0" DragDelta="DragTop" DragStarted="DragStarted" DragCompleted="OnDragEnded"></Thumb> + <Thumb VerticalAlignment="Bottom" Cursor="SizeNS" Opacity="0" DragDelta="DragBottom" DragStarted="DragStarted" DragCompleted="OnDragEnded"></Thumb> + + <Grid ClipToBounds="False" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0 -20 0 0" Width="10" Height="10"> + <Ellipse Stroke="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=CornersBrush,TargetNullValue={StaticResource CornersBrush},FallbackValue={StaticResource CornersBrush}}" StrokeThickness="2"></Ellipse> + <Rectangle HorizontalAlignment="Center" VerticalAlignment="Stretch" Margin="0 10 0 -8" StrokeThickness="1" Stroke="Red"></Rectangle> + <Thumb Opacity="0" DragDelta="DragAngle" DragStarted="DragStarted" Cursor="Arrow" DragCompleted="OnDragEnded"></Thumb> + </Grid> + + <Grid Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="-8 -8 0 0"> + <Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=CornersBrush,TargetNullValue={StaticResource CornersBrush},FallbackValue={StaticResource CornersBrush}}" BorderThickness="2 2 0 0"></Border> + <Thumb Opacity="0" DragDelta="DragTopLeft" DragStarted="DragStarted" Cursor="SizeNWSE" DragCompleted="OnDragEnded"></Thumb> + </Grid> + + <Grid Width="10" Height="10" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0 -8 -8 0"> + <Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=CornersBrush,TargetNullValue={StaticResource CornersBrush},FallbackValue={StaticResource CornersBrush}}" BorderThickness="0 2 2 0"></Border> + <Thumb Opacity="0" DragDelta="DragTopRight" DragStarted="DragStarted" Cursor="SizeNESW" DragCompleted="OnDragEnded"></Thumb> + </Grid> + + <Grid Width="10" Height="10" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0 0 -8 -8"> + <Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=CornersBrush,TargetNullValue={StaticResource CornersBrush},FallbackValue={StaticResource CornersBrush}}" BorderThickness="0 0 2 2"></Border> + <Thumb Opacity="0" DragDelta="DragBottomRight" DragStarted="DragStarted" Cursor="SizeNWSE" DragCompleted="OnDragEnded"></Thumb> + </Grid> + + <Grid Width="10" Height="10" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="-8 0 0 -8"> + <Border BorderBrush="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=CornersBrush,TargetNullValue={StaticResource CornersBrush},FallbackValue={StaticResource CornersBrush}}" BorderThickness="2 0 0 2"></Border> + <Thumb Opacity="0" DragDelta="DragBottomLeft" DragStarted="DragStarted" Cursor="SizeNESW" DragCompleted="OnDragEnded"></Thumb> + </Grid> + </Grid> + </Border> + </Grid> +</local:ElementEditor> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs new file mode 100644 index 000000000..4e29296b0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/MotorGroupElementEditor.xaml.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Editors; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Technician.Editors +{ + [ContentProperty("InnerContent")] + public partial class MotorGroupElementEditor : ElementEditor + { + /// <summary> + /// Initializes a new instance of the <see cref="MonitorElementEditor"/> class. + /// </summary> + public MotorGroupElementEditor() + : base() + { + InitializeComponent(); + } + + /// <summary> + /// Initializes a new instance of the <see cref="MonitorElementEditor"/> class. + /// </summary> + /// <param name="frameworkElement">The framework element.</param> + public MotorGroupElementEditor(MotorGroupItem motorGroupItem) + : this() + { + MotorGroupItem = motorGroupItem; + DataContext = MotorGroupItem; + } + + /// <summary> + /// Initializes a new instance of the <see cref="MonitorElementEditor"/> class. + /// </summary> + /// <param name="frameworkElement">The framework element.</param> + /// <param name="bounds">The bounds.</param> + public MotorGroupElementEditor(MotorGroupItem monitorItem, Rect bounds) + : this(monitorItem) + { + Left = bounds.Left; + Top = bounds.Top; + Width = bounds.Width; + Height = bounds.Height; + } + + private MotorGroupItem _monitorItem; + + public MotorGroupItem MotorGroupItem + { + get { return _monitorItem; } + set + { + _monitorItem = value; RaisePropertyChanged(nameof(MotorGroupItem)); + + if (_monitorItem != null) + { + _monitorItem.HomingCompleted -= _monitorItem_HomingCompleted; + _monitorItem.HomingCompleted += _monitorItem_HomingCompleted; + } + } + } + + private void _monitorItem_HomingCompleted(object sender, EventArgs e) + { + StopAnimation(); + } + + + /// <summary> + /// Clones this instance. + /// </summary> + /// <returns></returns> + public override IElementEditor Clone() + { + try + { + var clonedItem = MotorGroupItem.Clone() as MotorGroupItem; + MotorGroupElementEditor cloned = new MotorGroupElementEditor(clonedItem); + cloned.Top = Top; + cloned.Left = Left; + cloned.Width = Width; + cloned.Height = Height; + cloned.Angle = Angle; + return cloned; + } + catch (Exception ex) + { + throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex); + } + } + + /// <summary> + /// Gets the hosted element. + /// </summary> + [ParameterIgnore] + public override Object HostedElement + { + get { return MotorGroupItem; } + } + + private void OnForwardPressed(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.ForwardPressed); + AnimateRight(); + } + + private void OnForwardReleased(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.ForwardReleased); + StopAnimation(); + } + + private void OnBackwardPressed(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.BackwardPressed); + AnimateLeft(); + } + + private void OnBackwardReleased(object sender, MouseButtonEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.BackwardReleased); + StopAnimation(); + } + + private void OnHomingStarted(object sender, RoutedEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.HomingStarted); + AnimateLeft(); + } + + private void OnHomingStopped(object sender, RoutedEventArgs e) + { + MotorGroupItem.RaiseAction(MotorActionType.HomingStopped); + StopAnimation(); + } + + private void AnimateRight() + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play(); + } + + private void AnimateLeft() + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Play(); + } + + public void StopAnimation() + { + this.Dispatcher.Invoke(() => + { + WpfAnimatedGif.ImageBehavior.GetAnimationController(image).Pause(); + }); + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif Binary files differnew file mode 100644 index 000000000..682a20da7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.gif diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png Binary files differnew file mode 100644 index 000000000..0dca92823 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/motor-group.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml new file mode 100644 index 000000000..4210d12a6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml @@ -0,0 +1,54 @@ +<UserControl x:Class="Tango.MachineStudio.Technician.PropertiesTemplates.MotorGroupTemplate" + 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:converters="clr-namespace:Tango.MachineStudio.Technician.Converters" + xmlns:items="clr-namespace:Tango.MachineStudio.Technician.TechItems" + xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" + xmlns:local="clr-namespace:Tango.MachineStudio.Technician.PropertiesTemplates" + mc:Ignorable="d" + d:DesignHeight="500" d:DesignWidth="200" d:DataContext="{d:DesignInstance Type=items:MotorGroupItem, IsDesignTimeCreatable=False}"> + + <UserControl.Resources> + <converters:MonitorsToSingleChannleMonitorsConverter x:Key="MonitorsToSingleChannleMonitorsConverter" /> + + <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}"> + <Setter Property="mahapps:ControlsHelper.HeaderFontSize" Value="14" /> + <Setter Property="Margin" Value="2" /> + </Style> + </UserControl.Resources> + + <Grid> + <StackPanel> + <GroupBox Header="GROUP NAME"> + <TextBox Text="{Binding GroupName,UpdateSourceTrigger=PropertyChanged}"></TextBox> + </GroupBox> + <GroupBox Header="MOTORS" Margin="0 10 0 0"> + <StackPanel> + <TextBlock FontSize="10">Selected Motors</TextBlock> + <Grid> + <ComboBox Margin="0 5 0 0" ItemsSource="{Binding SelectedMotors}"> + <ComboBox.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal"> + <CheckBox IsChecked="{Binding IsSelected,Mode=TwoWay}" VerticalAlignment="Center"></CheckBox> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center" Text="{Binding Data.Description}"></TextBlock> + </StackPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> + <TextBlock IsHitTestVisible="False" VerticalAlignment="Center" Margin="5 0 0 0"> + <Run Text="{Binding SelectedMotors.SynchedSource.Count,Mode=OneWay}"></Run> + <Run>Motors</Run> + </TextBlock> + </Grid> + + <TextBlock FontSize="10" Margin="0 20 0 0"><Run>Speed</Run> <Run Text="{Binding Speed,StringFormat={}{0:N0} ms,FallbackValue=0}"></Run></TextBlock> + <Slider Margin="0 5 0 0" Minimum="1" Maximum="1000" Value="{Binding Speed,Mode=TwoWay}"></Slider> + </StackPanel> + </GroupBox> + </StackPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs new file mode 100644 index 000000000..8d2c3df8a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MotorGroupTemplate.xaml.cs @@ -0,0 +1,31 @@ +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; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; +using Tango.SharedUI.Components; + +namespace Tango.MachineStudio.Technician.PropertiesTemplates +{ + /// <summary> + /// Interaction logic for MonitorTemplate.xaml + /// </summary> + public partial class MotorGroupTemplate : UserControl + { + public MotorGroupTemplate() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 2b90207b0..e8b14e277 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -106,6 +106,9 @@ <Compile Include="Editors\IOElementEditor.xaml.cs"> <DependentUpon>IOElementEditor.xaml</DependentUpon> </Compile> + <Compile Include="Editors\MotorGroupElementEditor.xaml.cs"> + <DependentUpon>MotorGroupElementEditor.xaml</DependentUpon> + </Compile> <Compile Include="Editors\ThreadMotionElementEditor.xaml.cs"> <DependentUpon>ThreadMotionElementEditor.xaml</DependentUpon> </Compile> @@ -135,6 +138,9 @@ <Compile Include="PropertiesTemplates\DispenserTemplate.xaml.cs"> <DependentUpon>DispenserTemplate.xaml</DependentUpon> </Compile> + <Compile Include="PropertiesTemplates\MotorGroupTemplate.xaml.cs"> + <DependentUpon>MotorGroupTemplate.xaml</DependentUpon> + </Compile> <Compile Include="PropertiesTemplates\ThreadMotionTemplate.xaml.cs"> <DependentUpon>ThreadMotionTemplate.xaml</DependentUpon> </Compile> @@ -156,6 +162,7 @@ <Compile Include="TechItems\DispenserItem.cs" /> <Compile Include="TechItems\MotorItem.cs" /> <Compile Include="TechItems\MultiGraphItem.cs" /> + <Compile Include="TechItems\MotorGroupItem.cs" /> <Compile Include="TechItems\SingleGraphItem.cs" /> <Compile Include="TechItems\MonitorItem.cs" /> <Compile Include="TechItems\TechItem.cs" /> @@ -193,6 +200,10 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="Editors\MotorGroupElementEditor.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Editors\ThreadMotionElementEditor.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -229,6 +240,10 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="PropertiesTemplates\MotorGroupTemplate.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="PropertiesTemplates\ThreadMotionTemplate.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -414,5 +429,11 @@ <ItemGroup> <Resource Include="Images\cogs-small.gif" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\motor-group.gif" /> + </ItemGroup> + <ItemGroup> + <Resource Include="Images\motor-group.png" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs new file mode 100644 index 000000000..35aae5cd7 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs @@ -0,0 +1,158 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Xml.Serialization; +using Tango.Integration.Observables; +using Tango.SharedUI.Components; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Technician.TechItems +{ + public class MotorGroupItem : TechItem + { + public event EventHandler<MotorActionType> ActionExecuted; + public event EventHandler HomingCompleted; + + private SelectedObjectCollection<TechMotor> _selectedMotors; + [XmlIgnore] + public SelectedObjectCollection<TechMotor> SelectedMotors + { + get { return _selectedMotors; } + set { _selectedMotors = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection<TechMotor> _techMotors; + [XmlIgnore] + public ObservableCollection<TechMotor> TechMotors + { + get { return _techMotors; } + set { _techMotors = value; RaisePropertyChangedAuto(); SetSelectedMotors(); } + } + + private void SetSelectedMotors() + { + if (TechMotors != null) + { + SelectedMotors = new SelectedObjectCollection<TechMotor>(ObservablesEntitiesAdapter.Instance.TechMotors.ToObservableCollection(), TechMotors); + } + } + + public List<String> ItemsGuids { get; set; } + + private String _groupName; + + public String GroupName + { + get { return _groupName; } + set { _groupName = value; RaisePropertyChangedAuto(); TechName = value; } + } + + + private bool _isHoming; + [XmlIgnore] + public bool IsHoming + { + get { return _isHoming; } + set + { + _isHoming = value; + RaisePropertyChangedAuto(); + } + } + + private bool _isHomingCompleted; + + public bool IsHomingCompleted + { + get { return _isHomingCompleted; } + set + { + _isHomingCompleted = value; + RaisePropertyChangedAuto(); + + if (value) + { + HomingCompleted?.Invoke(this, new EventArgs()); + } + } + } + + private double _homingProgress; + [XmlIgnore] + public double HomingProgress + { + get { return _homingProgress; } + set + { + _homingProgress = value; + RaisePropertyChangedAuto(); + } + } + + private double _homingMaximumProgress; + [XmlIgnore] + public double HomingMaximumProgress + { + get { return _homingMaximumProgress; } + set { _homingMaximumProgress = value; RaisePropertyChangedAuto(); } + } + + private bool _isForwardPressed; + [XmlIgnore] + public bool IsForwardPressed + { + get { return _isForwardPressed; } + set { _isForwardPressed = value; RaisePropertyChangedAuto(); } + } + + private bool _isBackwardPressed; + [XmlIgnore] + public bool IsBackwardPressed + { + get { return _isBackwardPressed; } + set { _isBackwardPressed = value; RaisePropertyChangedAuto(); } + } + + private double _speed; + public double Speed + { + get { return _speed; } + set { _speed = value; RaisePropertyChangedAuto(); } + } + + public MotorGroupItem() : base() + { + ItemsGuids = new List<string>(); + TechMotors = new ObservableCollection<TechMotor>(); + Name = "Motor Group"; + Description = "Motor Group Controller"; + Image = ResourceHelper.GetImageFromResources("Images/motor-group.png"); + Color = Colors.White; + GroupName = "Motor Group"; + } + + public MotorGroupItem(object dummyConstructor) : this() + { + + } + + public override TechItem Clone() + { + MotorGroupItem cloned = base.Clone() as MotorGroupItem; + cloned.TechMotors = new ObservableCollection<TechMotor>(TechMotors); + cloned.Speed = Speed; + cloned.ItemsGuids = ItemsGuids; + cloned.TechMotors = cloned.TechMotors.ToObservableCollection(); + return cloned; + } + + public void RaiseAction(MotorActionType action) + { + ActionExecuted?.Invoke(this, action); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs index 8361b6ef7..a7b5ae5b9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItem.cs @@ -21,6 +21,7 @@ namespace Tango.MachineStudio.Technician.TechItems [XmlInclude(typeof(MultiGraphItem))] [XmlInclude(typeof(SingleGraphItem))] [XmlInclude(typeof(ThreadMotionItem))] + [XmlInclude(typeof(MotorGroupItem))] public abstract class TechItem : ExtendedObject { public TechItem() diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index d87652e42..1b0ee0a56 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -362,9 +362,14 @@ namespace Tango.MachineStudio.Technician.ViewModels } else if (item is ThreadMotionItem) { - var editor = CreateElement<ThreadMotionElementEditor, ThreadMotionItem, int>(bounds, 0); + var editor = CreateElement<ThreadMotionElementEditor, ThreadMotionItem, object>(bounds, null); InitThreadMotionItem(editor.ThreadMotionItem); } + else if (item is MotorGroupItem) + { + var editor = CreateElement<MotorGroupElementEditor, MotorGroupItem, object>(bounds, null); + InitMotorGroupItem(editor.MotorGroupItem); + } } private Editor CreateElement<Editor, Tech, Value>(Rect bounds, Value value) where Editor : IElementEditor where Tech : TechItem @@ -428,6 +433,11 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement<ThreadMotionElementEditor>(item); InitThreadMotionItem(editor.ThreadMotionItem); } + else if (item is MotorGroupItem) + { + var editor = CreateElement<MotorGroupElementEditor>(item); + InitMotorGroupItem(editor.MotorGroupItem); + } } public void OnElementsRemoved(List<IElementEditor> elements) @@ -502,6 +512,16 @@ namespace Tango.MachineStudio.Technician.ViewModels var ioItem = element.HostedElement as IOItem; InitIOItem(ioItem); } + else if (element is ThreadMotionItem) + { + var threadMotionItem = element.HostedElement as ThreadMotionItem; + InitThreadMotionItem(threadMotionItem); + } + else if (element is MotorGroupItem) + { + var motorGroupItem = element.HostedElement as MotorGroupItem; + InitMotorGroupItem(motorGroupItem); + } } } @@ -722,6 +742,76 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + private void InitMotorGroupItem(MotorGroupItem item) + { + item.ActionExecuted += async (x, action) => + { + if (action == MotorActionType.ForwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Forward, + }))); + } + else if (action == MotorActionType.ForwardReleased) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + else if (action == MotorActionType.BackwardPressed) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StartMotorJogging(new MotorJoggingRequest() + { + Code = motor.Code, + Direction = MotorDirection.Backward, + }))); + } + else if (action == MotorActionType.BackwardReleased) + { + await Task.WhenAll(item.TechMotors.Select(motor => MachineOperator.StopMotorJogging(new MotorAbortJoggingRequest() + { + Code = motor.Code, + }))); + } + //else if (action == MotorActionType.HomingStarted) + //{ + // item.HomingProgress = 0; + // item.IsHoming = true; + // item.IsHomingCompleted = false; + + // MachineOperator.StartMotorHoming(new MotorHomingRequest() + // { + // Code = item.TechMotor.Code + // }) + // .Subscribe((response) => + // { + + // item.HomingMaximumProgress = response.Message.MaxProgress; + // item.HomingProgress = response.Message.Progress; + + // }, () => + // { + + // item.IsHoming = false; + // item.IsHomingCompleted = true; + + // }); + //} + //else if (action == MotorActionType.HomingStopped) + //{ + // await MachineOperator.StopMotorHoming(new MotorAbortHomingRequest() + // { + // Code = item.TechMotor.Code, + // }); + + // item.IsHoming = false; + //} + }; + } + #endregion #region Public Methods @@ -754,6 +844,11 @@ namespace Tango.MachineStudio.Technician.ViewModels foreach (var item in project.Items) { + if (item is MotorGroupItem) + { + (item as MotorGroupItem).TechMotors = ObservablesEntitiesAdapter.Instance.TechMotors.Where(x => (item as MotorGroupItem).ItemsGuids.Contains(x.Guid)).ToObservableCollection(); + } + AddTechItem(item); } } @@ -799,6 +894,12 @@ namespace Tango.MachineStudio.Technician.ViewModels foreach (var element in Elements) { + if (element.HostedElement is MotorGroupItem) + { + var group = element.HostedElement as MotorGroupItem; + group.ItemsGuids = group.TechMotors.Select(x => x.Guid).ToList(); + } + (element.HostedElement as TechItem).SetBounds(element.GetBounds()); project.Items.Add(element.HostedElement as TechItem); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 7042be696..1658b97d8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -355,6 +355,9 @@ <DataTemplate DataType="{x:Type items:MonitorItem}"> <templates:MonitorTemplate/> </DataTemplate> + <DataTemplate DataType="{x:Type items:MotorGroupItem}"> + <templates:MotorGroupTemplate/> + </DataTemplate> <DataTemplate DataType="{x:Type items:ThreadMotionItem}"> <templates:ThreadMotionTemplate/> </DataTemplate> |
