示例#1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="dvtkDataAttribute">The encapsulated DvtkData attribute.</param>
        /// <param name="parentAttributeSet">The AttributeSet this instance is part of.</param>
        public ValidAttribute(TagSequence tagSequence, DvtkData.Dimse.Attribute dvtkDataAttribute, AttributeSet parentAttributeSet)
        {
            // Sanity check.
            if (dvtkDataAttribute == null)
            {
                throw new ArgumentException("Internal error: dvtkDataAttribute may not be null.");
            }

            // Sanity check.
            if (parentAttributeSet == null)
            {
                throw new ArgumentException("Internal error: parentAttributeSet may not be null.");
            }

            TagSequence = tagSequence;
            this.dvtkDataAttribute = dvtkDataAttribute;
            this.parentAttributeSet = parentAttributeSet;
        }
        public AttributeList GetNextAttributes(out TagSequence lowestTagSequence)
        {
            AttributeList nextAttributes = null;

            lowestTagSequence = DetermineLowestTagSequence();

            //
            // If unprocessed attributes still exist, create and fill the AttributeList to return.
            //

            if (lowestTagSequence != null)
                // Still attributes to process.
            {
                nextAttributes = DetermineNextAttributes(lowestTagSequence);
            }
            else
                // No more attributes left to process.
            {
                nextAttributes = null;
            }

            return(nextAttributes);
        }
示例#3
0
 /// <summary>
 /// Constructor.
 ///
 /// Use this to encapsulate an existing DvtkData sequence item.
 /// </summary>
 /// <param name="tagSequence">The tag sequence of this sequence item.</param>
 /// <param name="dvtkDataSequenceItem">The encapsulated DvtkData SequenceItem.</param>
 internal SequenceItem(TagSequence tagSequence, DvtkData.Dimse.SequenceItem dvtkDataSequenceItem) : base(tagSequence, dvtkDataSequenceItem)
 {
 }
示例#4
0
 /// <summary>
 /// Deletes this instance from the AttributeSet it is contained in.
 /// </summary>
 /// <remarks>
 /// <b>Don't use this instance anymore after calling this method!</b>
 /// </remarks>
 public override void Delete()
 {
     if (this.parentAttributeSet != null)
     {
         this.parentAttributeSet.DvtkDataAttributeSet.Remove(this.dvtkDataAttribute);
         TagSequence = new TagSequence();
         this.parentAttributeSet = null;
     }
 }
示例#5
0
        //
        // - Methods -
        //
        /// <summary>
        /// Indicates if the specified attribute exists.
        /// </summary>
        /// <param name="tagSequenceString">The tag sequence (see class TagSequence for the format).</param>
        /// <returns>Boolean indicating if the specified attribute exists.</returns>
        public bool Exists(String tagSequenceString)
        {
            bool exists = false;

            TagSequence tagSequence = new TagSequence(tagSequenceString);

            if (!tagSequence.IsSingleAttributeMatching)
            {
                throw new HliException(tagSequenceString.ToString() + " not valid for the Exists method.");
            }

            if (tagSequence.IsValidForCommandSet)
            {
                exists = this.CommandSet.Exists(tagSequence);
            }
            else if (tagSequence.IsValidForDataSet)
            {
                exists = this.DataSet.Exists(tagSequence);
            }
            else
            {
                throw new HliException(tagSequenceString.ToString() + " not valid for a DicomMessage attribute.");
            }

            return(exists);
        }
示例#6
0
        /// <summary>
        /// Adds a single attribute with the tag, VR and values specified.
        /// </summary>
        /// <remarks>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// </remarks>
        /// <param name="dvtkDataTag">The tag of the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="values">The values, which will be copied from another attribute, for this attribute.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="values"/> is a null reference.
        /// </exception>
        public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Values values)
        {
            TagSequence internalTagSequence = new TagSequence();

            internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber));

            //
            // Sanity checks.
            //

            // Check if the tag supplied is valid for a CommandSet.
            if (!internalTagSequence.IsValidForCommandSet)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a CommandSet attribute.", "dvtkDataTag");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            //
            // Perform the actual operation in the base class.
            //

            Set(internalTagSequence, vR, values);
        }
示例#7
0
        /// <summary>
        /// Adds a single attribute with the tag sequence, VR and values specified.
        /// </summary>
        /// <remarks>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// <br></br><br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="values">The values, which will be copied from another attribute, for this attribute.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting an attribute.<br></br>
        /// -or-<br></br>
        /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="values"/> is a null reference.
        /// </exception>
        public override void Set(String tagSequence, VR vR, Values values)
        {
            TagSequence internalTagSequence = new TagSequence(tagSequence);

            //
            // Sanity checks.
            //

            if (!internalTagSequence.IsSingleAttributeMatching)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting an attribute.");
            }

            // Check if the tag supplied is valid for a CommandSet.
            if (!internalTagSequence.IsValidForCommandSet)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting a CommandSet attribute.", "dvtkDataTag");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            //
            // Perform the actual operation in the base class.
            //

            Set(internalTagSequence, vR, values);
        }
