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(); }
public override void ToXML(XmlWriter xmlWriter) { StartToXML(xmlWriter); xmlWriter.WriteAttributeString("Type", VCType); if (this is ROIChannel) { xmlWriter.WriteAttributeString("roi_start", ((ROIChannel)this).GetROI().GetROIStart().ToString()); xmlWriter.WriteAttributeString("roi_end", ((ROIChannel)this).GetROI().GetROIEnd().ToString()); xmlWriter.WriteAttributeString("bg1_start", ((ROIChannel)this).GetROI().GetBG1Start().ToString()); xmlWriter.WriteAttributeString("bg1_end", ((ROIChannel)this).GetROI().GetBG1End().ToString()); xmlWriter.WriteAttributeString("bg2_start", ((ROIChannel)this).GetROI().GetBG2Start().ToString()); xmlWriter.WriteAttributeString("bg2_end", ((ROIChannel)this).GetROI().GetBG2End().ToString()); xmlWriter.WriteAttributeString("bg_type", (ROI.BGTypeToString(((ROIChannel)this).GetROI().GetBGType()))); } else { List <Parameter> parameters = GetParameters(); foreach (Parameter param in parameters) { xmlWriter.WriteAttributeString(param.Name.Replace(' ', '_'), param.Value); } } xmlWriter.WriteEndElement(); }
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); }
public void SetROI(ROI newROI) { roi = newROI; }
public ROIChannel(string newName, MCAInstrument parent, ChannelType newType, uint id) : base(newName, parent, newType, id) { VCType = "ROI"; roi = new ROI(); }
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); }