Exemplo n.º 1
0
        private void PopulateROIVCPanel(VirtualChannel chan, Instrument inst)
        {
            ROIChannel roiChan = (ROIChannel)chan;
            ROI        roi     = roiChan.GetROI();

            ROIStartTextBox.Text = roi.GetROIStart().ToString();
            ROIEndTextBox.Text   = roi.GetROIEnd().ToString();

            switch (roiChan.GetROI().GetBGType())
            {
            case ROI.BG_Type.NONE:
                ROIBackgroundComboBox.Text = "None";
                break;

            case ROI.BG_Type.FLAT:
                ROIBackgroundComboBox.Text = "Flat";
                break;

            case ROI.BG_Type.LINEAR:
                ROIBackgroundComboBox.Text = "Linear";
                break;
            }

            BG1StartTextBox.Text = roi.GetBG1Start().ToString();
            BG1EndTextBox.Text   = roi.GetBG1End().ToString();
            BG2StartTextBox.Text = roi.GetBG2Start().ToString();
            BG2EndTextBox.Text   = roi.GetBG2End().ToString();
        }
Exemplo n.º 2
0
        private void AddVirtualChannelButton_Click(object sender, EventArgs e)
        {
            Instrument inst = (Instrument)SitesTreeView.SelectedNode.Tag;

            if (inst.GetChannels().Length == 0)
            {
                MessageBox.Show("The instrument has no channels to make a virtual instrument from!");
            }
            bool isMCA = false;

            if (inst is MCAInstrument)
            {
                isMCA = true;
            }

            VirtualChannelTypeDialog dialog = new VirtualChannelTypeDialog(isMCA);
            DialogResult             result = dialog.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return;
            }

            int    iteration  = 0;
            bool   uniqueName = false;
            string name       = "";

            while (!uniqueName)
            {
                iteration++;
                name       = "New-VC-" + iteration.ToString();
                uniqueName = !siteMan.ContainsName(name);
            }

            if (dialog.vcType == "ROI")
            {
                VirtualChannel roiChannel = new ROIChannel(name, (MCAInstrument)inst, Channel.ChannelType.DURATION_VALUE, 0);
                siteMan.Save();
                UpdateSitesTree();
                siteManChanged                = true;
                SitesTreeView.SelectedNode    = SitesTreeView.Nodes.Find(inst.Name, true)[0];
                ChannelsComboBox.SelectedItem = name;
                selectedVirtualChannel        = roiChannel;
                return;
            }

            VirtualChannelHookup hookup = VirtualChannel.GetHookup(dialog.vcType);

            List <string> validInstrumentChannels = new List <string>();

            foreach (Channel chan in inst.GetChannels())
            {
                validInstrumentChannels.Add(chan.Name);
            }

            List <Parameter> parameters = new List <Parameter>();

            foreach (ParameterTemplate paramTemp in hookup.TemplateParameters)
            {
                switch (paramTemp.Type)
                {
                case ParameterType.Int:
                    parameters.Add(new IntParameter(paramTemp.Name)
                    {
                        Value = "0"
                    });
                    break;

                case ParameterType.Double:
                    parameters.Add(new DoubleParameter(paramTemp.Name)
                    {
                        Value = "0"
                    });
                    break;

                case ParameterType.Enum:
                    parameters.Add(new EnumParameter(paramTemp.Name)
                    {
                        Value = paramTemp.ValidValues[0], ValidValues = paramTemp.ValidValues
                    });
                    break;

                case ParameterType.TimeSpan:
                    parameters.Add(new TimeSpanParameter(paramTemp.Name)
                    {
                        Value = "0"
                    });
                    break;

                case ParameterType.FileName:
                    parameters.Add(new FileNameParameter(paramTemp.Name)
                    {
                        Value = ""
                    });
                    break;

                case ParameterType.InstrumentChannel:
                    parameters.Add(new InstrumentChannelParameter(paramTemp.Name, inst)
                    {
                        Value = validInstrumentChannels[0]
                    });
                    break;
                }
            }
            VirtualChannel virtualChannel = hookup.FromParameters(inst, name, parameters, 0);

            siteMan.Save();
            UpdateSitesTree();
            siteManChanged                = true;
            SitesTreeView.SelectedNode    = SitesTreeView.Nodes.Find(inst.Name, true)[0];
            ChannelsComboBox.SelectedItem = name;
            selectedVirtualChannel        = virtualChannel;
        }