示例#8
0
        //
        // - Methods -
        //
        private void SetTagCellForDicomAttribute(DicomAttribute dicomAttribute, int columnIndex)
        {
            if (dicomAttribute != null)
            {
                TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                if (dicomAttribute.DisplayFullTagSequence)
                {
                    ArrayList tags = tagSequence.Tags;

                    for (int tagIndex = 0; tagIndex < tags.Count; tagIndex++)
                    {
                        Tag tag = tags[tagIndex] as Tag;
                        if (tag.ContainsIndex)
                        {
                            SetCellOK(columnIndex, "".PadRight(tagIndex, '>') + tag.DicomNotation + "(" + tag.IndexNumber + ")");
                        }
                        else
                        {
                            SetCellOK(columnIndex, "".PadRight(tagIndex, '>') + tag.DicomNotation);
                        }
                    }
                }
                else
                {
                    SetCellOK(columnIndex, tagSequence.DicomNotation);
                }
            }

            if (this.displayFlags)
            {
                SetCellOK(columnIndex, "<br><i>Flags:</i>");
                SetCellOK(columnIndex, "<i>" + dicomAttribute.ValidationRule.FlagsString + "</i>");
            }
        }
示例#9
0
        private void SetPresentCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributePresent[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase != null)
            {
                String presentString = "";
                bool containsError = false;

                if (attributebase.IsPresent)
                {
                    presentString = "+";
                }
                else
                {
                    presentString = "-";
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_present) == FlagsBase.Compare_present)
                {
                    if (attributeList.ContainsComparePresentErrors)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Present) == FlagsBase.Present)
                {
                    if (!attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                if ((attributebase.ValidationRule.Flags & FlagsBase.Not_present) == FlagsBase.Not_present)
                {
                    if (attributebase.IsPresent)
                    {
                        containsError = true;
                    }
                }

                // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                // field is true.
                if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                {
                    DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                    TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                    if (tagSequence.LastTag.ElementNumber == 0)
                    {
                        containsError = false;
                    }
                }

                if (containsError)
                {
                    SetCellError(columnIndex, presentString);
                }
                else
                {
                    SetCellOK(columnIndex, presentString);
                }
            }
        }
示例#10
0
        //
        // - Methods -
        //

        /// <summary>
        /// Adds a sequence item to the end of the item list.
        /// </summary>
        /// <remarks>
        /// This method is only meaningfull if this instance has a VR SQ.
        /// </remarks>
        /// <param name="item">The sequence item to add.</param>
        public override void AddItem(SequenceItem item)
        {
            if (this.VR == VR.SQ)
            {
                SequenceItem cloneSequenceItem = item.Clone();

                DvtkDataSequence.Add(cloneSequenceItem.DvtkDataSequenceItem);
            }
            else
            {
                Thread.WriteWarningCurrentThread("Adding a sequence item to an attribute with tag sequence " + TagSequence.ToString() + " and VR " + this.VR.ToString() + ". Doing nothing.");
            }
        }
示例#11
0
 /// <summary>
 /// Clears all sequence items present in the attribute.
 /// </summary>
 /// <remarks>
 /// This method is only meaningfull if this instance has a VR SQ.
 /// </remarks>
 public override void ClearItems()
 {
     if (this.VR == VR.SQ)
     {
         DvtkDataSequence.Clear();
     }
     else
     {
         Thread.WriteWarningCurrentThread("Clearing the sequence items of an attribute with tag sequence " + TagSequence.ToString() + " and VR " + this.VR.ToString() + ". Doing nothing.");
     }
 }
