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