]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxOutputDlg.cpp
eee5600914af868db09e818962694a5445756a18
[creaImageIO.git] / src / creaImageIOWxOutputDlg.cpp
1 #include <creaImageIOWxOutputDlg.h>
2
3 namespace creaImageIO
4 {
5         // CTor
6    WxOutputDlg::WxOutputDlg(wxWindow *parent, const std::vector<std::string> filenames, int i_dim, bool single)
7     : wxDialog(parent, -1,_T("OUTPUT FORMAT"), wxDefaultPosition, wxSize(350,450))
8    {
9
10                 int size = filenames.size();
11                 
12                 int deflt = 1;
13
14                 std::string sentence;
15                 sentence = "You select";
16                 std::string sentence2 = "You have the possibility to select output format :";
17                 int nbsent= 0;
18                 std::vector<std::string> outsentences;
19                 if (size == 1)
20                 {
21                    sentence += " 1 ";
22                 }
23                 else
24                 {
25                    sentence += " n ";
26                 }
27                 if(single)
28                 {
29                         sentence += " single frames";
30                 }
31                 else
32                 {
33                         sentence += " multi-frames"; 
34                 }
35                 sentence += " as output";
36           
37                 
38                 if (size == 1)
39                 {
40                         if(single)
41                         {
42                                 outsentences.push_back("It shall be a single file with a single 2D frmae");
43                         }
44                         else
45                         {
46                                 outsentences.push_back("It shall be  multiple files with 2D frames");
47                                 outsentences.push_back("It shall be a single file with 3D frames");
48                         }                       
49                 }
50                 else
51                 {
52                         if(single)
53                         {
54                                 outsentences.push_back("It shall be a single file with 3D frames");
55                                 outsentences.push_back("It shall be  multiple files with 2D frames");
56                         }
57                         else
58                         {
59                                 outsentences.push_back("It shall be a single file with (3D+t) frames");
60                                 outsentences.push_back("It shall be  multiple (n+t) files with 2D frames");
61                                 outsentences.push_back("It shall be  multiple (n) files with (2D+t) frames");
62                                 outsentences.push_back("It shall be a multiple (t) files with (2D+n) frames");
63                                 deflt = 3;
64                         }
65                 
66                 }
67                 if(i_dim != -1)
68                 {
69                         deflt = i_dim;
70                 }
71
72
73           int start_point = 45;
74           wxStaticText * ExportText=new wxStaticText(this,-1,crea::std2wx(sentence), wxPoint(5,10));
75           
76           std::vector<std::string>::iterator it = outsentences.begin();
77           for(int i = 0;it != outsentences.end(); it++, i++, start_point += 45)
78           {
79                  wxCheckBox *check = new wxCheckBox(this, -1, crea::std2wx((*it)), wxPoint(5,start_point) );
80                  if(i == deflt)
81                          check->SetValue(true);
82                  else
83                          check->SetValue(false);
84                   Connect( check->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &WxOutputDlg::OnChange );
85                   checkOut.push_back(check);
86           }
87           
88          checkAsking = new wxCheckBox(this, -1, _T("Do you want to save this output and no more asking"), wxPoint(5,start_point) );
89
90           // VALIDATION BUTTON
91           wxButton *Ok = new wxButton(this, -1,_T("OK"), wxPoint(5,start_point+20) );
92           Connect( Ok->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxOutputDlg::OnOk ); 
93         
94           wxButton *Cancel = new wxButton(this, wxID_CANCEL,_T("CANCEL"), wxPoint(100,start_point+20) );
95           Layout(); 
96           
97         }
98
99         WxOutputDlg::~WxOutputDlg(){}
100
101         void WxOutputDlg::OnOk(wxCommandEvent &event)
102         {
103                 Close();
104                 SetReturnCode(wxID_OK);
105         }       
106
107         void WxOutputDlg::OnChange(wxCommandEvent& event)
108         {
109                 std::vector<wxCheckBox*>::iterator it = checkOut.begin();
110
111                 for(int i = 0;it != checkOut.end(); it++, i++)
112                 {
113                         if( (*it)->GetId() == event.GetId())
114                         {
115                         }
116                         else
117                         {
118                                 (*it)->SetValue(false);
119                         }
120                 }
121         }
122
123         const std::string WxOutputDlg::getDim()
124         {
125                 char res[2];
126                 std::vector<wxCheckBox*>::iterator it = checkOut.begin();
127             for(int i = 1;it != checkOut.end(); it++, i++)
128             {
129                         if( (*it)->GetValue() )
130                         {
131                                 sprintf(res,"%d", i);
132                         }
133                         else
134                         {
135                                 
136                         }
137                 }
138                 return res;
139         }
140         const std::string WxOutputDlg::getAsking()
141         { 
142                 if(checkAsking->GetValue())
143                         return "false"; 
144                 else
145                         return "true";
146         }
147 }