示例#12
0
        /// <summary>
        /// Obsolete class, use the classes in the namespace DvtkHighLevelInterface.Common.Compare instead.
        /// </summary>
        /// <param name="dicomAttributesToValidate">-</param>
        /// <param name="zeroBasedIndex">-</param>
        private void AddAttributeInformationForAttribute(DicomAttributesToValidate dicomAttributesToValidate, int zeroBasedIndex)
        {
            bool isAttributePresent = false;
            DicomAttributeToValidate dicomAttributeToValidate = dicomAttributesToValidate[zeroBasedIndex] as DicomAttributeToValidate;
            CompareFlags compareFlags = dicomAttributeToValidate.ValidationRuleDicomAttribute.CompareFlags;
            DicomAttributeFlags dicomAttributeFlags = dicomAttributeToValidate.ValidationRuleDicomAttribute.DicomAttributeFlags;

            if (dicomAttributeToValidate.Attribute is ValidAttribute)
            {
                isAttributePresent = true;
            }
            else
            {
                isAttributePresent = false;
            }

            // Attribute Tag column.
            if (this.displayAttributeTag)
            {
                if (isAttributePresent)
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.DisplayFullTagSequence)
                    {
                        ArrayList tags = (dicomAttributeToValidate.Attribute as ValidAttribute).TagSequence.Tags;

                        for (int tagIndex = 0; tagIndex < tags.Count; tagIndex++)
                        {
                            Tag tag = tags[tagIndex] as Tag;
                            if (tag.ContainsIndex)
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation + "(" + tag.IndexNumber + ")");
                            }
                            else
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation);
                            }
                        }
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], ((ValidAttribute)dicomAttributeToValidate.Attribute).TagSequence.DicomNotation);
                    }
                }
                else
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                    {
                        SetCellNotApplicable((int)this.columnIndexAttributeTag[zeroBasedIndex]);
                    }
                    else
                    {
                        TagSequence tagSequence = new TagSequence(dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence);
                        ArrayList tags = tagSequence.Tags;

                        for (int tagIndex = 0; tagIndex < tags.Count; tagIndex++)
                        {
                            Tag tag = tags[tagIndex] as Tag;
                            if (tag.ContainsIndex)
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation + "(" + tag.IndexNumber + ")");
                            }
                            else
                            {
                                SetCellOK((int)this.columnIndexAttributeTag[zeroBasedIndex], "".PadRight(tagIndex, '>') + tag.DicomNotation);
                            }
                        }
                    }
                }
            }

            // Attribute Name column.
            if (this.displayAttributeName)
            {
                if (isAttributePresent)
                {
                    SetCellOK((int)this.columnIndexAttributeName[zeroBasedIndex], GetAttributeName(dicomAttributeToValidate.Attribute));
                }
                else
                {
                    if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                    {
                        SetCellNotApplicable((int)this.columnIndexAttributeName[zeroBasedIndex]);
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeName[zeroBasedIndex], "-");
                    }
                }
            }

            // Attribute Present column.
            if (this.displayAttributePresent)
            {
                if (dicomAttributeToValidate.ValidationRuleDicomAttribute.TagSequence == "")
                {
                    SetCellNotApplicable((int)this.columnIndexAttributePresent[zeroBasedIndex]);
                }
                else
                {
                    String presentString = "";
                    bool containsError = false;

                    if (isAttributePresent)
                    {
                        presentString = "+";
                    }
                    else
                    {
                        presentString = "-";
                    }

                    if ((compareFlags & CompareFlags.Compare_present) == CompareFlags.Compare_present)
                    {
                        if (dicomAttributesToValidate.ContainsComparePresentErrors)
                        {
                            containsError = true;
                        }
                    }

                    if ((dicomAttributeFlags & DicomAttributeFlags.Present) == DicomAttributeFlags.Present)
                    {
                        if (!isAttributePresent)
                        {
                            containsError = true;
                        }
                    }

                    if ((dicomAttributeFlags & DicomAttributeFlags.Not_present) == DicomAttributeFlags.Not_present)
                    {
                        if (isAttributePresent)
                        {
                            containsError = true;
                        }
                    }

                    if (containsError)
                    {
                        SetCellError((int)this.columnIndexAttributePresent[zeroBasedIndex], presentString);
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributePresent[zeroBasedIndex], presentString);
                    }
                }
            }

            // Attribute VR column.
            if (this.displayAttributeVR)
            {
                if (isAttributePresent)
                {
                    bool containsError = false;

                    if ((compareFlags & CompareFlags.Compare_VR) == CompareFlags.Compare_VR)
                    {
                        if (dicomAttributesToValidate.ContainsCompareVRErrors)
                        {
                            containsError = true;
                        }
                    }

                    if (containsError)
                    {
                        SetCellError((int)this.columnIndexAttributeVR[zeroBasedIndex], dicomAttributeToValidate.Attribute.VR.ToString());
                    }
                    else
                    {
                        SetCellOK((int)this.columnIndexAttributeVR[zeroBasedIndex], dicomAttributeToValidate.Attribute.VR.ToString());
                    }
                }
                else
                {
                    SetCellNotApplicable((int)this.columnIndexAttributeVR[zeroBasedIndex]);
                }
            }

            // Attribute Values column.
            if (this.displayAttributeValues)
            {
                int columnIndex = (int)this.columnIndexAttributeValues[zeroBasedIndex];

                if (isAttributePresent)
                {
                    if (dicomAttributeToValidate.Attribute.VR == VR.SQ)
                    {
                        SetCellNotApplicable(columnIndex);
                    }
                    else
                    {
                        bool containsError = false;

                        if ((compareFlags & CompareFlags.Compare_values) == CompareFlags.Compare_values)
                        {
                            if (dicomAttributesToValidate.ContainsCompareValuesErrors)
                            {
                                containsError = true;
                            }
                        }

                        if ((dicomAttributeFlags & DicomAttributeFlags.Values) == DicomAttributeFlags.Values)
                        {
                            if (dicomAttributeToValidate.Attribute.Values.Count == 0)
                            {
                                containsError = true;
                            }
                        }

                        if ((dicomAttributeFlags & DicomAttributeFlags.No_values) == DicomAttributeFlags.No_values)
                        {
                            if (dicomAttributeToValidate.Attribute.Values.Count > 0)
                            {
                                containsError = true;
                            }
                        }

                        if (containsError)
                        {
                            SetCellError(columnIndex, dicomAttributeToValidate.Attribute.Values.ToString());
                        }
                        else
                        {
                            SetCellOK(columnIndex, dicomAttributeToValidate.Attribute.Values.ToString());
                        }
                    }
                }
                else
                {
                    SetCellNotApplicable(columnIndex);
                }
            }
        }
