+ {
+ /////////////////////// ValEntry
+
+ // When "set" is a Document, then we are at the top of the
+ // hierarchy and the Key is simply of the form ( group, elem )...
+ if ( dynamic_cast< Document* > ( set ) )
+ {
+ newValEntry->SetKey( newValEntry->GetKey() );
+ }
+ // ...but when "set" is a SQItem, we are inserting this new
+ // valEntry in a sequence item. Hence the key has the
+ // generalized form (refer to \ref BaseTagKey):
+
+ // time waste hunting
+ //if (SQItem *parentSQItem = dynamic_cast< SQItem* > ( set ) )
+ //{
+ // newValEntry->SetKey( parentSQItem->GetBaseTagKey()
+ // + newValEntry->GetKey() );
+ //}
+
+ if ( !set->AddEntry( newValEntry ) )
+ {
+ gdcmWarningMacro( "in ParseDES : cannot add a ValEntry "
+ << newValEntry->GetKey()
+ << " (at offset : "
+ << newValEntry->GetOffset() << " )" );
+ used=false;
+ }
+ else
+ {
+ // Load only if we can add (not a duplicate key)
+ LoadDocEntry( newValEntry );
+ }
+
+ if ( newValEntry->GetElement() == 0x0000 ) // if on group length
+ {
+ if ( newValEntry->GetGroup()%2 != 0 ) // if Shadow Group
+ {
+ if ( LoadMode & NO_SHADOW ) // if user asked to skip shad.gr
+ {
+ std::string strLgrGroup = newValEntry->GetValue();
+ int lgrGroup;
+ if ( strLgrGroup != GDCM_UNFOUND)
+ {
+ lgrGroup = atoi(strLgrGroup.c_str());
+ Fp->seekg(lgrGroup, std::ios::cur);
+ used = false;
+ RemoveEntry( newDocEntry );
+ newDocEntry = 0;
+ continue;
+ }
+ }
+ }
+ }
+
+ bool delimitor=newValEntry->IsItemDelimitor();
+
+ // FIXME : Brutal patch, waiting till we find a clever way to guess
+ // if a doc entry is a Sequence,
+ // - when it's odd number
+ // - and the file is Implicit VR Transfert Syntax
+ //
+ // '&& offset!=132' is a very fierce way to guess
+ // if we are at zero level (Probabely not enough ...).
+ // We want to go on parsing.
+ if ( (delimitor && offset!=132) ||
+ (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) )
+ {
+ if (offset!=132)
+ {
+ gdcmWarningMacro( "in ParseDES : Item found out of a Sequence "
+ << newValEntry->GetKey()
+ << " (at offset : "
+ << newValEntry->GetOffset() << " )" );
+ }
+ if ( !used )
+ delete newDocEntry;
+ break;
+ }
+ }
+
+ // Just to make sure we are at the beginning of next entry.
+ SkipToNextDocEntry(newDocEntry);
+ }
+ else
+ {
+ /////////////////////// SeqEntry : VR = "SQ"
+
+ unsigned long l = newDocEntry->GetReadLength();
+ if ( l != 0 ) // don't mess the delim_mode for 'zero-length sequence'
+ {
+ if ( l == 0xffffffff )
+ {
+ delim_mode_intern = true;
+ }
+ else
+ {
+ delim_mode_intern = false;
+ }
+ }
+
+ if ( (LoadMode & NO_SHADOWSEQ) && ! delim_mode_intern )
+ {
+ // User asked to skip SeQuences *only* if they belong to Shadow Group
+ if ( newDocEntry->GetGroup()%2 != 0 )
+ {
+ Fp->seekg( l, std::ios::cur);
+ used = false;
+ continue;
+ }
+ }
+ if ( (LoadMode & NO_SEQ) && ! delim_mode_intern )
+ {
+ // User asked to skip *any* SeQuence
+ Fp->seekg( l, std::ios::cur);
+ used = false;
+ continue;
+ }
+ // delay the dynamic cast as late as possible
+ newSeqEntry = dynamic_cast<SeqEntry*>(newDocEntry);
+
+ // no other way to create the Delimitor ...
+ newSeqEntry->SetDelimitorMode( delim_mode_intern );
+
+ // At the top of the hierarchy, stands a Document. When "set"
+ // is a Document, then we are building the first depth level.
+ // Hence the SeqEntry we are building simply has a depth
+ // level of one:
+ if ( dynamic_cast< Document* > ( set ) )
+ {
+ newSeqEntry->SetDepthLevel( 1 );
+ newSeqEntry->SetKey( newSeqEntry->GetKey() );
+ }
+ // But when "set" is already a SQItem, we are building a nested
+ // sequence, and hence the depth level of the new SeqEntry
+ // we are building, is one level deeper:
+
+ // time waste hunting
+ if (SQItem *parentSQItem = dynamic_cast< SQItem* > ( set ) )
+ {
+ newSeqEntry->SetDepthLevel( parentSQItem->GetDepthLevel() + 1 );
+
+ // newSeqEntry->SetKey( parentSQItem->GetBaseTagKey()
+ // + newSeqEntry->GetKey() );
+ }
+
+ if ( l != 0 )
+ { // Don't try to parse zero-length sequences
+ ParseSQ( newSeqEntry,
+ newDocEntry->GetOffset(),
+ l, delim_mode_intern);
+ }
+ if ( !set->AddEntry( newSeqEntry ) )
+ {
+ gdcmWarningMacro( "in ParseDES : cannot add a SeqEntry "
+ << newSeqEntry->GetKey()
+ << " (at offset : "
+ << newSeqEntry->GetOffset() << " )" );
+ used = false;
+ }
+
+ if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max)
+ {
+ if ( !used )
+ delete newDocEntry;
+ break;
+ }
+ } // end SeqEntry : VR = "SQ"
+
+ if ( !used )
+ {
+ delete newDocEntry;
+ }
+ } // end While