~ubuntu-branches/ubuntu/oneiric/ginkgocadx/oneiric

« back to all changes in this revision

Viewing changes to .pc/spelling.patch/src/cadxcore/commands/comandoexportacion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Tille
  • Date: 2011-05-02 08:09:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110502080926-tfd00s81ak843xk3
Tags: 2.4.1.1-1
Initial release (Closes: #628106)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
*  
 
3
*  $Id: comandoexportacion.cpp 3527 2011-03-16 21:45:37Z carlos $
 
4
*  Ginkgo CADx Project
 
5
*
 
6
*  Copyright 2008-10 MetaEmotion S.L. All rights reserved.
 
7
*  http://ginkgo-cadx.com
 
8
*
 
9
*  This file is licensed under LGPL v3 license.
 
10
*  See License.txt for details
 
11
*
 
12
*/
 
13
#ifdef _MSC_VER
 
14
#pragma warning(push)
 
15
#pragma warning(disable: 4996)
 
16
#endif
 
17
 
 
18
#include <sstream>
 
19
 
 
20
#include <wx/filename.h>
 
21
#include <wx/file.h>
 
22
#include <wx/dir.h>
 
23
#include <wx/confbase.h>
 
24
 
 
25
#include <api/globals.h>
 
26
#include <api/ientorno.h>
 
27
#include <api/internacionalizacion.h>
 
28
#include <api/icontextoestudio.h>
 
29
 
 
30
#include <main/entorno.h>
 
31
#include <main/controllers/controladoreventos.h>
 
32
 
 
33
#include <eventos/eventosginkgo.h>
 
34
 
 
35
#include "comandoexportacion.h"
 
36
 
 
37
#include <itkExceptionObject.h>
 
38
#include <itkImage.h>
 
39
#include <itkOrientedImage.h>
 
40
#include <itkRGBPixel.h>
 
41
#include <itkGDCMImageIO.h>
 
42
#include <itkJPEGImageIO.h>
 
43
#include <itkPNGImageIO.h>
 
44
#include <itkVectorResampleImageFilter.h>
 
45
#include <itkLinearInterpolateImageFunction.h>
 
46
#include <itkImageFileWriter.h>
 
47
 
 
48
 
 
49
 
 
50
namespace GADAPI {
 
51
 
 
52
        ComandoExportacion::ComandoExportacion(ComandoExportacionParams* pParams): GNC::GCS::IComando(pParams,"Exportacion")
 
53
        {
 
54
                m_pExportacionParams = pParams;
 
55
        }
 
56
 
 
57
        void ComandoExportacion::Execute()
 
58
        {
 
59
                if (!NotificarProgreso(0.0, _Std("Exporting files...")) )
 
60
                        return;
 
61
                if(m_pExportacionParams->m_pDatosPersistentes->m_formatoDestino == GNC::GUI::DICOM){
 
62
                        ExportarDICOM();
 
63
                }
 
64
                else{
 
65
                        ExportarImagenes();
 
66
                }
 
67
        }
 
68
 
 
69
        void ComandoExportacion::Update()
 
70
        {
 
71
                if (m_pExportacionParams->m_hasError)
 
72
                {
 
73
                        GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL,m_pExportacionParams->m_Error, GNC::GCS::Eventos::EventoMensajes::StatusMessage,true, GNC::GCS::Eventos::EventoMensajes::Error));
 
74
                } else {
 
75
                        GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Eventos::EventoMensajes(NULL, _Std("Export has been finished sucessfully"), GNC::GCS::Eventos::EventoMensajes::StatusMessage,true, GNC::GCS::Eventos::EventoMensajes::Informacion));
 
76
                }
 
77
        }
 
78
 
 
79
        //endregion
 
80
 
 
81
        void ComandoExportacion::ExportarDICOM()
 