示例#13
0
        /// <summary>
        /// Creates a deep copy of this TagSequence.
        /// </summary>
        /// <returns>The created deep copy.</returns>
        internal TagSequence Clone()
        {
            TagSequence cloneTagSequence = new TagSequence();

            foreach(Tag tag in this.tags)
            {
                Tag cloneTag = tag.Clone();
                cloneTagSequence.Add(cloneTag);
            }

            return(cloneTagSequence);
        }
示例#14
0
        /// <summary>
        /// Adds a single attribute with the tag sequence, VR and values specified.
        /// </summary>
        /// <remarks>
        /// Depending on the group number of the last tag in the tag sequence, the attribute
        /// is set in the CommandSet or DataSet of this instance.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag sequence, it is removed first before it is 
        /// again set.
        /// <br></br><br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequence">The tag sequence that uniquely identifies the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="parameters">
        /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use
        /// multiple parameter arguments for this method when adding a single attribute with multiple values.
        /// </param>
        internal void Set(TagSequence tagSequence, VR vR, params Object[] parameters)
        {
            // Check if the TagSequence supplied uniquely identifies one attribute.
            if (!tagSequence.IsSingleAttributeMatching)
            {
                throw new HliException(tagSequence.ToString() + " not valid for setting an attribute.");
            }

            if (tagSequence.IsValidForCommandSet)
            {
                CommandSet.Set(tagSequence, vR, parameters);
            }
            else if (tagSequence.IsValidForDataSet)
            {
                DataSet.Set(tagSequence, vR, parameters);
            }
            else
            {
                throw new HliException(tagSequence.ToString() + " not valid for setting a DicomMessage attribute.");
            }
        }
示例#15
0
        /// <summary>
        /// Adds a single attribute with the tag sequence string, VR and values specified.
        /// </summary>
        /// <remarks>
        /// Depending on the group number of the last tag in the tag sequence string, the attribute
        /// is set in the CommandSet or DataSet of this instance.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag sequence string, it is removed first before it is 
        /// again set.
        /// <br></br><br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence string,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequenceString">The tag sequence string that uniquely identifies the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="parameters">
        /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use
        /// multiple parameter arguments for this method when adding a single attribute with multiple values.
        /// </param>
        public void Set(String tagSequenceString, VR vR, params Object[] parameters)
        {
            TagSequence tagSequence = new TagSequence(tagSequenceString);

            Set(tagSequence, vR, parameters);
        }
示例#16
0
        /// <summary>
        /// Adds a single attribute with the tag, VR and values specified.
        /// </summary>
        /// <remarks>
        /// Depending on the group number of the tag, the attribute
        /// is set in the CommandSet or DataSet of this instance.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag, it is removed first before it is 
        /// again set.
        /// </remarks>
        /// <param name="dvtkDataTag">The tag that uniquely identifies the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="parameters">
        /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead use
        /// multiple parameter arguments for this method when adding a single attribute with multiple values.
        /// </param>
        public void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, params Object[] parameters)
        {
            TagSequence tagSequence = new TagSequence();

            tagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber));

            Set(tagSequence, vR, parameters);
        }
示例#17
0
 /// <summary>
 /// Constructor.
 /// 
 /// Use this to encapsulate an existing DvtkData sequence item.
 /// </summary>
 /// <param name="tagSequence">The tag sequence of this sequence item.</param>
 /// <param name="dvtkDataSequenceItem">The encapsulated DvtkData SequenceItem.</param>
 internal SequenceItem(TagSequence tagSequence, DvtkData.Dimse.SequenceItem dvtkDataSequenceItem)
     : base(tagSequence, dvtkDataSequenceItem)
 {
 }
示例#18
0
        /// <summary>
        /// Creates a deep copy of this instance.
        /// </summary>
        /// <param name="parentAttributeSetToCloneTo">
        /// The AttributeSet the new cloned Attribute wil become part of.
        /// </param>
        /// <returns>The created deep copy of this instance.</returns>
        internal override Attribute Clone(AttributeSet parentAttributeSetToCloneTo)
        {
            //
            // Clone the attribute without values.
            //

            TagSequence newTagSequence = parentAttributeSetToCloneTo.TagSequence.Clone();

            Tag lastTagCurrentAttribute = TagSequence.Tags[TagSequence.Tags.Count - 1] as Tag;

            newTagSequence.Add(lastTagCurrentAttribute);

            ValidAttribute cloneAttribute = new ValidAttribute(newTagSequence, new DvtkData.Dimse.Attribute(lastTagCurrentAttribute.AsUInt32, (DvtkData.Dimse.VR) this.VR), parentAttributeSetToCloneTo);


            //
            // Add the values or items to the cloned attribute.
            //

            Values currentValues = this.Values;
            Values cloneValues   = cloneAttribute.Values;

            if (currentValues.IsImplementedWithCollection)
            {
                Object[] collectionAsArray = new Object[currentValues.CollectionImplementation.Count];

                currentValues.CollectionImplementation.CopyTo(collectionAsArray, 0);

                cloneValues.Add(collectionAsArray);
            }
            else if (currentValues.IsImplementedWithString)
            {
                cloneValues.Add(currentValues.StringImplementation);
            }
            else if ((currentValues.Attribute.VR == VR.OB) || (currentValues.Attribute.VR == VR.OF) || (currentValues.Attribute.VR == VR.OW))
            {
                cloneValues.Add(currentValues);
            }
            else if (this.VR == VR.UN)
            {
                cloneValues.ByteArrayImplementation = currentValues.ByteArrayImplementation;
            }
            else if (this.VR == VR.SQ)
            {
                for (int index = 1; index <= this.ItemCount; index++)
                {
                    // The AddItem will take care that the item is cloned.
                    cloneAttribute.AddItem(this.GetItem(index));
                }
            }
            else
            {
                // Do nothing.
            }


            //
            // Set the Name of the attribute.
            //

            cloneAttribute.Name = Name;

            return(cloneAttribute);
        }
