예제 #1
0
        /// <summary>
        /// PDF click event. Generates a PDF with the cochleogram, histogram, sonogram, disparity between cochleae and average activity of the loaded aedat file.
        /// </summary>
        private void Btn_PDF_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog savePDFDialog = new SaveFileDialog();

            savePDFDialog.Title  = "Select a name and a path for the .pdf file";
            savePDFDialog.Filter = "pdf files|*.pdf";
            if (savePDFDialog.ShowDialog() == true)
            {
                this.Cursor = Cursors.Wait;
                Document  doc = new Document();
                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(savePDFDialog.FileName, FileMode.Create));
                doc.SetPageSize(iTextSharp.text.PageSize.A4);
                doc.SetMargins(50, 50, 50, 50);
                doc.Open();

                #region Fonts
                iTextSharp.text.Font fTitle = FontFactory.GetFont("Arial", 30, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                iTextSharp.text.Font fHead  = FontFactory.GetFont("Arial", 18, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                iTextSharp.text.Font fText  = FontFactory.GetFont("Arial", 11, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
                #endregion

                #region Main page
                iTextSharp.text.Paragraph title = new iTextSharp.text.Paragraph("\n\n\n\n\nData Report for " + fileName, fTitle);
                title.Alignment = Element.ALIGN_CENTER;
                doc.Add(title);
                if (settings.PdfS.showDate)
                {
                    iTextSharp.text.Paragraph date = new iTextSharp.text.Paragraph("\n\n" + DateTime.Now);
                    date.Alignment = Element.ALIGN_RIGHT;
                    doc.Add(date);
                }
                #endregion
                if (settings.PdfS.showCochleogram || settings.PdfS.showHistogram)
                {
                    doc.SetMargins(0, 30, 50, 30);
                    doc.NewPage();
                }
                iTextSharp.text.Paragraph paragraph;
                #region Cochleogram
                if (settings.PdfS.showCochleogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("           1. Cochleogram\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     The following charts represents the cochleogram for both cochleae.\n", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - " + settings.MainS.leftColor + " - Left Cochlea.", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - " + settings.MainS.rightColor + " - Right Cochlea.\n\n\n", fText);
                    doc.Add(paragraph);

                    using (MemoryStream stream = new MemoryStream())
                    {
                        chart_Cochleogram.SaveImage(stream, ImageFormat.Png);
                        iTextSharp.text.Image chartImage2 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage2.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f);
                        doc.Add(chartImage2);
                    }
                }
                #endregion
                #region Histogram
                if (settings.PdfS.showHistogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("\n           2. Histogram\n\n", fHead);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        Histogram spd = new Histogram();
                        spd.chart_Histogram.Width  = 773;
                        spd.chart_Histogram.Height = 350;
                        spd.chart_Histogram.SaveImage(stream, ChartImageFormat.Png);
                        iTextSharp.text.Image chartImage3 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage3.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(chartImage3);
                    }
                }
                #endregion
                if (settings.PdfS.showSonogram || settings.PdfS.showDiff)
                {
                    doc.SetMargins(50, 30, 50, 30);
                    doc.NewPage();
                }
                #region Sonogram
                if (settings.PdfS.showSonogram)
                {
                    paragraph = new iTextSharp.text.Paragraph("           3. Sonogram\n\n", fHead);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (settings.MainS.eventSize == 16)
                        {
                            aedatObject16.generateSonogram("archivobmp", aedatObject16.maxValueSonogram());
                        }
                        else if (settings.MainS.eventSize == 32)
                        {
                            aedatObject32.generateSonogram("archivobmp", aedatObject32.maxValueSonogram());
                        }
                        Sonogram sd = new Sonogram();
                        iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Sonogram), ImageFormat.Bmp);
                        image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(image1);
                    }
                }
                #endregion
                #region Disparity
                if (settings.PdfS.showDiff && (cochleaInfo == EnumCochleaInfo.STEREO32 || cochleaInfo == EnumCochleaInfo.STEREO64 || cochleaInfo == EnumCochleaInfo.STEREO128 || cochleaInfo == EnumCochleaInfo.STEREO256))
                {
                    paragraph = new iTextSharp.text.Paragraph("\n\n           4. Disparity between cochleae\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     Disparity between both cochleae.\n", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - Red: left cochlea predominance.", fText);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                         - Green: right cochlea predominance.\n\n\n", fText);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        if (settings.MainS.eventSize == 16)
                        {
                            aedatObject16.generateDisparity("archivobmpDiff", aedatObject16.maxValueSonogram());
                        }

                        else if (settings.MainS.eventSize == 32)
                        {
                            aedatObject32.generateDisparity("archivobmpDiff", aedatObject32.maxValueSonogram());
                        }
                        Difference            sd     = new Difference();
                        iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(ImageToBitmap(sd.Img_Difference), ImageFormat.Bmp);
                        image1.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 100, iTextSharp.text.PageSize.A4.Height - 200);
                        doc.Add(image1);
                    }
                }
                #endregion
                #region Average activity
                if (settings.PdfS.showAverage)
                {
                    doc.SetMargins(0, 30, 50, 30);
                    doc.NewPage();
                    paragraph = new iTextSharp.text.Paragraph("\n\n           5. Average activity of both cochleae\n\n", fHead);
                    doc.Add(paragraph);
                    paragraph = new iTextSharp.text.Paragraph("                     Each dot represents the average of events of a certain time period (Integration Period = " + settings.ToolsS.integrationPeriod.ToString() + " us ).\n", fText);
                    doc.Add(paragraph);
                    using (MemoryStream stream = new MemoryStream())
                    {
                        Average m = new Average();
                        m.chart_Average.Width  = 846;
                        m.chart_Average.Height = 322;
                        m.chart_Average.SaveImage(stream, ChartImageFormat.Png);
                        iTextSharp.text.Image chartImage4 = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                        chartImage4.ScaleToFit(iTextSharp.text.PageSize.A4);// ScalePercent(75f);
                        doc.Add(chartImage4);
                    }
                }
                #endregion
                doc.Close();

                InfoWindow iw = new InfoWindow("PDF generated", "The PDF file was generated succesfully and it's available at the path you chose");  // Tell the user that the process went OK
                iw.ShowDialog();

                this.Cursor = Cursors.Arrow;
            }
        }
