diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-13 17:28:44 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-13 17:28:44 +0200 |
| commit | 7fd31b19dc4a836230bed3e4c38f5cc94e5d0a37 (patch) | |
| tree | a18bf1cf076a5fca4a48057e2b4e5320d0a71fde /Software/Visual_Studio | |
| parent | d55420499a73f2a3e8e50cf221ff1dd32f8a3d71 (diff) | |
| download | Tango-7fd31b19dc4a836230bed3e4c38f5cc94e5d0a37.tar.gz Tango-7fd31b19dc4a836230bed3e4c38f5cc94e5d0a37.zip | |
Implemented Digital In.
Diffstat (limited to 'Software/Visual_Studio')
24 files changed, 477 insertions, 46 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/TechIosToDigitalInsConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/TechIosToDigitalInsConverter.cs new file mode 100644 index 000000000..4b587743d --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Converters/TechIosToDigitalInsConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.Integration.Observables; +using Tango.Integration.Observables.Enumerations; + +namespace Tango.MachineStudio.Technician.Converters +{ + public class TechIosToDigitalInsConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + ObservableCollection<TechIo> ios = value as ObservableCollection<TechIo>; + + if (ios != null) + { + return ios.Where(x => x.Type == IOType.DigitalInput.ToInt32()).ToObservableCollection(); + } + else + { + return null; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml new file mode 100644 index 000000000..29eab7042 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml @@ -0,0 +1,92 @@ +<local:ElementEditor x:Class="Tango.MachineStudio.Technician.Editors.DigitalInElementEditor" + 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:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:items="clr-namespace:Tango.MachineStudio.Technician.TechItems" + 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" Background="Transparent" ClipToBounds="False" BorderThickness="0" MinWidth="1" MinHeight="1" RenderTransformOrigin="0.5,0.5" d:DataContext="{d:DesignInstance Type=items:DigitalInItem, IsDesignTimeCreatable=False}" Height="83.778" Width="72.703"> + + <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> + </UserControl.Resources> + + <UserControl.RenderTransform> + <RotateTransform Angle="{Binding RelativeSource={RelativeSource AncestorType=local:ElementEditor},Path=Angle}"></RotateTransform> + </UserControl.RenderTransform> + + <Grid> + + + <!--Content--> + <Grid IsHitTestVisible="{Binding RelativeSource={RelativeSource AncestorType=local:ElementsEditor},Path=IsEditable,Converter={StaticResource BooleanInverseConverter}}"> + <Grid.RowDefinitions> + <RowDefinition Height="221*"/> + <RowDefinition Height="Auto"/> + </Grid.RowDefinitions> + + <Border BorderBrush="Gray" BorderThickness="1" CornerRadius="5" Padding="5"> + <Border.Background> + <ImageBrush ImageSource="../Images/black-screen.jpg" Opacity="0.1" /> + </Border.Background> + <Grid> + <Viewbox Margin="5"> + <visuals:Led Width="100" Height="100" IsChecked="{Binding Value}" IsHitTestVisible="False" /> + </Viewbox> + </Grid> + </Border> + + <Border VerticalAlignment="Bottom" Grid.Row="1" Margin="0 0 0 0"> + <TextBlock TextWrapping="Wrap" FontSize="14" Foreground="DimGray" HorizontalAlignment="Center" Text="{Binding TechIo.Description}"></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/DigitalInElementEditor.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml.cs new file mode 100644 index 000000000..e884e70b9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/DigitalInElementEditor.xaml.cs @@ -0,0 +1,90 @@ +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.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Editors; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; + +namespace Tango.MachineStudio.Technician.Editors +{ + [ContentProperty("InnerContent")] + public partial class DigitalInElementEditor : ElementEditor + { + public DigitalInElementEditor() + : base() + { + InitializeComponent(); + } + + public DigitalInElementEditor(DigitalInItem digitalInItem) + : this() + { + DigitalInItem = digitalInItem; + DataContext = DigitalInItem; + } + + public DigitalInElementEditor(DigitalInItem digitalInItem, Rect bounds) + : this(digitalInItem) + { + Left = bounds.Left; + Top = bounds.Top; + Width = bounds.Width; + Height = bounds.Height; + } + + private DigitalInItem _digitalInItem; + + public DigitalInItem DigitalInItem + { + get { return _digitalInItem; } + set { _digitalInItem = value; RaisePropertyChanged(nameof(DigitalInItem)); } + } + + + /// <summary> + /// Clones this instance. + /// </summary> + /// <returns></returns> + public override IElementEditor Clone() + { + try + { + var clonedItem = DigitalInItem.Clone() as DigitalInItem; + DigitalInElementEditor cloned = new DigitalInElementEditor(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 DigitalInItem; } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/digital-in.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/digital-in.png Binary files differnew file mode 100644 index 000000000..3b5ebac18 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/digital-in.png diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml new file mode 100644 index 000000000..1121fe9e1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml @@ -0,0 +1,33 @@ +<UserControl x:Class="Tango.MachineStudio.Technician.PropertiesTemplates.DigitalInTemplate" + 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:DigitalOutItem, IsDesignTimeCreatable=False}"> + + <UserControl.Resources> + <converters:TechIosToDigitalInsConverter x:Key="TechIosToDigitalInsConverter" /> + + <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="INPUT"> + <StackPanel> + <TextBlock FontSize="10">Selected Pin</TextBlock> + <ComboBox Margin="0 5 0 0" ItemsSource="{Binding Adapter.TechIos,Converter={StaticResource TechIosToDigitalInsConverter}}" SelectedItem="{Binding TechIo,Mode=TwoWay}" DisplayMemberPath="Description" /> + </StackPanel> + </GroupBox> + </StackPanel> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml.cs new file mode 100644 index 000000000..9862a95b9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalInTemplate.xaml.cs @@ -0,0 +1,28 @@ +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 Tango.MachineStudio.Technician.PropertiesTemplates +{ + /// <summary> + /// Interaction logic for MonitorTemplate.xaml + /// </summary> + public partial class DigitalInTemplate : UserControl + { + public DigitalInTemplate() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalOutTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalOutTemplate.xaml index 9d30e744c..dafceefcb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalOutTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DigitalOutTemplate.xaml @@ -22,7 +22,7 @@ <Grid> <StackPanel> - <GroupBox Header="INPUT"> + <GroupBox Header="OUTPUT"> <StackPanel> <TextBlock FontSize="10">Selected Pin</TextBlock> <ComboBox Margin="0 5 0 0" ItemsSource="{Binding Adapter.TechIos,Converter={StaticResource TechIosToDigitalOutsConverter}}" SelectedItem="{Binding TechIo,Mode=TwoWay}" DisplayMemberPath="Description" /> 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 820a7ee57..08c1980f4 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 @@ -99,8 +99,12 @@ <Compile Include="Converters\MonitorsToMultiChannleMonitorsConverter.cs" /> <Compile Include="Converters\MonitorsToSingleChannleMonitorsConverter.cs" /> <Compile Include="Converters\SecondsToGraphPointsConverter.cs" /> + <Compile Include="Converters\TechIosToDigitalInsConverter.cs" /> <Compile Include="Converters\TechIosToDigitalOutsConverter.cs" /> <Compile Include="Converters\TransitionLinkConverter.cs" /> + <Compile Include="Editors\DigitalInElementEditor.xaml.cs"> + <DependentUpon>DigitalInElementEditor.xaml</DependentUpon> + </Compile> <Compile Include="Editors\DispenserElementEditor.xaml.cs"> <DependentUpon>DispenserElementEditor.xaml</DependentUpon> </Compile> @@ -130,6 +134,9 @@ </Compile> <Compile Include="Helpers\GraphsHelper.cs" /> <Compile Include="Project\MachineTechViewProject.cs" /> + <Compile Include="PropertiesTemplates\DigitalInTemplate.xaml.cs"> + <DependentUpon>DigitalInTemplate.xaml</DependentUpon> + </Compile> <Compile Include="PropertiesTemplates\DigitalOutTemplate.xaml.cs"> <DependentUpon>DigitalOutTemplate.xaml</DependentUpon> </Compile> @@ -157,6 +164,7 @@ <Compile Include="PropertiesTemplates\SingleGraphTemplate.xaml.cs"> <DependentUpon>SingleGraphTemplate.xaml</DependentUpon> </Compile> + <Compile Include="TechItems\DigitalInItem.cs" /> <Compile Include="TechItems\DigitalOutItem.cs" /> <Compile Include="TechItems\MeterItem.cs" /> <Compile Include="TechItems\MotorActionType.cs" /> @@ -169,6 +177,7 @@ <Compile Include="TechItems\TechItem.cs" /> <Compile Include="Navigation\TechNavigationView.cs" /> <Compile Include="Navigation\TechNavigationManager.cs" /> + <Compile Include="TechItems\TechItemAttribute.cs" /> <Compile Include="TechItems\ThreadMotionItem.cs" /> <Compile Include="TechnicianModule.cs" /> <Compile Include="ViewModelLocator.cs" /> @@ -193,6 +202,10 @@ <Compile Include="..\..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Page Include="Editors\DigitalInElementEditor.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="Editors\DispenserElementEditor.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -229,6 +242,10 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> + <Page Include="PropertiesTemplates\DigitalInTemplate.xaml"> + <Generator>MSBuild:Compile</Generator> + <SubType>Designer</SubType> + </Page> <Page Include="PropertiesTemplates\DigitalOutTemplate.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -436,5 +453,8 @@ <ItemGroup> <Resource Include="Images\motor-group.png" /> </ItemGroup> + <ItemGroup> + <Resource Include="Images\digital-in.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/DigitalInItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalInItem.cs new file mode 100644 index 000000000..f6d09ae59 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalInItem.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +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.Helpers; + +namespace Tango.MachineStudio.Technician.TechItems +{ + [TechItem(0)] + public class DigitalInItem : TechItem + { + private TechIo _techIo; + [XmlIgnore] + public TechIo TechIo + { + get { return _techIo; } + set { _techIo = value; RaisePropertyChangedAuto(); TechName = _techIo != null ? _techIo.Description : null; ItemGuid = value != null ? value.Guid : null; } + } + + private bool _value; + [XmlIgnore] + public bool Value + { + get { return _value; } + set { _value = value; RaisePropertyChangedAuto(); } + } + + public DigitalInItem() : base() + { + Name = "Digital In"; + Description = "Digital Input Pin LED"; + Image = ResourceHelper.GetImageFromResources("Images/digital-in.png"); + Color = Colors.White; + } + + public DigitalInItem(TechIo techIo) : this() + { + TechIo = techIo; + } + + public override TechItem Clone() + { + DigitalInItem cloned = base.Clone() as DigitalInItem; + cloned.TechIo = TechIo; + return cloned; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalOutItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalOutItem.cs index 817cfd9b7..ae8a0a023 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalOutItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DigitalOutItem.cs @@ -10,6 +10,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(1)] public class DigitalOutItem : TechItem { public event EventHandler<bool> ValueChanged; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs index bc656c67c..8bb72fc66 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/DispenserItem.cs @@ -11,6 +11,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(8)] public class DispenserItem : TechItem { public event EventHandler<MotorActionType> ActionExecuted; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MeterItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MeterItem.cs index 8fb7c83cc..d7f019fa9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MeterItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MeterItem.cs @@ -11,6 +11,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(3)] public class MeterItem : TechItem { private TechMonitor _techMonitor; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MonitorItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MonitorItem.cs index f81d98438..987c6cc99 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MonitorItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MonitorItem.cs @@ -10,6 +10,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(2)] public class MonitorItem : TechItem { private TechMonitor _techMonitor; 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 index 35aae5cd7..551bf1f0a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorGroupItem.cs @@ -12,6 +12,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(7)] public class MotorGroupItem : TechItem { public event EventHandler<MotorActionType> ActionExecuted; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs index 77a0c1b4d..ce668a464 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MotorItem.cs @@ -11,6 +11,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(6)] public class MotorItem : TechItem { public event EventHandler<MotorActionType> ActionExecuted; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MultiGraphItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MultiGraphItem.cs index 232442357..65ee521ef 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MultiGraphItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/MultiGraphItem.cs @@ -10,6 +10,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(5)] public class MultiGraphItem : TechItem { private TechMonitor _techMonitor; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SingleGraphItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SingleGraphItem.cs index 1efcd93a8..9d44c6a33 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SingleGraphItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/SingleGraphItem.cs @@ -10,6 +10,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(4)] public class SingleGraphItem : TechItem { private TechMonitor _techMonitor; 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 92ad1c536..a64cd7908 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 @@ -10,6 +10,7 @@ using System.Xml.Serialization; using Tango.Core; using Tango.Core.Helpers; using Tango.Integration.Observables; +using System.Reflection; namespace Tango.MachineStudio.Technician.TechItems { @@ -22,6 +23,7 @@ namespace Tango.MachineStudio.Technician.TechItems [XmlInclude(typeof(SingleGraphItem))] [XmlInclude(typeof(ThreadMotionItem))] [XmlInclude(typeof(MotorGroupItem))] + [XmlInclude(typeof(DigitalInItem))] public abstract class TechItem : ExtendedObject { public TechItem() @@ -177,7 +179,7 @@ namespace Tango.MachineStudio.Technician.TechItems { List<TechItem> items = new List<TechItem>(); - foreach (var type in typeof(TechItem).Assembly.GetTypes().Where(x => typeof(TechItem).IsAssignableFrom(x) && !x.IsAbstract)) + foreach (var type in typeof(TechItem).Assembly.GetTypes().Where(x => typeof(TechItem).IsAssignableFrom(x) && !x.IsAbstract).OrderBy(x => x.GetCustomAttribute<TechItemAttribute>().Index)) { items.Add(Activator.CreateInstance(type) as TechItem); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItemAttribute.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItemAttribute.cs new file mode 100644 index 000000000..cd6dfb1ea --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/TechItemAttribute.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Technician.TechItems +{ + public class TechItemAttribute : Attribute + { + public int Index { get; set; } + + public TechItemAttribute(int index) + { + Index = index; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ThreadMotionItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ThreadMotionItem.cs index 04b71ac8c..79ecf9372 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ThreadMotionItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ThreadMotionItem.cs @@ -9,6 +9,7 @@ using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems { + [TechItem(9)] public class ThreadMotionItem : TechItem { public event EventHandler<MotorActionType> ActionExecuted; 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 c886c2345..c6f72be3e 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 @@ -212,17 +212,6 @@ namespace Tango.MachineStudio.Technician.ViewModels } } } - else if (item.GetType() == typeof(DigitalOutItem)) - { - DigitalOutItem digitalOutItem = item as DigitalOutItem; - - var digitalPin = data.DigitalPins.SingleOrDefault(x => x.Port == digitalOutItem.TechIo.Port); - - if (digitalPin != null) - { - digitalOutItem.EffectiveValue = digitalPin.Value; - } - } else if (item.GetType() == typeof(MeterItem)) { MeterItem meterItem = item as MeterItem; @@ -269,6 +258,28 @@ namespace Tango.MachineStudio.Technician.ViewModels } } } + else if (item.GetType() == typeof(DigitalOutItem)) + { + DigitalOutItem digitalOutItem = item as DigitalOutItem; + + var digitalPin = data.DigitalPins.SingleOrDefault(x => x.Port == digitalOutItem.TechIo.Port); + + if (digitalPin != null) + { + digitalOutItem.EffectiveValue = digitalPin.Value; + } + } + else if (item.GetType() == typeof(DigitalInItem)) + { + DigitalInItem digitalInItem = item as DigitalInItem; + + var digitalPin = data.DigitalPins.SingleOrDefault(x => x.Port == digitalInItem.TechIo.Port); + + if (digitalPin != null) + { + digitalInItem.Value = digitalPin.Value; + } + } } } } @@ -358,11 +369,6 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement<DispenserElementEditor, DispenserItem, TechDispenser>(bounds, Adapter.TechDispensers.FirstOrDefault()); InitDispenserItem(editor.DispenserItem); } - else if (item is DigitalOutItem) - { - var editor = CreateElement<DigitalOutElementEditor, DigitalOutItem, TechIo>(bounds, Adapter.TechIos.Where(x => x.Type == IOType.DigitalOutput.ToInt32()).FirstOrDefault()); - InitDigitalOutItem(editor.DigitalOutItem); - } else if (item is ThreadMotionItem) { var editor = CreateElement<ThreadMotionElementEditor, ThreadMotionItem, object>(bounds, null); @@ -373,6 +379,15 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement<MotorGroupElementEditor, MotorGroupItem, object>(bounds, null); InitMotorGroupItem(editor.MotorGroupItem); } + else if (item is DigitalOutItem) + { + var editor = CreateElement<DigitalOutElementEditor, DigitalOutItem, TechIo>(bounds, Adapter.TechIos.Where(x => x.Type == IOType.DigitalOutput.ToInt32()).FirstOrDefault()); + InitDigitalOutItem(editor.DigitalOutItem); + } + else if (item is DigitalInItem) + { + CreateElement<DigitalInElementEditor, DigitalInItem, TechIo>(bounds, Adapter.TechIos.Where(x => x.Type == IOType.DigitalInput.ToInt32()).FirstOrDefault()); + } } private Editor CreateElement<Editor, Tech, Value>(Rect bounds, Value value) where Editor : IElementEditor where Tech : TechItem @@ -426,11 +441,6 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement<DispenserElementEditor>(item); InitDispenserItem(editor.DispenserItem); } - else if (item is DigitalOutItem) - { - var editor = CreateElement<DigitalOutElementEditor>(item); - InitDigitalOutItem(editor.DigitalOutItem); - } else if (item is ThreadMotionItem) { var editor = CreateElement<ThreadMotionElementEditor>(item); @@ -441,6 +451,17 @@ namespace Tango.MachineStudio.Technician.ViewModels var editor = CreateElement<MotorGroupElementEditor>(item); InitMotorGroupItem(editor.MotorGroupItem); } + else if (item is DigitalOutItem) + { + (item as DigitalOutItem).TechIo = Adapter.TechIos.FirstOrDefault(x => x.Guid == item.ItemGuid); + var editor = CreateElement<DigitalOutElementEditor>(item); + InitDigitalOutItem(editor.DigitalOutItem); + } + else if (item is DigitalInItem) + { + (item as DigitalInItem).TechIo = Adapter.TechIos.FirstOrDefault(x => x.Guid == item.ItemGuid); + CreateElement<DigitalInElementEditor>(item); + } } public void OnElementsRemoved(List<IElementEditor> elements) @@ -672,21 +693,6 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } - private void InitDigitalOutItem(DigitalOutItem item) - { - item.ValueChanged += async (x, value) => - { - try - { - await MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { Port = item.TechIo.Port, Value = value }); - } - catch (Exception ex) - { - //TODO: Show Exception. - } - }; - } - private void InitSingleGraphitem(SingleGraphItem item, SingleGraphElementEditor editor) { editor.InnerGraph.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(item.TechMonitor.PointsPerFrame); @@ -815,6 +821,21 @@ namespace Tango.MachineStudio.Technician.ViewModels }; } + private void InitDigitalOutItem(DigitalOutItem item) + { + item.ValueChanged += async (x, value) => + { + try + { + await MachineOperator.SetDigitalOut(new SetDigitalOutRequest() { Port = item.TechIo.Port, Value = value }); + } + catch (Exception ex) + { + //TODO: Show Exception. + } + }; + } + #endregion #region Public Methods 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 784bd56fb..a55d335ea 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:DigitalInItem}"> + <templates:DigitalInTemplate/> + </DataTemplate> <DataTemplate DataType="{x:Type items:MotorGroupItem}"> <templates:MotorGroupTemplate/> </DataTemplate> diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index f998fab2e..c6f1cb1ab 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -37,7 +37,8 @@ namespace Tango.Emulations.Emulators private List<int> _dispenserHomingRequestCodes; private double _graphAmplitude; private double _graphFrequency; - private List<DigitalPin> _digitalPinsStates; + private List<DigitalPin> _digitalOutputPinsStates; + private List<DigitalPin> _digitalInputPinsStates; #region Constructors @@ -69,12 +70,17 @@ namespace Tango.Emulations.Emulators _motorHomingRequestCodes = new List<int>(); _dispenserJoggingRequestCodes = new List<int>(); _dispenserHomingRequestCodes = new List<int>(); - _digitalPinsStates = new List<DigitalPin>(); + _digitalOutputPinsStates = new List<DigitalPin>(); var adapter = ObservablesEntitiesAdapter.Instance; adapter.Initialize(); - _digitalPinsStates = adapter.TechIos.Where(x => x.Type == IOType.DigitalOutput.ToInt32() || x.Type == IOType.DigitalInput.ToInt32()).Select(x => new DigitalPin() + _digitalOutputPinsStates = adapter.TechIos.Where(x => x.Type == IOType.DigitalOutput.ToInt32()).Select(x => new DigitalPin() + { + Port = x.Port, + }).ToList(); + + _digitalInputPinsStates = adapter.TechIos.Where(x => x.Type == IOType.DigitalInput.ToInt32()).Select(x => new DigitalPin() { Port = x.Port, }).ToList(); @@ -240,7 +246,7 @@ namespace Tango.Emulations.Emulators res.Dispenser8MotorFrequency.AddRange(dispenserFrequencies[7].Data); } - res.DigitalPins.AddRange(_digitalPinsStates); + res.DigitalPins.AddRange(_digitalOutputPinsStates.Concat(_digitalInputPinsStates)); Transporter.SendResponse<PushDiagnosticsResponse>(res, request.Container.Token); Thread.Sleep(10); @@ -344,8 +350,15 @@ namespace Tango.Emulations.Emulators { _graphFrequency = 10; + var inputPin = _digitalInputPinsStates.FirstOrDefault(); + for (int i = 0; i < 100; i++) { + if (inputPin != null) + { + inputPin.Value = !inputPin.Value; + } + Transporter.SendResponse<MotorHomingResponse>(new MotorHomingResponse() { MaxProgress = 100, Progress = i }, request.Container.Token); if (!_motorHomingRequestCodes.Contains(homeRequest.Code)) @@ -451,7 +464,7 @@ namespace Tango.Emulations.Emulators private void HandleSetDigitalOutRequest(TangoMessage<SetDigitalOutRequest> request) { LogManager.Log("Set digital output pin request received: " + Environment.NewLine + request.Message.ToJsonString()); - var pinState = _digitalPinsStates.SingleOrDefault(x => x.Port == request.Message.Port); + var pinState = _digitalOutputPinsStates.SingleOrDefault(x => x.Port == request.Message.Port); if (pinState != null) { pinState.Value = request.Message.Value; diff --git a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs index 8455cb91d..ca213cc3f 100644 --- a/Software/Visual_Studio/Tango.Settings/SettingsManager.cs +++ b/Software/Visual_Studio/Tango.Settings/SettingsManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Logging; using Tango.Serialization; @@ -96,18 +97,34 @@ namespace Tango.Settings { if (IsInitialized) return; + IsInitialized = true; + LogManager.Log("Initializing application configuration..."); DefaultFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Twine", "Tango", "Settings.xml"); DefaultFolder = Path.GetDirectoryName(DefaultFilePath); + bool waited = false; + + Retry: + try { Default = LoadFromXML(DefaultFilePath); } catch (Exception ex) { - LogManager.Log(ex, "Could not load application configuration."); + if (!waited) + { + LogManager.Log(ex, "Could not load application configuration. Retrying in 1 second..."); + waited = true; + Thread.Sleep(1000); + goto Retry; + } + else + { + LogManager.Log(ex, "Could not load application configuration."); + } try { @@ -138,8 +155,6 @@ namespace Tango.Settings { LogManager.Log("Application configuration loaded successfully."); } - - IsInitialized = true; } } } |