示例#19
0
文件: Values.cs 项目: ewcasas/DVTK
        /// <summary>
        /// Converts the supplied array to a DvtkData TagCollection.
        /// </summary>
        /// <remarks>
        /// When an array element is null, it will be skipped.<br></br><br></br>
        /// When an array element cannot be converted, it will be interpreted as a tag with value 0x00000000.
        /// </remarks>
        /// <param name="objects">The array to convert.</param>
        /// <returns>The returned DvtkData TagCollection.</returns>
        private DvtkData.Collections.TagCollection ConvertToTagCollection(object[] objects)
        {
            DvtkData.Collections.TagCollection tagCollection = new DvtkData.Collections.TagCollection();

            foreach (object item in objects)
            {
                if (item != null)
                {
                    DvtkData.Dimse.Tag dvtkDataTag = null;

                    try
                    {
                        if (item is DvtkData.Dimse.Tag)
                        {
                            DvtkData.Dimse.Tag sourceDvtkDataTag = item as DvtkData.Dimse.Tag;

                            dvtkDataTag = new DvtkData.Dimse.Tag(sourceDvtkDataTag.GroupNumber, sourceDvtkDataTag.ElementNumber);
                        }
                        else if (item is System.Int32)
                        {
                            dvtkDataTag = (System.Int32)item;
                        }
                        else if (item is System.UInt32)
                        {
                            dvtkDataTag = (System.UInt32)item;
                        }
                        else if (item is String)
                        {
                            TagSequence tagSequence = new TagSequence(item as String);

                            if (tagSequence.IsSingleAttributeMatching)
                            {
                                if (tagSequence.Tags.Count == 1)
                                {
                                    Tag tag = tagSequence.Tags[0] as Tag;

                                    dvtkDataTag = new DvtkData.Dimse.Tag(tag.GroupNumber, tag.ElementNumber);
                                }
                                else
                                {
                                    throw new ArgumentException("One of the Array elements represents a nested tag.");
                                }
                            }
                            else
                            {
                                throw new ArgumentException("One of the Array elements represents an indexed tag.");
                            }
                        }
                        else
                        {
                            throw new ArgumentException("One of the Array elements is of an unexpected type.");
                        }
                    }
                    catch
                    {
                        dvtkDataTag = new DvtkData.Dimse.Tag(0x0000, 0x0000);
                    }

                    tagCollection.Add(dvtkDataTag);
                }
            }

            return (tagCollection);
        }
示例#20
0
        /// <summary>
        /// Gets a sequence item.
        /// </summary>
        /// <remarks>
        /// This method is only meaningfull if this instance has a VR SQ.
        /// </remarks>
        /// <param name="oneBasedIndex">The one based index.</param>
        /// <returns>The sequence item.</returns>
        public override SequenceItem GetItem(int oneBasedIndex)
        {
            SequenceItem sequenceItem = null;

            if (this.VR == VR.SQ)
            {
                if ((oneBasedIndex >= 1) && (oneBasedIndex <= ItemCount))
                {
                    TagSequence sequenceItemTagSequence = TagSequence.Clone();
                    Tag         lastTag = sequenceItemTagSequence.Tags[sequenceItemTagSequence.Tags.Count - 1] as Tag;
                    lastTag.IndexNumber = oneBasedIndex;

                    sequenceItem = new SequenceItem(sequenceItemTagSequence, DvtkDataSequence[oneBasedIndex - 1]);
                }
                else
                {
                    sequenceItem = new SequenceItem();
                    Thread.WriteWarningCurrentThread("Getting sequence item " + oneBasedIndex.ToString() + " from attribute with tag sequence " + TagSequence.ToString() + " containing " + ItemCount.ToString() + " items. Returning an empty sequence item.");
                }
            }
            else
            {
                sequenceItem = new SequenceItem();
                Thread.WriteWarningCurrentThread("Getting a sequence item from attribute with tag sequence " + TagSequence.ToString() + " and VR " + this.VR.ToString() + ". Returning an empty sequence item.");
            }

            return(sequenceItem);
        }
