]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxDumpPanel.cpp
\ No newline at end of file
[creaImageIO.git] / src2 / creaImageIOWxDumpPanel.cpp
1 #include <creaImageIOWxDumpPanel.h>
2 #include <creaImageIOSystem.h>
3 #include <creaImageIOGimmick.h>
4 #include <gdcmGlobal.h>
5 #include <gdcmDictSet.h>
6 #include "gdcmFile.h"
7 #include "gdcmDocument.h"
8 #include "gdcmFileHelper.h"
9 #include "icons/save.xpm"
10
11 namespace creaImageIO
12 {
13         // CTor
14    WxDumpPanel::WxDumpPanel(wxWindow *parent,  std::string i_filename)
15     : wxDialog(parent, -1,_T("DICOM TAGS"), wxDefaultPosition, wxSize(550,580)), filename(i_filename)
16    {
17         int size = 16;
18         mIcon = new wxImageList(size,size,true);
19         mIcon->Add(wxBitmap(wxBitmap(wxIcon(save_xpm)).ConvertToImage().Rescale(size, size)));
20         wxToolBar *mToolBar = new wxToolBar(this,-1,wxDefaultPosition,wxDefaultSize);
21         mToolBar->AddTool( DUMP_SAVE_ID,_T("Save"), mIcon->GetBitmap(0), _T("Save Dicom Tags in text file"));
22         mToolBar->Realize();
23         DumpText = new wxTextCtrl( this, wxID_ANY,_T(""), wxPoint(5,30), wxSize(520,510), wxTE_READONLY| wxMac | wxTE_MULTILINE | wxTE_RICH );
24         Layout(); 
25         Print();
26         }
27
28         // DTor
29         WxDumpPanel::~WxDumpPanel(){}
30
31         ///////////////////////////////////////////////////
32         /// Display in a control Text all dicom tags
33         ///////////////////////////////////////////////////
34         void WxDumpPanel::Print()
35         {
36            std::stringstream os;
37            if ( !filename.empty()) // ====== Deal with a single file ======
38            {
39                    GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
40                    f->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);
41                    f->SetFileName( filename );
42                    f->SetMaxSizeLoadEntry(0xffff);
43                    f->Load();
44                    GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
45                    fh->SetPrintLevel( 0 );
46                    fh->Print(os);
47                    std::string result;
48                    std::string line;
49                    while(std::getline(os, line))
50                    {
51                           result +=line;
52                           result += "\n";
53                    }
54                    DumpText->SetValue(crea::std2wx(result));
55                 }
56         }
57
58 ///////////////////////////////////////////////////     
59 /// wxEvent to save Dicom Tags in a text file    //
60 ///////////////////////////////////////////////////
61         void WxDumpPanel::SaveInfos(wxCommandEvent& event)
62         {
63         wxFileDialog* FD = new wxFileDialog( 0,_T("Select file"), _T(""), _T(""),
64                                                crea::std2wx("*.txt"), wxOPEN, wxDefaultPosition);
65         if (FD->ShowModal()==wxID_OK)
66                 {
67                         wxBusyCursor busy;
68                         std::ofstream ofs(crea::wx2std(FD->GetPath()).c_str());
69                         ofs.clear();
70                         ofs << crea::wx2std(DumpText->GetValue());;
71                         ofs.close();
72                 }
73                 Close();
74         }
75
76 ////////////////////////////////////////////////////////////
77 ////////////////////////////////////////////////////////////
78 BEGIN_EVENT_TABLE(WxDumpPanel, wxDialog)
79     EVT_TOOL(DUMP_SAVE_ID, WxDumpPanel::SaveInfos)
80 END_EVENT_TABLE()
81 }
82