-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileOpenDialog.cpp
461 lines (352 loc) · 15.3 KB
/
FileOpenDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/* ----------------------------------------------------------------------------
FileOpenDialog.cpp
MIView - Medical Image Viewer
Copyright (C) 2009-2011 Gregory Book
MIView is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------- */
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "FileOpenDialog.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
////@begin includes
////@end includes
#include "MainFrame.h"
#include "FileOpenDialog.h"
////@begin XPM images
////@end XPM images
/*!
* FileOpenDialog type definition
*/
IMPLEMENT_DYNAMIC_CLASS( FileOpenDialog, wxDialog )
/*!
* FileOpenDialog event table definition
*/
BEGIN_EVENT_TABLE( FileOpenDialog, wxDialog )
////@begin FileOpenDialog event table entries
EVT_BUTTON( ID_BTN_GETFILENAME, FileOpenDialog::OnOpenFile )
EVT_CHECKBOX( ID_IS_MOSAIC, FileOpenDialog::OnIsMosaicClick )
////@end FileOpenDialog event table entries
END_EVENT_TABLE()
/*!
* FileOpenDialog constructors
*/
FileOpenDialog::FileOpenDialog()
{
Init();
}
FileOpenDialog::FileOpenDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
Init();
Create(parent, id, caption, pos, size, style);
}
/*!
* FileOpenDialog creator
*/
bool FileOpenDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin FileOpenDialog creation
SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
wxDialog::Create( parent, id, caption, pos, size, style );
CreateControls();
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
Centre();
////@end FileOpenDialog creation
return true;
}
/*!
* FileOpenDialog destructor
*/
FileOpenDialog::~FileOpenDialog()
{
////@begin FileOpenDialog destruction
////@end FileOpenDialog destruction
}
/*!
* Member initialisation
*/
void FileOpenDialog::Init()
{
////@begin FileOpenDialog member initialisation
sizerMain = NULL;
sizerFilename = NULL;
labelFilename = NULL;
txtFilename = NULL;
btnGetFilename = NULL;
radioOpenSingleFile = NULL;
radioOpenAllFilesWith = NULL;
radioOpenAll = NULL;
staticLine1 = NULL;
sizerOptions = NULL;
sizerFileFormat = NULL;
radioFileTypeAuto = NULL;
radioFileTypeDicom = NULL;
radioFileTypeImage = NULL;
radioFileTypeAnalyze = NULL;
chkIsMosaic = NULL;
sizerXYSize = NULL;
staticXSizeLabel = NULL;
spinXSize = NULL;
staticYSizeLabel = NULL;
spinYSize = NULL;
sizerNumberSlices = NULL;
staticNumberSlicesLabel = NULL;
spinNumberOfSlices = NULL;
sizerBottomButtons = NULL;
btnHelp = NULL;
btnCancel = NULL;
btnOpen = NULL;
////@end FileOpenDialog member initialisation
}
/*!
* Control creation for FileOpenDialog
*/
void FileOpenDialog::CreateControls()
{
////@begin FileOpenDialog content construction
FileOpenDialog* itemDialog1 = this;
sizerMain = new wxBoxSizer(wxVERTICAL);
itemDialog1->SetSizer(sizerMain);
sizerFilename = new wxBoxSizer(wxHORIZONTAL);
sizerMain->Add(sizerFilename, 0, wxGROW|wxALL, 5);
labelFilename = new wxStaticText( itemDialog1, wxID_STATIC, _("Filename"), wxDefaultPosition, wxDefaultSize, 0 );
labelFilename->SetFont(wxFont(8, wxSWISS, wxNORMAL, wxBOLD, false, wxT("Tahoma")));
sizerFilename->Add(labelFilename, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
txtFilename = new wxTextCtrl( itemDialog1, ID_FILENAME, wxEmptyString, wxDefaultPosition, wxSize(349, -1), 0 );
sizerFilename->Add(txtFilename, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
btnGetFilename = new wxButton( itemDialog1, ID_BTN_GETFILENAME, _("..."), wxDefaultPosition, wxSize(24, -1), 0 );
sizerFilename->Add(btnGetFilename, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
radioOpenSingleFile = new wxRadioButton( itemDialog1, ID_RADIO_OPENSINGLEFILE, _("Open only this file"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
radioOpenSingleFile->SetValue(false);
sizerMain->Add(radioOpenSingleFile, 0, wxALIGN_LEFT|wxALL, 5);
radioOpenAllFilesWith = new wxRadioButton( itemDialog1, ID_RADIO_OPENALLFILESWITH, _("Open only selected files"), wxDefaultPosition, wxDefaultSize, 0 );
radioOpenAllFilesWith->SetValue(true);
sizerMain->Add(radioOpenAllFilesWith, 0, wxALIGN_LEFT|wxALL, 5);
radioOpenAll = new wxRadioButton( itemDialog1, ID_RADIO_OPENALL, _("Open all files in folder with same extension"), wxDefaultPosition, wxDefaultSize, 0 );
radioOpenAll->SetValue(false);
sizerMain->Add(radioOpenAll, 0, wxALIGN_LEFT|wxALL, 5);
staticLine1 = new wxStaticLine( itemDialog1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
sizerMain->Add(staticLine1, 0, wxGROW|wxALL, 0);
sizerOptions = new wxBoxSizer(wxHORIZONTAL);
sizerMain->Add(sizerOptions, 1, wxGROW|wxALL, 5);
wxStaticBox* itemStaticBoxSizer12Static = new wxStaticBox(itemDialog1, wxID_ANY, _("File Format"));
sizerFileFormat = new wxStaticBoxSizer(itemStaticBoxSizer12Static, wxVERTICAL);
sizerOptions->Add(sizerFileFormat, 0, wxGROW|wxALL, 5);
radioFileTypeAuto = new wxRadioButton( itemDialog1, ID_RADIO_FILETYPE_AUTO, _("Automatically Detect"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
radioFileTypeAuto->SetValue(true);
sizerFileFormat->Add(radioFileTypeAuto, 0, wxALIGN_LEFT|wxALL, 5);
radioFileTypeDicom = new wxRadioButton( itemDialog1, ID_RADIO_FILETYPE_DICOM, _("Dicom, ACR/NEMA (.dcm)"), wxDefaultPosition, wxDefaultSize, 0 );
radioFileTypeDicom->SetValue(false);
sizerFileFormat->Add(radioFileTypeDicom, 0, wxALIGN_LEFT|wxALL, 5);
radioFileTypeImage = new wxRadioButton( itemDialog1, ID_RADIO_FILETYPE_IMAGE, _("Image (.jpg .png .bmp .tif .gif)"), wxDefaultPosition, wxDefaultSize, 0 );
radioFileTypeImage->SetValue(false);
sizerFileFormat->Add(radioFileTypeImage, 0, wxALIGN_LEFT|wxALL, 5);
radioFileTypeAnalyze = new wxRadioButton( itemDialog1, ID_RADIO_FILETYPE_ANALYZE, _("Analyze 7.5 or Nifti1 (.img .hdr .nii)"), wxDefaultPosition, wxDefaultSize, 0 );
radioFileTypeAnalyze->SetValue(false);
sizerFileFormat->Add(radioFileTypeAnalyze, 0, wxALIGN_LEFT|wxALL, 5);
wxStaticBox* itemStaticBoxSizer17Static = new wxStaticBox(itemDialog1, wxID_ANY, _("DICOM Mosaic Options"));
wxStaticBoxSizer* itemStaticBoxSizer17 = new wxStaticBoxSizer(itemStaticBoxSizer17Static, wxVERTICAL);
sizerOptions->Add(itemStaticBoxSizer17, 0, wxGROW|wxALL, 5);
chkIsMosaic = new wxCheckBox( itemDialog1, ID_IS_MOSAIC, _("File(s) are DICOM mosaic images"), wxDefaultPosition, wxDefaultSize, 0 );
chkIsMosaic->SetValue(false);
itemStaticBoxSizer17->Add(chkIsMosaic, 0, wxALIGN_LEFT|wxALL, 5);
sizerXYSize = new wxBoxSizer(wxHORIZONTAL);
itemStaticBoxSizer17->Add(sizerXYSize, 0, wxALIGN_LEFT|wxALL, 0);
staticXSizeLabel = new wxStaticText( itemDialog1, wxID_STATIC, _("X size"), wxDefaultPosition, wxDefaultSize, 0 );
sizerXYSize->Add(staticXSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 3);
spinXSize = new wxSpinCtrl( itemDialog1, ID_MOSAIC_XSIZE, _T("64"), wxDefaultPosition, wxSize(49, -1), wxSP_ARROW_KEYS, 0, 32768, 64 );
spinXSize->Enable(false);
sizerXYSize->Add(spinXSize, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3);
sizerXYSize->Add(5, 5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
staticYSizeLabel = new wxStaticText( itemDialog1, wxID_STATIC, _("Y size"), wxDefaultPosition, wxDefaultSize, 0 );
sizerXYSize->Add(staticYSizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 3);
spinYSize = new wxSpinCtrl( itemDialog1, MOSAIC_YSIZE, _T("64"), wxDefaultPosition, wxSize(49, -1), wxSP_ARROW_KEYS, 0, 32768, 64 );
spinYSize->Enable(false);
sizerXYSize->Add(spinYSize, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3);
sizerNumberSlices = new wxBoxSizer(wxHORIZONTAL);
itemStaticBoxSizer17->Add(sizerNumberSlices, 0, wxALIGN_LEFT|wxALL, 0);
staticNumberSlicesLabel = new wxStaticText( itemDialog1, wxID_STATIC, _("Number of Slices"), wxDefaultPosition, wxDefaultSize, 0 );
sizerNumberSlices->Add(staticNumberSlicesLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 3);
spinNumberOfSlices = new wxSpinCtrl( itemDialog1, ID_MOSAIC_SLICES, _T("36"), wxDefaultPosition, wxSize(75, -1), wxSP_ARROW_KEYS, 0, 65565, 36 );
spinNumberOfSlices->Enable(false);
sizerNumberSlices->Add(spinNumberOfSlices, 0, wxALIGN_CENTER_VERTICAL|wxALL, 3);
wxStaticText* itemStaticText28 = new wxStaticText( itemDialog1, wxID_STATIC, _("Mosaic images MUST describe a 3D volume"), wxDefaultPosition, wxDefaultSize, 0 );
itemStaticText28->SetForegroundColour(wxColour(170, 0, 0));
itemStaticBoxSizer17->Add(itemStaticText28, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
sizerOptions->Add(5, 5, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
sizerBottomButtons = new wxBoxSizer(wxVERTICAL);
sizerOptions->Add(sizerBottomButtons, 0, wxGROW|wxALL, 5);
btnHelp = new wxButton( itemDialog1, ID_BUTTON_HELP, _("Help"), wxDefaultPosition, wxDefaultSize, 0 );
sizerBottomButtons->Add(btnHelp, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
sizerBottomButtons->Add(0, 5, 1, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
btnCancel = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
sizerBottomButtons->Add(btnCancel, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
btnOpen = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
sizerBottomButtons->Add(btnOpen, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
////@end FileOpenDialog content construction
// disable all the special controls
spinNumberOfSlices->Disable();
spinXSize->Disable();
spinYSize->Disable();
}
/*!
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BTN_GETFILENAME
*/
void FileOpenDialog::OnOpenFile( wxCommandEvent& event )
{
static const wxChar *FILETYPES = _T( "Dicom/ACR-NEMA/Papyrus (*.dcm, *.acr, *.pap)|*.dcm;*.acr;*.pap|Analyze 7.5 (*.img,*.hdr)|*.img;*.hdr|GIF (*.gif)|*.gif|TIFF (*.tif, *.tiff)|*.tif;*.tiff|PNG (*.png)|*.png|BMP (*.bmp)|*.bmp|JPEG (*.jpg,*.jpeg,*.jpe,*.jff,*.jfif,*.jif,*.jtf)|*.jpg;*.jpeg;*.jpe;*.jff;*.jfif;*.jif;*.jtf|All files(*.*)|*.*");
wxFileDialog *openFileDialog = new wxFileDialog (this, "Open file", "", "", FILETYPES, wxOPEN|wxFD_MULTIPLE, wxDefaultPosition);
if (openFileDialog->ShowModal() == wxID_OK) {
filenames.Clear(); /* clear any old stuff in case they cancelled something earlier */
openFileDialog->GetPaths(filenames);
// filename.Replace("\\","/");
if (filenames.Count() > 1)
txtFilename->SetValue("{multiple}");
else
txtFilename->SetValue(filenames[0]);
}
}
/*!
* wxEVT_COMMAND_CHECKBOX_CLICKED event handler for ID_IS_MOSAIC
*/
void FileOpenDialog::OnIsMosaicClick( wxCommandEvent& event )
{
if (chkIsMosaic->GetValue()) {
spinXSize->Enable();
spinYSize->Enable();
spinNumberOfSlices->Enable();
}
else {
spinXSize->Disable();
spinYSize->Disable();
spinNumberOfSlices->Disable();
}
}
/*!
* Should we show tooltips?
*/
bool FileOpenDialog::ShowToolTips()
{
return true;
}
/*!
* Get bitmap resources
*/
wxBitmap FileOpenDialog::GetBitmapResource( const wxString& name )
{
// Bitmap retrieval
////@begin FileOpenDialog bitmap retrieval
wxUnusedVar(name);
return wxNullBitmap;
////@end FileOpenDialog bitmap retrieval
}
/*!
* Get icon resources
*/
wxIcon FileOpenDialog::GetIconResource( const wxString& name )
{
// Icon retrieval
////@begin FileOpenDialog icon retrieval
wxUnusedVar(name);
return wxNullIcon;
////@end FileOpenDialog icon retrieval
}
// --------------------------------------------------------
// ---------- GetFilePaths --------------------------------
// --------------------------------------------------------
wxArrayString FileOpenDialog::GetFilePaths(void)
{
return filenames;
}
// --------------------------------------------------------
// ---------- GetFilePrefix -------------------------------
// --------------------------------------------------------
wxString FileOpenDialog::GetFilePrefix(void)
{
return filePrefix;
}
int FileOpenDialog::GetLoadType(void)
{
if (radioOpenAll->GetValue()) return OPEN_ALL;
if (radioOpenAllFilesWith->GetValue()) return OPEN_SELECTED;
if (radioOpenSingleFile->GetValue()) return OPEN_SINGLE;
return 0;
}
bool FileOpenDialog::GetIsMosaic(void)
{
if (chkIsMosaic->GetValue())
return true;
else
return false;
}
int FileOpenDialog::GetMosaicXSize()
{
return spinXSize->GetValue();
}
int FileOpenDialog::GetMosaicYSize()
{
return spinYSize->GetValue();
}
int FileOpenDialog::GetMosaicNumSlices()
{
return spinNumberOfSlices->GetValue();
}
int FileOpenDialog::GetFileType(void)
{
filename = filenames[0];
if (radioFileTypeAnalyze->GetValue())
return FILETYPE_ANALYZE;
if (radioFileTypeAuto->GetValue()) {
if ((filename.Right(4) == ".dcm") || (filename.Right(4) == ".acr"))
return FILETYPE_DICOM;
if ((filename.Right(4) == ".img") || (filename.Right(4) == ".hdr") || (filename.Right(4) == ".nii"))
return FILETYPE_ANALYZE;
if ((filename.Right(4) == ".jpg") || (filename.Right(5) == ".jpeg") || (filename.Right(4) == ".jpe"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".jff") || (filename.Right(5) == ".jfif") || (filename.Right(4) == ".jif"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".gif") || (filename.Right(4) == ".bmp") || (filename.Right(4) == ".xpm"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".tif") || (filename.Right(5) == ".tiff") || (filename.Right(4) == ".png"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".pcx") || (filename.Right(4) == ".pnm") || (filename.Right(4) == ".ico"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".cur") || (filename.Right(4) == ".ani") || (filename.Right(4) == ".jtf"))
return FILETYPE_RASTER;
}
if (radioFileTypeDicom->GetValue())
return FILETYPE_DICOM;
if (radioFileTypeImage->GetValue()) {
if ((filename.Right(4) == ".jpg") || (filename.Right(5) == ".jpeg") || (filename.Right(4) == ".jpe"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".jff") || (filename.Right(5) == ".jfif") || (filename.Right(4) == ".jif"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".gif") || (filename.Right(4) == ".bmp") || (filename.Right(4) == ".xpm"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".tif") || (filename.Right(5) == ".tiff") || (filename.Right(4) == ".png"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".pcx") || (filename.Right(4) == ".pnm") || (filename.Right(4) == ".ico"))
return FILETYPE_RASTER;
if ((filename.Right(4) == ".cur") || (filename.Right(4) == ".ani") || (filename.Right(4) == ".jtf"))
return FILETYPE_RASTER;
}
return FILETYPE_UNKNOWN;
}