Ejemplo n.º 1
0
        public void HandleFileLoad(string fileName)
        {
            try
            {
                //check if par & spc exists!
                if (Path.GetExtension(fileName) == ".spc" || Path.GetExtension(fileName) == ".par")
                {
                    if (File.Exists(fileName) && File.Exists(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".spc") && (File.Exists(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".par")))
                    {
                        this.createMDIChild(fileName);
                    }
                }
                else if (Path.GetExtension(fileName) == ".bp2")
                {
                    //check if bp2 exists
                    if (File.Exists(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".bp2"))
                    {
                        string json = File.ReadAllText(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".bp2");
                        PlottableEPRSpectrum spc_tmp = JsonConvert.DeserializeObject <PlottableEPRSpectrum>(json, new JsonSerializerSettings
                        {
                            ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
                        });

                        PlottableEPRSpectrum spc = new PlottableEPRSpectrum(spc_tmp.fileName);
                        spc.g = spc_tmp.g;
                        spc.A = spc_tmp.A;
                        createMDIChild(spc);
                        this.RefreshData();
                        if (spc_tmp.showInt)
                        {
                            spc.showInt = true;
                            this.IntButton.Foreground = Brushes.Magenta;
                            spc.plotInt(this.getActivePlotView());
                        }
                        if (spc_tmp.showDeriv)
                        {
                            spc.showDeriv = true;
                            this.DerivButton.Foreground = Brushes.SaddleBrown;
                            spc.plotDeriv(this.getActivePlotView());
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        public List <PlottableEPRSpectrum> getAllSpectra()
        {
            List <PlottableEPRSpectrum> EPRSpectra = new List <PlottableEPRSpectrum>();

            if (mdiTabMenu.Items.Count != 0)
            {
                foreach (TabItem tab in mdiTabMenu.Items)
                {
                    StackPanel           sp       = (StackPanel)tab.Content;
                    EPRPlotView          plotView = (EPRPlotView)sp.Children[0];
                    PlottableEPRSpectrum spc      = plotView.spc;
                    EPRSpectra.Add(spc);
                }
            }
            return(EPRSpectra);
        }
Ejemplo n.º 3
0
        private void createMDIChild(PlottableEPRSpectrum spc)
        {
            //create inner stackpanel
            StackPanel side = new StackPanel();

            side.Orientation = Orientation.Vertical;

            //create textbox
            TextBlock tb = new TextBlock();

            tb.Padding             = new Thickness(5);
            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            tb.VerticalAlignment   = System.Windows.VerticalAlignment.Stretch;
            tb.MinHeight           = 200;
            tb.Inlines.Add(new Bold(new Run(spc.getTitle())));
            tb.Inlines.Add("\nFrequency: " + spc.freq.ToString() + " GHz");
            tb.Inlines.Add("\nResolution: " + spc.getX().Length);
            tb.Inlines.Add("\nField: " + spc.getX().First() + " - " + spc.getX().Last() + " " + spc.unit);
            tb.Inlines.Add("\nMicrowave Power: " + spc.power + " mW");
            tb.Inlines.Add("\nModulation Amplitude: " + (spc.modAmp / 10) + " mT");
            tb.Inlines.Add("\nReceiver Gain: " + spc.gain.ToString("E"));
            tb.Inlines.Add("\nConversion Time: " + spc.convTime + " msec");
            tb.Inlines.Add("\nTimeConversion: " + spc.timeConv + " msec");
            tb.Inlines.Add("\nNumber of Scans: " + spc.scans);
            tb.Inlines.Add("\n\nOperator: " + spc.operator_);
            tb.Inlines.Add("\nDate: " + spc.date);
            tb.Inlines.Add("\nComment: " + spc.comment);
            tb.Inlines.Add("\n\nDouble Integral: " + spc.doubleIntegral().ToString("E"));
            tb.TextWrapping = TextWrapping.Wrap;
            side.Children.Add(tb);

            //create plotview
            EPRPlotView plotView = new EPRPlotView();

            plotView.Padding             = new Thickness(5);
            plotView.Width               = this.ActualWidth * 0.80;
            plotView.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            spc.plotEPR(plotView);
            if (File.Exists(spc.getFileName() + ".bp2"))
            {
                spc.loadBP2();
            }

            //stack items
            StackPanel sp = new StackPanel();

            sp.Background  = Brushes.White;
            sp.Orientation = Orientation.Horizontal;
            sp.Children.Add(plotView);
            sp.Children.Add(side);

            //add all together
            TabItem eprItem = new TabItem();

            eprItem.Header  = spc.getTitle();
            eprItem.Content = sp;
            mdiTabMenu.Items.Add(eprItem);
            mdiTabMenu.SelectedItem = eprItem;

            this.RefreshData();
        }
Ejemplo n.º 4
0
        private void RefreshData()
        {
            this.clearSidebar();
            StackPanel sidebar = this.getActiveSidebar();

            //g
            Label lblg = new Label();

            lblg.FontWeight = System.Windows.FontWeights.Bold;
            lblg.Content    = "g-Values";
            sidebar.Children.Add(lblg);

            foreach (double g in this.getActivePlotView().spc.g)
            {
                PlottableEPRSpectrum spc  = this.getActiveSpectrum();
                ArrowAnnotation      Line = new ArrowAnnotation()
                {
                    StrokeThickness = 1,
                    Color           = OxyColors.Black,
                    Text            = g.ToString("g6"),
                    StartPoint      = new DataPoint(spc.calcB(g), spc.getY().Max() - spc.getY().Max() * 0.18),
                    EndPoint        = new DataPoint(spc.calcB(g), spc.getY().Max() - spc.getY().Max() * 0.8),
                };

                MaterialDesignThemes.Wpf.Chip chip = new MaterialDesignThemes.Wpf.Chip();
                chip.IsDeletable  = true;
                chip.Content      = g.ToString("g6");
                chip.Tag          = g;
                chip.DeleteClick += (s, e) => GChip_DeleteClick(s, e);
                sidebar.Children.Add(chip);

                this.getActivePlotView().Model.Annotations.Add(Line);
            }

            //couplings
            Label lblA = new Label();

            lblA.FontWeight = System.Windows.FontWeights.Bold;
            lblA.Content    = "Hyperfinecouplings";
            sidebar.Children.Add(lblA);

            foreach (Tuple <DataPoint, DataPoint> tp in this.getActivePlotView().spc.A)
            {
                double          distance = Math.Abs(tp.Item1.X - tp.Item2.X);
                ArrowAnnotation Line     = new ArrowAnnotation()
                {
                    StrokeThickness = 1,
                    Color           = OxyColors.Black,
                    Text            = distance.ToString("g4") + " mT",
                    StartPoint      = tp.Item1,
                    EndPoint        = new DataPoint(tp.Item2.X, tp.Item1.Y)
                };
                this.getActivePlotView().Model.Annotations.Add(Line);

                MaterialDesignThemes.Wpf.Chip chip = new MaterialDesignThemes.Wpf.Chip();
                chip.IsDeletable  = true;
                chip.Content      = distance.ToString("g4") + " mT";
                chip.Tag          = tp;
                chip.DeleteClick += (s, e) => AChip_DeleteClick(s, e);
                sidebar.Children.Add(chip);
            }



            this.getActivePlotView().Model.InvalidatePlot(false);
        }
Ejemplo n.º 5
0
        private void createMDIChild(string filename)
        {
            PlottableEPRSpectrum spc = new PlottableEPRSpectrum(filename);

            this.createMDIChild(spc);
        }