From e4c917c43e90a4453c6cd5b1842a418dc0f1b514 Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 15 Feb 2018 00:29:13 +0200 Subject: Working on Data Capture Module.. --- .../Recording/DataRecording.cs | 23 ++++-- .../Tango.MachineStudio.DataCapture.csproj | 7 ++ .../ViewModels/MainViewVM.cs | 83 +++++++++++++++------- .../Views/MainView.xaml | 5 +- .../Views/PlayingBarView.xaml | 53 ++++++++++++++ .../Views/PlayingBarView.xaml.cs | 28 ++++++++ .../ViewModels/MainViewVM.cs | 31 ++++---- 7 files changed, 185 insertions(+), 45 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Recording/DataRecording.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Recording/DataRecording.cs index a191c244e..ddf24e113 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Recording/DataRecording.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Recording/DataRecording.cs @@ -1,14 +1,31 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.Core; +using Tango.Integration.Diagnostics; namespace Tango.MachineStudio.DataCapture.Recording { public class DataRecording : ExtendedObject { + public DataRecording() + { + Date = DateTime.Now; + } + + public DataRecording(String filePath) : this() + { + FilePath = filePath; + } + + public DataRecording(String filePath, DateTime date) : this(filePath) + { + Date = date; + } + private DateTime _date; public DateTime Date @@ -17,12 +34,9 @@ namespace Tango.MachineStudio.DataCapture.Recording set { _date = value; RaisePropertyChangedAuto(); } } - private String _name; - public String Name { - get { return _name; } - set { _name = value; RaisePropertyChangedAuto(); } + get { return Path.GetFileNameWithoutExtension(FilePath); } } private String _file; @@ -33,5 +47,6 @@ namespace Tango.MachineStudio.DataCapture.Recording set { _file = value; RaisePropertyChangedAuto(); } } + public DiagnosticsFilePlayer Player { get; set; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj index 1c13be809..8936a66db 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj @@ -81,6 +81,9 @@ GlobalVersionInfo.cs + + PlayingBarView.xaml + RecordingBarView.xaml @@ -88,6 +91,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs index b63ee51d0..269007dac 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/ViewModels/MainViewVM.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; @@ -32,6 +33,8 @@ namespace Tango.MachineStudio.DataCapture.ViewModels private IStudioApplicationManager _applicationManager; private IDiagnosticsFrameProvider _frameProvider; private String _recordingsFolder; + private BarItem _recordingBarItem; + private BarItem _playerBarItem; #region Properties @@ -52,7 +55,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels public DataRecording SelectedRecording { get { return _selectedRecording; } - set { _selectedRecording = value; RaisePropertyChangedAuto(); } + set { _selectedRecording = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } } /// @@ -140,35 +143,29 @@ namespace Tango.MachineStudio.DataCapture.ViewModels ToggleCameraCommand = new RelayCommand(ToggleCamera); - Recordings.Add(new DataRecording() - { - Name = "Recording 1" - }); - Recordings.Add(new DataRecording() - { - Name = "Recording 2" - }); - Recordings.Add(new DataRecording() - { - Name = "Recording 3" - }); - RemoveRecordingCommand = new RelayCommand(RemoveRecording); MediaRecordingCommand = new RelayCommand(StartDiagnosticsRecording, () => !Recorder.IsRecording && MachineOperator != null && !Player.IsPlaying); MediaStopCommand = new RelayCommand(StopRecorderOrPlayer, () => Recorder.IsRecording || Player.IsPlaying); - MediaPlayPauseCommand = new RelayCommand(DiagnosticsTogglePlayPause, () => !Recorder.IsRecording && Player.IsLoaded); + MediaPlayPauseCommand = new RelayCommand(DiagnosticsTogglePlayPause, () => !Recorder.IsRecording && SelectedRecording != null); _recordingsFolder = Path.Combine(SettingsManager.DefaultFolder, "Recordings"); Directory.CreateDirectory(_recordingsFolder); _frameProvider.FrameReceived += _frameProvider_FrameReceived; - _notification.PushBarItem(new RecordingBarView() { DataContext = this }); - applicationManager.ConnectedMachineChanged += ApplicationManager_ConnectedMachineChanged; + + _recordingBarItem = new BarItem(_notification, new RecordingBarView() { DataContext = this }); + _playerBarItem = new BarItem(_notification, new PlayingBarView() { DataContext = this }); + + LoadRecordings(); } + #endregion + + #region Event Handlers + private void ApplicationManager_ConnectedMachineChanged(object sender, Integration.Services.IExternalBridgeClient machine) { MachineOperator = machine; @@ -186,10 +183,19 @@ namespace Tango.MachineStudio.DataCapture.ViewModels } } + #endregion #region Private Methods + private void LoadRecordings() + { + foreach (var file in Directory.GetFiles(_recordingsFolder, "*.tdr")) + { + Recordings.Add(new DataRecording(file, File.GetCreationTime(file))); + } + } + /// /// Removes the recording. /// @@ -211,11 +217,28 @@ namespace Tango.MachineStudio.DataCapture.ViewModels } } - private void DiagnosticsTogglePlayPause() + private async void DiagnosticsTogglePlayPause() { if (!Player.IsPlaying || Player.IsPaused) { _frameProvider.Disable = true; + + if (SelectedRecording.Player == null) + { + using (_notification.PushTaskItem("Loading Recording...")) + { + SelectedRecording.Player = new DiagnosticsFilePlayer(); + await SelectedRecording.Player.Load(SelectedRecording.FilePath); + } + } + + RegisterPlayer(SelectedRecording.Player); + + if (!Player.IsPlaying) + { + _playerBarItem.Push(); + } + Player.Play(); } else @@ -226,21 +249,21 @@ namespace Tango.MachineStudio.DataCapture.ViewModels InvalidateRelayCommands(); } - private async void LoadSelectedRecording() + private void RegisterPlayer(DiagnosticsFilePlayer player) { - using (_notification.PushTaskItem("Loading Recording...")) + foreach (var recording in Recordings) { - if (Player != null) + if (recording.Player != null) { - Player.Dispose(); + recording.Player.FrameReceived -= Player_FrameReceived; } + } - Player = new DiagnosticsFilePlayer(); + if (player != null) + { + Player = player; Player.FrameReceived += Player_FrameReceived; - await Player.Load(SelectedRecording.FilePath); } - - InvalidateRelayCommands(); } private void Player_FrameReceived(object sender, DataFileFrame frame) @@ -256,6 +279,8 @@ namespace Tango.MachineStudio.DataCapture.ViewModels using (_notification.PushTaskItem("Starting Recording...")) { Recorder.Start(); + + _recordingBarItem.Push(); } InvalidateRelayCommands(); @@ -268,6 +293,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels using (_notification.PushTaskItem("Stopping Recording...")) { await Recorder.Stop(); + _recordingBarItem.Pop(); } String recordingName = _notification.ShowTextInput("Enter recording name", "Recording name"); @@ -276,7 +302,9 @@ namespace Tango.MachineStudio.DataCapture.ViewModels { using (_notification.PushTaskItem("Saving Recording...")) { - await Recorder.Save(Path.Combine(_recordingsFolder, recordingName + ".tdr")); + String filePath = Path.Combine(_recordingsFolder, recordingName + ".tdr"); + await Recorder.Save(filePath); + Recordings.Insert(0, new DataRecording(filePath)); } } @@ -287,6 +315,7 @@ namespace Tango.MachineStudio.DataCapture.ViewModels { await Player.Stop(); _frameProvider.Disable = false; + _playerBarItem.Pop(); } InvalidateRelayCommands(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml index 74addf942..72f7da03d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/MainView.xaml @@ -17,6 +17,7 @@ + @@ -38,7 +39,7 @@ - + @@ -50,7 +51,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml new file mode 100644 index 000000000..3e76ce6ef --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml @@ -0,0 +1,53 @@ + + + + + + + + / + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.xaml.cs new file mode 100644 index 000000000..f9e502f8b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Views/PlayingBarView.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.DataCapture.Views +{ + /// + /// Interaction logic for RecordingBarView.xaml + /// + public partial class PlayingBarView : UserControl + { + public PlayingBarView() + { + InitializeComponent(); + } + } +} 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 148e4375c..10c35b3b9 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 @@ -29,6 +29,7 @@ using Tango.Integration.Printing; using Tango.Integration.Diagnostics; using Microsoft.Win32; using Tango.MachineStudio.Technician.ViewModels; +using Tango.MachineStudio.Common.Diagnostics; namespace Tango.MachineStudio.Developer.ViewModels { @@ -496,10 +497,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The application manager. /// The notification provider. [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view) : this(view) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider) : this(view) { _notification = notificationProvider; ApplicationManager = applicationManager; + diagnosticsFrameProvider.FrameReceived += DiagnosticsFrameProvider_FrameReceived; //Initialize Commands... EditMachineCommand = new RelayCommand(EditMachine, () => SelectedMachine != null); @@ -520,8 +522,8 @@ namespace Tango.MachineStudio.Developer.ViewModels ExitFullScreenCommand = new RelayCommand(ExitFullScreen); 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); + MediaLoadCommand = new RelayCommand(LoadDiagnosticsRecordingFile, () => !Recorder.IsRecording && !Player.IsPlaying); + MediaPlayPauseCommand = new RelayCommand(DiagnosticsTogglePlayPause, () => !Recorder.IsRecording && Player.IsLoaded); CaptureDevices = new ObservableCollection(); var availableDevices = CaptureDevice.GetAvailableCaptureDevices(); @@ -549,6 +551,11 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Event Handlers + private void DiagnosticsFrameProvider_FrameReceived(object sender, PushDiagnosticsResponse response) + { + PopulateDiagnosticsData(response); + } + private void Player_FrameReceived(object sender, DataFileFrame frame) { PopulateDiagnosticsData(frame.PushDiagnosticsResponse); @@ -567,15 +574,15 @@ namespace Tango.MachineStudio.Developer.ViewModels private void MachineOperator_DiagnosticsDataAvailable(object sender, PushDiagnosticsResponse response) { - if (Recorder.IsRecording) - { - Recorder.Write(response); - } + //if (Recorder.IsRecording) + //{ + // Recorder.Write(response); + //} - if (!Player.IsPlaying) - { - PopulateDiagnosticsData(response); - } + //if (!Player.IsPlaying) + //{ + // PopulateDiagnosticsData(response); + //} } /// @@ -1085,7 +1092,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedBrushStop != null && SelectedSegment != null) { SelectedSegment.BrushStops.Remove(SelectedBrushStop); - + if (SelectedSegment.BrushStops.Count > 1) { SelectedSegment.BrushStops.Last().OffsetPercent = 100; -- cgit v1.3.1