]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxSimpleDlg.cpp
0abba6ab59d1e3d959446dc413768ed230d231b5
[creaImageIO.git] / src / creaImageIOWxSimpleDlg.cpp
1 #include "creaImageIOWxSimpleDlg.h"
2 #include "creaImageIOWxGimmickReaderDialog.h"
3
4 namespace creaImageIO
5 {
6
7         ///Ctor
8    WxSimpleDlg::WxSimpleDlg(wxWindow *parent, 
9                                                         wxString i_title,  
10                                                         const std::string i_namedescp , 
11                                                         const std::string i_namedb)
12     : wxDialog(parent, -1,_T("DISPLAY IMAGES"), wxDefaultPosition, wxSize(230,150))
13    {
14                 namedescp       = i_namedescp; 
15                 namedb          = i_namedb;
16
17            if(!i_title.empty())
18            {
19                         this->SetTitle(i_title);  
20            }
21            // Button to select file(s)
22            wxButton *fileBut = new wxButton(this, -1,_T("Select a file to display"), wxPoint(10,7) );
23            Connect( fileBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadFile ); 
24
25            // Button to select directory
26            wxButton *directoryBut = new wxButton(this, -1,_T("Select a directory to display"), wxPoint(10,40) );
27            Connect( directoryBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadDirectory ); 
28
29            // button to select creaImageIO
30            wxButton *gimmickBut = new wxButton(this, -1,_T("Select Gimmick"), wxPoint(10,70) );
31            Connect( gimmickBut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxSimpleDlg::OnReadGimmick ); 
32
33            /// \TODO  Button to select Bruker directory
34         
35         Layout(); 
36         
37         }
38 //////////////////////////////////////////////////////////////////////
39 //                                                                  //
40 //////////////////////////////////////////////////////////////////////
41           void WxSimpleDlg::OnReadFile(wxCommandEvent& event)
42           {
43                   int resultShowModal;
44                   wxFileDialog* fileDlg = new wxFileDialog( 0,  _T("Select file"), _T(""), _T(""), crea::std2wx("*"), wxOPEN |wxFD_MULTIPLE, wxDefaultPosition);
45     
46                     resultShowModal = fileDlg->ShowModal();
47                         if ( resultShowModal==wxID_OK )
48                         {
49                                 wxArrayString wxArray;
50                                 fileDlg->GetPaths(wxArray);
51                                 if(wxArray.size() >0)
52                                 {
53                                         std::vector<std::string> files;
54                                         for( int i = 0; i < wxArray.GetCount(); i++)
55                                         {
56                                                 files.push_back( crea::wx2std(wxArray[i]));
57                                         }
58                                         if(!m_view.readFile(files,m_results))
59                                         {
60                                                 //TO DO WARNING MESSAGE;
61                                         }
62                                 }
63                                 else
64                                 {
65                                         // TO DO WARNING MESSAGES
66                                 }
67                         }
68                   SetReturnCode( resultShowModal );
69 //               Close();
70                  EndModal( resultShowModal );
71           }
72
73  //////////////////////////////////////////////////////////////////////
74 //                                                                                                                                      //
75 //////////////////////////////////////////////////////////////////////
76
77           void WxSimpleDlg::OnReadDirectory(wxCommandEvent &event)
78           {
79                   int resultShowModal;
80              long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
81                  wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style);
82                  
83                  resultShowModal = dirDlg->ShowModal();
84                  if ( resultShowModal==wxID_OK )
85                  {  
86                         if(! m_view.readDirectory(crea::wx2std(dirDlg->GetPath()),m_results))
87                         {
88                                 //TO DO WARNING MESSAGE;
89                         }
90                  }
91                  SetReturnCode( resultShowModal );
92 //               Close();
93                  EndModal( resultShowModal );
94           }
95
96           //////////////////////////////////////////////////////////////////////
97 //                                                                                                                                      //
98 //////////////////////////////////////////////////////////////////////
99
100           void WxSimpleDlg::OnReadGimmick(wxCommandEvent &event)
101           {
102                   // Run Gimmick
103                    WxGimmickReaderDialog dlg(0,-1, 
104                                    namedescp,
105                                    namedb, 
106                                    _T("Select image(s)        - Gimmick! (c) CREATIS-LRMN 2008"),
107                    wxDefaultPosition,
108                    wxSize(810,750),
109                    GIMMICK_2D_IMAGE_SELECTION,
110                    GIMMICK_3D_IMAGE_SELECTION,
111                    _3D,
112                                    1);
113                  dlg.ShowModal();
114                  if (dlg.GetReturnCode() == wxID_OK)
115              {
116                         dlg.GetSelectedImages(m_results,3);
117                         dlg.OnExit();
118                  }
119                  SetReturnCode( dlg.GetReturnCode() );
120 //               Close();
121                  EndModal( dlg.GetReturnCode() );
122            }
123
124  //////////////////////////////////////////////////////////////////////
125 // Return the results vector                                                                            //
126 //////////////////////////////////////////////////////////////////////
127           std::vector<vtkImageData*> WxSimpleDlg::getImagesSelected()
128           {
129                   return m_results;
130           }
131 }
132