From a99317fcf5d6417c109f3af03d1b53394eb77c77 Mon Sep 17 00:00:00 2001 From: Brian Tabone Date: Sat, 23 Nov 2019 14:56:25 -0600 Subject: [PATCH 1/2] Added drag and drop workbook files onto window to load them --- Signals And Transforms/MainWindow.xaml | 2 +- Signals And Transforms/MainWindow.xaml.cs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Signals And Transforms/MainWindow.xaml b/Signals And Transforms/MainWindow.xaml index d5b8326..9e1a957 100644 --- a/Signals And Transforms/MainWindow.xaml +++ b/Signals And Transforms/MainWindow.xaml @@ -10,7 +10,7 @@ xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon" mc:Ignorable="d" Title="Signals And Transforms" Height="768" Width="1380"> - + diff --git a/Signals And Transforms/MainWindow.xaml.cs b/Signals And Transforms/MainWindow.xaml.cs index b41bbcf..963f853 100644 --- a/Signals And Transforms/MainWindow.xaml.cs +++ b/Signals And Transforms/MainWindow.xaml.cs @@ -121,5 +121,27 @@ private void MenuItemLoad_Click(object sender, RoutedEventArgs e) SetActiveWorkbookTitle(); } } + + /// + /// Handle the user action of dropping a workbook file onto the app to open. If it + /// isn't a workbook file (ending in the WORKBOOK_FILE_EXTENSION) then it is ignored + /// + /// + /// + private void LayoutRoot_Drop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + // Note that you can have more than one file. + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + string file = files[0]; + // Make active + if (file.EndsWith(Properties.Resources.WORKBOOK_FILE_EXTENSION)) + { + WorkBookManager.Manager().Load(file, true); + SetActiveWorkbookTitle(); + } + } + } } } From f1c859b45764c36a66983eec4e4d3796d2bdf229 Mon Sep 17 00:00:00 2001 From: Brian Tabone Date: Sat, 23 Nov 2019 15:11:57 -0600 Subject: [PATCH 2/2] Fixed bug on navigation to convolution without any signal data (caused crash) --- Signals And Transforms/MainWindow.xaml.cs | 17 ++++++++++++----- Signals And Transforms/Models/WorkBook.cs | 5 +++++ .../View Models/ConvolutionViewModel.cs | 5 +++++ .../View Models/SignalGeneratorViewModel.cs | 6 +++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Signals And Transforms/MainWindow.xaml.cs b/Signals And Transforms/MainWindow.xaml.cs index 963f853..99d546b 100644 --- a/Signals And Transforms/MainWindow.xaml.cs +++ b/Signals And Transforms/MainWindow.xaml.cs @@ -116,9 +116,7 @@ private void MenuItemLoad_Click(object sender, RoutedEventArgs e) openFileDialog.Filter = $"{Properties.Resources.DATABASE_FILES} (*{Properties.Resources.WORKBOOK_FILE_EXTENSION})|*{Properties.Resources.WORKBOOK_FILE_EXTENSION}|{Properties.Resources.ALL_FILES} (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { - // Make active - WorkBookManager.Manager().Load(openFileDialog.FileName, true); - SetActiveWorkbookTitle(); + SetActiveWorkbook(openFileDialog.FileName); } } @@ -138,10 +136,19 @@ private void LayoutRoot_Drop(object sender, DragEventArgs e) // Make active if (file.EndsWith(Properties.Resources.WORKBOOK_FILE_EXTENSION)) { - WorkBookManager.Manager().Load(file, true); - SetActiveWorkbookTitle(); + SetActiveWorkbook(file); } } } + + /// + /// Open the workbook specified in the file pathname variable and set to active workbook + /// + /// + private void SetActiveWorkbook(string file) + { + WorkBookManager.Manager().Load(file, true); + SetActiveWorkbookTitle(); + } } } diff --git a/Signals And Transforms/Models/WorkBook.cs b/Signals And Transforms/Models/WorkBook.cs index 8584fe8..5be98d4 100644 --- a/Signals And Transforms/Models/WorkBook.cs +++ b/Signals And Transforms/Models/WorkBook.cs @@ -56,6 +56,11 @@ public Signal SumOfSources() { List signals = new List(Signals.Values); Signal baseSignal = signals.Where(sig => sig.Type == SignalType.Source).FirstOrDefault(); + if (baseSignal == null) + { + return null; + } + Signal workbookSourceSignal = new Signal(); workbookSourceSignal.Name = "Source"; workbookSourceSignal.SamplingHZ = baseSignal.SamplingHZ; diff --git a/Signals And Transforms/View Models/ConvolutionViewModel.cs b/Signals And Transforms/View Models/ConvolutionViewModel.cs index cea4a15..dc10161 100644 --- a/Signals And Transforms/View Models/ConvolutionViewModel.cs +++ b/Signals And Transforms/View Models/ConvolutionViewModel.cs @@ -107,6 +107,11 @@ public void PlotData() { Signal workbookSourceSignal = manager.ActiveWorkBook().SumOfSources(); + if (workbookSourceSignal == null) + { + return; + } + SignalPlotPoints = new List(workbookSourceSignal.Samples.Count); for (int idx = 0; idx < workbookSourceSignal.Samples.Count; idx++) diff --git a/Signals And Transforms/View Models/SignalGeneratorViewModel.cs b/Signals And Transforms/View Models/SignalGeneratorViewModel.cs index 81ff317..ee31126 100644 --- a/Signals And Transforms/View Models/SignalGeneratorViewModel.cs +++ b/Signals And Transforms/View Models/SignalGeneratorViewModel.cs @@ -70,7 +70,11 @@ public void PlotSignals() FrequencyHistogram = new List(512); Signal workbookSourceSignal = workBookManager.ActiveWorkBook().SumOfSources(); - + if (workbookSourceSignal == null) + { + return; + } + // Test data for now for (int idx=0; idx