X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmSQItem.cxx;h=ce080c6072c2dc2538d6669691b2ee9cd50ee196;hb=11acea13c5f6b70f1cd3753ccbb92e330df32fcb;hp=8b77a1c26f751e83c3efbb5d1d68e40d8b00bf9a;hpb=0b36f4932e894a1dde4a80e614755816b4b29218;p=gdcm.git diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 8b77a1c2..ce080c60 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -4,6 +4,7 @@ #include "gdcmSQItem.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" +#include "gdcmValEntry.h" //----------------------------------------------------------------------------- @@ -11,14 +12,24 @@ /** * \ingroup gdcmSQItem * \brief Constructor from a given gdcmSQItem - * @param in Pointer to existing dictionary entry */ -gdcmSQItem::gdcmSQItem() : gdcmDocEntry( ) { - - +gdcmSQItem::gdcmSQItem(int depthLevel ) + : gdcmDocEntrySet(depthLevel) { + SQDepthLevel = depthLevel +1; } - +/** + * \brief Canonical destructor. + */ +gdcmSQItem::~gdcmSQItem() +{ + for(ListDocEntry::iterator cc = docEntries.begin(); + cc != docEntries.end(); + ++cc) + { + delete *cc; + } +} //----------------------------------------------------------------------------- @@ -27,15 +38,166 @@ gdcmSQItem::gdcmSQItem() : gdcmDocEntry( ) { * \ingroup gdcmSQItem * \brief canonical Printer */ - + void gdcmSQItem::Print(std::ostream & os) { + std::ostringstream s; + + if (SQDepthLevel>0) { + for (int i=0;iSetPrintLevel(printLevel); //self->GetPrintLevel() ? + (*i)->SetPrintLevel(2); + (*i)->Print(os); + } +} //----------------------------------------------------------------------------- // Public +bool gdcmSQItem::AddEntry(gdcmDocEntry *entry) { + docEntries.push_back(entry); + //TODO : check if it worked + return true; +} + + +/** + * \brief Sets Entry (Dicom Element) value of an element, + * specified by it's tag (Group, Number) + * and the length, too ... inside a SQ Item + * If the Element is not found, it's just created ! + * \warning we suppose, right now, the element belongs to a Public Group + * (NOT a shadow one) + * @param val string value to set + * @param group Group of the searched tag. + * @param element Element of the searched tag. + * @return true if element was found or created successfully + */ + bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group, + guint16 element) { + + for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) { + if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 ) + continue; + if ( group < (*i)->GetGroup() || + (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){ + // instead of ReplaceOrCreateByNumber + // that is a method of gdcmDocument :-( + gdcmDocEntry *Entry; + TagKey key = gdcmDictEntry::TranslateToKey(group, element); + if ( ! ptagHT->count(key)) { + // we assume a Public Dictionnary *is* loaded + gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); + // if the invoked (group,elem) doesn't exist inside the Dictionary + // we create a VirtualDictEntry + gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element); + if (DictEntry == NULL) { + DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??"); + } + // we assume the constructor didn't fail + Entry = new gdcmDocEntry(DictEntry); + /// \todo + /// ---- + /// better we don't assume too much ! + /// gdcmSQItem is now used to describe any DICOMDIR related object + /// + } else { + Entry = ptagHT->find(key)->second; + } + ((gdcmValEntry*)Entry)->SetValue(val); + Entry->SetLength(val.length()); + docEntries.insert(i,Entry); + return true; + } + if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) { + ((gdcmValEntry*)(*i))->SetValue(val); + (*i)->SetLength(val.length()); + return true; + } + } +} //----------------------------------------------------------------------------- // Protected //----------------------------------------------------------------------------- // Private +// end-user intended : the guy *wants* to create his own SeQuence ?!? +gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group, + guint16 element) { +// TODO + gdcmDocEntry *a; + std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <GetDefaultPubDict(); + gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name); + if( dictEntry == NULL) + return NULL; + return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()); +} + +/* + * \ingroup gdcmSQItem + * \brief Gets a Dicom Element inside a SQ Item Entry, by number + * @return + */ +gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) { + for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) { + if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) + return (*i); + } + return NULL; +} + +/* + * \ingroup gdcmSQItem + * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number + * @return + */ + +std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) { + for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) { + if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) { + return ((gdcmValEntry *)(*i))->GetValue(); + } + } + return GDCM_UNFOUND; +} + +/** + * \ingroup gdcmSQItem + * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name + * @param name : name of the searched element. + * @return + */ + +std::string gdcmSQItem::GetEntryByName(TagName name) { + gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict(); + gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name); + + if( dictEntry == NULL) + return GDCM_UNFOUND; + return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()); +} + //-----------------------------------------------------------------------------