Go to the documentation of this file.00001 #include <creaImageIOWxDumpPanel.h>
00002 #include <creaImageIOSystem.h>
00003 #include <creaImageIOGimmick.h>
00004 #include <boost/algorithm/string.hpp>
00005 #if defined(USE_GDCM)
00006 #include <gdcmGlobal.h>
00007 #include <gdcmDictSet.h>
00008 #include "gdcmFile.h"
00009 #include "gdcmDocument.h"
00010 #include "gdcmFileHelper.h"
00011 #endif
00012
00013 #if defined(USE_GDCM2)
00014 #include "gdcmGlobal.h"
00015 #include "gdcmFile.h"
00016 #include "gdcmDictPrinter.h"
00017 #include "gdcmPrinter.h"
00018 #include "gdcmReader.h"
00019 #include "gdcmSmartPointer.h"
00020 #include "gdcmSequenceOfItems.h"
00021 #endif
00022 #include "icons/save.xpm"
00023
00024 namespace creaImageIO
00025 {
00026
00027 WxDumpPanel::WxDumpPanel(wxWindow *parent, std::string i_filename)
00028 : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
00029 {
00030 int size = 16;
00031 mIcon = new wxImageList(size,size,true);
00032 mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
00033 wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
00034 mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
00035 mToolBar->Realize();
00036 DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
00037 Layout();
00038 Print();
00039 }
00040
00041
00042 WxDumpPanel::~WxDumpPanel(){}
00043
00047 void WxDumpPanel::Print()
00048 {
00049 std::stringstream os;
00050 std::string result = "";
00051 if ( !filename.empty())
00052 {
00053
00054 #if defined(USE_GDCM)
00055 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
00056 f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
00057 f->SetFileName( filename );
00058 f->SetMaxSizeLoadEntry(0xffff);
00059 f->Load();
00060 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
00061 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ |GDCM_NAME_SPACE::LD_NOSHADOW);
00062 fh->SetPrintLevel( 0 );
00063 fh->Print(os);
00064
00065 std::string line;
00066 while(std::getline(os, line))
00067 {
00068 result +=clean(line.c_str());
00069 result += "\n";
00070 }
00071
00072
00073 #endif
00074 #if defined(USE_GDCM2)
00075 gdcm::Reader reader;
00076 reader.SetFileName( filename.c_str() );
00077 if (reader.Read())
00078 {
00079 gdcm::Printer printer;
00080 printer.SetFile ( reader.GetFile() );
00081 printer.SetColor( 0 );
00082 printer.Print( os );
00083 result = os.str();
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00133
00136
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 #endif
00156 DumpText->SetValue(crea::std2wx(result));
00157
00158 }
00159 }
00160
00161
00162 const std::string WxDumpPanel::clean(const std::string &i_line)
00163 {
00164
00165 if (i_line.substr(4,1) == "|")
00166 {
00167 std::string tag;
00168 std::string line;
00169 std:string signification;
00170 std::string value;
00171 std::string resultat;
00172
00173 tag = "(" + i_line.substr(0,9) + ")";
00174 line = i_line.substr(14,i_line.size()-10);
00175 int pos1 = line.find_first_of("[");
00176 int pos2 = line.find_first_of("]");
00177 signification = line.substr(pos1+1, pos2-pos1-1);
00178 line = line.substr(pos2+1);
00179 pos1 = line.find_first_of("[");
00180 pos2 = line.find_first_of("]");
00181 value = line.substr(pos1+1, pos2-pos1-1);
00182 resultat = tag + " " + signification + ": " +value;
00183 return resultat;
00184 }
00185 else
00186 {
00187 return i_line;
00188 }
00189 }
00190
00194 void WxDumpPanel::SaveInfos(wxCommandEvent& event)
00195 {
00196 wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
00197 crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
00198 if (FD->ShowModal()==wxID_OK)
00199 {
00200 wxBusyCursor busy;
00201 std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
00202 ofs.clear();
00203 ofs << crea::wx2std(DumpText->GetValue());;
00204 ofs.close();
00205 }
00206 Close();
00207 }
00208
00211 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
00212 EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)
00213 END_EVENT_TABLE()
00214 }
00215