- return GDCM_UNFOUND;
- }
- return elem->GetVR();
-}
-
-/**
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the value length of a given tag..
- * @param group Group number of the searched tag.
- * @param element Element number of the searched tag.
- * @return Corresponding element length; -2 if not found
- */
-int Document::GetEntryLengthByNumber(uint16_t group, uint16_t element)
-{
- DocEntry* elem = GetDocEntryByNumber(group, element);
- if ( !elem )
- {
- return -2; //magic number
- }
- return elem->GetLength();
-}
-/**
- * \brief Sets the value (string) of the Header Entry (Dicom Element)
- * @param content string value of the Dicom Element
- * @param tagName name of the searched Dicom Element.
- * @return true when found
- */
-bool Document::SetEntryByName( std::string const & content,
- TagName const & tagName)
-{
- DictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( !dictEntry )
- {
- return false;
- }
-
- return SetEntryByNumber(content,dictEntry->GetGroup(),
- dictEntry->GetElement());
-}
-
-/**
- * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
- * through it's (group, element) and modifies it's content with
- * the given value.
- * @param content new value (string) to substitute with
- * @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
- */
-bool Document::SetEntryByNumber(std::string const& content,
- uint16_t group, uint16_t element)
-{
- ValEntry* valEntry = GetValEntryByNumber(group, element);
- if (!valEntry )
- {
- dbg.Verbose(0, "Document::SetEntryByNumber: no corresponding",
- " ValEntry (try promotion first).");
- return false;
- }
- // Non even content must be padded with a space (020H)...
- valEntry->SetValue(content);
- return true;
-}
-
-/**
- * \brief Accesses an existing DocEntry (i.e. a Dicom Element)
- * through it's (group, element) and modifies it's content with
- * the given value.
- * @param content new value (void* -> uint8_t*) to substitute with
- * @param lgth new value length
- * @param group group number of the Dicom Element to modify
- * @param element element number of the Dicom Element to modify
- */
-bool Document::SetEntryByNumber(uint8_t*content, int lgth,
- uint16_t group, uint16_t element)
-{
- (void)lgth; //not used
- TagKey key = DictEntry::TranslateToKey(group, element);
- if ( !TagHT.count(key))
- {
- return false;
- }
-
-/* Hope Binary field length is *never* wrong
- if(lgth%2) // Non even length are padded with a space (020H).
- {
- lgth++;
- //content = content + '\0'; // fing a trick to enlarge a binary field?
- }
-*/
- BinEntry* entry = (BinEntry *)TagHT[key];
- entry->SetBinArea(content);
- entry->SetLength(lgth);
- entry->SetValue(GDCM_BINLOADED);
-
- return true;
-}
-
-/**
- * \brief Gets (from Header) a 'non string' element value
- * (LoadElementValues has already be executed)
- * @param group group number of the Entry
- * @param elem element number of the Entry
- * @return Pointer to the 'non string' area
- */
-void* Document::GetEntryBinAreaByNumber(uint16_t group, uint16_t elem)
-{
- DocEntry* entry = GetDocEntryByNumber(group, elem);
- if (!entry)
- {
- dbg.Verbose(1, "Document::GetDocEntryByNumber: no entry");
- return 0;
- }
- if ( BinEntry* binEntry = dynamic_cast<BinEntry*>(entry) )
- {
- return binEntry->GetBinArea();
- }
-
- return 0;
-}
-
-/**
- * \brief Loads (from disk) the element content
- * when a string is not suitable
- * @param group group number of the Entry
- * @param elem element number of the Entry
- */
-void Document::LoadEntryBinArea(uint16_t group, uint16_t elem)
-{
- // Search the corresponding DocEntry
- DocEntry *docElement = GetDocEntryByNumber(group, elem);
- if ( !docElement )
- return;
-
- BinEntry *binElement = dynamic_cast<BinEntry *>(docElement);
- if( !binElement )
- return;
-
- LoadEntryBinArea(binElement);
-}
-
-/**
- * \brief Loads (from disk) the element content
- * when a string is not suitable
- * @param element Entry whose binArea is going to be loaded
- */
-void Document::LoadEntryBinArea(BinEntry* element)
-{
- if(element->GetBinArea())
- return;
-
- bool openFile = !Fp;
- if(openFile)
- OpenFile();
-
- size_t o =(size_t)element->GetOffset();
- Fp->seekg(o, std::ios::beg);
-
- size_t l = element->GetLength();
- uint8_t* a = new uint8_t[l];
- if( !a )
- {
- dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
- return;
- }
-
- /// \todo check the result
- Fp->read((char*)a, l);
- if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1
- {
- delete[] a;
- return;
- }
-
- element->SetBinArea(a);
-
- if(openFile)
- CloseFile();
-}
-
-/**
- * \brief Sets a 'non string' value to a given Dicom Element
- * @param area area containing the 'non string' value
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return
- */
-/*bool Document::SetEntryBinAreaByNumber(uint8_t* area,
- uint16_t group, uint16_t element)
-{
- DocEntry* currentEntry = GetDocEntryByNumber(group, element);
- if ( !currentEntry )
- {
- return false;
- }
-
- if ( BinEntry* binEntry = dynamic_cast<BinEntry*>(currentEntry) )
- {
- binEntry->SetBinArea( area );
- return true;
- }
-
- return false;
-}*/
-
-/**
- * \brief Update the entries with the shadow dictionary.
- * Only non even entries are analyzed
- */
-void Document::UpdateShaEntries()
-{
- //DictEntry *entry;
- std::string vr;
-
- /// \todo TODO : still any use to explore recursively the whole structure?
-/*
- for(ListTag::iterator it=listEntries.begin();
- it!=listEntries.end();
- ++it)
- {
- // Odd group => from public dictionary
- if((*it)->GetGroup()%2==0)
- continue;
-
- // Peer group => search the corresponding dict entry
- if(RefShaDict)
- entry=RefShaDict->GetDictEntryByNumber((*it)->GetGroup(),(*it)->GetElement());
- else
- entry=NULL;
-
- if((*it)->IsImplicitVR())
- vr="Implicit";
- else
- vr=(*it)->GetVR();
-
- (*it)->SetValue(GetDocEntryUnvalue(*it)); // to go on compiling
- if(entry){
- // Set the new entry and the new value
- (*it)->SetDictEntry(entry);
- CheckDocEntryVR(*it,vr);
-
- (*it)->SetValue(GetDocEntryValue(*it)); // to go on compiling
-