~ubuntu-branches/ubuntu/precise/ginkgocadx/precise

« back to all changes in this revision

Viewing changes to src/cadxcore/main/gui/import/selectimagesimportation.cpp

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2011-09-09 08:39:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: package-import@ubuntu.com-20110909083926-iktecd132cnku5cd
Tags: 2.5.4.0~rc-1
New upstream version (patches were applied)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *  
3
 
 *  $Id: selectimagesimportation.cpp 3934 2011-07-07 08:47:50Z tovar $
 
3
 *  $Id: selectimagesimportation.cpp 4076 2011-08-11 06:37:52Z carlos $
4
4
 *  Ginkgo CADx Project
5
5
 *
6
6
 *  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
13
13
 */
14
14
#include <vector>
15
15
#include <sstream>
16
 
 
 
16
 
 
17
#include <wx/image.h>
17
18
#include <wx/msgdlg.h>
18
19
#include <wx/msgout.h>
19
20
#include <wx/filename.h>
27
28
#include <wx/sizer.h>
28
29
#include <wx/aui/auibar.h>
29
30
#include <wx/arrstr.h>
 
31
#include <wx/thread.h>
 
32
#include <wx/menu.h>
30
33
 
31
34
#include <wx/ginkgostyle/ginkgostyle.h>
32
35
 
39
42
 
40
43
#include "selectimagesimportation.h"
41
44
#include <api/icontextoestudio.h>
 
45
#include <resources/ginkgoresourcemanager.h>
 
46
 
 
47
#include <vtkImageData.h>
 
48
#include <vtkUnsignedCharArray.h>
 
49
#include <vtkPointData.h>
 
50
#include <vtkginkgoimageviewer.h>
 
51
 
 
52
#define ID_BUTTON_HIDE 0
 
53
#define ID_BUTTON_ROTATE_LEFT 1
 
54
#define ID_BUTTON_ROTATE_RIGHT 2
 
55
#define ID_BUTTON_DELETE 3
42
56
 
43
57
 
44
58
namespace GNC {
45
59
        namespace GUI {
 
60
                ///////////////////////////////////////////////////////////
46
61
                class ButtonsBar:public wxAuiToolBar{
47
62
                public:
48
63
                        ButtonsBar(wxWindow* pParent, const wxColour& color, const wxFont& fuente): wxAuiToolBar(pParent,wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_TB_HORZ_TEXT)
65
80
                        }
66
81
                };
67
82
 
68
 