82
        {
 
83
                GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
 
84
                bool correcto = true;
 
85
 
 
86
                std::vector<std::string> resultado;
 
87
                std::vector<std::string> listaPaths;
 
88
 
 
89
 
 
90
                if (pDatosPersistentes->m_ficheroActual) {
 
91
                        listaPaths.push_back(pDatosPersistentes->m_pVista->GetEstudio()->GetRutaDeImagenActiva());
 
92
                        if(pDatosPersistentes->m_exportarDiagnostico) {
 
93
                                listaPaths.push_back(pDatosPersistentes->m_pVista->GetEstudio()->GetRutaDeDiagnosticoActivo());
 
94
                        }
 
95
                }
 
96
                else
 
97
                {
 
98
                        listaPaths = pDatosPersistentes->m_pVista->GetRutasImagenes();
 
99
                        if(pDatosPersistentes->m_exportarDiagnostico) {
 
100
                                std::vector<std::string> diagnosticos;
 
101
                                diagnosticos = pDatosPersistentes->m_pVista->GetRutasDiagnosticos();
 
102
                                for(std::vector<std::string>::iterator it = diagnosticos.begin(); it!= diagnosticos.end(); it++) {
 
103
                                        listaPaths.push_back((*it));
 
104
                                }
 
105
                        }
 
106
                }
 
107
 
 
108
                GIL::DICOM::IDICOMManager*      pDICOMManager;
 
109
 
 
110
                wxString wxPath = FROMPATH(pDatosPersistentes->m_pathDestino);
 
111
                wxString destino(wxT(""));
 
112
 
 
113
                int contador = 1;
 
114
                for(std::vector<std::string>::iterator it = listaPaths.begin(); it!= listaPaths.end(); ++it,++contador) {
 
115
                        wxString cadena = wxString::Format(_("Exporting file %d of %d"), contador, listaPaths.size());
 
116
                        if (!NotificarProgreso((float)contador/listaPaths.size(), std::string(cadena.ToUTF8())))
 
117
                                return;
 
118
 
 
119
                        GIL::DICOM::TipoJerarquia base;
 
120
 
 
121
                        pDICOMManager = GNC::Entorno::Instance()->GetControladorImportacionPACS()->CrearInstanciaDeDICOMManager();
 
122
                        pDICOMManager->CargarFichero((*it), base);
 
123
 
 
124
                        pDICOMManager->ActualizarJerarquia(pDatosPersistentes->m_base);
 
125
 
 
126
                        //anonimizar tags Ginkgo
 
127
                        if(!pDatosPersistentes->m_incluirTagsGinkgo){
 
128
                                pDICOMManager->AnonimizarTagsPrivados();
 
129
                        }
 
130
 
 
131
                        wxString destino = GetFichero(wxPath,wxT("dcm"));
 
132
 
 
133
                        std::string destinoStd(TOPATH(destino));
 
134
                        correcto = correcto && pDICOMManager->AlmacenarFichero(destinoStd);
 
135
                        resultado.push_back(destinoStd);
 
136
                        GNC::Entorno::Instance()->GetControladorImportacionPACS()->LiberarInstanciaDeDICOMManager(pDICOMManager);
 
137
                }
 
138
 
 
139
                if(!correcto) {
 
140
                        m_pExportacionParams->m_Error = _Std("Error storing file, check the permissions over the directory.");
 
141
                        m_pExportacionParams->m_hasError = true;
 
142
                }
 
143
        }
 
144
 
 
145
 
 
146
        void ComandoExportacion::ExportarImagenes()
 
147
        {
 
148
                GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
 
149
                std::vector<std::string> resultado;
 
150
 
 
151
                GNC::GCS::IContratoExportacionImages* pContratoImages = dynamic_cast<GNC::GCS::IContratoExportacionImages*>(pDatosPersistentes->m_pVista);
 
152
 
 
153
                if(pContratoImages == NULL){
 
154
                        //error!!!! no deberia llegar porque en el paso uno no le deberia haber dejado seleccionar otra cosa que un dicom
 
155
                        m_pExportacionParams->m_Error = _Std("Unexpected Error exporting, the view is not allowed to export to the format selected");
 
156
                        m_pExportacionParams->m_hasError = true;
 
157
                        return ;
 
158
                }
 
159
 
 
160
                std::vector<std::string> listaPaths;
 
161
                GNC::GCS::IContratoExportacionImages::ImageType::Pointer img;
 
162
                try{
 
163
                        if(pDatosPersistentes->m_ficheroActual){
 
164
                                wxString cadena = wxString::Format(_("Exporting file %d of %d"), 1, 1);
 
165
                                if (!NotificarProgreso(0.2, std::string(cadena.ToUTF8())))
 
166
                                        return;
 
167
 
 
168
                                pContratoImages->GetImageActual(img, pDatosPersistentes->m_mapasValoracion, pDatosPersistentes->m_incluirWidgets, GNC::GCS::Vector::NaN());
 
169
                                wxString res=ExportarImage(img);
 
170
                                if(res!=wxEmptyString){
 
171
                                        std::string strTmp(TOPATH(res));
 
172
                                        resultado.push_back(strTmp);
 
173
                                }
 
174
                        }
 
175
                        else
 
176
                        {
 
177
                                int size = pDatosPersistentes->m_pVista->GetRutasImagenes().size();
 
178
                                for(std::string::size_type i = 0; (int)i < size; i++){
 
179
                                        wxString cadena = wxString::Format(_("Exporting file %d of %d"), i+1, size);
 
180
                                        if (!NotificarProgreso((float)i/size, std::string(cadena.ToUTF8())))
 
181
                                                return;
 
182
 
 
183
                                        pContratoImages->GetImage(img, i, pDatosPersistentes->m_mapasValoracion, pDatosPersistentes->m_incluirWidgets, GNC::GCS::Vector::NaN());
 
184
                                        wxString res = ExportarImage(img);
 
185
                                        if(res != wxEmptyString){
 
186
                                                std::string strTmp(TOPATH(res));
 
187
                                                resultado.push_back(strTmp);
 
188
                                        }
 
189
                                }
 
190
                        }
 
191
                }
 
192
                catch(itk::ExceptionObject& ex) {
 
193
                        std::cerr << "Error" << ex.GetDescription() << std::endl;
 
194
 
 
195
                        m_pExportacionParams->m_Error = _Std("Failed to store the file, check permissions on the directory");
 
196
                        m_pExportacionParams->m_hasError = true;
 
197
                }
 
198
        }
 