예제 #2
0
        private void Btn_saveCSV_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd         = new SaveFileDialog();
            StringBuilder  sb_csv      = new StringBuilder();
            float          mult_factor = 0.1f;

            sfd.Filter = "CSV file (.csv)|*.csv";

            sfd.Title = "Select path to save the csv file";
            sfd.ShowDialog();

            if (sfd.FileName != "")
            {
                switch (MainWindow.settings.MainS.eventSize)
                {
                case 16: mult_factor = 0.2f; break;

                case 32: mult_factor = 0.1f; break;
                }


                if (chart_Average.Series[1].Points.Count > 0)
                {
                    sb_csv.Append(chart_Average.Series[0].Name + "_X;" + chart_Average.Series[0].Name + "_Y;" + chart_Average.Series[1].Name + "_X;" + chart_Average.Series[1].Name + "_Y;\n");
                }
                else
                {
                    sb_csv.Append("Mono_X;" + "Mono_Y;\n");
                }


                if (chart_Average.Series[1].Points.Count > 0)
                {
                    for (int i = 0; i < chart_Average.Series[0].Points.Count; i++)
                    {
                        sb_csv.Append((chart_Average.Series[0].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[0].Points[i].YValues[0].ToString("0.######################") + ";" + (chart_Average.Series[1].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[1].Points[i].YValues[0].ToString("0.######################") + ";\n");
                    }
                }
                else
                {
                    for (int i = 0; i < chart_Average.Series[0].Points.Count; i++)
                    {
                        sb_csv.Append((chart_Average.Series[0].Points[i].XValue * mult_factor).ToString("0.######################") + ";" + chart_Average.Series[0].Points[i].YValues[0].ToString("0.######################") + ";\n");
                    }
                }

                File.AppendAllText(sfd.FileName, sb_csv.Replace(",", ".").ToString());
                InfoWindow iw = new InfoWindow("Success!", "CSV file saved successfuly");
                iw.ShowDialog();
            }


            /*
             * if (MainWindow.settings.MainS.eventSize == 16)
             * {
             *  c16.generateSonogramCSV(sfd.FileName);
             * }
             *
             * else if (MainWindow.settings.MainS.eventSize == 32)
             * {
             *  c32.generateSonogramCSV(sfd.FileName);
             * }
             *
             * InfoWindow iw = new InfoWindow("Success!", "CSV file saved successfuly");
             * iw.ShowDialog();
             */
        }
예제 #3
0
        /// <summary>
        /// Load the aedat or CSV file selected by the user
        /// </summary>
        public void loadFile()
        {
            if (selectFileDialog.ShowDialog() == true)
            {
                try
                {
                    root        = selectFileDialog.FileName;
                    this.Cursor = Cursors.Wait;
                    fileName    = root.Split('\\')[root.Split('\\').Length - 1];



                    if (settings.MainS.eventSize == 16)
                    {
                        aedatObject16 = new aedat16(root);
                        aedatObject16.adaptAedat();
                    }
                    else if (settings.MainS.eventSize == 32)
                    {
                        aedatObject32 = new aedat32(root);
                        aedatObject32.adaptAedat();
                    }
                    TB_aedatName.Text         = fileName;
                    tab_fileLoaded.Visibility = Visibility.Visible;

                    isLoaded = true;

                    initState();
                    displayCharts();

                    for (int i = 2; i < buttonList.Count; i++)  //Enable tools buttons after loading the file
                    {
                        buttonList[i].IsEnabled = true;
                        buttonList[i].Opacity   = 1;
                    }
                    if (cochleaInfo == EnumCochleaInfo.MONO32 || cochleaInfo == EnumCochleaInfo.MONO64 || cochleaInfo == EnumCochleaInfo.MONO128 || cochleaInfo == EnumCochleaInfo.MONO256) // If the file corresponds to a mono sound, there's no point on enabling the "Disparity between cochleae" function.
                    {
                        Btn_difference.IsEnabled   = false;
                        Btn_difference.Opacity     = 0.6;
                        Btn_StereoToMono.IsEnabled = false;
                        Btn_StereoToMono.Opacity   = 0.6;
                        Btn_MonoToStereo.IsEnabled = true;
                        Btn_MonoToStereo.Opacity   = 1;
                    }
                    else
                    {
                        Btn_difference.IsEnabled   = true;
                        Btn_difference.Opacity     = 1;
                        Btn_StereoToMono.IsEnabled = true;
                        Btn_StereoToMono.Opacity   = 1;
                        Btn_MonoToStereo.IsEnabled = false;
                        Btn_MonoToStereo.Opacity   = 0.6;
                    }
                    menuItem_Reload.IsEnabled = true; menuItem_Report.IsEnabled = true; menuItem_Tools.IsEnabled = true;

                    this.Cursor = Cursors.Arrow;

                    InfoWindow iw = new InfoWindow("Success!", "The Aedat file was loaded correctly"); // Show the user a message saying that everything went OK
                    iw.ShowDialog();
                }
                catch (Exception e)
                {
                    this.Cursor = Cursors.Arrow;
                    InfoWindow iw = new InfoWindow("Error", "The Aedat file was not loaded correctly. This may be caused by an incorrect\nconfiguration of the number of channels and address length in NAVIS' settings.");
                    iw.ShowDialog();
                    for (int i = 2; i < buttonList.Count; i++)  //Enable tools buttons after loading the file
                    {
                        buttonList[i].IsEnabled = false;
                        buttonList[i].Opacity   = 0.6;
                    }
                    menuItem_Reload.IsEnabled = false; menuItem_Report.IsEnabled = false; menuItem_Tools.IsEnabled = false;
                    tab_fileLoaded.Visibility = Visibility.Hidden;
                }
            }
        }