                //drag&drop
 
83
                //drag&drop////////////////////////////////////////////////////////
69
84
                class DropTargetSelectImages: public wxFileDropTarget
70
85
                {
71
86
                public:
73
88
                        {
74
89
                                m_pParent = pParent;
75
90
                                m_fileSpecs = fileSpecs;
 
91
                                m_enabled = true;
76
92
                        }
77
93
                        ~DropTargetSelectImages()
78
94
                        {
79
95
                        }
 
96
 
 
97
                        void SetEnable(bool enabled) {
 
98
                                m_enabled = enabled;
 
99
                        }
 
100
 
80
101
                        bool OnDropFiles(wxCoord /*x*/, wxCoord /*y*/, const wxArrayString& filenames)
81
102
                        {
 
103
                                if (!m_enabled)
 
104
                                        return false;
82
105
                                wxArrayString images;
83
 
                                std::list<std::string> listaPaths;
84
106
                                for(wxArrayString::const_iterator it = filenames.begin(); it!= filenames.end(); it++)
85
107
                                {
86
108
                                        if(wxDirExists((*it))) {
87
 
                                                //se leen los ficheros dicom del directorio
88
 
                                                wxDir dir;
89
 
                                                if (dir.Open((*it))) {
90
 
                                                        for (std::list<std::string>::iterator itSpecs = m_fileSpecs.begin(); itSpecs != m_fileSpecs.end(); ++itSpecs) {
91
 
                                                                wxString wxPathFich;
92
 
                                                                bool cont = dir.GetFirst(&wxPathFich, wxString::FromUTF8((*itSpecs).c_str()));
93
 
                                                                while (cont) {
94
 
                                                                        wxPathFich=dir.GetName()+ wxFileName::GetPathSeparator(wxPATH_NATIVE) +wxPathFich;      
95
 
                                                                        images.push_back(wxPathFich);                                                   
96
 
                                                                        cont = dir.GetNext(&wxPathFich);
97
 
                                                                }
98
 
                                                        }
99
 
#if !defined(_WINDOWS)
100
 
                                                        for (std::list<std::string>::iterator itSpecs = m_fileSpecs.begin(); itSpecs != m_fileSpecs.end(); ++itSpecs) {
101
 
                                                                wxString wxPathFich;
102
 
                                                                bool cont = dir.GetFirst(&wxPathFich, wxString::FromUTF8((*itSpecs).c_str()).Upper());
103
 
                                                                while (cont) {
104
 
                                                                        wxPathFich=dir.GetName()+ wxFileName::GetPathSeparator(wxPATH_NATIVE) +wxPathFich;      
105
 
                                                                        images.push_back(wxPathFich);                                                   
106
 
                                                                        cont = dir.GetNext(&wxPathFich);
107
 
                                                                }
108
 
                                                        }
109
 
#endif
110
 
                                                }
 
109
                                                m_pParent->ScanPath((*it));
111
110
                                        } else if(wxFileExists((*it))){
112
111
                                                wxFileName filename((*it));
113
112
                                                wxString extensionFile = filename.GetExt().Lower();
126
125
 
127
126
                        SelectImagesImportation* m_pParent;
128
127
                        std::list<std::string> m_fileSpecs;
129
 
                };
130
 
                //
131
 
 
132
 
                SelectImagesImportation::SelectImagesImportation(wxWindow* pParent,std::string& dirTemp, IWizard* pWizard, bool reescalar, GnkPtr<GIL::IModeloIntegracion>& pModeloIntegracion, const std::list<std::string>& fileSpecs, const wxString& defaultFilter) : SelectImagesImportationBase(pParent), IPasoWizard(pWizard)
 
128
                        bool m_enabled;
 
129
                };
 
130
                /////////////////////////////////////////////////////TIMER DIRECTORY
 
131
                class TimerDirectory: public wxTimer {
 
132
                public:
 
133
                        TimerDirectory(SelectImagesImportation* pSelectImages) 
 
134
                        {
 
135
                                m_pSelectImages = pSelectImages;
 
136
                        }
 
137
 
 
138
                        ~TimerDirectory() 
 
139
                        {
 
140
                        }
 
141
 
 
142
                        void SetPath(const std::string& path, bool monitorize) 
 
143
                        {
 
144
                                m_path = wxString::FromUTF8(path.c_str());
 
145
                                m_monitorize = monitorize;
 
146
                        }
 
147
                        
 
148
                        virtual void Notify()
 
149
                        {
 
150
                                if (m_monitorize) {
 
151
                                        if (m_pSelectImages->ScanPath(m_path)) {
 
152
                                                this->Start(1000, true);
 
153
                                        } else {
 
154
                                                wxMessageBox(_("Path of the location doesn't exists"), _("Info"), wxOK | wxICON_INFORMATION, m_pSelectImages);
 
155
                                        }
 
156
                                } else {
 
157
                                        m_pSelectImages->AddImage(m_path);
 
158
                                }
 
159
                        }
 
160
 
 
161
                protected:
 
162
                        wxString m_path;
 
163
                        bool m_monitorize;
 
164
                        SelectImagesImportation* m_pSelectImages;
 
165
                };
 
166
 
 
167
 
 
168
                ////////////////////////////////////////////////////////
 
169
 
 
170
                SelectImagesImportation::SelectImagesImportation(wxWindow* pParent,std::string& dirTemp, IWizard* pWizard, GnkPtr<GIL::IModeloIntegracion>& pModeloIntegracion, const std::list<std::string>& fileSpecs, const wxString& defaultFilter) : SelectImagesImportationBase(pParent), IPasoWizard(pWizard)
133
171
                {                       
134
172
                        SetScrollbars(10, 10, 50, 50, 0, 0, false);
135
173
                        AdjustScrollbars();
136
174
                        m_firstAttach = true;
 
175
                        m_pwxImagePreview = new wxImage();
137
176
                        
138
 
                        std::list<std::string> m_fileSpecs = fileSpecs;
 
177
                        m_fileSpecs = fileSpecs;
139
178
                        if (defaultFilter.IsEmpty()) {
140
179
#if defined(_WIN32) || defined(__WXMAC__)
141
180
                                m_pDefaultFilter =_("Images (*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.tiff)|*.jpg;*.jpeg;*.bmp;*.png;*.tif;*.tiff|JPEG Images (*.jpg;*.jpeg)|*.jpg;*.jpeg|BMP Images (*.bmp)|*.bmp|PNG Images (*.png)|*.png|TIFF Images (*.tif;*.tiff)|*.tif;*.tiff|All files(*.*)|*.*");
155
194
                        m_pModeloIntegracion = pModeloIntegracion;
156
195
                        Hide();
157
196
                        m_dirTemp = dirTemp;
158
 
                        m_reescalar = reescalar;
159
197
 
160
198
                        wxColour barColor = wxColour(200,200,200);
161
199
                        wxFont fontBar = wxFont( 10, 70, 90, wxFONTWEIGHT_BOLD, false, wxEmptyString );
170
208
                        for (GNC::GCS::IEntorno::MapaUbicaciones::iterator it = mapa.begin(); it != mapa.end(); it++) {
171
209
                                GIL::Ubicacion& u = (*it).second;
172
210
 
173
 
                                m_pButtonsBar->AddTool(idButton, wxString::FromUTF8(u.Titulo.c_str()), GinkgoResourcesManager::IconosMenus::GetIcoImportar(), wxString::FromUTF8(u.Descripcion.c_str()));
 
211
                                m_pButtonsBar->AddTool(idButton, wxString::FromUTF8(u.Titulo.c_str()), GinkgoResourcesManager::IconosMenus::GetIcoImportar(), wxString::FromUTF8(u.Descripcion.c_str()), wxITEM_CHECK);
174
212
                                m_pButtonsBar->Connect(idButton++, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(SelectImagesImportation::OnUbicacionClick), NULL, this);
175
213
                        }
176
214
 
177
215
                        m_pButtonsBar->Realize();
178
216
                        m_pSizerButtons->Add(m_pButtonsBar, 1, wxEXPAND| wxALL, 0);
179
217
 
180
 
                        m_pImagenes->SetDropTarget(new DropTargetSelectImages(this, m_fileSpecs));
 
218
                        ButtonsBar* pToolPreview = new ButtonsBar(m_pPreviewPanel, barColor, fontBar);
 
219
                        pToolPreview->AddTool(ID_BUTTON_HIDE,_("Back"), GinkgoResourcesManager::Adquisicion::GetIcoAdquirirArchivo(),_("Back"));
 
220
                        pToolPreview->Connect(ID_BUTTON_HIDE,wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler( SelectImagesImportation::OnHidePreview),NULL,this);
 
221
                        
 
222
                        pToolPreview->Realize();
 
223
                        m_pPreviewPanel->GetSizer()->Insert(0,pToolPreview,0,wxEXPAND);
 
224
                        m_pPreviewPanel->Layout();
181
225
                        
182
226
                        m_pImagenes->Connect(wxEVT_COMMAND_THUMBNAIL_LEFT_DCLICK,wxCommandEventHandler(SelectImagesImportation::OnThumbLeftDClickSelected),NULL,this);
 
227
                        m_pImagenes->Connect(wxEVT_COMMAND_THUMBNAIL_RIGHT_CLICK,wxCommandEventHandler(SelectImagesImportation::OnThumbRightClickSelected),NULL,this);
183
228
                        m_pImagenes->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(SelectImagesImportation::OnImagenesKeyDown),NULL,this);
184
229
 
 
230
                        m_pTimerDirectory = new TimerDirectory(this);
 
231
                        m_pDropTarget = new DropTargetSelectImages(this, m_fileSpecs);
 
232
                        m_pImagenes->SetDropTarget(m_pDropTarget);
 
233
 
185
234
                        m_panelStep0->Layout();
186
235
                        Layout();
187
236
                }
193
242
 
194
243
                SelectImagesImportation::~SelectImagesImportation()
195
244
                {
 
245
                        if (m_pTimerDirectory != NULL) {
 
246
                                delete m_pTimerDirectory;
 
247
                                m_pTimerDirectory = NULL;
 
248
                        }
 
249
                        GIL::Ubicacion* pUbicacion = GetUbicacionSelected();
 
250
                        if (pUbicacion != NULL && pUbicacion->CleanAfter) {
 
251
                                /*//remove content from ubicacion directory...
 
252
                                */
 
253
                                wxArrayString paths=this->GetSelectedPaths();
 
254
                                for (wxArrayString::iterator it = paths.begin(); it != paths.end(); ++it) {
 
255
                                        wxRemoveFile((*it));
 
256
                                }
 
257
                        }
 
258
                        if (m_pwxImagePreview != NULL)
 
259
                        {
 
260
                                delete m_pwxImagePreview;
 
261
                                m_pwxImagePreview = NULL;
 
262
                        }
196
263
                        m_pImagenes->Disconnect(wxEVT_COMMAND_THUMBNAIL_LEFT_DCLICK,wxCommandEventHandler(SelectImagesImportation::OnThumbLeftDClickSelected),NULL,this);
197
264
                        m_pImagenes->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(SelectImagesImportation::OnImagenesKeyDown),NULL,this);
198
265
                }
199
266
 
200
 
                void SelectImagesImportation::OnThumbLeftDClickSelected(wxCommandEvent& event)
201
 
                {
202
 
                        while(m_pImagenes->GetSelection()!=-1){
203
 
                                m_pImagenes->Delete(m_pImagenes->GetSelection());
204
 
                        }
205
 
                        event.Skip();
206
 
                }
207
 
 
208
267
                void SelectImagesImportation::OnImagenesKeyDown(wxKeyEvent &event)
209
268
                {
210
269
                        if (event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK) {
211
 
                                while(m_pImagenes->GetSelection()!=-1){
212
 
                                        m_pImagenes->Delete(m_pImagenes->GetSelection());
213
 
                                }
 
270
                                DeleteSelectedThumbnails();
214
271
                                event.Skip(false);
215
272
                        }
216
273
                        else
217
274
                        {
218
275
                                event.Skip(true);
219
276
                        }
 
277
                }
 
278
 
 
279
                void SelectImagesImportation::OnDeleteSelectedThumbnails(wxCommandEvent &)
 
280
                {
 
281
                        DeleteSelectedThumbnails();
 
282
                }
 
283
 
 
284
                void SelectImagesImportation::DeleteSelectedThumbnails()
 
285
                {
 
286
                        bool deleteFromDisk = false;
 
287
                                ///if monitoring... ask
 
288
                        GIL::Ubicacion* pUbicacion = GetUbicacionSelected();
 
289
                        if (pUbicacion != NULL) {
 
290
                                if (pUbicacion->Monitorize) {
 
291
                                        int answer = wxMessageBox(_("Are you sure to delete this file from disk?"),_("Delete"), wxYES_NO , this);
 
292
                                        if (answer == wxYES) {
 
293
                                                deleteFromDisk = true;
 
294
                                        } else {
 
295
                                                return;
 
296
                                        }
 
297
                                }
 
298
                        }
 
299
                        while(m_pImagenes->GetSelection()!=-1){
 
300
                                if (deleteFromDisk) {
 
301
                                        wxThumbnailItem* item = m_pImagenes->GetItem(m_pImagenes->GetSelection());
 
302
                                        if (item != NULL) {
 
303
                                                wxRemoveFile(item->GetFilename());
 
304
                                        }
 
305
                                }
 
306
                                m_pImagenes->Delete(m_pImagenes->GetSelection());
 
307
                        }
 
308
                }
 
309
 
 
310
                void SelectImagesImportation::OnPreviewClick(wxCommandEvent &)
 
311
                {
 
312
                        ShowPreview();
 
313
                }
 
314
 
 
315
                void SelectImagesImportation::OnThumbLeftDClickSelected(wxCommandEvent& event)
 
316
                {
 
317
                        ShowPreview();
 
318
                        event.Skip();
 
319
                }
 
320
 
 
321
                void SelectImagesImportation::OnThumbRightClickSelected(wxCommandEvent& event)
 
322
                {
 
323
                        //menu...
 
324
                        wxArrayInt selection = m_pImagenes->GetSelections();
 
325
                        if (selection.size() == 0) {
 
326
                                return;
 
327
                        }
 
328
 
 
329
                        wxMenu contextual;
 
330
                        wxMenuItem* pRotateLeft = new wxMenuItem(&contextual, ID_BUTTON_DELETE, _("Delete selected items"));
 
331
                        contextual.Connect(ID_BUTTON_DELETE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SelectImagesImportation::OnDeleteSelectedThumbnails),NULL,this);
 
332
                        contextual.Append(pRotateLeft);
 
333
                        m_pImagenes->PopupMenu(&contextual);
 
334
                        event.Skip();
 
335
                }
 
336
 
 
337
                void SelectImagesImportation::ShowPreview()
 
338
                {
 
339
                        // Si hacemos doble click ampliamos la imagen para una mejor visualizacion
 
340
                        if (m_pImagenes->GetSelections().size() != 1) 
 
341
                        {
 
342
                                wxMessageBox(_("You must select an image"), _("Info"), wxOK | wxICON_INFORMATION, this);
 
343
                                return;
 
344
                        }
 
345
 
 
346
                        wxBusyInfo info(_("Generating preview..."));
 
347
                        wxThumbnailItem* item = m_pImagenes->GetItem(m_pImagenes->GetSelection());
 
348
                        if (item == NULL)
 
349
                                return;
 
350
 
 
351
                        Freeze();
 
352
                        m_pImagenes->Hide();
 
353
                        m_pPreviewPanel->Show();
 
354
                        m_pButtonsBar->Hide();
 
355
                        m_pPreview->SetFocus();
 
356
                        m_pButtonRemoveAll->Hide();
 
357
                        m_pButtonPreview->Hide();
 
358
 
 
359
                        //load preview...
 
360
                        wxString pathTmp = item->GetFilename();
 
361
                        m_pwxImagePreview->LoadFile(pathTmp);
 
362
 
 
363
                        vtkSmartPointer<vtkImageData> data = vtkSmartPointer<vtkImageData>::New();
 
364
                        double spacing[3] = {1.0f,1.0f,1.0f};
 
365
                        double origin[3] = {0.0f,0.0f,0.0f};
 
366
 
 
367
                        data->SetDimensions(m_pwxImagePreview->GetWidth(), m_pwxImagePreview->GetHeight(), 1);
 
368
                        data->SetNumberOfScalarComponents(3);
 
369
                        data->SetScalarTypeToUnsignedChar();
 
370
                        data->SetSpacing(spacing[0],spacing[1],spacing[2]);
 
371
                        data->SetOrigin(origin[0],origin[1],origin[2]);
 
372
 
 
373
                        vtkSmartPointer<vtkUnsignedCharArray> dataImagen = vtkSmartPointer<vtkUnsignedCharArray>::New();
 
374
                        dataImagen->SetNumberOfComponents(3);
 
375
                        unsigned int size = data->GetDimensions()[0] * data->GetDimensions()[1];
 
376
                        dataImagen->SetArray(m_pwxImagePreview->GetData(),size,1);
 
377
 
 
378
                        data->GetPointData()->SetScalars(dataImagen);
 
379
 
 
380
                        m_pPreview->SetInput(data);
 
381
                        m_pPreview->GetView()->SetInteractionStyle(vtkGinkgoImageViewer::ZOOM_WITH_SELECT_INTERACTION);
 
382
 
 
383
 
 
384
                        m_panelStep0->Layout();
 
385
                        m_panelStep0->Refresh();
 
386
                        Thaw();
 
387
                }
 
388
 
 
389
                void SelectImagesImportation::OnHidePreview(wxCommandEvent& )
 
390
                {
 
391
                        HidePreview();
 
392
                }
 
393
 
 
394
                void SelectImagesImportation::HidePreview()
 
395
                {
 
396
                        if (!m_pImagenes->IsShown())
 
397
                        {
 
398
                                Freeze();
 
399
                                m_pImagenes->Show();
 
400
                                m_pPreviewPanel->Hide();
 
401
                                m_pButtonRemoveAll->Show();
 
402
                                m_pButtonPreview->Show();
 
403
                                m_pButtonsBar->Show();
 
404
 
 
405
                                m_panelStep0->Layout();
 
406
                                m_panelStep0->Refresh();
 
407
                                Thaw();
 
408
                        }
220
409
                }
221
410
 
222
411
                void SelectImagesImportation::OnRemoveAll(wxCommandEvent &event){
223
 
                        m_pImagenes->Clear();
 
412
                        m_pImagenes->SelectAll();
 
413
                        DeleteSelectedThumbnails();
224
414
                        event.Skip();
225
415
                }
226
416
 
227
417
                void SelectImagesImportation::OnSelectFiles(wxCommandEvent & )
228
418
                {
229
 
                        AddImage();
230
 
                }
231
 
 
232
 
