private void BuildNode(object data, Type t1, ref TreeNode parentNode) { string currentElement = string.Empty; try { TreeNode childMain = null; TreeNode childProp = null; object value = null; if (data == null) { return; } PropertyInfo[] props = t1.GetProperties(); foreach (PropertyInfo prop in props) { ElementAttribute[] attribs = prop.GetCustomAttributes(typeof(ElementAttribute), false) as ElementAttribute[]; DicomTag tag; DicomVRType vr = DicomVRType.UN; if (attribs == null || attribs.Length == 0) { continue; } tag = DicomTagTable.Instance.Find(attribs[0].Tag); if (tag != null) { vr = tag.VR; } if ((attribs[0].Requirement == DicomIodUsageType.Type1MandatoryElement || attribs[0].Requirement == DicomIodUsageType.Type2MandatoryElement) && vr != DicomVRType.SQ) { continue; } if (!prop.Name.StartsWith("ExtensionData")) { // For exceptions currentElement = GetName(t1) + "." + prop.Name; // Property value value = prop.GetValue(data, null); if (prop.Name.EndsWith("PrimaryID")) { parentNode.Text += string.Format(" - [{0}]", value); } if (IsGenericType(typeof(List <>), prop.PropertyType)) { IList list = (IList)prop.GetValue(data, null); if (list != null) { foreach (object child in list) { childMain = new TreeNode(string.Format("{0}", prop.Name)); CheckNode(childMain, attribs[0]); childMain.Tag = attribs[0]; if (attribs[0].Requirement == DicomIodUsageType.Type1MandatoryElement || attribs[0].Requirement == DicomIodUsageType.Type2MandatoryElement) { childMain.ForeColor = Color.Red; } BuildNode(child, child.GetType(), ref childMain); parentNode.Nodes.Add(childMain); } } } else if (prop.PropertyType.IsClass && prop.PropertyType != typeof(String) && prop.PropertyType != typeof(PersonName)) { object child_object; childMain = new TreeNode(prop.Name); childMain.Tag = attribs[0]; CheckNode(childMain, attribs[0]); child_object = Convert.ChangeType(value, prop.PropertyType); BuildNode(child_object, prop.PropertyType, ref childMain); parentNode.Nodes.Add(childMain); } else { childProp = new TreeNode(prop.Name); childProp.Tag = attribs[0]; CheckNode(childProp, attribs[0]); if (attribs[0].Requirement == DicomIodUsageType.Type1MandatoryElement || attribs[0].Requirement == DicomIodUsageType.Type2MandatoryElement) { childProp.ForeColor = Color.Red; } parentNode.Nodes.Add(childProp); } } } } catch (Exception ex) { throw new Exception(currentElement, ex); } }
private void DicomModifyElementDlg_Load(object sender, EventArgs e) { //m_strValue = m_pMyTreeData->m_strValue; if (m_pDicomIOD != null) { strCode = GetStringTag(m_pDicomIOD.TagCode); strName = m_pDicomIOD.Name; strUsage = GetUsage(m_pDicomIOD.Usage); strHint = m_pDicomIOD.Description; DicomTag pDicomTag = DicomTagTable.Instance.Find(m_pDicomIOD.TagCode); if (pDicomTag != null) { if (pDicomTag.MinVM == pDicomTag.MaxVM) { m_bMultipleItems = pDicomTag.MinVM > 1; strVRMultiplicity = string.Format("Exactly {0:D} value", pDicomTag.MinVM); if (pDicomTag.MinVM > 1) { strVRMultiplicity += "s"; } } else if (pDicomTag.MaxVM == -1) { m_bMultipleItems = true; strVRMultiplicity = string.Format("At least {0:D} value", pDicomTag.MinVM); if (pDicomTag.MinVM > 1) { strVRMultiplicity += "s"; } } else { m_bMultipleItems = true; strVRMultiplicity = string.Format("{0:D} to {0:D} values", pDicomTag.MinVM); } strVRMultiplicity += "."; if (pDicomTag.VMDivider != 1) { String strTemp; strTemp = string.Format("Count must be divisible by {0:D}.", pDicomTag.VMDivider); strVRMultiplicity += strTemp; } } } m_nVR = m_pElement.VR; string tempStrVR = strVR; GetVRInfo(m_nVR, ref tempStrVR, ref m_strVRInfo); strVR = tempStrVR; PopulateListBox(); if (m_bMultipleItems) { strStaticInstructions = "Select an existing item, and click 'Modify' to change a value, or an 'Insert' button to insert a new value. Double-click an item to modify it."; } else { strStaticInstructions = "Click 'Insert' to add a value, 'Delete' to delete the value, or 'Modify' to change a value. Double-click an item to modify it."; } _txtBox_ValueMulti.Visible = false; _txtBox_ValueSingle.Visible = false; EnableItems(true); ShowItems(); _lstBox_Value.Focus(); if (_lstBox_Value.Items.Count > 0) { _lstBox_Value.SelectedIndex = 0; } }
public static object GetElementValue(this DicomDataSet ds, long tag, bool list) { DicomVRType vr = DicomVRType.UN; if (Tags.ContainsKey(tag)) { vr = Tags[tag].VR; } else { DicomTag dt = DicomTagTable.Instance.Find(tag); if (dt != null) { vr = dt.VR; Tags.Add(tag, dt); } } switch (vr) { case DicomVRType.AE: case DicomVRType.CS: case DicomVRType.LO: case DicomVRType.LT: case DicomVRType.SH: case DicomVRType.ST: case DicomVRType.UI: case DicomVRType.UT: case DicomVRType.PN: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <string> >(tag, null)); } return(ds.GetValue <string>(tag, string.Empty)); case DicomVRType.FL: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <float> >(tag, null)); } return(ds.GetValue <float?>(tag, null)); case DicomVRType.OW: case DicomVRType.SS: case DicomVRType.US: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <short> >(tag, null)); } return(ds.GetValue <short?>(tag, null)); case DicomVRType.DS: case DicomVRType.FD: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <double> >(tag, null)); } return(ds.GetValue <double?>(tag, null)); case DicomVRType.AT: case DicomVRType.IS: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <int> >(tag, null)); } return(ds.GetValue <int?>(tag, null)); case DicomVRType.SL: case DicomVRType.UL: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <long> >(tag, null)); } return(ds.GetValue <long?>(tag, null)); case DicomVRType.DA: if (list && ds.GetCount(tag) > 0) { return(ds.GetValue <List <DateTime> >(tag, null)); } return(ds.GetValue <DateTime?>(tag, null)); } return(null); }
DicomVRType GetVRInfo(DicomVRType nVR, ref String strVR, ref String strVRDetail) { bool bMulti = false; DicomVR pVR = DicomVRTable.Instance.Find(nVR); if (pVR != null) { strVR = pVR.Name; if (((pVR.Restriction & DicomVRRestriction.BinaryFixed) == DicomVRRestriction.BinaryFixed) || ((pVR.Restriction & DicomVRRestriction.StringFixed) == DicomVRRestriction.StringFixed)) { bMulti = true; } } else { nVR = DicomVRType.UN; strVR = "Unknown"; bMulti = true; } switch (nVR) { case DicomVRType.OB: case DicomVRType.UN: strVRDetail = "Hexadecimal"; break; case DicomVRType.SS: case DicomVRType.US: case DicomVRType.OW: case DicomVRType.SL: case DicomVRType.IS: case DicomVRType.UL: strVRDetail = "Integer"; break; case DicomVRType.AT: strVRDetail = "Group:Element\r\n(Group and Element should be hexadecimal words)"; break; case DicomVRType.FD: case DicomVRType.FL: case DicomVRType.DS: strVRDetail = "Float"; break; case DicomVRType.CS: case DicomVRType.SH: case DicomVRType.LO: case DicomVRType.AE: case DicomVRType.LT: case DicomVRType.ST: case DicomVRType.UI: case DicomVRType.UT: case DicomVRType.PN: if (bMulti != false) { strVRDetail = "String"; } else { strVRDetail = "Text"; } break; case DicomVRType.AS: strVRDetail = "Number Reference\r\n(Reference = 'days' or 'weeks' or 'months' or 'years')"; break; case DicomVRType.DA: { strVRDetail = "MM/DD/YYYY\r\n(MM=Month, DD=Day, YYYY=Year)"; /* * EnableDateCtrl(TRUE); * m_Date.SetFormat("MM/dd/yyy"); * m_Date.SetDate(m_strValue); */ } break; case DicomVRType.DT: strVRDetail = "MM/DD/YYYY HH:MM:SS.FFFFFF+OOOO\r\n(MM=Month, DD=Day, YYYY=Year)\r\n(HH=Hours, MM=Minutes, SS=Seconds, FFFFFF=Fractional Second, OOOO=Offset from Coordinated Universal Time)"; break; case DicomVRType.TM: strVRDetail = "HH:MM:SS.FFFF\r\n(HH=Hours, MM=Minutes, SS=Seconds, FFFFFF=Fractional Second)"; break; default: strVRDetail = ""; break; } return(nVR); }