]> Creatis software - gdcm.git/blob - gdcmValEntry.cxx
7f9613dccc45a16711a54f466f6ba96e56a80c54
[gdcm.git] / gdcmValEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmValEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/21 04:43:02 $
7   Version:   $Revision: 1.8 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmValEntry.h"
20 #include "gdcmTS.h"
21 #include "gdcmGlobal.h"
22 #include "gdcmUtil.h"
23
24 // CLEAN ME
25 #define MAX_SIZE_PRINT_ELEMENT_VALUE 128
26
27 //-----------------------------------------------------------------------------
28 // Constructor / Destructor
29 /**
30  * \ingroup gdcmValEntry
31  * \brief   Constructor from a given gdcmDictEntry
32  * @param   e Pointer to existing dictionary entry
33  */
34 gdcmValEntry::gdcmValEntry(gdcmDictEntry* e) : gdcmDocEntry(e) {
35    voidArea = NULL; // will be in BinEntry ?
36 }
37
38 /**
39  * \ingroup gdcmValEntry
40  * \brief   Constructor from a given gdcmDocEntry
41  * @param   e Pointer to existing Doc entry
42  */
43 gdcmValEntry::gdcmValEntry(gdcmDocEntry* e) : gdcmDocEntry(e->GetDictEntry()){
44    this->UsableLength = e->GetLength();
45    this->ReadLength   = e->GetReadLength();
46    this->ImplicitVR   = e->IsImplicitVR();
47    this->Offset       = e->GetOffset();
48    this->printLevel   = e->GetPrintLevel();
49    this->SQDepthLevel = e->GetDepthLevel();
50
51    this->voidArea = NULL; // will be in BinEntry ?
52 }
53
54
55 /**
56  * \brief   Canonical destructor.
57  */
58 gdcmValEntry::~gdcmValEntry (void) {
59    if (!voidArea)  // will be in BinEntry
60       free(voidArea);
61 }
62
63
64 //-----------------------------------------------------------------------------
65 // Print
66 /**
67  * \ingroup gdcmValEntry
68  * \brief   canonical Printer
69  */
70 void gdcmValEntry::Print(std::ostream & os) { 
71
72    std::ostringstream s; 
73    //size_t o;  //not used
74    unsigned short int g, e;
75    char st[20];
76    TSKey v;
77    std::string d2, vr;
78      
79    PrintCommonPart(os); 
80
81    g  = GetGroup();
82    
83    if (g == 0xfffe) {
84       s << std::endl;
85       os << s.str(); 
86       return;  // just to avoid identing all the remaining code     
87    }
88    
89    e  = GetElement();
90    vr = GetVR();
91    gdcmTS * ts = gdcmGlobal::GetTS();
92     
93    if (voidArea != NULL) { // should be moved in gdcmBinEntry Printer (when any)
94        s << " [gdcm::Non String Data Loaded in Unsecure Area (" 
95          << GetLength() << ") ]";
96    } 
97    
98    else {
99       v  = GetValue();  // not applicable for SQ ...     
100       d2 = CreateCleanString(v);  // replace non printable characters by '.'            
101       if( (GetLength()<=MAX_SIZE_PRINT_ELEMENT_VALUE) || 
102           (printLevel>=3)  || 
103           (d2.find("gdcm::NotLoaded.") < d2.length()) )
104          s << " [" << d2 << "]";
105       else 
106          s << " [gdcm::too long for print (" << GetLength() << ") ]";
107    }
108    
109    // Display the UID value (instead of displaying only the rough code)  
110    if (g == 0x0002) {  // Any more to be displayed ?
111       if ( (e == 0x0010) || (e == 0x0002) )
112          s << "  ==>\t[" << ts->GetValue(v) << "]";
113    } else {
114       if (g == 0x0008) {
115          if ( (e == 0x0016) || (e == 0x1150)  )
116             s << "  ==>\t[" << ts->GetValue(v) << "]";
117       } else {
118          if (g == 0x0004) {
119             if ( (e == 0x1510) || (e == 0x1512)  )
120                s << "  ==>\t[" << ts->GetValue(v) << "]";
121          }     
122       }
123    }
124    //if (e == 0x0000) {        // elem 0x0000 --> group length 
125    if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") ) {
126       if (v == "4294967295") // to avoid troubles in convertion 
127          sprintf (st," x(ffffffff)");
128       else {
129          if ( GetLength() !=0 )        
130             sprintf(st," x(%x)", atoi(v.c_str()));//FIXME
131          else
132           sprintf(st," "); 
133       }
134       s << st;
135    }
136         
137    s << std::endl;
138    os << s.str();   
139 }
140  
141
142 //-----------------------------------------------------------------------------
143 // Public
144
145 //-----------------------------------------------------------------------------
146 // Protected
147
148 //-----------------------------------------------------------------------------
149 // Private
150
151 //-----------------------------------------------------------------------------