]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxSimpleDlg.cpp
5d053226805a45430b51785d2e0af1d1a6e2ecb9
[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_attrDicomTags , m_resultsDicomAtr , 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_attrDicomTags , m_resultsDicomAtr , 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                                 dlg.getSelected(outStrGimmick, m_attrDicomTags,true,"");
150
151                         m_results.clear();
152                         int size=(int)outStrGimmick.size();
153                         int ii;
154 //                      if(!bInfo)
155 //                      {
156                                 for (ii=0;ii<size;ii++)
157                                 {
158                                         m_results.push_back(outStrGimmick[ii].img);
159                                         m_resultsDicomAtr.push_back( outStrGimmick[ii].infos );
160                                 }
161 //                      } else {
162 //                              for (ii=0;ii<size;ii++)
163 //                              {
164 //                                      m_resultsInfo.push_back(outStrGimmick[ii]);
165 //                              }
166 //                      }
167
168                         dlg.OnExit();
169                  }
170                  SetReturnCode( dlg.GetReturnCode() );
171                  EndModal( dlg.GetReturnCode() );
172            }
173
174         wxString WxSimpleDlg::getInfoImage()
175         {
176                 return infoimage;
177         }
178
179  //////////////////////////////////////////////////////////////////////
180 // Return the results vector                                                                            //
181 //////////////////////////////////////////////////////////////////////
182           std::vector<vtkImageData*> WxSimpleDlg::getImagesSelected()
183           {
184                   return m_results;
185           }
186
187         std::vector< std::map<std::string, std::string> >  WxSimpleDlg::getDicomInfoImagesSelected()
188         {
189                 return m_resultsDicomAtr;
190         }
191
192         void WxSimpleDlg::SetAttrDicomTags( std::vector<std::string> attr )
193         {
194                 m_attrDicomTags=attr;
195         }
196           
197
198
199 }
200