示例#21
0
        private void SetValuesCellForAttribute(AttributeList attributeList, int zeroBasedIndex)
        {
            int columnIndex = (int)this.columnIndexAttributeValues[zeroBasedIndex];

            AttributeBase attributebase = attributeList[zeroBasedIndex];

            if (attributebase.IsPresent)
            {
                bool isDicomSequenceAttribute = false;

                if (attributebase is DicomAttribute)
                {
                    if ((attributebase as DicomAttribute).AttributeOnly.VR == VR.SQ)
                    {
                        isDicomSequenceAttribute = true;
                    }
                }

                if (!isDicomSequenceAttribute)
                {
                    bool containsError = false;

                    String valuesString = attributebase.ValuesToString();

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Compare_values) == FlagsBase.Compare_values)
                    {
                        if (attributeList.ContainsCompareValuesErrors)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.Values) == FlagsBase.Values)
                    {
                        if (valuesString.Length == 0)
                        {
                            containsError = true;
                        }
                    }

                    if ((attributebase.ValidationRule.Flags & FlagsBase.No_values) == FlagsBase.No_values)
                    {
                        if (valuesString.Length > 0)
                        {
                            containsError = true;
                        }
                    }

                    // If this is a Dicom attribute which is a group length, only compare when the compareGroupLength
                    // field is true.
                    if ((!this.displayGroupLength) && (attributebase is DicomAttribute))
                    {
                        DicomAttribute dicomAttribute = attributebase as DicomAttribute;

                        TagSequence tagSequence = new TagSequence(dicomAttribute.ValidationRuleDicomAttribute.TagSequenceString);

                        if (tagSequence.LastTag.ElementNumber == 0)
                        {
                            containsError = false;
                        }
                    }

                    // If the attribute contains no values, display this with the text "No values" in italic.
                    if (valuesString.Length == 0)
                    {
                        valuesString = "<i>No values</i>";
                    }

                    if (containsError)
                    {
                        SetCellError(columnIndex, valuesString);
                    }
                    else
                    {
                        SetCellOK(columnIndex, valuesString);
                    }
                }
                else
                    // Is Sequence attribute.
                {
                    if ((attributebase.ValidationRule.Flags & FlagsBase.Include_sequence_items) == 0)
                        // If sequence item will not be displayed.
                    {
                        SetCellOK(columnIndex, "<i>Items will not be displayed.</i>");
                    }
                }
            }
        }
示例#22
0
        /// <summary>
        /// Insert a Sequence Item at a specified position.
        /// </summary>
        /// <remarks>
        /// This method is only meaningfull if this instance has a VR SQ. The inserted Sequence
        /// Item will get item number oneBasedIndex.
        /// </remarks>
        /// <param name="oneBasedIndex">The one based index of the position to insert.</param>
        /// <param name="item">The Sequence item to insert.</param>
        public override void InsertItem(int oneBasedIndex, SequenceItem item)
        {
            if (this.VR == VR.SQ)
            {
                if ((oneBasedIndex >= 1) && (oneBasedIndex <= (ItemCount + 1)))
                {
                    SequenceItem cloneSequenceItem = item.Clone();

                    DvtkDataSequence.Insert(oneBasedIndex - 1, cloneSequenceItem.DvtkDataSequenceItem);
                }
                else
                {
                    Thread.WriteWarningCurrentThread("Inserting sequence item at one based position " + oneBasedIndex.ToString() + " fom attribute with tag sequence " + TagSequence.ToString() + " containing " + ItemCount.ToString() + " items. Doing nothing.");
                }
            }
            else
            {
                Thread.WriteWarningCurrentThread("Adding a sequence item to an attribute with tag sequence " + TagSequence.ToString() + " and VR " + this.VR.ToString() + ". Doing nothing.");
            }
        }
示例#23
0
        /// <summary>
        /// Adds a single attribute with the tag, VR and value specified.
        /// </summary>
        /// <remarks>
        /// Only use this method for setting an attribute with VR OB, OF or OW.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// </remarks>
        /// <param name="dvtkDataTag">The tag of the attribute.</param>
        /// <param name="vR">The VR (may only be OB, OF or OW) of the attribute.</param>
        /// <param name="value">The value of the attribute.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br>
        /// -or-<br></br>
        /// <paramref name="vR"/> is unequal to OB, OF or OW.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="value"/> is a null reference.
        /// </exception>
        public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, Byte[] value)
        {
            TagSequence internalTagSequence = new TagSequence();

            internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber));

            //
            // Sanity checks.
            //

            // Check if the tag supplied is valid for a CommandSet.
            if (!internalTagSequence.IsValidForCommandSet)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a CommandSet attribute.", "dvtkDataTag");
            }

            // Check the supplied VR.

            if ((vR != VR.OB) && (vR != VR.OF) && (vR != VR.OW))
            {
                throw new ArgumentException("Supplied VR is " + vR.ToString() + ". VR may only be OB, OF or OW.", "vR");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            //
            // Perform the actual operation in the base class.
            //

            Set(internalTagSequence, vR, value);
        }
