Example #1
0
 public ChannelGraph(MainWindow containingWindow, int channelNumber)
     : base()
 {
     _channel = channelNumber;
     this.Width = containingWindow.BDFLength; //NOTE: always scaled in seconds
     bdf = containingWindow.bdf;
     _channelLabel = new TextBlock(new Run(bdf.channelLabel(_channel)));
     this.VerticalAlignment = VerticalAlignment.Top;
     path.Stroke = Brushes.Black;
     path.StrokeLineJoin = PenLineJoin.Round;
     path.Data = geometry;
     this.Children.Add(path);
     this.ToolTip = bdf.channelLabel(_channel) + "(" + (_channel + 1).ToString("0") + ")";
     baseline.X1 = 0;
     baseline.HorizontalAlignment = HorizontalAlignment.Left;
     baseline.VerticalAlignment = VerticalAlignment.Top;
     baseline.Stroke = Brushes.LightBlue;
     Grid.SetColumn(baseline, 0);
     Grid.SetRow(baseline, 0);
     Grid.SetColumnSpan(baseline, 2);
     Panel.SetZIndex(baseline, int.MinValue);
     containingWindow.MainFrame.Children.Add(baseline);
 }
Example #2
0
        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 PKDetectorEventCounterDescription(BDFEDFFileStream.BDFEDFFileReader BDF)
 {
     bdf = BDF;
 }