diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-06 19:46:56 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-06 19:46:56 +0200 |
| commit | a37d0e9c9203d680bf63698cf9d47447a57b5684 (patch) | |
| tree | 0547105ad8973076ddc558f6e5afdd192b86f7b3 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer | |
| parent | 198a620cf30e86158c60cb632df740ca94b73b57 (diff) | |
| download | Tango-a37d0e9c9203d680bf63698cf9d47447a57b5684.tar.gz Tango-a37d0e9c9203d680bf63698cf9d47447a57b5684.zip | |
Diagnostics Data Playing Works!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer')
2 files changed, 155 insertions, 37 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index edc6274c3..2ca3d215e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -55,6 +55,16 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _recorder = value; RaisePropertyChangedAuto(); } } + private DiagnosticsFilePlayer _player; + /// <summary> + /// Gets or sets the diagnostics file player. + /// </summary> + public DiagnosticsFilePlayer Player + { + get { return _player; } + set { _player = value; RaisePropertyChangedAuto(); } + } + /// <summary> /// Gets or sets the application manager. /// </summary> @@ -443,6 +453,16 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> public RelayCommand MediaLoadFileCommand { get; set; } + /// <summary> + /// Gets or sets the media play pause command. + /// </summary> + public RelayCommand MediaPlayPauseCommand { get; set; } + + /// <summary> + /// Gets or sets the media load command. + /// </summary> + public RelayCommand MediaLoadCommand { get; set; } + #endregion #region Constructors @@ -461,6 +481,7 @@ namespace Tango.MachineStudio.Developer.ViewModels Graphs = new ObservableCollection<IRealTimeGraph>(); _controllers = new Dictionary<String, GraphControllerBase>(); Recorder = new DiagnosticsFileRecorder(); + Player = new DiagnosticsFilePlayer(); } /// <summary> @@ -491,8 +512,10 @@ namespace Tango.MachineStudio.Developer.ViewModels StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); ExitFullScreenCommand = new RelayCommand(ExitFullScreen); - MediaRecordingCommand = new RelayCommand(StartDiagnosticsRecording, () => !Recorder.IsRecording && MachineOperator != null); - MediaStopCommand = new RelayCommand(StopRecorderOrPlayer, () => Recorder.IsRecording); + MediaRecordingCommand = new RelayCommand(StartDiagnosticsRecording, () => !Recorder.IsRecording && MachineOperator != null && !Player.IsPlaying); + MediaStopCommand = new RelayCommand(StopRecorderOrPlayer, () => Recorder.IsRecording || Player.IsPlaying); + MediaLoadCommand = new RelayCommand(LoadDiagnosticsRecordingFile,() => !Recorder.IsRecording && !Player.IsPlaying); + MediaPlayPauseCommand = new RelayCommand(DiagnosticsTogglePlayPause,() => !Recorder.IsRecording && Player.IsLoaded); CaptureDevices = new ObservableCollection<CaptureDevice>(); var availableDevices = CaptureDevice.GetAvailableCaptureDevices(); @@ -518,6 +541,11 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Event Handlers + private void Player_FrameReceived(object sender, DataFileFrame frame) + { + PopulateDiagnosticsData(frame.PushDiagnosticsResponse); + } + private void ApplicationManager_ConnectedMachineChanged(object sender, Integration.Services.IExternalBridgeClient machine) { MachineOperator = machine; @@ -536,27 +564,12 @@ namespace Tango.MachineStudio.Developer.ViewModels Recorder.PushData(response); } - foreach (var prop in response.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + if (!Player.IsPlaying) { - GraphControllerBase controller = null; - - if (_controllers.TryGetValue(prop.Name, out controller)) - { - if (controller is GraphController) - { - double[] arr = Enumerable.ToArray(prop.GetValue(response) as IEnumerable<double>); - (controller as GraphController).PushData(arr); - } - else - { - DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(response) as IEnumerable<DoubleArray>); - (controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList()); - } - } + PopulateDiagnosticsData(response); } } - /// <summary> /// Handles the Saved event of the SelectedMachine. /// </summary> @@ -665,6 +678,74 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void ClearGraphs() + { + _controllers.ToList().ForEach(x => x.Value.Clear()); + } + + private void PopulateDiagnosticsData(PushDiagnosticsResponse data) + { + foreach (var prop in data.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + GraphControllerBase controller = null; + + if (_controllers.TryGetValue(prop.Name, out controller)) + { + if (controller is GraphController) + { + double[] arr = Enumerable.ToArray(prop.GetValue(data) as IEnumerable<double>); + (controller as GraphController).PushData(arr); + } + else + { + DoubleArray[] arrayOfDoubles = Enumerable.ToArray(prop.GetValue(data) as IEnumerable<DoubleArray>); + (controller as GraphMultiController).PushData(arrayOfDoubles.Select(x => x.Data.ToList()).ToList()); + } + } + } + } + + private void DiagnosticsTogglePlayPause() + { + if (!Player.IsPlaying || Player.IsPaused) + { + if (!Player.IsPlaying) + { + ClearGraphs(); + } + Player.Play(); + } + else + { + Player.Pause(); + } + + InvalidateRelayCommands(); + } + + private async void LoadDiagnosticsRecordingFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Title = "Select Tango Diagnostics Recording File"; + dlg.Filter = "Tango Diagnostics Recording|*.tdr"; + if (dlg.ShowDialog().Value) + { + using (_notification.PushTaskItem("Loading Recording...")) + { + if (Player != null) + { + Player.Dispose(); + } + + Player = new DiagnosticsFilePlayer(); + Player.FrameReceived += Player_FrameReceived; + await Player.Load(dlg.FileName); + } + } + + InvalidateRelayCommands(); + } + private void StartDiagnosticsRecording() { using (_notification.PushTaskItem("Starting Recording...")) @@ -677,24 +758,34 @@ namespace Tango.MachineStudio.Developer.ViewModels private async void StopRecorderOrPlayer() { - using (_notification.PushTaskItem("Stopping Recording...")) + if (Recorder.IsRecording) { - await Recorder.Stop(); - } + using (_notification.PushTaskItem("Stopping Recording...")) + { + await Recorder.Stop(); + } - SaveFileDialog dlg = new SaveFileDialog(); - dlg.Title = "Select diagnostics file location"; - dlg.Filter = "Tango Diagnostics Recording|*.tdr"; - if (dlg.ShowDialog().Value) - { - using (_notification.PushTaskItem("Saving Recording...")) + SaveFileDialog dlg = new SaveFileDialog(); + dlg.Title = "Select diagnostics file location"; + dlg.Filter = "Tango Diagnostics Recording|*.tdr"; + if (dlg.ShowDialog().Value) { - await Recorder.Save(dlg.FileName); + using (_notification.PushTaskItem("Saving Recording...")) + { + await Recorder.Save(dlg.FileName); + } } + + Recorder.Dispose(); + Recorder = new DiagnosticsFileRecorder(); + } + else if (Player.IsPlaying) + { + await Player.Stop(); + ClearGraphs(); } - Recorder.Dispose(); - Recorder = new DiagnosticsFileRecorder(); + InvalidateRelayCommands(); } private void ExitFullScreen() @@ -986,6 +1077,13 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedBrushStop != null && SelectedSegment != null) { SelectedSegment.BrushStops.Remove(SelectedBrushStop); + + if (SelectedSegment.BrushStops.Count > 1) + { + SelectedSegment.BrushStops.Last().OffsetPercent = 100; + } + + SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); } } @@ -997,10 +1095,13 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedSegment != null) { var stop = new BrushStop(); + stop.OffsetPercent = 100; + stop.Segment = SelectedSegment; stop.ColorSpace = Adapter.ColorSpaces.FirstOrDefault(); stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(stop); + SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index 33652f119..820c5bb18 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -1608,22 +1608,36 @@ <DockPanel> <DockPanel DockPanel.Dock="Top"> <StackPanel Orientation="Horizontal" DockPanel.Dock="Left" Height="50" VerticalAlignment="Bottom" Margin="0 0 0 5"> - <Button Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="28" Height="28" Background="Transparent" ToolTip="Load Data File"> + <Button Command="{Binding MediaLoadCommand}" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="28" Height="28" Background="Transparent" ToolTip="Load Data File"> <materialDesign:PackIcon Width="20" Height="20" Kind="Eject" Foreground="{StaticResource AccentColorBrush}" /> </Button> - <Button Margin="5 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="35" Height="35" Background="Transparent"> - <materialDesign:PackIcon Width="20" Height="20" Kind="Play" Foreground="{StaticResource AccentColorBrush}" /> + <Button Command="{Binding MediaPlayPauseCommand}" Margin="5 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="35" Height="35" Background="Transparent"> + <materialDesign:PackIcon Width="20" Height="20" Foreground="{StaticResource AccentColorBrush}"> + <materialDesign:PackIcon.Style> + <Style TargetType="materialDesign:PackIcon"> + <Setter Property="Kind" Value="Play"></Setter> + <Style.Triggers> + <MultiDataTrigger> + <MultiDataTrigger.Conditions> + <Condition Binding="{Binding Player.IsPlaying}" Value="True" /> + <Condition Binding="{Binding Player.IsPaused}" Value="False" /> + </MultiDataTrigger.Conditions> + <Setter Property="Kind" Value="Pause"></Setter> + </MultiDataTrigger> + </Style.Triggers> + </Style> + </materialDesign:PackIcon.Style> + </materialDesign:PackIcon> </Button> <Button Command="{Binding MediaStopCommand}" Margin="5 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Padding="0" Width="28" Height="28" Background="Transparent"> <materialDesign:PackIcon Width="20" Height="20" Kind="Stop" Foreground="{StaticResource AccentColorBrush}" /> </Button> <Button Command="{Binding MediaRecordingCommand}" Margin="5 0 0 0" Style="{StaticResource MaterialDesignFloatingActionButton}" Foreground="#FF7A7A" BorderBrush="#FF8585" Padding="0" Width="20" Height="20" Background="Transparent" ToolTip="Start Recording"> - <materialDesign:PackIcon Width="10" Height="10" Kind="Record" /> </Button> </StackPanel> <Grid> - <TextBlock Text="00:00:00 / 00:00:00" Margin="0 -5 0 0" VerticalAlignment="Center" HorizontalAlignment="Right" Foreground="#FF8585" FontSize="20" FontFamily="{StaticResource digital-7}"> + <TextBlock Margin="0 -5 0 0" VerticalAlignment="Center" HorizontalAlignment="Right" Foreground="#FF8585" FontSize="20" FontFamily="{StaticResource digital-7}"> <TextBlock.Style> <Style TargetType="TextBlock"> <Setter Property="Opacity" Value="1"></Setter> @@ -1652,11 +1666,14 @@ </Style.Triggers> </Style> </TextBlock.Style> + <Run Text="{Binding Player.CurrentTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss,FallbackValue='00:00:00'}"/> + <Run>/</Run> + <Run Text="{Binding Player.TotalTime,Mode=OneWay,StringFormat=hh\\:mm\\:ss,FallbackValue='00:00:00'}"/> </TextBlock> </Grid> </DockPanel> <Grid> - <Slider Visibility="{Binding Recorder.IsRecording,Converter={StaticResource BooleanToVisibilityInverseConverter}}"></Slider> + <Slider Visibility="{Binding Recorder.IsRecording,Converter={StaticResource BooleanToVisibilityInverseConverter}}" Maximum="{Binding Player.TotalFrames}" Value="{Binding Player.CurrentFrame}"></Slider> <DockPanel Visibility="{Binding Recorder.IsRecording,Converter={StaticResource BooleanToVisibilityConverter}}"> <TextBlock DockPanel.Dock="Left"> <Run FontWeight="SemiBold" FontStyle="Italic">Total Frames:</Run> |
