2 //-----------------------------------------------------------------------------
3 #include "gdcmDictSet.h"
6 #include <stdlib.h> // For getenv
8 #define PUB_DICT_NAME "DicomV3Dict"
10 # define PUB_DICT_PATH "../Dicts/"
12 #define PUB_DICT_FILENAME "dicomV3.dic"
14 //-----------------------------------------------------------------------------
15 // Constructor / Destructor
17 * \ingroup gdcmDictSet
18 * \brief The Dictionnary Set obtained with this constructor simply
19 * contains the Default Public dictionnary.
21 gdcmDictSet::gdcmDictSet(void)
23 DictPath = BuildDictPath();
24 std::string PubDictFile = DictPath + PUB_DICT_FILENAME;
25 Dicts[PUB_DICT_NAME] = new gdcmDict(PubDictFile);
29 * \ingroup gdcmDictSet
32 gdcmDictSet::~gdcmDictSet()
34 // Remove dictionnaries
35 for (DictSetHT::iterator tag = Dicts.begin(); tag != Dicts.end(); ++tag)
37 gdcmDict *EntryToDelete = tag->second;
44 // Remove virtual dictionnary entries
45 std::map<std::string,gdcmDictEntry *>::iterator it;
46 for(it=virtualEntry.begin(); it!=virtualEntry.end(); ++it)
48 gdcmDictEntry *Entry = it->second;
55 //-----------------------------------------------------------------------------
58 * \ingroup gdcmDictSet
59 * \brief Print, in an informal fashion, the list of all the dictionaries
60 * contained is this gdcmDictSet, along with their respective content.
61 * @param os Output stream used for printing.
63 void gdcmDictSet::Print(std::ostream& os)
65 for (DictSetHT::iterator dict = Dicts.begin(); dict != Dicts.end(); ++dict)
67 os << "Printing dictionary " << dict->first << std::endl;
68 dict->second->Print(os);
72 //-----------------------------------------------------------------------------
75 * \ingroup gdcmDictSet
76 * \brief Consider all the entries of the public dicom dictionnary.
77 * Build all list of all the tag names of all those entries.
78 * \sa gdcmDictSet::GetPubDictTagNamesByCategory
79 * @return A list of all entries of the public dicom dictionnary.
81 std::list<std::string> *gdcmDictSet::GetPubDictEntryNames(void)
83 return(GetDefaultPubDict()->GetDictEntryNames());
87 * \ingroup gdcmDictSet
88 * \brief Consider all the entries of the public dicom dictionnary.
89 * Build an hashtable whose keys are the names of the groups
90 * (fourth field in each line of dictionary) and whose corresponding
91 * values are lists of all the dictionnary entries among that
92 * group. Note that apparently the Dicom standard doesn't explicitely
93 * define a name (as a string) for each group.
94 * A typical usage of this method would be to enable a dynamic
95 * configuration of a Dicom file browser: the admin/user can
96 * select in the interface which Dicom tags should be displayed.
97 * \warning Dicom *doesn't* define any name for any 'categorie'
98 * (the dictionnary fourth field was formerly NIH defined
99 * - and no longer he is-
100 * and will be removed when Dicom provides us a text file
101 * with the 'official' Dictionnary, that would be more friendly
102 * than asking us to perform a line by line check of the dictionnary
103 * at the beginning of each year to -try to- guess the changes)
104 * Therefore : please NEVER use that fourth field :-(
106 * @return An hashtable: whose keys are the names of the groups and whose
107 * corresponding values are lists of all the dictionnary entries
110 std::map<std::string, std::list<std::string> > *gdcmDictSet::GetPubDictEntryNamesByCategory(void)
112 return(GetDefaultPubDict()->GetDictEntryNamesByCategory());
116 * \ingroup gdcmDictSet
117 * \brief Loads a dictionary from a specified file, and add it
118 * to already the existing ones contained in this gdcmDictSet.
119 * @param FileName Absolute or relative filename containing the
120 * dictionary to load.
121 * @param Name Symbolic name that be used as identifier of the newly
122 * created dictionary.
124 gdcmDict *gdcmDictSet::LoadDictFromFile(std::string FileName, DictKey Name)
126 gdcmDict *NewDict = new gdcmDict(FileName);
127 AppendDict(NewDict,Name);
132 * \ingroup gdcmDictSet
133 * \brief Retrieve the specified dictionary (when existing) from this
135 * @param DictName The symbolic name of the searched dictionary.
136 * \result The retrieved dictionary.
138 gdcmDict *gdcmDictSet::GetDict(DictKey DictName)
140 DictSetHT::iterator dict = Dicts.find(DictName);
141 if(dict!=Dicts.end())
147 * \ingroup gdcmDictSet
148 * \brief Retrieve the default reference DICOM V3 public dictionary.
149 * \result The retrieved default dictionary.
151 gdcmDict *gdcmDictSet::GetDefaultPubDict()
153 return GetDict(PUB_DICT_NAME);
157 * \ingroup gdcmDictSet
158 * \brief Create a gdcmDictEntry which will be reference
160 * @return virtual entry
162 gdcmDictEntry *gdcmDictSet::NewVirtualDictEntry(guint16 group, guint16 element,
163 std::string vr,std::string fourth,
166 gdcmDictEntry *entry;
167 std::string tag=gdcmDictEntry::TranslateToKey(group,element)+"#"+vr+"#"+fourth+"#"+name;
168 std::map<std::string,gdcmDictEntry *>::iterator it;
170 it=virtualEntry.find(tag);
171 if(it!=virtualEntry.end())
177 entry=new gdcmDictEntry(group,element,vr,fourth,name);
178 virtualEntry[tag]=entry;
184 * \ingroup gdcmDictSet
185 * \brief Obtain from the GDCM_DICT_PATH environnement variable the
186 * path to directory containing the dictionnaries. When
187 * the environnement variable is absent the path is defaulted
189 * @return path to directory containing the dictionnaries
191 std::string gdcmDictSet::BuildDictPath(void)
193 std::string ResultPath;
194 const char *EnvPath = (char*)0;
195 EnvPath = getenv("GDCM_DICT_PATH");
196 if (EnvPath && (strlen(EnvPath) != 0))
198 ResultPath = EnvPath;
199 if (ResultPath[ResultPath.length() -1] != '/' )
201 dbg.Verbose(1, "gdcmDictSet::BuildDictPath:",
202 "Dictionary path set from environnement");
205 ResultPath = PUB_DICT_PATH;
209 //-----------------------------------------------------------------------------
211 bool gdcmDictSet::AppendDict(gdcmDict *NewDict,DictKey Name)
213 Dicts[Name] = NewDict;
217 //-----------------------------------------------------------------------------
220 //-----------------------------------------------------------------------------