]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxSimpleDlg.cpp
2188 creaImageIO Feature New Normal ImagesChooserDialog Box return DICOM tags maps
[creaImageIO.git] / src / creaImageIOWxSimpleDlg.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28 #include "creaImageIOWxSimpleDlg.h"
29
30
31 namespace creaImageIO
32 {
33
34
35         ///Ctor
36    WxSimpleDlg::WxSimpleDlg(wxWindow *parent, 
37                             wxString i_title,  
38                             const std::string i_namedescp , 
39                             const std::string i_namedb)
40     : wxDialog(parent, -1,_T("SELECT IMAGE(S)"), wxDefaultPosition, wxSize(230,150))
41    {
42                 namedescp       = i_namedescp; 
43                 namedb          = i_namedb;
44
45            if(!i_title.empty())
46            {
47                         this->SetTitle(i_title);  
48            }
49            // Button to select file(s)
50            wxButton *fileBut = new wxButton(this, -1,_T("Select a single file"), wxPoint(10,7) );
51            Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadFile ); 
52
53            // Button to select directory
54            wxButton *directoryBut = new wxButton(this, -1,_T("Select all the files in a directory"), wxPoint(10,40) );
55            Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadDirectory ); 
56
57            // button to select creaImageIO
58            wxButton *gimmickBut = new wxButton(this, -1,_T("Select thru Dicom browser"), wxPoint(10,70) );
59            Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadGimmick ); 
60
61            /// \TODO  Button to select Bruker directory
62            bInfo = false;
63         Layout(); 
64         
65         }
66 //////////////////////////////////////////////////////////////////////
67 //                                                                  //
68 //////////////////////////////////////////////////////////////////////
69           void WxSimpleDlg::OnReadFile(wxCommandEvent& event)
70           {
71                   int resultShowModal;
72                   wxFileDialog* fileDlg = new wxFileDialog( 0,  _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition);
73     
74                     resultShowModal = fileDlg->ShowModal();
75                         if ( resultShowModal==wxID_OK )
76                         {
77                                 wxArrayString wxArray;
78                                 fileDlg->GetPaths(wxArray);
79                                 if(wxArray.size() >0)
80                                 {
81                                         m_results.clear();
82                                         infoimage=_T("FILE(s):")+wxArray[0];
83                                         std::vector<std::string> files;
84                                         for( int i = 0; i < wxArray.GetCount(); i++)
85                                         {
86                                                 files.push_back( crea::wx2std(wxArray[i]));
87                                         }
88                                         if(!m_view.readFile(files,m_results))
89                                         {
90                                                 //TO DO WARNING MESSAGE;
91                                         }
92                                 } else {
93                                         // TO DO WARNING MESSAGES
94                                 }
95                         }
96                   SetReturnCode( resultShowModal );
97 //               Close();
98                  EndModal( resultShowModal );
99           }
100
101  //////////////////////////////////////////////////////////////////////
102 //                                                                                                                                      //
103 //////////////////////////////////////////////////////////////////////
104
105           void WxSimpleDlg::OnReadDirectory(wxCommandEvent &event)
106           {
107                   int resultShowModal;
108              long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
109                  wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style);
110                  
111                  resultShowModal = dirDlg->ShowModal();
112                  if ( resultShowModal==wxID_OK )
113                  {  
114                          m_results.clear();
115                         infoimage=_T("DIRECTORY:")+dirDlg->GetPath();
116                         if(! m_view.readDirectory(crea::wx2std(dirDlg->GetPath()),m_results))
117                         {
118                                 //TO DO WARNING MESSAGE;
119                         }
120                  }
121                  SetReturnCode( resultShowModal );
122 //               Close();
123                  EndModal( resultShowModal );
124           }
125
126           //////////////////////////////////////////////////////////////////////
127 //                                                                                                                                      //
128 //////////////////////////////////////////////////////////////////////
129
130           void WxSimpleDlg::OnReadGimmick(wxCommandEvent &event)
131           {
132                   // Run Gimmick
133                    WxGimmickReaderDialog dlg(0,-1, 
134                                    namedescp,
135                                    namedb, 
136                                    _T("Select image(s)        - Gimmick! (c) CREATIS-LRMN 2008"),
137                    wxDefaultPosition,
138                    wxSize(810,750),
139                    GIMMICK_2D_IMAGE_SELECTION,
140                    GIMMICK_3D_IMAGE_SELECTION,
141                    _3D,
142                                    1);
143                  dlg.ShowModal();
144                  if (dlg.GetReturnCode() == wxID_OK)
145              {
146                                 dlg.stopReading();
147
148                                 std::vector<creaImageIO::OutStrGimmick> outStrGimmick;
149                                 std::vector<std::string>                attrDicomTags;
150
151                                    attrDicomTags.push_back("D0028_0010");
152                                    attrDicomTags.push_back("D0008_0023");
153                                    attrDicomTags.push_back("D0008_1070");
154                                    attrDicomTags.push_back("D0019_100e");
155
156                                 dlg.getSelected(outStrGimmick, attrDicomTags,true,"");
157
158                         m_results.clear();
159                         int size=(int)outStrGimmick.size();
160                         int ii;
161 //                      if(!bInfo)
162 //                      {
163                                 for (ii=0;ii<size;ii++)
164                                 {
165                                         m_results.push_back(outStrGimmick[ii].img);
166                                         printf("EED WxSimpleDlg::OnReadGimmick D0028_0010 %s\n", outStrGimmick[ii].infos.find("D0028_0010")->second.c_str() );
167                                         printf("EED WxSimpleDlg::OnReadGimmick D0008_0023 %s\n", outStrGimmick[ii].infos.find("D0008_0023")->second.c_str() );
168                                         printf("EED WxSimpleDlg::OnReadGimmick D0008_1070 %s\n", outStrGimmick[ii].infos.find("D0008_1070")->second.c_str() );
169                                         printf("EED WxSimpleDlg::OnReadGimmick D0019_100e %s\n", outStrGimmick[ii].infos.find("D0019_100e")->second.c_str() );
170                                         m_resultsDicomAtr.push_back( outStrGimmick[ii].infos );
171                                 }
172 //                      } else {
173 //                              for (ii=0;ii<size;ii++)
174 //                              {
175 //                                      m_resultsInfo.push_back(outStrGimmick[ii]);
176 //                              }
177 //                      }
178
179                         dlg.OnExit();
180                  }
181                  SetReturnCode( dlg.GetReturnCode() );
182                  EndModal( dlg.GetReturnCode() );
183            }
184
185         wxString WxSimpleDlg::getInfoImage()
186         {
187                 return infoimage;
188         }
189
190  //////////////////////////////////////////////////////////////////////
191 // Return the results vector                                                                            //
192 //////////////////////////////////////////////////////////////////////
193           std::vector<vtkImageData*> WxSimpleDlg::getImagesSelected()
194           {
195                   return m_results;
196           }
197
198         std::vector< std::map<std::string, std::string> >  WxSimpleDlg::getDicomInfoImagesSelected()
199         {
200                 return m_resultsDicomAtr;
201         }
202
203           
204 }
205