creaImageIO_lib
creaImageIOWxSimpleDlg.cpp
Go to the documentation of this file.
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 
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 
62  bInfo = false;
63  Layout();
64 
65  }
67 // //
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 printf("EED WxSimpleDlg::OnReadFile 1 \n");
75  resultShowModal = fileDlg->ShowModal();
76  if ( resultShowModal==wxID_OK )
77  {
78 printf("EED WxSimpleDlg::OnReadFile 2 \n");
79  wxArrayString wxArray;
80  fileDlg->GetPaths(wxArray);
81  if(wxArray.size() >0)
82  {
83 printf("EED WxSimpleDlg::OnReadFile 3 \n");
84  m_results.clear();
85  infoimage=_T("FILE(s):")+wxArray[0];
86  std::vector<std::string> files;
87  for( int i = 0; i < wxArray.GetCount(); i++)
88  {
89 printf("EED WxSimpleDlg::OnReadFile 4 \n");
90  files.push_back( crea::wx2std(wxArray[i]));
91  }
92  if(!m_view.readFile(files,m_results))
93  {
94  //TO DO WARNING MESSAGE;
95  }
96  } else {
97 printf("EED WxSimpleDlg::OnReadFile 5 \n");
98  // TO DO WARNING MESSAGES
99  }
100  }
101  SetReturnCode( resultShowModal );
102 // Close();
103  EndModal( resultShowModal );
104  }
105 
107 // //
109 
110  void WxSimpleDlg::OnReadDirectory(wxCommandEvent &event)
111  {
112  int resultShowModal;
113  long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
114  wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style);
115 
116  resultShowModal = dirDlg->ShowModal();
117  if ( resultShowModal==wxID_OK )
118  {
119  m_results.clear();
120  infoimage=_T("DIRECTORY:")+dirDlg->GetPath();
121  if(! m_view.readDirectory(crea::wx2std(dirDlg->GetPath()),m_results))
122  {
123  //TO DO WARNING MESSAGE;
124  }
125  }
126  SetReturnCode( resultShowModal );
127 // Close();
128  EndModal( resultShowModal );
129  }
130 
132 // //
134 
135  void WxSimpleDlg::OnReadGimmick(wxCommandEvent &event)
136  {
137  // Run Gimmick
138  WxGimmickReaderDialog dlg(0,-1,
139  namedescp,
140  namedb,
141  _T("Select image(s) - Gimmick! (c) CREATIS-LRMN 2008"),
142  wxDefaultPosition,
143  wxSize(810,750),
146  _3D,
147  1);
148  dlg.ShowModal();
149  if (dlg.GetReturnCode() == wxID_OK)
150  {
151  std::vector<creaImageIO::OutStrGimmick> out;
152  std::vector<std::string> attr;
153  dlg.stopReading();
154  dlg.getSelected(out, attr,true,"");
155  m_results.clear();
156  int size=(int)out.size();
157 printf("EED WxSimpleDlg::OnReadGimmick size=%d \n");
158  int ii;
159  if(!bInfo)
160  {
161  for (ii=0;ii<size;ii++)
162  {
163  m_results.push_back(out[ii].img);
164  }
165  }
166  else
167  {
168  for (ii=0;ii<size;ii++)
169  {
170  m_resultsInfo.push_back(out[ii]);
171  }
172  }
173  dlg.OnExit();
174  }
175  SetReturnCode( dlg.GetReturnCode() );
176  EndModal( dlg.GetReturnCode() );
177  }
178 
180  {
181  return infoimage;
182  }
183 
185 // Return the results vector //
187  std::vector<vtkImageData*> WxSimpleDlg::getImagesSelected()
188  {
189  return m_results;
190  }
191 
192 
193 }
194