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