1 /*=========================================================================
4 Module: $RCSfile: gdcmSQItem.cxx,v $
6 Date: $Date: 2004/06/19 23:51:04 $
7 Version: $Revision: 1.10 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmSQItem.h"
20 #include "gdcmSeqEntry.h"
21 #include "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmGlobal.h"
25 #include "gdcmDebug.h"
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
31 * \brief Constructor from a given gdcmSQItem
33 gdcmSQItem::gdcmSQItem(int depthLevel )
34 : gdcmDocEntrySet(depthLevel) {
35 SQDepthLevel = depthLevel +1;
39 * \brief Canonical destructor.
41 gdcmSQItem::~gdcmSQItem()
43 for(ListDocEntry::iterator cc = docEntries.begin();
44 cc != docEntries.end();
52 //-----------------------------------------------------------------------------
55 * \brief canonical Printer
57 void gdcmSQItem::Print(std::ostream & os) {
61 for (int i=0;i<SQDepthLevel;i++)
64 std::cout << s.str() << "SQItemNumber " << SQItemNumber << std::endl;
65 for (ListDocEntry::iterator i = docEntries.begin();
66 i != docEntries.end();
70 //(*i)->SetPrintLevel(printLevel); //self->GetPrintLevel() ?
71 (*i)->SetPrintLevel(2);
76 //-----------------------------------------------------------------------------
79 * \brief adds any Entry (Dicom Element) to the Sequence Item
81 bool gdcmSQItem::AddEntry(gdcmDocEntry *entry)
83 docEntries.push_back(entry);
84 //TODO : check if it worked
89 * \brief Sets Entry (Dicom Element) value of an element,
90 * specified by it's tag (Group, Number)
91 * and the length, too ... inside a SQ Item
92 * If the Element is not found, it's just created !
93 * \warning we suppose, right now, the element belongs to a Public Group
95 * @param val string value to set
96 * @param group Group of the searched tag.
97 * @param element Element of the searched tag.
98 * @return true if element was found or created successfully
100 bool gdcmSQItem::SetEntryByNumber(std::string val,guint16 group,
103 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i)
105 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
107 if ( ( group < (*i)->GetGroup() )
108 ||( group == (*i)->GetGroup() && element < (*i)->GetElement()) )
110 // instead of ReplaceOrCreateByNumber
111 // that is a method of gdcmDocument :-(
112 gdcmValEntry* Entry = (gdcmValEntry*)0;
113 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
114 if ( ! ptagHT->count(key))
116 // we assume a Public Dictionnary *is* loaded
117 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
118 // if the invoked (group,elem) doesn't exist inside the Dictionary
119 // we create a VirtualDictEntry
120 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group,
122 if (DictEntry == NULL)
124 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,
129 // we assume the constructor didn't fail
130 Entry = new gdcmValEntry(DictEntry);
133 /// better we don't assume too much !
134 /// gdcmSQItem is now used to describe any DICOMDIR related object
136 gdcmDocEntry* FoundEntry = ptagHT->find(key)->second;
137 Entry = dynamic_cast<gdcmValEntry*>(FoundEntry);
139 dbg.Verbose(0, "gdcmSQItem::SetEntryByNumber: docEntries"
140 " contains non gdcmValEntry occurences");
143 Entry->SetValue(val);
144 Entry->SetLength(val.length());
145 docEntries.insert(i,Entry);
148 if (group == (*i)->GetGroup() && element == (*i)->GetElement() )
150 if ( gdcmValEntry* Entry = dynamic_cast<gdcmValEntry*>(*i) )
151 Entry->SetValue(val);
152 (*i)->SetLength(val.length());
157 //-----------------------------------------------------------------------------
160 //-----------------------------------------------------------------------------
163 // end-user intended : the guy *wants* to create his own SeQuence ?!?
165 /// \brief to be written if really usefull
166 gdcmDocEntry *gdcmSQItem::NewDocEntryByNumber(guint16 group,
170 std::cout << " gdcmSQItem::NewDocEntryByNumber : TODO" <<std::endl;
174 /// \brief to be written if really usefull
175 gdcmDocEntry *gdcmSQItem::NewDocEntryByName (std::string Name) {
178 std::cout << " gdcmSQItem::NewDocEntryByName : TODO" <<std::endl;
183 * \brief Gets a Dicom Element inside a SQ Item Entry, by name
186 gdcmDocEntry *gdcmSQItem::GetDocEntryByName(std::string name) {
187 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
188 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
189 if( dictEntry == NULL)
191 return GetDocEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
195 * \ingroup gdcmSQItem
196 * \brief Gets a Dicom Element inside a SQ Item Entry, by number
199 gdcmDocEntry *gdcmSQItem::GetDocEntryByNumber(guint16 group, guint16 element) {
200 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
201 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
208 * \ingroup gdcmSQItem
209 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by number
213 std::string gdcmSQItem::GetEntryByNumber(guint16 group, guint16 element) {
214 for(ListDocEntry::iterator i=docEntries.begin();i!=docEntries.end();++i) {
215 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element) {
216 return ((gdcmValEntry *)(*i))->GetValue();
223 * \ingroup gdcmSQItem
224 * \brief Get the value of a Dicom Element inside a SQ Item Entry, by name
225 * @param name : name of the searched element.
229 std::string gdcmSQItem::GetEntryByName(TagName name) {
230 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
231 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
233 if( dictEntry == NULL)
235 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
238 //-----------------------------------------------------------------------------