]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxSimpleDlg.cpp
thread bug correction
[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                                         infoimage=_T("FILE(s):")+wxArray[0];
54                                         std::vector<std::string> files;
55                                         for( int i = 0; i < wxArray.GetCount(); i++)
56                                         {
57                                                 files.push_back( crea::wx2std(wxArray[i]));
58                                         }
59                                         if(!m_view.readFile(files,m_results))
60                                         {
61                                                 //TO DO WARNING MESSAGE;
62                                         }
63                                 } else {
64                                         // TO DO WARNING MESSAGES
65                                 }
66                         }
67                   SetReturnCode( resultShowModal );
68 //               Close();
69                  EndModal( resultShowModal );
70           }
71
72  //////////////////////////////////////////////////////////////////////
73 //                                                                                                                                      //
74 //////////////////////////////////////////////////////////////////////
75
76           void WxSimpleDlg::OnReadDirectory(wxCommandEvent &event)
77           {
78                   int resultShowModal;
79              long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
80                  wxDirDialog* dirDlg = new wxDirDialog( 0, _T("Select the directory to display"), _T(""), style);
81                  
82                  resultShowModal = dirDlg->ShowModal();
83                  if ( resultShowModal==wxID_OK )
84                  {  
85                         infoimage=_T("DIRECTORY:")+dirDlg->GetPath();
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         //              infoimage=_T("DICOM: ???_EED_???");
117 //EED 07JUIN2010                        dlg.GetSelectedImages(m_results,3);
118                         std::vector<creaImageIO::OutStrGimmick> out;
119                         std::vector<std::string> attr;
120 //                              attr.push_back("D0028_0010");
121 //                              attr.push_back("D0008_0023");
122 //                              attr.push_back("D0008_1070");
123                                 dlg.stopReading();
124                                 dlg.getSelected(out, attr,true,"");
125 //                              crea::VtkBasicSlicer(out.front().img);
126                         m_results.clear();
127                         int size=out.size();
128                         int ii;
129                         for (ii=0;ii<size;ii++)
130                         {
131                                 m_results.push_back(out[ii].img);
132                         }
133
134                         dlg.OnExit();
135                  }
136                  SetReturnCode( dlg.GetReturnCode() );
137 //               Close();
138                  EndModal( dlg.GetReturnCode() );
139            }
140
141         wxString WxSimpleDlg::getInfoImage()
142         {
143                 return infoimage;
144         }
145
146  //////////////////////////////////////////////////////////////////////
147 // Return the results vector                                                                            //
148 //////////////////////////////////////////////////////////////////////
149           std::vector<vtkImageData*> WxSimpleDlg::getImagesSelected()
150           {
151                   return m_results;
152           }
153 }
154