45
|
1 // Filename : alloc.cpp
|
65
|
2 // Last Change: 2021-05-10 月 10:53:23.
|
45
|
3 //
|
|
4 #include <wx/dir.h>
|
|
5 #include <wx/filefn.h>
|
|
6 #include <wx/textfile.h>
|
|
7 #include <wx/utils.h>
|
|
8 #include <wx/msgdlg.h>
|
65
|
9 #include <wx/progdlg.h>
|
|
10 #include <wx/filename.h>
|
45
|
11 #include <wx/fileconf.h>
|
|
12
|
|
13 #include "alloc.h"
|
|
14
|
65
|
15 #define WIDTH 2480
|
|
16 #define HEIGHT 3508
|
|
17
|
45
|
18
|
|
19 AllocFrame::AllocFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
|
|
20 : wxFrame(parent, id, title, pos, size, style)
|
|
21 {
|
|
22 CreateControls();
|
|
23 InitializeControlsValue();
|
|
24 m_buttonAlloc->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AllocFrame::OnAlloc), NULL, this);
|
|
25 }
|
|
26
|
|
27 AllocFrame::~AllocFrame()
|
|
28 {
|
|
29 m_buttonAlloc->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AllocFrame::OnAlloc), NULL, this);
|
|
30 }
|
|
31
|
|
32 /* Functions */
|
|
33 void AllocFrame::CreateControls()
|
|
34 {
|
|
35 this->SetIcon(wxIcon(wxT("sample")));
|
|
36 this->SetSizeHints(wxDefaultSize, wxDefaultSize);
|
|
37 this->SetBackgroundColour(wxColour(196, 234, 170));
|
|
38 wxSize pksz = wxSize(330, -1);
|
|
39
|
|
40 wxFlexGridSizer* fgSizer = new wxFlexGridSizer(0, 2, 0, 0);
|
|
41 fgSizer->SetFlexibleDirection(wxBOTH);
|
|
42 fgSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
|
|
43
|
|
44 m_staticTextPdf = new wxStaticText(this, wxID_ANY, wxT("PDFファイル"), wxDefaultPosition, wxDefaultSize, 0);
|
|
45 fgSizer->Add(m_staticTextPdf, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5);
|
|
46
|
51
|
47 m_filePickerPdf1 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL);
|
45
|
48 fgSizer->Add(m_filePickerPdf1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
49
|
|
50 fgSizer->Add(0, 0, 1, wxEXPAND, 5);
|
|
51
|
51
|
52 m_filePickerPdf2 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL);
|
45
|
53 fgSizer->Add(m_filePickerPdf2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
54
|
65
|
55 fgSizer->Add(0, 0, 1, wxEXPAND, 5);
|
|
56
|
|
57 m_checkBoxSkipPdf = new wxCheckBox(this, wxID_ANY, wxT("PDFからの変換をスキップする"), wxDefaultPosition, wxDefaultSize, 0);
|
|
58 fgSizer->Add(m_checkBoxSkipPdf, 0, wxALL, 5);
|
|
59
|
45
|
60 m_staticTextTif = new wxStaticText(this, wxID_ANY, wxT("TIFフォルダ"), wxDefaultPosition, wxDefaultSize, 0);
|
|
61 fgSizer->Add(m_staticTextTif, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5);
|
|
62
|
51
|
63 m_dirPickerTif = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL);
|
45
|
64 fgSizer->Add(m_dirPickerTif, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
65
|
65
|
66 fgSizer->Add(0, 0, 1, wxEXPAND, 5);
|
|
67
|
|
68 m_checkBoxJ2T = new wxCheckBox(this, wxID_ANY, wxT("JPEGから変換する"), wxDefaultPosition, wxDefaultSize, 0);
|
|
69 //m_checkBoxJ2T->SetValue(true);
|
|
70 fgSizer->Add(m_checkBoxJ2T, 0, wxALL, 5);
|
|
71
|
45
|
72 m_staticTextWork = new wxStaticText(this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0);
|
|
73 fgSizer->Add(m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5);
|
|
74
|
51
|
75 m_dirPickerWork = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL);
|
45
|
76 fgSizer->Add(m_dirPickerWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
|
|
77
|
|
78 fgSizer->Add(0, 0, 1, wxEXPAND, 5);
|
|
79
|
|
80 m_buttonAlloc = new wxButton(this, wxID_ANY, wxT("コピー"), wxDefaultPosition, wxDefaultSize, 0);
|
|
81 fgSizer->Add(m_buttonAlloc, 0, wxALL|wxALIGN_RIGHT, 5);
|
|
82
|
|
83 this->SetSizer(fgSizer);
|
|
84 this->Layout();
|
|
85
|
|
86 this->Centre(wxBOTH);
|
|
87
|
|
88 m_filePickerPdf1->SetDropTarget(new DnDFile(m_filePickerPdf1));
|
|
89 m_filePickerPdf2->SetDropTarget(new DnDFile(m_filePickerPdf2));
|
|
90 }
|
|
91
|
|
92 void AllocFrame::InitializeControlsValue()
|
|
93 {
|
|
94 wxString conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("alloc.conf");
|
|
95 wxFileConfig* conf = new wxFileConfig(wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
|
|
96
|
|
97 wxString pdf1, pdf2, tiff, work;
|
|
98 conf->SetPath(wxT("/Files"));
|
|
99 conf->Read(wxT("pdf1"), &pdf1);
|
|
100 conf->Read(wxT("pdf2"), &pdf2);
|
|
101 conf->SetPath(wxT("/Dirs"));
|
|
102 conf->Read(wxT("tiff"), &tiff);
|
|
103 conf->Read(wxT("work"), &work);
|
|
104
|
|
105 delete conf;
|
|
106
|
|
107 m_filePickerPdf1->SetPath(pdf1);
|
|
108 m_filePickerPdf2->SetPath(pdf2);
|
|
109 m_dirPickerTif->SetPath(tiff);
|
|
110 m_dirPickerWork->SetPath(work);
|
|
111 }
|
|
112
|
65
|
113 void AllocFrame::Pdf2Jpg()
|
45
|
114 {
|
52
|
115 wxString kanso = m_filePickerPdf1->GetPath();
|
|
116 wxString normal = m_filePickerPdf2->GetPath();
|
|
117
|
|
118 if (!kanso.IsEmpty())
|
|
119 wxCopyFile(kanso, m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("1.pdf"));
|
|
120 wxCopyFile(normal, m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("2.pdf"));
|
45
|
121
|
|
122 wxString batchfile = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("alloc.bat");
|
|
123 wxTextFile textfile;
|
|
124
|
|
125 wxString cmd;
|
|
126 textfile.Create(batchfile);
|
|
127
|
|
128 cmd = wxT("cd ") + m_dirPickerWork->GetPath();
|
|
129 textfile.AddLine(cmd);
|
|
130
|
52
|
131 //cmd = wxT("\"C:\\Program Files\\gs\\gs9.50\\bin\\gswin64c.exe\" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=a.pdf 1.pdf 2.pdf");
|
|
132 cmd = wxT("\"C:\\Program Files\\gs\\gs9.50\\bin\\gswin64c.exe\" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=a.pdf ");
|
|
133 if (!kanso.IsEmpty()) cmd += wxT("1.pdf ");
|
|
134 cmd += wxT("2.pdf");
|
45
|
135 textfile.AddLine(cmd);
|
|
136
|
|
137 for (int i = 0; i < 50; i++) {
|
|
138 cmd = wxString::Format(wxT("magick -density 400 a.pdf[%d] _%02d.jpg"), i, i + 1);
|
|
139 textfile.AddLine(cmd);
|
|
140 }
|
|
141
|
|
142 wxCSConv cust(wxT("cp932"));
|
|
143 textfile.Write(wxTextFileType_Dos, cust);
|
|
144 textfile.Close();
|
|
145
|
|
146 wxExecute(batchfile, wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE, NULL, NULL);
|
|
147 }
|
|
148
|
65
|
149 bool AllocFrame::AllocateTif()
|
45
|
150 {
|
54
|
151 wxArrayString files;
|
65
|
152 if (m_checkBoxJ2T->IsChecked()) // scansnap ix1400
|
|
153 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.jpg"), wxDIR_FILES);
|
|
154 else { // im c6000
|
|
155 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tif"), wxDIR_FILES);
|
|
156 if (files.GetCount() == 0)
|
|
157 wxDir::GetAllFiles(m_dirPickerTif->GetPath(), &files, wxT("*.tiff"), wxDIR_FILES);
|
|
158 }
|
54
|
159 files.Sort();
|
45
|
160
|
65
|
161 wxProgressDialog pd(wxT("Progress Dialog"), wxT("Wait a moment..."), files.GetCount(), this, wxPD_CAN_ABORT|wxPD_APP_MODAL|wxPD_ELAPSED_TIME|wxPD_ESTIMATED_TIME|wxPD_REMAINING_TIME);
|
|
162 bool cout = true;
|
54
|
163 for (int i = 0; i < files.GetCount(); i++ ) {
|
65
|
164 wxString work_path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1);
|
|
165 if (i % 8 == 0) wxFileName::Mkdir(work_path, wxS_DIR_DEFAULT, 0);
|
45
|
166 if (i % 8 == 3 || i % 8 == 5 || i % 8 == 7) continue;
|
65
|
167
|
|
168 wxFileName f(files[i]);
|
|
169 wxString outtif = work_path + wxFILE_SEP_PATH + f.GetName() + wxT(".tif");
|
|
170
|
|
171 if (m_checkBoxJ2T->IsChecked()) { // scansnap ix1400
|
|
172 wxImage jpg(files[i], wxBITMAP_TYPE_JPEG);
|
|
173 wxImage tif = jpg.Resize(wxSize(WIDTH, HEIGHT), wxPoint(0, 0), 255, 255, 255);
|
|
174 //wxImage tif = jpg.Scale(WIDTH, HEIGHT, wxIMAGE_QUALITY_NORMAL);
|
|
175 tif.SetOption(wxIMAGE_OPTION_RESOLUTIONUNIT, wxIMAGE_RESOLUTION_INCHES);
|
|
176 tif.SetOption(wxIMAGE_OPTION_RESOLUTION, 300);
|
|
177 tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 8); // ビットの深さ 1(b/w) or 8(rgb, greyscale)
|
|
178 tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1); // 2(rgb) or 0(greyscale) or 1(grayscale)
|
|
179 tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 1); // チャンネル数 1(greyscale) or 3(rgb)
|
|
180 tif.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 5); // 1(非圧縮), 2(ITU-T), 3(ファクシミリ互換のITU-T Group 3), 4(ファクシミリ互換のITU-T Group 4), 5(固定長コードLZW圧縮), 6(JPEG), 7(JPEG圧縮-2), 8(ZIP圧縮), 32773(Packbits圧縮)
|
|
181
|
|
182 /*
|
|
183 tif.SetOption(wxIMAGE_OPTION_TIFF_BITSPERSAMPLE, 1); // ビットの深さ 1(b/w) or 8(rgb, greyscale)
|
|
184 tif.SetOption(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 0); // 2(rgb) or 0(greyscale) or 1(grayscale)
|
|
185 //tif.SetOption(wxIMAGE_OPTION_TIFF_SAMPLESPERPIXEL, 3); // チャンネル数 1(greyscale) or 3(rgb)
|
|
186 tif.SetOption(wxIMAGE_OPTION_TIFF_COMPRESSION, 4); // 1(非圧縮), 2(ITU-T), 3(ファクシミリ互換のITU-T Group 3), 4(ファクシミリ互換のITU-T Group 4), 5(固定長コードLZW圧縮), 6(JPEG), 7(JPEG圧縮-2), 8(ZIP圧縮), 32773(Packbits圧縮)
|
|
187 tif.ConvertToGreyscale();
|
|
188 */
|
|
189 tif.SaveFile(outtif, wxBITMAP_TYPE_TIFF);
|
|
190 } else { // im c6000 (.tiff -> .tif)
|
|
191 wxCopyFile(f.GetFullPath(), outtif);
|
|
192 }
|
|
193
|
|
194 if (i == files.GetCount())
|
|
195 cout = pd.Update(i, wxT("Thanks !"));
|
|
196 if (i == files.GetCount() / 2)
|
|
197 cout = pd.Update(i, wxT("Only a half left !"));
|
|
198 else
|
|
199 cout = pd.Update(i);
|
|
200 if (!cout) {
|
|
201 if (wxMessageBox(wxT("Do you really want to cancel ?"), wxT("Question"), wxYES_NO|wxICON_QUESTION) == wxYES)
|
|
202 break;
|
|
203 pd.Resume();
|
|
204 }
|
45
|
205 }
|
65
|
206 return cout;
|
45
|
207 }
|
|
208
|
|
209 /* Event Handlers */
|
|
210 void AllocFrame::OnAlloc(wxCommandEvent& WXUNUSED(event))
|
|
211 {
|
|
212 wxFileName::Rmdir(m_dirPickerWork->GetPath(), wxPATH_RMDIR_RECURSIVE);
|
|
213 wxFileName::Mkdir(m_dirPickerWork->GetPath(), wxS_DIR_DEFAULT, 0);
|
|
214
|
65
|
215 if (AllocateTif()) {
|
|
216 wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO);
|
|
217 if (dlg.ShowModal() == wxID_YES) {
|
|
218 wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL);
|
|
219 }
|
45
|
220 }
|
65
|
221 if (!m_checkBoxSkipPdf->IsChecked()) Pdf2Jpg();
|
|
222 wxMessageBox(wxT("コピー完了"));
|
45
|
223 }
|
|
224
|