                void SelectImagesImportation::AddImage() {
 
419
                        UnCheckAll();
 
420
                        m_pDropTarget->SetEnable(true);
 
421
                        m_pTimerDirectory->Stop();
233
422
                        std::string pathDefecto;
234
423
                        GNC::GCS::ConfigurationController::Instance()->readStringUser("/GinkgoCore/Importacion", "PathDefecto", pathDefecto);
235
424
                        wxString wxPathDefecto = wxString::FromUTF8(pathDefecto.c_str());
272
461
 
273
462
                void SelectImagesImportation::AddImages(const wxArrayString& files)
274
463
                {
275
 
                        wxBusyInfo info(_("Creating Thumbnails..."));
276
464
                        for (wxArrayString::const_iterator it = files.begin(); it != files.end(); it++) {
277
465
                                const wxString& fileName = (*it);
278
466
                                if(m_pImagenes->FindItemForFilename(fileName)==-1){
 
467
                                        wxBusyInfo info(_("Creating Thumbnails..."));
279
468
                                        wxThumbnailItem* pItem = NULL;
280
469
                                        if (m_pDefaultImage.IsOk()) {
281
470
                                                pItem = new wxMemoryImageThumbnailItem(fileName, m_pDefaultImage);
283
472
                                                pItem = new wxImageThumbnailItem(fileName);
284
473
                                        }                                               
285
474
                                        m_pImagenes->Insert( pItem, m_pImagenes->GetCount());
286
 
                                }
287
 
                        }
288
 
                }
289
 
 
290
 
                wxArrayString SelectImagesImportation::GetSelectedPaths(){
 
475
                                        Update();
 
476
                                }
 
477
                        }
 
478
                }
 
