Mercurial > mercurial > hgweb_golang.cgi
comparison src/kaigo/horori/alloc/alloc.cpp @ 45:20b42e2deae1
add alloc, (new)mover, merger & (new)searcher.
| author | pyon@macmini |
|---|---|
| date | Thu, 16 Apr 2020 20:59:35 +0900 |
| parents | |
| children | 4e14902379da |
comparison
equal
deleted
inserted
replaced
| 44:b50f2a581cf8 | 45:20b42e2deae1 |
|---|---|
| 1 // Filename : alloc.cpp | |
| 2 // Last Change: 2020-04-16 木 12:26:33. | |
| 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> | |
| 9 #include <wx/fileconf.h> | |
| 10 | |
| 11 #include "alloc.h" | |
| 12 | |
| 13 | |
| 14 AllocFrame::AllocFrame(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) | |
| 15 : wxFrame(parent, id, title, pos, size, style) | |
| 16 { | |
| 17 CreateControls(); | |
| 18 InitializeControlsValue(); | |
| 19 m_buttonAlloc->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AllocFrame::OnAlloc), NULL, this); | |
| 20 } | |
| 21 | |
| 22 AllocFrame::~AllocFrame() | |
| 23 { | |
| 24 m_buttonAlloc->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(AllocFrame::OnAlloc), NULL, this); | |
| 25 } | |
| 26 | |
| 27 /* Functions */ | |
| 28 void AllocFrame::CreateControls() | |
| 29 { | |
| 30 this->SetIcon(wxIcon(wxT("sample"))); | |
| 31 this->SetSizeHints(wxDefaultSize, wxDefaultSize); | |
| 32 this->SetBackgroundColour(wxColour(196, 234, 170)); | |
| 33 wxSize pksz = wxSize(330, -1); | |
| 34 | |
| 35 wxFlexGridSizer* fgSizer = new wxFlexGridSizer(0, 2, 0, 0); | |
| 36 fgSizer->SetFlexibleDirection(wxBOTH); | |
| 37 fgSizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); | |
| 38 | |
| 39 m_staticTextPdf = new wxStaticText(this, wxID_ANY, wxT("PDFファイル"), wxDefaultPosition, wxDefaultSize, 0); | |
| 40 fgSizer->Add(m_staticTextPdf, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5); | |
| 41 | |
| 42 m_filePickerPdf1 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_CHANGE_DIR|wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL); | |
| 43 fgSizer->Add(m_filePickerPdf1, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 44 | |
| 45 fgSizer->Add(0, 0, 1, wxEXPAND, 5); | |
| 46 | |
| 47 m_filePickerPdf2 = new wxFilePickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a file"), wxT("*.pdf"), wxDefaultPosition, pksz, wxFLP_CHANGE_DIR|wxFLP_FILE_MUST_EXIST|wxFLP_SMALL|wxFLP_USE_TEXTCTRL); | |
| 48 fgSizer->Add(m_filePickerPdf2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 49 | |
| 50 m_staticTextTif = new wxStaticText(this, wxID_ANY, wxT("TIFフォルダ"), wxDefaultPosition, wxDefaultSize, 0); | |
| 51 fgSizer->Add(m_staticTextTif, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); | |
| 52 | |
| 53 m_dirPickerTif = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_CHANGE_DIR|wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); | |
| 54 fgSizer->Add(m_dirPickerTif, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 55 | |
| 56 m_staticTextWork = new wxStaticText(this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0); | |
| 57 fgSizer->Add(m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5); | |
| 58 | |
| 59 m_dirPickerWork = new wxDirPickerCtrl(this, wxID_ANY, wxEmptyString, wxT("Select a folder"), wxDefaultPosition, pksz, wxDIRP_CHANGE_DIR|wxDIRP_DIR_MUST_EXIST|wxDIRP_SMALL|wxDIRP_USE_TEXTCTRL); | |
| 60 fgSizer->Add(m_dirPickerWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
| 61 | |
| 62 fgSizer->Add(0, 0, 1, wxEXPAND, 5); | |
| 63 | |
| 64 m_buttonAlloc = new wxButton(this, wxID_ANY, wxT("コピー"), wxDefaultPosition, wxDefaultSize, 0); | |
| 65 fgSizer->Add(m_buttonAlloc, 0, wxALL|wxALIGN_RIGHT, 5); | |
| 66 | |
| 67 this->SetSizer(fgSizer); | |
| 68 this->Layout(); | |
| 69 | |
| 70 this->Centre(wxBOTH); | |
| 71 | |
| 72 m_filePickerPdf1->SetDropTarget(new DnDFile(m_filePickerPdf1)); | |
| 73 m_filePickerPdf2->SetDropTarget(new DnDFile(m_filePickerPdf2)); | |
| 74 } | |
| 75 | |
| 76 void AllocFrame::InitializeControlsValue() | |
| 77 { | |
| 78 wxString conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("alloc.conf"); | |
| 79 wxFileConfig* conf = new wxFileConfig(wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE); | |
| 80 | |
| 81 wxString pdf1, pdf2, tiff, work; | |
| 82 conf->SetPath(wxT("/Files")); | |
| 83 conf->Read(wxT("pdf1"), &pdf1); | |
| 84 conf->Read(wxT("pdf2"), &pdf2); | |
| 85 conf->SetPath(wxT("/Dirs")); | |
| 86 conf->Read(wxT("tiff"), &tiff); | |
| 87 conf->Read(wxT("work"), &work); | |
| 88 | |
| 89 delete conf; | |
| 90 | |
| 91 m_filePickerPdf1->SetPath(pdf1); | |
| 92 m_filePickerPdf2->SetPath(pdf2); | |
| 93 m_dirPickerTif->SetPath(tiff); | |
| 94 m_dirPickerWork->SetPath(work); | |
| 95 } | |
| 96 | |
| 97 void AllocFrame::Pdf2Tif() | |
| 98 { | |
| 99 wxCopyFile(m_filePickerPdf1->GetPath(), m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("1.pdf")); | |
| 100 wxCopyFile(m_filePickerPdf2->GetPath(), m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("2.pdf")); | |
| 101 | |
| 102 wxString batchfile = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxT("alloc.bat"); | |
| 103 wxTextFile textfile; | |
| 104 | |
| 105 wxString cmd; | |
| 106 textfile.Create(batchfile); | |
| 107 | |
| 108 cmd = wxT("cd ") + m_dirPickerWork->GetPath(); | |
| 109 textfile.AddLine(cmd); | |
| 110 | |
| 111 cmd = wxT("\"C:\\Program Files\\gs\\gs9.50\\bin\\gswin64c.exe\" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=a.pdf 1.pdf 2.pdf"); | |
| 112 textfile.AddLine(cmd); | |
| 113 | |
| 114 for (int i = 0; i < 50; i++) { | |
| 115 cmd = wxString::Format(wxT("magick -density 400 a.pdf[%d] _%02d.jpg"), i, i + 1); | |
| 116 textfile.AddLine(cmd); | |
| 117 } | |
| 118 | |
| 119 wxCSConv cust(wxT("cp932")); | |
| 120 textfile.Write(wxTextFileType_Dos, cust); | |
| 121 textfile.Close(); | |
| 122 | |
| 123 wxExecute(batchfile, wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE, NULL, NULL); | |
| 124 } | |
| 125 | |
| 126 void AllocFrame::AllocateTif() | |
| 127 { | |
| 128 wxDir dir(m_dirPickerTif->GetPath()); | |
| 129 if (!dir.IsOpened()) return; | |
| 130 | |
| 131 wxString filename; | |
| 132 bool cont = dir.GetFirst(&filename, wxT("*.tif"), wxDIR_FILES); | |
| 133 | |
| 134 for (int i = 0; cont; i++ ) { | |
| 135 wxString path = m_dirPickerWork->GetPath() + wxFILE_SEP_PATH + wxString::Format(wxT("%02d"), i / 8 + 1); | |
| 136 if (i % 8 == 0) wxFileName::Mkdir(path, wxS_DIR_DEFAULT, 0); | |
| 137 wxString fn = filename; | |
| 138 cont = dir.GetNext(&filename); | |
| 139 | |
| 140 if (i % 8 == 3 || i % 8 == 5 || i % 8 == 7) continue; | |
| 141 wxCopyFile(m_dirPickerTif->GetPath() + wxFILE_SEP_PATH + fn, path + wxFILE_SEP_PATH + fn); | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 /* Event Handlers */ | |
| 146 void AllocFrame::OnAlloc(wxCommandEvent& WXUNUSED(event)) | |
| 147 { | |
| 148 wxFileName::Rmdir(m_dirPickerWork->GetPath(), wxPATH_RMDIR_RECURSIVE); | |
| 149 wxFileName::Mkdir(m_dirPickerWork->GetPath(), wxS_DIR_DEFAULT, 0); | |
| 150 | |
| 151 Pdf2Tif(); | |
| 152 AllocateTif(); | |
| 153 wxMessageBox(wxT("コピー終了")); | |
| 154 | |
| 155 wxMessageDialog dlg(this, wxT("Mover を起動しますか?"), wxT("Question ?"), wxYES_NO); | |
| 156 if (dlg.ShowModal() == wxID_YES) { | |
| 157 wxExecute(wxT("mover.exe"), wxEXEC_ASYNC, NULL, NULL); | |
| 158 } | |
| 159 Close(); | |
| 160 } | |
| 161 |