示例#24
0
 /// <summary>
 /// Removes a sequence item.
 /// </summary>
 /// <param name="oneBasedIndex">The one based index</param>
 public override void RemoveItemAt(int oneBasedIndex)
 {
     if (this.VR == VR.SQ)
     {
         if ((oneBasedIndex >= 1) && (oneBasedIndex <= ItemCount))
         {
             DvtkDataSequence.RemoveAt(oneBasedIndex - 1);
         }
         else
         {
             Thread.WriteWarningCurrentThread("Removing sequence item " + oneBasedIndex.ToString() + " from attribute with tag sequence " + TagSequence.ToString() + " containing " + ItemCount.ToString() + " items. Doing nothing.");
         }
     }
     else
     {
         Thread.WriteWarningCurrentThread("Removing a sequence item from attribute with tag sequence " + TagSequence.ToString() + " and VR " + this.VR.ToString() + ". Doing nothing.");
     }
 }
示例#25
0
        /// <summary>
        /// Adds a single attribute with the tag sequence, VR and value specified.
        /// </summary>
        /// <remarks>
        /// Only use this method for setting an attribute with VR OB, OF or OW.
        /// <br></br><br></br>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// <br></br><br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="vR">The VR (may only be OB, OF or OW) of the attribute.</param>
        /// <param name="value">The value of the attribute.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting an attribute.<br></br>
        /// -or-<br></br>
        /// <paramref name="dvtkDataTag"/> is not valid for setting a CommandSet attribute.<br></br>
        /// -or-<br></br>
        /// <paramref name="vR"/> is unequal to OB, OF or OW.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="value"/> is a null reference.
        /// </exception>
        public override void Set(String tagSequence, VR vR, Byte[] value)
        {
            TagSequence internalTagSequence = new TagSequence(tagSequence);

            //
            // Sanity checks.
            //

            if (!internalTagSequence.IsSingleAttributeMatching)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting an attribute.");
            }

            // Check if the tag supplied is valid for a CommandSet.
            if (!internalTagSequence.IsValidForCommandSet)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting a CommandSet attribute.", "dvtkDataTag");
            }

            // Check the supplied VR.

            if ((vR != VR.OB) && (vR != VR.OF) && (vR != VR.OW))
            {
                throw new ArgumentException("Supplied VR is " + vR.ToString() + ". VR may only be OB, OF or OW.", "vR");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            //
            // Perform the actual operation in the base class.
            //

            Set(internalTagSequence, vR, value);
        }
示例#26
0
        //
        // - Methods -
        //
        /// <summary>
        /// Get the next collection of attributes to compare to each other.
        /// If an attribute is not present, a null pointer is returned in the AttributeCollection.
        /// If all attributes have been compared, null is returned.
        /// </summary>
        /// <returns>The attributes to validate.</returns>
        /// 
        private AttributeList DetermineNextAttributes(TagSequence lowestTagSequence)
        {
            AttributeList nextAttributes = new AttributeList();

            nextAttributes.CompareRule = new CompareRule();

            for (int index = 0; index < this.attributeCollections.Count; index++)
            {
                int attributeSetIndex = (int)this.currentAttributeIndices[index];
                AttributeCollectionBase attributeCollectionBase = this.attributeCollections[index];

                if (attributeCollectionBase == null)
                {
                    nextAttributes.Add(null);
                    nextAttributes.CompareRule.Add(null);
                }
                else if (attributeCollectionBase is Hl7AttributeCollection)
                {
                    nextAttributes.Add(null);
                    nextAttributes.CompareRule.Add(null);
                }
                else if (attributeCollectionBase is DicomAttributeCollection)
                {
                    DicomAttributeCollection dicomAttributeCollection = attributeCollectionBase as DicomAttributeCollection;

                    if (attributeSetIndex < dicomAttributeCollection.AttributeSetOnly.Count)
                        // Still unprocessed attributes left in this dataset.
                    {
                        ValidAttribute attributeOnly = dicomAttributeCollection.AttributeSetOnly[attributeSetIndex] as ValidAttribute;

                        if (attributeOnly.TagSequence.LastTag.AsUInt32 == lowestTagSequence.LastTag.AsUInt32)
                        {
                            // Add entry with existing attribute.
                            ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                            nextAttributes.CompareRule.Add(validationRuleDicomAttribute);
                            DicomAttribute dicomAttribute = new DicomAttribute(attributeOnly, validationRuleDicomAttribute);
                            nextAttributes.Add(dicomAttribute);

                            // This attribute will be returned. Increase the attribute index.
                            this.currentAttributeIndices[index] = attributeSetIndex + 1;
                        }
                        else
                        {
                            // Add entry with non-existing attribute.
                            ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                            DicomAttribute dicomAttribute = new DicomAttribute(new DvtkHighLevelInterface.Dicom.Other.InvalidAttribute(), validationRuleDicomAttribute);
                            nextAttributes.Add(dicomAttribute);
                        }
                    }
                    else
                        // No more unprocessed attributes left in this dataset.
                    {
                        // Add entry with non-existing attribute.
                        ValidationRuleDicomAttribute validationRuleDicomAttribute = new ValidationRuleDicomAttribute(lowestTagSequence.ToString(), dicomAttributeCollection.Flags);
                        DicomAttribute dicomAttribute = new DicomAttribute(new DvtkHighLevelInterface.Dicom.Other.InvalidAttribute(), validationRuleDicomAttribute);
                        nextAttributes.Add(dicomAttribute);
                    }
                }
            }

            return(nextAttributes);
        }
