1 #include <creaImageIOWxDumpPanel.h>
2 #include <creaImageIOSystem.h>
3 #include <creaImageIOGimmick.h>
5 #include <gdcmGlobal.h>
6 #include <gdcmDictSet.h>
8 #include "gdcmDocument.h"
9 #include "gdcmFileHelper.h"
12 #if defined(USE_GDCM2)
13 #include "gdcmGlobal.h"
15 #include "gdcmDictPrinter.h"
16 #include "gdcmPrinter.h"
17 #include "gdcmReader.h"
19 #include "icons/save.xpm"
24 WxDumpPanel::WxDumpPanel(wxWindow *parent, std::string i_filename)
25 : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
28 mIcon = new wxImageList(size,size,true);
29 mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
30 wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
31 mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
33 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
39 WxDumpPanel::~WxDumpPanel(){}
41 ///////////////////////////////////////////////////
42 /// Display in a control Text all dicom tags
43 ///////////////////////////////////////////////////
44 void WxDumpPanel::Print()
47 std::string result = "";
48 if ( !filename.empty()) // ====== Deal with a single file ======
52 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
53 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
54 f->SetFileName( filename );
55 f->SetMaxSizeLoadEntry(0xffff);
57 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
58 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
59 fh->SetPrintLevel( 0 );
63 while(std::getline(os, line))
65 result +=clean(line.c_str());
71 #if defined(USE_GDCM2)
73 reader.SetFileName( filename.c_str() );
76 gdcm::Printer printer;
77 printer.SetFile ( reader.GetFile() );
78 printer.SetColor( 0 );
83 DumpText->SetValue(crea::std2wx(result));
89 const std::string WxDumpPanel::clean(const std::string &i_line)
92 if (i_line.substr(4,1) == "|")
96 std:string signification;
100 tag = "(" + i_line.substr(0,9) + ")";
101 line = i_line.substr(14,i_line.size()-10);
102 int pos1 = line.find_first_of("[");
103 int pos2 = line.find_first_of("]");
104 signification = line.substr(pos1+1, pos2-pos1-1);
105 line = line.substr(pos2+1);
106 pos1 = line.find_first_of("[");
107 pos2 = line.find_first_of("]");
108 value = line.substr(pos1+1, pos2-pos1-1);
109 resultat = tag + " " + signification + ": " +value;
118 ///////////////////////////////////////////////////
119 /// wxEvent to save Dicom Tags in a text file //
120 ///////////////////////////////////////////////////
121 void WxDumpPanel::SaveInfos(wxCommandEvent& event)
123 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
124 crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
125 if (FD->ShowModal()==wxID_OK)
128 std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
130 ofs << crea::wx2std(DumpText->GetValue());;
136 ////////////////////////////////////////////////////////////
137 ////////////////////////////////////////////////////////////
138 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
139 EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)