+ EndMethod( EndArg );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Private
+/**
+ * \brief Sets all fields to NULL
+ */
+void DicomDir::Initialize()
+{
+ StartMethod = NULL;
+ ProgressMethod = NULL;
+ EndMethod = NULL;
+ StartMethodArgDelete = NULL;
+ ProgressMethodArgDelete = NULL;
+ EndMethodArgDelete = NULL;
+ StartArg = NULL;
+ ProgressArg = NULL;
+ EndArg = NULL;
+
+ Progress = 0.0;
+ Abort = false;
+
+ MetaElems = NULL;
+}
+
+/**
+ * \brief create a 'DicomDir' from a DICOMDIR Header
+ */
+void DicomDir::CreateDicomDir()
+{
+ // The SeqEntries of "Directory Record Sequence" are parsed.
+ // When a DicomDir tag ("PATIENT", "STUDY", "SERIE", "IMAGE") is found :
+ // 1 - we save the beginning iterator
+ // 2 - we continue to parse
+ // 3 - we find an other tag
+ // + we create the object for the precedent tag
+ // + loop to 1 -
+
+ // Directory record sequence
+ DocEntry *e = GetDocEntry(0x0004, 0x1220);
+ if ( !e )
+ {
+ gdcmVerboseMacro( "No Directory Record Sequence (0004,1220) found");
+ /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
+ return;
+ }
+
+ SeqEntry *s = dynamic_cast<SeqEntry *>(e);
+ if ( !s )
+ {
+ gdcmVerboseMacro( "Element (0004,1220) is not a Sequence ?!?");
+ return;
+ }
+
+ NewMeta();
+
+ DocEntry *d;
+ std::string v;
+ SQItem *si;
+
+ SQItem *tmpSI=s->GetFirstSQItem();
+ while(tmpSI)
+ {
+ d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type
+ if ( ValEntry* valEntry = dynamic_cast<ValEntry *>(d) )
+ {
+ v = valEntry->GetValue();
+ }
+ else
+ {
+ gdcmVerboseMacro( "Not a ValEntry.");
+ continue;
+ }
+
+ if( v == "PATIENT " )
+ {
+ si = new DicomDirPatient(true);
+ if( !AddPatientToEnd( static_cast<DicomDirPatient *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add PatientToEnd failed");
+ }
+ }
+ else if( v == "STUDY " )
+ {
+ si = new DicomDirStudy(true);
+ if( !AddStudyToEnd( static_cast<DicomDirStudy *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddStudyToEnd failed");
+ }
+ }
+ else if( v == "SERIES" )
+ {
+ si = new DicomDirSerie(true);
+ if( !AddSerieToEnd( static_cast<DicomDirSerie *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddSerieToEnd failed");
+ }
+ }
+ else if( v == "IMAGE " )
+ {
+ si = new DicomDirImage(true);
+ if( !AddImageToEnd( static_cast<DicomDirImage *>(si)) )
+ {
+ delete si;
+ si = NULL;
+ gdcmErrorMacro( "Add AddImageToEnd failed");
+ }
+ }
+ else
+ {
+ // It was not a 'PATIENT', nor a 'STUDY', nor a 'SERIE',
+ // neither an 'IMAGE' SQItem. Skip to next item.
+ continue;
+ }
+ if( si )
+ MoveSQItem(si,tmpSI);
+
+ tmpSI=s->GetNextSQItem();
+ }
+ ClearEntry();
+}
+
+/**
+ * \brief AddPatientToEnd
+ * @param dd SQ Item to enqueue to the DicomPatient chained List
+ */
+bool DicomDir::AddPatientToEnd(DicomDirPatient *dd)
+{
+ Patients.push_back(dd);
+ return true;
+}
+
+/**
+ * \brief AddStudyToEnd
+ * @param dd SQ Item to enqueue to the DicomDirStudy chained List
+ */
+bool DicomDir::AddStudyToEnd(DicomDirStudy *dd)
+{
+ if( Patients.size() > 0 )
+ {
+ ListDicomDirPatient::iterator itp = Patients.end();