示例#27
0
        //
        // - Constructors -
        //

        /// <summary>
        /// Default constructor.
        /// </summary>
        public InvalidAttribute()
        {
            TagSequence = new TagSequence("0x00000000");
        }
示例#28
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="tagSequence">Tag sequence used to retrieve the attribute.</param>
 public InvalidAttribute(TagSequence tagSequence)
 {
     TagSequence = tagSequence;
 }
示例#29
0
        /// <summary>
        /// Adds a single attribute with the tag, VR and values specified.
        /// </summary>
        /// <remarks>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// </remarks>
        /// <param name="dvtkDataTag">The tag of the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="values">
        /// The values of the attribute. Do not use the DICOM delimeter '\' directly. Instead supply
        /// multiple values arguments for this method when adding a single attribute with multiple values.
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting a FileMetaInformation attribute.<br></br>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="values"/> is a null reference.
        /// </exception>
        public override void Set(DvtkData.Dimse.Tag dvtkDataTag, VR vR, params Object[] values)
        {
            TagSequence internalTagSequence = new TagSequence();

            internalTagSequence.Add(new Tag(dvtkDataTag.GroupNumber, dvtkDataTag.ElementNumber));

            //
            // Sanity checks.
            //

            // Check if the tag supplied is valid for a FileMetaInformation.
            if (!internalTagSequence.IsValidForFileMetaInformation)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " is not valid for setting a FileMetaInformation attribute.", "dvtkDataTag");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            //
            // Perform the actual operation.
            //

            Set(internalTagSequence, vR, values);

            if ((internalTagSequence.ToString() == "0x00020010") && (values.Length == 1))
            {
                this.dvtkDataFileHead.TransferSyntax = new DvtkData.Dul.TransferSyntax(values[0].ToString());
            }
        }
示例#30
0
        /// <summary>
        /// Gets the attribute that has the supplied tag sequence string.
        /// </summary>
        /// <param name="tagSequenceString"></param>
        /// <returns></returns>
        public Attribute this[String tagSequenceString]
        {
            get
            {
                Attribute attribute = null;

                TagSequence tagSequence = new TagSequence(tagSequenceString);

                if (!tagSequence.IsSingleAttributeMatching)
                {
                    throw new HliException(tagSequenceString.ToString() + " not valid for the index property.");				}

                if (tagSequence.IsValidForCommandSet)
                {
                    attribute = this.CommandSet[tagSequence];
                }
                else if (tagSequence.IsValidForDataSet)
                {
                    attribute = this.DataSet[tagSequence];
                }
                else
                {
                    throw new HliException(tagSequenceString.ToString() + " not valid for a DicomMessage attribute.");
                }

                return(attribute);
            }
        }
示例#31
0
        /// <summary>
        /// Adds a single attribute with the tag sequence, VR and values specified.
        /// </summary>
        /// <remarks>
        /// If an attribute already exists with this tag, it is removed first before it is again
        /// added.
        /// <br></br>
        /// If sequence items (each with a sequence item index) are specified in the tag sequence,
        /// empty sequence items will be added automatically to avoid gaps in the sequence items of sequence
        /// attributes.
        /// </remarks>
        /// <param name="tagSequence">The tag sequence of the attribute.</param>
        /// <param name="vR">The VR of the attribute.</param>
        /// <param name="values">The values, which will be copied from another attribute, for this attribute.</param>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="dvtkDataTag"/> is not valid for setting an attribute.<br></br>
        /// -or-<br></br>
        /// <paramref name="dvtkDataTag"/> is not valid for setting a FileMetaInformation attribute.<br></br>
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="values"/> is a null reference.
        /// </exception>
        public override void Set(String tagSequence, VR vR, Values values)
        {
            TagSequence internalTagSequence = new TagSequence(tagSequence);

            //
            // Sanity checks.
            //

            if (!internalTagSequence.IsSingleAttributeMatching)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting an attribute.");
            }

            // Check if the tag supplied is valid for a FileMetaInformation.
            if (!internalTagSequence.IsValidForFileMetaInformation)
            {
                throw new ArgumentException(internalTagSequence.ToString() + " not valid for setting a FileMetaInformation attribute.", "dvtkDataTag");
            }

            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            //
            // Perform the actual operation.
            //

            Set(internalTagSequence, vR, values);

            if ((internalTagSequence.ToString() == "0x00020010") && (values.Count == 1))
            {
                this.dvtkDataFileHead.TransferSyntax = new DvtkData.Dul.TransferSyntax(values[0]);
            }
        }
示例#32
0
 //
 // - Constructors -
 //
 /// <summary>
 /// Default constructor.
 /// </summary>
 public InvalidAttribute()
 {
     TagSequence = new TagSequence("0x00000000");
 }