199
 
 
200
        wxString ComandoExportacion::ExportarImage(GNC::GCS::IContratoExportacionImages::ImageType::Pointer img)
 
201
        {
 
202
                GnkPtr<GNC::GUI::TipoWizardExportacion> pDatosPersistentes = m_pExportacionParams->m_pDatosPersistentes;
 
203
                if(img.IsNull()){
 
204
                        m_pExportacionParams->m_Error = _Std("The key files will not be exported");
 
205
                        m_pExportacionParams->m_hasError = true;
 
206
                        return wxEmptyString;
 
207
                }
 
208
 
 
209
                wxString destino = wxEmptyString;
 
210
 
 
211
                wxString wxPath = FROMPATH(pDatosPersistentes->m_pathDestino);
 
212
 
 
213
                typedef itk::ImageFileWriter<GNC::GCS::IContratoExportacionImages::ImageType> TipoWriter;
 
214
                TipoWriter::Pointer writer = TipoWriter::New();
 
215
                writer->SetInput(img);
 
216
 
 
217
 
 
218
                switch(pDatosPersistentes->m_formatoDestino) {
 
219
                        case GNC::GUI::BMP:
 
220
                                {
 
221
                                        destino = GetFichero(wxPath,wxT("bmp"));
 
222
                                        std::string strTmp (TOPATH(destino));
 
223
                                        writer->SetFileName(strTmp.c_str());
 
224
                                }
 
225
                                break;
 
226
                        case GNC::GUI::JPEG:
 
227
                                {
 
228
                                        destino = GetFichero(wxPath,wxT("jpg"));
 
229
                                        std::string strTmp (TOPATH(destino));
 
230
                                        writer->SetFileName(strTmp.c_str());
 
231
                                        itk::JPEGImageIO::Pointer imageIO = itk::JPEGImageIO::New();
 
232
                                        writer->SetImageIO(imageIO);
 
233
                                        imageIO->SetUseCompression(true);
 
234
                                        imageIO->SetQuality(pDatosPersistentes->m_jpegCalidad);
 
235
                                }
 
236
                                break;
 
237
                        case GNC::GUI::PNG:
 
238
                                {
 
239
                                        destino = GetFichero(wxPath,wxT("png"));
 
240
                                        std::string strTmp (TOPATH(destino));
 
241
                                        writer->SetFileName(strTmp.c_str());
 
242
                                }
 
243
                                break;
 
244
                        case GNC::GUI::DICOM:
 
245
                                break;
 
246
                }
 
247
 
 
248
                writer->Update();
 
249
                return destino;
 
250
        }
 
251
 
 
252
        wxString ComandoExportacion::GetFichero(const wxString& dir, const wxString& extension){
 
253
                wxString destino(wxEmptyString);
 
254
                std::string nombre (wxDateTime::Now().Format(_("image_%m-%d-%Y_")).ToUTF8());
 
255
                std::string stdDir(TOPATH(dir));
 
256
                std::string stdExtension(TOPATH(extension));
 
257
                int indice=0;
 
258
                //yy-mm-dd_imagen_indice
 
259
                do {
 
260
                        std::ostringstream ostr;
 
261
                        ostr << stdDir << (char)wxFileName::GetPathSeparator() << nombre << indice++ << "." << stdExtension;
 
262
                        destino = FROMPATH(ostr.str());
 
263
                } while(wxFile::Exists(destino));
 
264
                return destino;
 
265
        }
 
266
};
 
267
 
 
268
#ifdef _MSC_VER
 
269
#pragma warning(pop)
 
270
#endif
 
271