Exemple #1
0
        private void VCDownButton_Click(object sender, EventArgs e)
        {
            Instrument     inst = (Instrument)SitesTreeView.SelectedNode.Tag;
            VirtualChannel chan = selectedVirtualChannel;

            int index = inst.GetVirtualChannels().IndexOf(chan);

            if (index < inst.GetVirtualChannels().Count() - 1)
            {
                VirtualChannel nextChan = inst.GetVirtualChannels()[index + 1];
                // Check references to early channels don't get messed up
                foreach (Channel dependent in nextChan.Dependencies)
                {
                    if (dependent == chan)
                    {
                        MessageBox.Show("Cannot move channel down: it is referenced by the virtual channel below it!");
                        return;
                    }
                }

                // Ok, move the channel up
                chan.SetIndex(index + 1);

                siteMan.Save();
                UpdateSitesTree();
                siteManChanged                = true;
                SitesTreeView.SelectedNode    = SitesTreeView.Nodes.Find(inst.Name, true)[0];
                ChannelsComboBox.SelectedItem = chan.Name;
            }
        }
Exemple #2
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();
        }
Exemple #3
0
        public SiteManagerForm(MainForm master, SiteManager newSiteMan)
        {
            main    = master;
            siteMan = newSiteMan;

            selectedSystem         = null;
            selectedChannel        = null;
            selectedVirtualChannel = null;

            this.StartPosition = FormStartPosition.CenterParent;
            InitializeComponent();
        }
Exemple #4
0
        private void RemoveVirtualChannelButton_Click(object sender, EventArgs e)
        {
            Instrument     inst = (Instrument)SitesTreeView.SelectedNode.Tag;
            VirtualChannel chan = selectedVirtualChannel;

            inst.GetVirtualChannels().Remove(chan);
            siteMan.Save();
            UpdateSitesTree();
            siteManChanged             = true;
            SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(inst.Name, true)[0];
            ResetFields();
        }
Exemple #5
0
        private void VirtualChannelsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            Instrument inst = (Instrument)SitesTreeView.SelectedNode.Tag;

            foreach (Channel otherChan in inst.GetChannels())
            {
                if (otherChan.Name == ChannelsComboBox.Text)
                {
                    if (otherChan is VirtualChannel)
                    {
                        selectedChannel        = null;
                        selectedVirtualChannel = (VirtualChannel)otherChan;
                        SetupVirtualChannelGroupBox();
                    }
                    else
                    {
                        selectedChannel        = otherChan;
                        selectedVirtualChannel = null;
                        SetupChannelGroupBox();
                    }
                }
            }
        }
Exemple #6
0
        private void SetupVirtualChannelGroupBox()
        {
            Instrument     inst = (Instrument)SitesTreeView.SelectedNode.Tag;
            VirtualChannel chan = selectedVirtualChannel;

            Channel[] instChannels = inst.GetChannels();
            int       chanIndex    = -1;

            for (int i = 0; i < instChannels.Length; i++)
            {
                if (instChannels[i] == chan)
                {
                    chanIndex = i;
                    break;
                }
            }
            VirtualChannelNameTextBox.Text = chan.Name;
            VirtualChannelTypeTextBox.Text = chan.VCType;
            if (chan.VCType == "ROI")
            {
                PopulateROIVCPanel(chan, inst);
                VCParameterListPanel.Visible = false;
                VCParameterListPanel.BringToFront();
                ROIVCPanel.Visible = true;
            }
            else
            {
                List <Parameter> parameters = chan.GetParameters();
                VCParameterListPanel.LoadParameters(parameters);
                ROIVCPanel.Visible = false;
                ROIVCPanel.BringToFront();
                VCParameterListPanel.Visible = true;
            }
            VirtualChannelGroupBox.Visible = true;
            ChannelGroupBox.Visible        = false;
        }
Exemple #7
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;
        }
