comparison src/bprint.cpp @ 12:52958cd4a073

Implement Force Mask button in Batch Print Mode.
author pyon@macmini
date Sun, 18 May 2014 19:49:15 +0900
parents 4967d1e2b30c
children bbd65edf71d4
comparison
equal deleted inserted replaced
11:dfcf8c973219 12:52958cd4a073
1 // Filename : bprint.cpp 1 // Filename : bprint.cpp
2 // Last Change: 01-Nov-2013. 2 // Last Change: 16-May-2014.
3 // 3 //
4 4
5 #include "bprint.h" 5 #include "bprint.h"
6 #include "marksheet.h" 6 #include "marksheet.h"
7 #include "dndfile.h" 7 #include "dndfile.h"
53 bSizerButton->Add( 0, 20, 0, 0, 5 ); 53 bSizerButton->Add( 0, 20, 0, 0, 5 );
54 54
55 m_buttonClear = new wxButton( this, ID_BPCLEAR, wxT("クリア"), wxDefaultPosition, wxDefaultSize, 0 ); 55 m_buttonClear = new wxButton( this, ID_BPCLEAR, wxT("クリア"), wxDefaultPosition, wxDefaultSize, 0 );
56 bSizerButton->Add( m_buttonClear, 0, wxALL, 5 ); 56 bSizerButton->Add( m_buttonClear, 0, wxALL, 5 );
57 57
58 m_buttonPrint = new wxButton( this, ID_BPPRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 ); 58 m_buttonMaskPrint = new wxButton( this, ID_BPFFMP, wxT("FFMP"), wxDefaultPosition, wxDefaultSize, 0 );
59 bSizerButton->Add( m_buttonMaskPrint, 0, wxALL, 5 );
60
61 m_buttonPrint = new wxButton( this, ID_BPPRINT, wxT("一括印刷"), wxDefaultPosition, wxDefaultSize, 0 );
59 bSizerButton->Add( m_buttonPrint, 0, wxALL, 5 ); 62 bSizerButton->Add( m_buttonPrint, 0, wxALL, 5 );
63
64 m_buttonLdLog = new wxButton( this, ID_BPLDLOG, wxT("一括印刷ログ"), wxDefaultPosition, wxDefaultSize, 0 );
65 bSizerButton->Add( m_buttonLdLog, 0, wxALL, 5 );
66
67 bSizerButton->Add( 0, 20, 0, 0, 5 );
60 68
61 bSizerButton->Add( 0, 20, 0, 0, 5 ); 69 bSizerButton->Add( 0, 20, 0, 0, 5 );
62 70
63 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 ); 71 m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
64 m_buttonClose->SetDefault(); 72 m_buttonClose->SetDefault();
81 89
82 // Event Table 90 // Event Table
83 BEGIN_EVENT_TABLE( FrameBatchPrint, wxDialog ) 91 BEGIN_EVENT_TABLE( FrameBatchPrint, wxDialog )
84 EVT_GRID_CELL_CHANGING( FrameBatchPrint::OnInput ) 92 EVT_GRID_CELL_CHANGING( FrameBatchPrint::OnInput )
85 EVT_BUTTON( ID_BPCLEAR, FrameBatchPrint::OnClear ) 93 EVT_BUTTON( ID_BPCLEAR, FrameBatchPrint::OnClear )
94 EVT_BUTTON( ID_BPFFMP, FrameBatchPrint::OnMaskPrint )
86 EVT_BUTTON( ID_BPPRINT, FrameBatchPrint::OnPrint ) 95 EVT_BUTTON( ID_BPPRINT, FrameBatchPrint::OnPrint )
96 EVT_BUTTON( ID_BPLDLOG, FrameBatchPrint::OnLoadLog )
87 END_EVENT_TABLE() 97 END_EVENT_TABLE()
88 98
89 // Event Handlers & Functions 99 // Event Handlers & Functions
90 /* 氏名などを表示 */ 100 /* 氏名などを表示 */
91 void FrameBatchPrint::OnInput( wxGridEvent& event ) 101 void FrameBatchPrint::OnInput( wxGridEvent& event )
130 140
131 wxDir dir( path ); 141 wxDir dir( path );
132 if ( !dir.IsOpened() ) return; 142 if ( !dir.IsOpened() ) return;
133 143
134 wxString html; 144 wxString html;
135 html = html + wxT("<html><body>\n"); 145 html = wxT("<html><body>\n");
136 146
137 wxString file; 147 wxString file;
138 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); 148 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
139 bool notyet_mask = true; 149 bool notyet_mask = true;
140 int n = 0; 150 int n = 0;
186 log.Add( logmsg ); 196 log.Add( logmsg );
187 } 197 }
188 WriteLog( log ); 198 WriteLog( log );
189 } 199 }
190 200
201 /* 一枚目強制マスク印刷 */
202 void FrameBatchPrint::OnMaskPrint( wxCommandEvent& WXUNUSED(event) )
203 {
204 wxArrayInt rows = m_grid->GetSelectedRows();
205 if ( rows.GetCount() != 1 ) {
206 wxMessageDialog md( this, wxT("1件のみ選択してください."), wxT("Message"), wxOK|wxICON_INFORMATION );
207 md.ShowModal();
208 return;
209 }
210
211 wxString path = m_grid->GetCellValue( rows[0], 2 );
212 wxDir dir( path );
213 if ( !dir.IsOpened() ) return;
214
215 wxPrintDialogData pd;
216 wxPrinter p( &pd );
217 p.PrintDialog( NULL );
218
219 // 印刷用の html を作成
220 wxString file;
221 if ( dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ) ) {
222 wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH;
223 file = path + wxFILE_SEP_PATH + file;
224 file.Replace( wxFILE_SEP_PATH, wxT("/") );
225 wxString tmpjpg = wxString::Format( wxT("%stmp.jpg"), tmpdir );
226
227 wxImage img_org( file, wxBITMAP_TYPE_JPEG );
228 img_org.SetRGB( m_mask1, 255, 255, 255 ); // cm name
229 img_org.SetRGB( m_mask2, 255, 255, 255 ); // cm no.
230 img_org.SetRGB( m_mask3, 255, 255, 255 ); // barcode
231 img_org.SaveFile( tmpjpg );
232
233 wxString html;
234 html = wxT("<html><body>\n");
235 html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
236 html = html + wxT("</body></html>");
237
238 // start printing
239 wxHtmlPrintout hpout( wxT("Searcher03") );
240 hpout.SetMargins( 0, 0, 0, 0, 0 );
241 hpout.SetHtmlText( html, wxEmptyString, false );
242 p.Print( NULL, &hpout, false );
243 }
244 }
245
191 /* 入力禁止 */ 246 /* 入力禁止 */
192 void FrameBatchPrint::SetGridReadOnly( void ) 247 void FrameBatchPrint::SetGridReadOnly( void )
193 { 248 {
194 for ( int r = 0; r < m_grid->GetNumberRows(); r++ ) 249 for ( int r = 0; r < m_grid->GetNumberRows(); r++ )
195 for ( int c = 1; c < m_grid->GetNumberCols(); c++ ) 250 for ( int c = 1; c < m_grid->GetNumberCols(); c++ )
196 m_grid->SetReadOnly( r, c, true ); 251 m_grid->SetReadOnly( r, c, true );
197 } 252 }
198 253
199 /* 印刷ログ */ 254 /* 印刷ログ表示 */
255 void FrameBatchPrint::OnLoadLog( wxCommandEvent& WXUNUSED(event) )
256 {
257 wxFileDialog fd( this, wxT("Choose a file"), wxT("log"), wxEmptyString, wxT("log files (*.log)|bp_*.log"), wxFD_OPEN|wxFD_FILE_MUST_EXIST );
258 if ( fd.ShowModal() == wxID_CANCEL )
259 return;
260
261 m_grid->ClearGrid();
262
263 wxTextFile logfile;
264 logfile.Open( fd.GetPath() );
265
266 //
267 int d = logfile.GetLineCount() - m_grid->GetNumberRows();
268 if ( d > 0 )
269 m_grid->AppendRows( d, true );
270
271 wxArrayString hhsno;
272 wxString hhs, path, stat;
273 for ( int n = 0; n < logfile.GetLineCount(); n++ ) {
274 hhs = logfile[n].AfterLast( wxFILE_SEP_PATH );
275 stat = hhs.AfterFirst( ' ' );
276 hhs = hhs.BeforeFirst( ' ' );
277 path = logfile[n];
278 if ( !stat.IsEmpty() ) {
279 path = path.BeforeFirst( ' ' );
280 }
281 m_grid->SetCellValue( n, 0, hhs );
282 m_grid->SetCellValue( n, 2, path );
283 m_grid->SetCellValue( n, 3, stat );
284 hhsno.Add( hhs );
285 }
286 for ( int n = 0; n < hhsno.GetCount(); n++ ) {
287 wxArrayString info = wxSplit( GetHhsInfoByHhsNo( hhsno[n] ), '_', '\\' );
288 m_grid->SetCellValue( n, 1, info[0] );
289 }
290 logfile.Close();
291 }
292
293 /* 印刷ログ出力 */
200 void FrameBatchPrint::WriteLog( wxArrayString logline ) 294 void FrameBatchPrint::WriteLog( wxArrayString logline )
201 { 295 {
202 wxDateTime now = wxDateTime::Now(); 296 wxDateTime now = wxDateTime::Now();
203 wxString log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("bp_") + now.Format( wxT("%Y%m%d%H%M%S.log") ); 297 wxString log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log") + wxFILE_SEP_PATH + wxT("bp_") + now.Format( wxT("%Y%m%d%H%M%S.log") );
204 wxTextFile file( log_file ); 298 wxTextFile file( log_file );