/// <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); }
/// <summary> /// Get an attribute given the zero based index for this AttributeSet. /// </summary> public Attribute this[int zeroBasedIndex] { get { Attribute attribute = null; if ((zeroBasedIndex >= 0) && (zeroBasedIndex < Count)) { DvtkData.Dimse.Attribute dvtkDataAttribute = this.dvtkDataAttributeSet[zeroBasedIndex]; Tag tag = new Tag(dvtkDataAttribute.Tag.GroupNumber, dvtkDataAttribute.Tag.ElementNumber); TagSequence attributeTagSequence = this.tagSequence.Clone(); attributeTagSequence.Add(tag); attribute = new ValidAttribute(attributeTagSequence, dvtkDataAttribute, this); } else { throw new System.Exception("Set with tag sequence \"" + this.tagSequence.ToString() + "\" contains " + this.Count.ToString() + "Index for attribute supplied is " + zeroBasedIndex.ToString() + "."); } return(attribute); } }
/// <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); }
/// <summary> /// Create a new Attribute in this AttributeSet containing no values. /// /// Precondition: this Attribute may not exist in the AttributeSet. /// </summary> /// <param name="tagAsUInt32"></param> /// <param name="vR"></param> internal ValidAttribute Create(UInt32 tagAsUInt32, VR vR) { TagSequence newTagSequence = this.tagSequence.Clone(); newTagSequence.Add(new Tag(tagAsUInt32)); DvtkData.Dimse.Attribute dvtkDataAttribute = new DvtkData.Dimse.Attribute(tagAsUInt32, (DvtkData.Dimse.VR)vR); this.dvtkDataAttributeSet.Add(dvtkDataAttribute); MakeAscending(false); ValidAttribute validAttribute = new ValidAttribute(newTagSequence, dvtkDataAttribute, this); return(validAttribute); }
/// <summary> /// Get an attribute given the tag as UInt32. /// </summary> internal Attribute GetAttribute(UInt32 tagAsUInt32) { Attribute attribute = null; TagSequence attributeTagSequence = this.tagSequence.Clone(); attributeTagSequence.Add(new Tag(tagAsUInt32)); DvtkData.Dimse.Attribute dvtkDataAttribute = this.dvtkDataAttributeSet.GetAttribute(tagAsUInt32); if (dvtkDataAttribute == null) { attribute = new InvalidAttribute(attributeTagSequence); } else { attribute = new ValidAttribute(attributeTagSequence, dvtkDataAttribute, this); } return(attribute); }
/// <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); }
/// <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 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, 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 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.Count == 1)) { this.dvtkDataFileHead.TransferSyntax = new DvtkData.Dul.TransferSyntax(values[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); }
/// <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); }
/// <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); }