예제 #1
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);
        }
예제 #2
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);
        }