479
 
 
480
                bool SelectImagesImportation::ScanPath(const wxString& path)
 
481
                {
 
482
                        //se leen los ficheros dicom del directorio
 
483
                        if (!wxDirExists(path)) {
 
484
                                return false;
 
485
                        }
 
486
 
 
487
                        wxDir dir;
 
488
                        if (dir.Open(path)) {
 
489
                                wxArrayString images;
 
490
                                for (std::list<std::string>::iterator itSpecs = m_fileSpecs.begin(); itSpecs != m_fileSpecs.end(); ++itSpecs) {
 
491
                                        wxString wxPathFich;
 
492
                                        bool cont = dir.GetFirst(&wxPathFich, wxString::FromUTF8((*itSpecs).c_str()));
 
493
                                        while (cont) {
 
494
                                                wxPathFich=dir.GetName()+ wxFileName::GetPathSeparator(wxPATH_NATIVE) +wxPathFich;      
 
495
                                                images.push_back(wxPathFich);                                                   
 
496
                                                cont = dir.GetNext(&wxPathFich);
 
497
                                        }
 
498
                                }
 
499
#if !defined(_WINDOWS)
 
500
                                for (std::list<std::string>::iterator itSpecs = m_fileSpecs.begin(); itSpecs != m_fileSpecs.end(); ++itSpecs) {
 
501
                                        wxString wxPathFich;
 
502
                                        bool cont = dir.GetFirst(&wxPathFich, wxString::FromUTF8((*itSpecs).c_str()).Upper());
 
503
                                        while (cont) {
 
504
                                                wxPathFich=dir.GetName()+ wxFileName::GetPathSeparator(wxPATH_NATIVE) +wxPathFich;      
 
505
                                                images.push_back(wxPathFich);                                                   
 
506
                                                cont = dir.GetNext(&wxPathFich);
 
507
                                        }
 
508
                                }
 
509
#endif
 
510
                                AddImages(images);
 
511
                        }
 
512
                        return true;
 
513
                }
 