Exemplo n.º 3
0
        private VirtualChannel SaveVirtualChannel(Instrument inst, VirtualChannel chan)
        {
            if (chan.Name != VirtualChannelNameTextBox.Text && siteMan.ContainsName(VirtualChannelNameTextBox.Text))
            {
                MessageBox.Show("All items in the Site Manager require a unique name!");
                return(null);
            }

            string name = VirtualChannelNameTextBox.Text;
            string type = VirtualChannelTypeTextBox.Text;

            if (type == "ROI")
            {
                ROIChannel roiChan = (ROIChannel)chan;
                ROI        roi     = roiChan.GetROI();
                try
                {
                    roi.SetROIStart(double.Parse(ROIStartTextBox.Text));
                    roi.SetROIEnd(double.Parse(ROIEndTextBox.Text));
                    roi.SetBG1Start(double.Parse(BG1StartTextBox.Text));
                    roi.SetBG1End(double.Parse(BG1EndTextBox.Text));
                    roi.SetBG2Start(double.Parse(BG2StartTextBox.Text));
                    roi.SetBG2End(double.Parse(BG2EndTextBox.Text));
                }
                catch
                {
                    MessageBox.Show("Invalid ROI or BG bounds!");
                    return(null);
                }
                switch (ROIBackgroundComboBox.Text)
                {
                case "None":
                    roi.SetBGType(ROI.BG_Type.NONE);
                    break;

                case "Flat":
                    roi.SetBGType(ROI.BG_Type.FLAT);
                    break;

                case "Linear":
                    roi.SetBGType(ROI.BG_Type.LINEAR);
                    break;

                default:
                    MessageBox.Show("Invalid background type!");
                    return(null);
                }
                roiChan.SetROI(roi);
            }
            else
            {
                if (!VCParameterListPanel.ValidateInput())
                {
                    return(null);
                }
                VirtualChannelHookup  hookup          = VirtualChannel.GetHookup(type);
                List <VirtualChannel> virtualChannels = inst.GetVirtualChannels();
                int index = -1;
                for (int i = 0; i < virtualChannels.Count; i++)
                {
                    if (virtualChannels[i] == chan)
                    {
                        index = i;
                        break;
                    }
                }

                chan.Delete();
                chan = hookup.FromParameters(inst, name, VCParameterListPanel.Parameters, chan.ID);
                chan.SetIndex(index);
            }
            return(chan);
        }
