~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/visualizator/visualizator/commands/pdfextractercommand.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  $Id: PDFExtracterCommandParameters.cpp $
4
 
 *  Ginkgo CADx Project
5
 
 *
6
 
 *  Copyright 2008-12 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
 
 */
14
 
#include <wx/dir.h>
15
 
#include <wx/file.h>
16
 
#include <wx/filename.h>
17
 
#include <wx/mimetype.h>
18
 
#include <wx/msgdlg.h>
19
 
 
20
 
#include <main/controllers/dicommanager.h>
21
 
#include <main/entorno.h>
22
 
 
23
 
#include "pdfextractercommand.h"
24
 
 
25
 
#define IDC_EXTRACTER          5002
26
 
 
27
 
// Singleton de persistencia
28
 
namespace GNKVisualizator {
29
 
        namespace GADAPI {
30
 
 
31
 
                PDFExtracterCommandParameters::PDFExtracterCommandParameters(const std::list<std::string>& rutas, const std::list<std::string>& dests, bool forOpening) 
32
 
                {                       
33
 
                        m_pathsOriginal.insert(m_pathsOriginal.begin(), rutas.begin(), rutas.end());
34
 
                        m_pathsExtracted.insert(m_pathsExtracted.begin(), dests.begin(), dests.end());
35
 
                        m_error = false;
36
 
                        m_ForOpening = forOpening;
37
 
                }
38
 
 
39
 
                PDFExtracterCommandParameters::~PDFExtracterCommandParameters() {
40
 
                }
41
 
 
42
 
 
43
 
                PDFExtracterCommand::PDFExtracterCommand(PDFExtracterCommandParameters* pParams) : IComando(pParams)
44
 
                {
45
 
                        m_pExtracterParameters = pParams;
46
 
                        SetId(IDC_EXTRACTER);
47
 
                        EsperaA(IDC_EXTRACTER);
48
 
                }
49
 
 
50
 
                void PDFExtracterCommand::Execute()
51
 
                {
52
 
                        
53
 
                        wxString wxPathDirectorioTemporal;
54
 
 
55
 
                        if (m_pExtracterParameters->m_pathsExtracted.empty()) {
56
 
                                wxPathDirectorioTemporal = FROMPATH(GNC::GCS::IEntorno::Instance()->CreateGinkgoTempDir());
57
 
                        }
58
 
 
59
 
                        class ProxyNotificador: public GNC::IProxyNotificadorProgreso 
60
 
                        {
61
 
                        public:
62
 
                                ProxyNotificador(PDFExtracterCommand* pCmd) {
63
 
                                        m_pCmd = pCmd;
64
 
                                }
65
 
 
66
 
                                virtual bool NotificarProgreso(float progresoNormalizado, const std::string& texto) 
67
 
                                {
68
 
                                        return m_pCmd->NotificarProgreso(progresoNormalizado, texto);                                   
69
 
                                }
70
 
                                PDFExtracterCommand* m_pCmd;
71
 
                        };
72
 
 
73
 
                        ProxyNotificador proxy(this);           
74
 
                        bool calculatePaths = m_pExtracterParameters->m_pathsExtracted.empty();
75
 
 
76
 
                        int i = 0;
77
 
                        for (std::vector<std::string>::iterator itRutas = m_pExtracterParameters->m_pathsOriginal.begin(); itRutas != m_pExtracterParameters->m_pathsOriginal.end(); ++itRutas) 
78
 
                        {
79
 
 
80
 
                                std::string stdFilePath;
81
 
                                if (calculatePaths) {
82
 
                                        wxString fpath = wxPathDirectorioTemporal + wxFileName::GetPathSeparator() + wxString::Format(wxT("%d.pdf"),i);
83
 
                                        stdFilePath = std::string( TOPATH(fpath) );
84
 
                                }
85
 
                                else {
86
 
                                        stdFilePath = m_pExtracterParameters->m_pathsExtracted.at(i);
87
 
                                }
88
 
                                //extract pdf data in temp directory...
89
 
                                GIL::DICOM::DICOMManager manager;
90
 
                                manager.CargarFichero((*itRutas));
91
 
                                //encapsulated pdf...
92
 
                                if (manager.ExtractTagToFile(0x0042, 0x0011, stdFilePath, &proxy)) {
93
 
                                        m_pExtracterParameters->m_pathsExtracted.push_back(stdFilePath);
94
 
                                } else {
95
 
                                        m_pExtracterParameters->m_error = true;
96
 
                                }
97
 
                                i++;
98
 
                        }
99
 
                }
100
 
 
101
 
                void PDFExtracterCommand::Update()
102
 
                {
103
 
                        if (m_pExtracterParameters->m_error) {
104
 
                                wxMessageBox(_("Error extracting pdf, Ginkgo CADx is unable to load this format"), _("Error"), wxOK);
105
 
                        }
106
 
                        if (m_pExtracterParameters->m_pathsExtracted.empty()) {
107
 
                                return;
108
 
                        }
109
 
 
110
 
                        if (m_pExtracterParameters->m_ForOpening) {
111
 
 
112
 
                                wxMimeTypesManager manager;
113
 
                                wxFileType* fileType = manager.GetFileTypeFromMimeType(wxT("application/pdf"));
114
 
                                if (fileType == NULL) {
115
 
                                        wxMessageBox(_("There isn't any pdf reader registered in the system"), _("Info"), wxICON_WARNING|wxOK);
116
 
                                        return;
117
 
                                }
118
 
 
119
 
                                for (std::vector<std::string>::iterator itRutas = m_pExtracterParameters->m_pathsExtracted.begin(); itRutas != m_pExtracterParameters->m_pathsExtracted.end(); ++itRutas) {
120
 
                                        wxString openCmd = fileType->GetOpenCommand(FROMPATH((*itRutas)));
121
 
                                        if (!openCmd.IsEmpty()) {
122
 
                                                wxExecute(openCmd);
123
 
                                        } else {
124
 
                                                wxMessageBox(_("There isn't any pdf reader registered in the system"), _("Info"), wxICON_WARNING|wxOK);
125
 
                                                break;
126
 
                                        }
127
 
                                }
128
 
                                delete fileType;
129
 
                //              wxMessageBox(_("PDF files will be opened with system's PDF reader..."), _("Info"), wxICON_INFORMATION | wxOK);
130
 
                        }
131
 
                        else {
132
 
                                wxMessageBox(_("PDF files extracted successfully..."), _("Info"), wxICON_INFORMATION | wxOK);
133
 
                        }
134
 
                }
135
 
 
136
 
                void PDFExtracterCommand::OnAbort()
137
 
                {
138
 
                }
139
 
 
140
 
                void PDFExtracterCommand::LiberarRecursos()
141
 
                {
142
 
                }
143
 
        }
144
 
}
145