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..99d546b 100644 --- a/Signals And Transforms/MainWindow.xaml.cs +++ b/Signals And Transforms/MainWindow.xaml.cs @@ -116,10 +116,39 @@ 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); } } + + /// + /// 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)) + { + 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