3
* $Id: PDFExtracterCommandParameters.cpp $
6
* Copyright 2008-12 MetaEmotion S.L. All rights reserved.
7
* http://ginkgo-cadx.com
9
* This file is licensed under LGPL v3 license.
10
* See License.txt for details
16
#include <wx/filename.h>
17
#include <wx/mimetype.h>
18
#include <wx/msgdlg.h>
20
#include <main/controllers/dicommanager.h>
21
#include <main/entorno.h>
23
#include "pdfextractercommand.h"
25
#define IDC_EXTRACTER 5002
27
// Singleton de persistencia
28
namespace GNKVisualizator {
31
PDFExtracterCommandParameters::PDFExtracterCommandParameters(const std::list<std::string>& rutas, const std::list<std::string>& dests, bool forOpening)
33
m_pathsOriginal.insert(m_pathsOriginal.begin(), rutas.begin(), rutas.end());
34
m_pathsExtracted.insert(m_pathsExtracted.begin(), dests.begin(), dests.end());
36
m_ForOpening = forOpening;
39
PDFExtracterCommandParameters::~PDFExtracterCommandParameters() {
43
PDFExtracterCommand::PDFExtracterCommand(PDFExtracterCommandParameters* pParams) : IComando(pParams)
45
m_pExtracterParameters = pParams;
47
EsperaA(IDC_EXTRACTER);
50
void PDFExtracterCommand::Execute()
53
wxString wxPathDirectorioTemporal;
55
if (m_pExtracterParameters->m_pathsExtracted.empty()) {
56
wxPathDirectorioTemporal = FROMPATH(GNC::GCS::IEntorno::Instance()->CreateGinkgoTempDir());
59
class ProxyNotificador: public GNC::IProxyNotificadorProgreso
62
ProxyNotificador(PDFExtracterCommand* pCmd) {
66
virtual bool NotificarProgreso(float progresoNormalizado, const std::string& texto)
68
return m_pCmd->NotificarProgreso(progresoNormalizado, texto);
70
PDFExtracterCommand* m_pCmd;
73
ProxyNotificador proxy(this);
74
bool calculatePaths = m_pExtracterParameters->m_pathsExtracted.empty();
77
for (std::vector<std::string>::iterator itRutas = m_pExtracterParameters->m_pathsOriginal.begin(); itRutas != m_pExtracterParameters->m_pathsOriginal.end(); ++itRutas)
80
std::string stdFilePath;
82
wxString fpath = wxPathDirectorioTemporal + wxFileName::GetPathSeparator() + wxString::Format(wxT("%d.pdf"),i);
83
stdFilePath = std::string( TOPATH(fpath) );
86
stdFilePath = m_pExtracterParameters->m_pathsExtracted.at(i);
88
//extract pdf data in temp directory...
89
GIL::DICOM::DICOMManager manager;
90
manager.CargarFichero((*itRutas));
92
if (manager.ExtractTagToFile(0x0042, 0x0011, stdFilePath, &proxy)) {
93
m_pExtracterParameters->m_pathsExtracted.push_back(stdFilePath);
95
m_pExtracterParameters->m_error = true;
101
void PDFExtracterCommand::Update()
103
if (m_pExtracterParameters->m_error) {
104
wxMessageBox(_("Error extracting pdf, Ginkgo CADx is unable to load this format"), _("Error"), wxOK);
106
if (m_pExtracterParameters->m_pathsExtracted.empty()) {
110
if (m_pExtracterParameters->m_ForOpening) {
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);
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()) {
124
wxMessageBox(_("There isn't any pdf reader registered in the system"), _("Info"), wxICON_WARNING|wxOK);
129
// wxMessageBox(_("PDF files will be opened with system's PDF reader..."), _("Info"), wxICON_INFORMATION | wxOK);
132
wxMessageBox(_("PDF files extracted successfully..."), _("Info"), wxICON_INFORMATION | wxOK);
136
void PDFExtracterCommand::OnAbort()
140
void PDFExtracterCommand::LiberarRecursos()