+ entry->SetOffset(0); // just to avoid further missprinting
+ entry->SetLength(0); // just to avoid further missprinting
+
+ if( header )
+ {
+ // NULL when we Build Up (ex nihilo) a DICOMDIR
+ // or when we add the META elems
+ val = header->GetEntryByNumber(tmpGr, tmpEl);
+ }
+ else
+ {
+ val = GDCM_UNFOUND;
+ }
+
+ if( val == GDCM_UNFOUND)
+ {
+ if( tmpGr == 0x0004 && tmpEl == 0x1130 ) // File-set ID
+ {
+ // force to the *end* File Name
+ val = Util::GetName( path );
+ }
+ else if( tmpGr == 0x0004 && tmpEl == 0x1500 ) // Only used for image
+ {
+ if( header->GetFileName().substr(0, path.length()) != path )
+ {
+ dbg.Verbose(0, "DicomDir::SetElement : the base path"
+ " of file name is incorrect");
+ val = header->GetFileName();
+ }
+ else
+ {
+ val = &(header->GetFileName().c_str()[path.length()]);
+ }
+ }
+ else
+ {
+ val = it->Value;
+ }
+ }
+ else
+ {
+ if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 )
+ val = it->Value;
+ }
+
+ // GDCM_UNFOUND or not !
+
+ entry->SetValue( val ); // troubles expected when vr=SQ ...
+
+ if( dictEntry )
+ {
+ if( dictEntry->GetGroup() == 0xfffe )
+ {
+ entry->SetLength( entry->GetValue().length() ); // FIXME
+ }
+ else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" )
+ {
+ entry->SetLength(4);
+ }
+ else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" )
+ {
+ entry->SetLength(2);
+ }
+ else if( dictEntry->GetVR() == "SQ" )
+ {
+ entry->SetLength( 0xffffffff );
+ }
+ else
+ {
+ entry->SetLength( entry->GetValue().length() );
+ }
+ }
+
+ if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
+ {
+ std::cout << "GDCM_DICOMDIR_META ?!? should never print that"
+ << std::endl;
+ }
+ si->AddEntry(entry);
+ }
+ switch( type )
+ {
+ case GDCM_DICOMDIR_IMAGE:
+ AddDicomDirImageToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_SERIE:
+ AddDicomDirSerieToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_STUDY:
+ AddDicomDirStudyToEnd(si);
+ break;
+
+ case GDCM_DICOMDIR_PATIENT:
+ AddDicomDirPatientToEnd(si);
+ break;
+
+ default:
+ return;
+ }
+ //int count=1; // find a trick to increment
+ //s->AddEntry(si, count); // Seg Faults