514
 
 
515
                wxArrayString SelectImagesImportation::GetSelectedPaths()
 
516
                {
291
517
                        wxArrayString resultado;
292
518
                        for(int i=0;i<m_pImagenes->GetCount();++i){
293
519
                                wxThumbnailItem* item=dynamic_cast<wxThumbnailItem*>(m_pImagenes->GetItem(i));
298
524
                        return resultado;
299
525
                }
300
526
 
 
527
                void SelectImagesImportation::UnCheckAll()
 
528
                {
 
529
                        for (int i = 1; i < m_pButtonsBar->GetToolCount(); i++) {
 
530
                                //uncheck ubicaciones
 
531
                                m_pButtonsBar->ToggleTool(i, false);
 
532
                        }
 
533
                        m_pButtonsBar->Refresh(true);
 
534
                }
 
535
 
301
536
                void SelectImagesImportation::OnUbicacionClick(wxCommandEvent& event)
302
537
                {
303
538
                        int id = event.GetId();
 
539
                        if (id == 0) {
 
540
                                UnCheckAll();
 
541
                                m_pTimerDirectory->Stop();
 
542
                                m_pDropTarget->SetEnable(true);
 
543
                        } else {
 
544
                                GNC::GCS::IEntorno::MapaUbicaciones& mapa = GNC::Entorno::Instance()->GetUbicaciones();
 
545
                                GNC::GCS::IEntorno::MapaUbicaciones::iterator it = mapa.begin();
 
546
                                for (int i = 1; i != id && it != mapa.end(); i++, ++it);
 
547
                                if ((*it).second.Monitorize && !m_pButtonsBar->GetToolToggled(id)) {
 
548
                                        //if uncheck a monitorize change to normal mode
 
549
                                        UnCheckAll();
 
550
                                        m_pTimerDirectory->Stop();
 
551
                                        m_pDropTarget->SetEnable(true);
 
552
                                } else {
 
553
                                        SetUbicacion(&(*it).second, id);
 
554
                                }
 
555
                        }
 
556
                }
 
557
 
 
558
                void SelectImagesImportation::SetUbicacion(GIL::Ubicacion* ubicacion, int id)
 
559
                {
 
560
                        UnCheckAll();
 
561
                        m_pTimerDirectory->Stop();
 
562
                        m_pButtonsBar->ToggleTool(id, true);
 
563
                        if (!ubicacion->Monitorize) {
 
564
                                m_pDropTarget->SetEnable(true);
 
565
                                m_pTimerDirectory->SetPath(ubicacion->Ruta, false);
 
566
                        } else {
 
567
                                m_pDropTarget->SetEnable(false);
 
568
                                m_pImagenes->Clear();
 
569
                                m_pTimerDirectory->SetPath(ubicacion->Ruta,true);
 
570
                        }
 
571
                        if (ubicacion->CleanBefore) {
 
572
                                wxDir dir;
 
573
                                if (dir.Open(FROMPATH(ubicacion->Ruta))) {
 
574
                                        wxString fileName;
 
575
                                        bool cont = dir.GetFirst(&fileName);
 
576
                                        while (cont) {
 
577
                                                fileName=dir.GetName()+ wxFileName::GetPathSeparator(wxPATH_NATIVE) +fileName;
 
578
                                                if(wxFile::Exists(fileName)){
 
579
                                                        if (wxRemoveFile(fileName)) {
 
580
                                                                cont = dir.GetNext(&fileName);
 
581
                                                        } else {
 
582
                                                                break;
 
583
                                                        }
 
584
                                                }
 
585
                                        }
 
586
                                }
 
587
                        }
 
588
                        m_pTimerDirectory->Start(100, true);
 
589
                }
 
590
 
 
591
                GIL::Ubicacion* SelectImagesImportation::GetUbicacionSelected()
 
592
                {
304
593
                        GNC::GCS::IEntorno::MapaUbicaciones& mapa = GNC::Entorno::Instance()->GetUbicaciones();
305
594
                        GNC::GCS::IEntorno::MapaUbicaciones::iterator it = mapa.begin();
306
 
                        for (int i = 1; i != id && it != mapa.end(); i++, ++it);
307
 
                        GIL::Ubicacion& u = (*it).second;
308
 
                        wxString pathUbicacionWx = wxString::FromUTF8(u.Ruta.c_str());
309
 
                        AddImage(pathUbicacionWx);
 
595
                        for (int i = 1; i < m_pButtonsBar->GetToolCount() && it != mapa.end(); i++, ++it) {
 
596
                                if (m_pButtonsBar->GetToolToggled(i)) {
 
597
                                        return &(*it).second;
 
598
                                }
 
599
                        }
 
600
                        return NULL;
310
601
                }
311
602
 
312
603
//region "Metodos heredados de Ipasowizard"
313
604
 
314
605
                void SelectImagesImportation::Attach(wxSizer *sizer){
315
606
                        if (m_firstAttach) {
316
 
                                wxCommandEvent openDialogEvent(wxEVT_COMMAND_TOOL_CLICKED, 0);
317
 
                                m_pButtonsBar->AddPendingEvent(openDialogEvent);
 
607
                                //maybe an ubication, maybe a normal path...
 
608
                                std::string lastLocation;
 
609
                                GNC::GCS::ConfigurationController::Instance()->readStringUser("/GinkgoCore/Importacion", "LastLocation", lastLocation);
 
610
                                GNC::GCS::IEntorno::MapaUbicaciones& mapa = GNC::Entorno::Instance()->GetUbicaciones();
 
611
                                GNC::GCS::IEntorno::MapaUbicaciones::iterator it = mapa.begin();
 
612
                                int id = 1;
 
613
                                for (; id < m_pButtonsBar->GetToolCount() && it != mapa.end(); id++, ++it) {
 
614
                                        if ((*it).first == lastLocation) {
 
615
                                                break;
 
616
                                        }
 
617
                                }
 
618
                                if (it == mapa.end()) {
 
619
                                        //opens select file dialog...
 
620
                                        wxCommandEvent openDialogEvent(wxEVT_COMMAND_TOOL_CLICKED, 0);
 
621
                                        m_pButtonsBar->AddPendingEvent(openDialogEvent);
 
622
                                } else {
 
623
                                        SetUbicacion(&(*it).second, id);
 
624
                                }
318
625
                                m_firstAttach = false;
319
626
                        }
 
627
 
 
628
                        GIL::Ubicacion* pUbicacion = GetUbicacionSelected();
 
629
                        if (pUbicacion != NULL && pUbicacion->Monitorize) {
 
630
                                m_pTimerDirectory->Start(100,true);
 
631
                        }
320
632
                        Show(true);
321
633
                        sizer->Add(this, 1, wxEXPAND);
322
634
                        this->GetParent()->Layout();
323
635
                }
324
636
 
325
637
                void SelectImagesImportation::Detach(wxSizer *sizer){
 
638
                        m_pTimerDirectory->Stop();
326
639
                        Hide();
327
640
                        sizer->Detach(this);
328
641
                        sizer->GetContainingWindow()->Layout();
348
661
                        return true;
349
662
                }
350
663
 
 
664
                void SelectImagesImportation::OnCancelled()
 
665
                {
 
666
                        m_pTimerDirectory->Stop();
 
667
                        m_pImagenes->Clear();
 
668
                }
 
669
 
351
670
                bool SelectImagesImportation::Validar(){
352
671
                        wxArrayString paths=this->GetSelectedPaths();
353
672
                        if(paths.GetCount()==0){
357
676
                        }
358
677
 
359
678
                        m_pListaFicheros->clear();
360
 
 
361
 
                        wxString wxDirTemp = FROMPATH(m_dirTemp);
362
 
 
363
 
                        int dims[2] = {-1,-1};
364
 
                        //dimensiones del mas grande
365
 
                        GNC::GCS::Vector vectorMaximo(-1.0,-1.0);
366
 
                        GNC::GCS::Vector vectorOrigen(0.0,0.0);
367
 
                        //
368
 
                        bool redimensionar = false;
369
 
                        if (m_reescalar) {
370
 
                                //se leen las imagenes para ver que tengan la misma dimension
371
 
                                for(wxArrayString::iterator it=paths.begin();it!=paths.end();++it){
372
 
                                        if(!wxFileName::FileExists((*it))){
373
 
                                                wxString str(_("The file"));
374
 
                                                wxMessageBox(str <<(*it) <<_(" doesn't exist"), _("Info"),
375
 
                                                 wxOK | wxICON_INFORMATION, this);
376
 
                                                m_pListaFicheros->clear();
377
 
                                                //el fichero no existe
378
 
                                                return false;
379
 
                                        }
380
 
                                        wxImage img((*it));
381
 
                                        if(img.Ok())
 
679
                        GIL::Ubicacion* pUbicacion = GetUbicacionSelected();
 
680
 
 
681
                        if (pUbicacion != NULL) {
 
682
                                GNC::GCS::ConfigurationController::Instance()->writeStringUser("/GinkgoCore/Importacion", "LastLocation", pUbicacion->Titulo);
 
683
                        } else {
 
684
                                GNC::GCS::ConfigurationController::Instance()->deleteEntryUser("/GinkgoCore/Importacion", "LastLocation");
 
685
                        }
 
686
 
 
687
                        //file must exist
 
688
                        for(wxArrayString::iterator it=paths.begin();it!=paths.end();++it){
 
689
                                if(!wxFileName::FileExists((*it))){
 
690
                                        wxString str(_("The file"));
 
691
                                        wxMessageBox(str <<(*it) <<_(" doesn't exist"), _("Info"),
 
692
                                         wxOK | wxICON_INFORMATION, this);
 
693
                                        m_pListaFicheros->clear();
 
694
                                        //el fichero no existe
 
695
                                        return false;
 
696
                                }
 
697
                                
 
698
                                wxString wxDirTmp = FROMPATH(m_dirTemp);
 
699
                                wxFileName fileName((*it));
 
700
                                //if files will be cleaned at the end, we have to copy it in temporally folder
 
701
                                if (pUbicacion != NULL && pUbicacion->CleanAfter) {
 
702
                                        wxString nombreImagenTemporal = wxDirTmp + wxFileName::GetPathSeparator() + fileName.GetName() + wxString::Format(wxT("%d"),rand()) + wxT(".jpg");
 
703
                                        while(wxFile::Exists(nombreImagenTemporal))
382
704
                                        {
383
 
                                                if(dims[0]==-1 && dims[1]==-1){
384
 
                                                        dims[0]=img.GetWidth();
385
 
                                                        dims[1]=img.GetHeight();
386
 
                                                        vectorMaximo.x =(double) std::max<double>(img.GetWidth(),img.GetHeight());
387
 
                                                        vectorMaximo.y =(double) std::min<double>(img.GetWidth(),img.GetHeight());
388
 
                                                } else {
389
 
                                                        if(!( (dims[0] == img.GetWidth() && dims[1] == img.GetHeight()) || (dims[1] == img.GetWidth() && dims[0] == img.GetHeight()) )){
390
 
                                                                redimensionar = true;
391
 
                                                                GNC::GCS::Vector v1((double)std::max<double>(img.GetWidth(),img.GetHeight()),(double)std::min<double>(img.GetWidth(),img.GetHeight()));
392
 
                                                                if(!v1.DentroDeBoundingBox(vectorOrigen,vectorMaximo)){
393
 
                                                                        vectorMaximo.x = std::max<double>(vectorMaximo.x,v1.x);
394
 
                                                                        vectorMaximo.y = std::max<double>(vectorMaximo.y,v1.y);
395
 
                                                                }
396
 
                                                        }
397
 
                                                }
398
 
 
399
 
                                                wxFileName fileName((*it));
400
 
                                                std::string path(TOPATH((*it)));
401
 
                                                m_pListaFicheros->push_back(path);
402
 
                                        } else {
403
 
                                                wxString str(_("The file"));
404
 
                                                wxMessageBox(str <<(*it) <<_(" couldn't be readed"), _("Info"),
405
 
                                                 wxOK | wxICON_INFORMATION, this);
406
 
                                                m_pListaFicheros->clear();
407
 
                                                return false;
408
 
                                        }
409
 
                                }
410
 
 
411
 
                                //por ultimo si hay que redimensionar se redimensionan proporcionalmente y se rellena con negros
412
 
                                if (redimensionar && m_reescalar){
413
 
                                        int answer = wxMessageBox(_("All images must have the same dimensions.\nDo you want to continue resizing the images to the size of the largest?"),_("Different dimensions between images"), wxYES_NO , this);
414
 
                                        if (answer == wxNO) {
415
 
                                                m_pListaFicheros->clear();
416
 
                                                //el fichero no existe
417
 
                                                return false;
418
 
                                        }
419
 
                                        wxBusyInfo infoDlg(_("Scaling images, may take a while ..."), this);
420
 
                                        for(ListaFicheros::iterator it = m_pListaFicheros->begin(); it!= m_pListaFicheros->end(); it++){
421
 
                                                wxImage img(FROMPATH((*it)));
422
 
                                                if(!( (vectorMaximo.x == img.GetWidth() && vectorMaximo.y == img.GetHeight()) || (vectorMaximo.x == img.GetWidth() && vectorMaximo.y == img.GetHeight()) )){
423
 
                                                        //primero se rescala proporcionalmente
424
 
                                                        double scale;
425
 
                                                        if(img.GetHeight() > img.GetWidth()){
426
 
                                                                scale = (double)vectorMaximo.x / img.GetHeight();
427
 
                                                        } else {
428
 
                                                                scale = (double)vectorMaximo.x / img.GetWidth();
429
 
                                                        }
430
 
                                                        img = img.Rescale(img.GetWidth()*scale,img.GetHeight()*scale,wxIMAGE_QUALITY_HIGH);
431
 
                                                        //se cambia el tamaño hasta el maximo
432
 
                                                        if(img.GetHeight() > img.GetWidth()){
433
 
                                                                wxPoint punto((vectorMaximo.y / 2) - ((float)img.GetWidth()/2),0);
434
 
                                                                img = img.Resize(wxSize(vectorMaximo.y,vectorMaximo.x),punto,0,0,0);
435
 
                                                        } else {
436
 
                                                                wxPoint punto(0,(vectorMaximo.y / 2) - ((float)img.GetHeight()/2));
437
 
                                                                img = img.Resize(wxSize(vectorMaximo.x,vectorMaximo.y),punto,0,0,0);
438
 
                                                        }
439
 
 
440
 
                                                        wxFileName fileName(FROMPATH((*it)));
441
 
                                                        wxString nombreImagenTemporal = wxDirTemp + wxFileName::GetPathSeparator() + fileName.GetName() + wxString::Format(wxT("%d"),rand()) + wxT(".jpg");
442
 
                                                        while(wxFile::Exists(nombreImagenTemporal))
443
 
                                                        {
444
 
                                                                //si existe se busca uno que no exista
445
 
                                                                nombreImagenTemporal= wxDirTemp + wxFileName::GetPathSeparator() + fileName.GetName() + wxString::Format(wxT("%d"),rand()) + wxT(".jpg");
446
 
                                                        }
447
 
                                                        img.SetOption(wxIMAGE_OPTION_QUALITY,100);
448
 
                                                        img.SaveFile(nombreImagenTemporal);
449
 
                                                        (*it) = TOPATH(nombreImagenTemporal);
450
 
 
451
 
                                                }
452
 
                                        }
453
 
                                }
454
 
                        } else {
455
 
                                //file must exist
456
 
                                for(wxArrayString::iterator it=paths.begin();it!=paths.end();++it){
457
 
                                        if(!wxFileName::FileExists((*it))){
458
 
                                                wxString str(_("The file"));
459
 
                                                wxMessageBox(str <<(*it) <<_(" doesn't exist"), _("Info"),
460
 
                                                 wxOK | wxICON_INFORMATION, this);
461
 
                                                m_pListaFicheros->clear();
462
 
                                                //el fichero no existe
463
 
                                                return false;
464
 
                                        }
465
 
                                        
466
 
                                        wxFileName fileName((*it));
 
705
                                                //si existe se busca uno que no exista
 
706
                                                nombreImagenTemporal= wxDirTmp + wxFileName::GetPathSeparator() + fileName.GetName() + wxString::Format(wxT("%d"),rand()) + wxT(".jpg");
 
707
                                        }
 
708
                                        wxCopyFile((*it), nombreImagenTemporal);
 
709
                                        std::string path(TOPATH(nombreImagenTemporal));
 
710
                                        m_pListaFicheros->push_back(path);                                      
 
711
                                } else {
467
712
                                        std::string path(TOPATH((*it)));
468
713
                                        m_pListaFicheros->push_back(path);
469
714
                                }