]> Creatis software - gdcm.git/blobdiff - src/gdcmFileHelper.cxx
Typo
[gdcm.git] / src / gdcmFileHelper.cxx
index 2ad1f4f538ab50f61c1dc1317ac9cab15a5024c4..51ca3b5c3a614be3401bf3c4aabe978f3a17d1b8 100644 (file)
@@ -4,8 +4,8 @@
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
 
-  Date:      $Date: 2005/03/03 11:05:00 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2005/03/11 11:12:13 $
+  Version:   $Revision: 1.30 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -617,6 +617,13 @@ bool FileHelper::Write(std::string const &fileName)
          break;
       case ACR:
       case ACR_LIBIDO:
+      // Just to avoid further trouble if user create a file ex-nihilo,
+      // wants to write it as an ACR-NEMA file,
+      // and forget to create any Entry belonging to group 0008
+      // (shame on him !)
+      // We add Recognition Code (RET)
+        if ( ! FileInternal->GetValEntry(0x0008, 0x0010) )
+            FileInternal->InsertValEntry("", 0x0008, 0x0010);
          SetWriteFileTypeToACR();
          break;
       default:
@@ -660,6 +667,7 @@ bool FileHelper::Write(std::string const &fileName)
 
    RestoreWrite();
    RestoreWriteFileType();
+   RestoreWriteMandatory();
 
    // --------------------------------------------------------------
    // Special Patch to allow gdcm to re-write ACR-LibIDO formated images
@@ -943,17 +951,6 @@ void FileHelper::SetWriteFileTypeToImplicitVR()
  */ 
 void FileHelper::RestoreWriteFileType()
 {
-   // group 0002 may be pushed out for ACR-NEMA writting purposes 
-   Archive->Restore(0x0002,0x0000);
-   Archive->Restore(0x0002,0x0001);
-   Archive->Restore(0x0002,0x0002);
-   Archive->Restore(0x0002,0x0003);
-   Archive->Restore(0x0002,0x0010);
-   Archive->Restore(0x0002,0x0012);
-   Archive->Restore(0x0002,0x0013);
-   Archive->Restore(0x0002,0x0016);
-   Archive->Restore(0x0002,0x0100);
-   Archive->Restore(0x0002,0x0102);
 }
 
 /**
@@ -1054,7 +1051,7 @@ BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem,
    DocEntry *oldE = FileInternal->GetDocEntry(group, elem);
    BinEntry *newE;
 
-   if( oldE )
+   if( oldE ) 
       if( oldE->GetVR()!=vr )
          oldE = NULL;
 
@@ -1084,7 +1081,7 @@ BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem,
  *             - we push the sensitive entries to the Archive
  *          The writing process will restore the entries as they where before 
  *          entering FileHelper::CheckMandatoryElements, so the user will always
- *          see the entries just as he
+ *          see the entries just as he left them.
  * 
  * \todo : - warn the user if we had to add some entries :
  *         even if a mandatory entry is missing, we add it, with a default value
@@ -1115,7 +1112,6 @@ void FileHelper::CheckMandatoryElements()
    // Create them if not found
    // Always modify the value
    // Push the entries to the archive.
-
    ValEntry *e_0002_0000 = CopyValEntry(0x0002,0x0000);
       e_0002_0000->SetValue("0"); // for the moment
       Archive->Push(e_0002_0000);
@@ -1124,6 +1120,7 @@ void FileHelper::CheckMandatoryElements()
       e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(),
                                false);
       e_0002_0001->SetLength(2);
+      Archive->Push(e_0002_0001);
 
    ValEntry *e_0002_0002 = CopyValEntry(0x0002,0x0002);
       // [Secondary Capture Image Storage]
@@ -1135,11 +1132,6 @@ void FileHelper::CheckMandatoryElements()
       e_0002_0003->SetValue(Util::CreateUniqueUID());
       Archive->Push(e_0002_0003); 
 
-   ValEntry *e_0002_0010 = CopyValEntry(0x0002,0x0010);
-      //[Explicit VR - Little Endian] 
-      e_0002_0010->SetValue("1.2.840.10008.1.2.1"); 
-      Archive->Push(e_0002_0010);
    // 'Implementation Class UID'
    ValEntry *e_0002_0012 = CopyValEntry(0x0002,0x0012);
       e_0002_0012->SetValue(Util::CreateUniqueUID());
@@ -1203,7 +1195,7 @@ void FileHelper::CheckMandatoryElements()
       // the source image was NOT a true Dicom one.
       // We consider the image is a 'Secondary Capture' one
       // SOP Class UID
-      ValEntry *e_0008_0016  =  new ValEntry( 
+      e_0008_0016  =  new ValEntry( 
             Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0016) );
       // [Secondary Capture Image Storage]
       e_0008_0016 ->SetValue("1.2.840.10008.5.1.4.1.1.7"); 
@@ -1350,9 +1342,9 @@ void FileHelper::CheckMandatoryElements()
  
    // Remove some inconstencies (probably some more will be added)
 
-   // Push out (0020 0052),Frame of Reference UID
    // if (0028 0008)Number of Frames exists
-   // (0020 0052),Frame of Reference UID only meaningfull within a Serie
+   //    Push out (0020 0052),Frame of Reference UID
+   //    (only meaningfull within a Serie)
    ValEntry *e_0028_0008 = FileInternal->GetValEntry(0x0028, 0x0008);
    if ( !e_0028_0008 )
    {
@@ -1360,6 +1352,23 @@ void FileHelper::CheckMandatoryElements()
    }
 } 
  
+/**
+ * \brief Restore in the File the initial group 0002
+ */
+void FileHelper::RestoreWriteMandatory()
+{
+   // group 0002 may be pushed out for ACR-NEMA writting purposes 
+   Archive->Restore(0x0002,0x0000);
+   Archive->Restore(0x0002,0x0001);
+   Archive->Restore(0x0002,0x0002);
+   Archive->Restore(0x0002,0x0003);
+   Archive->Restore(0x0002,0x0012);
+   Archive->Restore(0x0002,0x0013);
+   Archive->Restore(0x0002,0x0016);
+   Archive->Restore(0x0002,0x0100);
+   Archive->Restore(0x0002,0x0102);
+}
+
 //-----------------------------------------------------------------------------
 // Private
 /**