- delete *cc;
- }
- Patients.clear();
-}
-
-/**
- * \brief adds to the HTable
- * the Entries (Dicom Elements) corresponding to the given type
- * @param path full path file name (only used when type = GDCM_DICOMDIR_IMAGE
- * @param type DicomDirObject type to create (GDCM_DICOMDIR_PATIENT,
- * GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
- * @param header Header of the current file
- */
-void DicomDir::SetElement(std::string const &path, DicomDirType type,
- Document *header)
-{
- ListDicomDirElem elemList; //FIXME this is going to be a by copy operation
- ListDicomDirElem::const_iterator it;
- uint16_t tmpGr, tmpEl;
- DictEntry *dictEntry;
- ValEntry *entry;
- std::string val;
- SQItem *si;
-
- switch( type )
- {
- case GDCM_DICOMDIR_IMAGE:
- elemList = Global::GetDicomDirElements()->GetDicomDirImageElements();
- si = new DicomDirImage(true);
- if( !AddImageToEnd(static_cast<DicomDirImage *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add ImageToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_SERIE:
- elemList = Global::GetDicomDirElements()->GetDicomDirSerieElements();
- si = new DicomDirSerie(true);
- if( !AddSerieToEnd(static_cast<DicomDirSerie *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add SerieToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_STUDY:
- elemList = Global::GetDicomDirElements()->GetDicomDirStudyElements();
- si = new DicomDirStudy(true);
- if( !AddStudyToEnd(static_cast<DicomDirStudy *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add StudyToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_PATIENT:
- elemList = Global::GetDicomDirElements()->GetDicomDirPatientElements();
- si = new DicomDirPatient(true);
- if( !AddPatientToEnd(static_cast<DicomDirPatient *>(si)) )
- {
- delete si;
- gdcmErrorMacro( "Add PatientToEnd failed");
- }
- break;
- case GDCM_DICOMDIR_META:
- elemList = Global::GetDicomDirElements()->GetDicomDirMetaElements();
- si = new DicomDirMeta(true);
- if( MetaElems )
- {
- delete MetaElems;
- gdcmErrorMacro( "MetaElements already exist, they will be destroyed");
- }
- MetaElems = static_cast<DicomDirMeta *>(si);
- break;
- default:
- return;
- }
- // removed all the seems-to-be-useless stuff about Referenced Image Sequence
- // to avoid further troubles
- // imageElem 0008 1140 "" // Referenced Image Sequence
- // imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later
- // imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later
- // imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later
- // imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later
- // for all the relevant elements found in their own spot of the DicomDir.dic
- // FIXME : troubles found when it's a SeqEntry
-
- for( it = elemList.begin(); it != elemList.end(); ++it)
- {
- tmpGr = it->Group;
- tmpEl = it->Elem;
- dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl);
-
- entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry !
-
- entry->SetOffset(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->GetEntryValue(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 )
- {
- gdcmVerboseMacro( "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->GetEntryLength(tmpGr,tmpEl) == 0 )
- val = it->Value;
- }
-
- entry->SetValue( val ); // troubles expected when vr=SQ ...
-
- if ( type == GDCM_DICOMDIR_META ) // fusible : should never print !
- {
- gdcmVerboseMacro("GDCM_DICOMDIR_META ?!? should never print that");
- }
- si->AddEntry(entry);
- }
-}
-
-//-----------------------------------------------------------------------------
-/**
- * \brief CallStartMethod
- */
-void DicomDir::CallStartMethod()
-{
- Progress = 0.0f;
- Abort = false;
- if( StartMethod )
- {
- StartMethod( StartArg );
- }
-}
-
-//-----------------------------------------------------------------------------
-/**
- * \brief CallProgressMethod
- */
-void DicomDir::CallProgressMethod()
-{
- if( ProgressMethod )
- {
- ProgressMethod( ProgressArg );
- }
-}
-
-//-----------------------------------------------------------------------------
-/**
- * \brief CallEndMethod
- */
-void DicomDir::CallEndMethod()
-{
- Progress = 1.0f;
- if( EndMethod )
- {
- 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 list is 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 (0x0004,0x1220)");
- /// \todo FIXME: what to do when the parsed file IS NOT a DICOMDIR file ?
- return;