Exemplo n.º 4
0
        public ReturnCode LoadFromXML(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(ReturnCode.FILE_DOESNT_EXIST);
            }
            XmlDocument doc = new XmlDocument();

            doc.Load(fileName);
            Persister.TakenIDs.Clear();
            sites.Clear();

            if (doc.DocumentElement.Attributes["Omniscient_Version"] == null)
            {
                MessageBox.Show("Warning: SiteManager.xml was made by an older version of Omniscient.");
            }

            foreach (XmlNode siteNode in doc.DocumentElement.ChildNodes)
            {
                if (siteNode.Name != "Site")
                {
                    return(ReturnCode.CORRUPTED_FILE);
                }
                Site newSite = Site.FromXML(siteNode, this);
                foreach (XmlNode facilityNode in siteNode.ChildNodes)
                {
                    if (facilityNode.Name != "Facility")
                    {
                        return(ReturnCode.CORRUPTED_FILE);
                    }
                    Facility newFacility = Facility.FromXML(facilityNode, newSite);
                    foreach (XmlNode systemNode in facilityNode.ChildNodes)
                    {
                        if (systemNode.Name != "System")
                        {
                            return(ReturnCode.CORRUPTED_FILE);
                        }
                        DetectionSystem newSystem = DetectionSystem.FromXML(systemNode, newFacility);
                        foreach (XmlNode instrumentNode in systemNode.ChildNodes)
                        {
                            if (instrumentNode.Name == "Instrument")
                            {
                                Instrument newInstrument = Instrument.FromXML(instrumentNode, newSystem);
                                if (!newInstrument.Equals(null))
                                {
                                    int       channelCount = 0;
                                    Channel[] channels     = newInstrument.GetStandardChannels();
                                    foreach (XmlNode chanNode in instrumentNode.ChildNodes)
                                    {
                                        if (chanNode.Name == "Channel")
                                        {
                                            if (channelCount >= channels.Length)
                                            {
                                                return(ReturnCode.CORRUPTED_FILE);
                                            }
                                            channels[channelCount].ApplyXML(chanNode);
                                            channelCount++;
                                        }
                                        else if (chanNode.Name == "VirtualChannel")
                                        {
                                            try
                                            {
                                                if (chanNode.Attributes["type"]?.InnerText != "ROI")
                                                {
                                                    VirtualChannel chan = VirtualChannel.FromXML(chanNode, newInstrument);
                                                }
                                                else
                                                {
                                                    ROIChannel chan = new ROIChannel(chanNode.Attributes["name"]?.InnerText,
                                                                                     (MCAInstrument)newInstrument, Channel.ChannelType.DURATION_VALUE,
                                                                                     uint.Parse(siteNode.Attributes["ID"]?.InnerText, System.Globalization.NumberStyles.HexNumber));
                                                    ROI roi = chan.GetROI();
                                                    roi.SetROIStart(double.Parse(chanNode.Attributes["roi_start"]?.InnerText));
                                                    roi.SetROIEnd(double.Parse(chanNode.Attributes["roi_end"]?.InnerText));
                                                    roi.SetBG1Start(double.Parse(chanNode.Attributes["bg1_start"]?.InnerText));
                                                    roi.SetBG1End(double.Parse(chanNode.Attributes["bg1_end"]?.InnerText));
                                                    roi.SetBG2Start(double.Parse(chanNode.Attributes["bg2_start"]?.InnerText));
                                                    roi.SetBG2End(double.Parse(chanNode.Attributes["bg2_end"]?.InnerText));
                                                    switch (chanNode.Attributes["bg_type"]?.InnerText)
                                                    {
                                                    case "None":
                                                        roi.SetBGType(ROI.BG_Type.NONE);
                                                        break;

                                                    case "Flat":
                                                        roi.SetBGType(ROI.BG_Type.FLAT);
                                                        break;

                                                    case "Linear":
                                                        roi.SetBGType(ROI.BG_Type.LINEAR);
                                                        break;

                                                    default:
                                                        return(ReturnCode.CORRUPTED_FILE);
                                                    }
                                                }
                                            }
                                            catch { return(ReturnCode.CORRUPTED_FILE); }
                                        }
                                        else
                                        {
                                            return(ReturnCode.CORRUPTED_FILE);
                                        }
                                    }
                                }
                            }
                            else if (instrumentNode.Name == "EventGenerator")
                            {
                                XmlNode        eventNode = instrumentNode; // Correct some shoddy nomenclature...
                                EventGenerator eg        = EventGenerator.FromXML(eventNode, newSystem);
                                if (eg == null)
                                {
                                    return(ReturnCode.CORRUPTED_FILE);
                                }
                                foreach (XmlNode actionNode in eventNode.ChildNodes)
                                {
                                    if (actionNode.Name != "Action")
                                    {
                                        return(ReturnCode.CORRUPTED_FILE);
                                    }
                                    Action action = Action.FromXML(actionNode, eg);
                                }
                            }
                            else
                            {
                                return(ReturnCode.CORRUPTED_FILE);
                            }
                        }
                    }
                }
            }
            return(ReturnCode.SUCCESS);
        }