]> Creatis software - gdcm.git/blob - src/gdcmDocEntry.cxx
general commit of (future) new classes.
[gdcm.git] / src / gdcmDocEntry.cxx
1 // gdcmDocEntry.cxx
2 //-----------------------------------------------------------------------------
3 //
4
5 #include "gdcmDocEntry.h"
6 #include "gdcmTS.h"
7 #include "gdcmGlobal.h"
8 #include "gdcmUtil.h"
9
10 #include <iomanip> // for std::ios::left, ...
11
12
13 #define MAX_SIZE_PRINT_ELEMENT_VALUE 64
14
15 //-----------------------------------------------------------------------------
16 // Constructor / Destructor
17 /**
18  * \ingroup gdcmDocEntry
19  * \brief   Constructor from a given gdcmDictEntry
20  * @param   in Pointer to existing dictionary entry
21  */
22 gdcmDocEntry::gdcmDocEntry(gdcmDictEntry* in) {
23    ImplicitVR = false;
24    entry = in;
25 }
26
27 //-----------------------------------------------------------------------------
28 // Print
29 /**
30  * \ingroup gdcmDocEntry
31  * \brief   canonical Printer
32  */
33 void gdcmDocEntry::Print(std::ostream & os) {
34
35 // TODO : (no more chained list ...)
36
37 /*
38    size_t o;
39    unsigned short int g, e;
40    char st[20];
41    TSKey v;
42    std::string d2, vr;
43    gdcmTS * ts = gdcmGlobal::GetTS();
44    std::ostringstream s;
45    guint32 lgth;
46    char greltag[10];  //group element tag
47
48    g  = GetGroup();
49    e  = GetElement();
50    v  = GetValue();
51    o  = GetOffset();
52    vr = GetVR();
53    sprintf(greltag,"%04x|%04x ",g,e);           
54    s << greltag ;
55        
56    d2 = CreateCleanString(v);  // replace non printable characters by '.'
57    if (printLevel>=2) { 
58       s << "lg : ";
59       lgth = GetReadLength(); // ReadLength, as opposed to UsableLength
60       if (lgth == 0xffffffff) {
61          sprintf(st,"x(ffff)");  // I said : "x(ffff)" !
62          s.setf(std::ios::left);
63          s << std::setw(10-strlen(st)) << " ";  
64          s << st << " ";
65          s.setf(std::ios::left);
66          s << std::setw(8) << "-1";      
67       } else {
68          sprintf(st,"x(%x)",lgth);
69          s.setf(std::ios::left);
70          s << std::setw(10-strlen(st)) << " ";  
71          s << st << " ";
72          s.setf(std::ios::left);
73          s << std::setw(8) << lgth; 
74       }
75       s << " Off.: ";
76       sprintf(st,"x(%x)",o); 
77       s << std::setw(10-strlen(st)) << " ";
78       s << st << " ";
79       s << std::setw(8) << o; 
80    }
81
82    s << "[" << vr  << "] ";
83
84    if (printLevel>=1) {      
85       s.setf(std::ios::left);
86       s << std::setw(66-GetName().length()) << " ";
87    }
88     
89    s << "[" << GetName()<< "]";
90
91    if (voidArea != NULL) {
92        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
93          << GetLength() << ") ]";
94    } 
95    
96    else {             
97       if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
98           (printLevel>=3)  || 
99           (d2.find("gdcm::NotLoaded.") < d2.length()) )
100          s << " [" << d2 << "]";
101       else 
102          s << " [gdcm::too long for print (" << GetLength() << ") ]";
103    }
104    
105    // Display the UID value (instead of displaying only the rough code)  
106    if (g == 0x0002) {  // Any more to be displayed ?
107       if ( (e == 0x0010) || (e == 0x0002) )
108          s << "  ==>\t[" << ts->GetValue(v) << "]";
109    } else {
110       if (g == 0x0008) {
111          if ( (e == 0x0016) || (e == 0x1150)  )
112             s << "  ==>\t[" << ts->GetValue(v) << "]";
113       } else {
114          if (g == 0x0004) {
115             if ( (e == 0x1510) || (e == 0x1512)  )
116                s << "  ==>\t[" << ts->GetValue(v) << "]";
117          }     
118       }
119    }
120    //if (e == 0x0000) {        // elem 0x0000 --> group length 
121    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
122       if (v == "4294967295") // to avoid troubles in convertion 
123          sprintf (st," x(ffffffff)");
124       else {
125          if ( GetLength() !=0 )        
126             sprintf(st," x(%x)", atoi(v.c_str()));//FIXME
127          else
128           sprintf(st," "); 
129       }
130       s << st;
131    }
132    s << std::endl;
133    os << s.str();
134    
135    */
136 }
137
138 //-----------------------------------------------------------------------------
139 // Public
140
141 /**
142  * \ingroup gdcmDocEntry
143  * \brief   Gets the full length of the DocEntry (not only value length)
144  */
145 guint32 gdcmDocEntry::GetFullLength(void) {
146    guint32 l;
147    l = GetLength();
148    if ( IsImplicitVR() ) 
149       l = l + 8;  // 2 (gr) + 2 (el) + 4 (lgth) 
150    else    
151       if ( GetVR()=="OB" || GetVR()=="OW" || GetVR()=="SQ" )
152          l = l + 12; // 2 (gr) + 2 (el) + 2 (vr) + 2 (unused) + 4 (lgth)
153       else
154          l = l + 8;  // 2 (gr) + 2 (el) + 2 (vr) + 2 (lgth)
155    return(l);
156 }
157
158 /**
159  * \ingroup gdcmDocEntry
160  * \brief   Copies all the attributes from an other DocEntry 
161  */
162
163 void gdcmDocEntry::Copy (gdcmDocEntry* e) {
164    this->entry        = e->entry;
165    this->UsableLength = e->UsableLength;
166    this->ReadLength   = e->ReadLength;
167    this->ImplicitVR   = e->ImplicitVR;
168    this->Offset       = e->Offset;
169    this->printLevel   = e->printLevel;
170    this->SQDepthLevel = e->SQDepthLevel;      
171 }
172
173 bool gdcmDocEntry::isItemDelimitor() {
174    if ( (GetGroup() == 0xfffe) && (GetElement() == 0xe00d) )
175       return true;
176    else
177       return false;      
178 }
179
180 bool gdcmDocEntry::isSequenceDelimitor() {
181    if (GetGroup() == 0xfffe && GetElement() == 0xe0dd)
182       return true;
183    else
184       return false; 
185 }
186
187 //-----------------------------------------------------------------------------
188 // Protected
189
190
191 //-----------------------------------------------------------------------------
192 // Private
193
194 //-----------------------------------------------------------------------------