Exemple #8
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (siteMan.GetSites().Count == 0)
            {
                MessageBox.Show("May as well make some changes before you save, am I right?");
                return;
            }
            TreeNode node     = SitesTreeView.SelectedNode;
            string   nodeName = node.Name;

            Channel chan = null;


            if (node.Tag is Site)
            {
                Site site = (Site)node.Tag;
                if (site.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text))
                {
                    MessageBox.Show("All items in the Site Manager require a unique name!");
                    return;
                }
                site.Name = NameTextBox.Text;
                nodeName  = site.Name;
            }
            else if (node.Tag is Facility)
            {
                Facility fac = (Facility)node.Tag;
                if (fac.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text))
                {
                    MessageBox.Show("All items in the Site Manager require a unique name!");
                    return;
                }
                fac.Name = NameTextBox.Text;
                nodeName = fac.Name;
            }
            else if (node.Tag is DetectionSystem)
            {
                DetectionSystem sys = (DetectionSystem)node.Tag;
                if (sys.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text))
                {
                    MessageBox.Show("All items in the Site Manager require a unique name!");
                    return;
                }
                sys.Name = NameTextBox.Text;
                nodeName = sys.Name;
                if (DeclarationCheckBox.Checked)
                {
                    selectedSystem.GetDeclarationInstrument().SetFilePrefix(DeclarationPrefixTextBox.Text);
                    selectedSystem.GetDeclarationInstrument().SetDataFolder(DeclarationDirectoryTextBox.Text);
                    selectedSystem.GetDeclarationInstrument().ScanDataFolder();
                }
            }
            else if (node.Tag is Instrument)
            {
                Instrument inst = (Instrument)node.Tag;
                if (inst.Name != NameTextBox.Text && siteMan.ContainsName(NameTextBox.Text))
                {
                    MessageBox.Show("All items in the Site Manager require a unique name!");
                    return;
                }
                if (!InstrumentParameterListPanel.ValidateInput())
                {
                    return;
                }
                string name = NameTextBox.Text;
                string type = inst.InstrumentType;

                if (name != inst.Name)
                {
                    inst.Name = name;
                }
                inst.ApplyParameters(InstrumentParameterListPanel.Parameters);
                // selectedChannel and selectedVirtualChannel might not exist anymore

                if (selectedVirtualChannel != null)
                {
                    foreach (VirtualChannel vc in inst.GetVirtualChannels())
                    {
                        if (vc.Name == selectedVirtualChannel.Name)
                        {
                            selectedVirtualChannel = vc;
                            break;
                        }
                    }
                    chan = SaveVirtualChannel(inst, selectedVirtualChannel);
                }
                else if (selectedChannel != null)
                {
                    foreach (Channel c in inst.GetStandardChannels())
                    {
                        if (c.Name == selectedChannel.Name)
                        {
                            selectedChannel = c;
                            break;
                        }
                    }
                    chan = SaveChannel(inst, selectedChannel);
                }
                nodeName = inst.Name;
            }
            else if (node.Tag is EventGenerator)
            {
                MessageBox.Show("Use the Event Manager to edit events.");
                return;
            }
            if (siteMan.Save() != ReturnCode.SUCCESS)
            {
                MessageBox.Show("Bad trouble saving the site manager!");
            }
            UpdateSitesTree();
            siteManChanged             = true;
            SitesTreeView.SelectedNode = SitesTreeView.Nodes.Find(nodeName, true)[0];
            if (selectedVirtualChannel != null)
            {
                ChannelsComboBox.SelectedItem = selectedVirtualChannel.Name;
            }
            else if (selectedChannel != null)
            {
                ChannelsComboBox.SelectedItem = selectedChannel.Name;
            }
        }
Exemple #9
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);
        }
Exemple #10
0
        private void ResetFields()
        {
            selectedSystem         = null;
            selectedChannel        = null;
            selectedVirtualChannel = null;
            TreeNode node = SitesTreeView.SelectedNode;

            NameTextBox.Text = node.Text;

            if (node.Tag is Site)
            {
                Site site = (Site)node.Tag;
                TypeLabel.Text = "Site";

                SystemPanel.Visible         = false;
                InstrumentPanel.Visible     = false;
                NewInstrumentButton.Enabled = false;
                NewSystemButton.Enabled     = false;
                NewFacilityButton.Enabled   = true;
            }
            else if (node.Tag is Facility)
            {
                Facility fac = (Facility)node.Tag;
                TypeLabel.Text = "Facility";

                SystemPanel.Visible         = false;
                InstrumentPanel.Visible     = false;
                NewInstrumentButton.Enabled = false;
                NewSystemButton.Enabled     = true;
                NewFacilityButton.Enabled   = true;
            }
            else if (node.Tag is DetectionSystem)
            {
                DetectionSystem sys = (DetectionSystem)node.Tag;
                selectedSystem = sys;
                TypeLabel.Text = "System";

                SetupSystemPanel();

                SystemPanel.Visible         = true;
                InstrumentPanel.Visible     = false;
                NewInstrumentButton.Enabled = true;
                NewSystemButton.Enabled     = true;
                NewFacilityButton.Enabled   = true;
            }
            else if (node.Tag is Instrument)
            {
                Instrument inst = (Instrument)node.Tag;
                TypeLabel.Text = "Instrument";
                InstrumentParameterListPanel.LoadParameters(inst.GetParameters());
                InstTypeTextBox.Text = inst.InstrumentType;

                ChannelsComboBox.Items.Clear();
                Channel[] channels = inst.GetChannels();
                if (channels.Length > 0)
                {
                    foreach (Channel channel in channels)
                    {
                        ChannelsComboBox.Items.Add(channel.Name);
                    }
                    if (channels[0] is VirtualChannel)
                    {
                        selectedChannel               = null;
                        selectedVirtualChannel        = (VirtualChannel)channels[0];
                        ChannelsComboBox.SelectedItem = selectedVirtualChannel.Name;
                        SetupVirtualChannelGroupBox();
                    }
                    else
                    {
                        selectedChannel               = channels[0];
                        selectedVirtualChannel        = null;
                        ChannelsComboBox.SelectedItem = selectedChannel.Name;
                        SetupChannelGroupBox();
                    }
                }
                else
                {
                    VirtualChannelGroupBox.Visible = false;
                }

                SystemPanel.Visible         = false;
                InstrumentPanel.Visible     = true;
                NewInstrumentButton.Enabled = true;
                NewSystemButton.Enabled     = true;
                NewFacilityButton.Enabled   = true;
            }
            else if (node.Tag is EventGenerator)
            {
                EventGenerator eg = (EventGenerator)node.Tag;
                TypeLabel.Text = "Event Generator";

                SystemPanel.Visible         = false;
                InstrumentPanel.Visible     = false;
                NewInstrumentButton.Enabled = false;
                NewSystemButton.Enabled     = false;
            }
        }
Exemple #11
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);
        }