]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxDumpPanel.cpp
Set GDCM2 library as available DICOM Reader
[creaImageIO.git] / src2 / creaImageIOWxDumpPanel.cpp
1 #include <creaImageIOWxDumpPanel.h>
2 #include <creaImageIOSystem.h>
3 #include <creaImageIOGimmick.h>
4 #if defined(USE_GDCM)
5 #include <gdcmGlobal.h>
6 #include <gdcmDictSet.h>
7 #include "gdcmFile.h"
8 #include "gdcmDocument.h"
9 #include "gdcmFileHelper.h"
10 #endif
11 #include "icons/save.xpm"
12
13 namespace creaImageIO
14 {
15         // CTor
16    WxDumpPanel::WxDumpPanel(wxWindow *parent,  std::string i_filename)
17     : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
18    {
19         int size = 16;
20         mIcon = new wxImageList(size,size,true);
21         mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
22         wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
23         mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
24         mToolBar->Realize();
25         DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
26         Layout(); 
27         Print();
28         }
29
30         // DTor
31         WxDumpPanel::~WxDumpPanel(){}
32
33         ///////////////////////////////////////////////////
34         /// Display in a control Text all dicom tags
35         ///////////////////////////////////////////////////
36         void WxDumpPanel::Print()
37         {
38            std::stringstream os;
39            if ( !filename.empty()) // ====== Deal with a single file ======
40            {
41         /*         GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
42                    f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
43                    f->SetFileName( filename );
44                    f->SetMaxSizeLoadEntry(0xffff);
45                    f->Load();
46                    GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
47                       f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW); 
48                    fh->SetPrintLevel( 0 );
49                    fh->Print(os);
50                    std::string result;
51                    std::string line;
52                    while(std::getline(os, line))
53                    {
54                           result +=clean(line.c_str());
55                           result += "\n";
56                    }
57                    DumpText->SetValue(crea::std2wx(result));
58                 
59                    std::string pixelType =f->GetPixelType();
60                         int nX,nY,nZ,nT,sPP,planarConfig;
61     
62       nX=f->GetXSize();
63       nY=f->GetYSize();
64       nZ=f->GetZSize();
65       nT=f->GetTSize();*/
66                 }
67         }
68
69
70         const std::string WxDumpPanel::clean(const std::string &i_line)
71         {
72                 
73                   if (i_line.substr(4,1) == "|")
74                            {
75                                    std::string tag;
76                                    std::string line;
77                                    std:string signification;
78                                    std::string value;
79                                    std::string resultat;
80
81                                    tag = "(" + i_line.substr(0,9) + ")";
82                                    line = i_line.substr(14,i_line.size()-10);
83                                    int pos1 = line.find_first_of("[");
84                                    int pos2 = line.find_first_of("]");
85                                    signification = line.substr(pos1+1, pos2-pos1-1);
86                                    line = line.substr(pos2+1);
87                                     pos1 = line.find_first_of("[");
88                                     pos2 = line.find_first_of("]");
89                                    value = line.substr(pos1+1, pos2-pos1-1);
90                                    resultat = tag + " " + signification + ": " +value;
91                                   return resultat;
92                            }
93                    else
94                    {
95                            return i_line;
96                    }
97         }
98
99 ///////////////////////////////////////////////////     
100 /// wxEvent to save Dicom Tags in a text file    //
101 ///////////////////////////////////////////////////
102         void WxDumpPanel::SaveInfos(wxCommandEvent& event)
103         {
104         wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
105                                                crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
106         if (FD->ShowModal()==wxID_OK)
107                 {
108                         wxBusyCursor busy;
109                         std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
110                         ofs.clear();
111                         ofs << crea::wx2std(DumpText->GetValue());;
112                         ofs.close();
113                 }
114                 Close();
115         }
116
117 ////////////////////////////////////////////////////////////
118 ////////////////////////////////////////////////////////////
119 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
120     EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)
121 END_EVENT_TABLE()
122 }
123