public Window2() { Log.writeToLog("Starting FileConverter " + Utilities.getVersionNumber()); Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Title = "Open Header file for conversion..."; dlg.DefaultExt = ".hdr"; // Default file extension dlg.Filter = "HDR Files (.hdr)|*.hdr"; // Filter files by extension Nullable<bool> result = dlg.ShowDialog(); if (result == null || result == false) { this.Close(); Environment.Exit(0); } directory = System.IO.Path.GetDirectoryName(dlg.FileName); head = (new HeaderFileReader(dlg.OpenFile())).read(); ED = head.Events; bdf = new BDFEDFFileReader( new FileStream(System.IO.Path.Combine(directory, head.BDFFile), FileMode.Open, FileAccess.Read)); oldSR = bdf.NSamp / bdf.RecordDurationDouble; oldNP = bdf.NSamp; oldNS = bdf.RecordDurationDouble; InitializeComponent(); this.MinHeight = SystemInformation.WorkingArea.Height - 240; this.Title = "Convert " + System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); this.TitleLine.Text = head.Title + " - " + head.Date + " " + head.Time + " S=" + head.Subject.ToString("0000"); _EDEList = ED.Values.ToList<EventDictionaryEntry>(); listView1.SelectedItem = 0; listView1.Focus(); listView1.ItemsSource = EDEList; System.Windows.Data.Binding GVBinding = new System.Windows.Data.Binding(); GVBinding.Source = this; GVBinding.NotifyOnSourceUpdated = true; GVBinding.Path = new PropertyPath("GVList"); GVBinding.Mode = BindingMode.OneWay; listView2.SetBinding(System.Windows.Controls.ListView.ItemsSourceProperty, GVBinding); GVList = EDEList[0].GroupVars; }
/// <summary> /// Access singleton instance of FactoryEvent; lazy constructor /// </summary> /// <param name="ed">EventDictionary on which all Events are based</param> public static EventFactory Instance(EventDictionary.EventDictionary newED) { if (instance == null) instance = new EventFactory(newED); else if (newED != ed) throw new Exception("Attempt to create second EventFactory"); return instance; }
private EventFactory(EventDictionary.EventDictionary newED) { nBits = newED.Bits; indexMax = (1 << nBits) - 2; //loops from 1 to Event.Index; = 2^n - 2 to avoid double bit change at loopback EventFactory.ed = newED; }
public MainWindow() { Log.writeToLog("Starting DatasetReviewer " + Assembly.GetExecutingAssembly().GetName().Version.ToString()); do { bool r; do { System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog(); dlg.Title = "Open Header file to be displayed..."; dlg.DefaultExt = ".hdr"; // Default file extension dlg.Filter = "HDR Files (.hdr)|*.hdr"; // Filter files by extension bool result = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK; if (!result) Environment.Exit(0); directory = System.IO.Path.GetDirectoryName(dlg.FileName); //will use to find other files in dataset headerFileName = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); try { head = (new HeaderFileReader(dlg.OpenFile())).read(); } catch (Exception e) { r = false; //loop around again ErrorWindow ew = new ErrorWindow(); ew.Message = "Error reading Header file: " + e.Message; continue; } ED = head.Events; try { bdf = new BDFEDFFileStream.BDFEDFFileReader( new FileStream(System.IO.Path.Combine(directory, head.BDFFile), FileMode.Open, FileAccess.Read)); } catch (Exception e) { r = false; //loop around again ErrorWindow ew = new ErrorWindow(); ew.Message = "Error reading BDF file header: " + e.Message; ew.ShowDialog(); continue; } BDFLength = (double)bdf.NumberOfRecords * bdf.RecordDurationDouble; Window1 w = new Window1(this); r = (bool)w.ShowDialog(); } while (r == false); Log.writeToLog(" on dataset " + headerFileName); if (includeANAs) { foreach (EventDictionaryEntry ede in ED.Values) // add ANA channels that are referenced by extrinsic Events { if (ede.IsCovered && ede.IsExtrinsic) { int chan = bdf.ChannelNumberFromLabel(ede.channelName); if (!channelList.Contains(chan)) //don't enter duplicate channelList.Add(chan); } } } } while (channelList.Count == 0); InitializeComponent(); //initialize the individual channel graphs foreach (int i in channelList) { ChannelGraph pg = new ChannelGraph(this, i); GraphCanvas.Children.Add(pg); } Title = headerFileName; //set window title BDFFileInfo.Content = bdf.ToString(); HDRFileInfo.Content = head.ToString(); Event.EventFactory.Instance(head.Events); // set up the factory EventFileReader efr = null; try { efr = new EventFileReader( new FileStream(System.IO.Path.Combine(directory, head.EventFile), FileMode.Open, FileAccess.Read)); // open Event file bool z = false; foreach (Event.InputEvent ie in efr)// read in all Events into dictionary { if (ie.IsNaked) events.Add(ie); else if (events.Count(e => e.GC == ie.GC) == 0) //quietly skip duplicates { if (!z) //use first found covered Event to synchronize clocks z = bdf.setZeroTime(ie); events.Add(ie); } } efr.Close(); //now events is Dictionary of Events in the dataset; lookup by GC } catch (Exception e) { ErrorWindow ew = new ErrorWindow(); ew.Message = "Error reading Event file : " + e.Message + ". Exiting DatasetReviewer."; ew.ShowDialog(); Log.writeToLog(Environment.NewLine + e.StackTrace); Environment.Exit(0); } try { ElectrodeInputFileStream eif = new ElectrodeInputFileStream( new FileStream(System.IO.Path.Combine(directory, head.ElectrodeFile), FileMode.Open, FileAccess.Read)); //open Electrode file electrodes = eif.etrPositions; //read 'em in } catch (Exception e) { ErrorWindow ew = new ErrorWindow(); ew.Message = "Error reading Electrode file : " + e.Message + ". Exitting DatasetReviewer."; ew.ShowDialog(); Log.writeToLog(Environment.NewLine + e.StackTrace); Environment.Exit(0); } EventMarkers.Width = BDFLength; eventTB = new TextBlock(new Run("Events")); Canvas.SetBottom(eventTB, ScrollBarSize + 13D); //initialize gridline array for (int i = 0; i < 18; i++) { Line l = new Line(); Grid.SetRow(l, 0); Grid.SetColumn(l, 0); Grid.SetColumnSpan(l, 2); l.Y1 = 0D; l.HorizontalAlignment = HorizontalAlignment.Left; l.VerticalAlignment = VerticalAlignment.Stretch; l.IsHitTestVisible = false; l.Stroke = Brushes.LightBlue; l.Visibility = Visibility.Hidden; Panel.SetZIndex(l, int.MinValue); MainFrame.Children.Add(l); gridlines[i] = l; } //Initialize timer timer.AutoReset = true; timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); //Initialize channel information popup Color c1 = Color.FromArgb(0xFF, 0xF8, 0xF8, 0xF8); Color c2 = Color.FromArgb(0xFF, 0xC8, 0xC8, 0xC8); popupTB.Background = new LinearGradientBrush(c1, c2, 45D); popupTB.Foreground = Brushes.Black; popupTB.Padding = new Thickness(4D); Border b = new Border(); b.BorderThickness = new Thickness(1); b.CornerRadius = new CornerRadius(4); b.BorderBrush = Brushes.Tomato; b.Margin = new Thickness(0, 0, 24, 24); //allows drop shadow to show up b.Effect = new DropShadowEffect(); b.Child = popupTB; channelPopup.Placement = PlacementMode.MousePoint; channelPopup.AllowsTransparency = true; channelPopup.Child = b; //Initialize Event information popup eventPopupTB.Background = new LinearGradientBrush(c1, c2, 45D); eventPopupTB.Foreground = Brushes.Black; eventPopupTB.Padding = new Thickness(4D); b = new Border(); b.BorderThickness = new Thickness(1); b.CornerRadius = new CornerRadius(4); b.BorderBrush = Brushes.Tomato; b.Margin = new Thickness(0, 0, 24, 24); //allows drop shadow to show up b.Effect = new DropShadowEffect(); b.Child = eventPopupTB; eventPopup.Placement = PlacementMode.MousePoint; eventPopup.AllowsTransparency = true; eventPopup.Child = b; //Initialize FOV slider FOV.Maximum = Math.Log10(BDFLength); FOV.Value = 1D; FOVMax.Text = BDFLength.ToString("0"); //Initialize Event selector bool first = true; foreach (EventDictionaryEntry e in head.Events.Values) { MenuItem mi = (MenuItem)EventSelector.FindResource("EventMenuItem"); mi.Header = e.Name; if (first) { mi.IsChecked = true; first = false; } EventSelector.Items.Add(mi); } noteFilePath = System.IO.Path.Combine(directory,System.IO.Path.ChangeExtension(head.BDFFile,".notes.txt")); //from here on the program is GUI-event driven }
public Window2() { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open Header file ..."; dlg.DefaultExt = ".hdr"; // Default file extension dlg.Filter = "HDR Files (.hdr)|*.hdr"; // Filter files by extension dlg.InitialDirectory = Properties.Settings.Default.LastDataset; bool result = dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK; if (!result) Environment.Exit(0); headerFileName = System.IO.Path.GetFileNameWithoutExtension(dlg.FileName); directory = System.IO.Path.GetDirectoryName(dlg.FileName); Properties.Settings.Default.LastDataset = directory; CCIUtilities.Log.writeToLog("Starting ASCtoFMConverter " + CCIUtilities.Utilities.getVersionNumber()); head = (new HeaderFileReader(dlg.OpenFile())).read(); ED = head.Events; bdf = new BDFEDFFileReader( new FileStream(System.IO.Path.Combine(directory, head.BDFFile), FileMode.Open, FileAccess.Read)); samplingRate = (int)((double)bdf.NSamp / bdf.RecordDurationDouble); OpenPCommand.InputGestures.Add( new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift, "Ctrl+Shift+O")); SavePCommand.InputGestures.Add( new KeyGesture(Key.S, ModifierKeys.Control, "Crtl+S")); ProcessCommand.InputGestures.Add( new KeyGesture(Key.P, ModifierKeys.Control, "Crtl+P")); ExitCommand.InputGestures.Add(new KeyGesture(Key.Q, ModifierKeys.Control, "Crtl+Q")); InitializeComponent(); //***** Set up menu commands and short cuts CommandBinding cbOpenP = new CommandBinding(OpenPCommand, cbOpen_Execute, cbOpen_CanExecute); this.CommandBindings.Add(cbOpenP); CommandBinding cbSaveP = new CommandBinding(SavePCommand, cbSave_Execute, validParams_CanExecute); this.CommandBindings.Add(cbSaveP); CommandBinding cbProcess = new CommandBinding(ProcessCommand, ConvertFM_Click, validParams_CanExecute); this.CommandBindings.Add(cbProcess); CommandBinding cbExit = new CommandBinding(ExitCommand, Done_Click, cbExit_CanExecute); this.CommandBindings.Add(cbExit); this.MinHeight = SystemInformation.WorkingArea.Height - 240; this.EpisodeEntries.Items.Add(new EpisodeDescriptionEntry(head, this)); //include initial episode description this.Title = "Convert " + headerFileName; this.TitleLine.Text = head.Title + " - " + head.Date + " " + head.Time + " S=" + head.Subject.ToString("0000"); if (head.GroupVars != null) { System.Windows.Data.Binding GVBinding = new System.Windows.Data.Binding(); GVBinding.Source = this; GVBinding.NotifyOnSourceUpdated = true; GVBinding.Path = new PropertyPath("GVList"); GVBinding.Mode = BindingMode.OneWay; listView2.SetBinding(System.Windows.Controls.ListView.ItemsSourceProperty, GVBinding); GVList = head.GroupVars.Values.ToList<GVEntry>(); } else GVList = new List<GVEntry>(0); this.Activate(); }