Пример #1
0
        /// <summary>
        /// Private method used by the Set method. This methods sets an attribute
        /// to a Sequence Attribute and makes sure it contains enough sequence items.
        /// </summary>
        /// <param name="tag">The tag of the Attribute.</param>
        /// <returns>The already existing or newly created sequence item.</returns>
        private Attribute SetSequenceAttribute(Tag tag)
        {
            Attribute attribute = GetAttribute(tag.AsUInt32);

            if (!(attribute is ValidAttribute))
            {
                attribute = Create(tag.AsUInt32, VR.SQ);
            }
            else if (attribute.VR != VR.SQ)
            {
                attribute.Delete();

                attribute = Create(tag.AsUInt32, VR.SQ);
            }

            // At this time, we have made sure that attribute is a Sequence Attribute.
            // Now take care that it contains enough Sequence Items.

            for (int sequenceIndex = attribute.ItemCount; sequenceIndex < tag.IndexNumber; sequenceIndex++)
            {
                attribute.AddItem(new SequenceItem());
            }

            return(attribute);
        }
Пример #2
0
        internal void Append(TagSequence tagSequence, VR vR, params Object[] parameters)
        {
            // Check if the supplied parameters correspond with the supplied VR.
            // If the check fails, an exception is thrown.
            CheckParameters(vR, parameters);

            if (tagSequence.IsSingleAttributeMatching)
            // Supplied TagSequence is single attribute matching.
            {
                if (Exists(tagSequence))
                // Attribute already exists.
                {
                    Attribute alreadyExistingAttribute = this[tagSequence];

                    if (alreadyExistingAttribute.VR == vR)
                    // Attribute already exists and has the same VR.
                    {
                        if (vR == VR.SQ)
                        // Attribute already exists and also has VR SQ.
                        {
                            foreach (SequenceItem itemToAdd in parameters)
                            {
                                alreadyExistingAttribute.AddItem(itemToAdd);
                            }
                        }
                        else
                        // Attribute already exists and has the same VR (unequal to SQ).
                        {
                            alreadyExistingAttribute.Values.Add(parameters);
                        }
                    }
                    else
                    // Attribute already exists but has a different VR.
                    {
                        Thread.WriteErrorCurrentThread("While appending, attribute with tag sequence " + tagSequence.ToString() + " already existed with a different VR. Nothing will be appended.");
                    }
                }
                else
                // Attribute does not already exists.
                {
                    // In this case, behaviour should be the same as the Set method.
                    Set(tagSequence, vR, parameters);
                }
            }
            else
            // Supplied TagSequence contains wildcards.
            {
                AttributeCollection existingAttributes = GetAttributes(tagSequence);

                foreach (ValidAttribute existingAttribute in existingAttributes)
                {
                    Append(existingAttribute.TagSequence, vR, parameters);
                }
            }
        }