diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 163 |
1 files changed, 132 insertions, 31 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()); } } |
