diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:05:44 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-08-02 15:05:44 +0300 |
| commit | 05fca4fe321600c4a9c0698b1e4c161e3ed79c9f (patch) | |
| tree | fda984b5a9ff3a3980bf9b6b5a560b3edaa4e668 /Software/Visual_Studio/MachineStudio/Modules | |
| parent | 3499090dce4acc5b5d4bbb02f07f138950790b25 (diff) | |
| download | Tango-05fca4fe321600c4a9c0698b1e4c161e3ed79c9f.tar.gz Tango-05fca4fe321600c4a9c0698b1e4c161e3ed79c9f.zip | |
Added Tango.CSV project!
Implemented Single/Multi graph recording to CSV!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
12 files changed, 553 insertions, 17 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingData.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingData.cs new file mode 100644 index 000000000..d6acd3873 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingData.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.IO; +using Tango.CSV; +using Tango.MachineStudio.Technician.TechItems; + +namespace Tango.MachineStudio.Technician.Models +{ + public class MultiTechRecordingData<T> : TechRecordingData<T, MultiTechRecordingValue> where T : TechItem + { + public int ChannelCount { get; set; } + + public MultiTechRecordingData(T techItem, int channel_count) : base(techItem) + { + ChannelCount = channel_count; + Init(); + } + + public void PushData(List<List<double>> data) + { + TimeSpan delta_base = DateTime.Now - _start_time; + double delta_mili = (DateTime.Now - _last_time).TotalMilliseconds; + + _last_time = DateTime.Now; + + Task.Factory.StartNew(() => + { + var width = data.Count; + var height = data.First().Count; + + for (int row = 0; row < height; row++) + { + String time = (delta_base.Add(TimeSpan.FromMilliseconds((delta_mili / data.Count) * row))).ToString(@"hh\:mm\:ss\.fff"); + + List<double> row_values = new List<double>(); + + for (int column = 0; column < width; column++) + { + row_values.Add(data[column][row]); + } + + CsvFile.Append(new MultiTechRecordingValue(time, row_values)); + } + }); + } + + protected override List<string> GetColumnNames() + { + return Enumerable.Range(1, ChannelCount).Select(x => TechItem.TechName + " " + x).ToList(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingValue.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingValue.cs new file mode 100644 index 000000000..c451c02a2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/MultiTechRecordingValue.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Technician.Models +{ + public class MultiTechRecordingValue : TechRecordingValue + { + public double Value1 { get; set; } + public double Value2 { get; set; } + public double Value3 { get; set; } + public double Value4 { get; set; } + public double Value5 { get; set; } + public double Value6 { get; set; } + public double Value7 { get; set; } + public double Value8 { get; set; } + public double Value9 { get; set; } + public double Value10 { get; set; } + + public MultiTechRecordingValue(string time, List<double> values) : base(time) + { + for (int i = 0; i < values.Count; i++) + { + typeof(MultiTechRecordingValue).GetProperty("Value" + (i + 1)).SetValue(this, values[i]); + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingData.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingData.cs new file mode 100644 index 000000000..3c5426ed9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingData.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.MachineStudio.Technician.TechItems; + +namespace Tango.MachineStudio.Technician.Models +{ + public class SingleTechRecordingData<T> : TechRecordingData<T, SingleTechRecordingValue> where T : TechItem + { + public SingleTechRecordingData(T techItem) : base(techItem) + { + Init(); + } + + public void PushData(List<double> data) + { + TimeSpan delta_base = DateTime.Now - _start_time; + double delta_mili = (DateTime.Now - _last_time).TotalMilliseconds; + + _last_time = DateTime.Now; + + Task.Factory.StartNew(() => + { + for (int i = 0; i < data.Count; i++) + { + CsvFile.Append(new SingleTechRecordingValue((delta_base.Add(TimeSpan.FromMilliseconds((delta_mili / data.Count) * i))).ToString(@"hh\:mm\:ss\.fff"), data[i])); + } + }); + } + + protected override List<string> GetColumnNames() + { + return new List<string>() { TechItem.TechName }; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingValue.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingValue.cs new file mode 100644 index 000000000..f9aa8623a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/SingleTechRecordingValue.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.Models +{ + public class SingleTechRecordingValue : TechRecordingValue + { + public double Value { get; set; } + + public SingleTechRecordingValue(String time, double value) : base(time) + { + Value = value; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingData.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingData.cs new file mode 100644 index 000000000..cb4b10db1 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingData.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; +using Tango.Core.IO; +using Tango.CSV; +using Tango.MachineStudio.Technician.TechItems; + +namespace Tango.MachineStudio.Technician.Models +{ + public abstract class TechRecordingData<T, TValue> : ExtendedObject, IDisposable where T : TechItem where TValue : TechRecordingValue + { + protected DateTime _last_time; + protected DateTime _start_time; + + public CsvFile<TValue> CsvFile { get; set; } + + public TemporaryFile TemporaryFile { get; set; } + + public T TechItem { get; set; } + + public TechRecordingData(T techItem) + { + _start_time = DateTime.Now; + _last_time = DateTime.Now; + TechItem = techItem; + TemporaryFile = TemporaryManager.CreateFile(".csv"); + } + + protected void Init() + { + CsvDefinition definition = new CsvDefinition(); + definition.Columns = new List<String>() { "Time" }.Concat(GetColumnNames()); + + CsvFile = new CsvFile<TValue>(new CsvDestination(TemporaryFile), definition); + } + + public void Save(String fileName) + { + CsvFile.Dispose(); + File.Copy(TemporaryFile.Path, fileName, true); + } + + public void Dispose() + { + CsvFile.Dispose(); + TemporaryFile.Delete(); + } + + protected abstract List<String> GetColumnNames(); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingValue.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingValue.cs new file mode 100644 index 000000000..4812b5017 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Models/TechRecordingValue.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.Models +{ + public abstract class TechRecordingValue + { + public String Time { get; set; } + + public TechRecordingValue(String time) + { + Time = time; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MultiGraphTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MultiGraphTemplate.xaml index da5818a6b..0e2afcf53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MultiGraphTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/MultiGraphTemplate.xaml @@ -4,13 +4,14 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:converters="clr-namespace:Tango.MachineStudio.Technician.Converters" xmlns:items="clr-namespace:Tango.MachineStudio.Technician.TechItems" xmlns:local="clr-namespace:Tango.MachineStudio.Technician.PropertiesTemplates" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="200" d:DataContext="{d:DesignInstance Type=items:SingleGraphItem, IsDesignTimeCreatable=False}"> + d:DesignHeight="600" d:DesignWidth="300" d:DataContext="{d:DesignInstance Type=items:SingleGraphItem, IsDesignTimeCreatable=False}"> <UserControl.Resources> <converters:MonitorsToMultiChannleMonitorsConverter x:Key="MonitorsToMultiChannleMonitorsConverter" /> @@ -53,6 +54,56 @@ <Button Margin="0 10" Command="{Binding ClearCommand}">CLEAR</Button> </StackPanel> </GroupBox> + + <GroupBox Header="CSV RECORDING"> + <StackPanel Margin="0 10"> + <DockPanel> + <Button HorizontalAlignment="Left" ToolTip="Record this graph data. When stopped, the data will be saved to a csv file." Command="{Binding ToggleRecordingCommand}"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon VerticalAlignment="Center" Kind="Record" Foreground="#FF6D6D"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Opacity" Value="1"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRecording}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard Name="blink"> + <Storyboard> + <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity" FillBehavior="Stop"> + <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" /> + <DiscreteDoubleKeyFrame KeyTime="00:00:0.5" Value="1" /> + <DiscreteDoubleKeyFrame KeyTime="00:00:1" Value="1" /> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <RemoveStoryboard BeginStoryboardName="blink" /> + </DataTrigger.ExitActions> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + <TextBlock Margin="10 0 0 0"> + <TextBlock.Style> + <Style TargetType="TextBlock"> + <Setter Property="Text" Value="Start Recording"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRecording}" Value="True"> + <Setter Property="Text" Value="Stop Recording"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBlock.Style> + </TextBlock> + </StackPanel> + </Button> + + <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="digital-7" FontSize="24" Text="{Binding RecordingTime,StringFormat=hh\\:mm\\:ss,TargetNullValue='00:00:00'}"></TextBlock> + </DockPanel> + </StackPanel> + </GroupBox> </StackPanel> </Grid> </UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/SingleGraphTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/SingleGraphTemplate.xaml index d7e40f2e0..5c090d4b5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/SingleGraphTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/SingleGraphTemplate.xaml @@ -4,13 +4,14 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:converters="clr-namespace:Tango.MachineStudio.Technician.Converters" xmlns:sharedConverters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:items="clr-namespace:Tango.MachineStudio.Technician.TechItems" xmlns:local="clr-namespace:Tango.MachineStudio.Technician.PropertiesTemplates" mc:Ignorable="d" - d:DesignHeight="400" d:DesignWidth="200" d:DataContext="{d:DesignInstance Type=items:SingleGraphItem, IsDesignTimeCreatable=False}"> + d:DesignHeight="600" d:DesignWidth="300" d:DataContext="{d:DesignInstance Type=items:SingleGraphItem, IsDesignTimeCreatable=False}"> <UserControl.Resources> <converters:MonitorsToSingleChannleMonitorsConverter x:Key="MonitorsToSingleChannleMonitorsConverter" /> @@ -54,6 +55,56 @@ </StackPanel> </GroupBox> + <GroupBox Header="CSV RECORDING"> + <StackPanel Margin="0 10"> + <DockPanel> + <Button HorizontalAlignment="Left" ToolTip="Record this graph data. When stopped, the data will be saved to a csv file." Command="{Binding ToggleRecordingCommand}"> + <StackPanel Orientation="Horizontal"> + <materialDesign:PackIcon VerticalAlignment="Center" Kind="Record" Foreground="#FF6D6D"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Opacity" Value="1"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRecording}" Value="True"> + <DataTrigger.EnterActions> + <BeginStoryboard Name="blink"> + <Storyboard> + <DoubleAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="Opacity" FillBehavior="Stop"> + <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="0" /> + <DiscreteDoubleKeyFrame KeyTime="00:00:0.5" Value="1" /> + <DiscreteDoubleKeyFrame KeyTime="00:00:1" Value="1" /> + </DoubleAnimationUsingKeyFrames> + </Storyboard> + </BeginStoryboard> + </DataTrigger.EnterActions> + <DataTrigger.ExitActions> + <RemoveStoryboard BeginStoryboardName="blink" /> + </DataTrigger.ExitActions> + </DataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> + <TextBlock Margin="10 0 0 0"> + <TextBlock.Style> + <Style TargetType="TextBlock"> + <Setter Property="Text" Value="Start Recording"></Setter> + <Style.Triggers> + <DataTrigger Binding="{Binding IsRecording}" Value="True"> + <Setter Property="Text" Value="Stop Recording"></Setter> + </DataTrigger> + </Style.Triggers> + </Style> + </TextBlock.Style> + </TextBlock> + </StackPanel> + </Button> + + <TextBlock DockPanel.Dock="Right" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="digital-7" FontSize="24" Text="{Binding RecordingTime,StringFormat=hh\\:mm\\:ss,TargetNullValue='00:00:00'}"></TextBlock> + </DockPanel> + </StackPanel> + </GroupBox> + <GroupBox Margin="0 10 0 0" Header="COLOR"> <StackPanel> <Viewbox Margin="0 5 0 0"> 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 1943780b4..c9e30457e 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 @@ -145,6 +145,12 @@ <DependentUpon>MonitorElementEditor.xaml</DependentUpon> </Compile> <Compile Include="Helpers\GraphsHelper.cs" /> + <Compile Include="Models\MultiTechRecordingValue.cs" /> + <Compile Include="Models\MultiTechRecordingData.cs" /> + <Compile Include="Models\SingleTechRecordingData.cs" /> + <Compile Include="Models\SingleTechRecordingValue.cs" /> + <Compile Include="Models\TechRecordingData.cs" /> + <Compile Include="Models\TechRecordingValue.cs" /> <Compile Include="Project\MachineTechViewProject.cs" /> <Compile Include="PropertiesTemplates\JobRunnerTemplate.xaml.cs"> <DependentUpon>JobRunnerTemplate.xaml</DependentUpon> @@ -416,6 +422,10 @@ <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\..\..\Tango.CSV\Tango.CSV.csproj"> + <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project> + <Name>Tango.CSV</Name> + </ProjectReference> <ProjectReference Include="..\..\..\Tango.DragAndDrop\Tango.DragAndDrop.csproj"> <Project>{b112d89a-a106-41ae-a0c1-4abc84c477f5}</Project> <Name>Tango.DragAndDrop</Name> @@ -562,7 +572,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file 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 52925ee59..d4bdfb7b2 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 @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Threading; using System.Xml.Serialization; using Tango.BL.Entities; using Tango.Core.Commands; @@ -19,6 +20,12 @@ namespace Tango.MachineStudio.Technician.TechItems [TechItem(5)] public class MultiGraphItem : TechItem { + private DispatcherTimer _timer; + private DateTime _recording_start_time; + + public event Action RecordingStarted; + public event Action RecordingStopped; + private TechMonitor _techMonitor; /// <summary> /// Gets or sets the db tech monitor. @@ -111,14 +118,40 @@ namespace Tango.MachineStudio.Technician.TechItems } } + private bool _isRecording; + /// <summary> + /// Gets or sets a value indicating whether this instance is recording. + /// </summary> + [XmlIgnore] + public bool IsRecording + { + get { return _isRecording; } + set { _isRecording = value; RaisePropertyChangedAuto(); } + } + + private TimeSpan _recordingTime; + [XmlIgnore] + public TimeSpan RecordingTime + { + get { return _recordingTime; } + set { _recordingTime = value; RaisePropertyChangedAuto(); } + } + [XmlIgnore] public RelayCommand ClearCommand { get; set; } + [XmlIgnore] + public RelayCommand ToggleRecordingCommand { get; set; } + /// <summary> /// Initializes a new instance of the <see cref="MultiGraphItem"/> class. /// </summary> public MultiGraphItem() : base() { + _timer = new DispatcherTimer(); + _timer.Tick += _timer_Tick; + _timer.Interval = TimeSpan.FromSeconds(1); + Max = 100; Name = "Multi Channel Graph"; Description = "Multi channel real-time graph"; @@ -131,6 +164,31 @@ namespace Tango.MachineStudio.Technician.TechItems Editor.InnerGraph.Controller.Clear(); } }); + + ToggleRecordingCommand = new RelayCommand(ToggleRecording); + } + + private void _timer_Tick(object sender, EventArgs e) + { + RecordingTime = DateTime.Now - _recording_start_time; + } + + private void ToggleRecording() + { + if (!IsRecording) + { + _recording_start_time = DateTime.Now; + IsRecording = true; + _timer.Start(); + RecordingStarted?.Invoke(); + } + else + { + _timer.Stop(); + IsRecording = false; + RecordingTime = TimeSpan.FromSeconds(0); + RecordingStopped?.Invoke(); + } } /// <summary> 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 f2bad5349..c175f1138 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 @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; +using System.Windows.Threading; using System.Xml.Serialization; using Tango.BL.Entities; using Tango.Core.Commands; @@ -20,6 +21,12 @@ namespace Tango.MachineStudio.Technician.TechItems [TechItem(4)] public class SingleGraphItem : TechItem { + private DispatcherTimer _timer; + private DateTime _recording_start_time; + + public event Action RecordingStarted; + public event Action RecordingStopped; + private TechMonitor _techMonitor; /// <summary> /// Gets or sets the db tech monitor. @@ -111,14 +118,39 @@ namespace Tango.MachineStudio.Technician.TechItems } } + private bool _isRecording; + /// <summary> + /// Gets or sets a value indicating whether this instance is recording. + /// </summary> + [XmlIgnore] + public bool IsRecording + { + get { return _isRecording; } + set { _isRecording = value; RaisePropertyChangedAuto(); } + } + + private TimeSpan _recordingTime; + [XmlIgnore] + public TimeSpan RecordingTime + { + get { return _recordingTime; } + set { _recordingTime = value; RaisePropertyChangedAuto(); } + } + [XmlIgnore] public RelayCommand ClearCommand { get; set; } + [XmlIgnore] + public RelayCommand ToggleRecordingCommand { get; set; } + /// <summary> /// Initializes a new instance of the <see cref="SingleGraphItem"/> class. /// </summary> public SingleGraphItem() : base() { + _timer = new DispatcherTimer(); + _timer.Tick += _timer_Tick; + _timer.Interval = TimeSpan.FromSeconds(1); Max = 100; Name = "Single Channel Graph"; Description = "Single channel real-time graph"; @@ -132,6 +164,31 @@ namespace Tango.MachineStudio.Technician.TechItems Editor.InnerGraph.Controller.Clear(); } }); + + ToggleRecordingCommand = new RelayCommand(ToggleRecording); + } + + private void _timer_Tick(object sender, EventArgs e) + { + RecordingTime = DateTime.Now - _recording_start_time; + } + + private void ToggleRecording() + { + if (!IsRecording) + { + _recording_start_time = DateTime.Now; + IsRecording = true; + _timer.Start(); + RecordingStarted?.Invoke(); + } + else + { + _timer.Stop(); + IsRecording = false; + RecordingTime = TimeSpan.FromSeconds(0); + RecordingStopped?.Invoke(); + } } /// <summary> 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 3dff65fbc..cd7582fe9 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 @@ -32,6 +32,7 @@ using Tango.MachineStudio.Common.EventLogging; using Tango.MachineStudio.Common; using Tango.Core.Commands; using Tango.MachineStudio.Technician.Helpers; +using Tango.MachineStudio.Technician.Models; namespace Tango.MachineStudio.Technician.ViewModels { @@ -54,6 +55,9 @@ namespace Tango.MachineStudio.Technician.ViewModels private const int MIN_DIAGNOSTICS_UPDATE_MILI = 500; private TechnicianModuleSettings _settings; + private List<SingleTechRecordingData<SingleGraphItem>> _single_graphs_recordings; + private List<MultiTechRecordingData<MultiGraphItem>> _multi_graph_recordings; + #region Properties @@ -221,6 +225,9 @@ namespace Tango.MachineStudio.Technician.ViewModels { _settings = SettingsManager.Default.GetOrCreate<TechnicianModuleSettings>(); + _single_graphs_recordings = new List<SingleTechRecordingData<SingleGraphItem>>(); + _multi_graph_recordings = new List<MultiTechRecordingData<MultiGraphItem>>(); + GraphsDurationSeconds = _settings.GraphsDuration; TempGraphsDurationSeconds = GraphsDurationSeconds; @@ -261,7 +268,7 @@ namespace Tango.MachineStudio.Technician.ViewModels UploadHardwareConfigurationCommand = new RelayCommand(UploadHardwareConfiguration); SyncHardwareConfigurationCommand = new RelayCommand(SyncHardwareConfiguration); ResetHardwareConfigurationCommand = new RelayCommand(() => ResetHardwareConfiguration()); - UpdateGraphsDurationCommand = new RelayCommand(() => + UpdateGraphsDurationCommand = new RelayCommand(() => { GraphsDurationSeconds = TempGraphsDurationSeconds; _settings.GraphsDuration = GraphsDurationSeconds; @@ -372,6 +379,12 @@ namespace Tango.MachineStudio.Technician.ViewModels }); controller.PushData(points); + + var _graph_recording = _single_graphs_recordings.SingleOrDefault(x => x.TechItem == graphItem); + if (_graph_recording != null) + { + _graph_recording.PushData(points); + } } } } @@ -400,6 +413,12 @@ namespace Tango.MachineStudio.Technician.ViewModels } controller.PushData(points); + + var _graph_recording = _multi_graph_recordings.SingleOrDefault(x => x.TechItem == graphItem); + if (_graph_recording != null) + { + _graph_recording.PushData(points); + } } } } @@ -745,19 +764,27 @@ namespace Tango.MachineStudio.Technician.ViewModels /// <param name="elements">The elements.</param> public void OnElementsRemoved(List<IElementEditor> elements) { - //foreach (var element in elements) - //{ - // if (element.HostedElement is SingleGraphItem) - // { - // _singleControllers.Remove(element.HostedElement as SingleGraphItem); - // (element.HostedElement as SingleGraphItem).Editor.InnerGraph.InnerGraph.Dispose(); - // } - // else if (element.HostedElement is MultiGraphItem) - // { - // _multiControllers.Remove(element.HostedElement as MultiGraphItem); - // (element.HostedElement as MultiGraphItem).Editor.InnerGraph.InnerGraph.Dispose(); - // } - //} + foreach (var element in elements) + { + if (element.HostedElement is SingleGraphItem) + { + var _graph_recording = _single_graphs_recordings.SingleOrDefault(x => x.TechItem == element.HostedElement); + + if (_graph_recording != null) + { + _single_graphs_recordings.Remove(_graph_recording); + } + } + else if (element.HostedElement is MultiGraphItem) + { + var _graph_recording = _multi_graph_recordings.SingleOrDefault(x => x.TechItem == element.HostedElement); + + if (_graph_recording != null) + { + _multi_graph_recordings.Remove(_graph_recording); + } + } + } } /// <summary> @@ -1023,6 +1050,39 @@ namespace Tango.MachineStudio.Technician.ViewModels editor.InnerGraph.Controller = controller; _singleControllers.Add(item, controller); + + item.RecordingStarted += () => + { + _single_graphs_recordings.Add(new SingleTechRecordingData<SingleGraphItem>(item)); + }; + + item.RecordingStopped += () => + { + try + { + var graph_recording = _single_graphs_recordings.SingleOrDefault(x => x.TechItem == item); + + if (graph_recording != null) + { + _single_graphs_recordings.Remove(graph_recording); + + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Save graph data as csv file"; + dlg.Filter = "CSV Files|*.csv"; + dlg.DefaultExt = ".csv"; + dlg.FileName = item.TechName; + if (dlg.ShowDialog().Value) + { + graph_recording.Save(dlg.FileName); + graph_recording.Dispose(); + } + } + } + catch (Exception ex) + { + _notification.ShowError(LogManager.Log(ex).Message); + } + }; } /// <summary> @@ -1050,6 +1110,39 @@ namespace Tango.MachineStudio.Technician.ViewModels editor.InnerGraph.Controller = controller; _multiControllers.Add(item, controller); + + item.RecordingStarted += () => + { + _multi_graph_recordings.Add(new MultiTechRecordingData<MultiGraphItem>(item, item.TechMonitor.ChannelCount)); + }; + + item.RecordingStopped += () => + { + try + { + var graph_recording = _multi_graph_recordings.SingleOrDefault(x => x.TechItem == item); + + if (graph_recording != null) + { + _multi_graph_recordings.Remove(graph_recording); + + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Save graph data as csv file"; + dlg.Filter = "CSV Files|*.csv"; + dlg.DefaultExt = ".csv"; + dlg.FileName = item.TechName; + if (dlg.ShowDialog().Value) + { + graph_recording.Save(dlg.FileName); + graph_recording.Dispose(); + } + } + } + catch (Exception ex) + { + _notification.ShowError(LogManager.Log(ex).Message); + } + }; } /// <summary> |
