Mercurial > mercurial > hgweb_mover2.cgi
comparison src/myframe.cpp @ 12:6ed3b64ed39a
finish 'UpdateListImage'.
| author | pyon@macmini |
|---|---|
| date | Sun, 23 Oct 2011 20:29:33 +0900 |
| parents | 9b0840b0be7e |
| children | df439f9831d2 |
comparison
equal
deleted
inserted
replaced
| 11:9b0840b0be7e | 12:6ed3b64ed39a |
|---|---|
| 240 wxExecute( cmd ); | 240 wxExecute( cmd ); |
| 241 } | 241 } |
| 242 /* 検知 */ | 242 /* 検知 */ |
| 243 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event)) | 243 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event)) |
| 244 { | 244 { |
| 245 ReadyImage(); | 245 UpdateCache(); |
| 246 UpdateListImage(); | |
| 246 } | 247 } |
| 247 | 248 |
| 248 /* 選択したファイルを移動 */ | 249 /* 選択したファイルを移動 */ |
| 249 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event)) | 250 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event)) |
| 250 { | 251 { |
| 260 | 261 |
| 261 wxString file = m_listCtrlView->GetItemText( item ); | 262 wxString file = m_listCtrlView->GetItemText( item ); |
| 262 wxString from = workdir + wxFILE_SEP_PATH + file; | 263 wxString from = workdir + wxFILE_SEP_PATH + file; |
| 263 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file; | 264 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file; |
| 264 wxRenameFile( from, to, true ); | 265 wxRenameFile( from, to, true ); |
| 265 m_undo.Insert( wxT("move ") + to + wxT(" ") + from, 0 ); | 266 |
| 266 } | 267 wxString movecmd = MOVECMD; |
| 267 ReadyImage(); | 268 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 ); |
| 269 } | |
| 270 UpdateCache(); | |
| 271 UpdateListImage(); | |
| 268 m_buttonUndo->Enable(true); | 272 m_buttonUndo->Enable(true); |
| 269 } | 273 } |
| 270 /* 選択したファイルを削除 */ | 274 /* 選択したファイルを削除 */ |
| 271 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) | 275 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event)) |
| 272 { | 276 { |
| 279 if ( item == -1 ) break; | 283 if ( item == -1 ) break; |
| 280 wxString file = m_listCtrlView->GetItemText( item ); | 284 wxString file = m_listCtrlView->GetItemText( item ); |
| 281 wxString from = workdir + wxFILE_SEP_PATH + file; | 285 wxString from = workdir + wxFILE_SEP_PATH + file; |
| 282 wxString to = trash + wxFILE_SEP_PATH + file; | 286 wxString to = trash + wxFILE_SEP_PATH + file; |
| 283 wxRenameFile( from, to, true ); | 287 wxRenameFile( from, to, true ); |
| 284 m_undo.Insert( wxT("move ") + to + wxT(" ") + from, 0 ); | 288 |
| 285 } | 289 wxString movecmd = MOVECMD; |
| 286 ReadyImage(); | 290 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 ); |
| 291 } | |
| 292 UpdateCache(); | |
| 293 UpdateListImage(); | |
| 287 m_buttonUndo->Enable(true); | 294 m_buttonUndo->Enable(true); |
| 288 } | 295 } |
| 289 /* アンドゥ */ | 296 /* アンドゥ */ |
| 290 void MyFrame::OnUndo(wxCommandEvent& WXUNUSED(event)) | 297 void MyFrame::OnUndo(wxCommandEvent& WXUNUSED(event)) |
| 291 { | 298 { |
| 293 wxExecute( m_undo[i] ); | 300 wxExecute( m_undo[i] ); |
| 294 } | 301 } |
| 295 wxMessageBox(wxT("戻し完了.")); | 302 wxMessageBox(wxT("戻し完了.")); |
| 296 m_buttonUndo->Enable(false); | 303 m_buttonUndo->Enable(false); |
| 297 m_undo.Clear(); | 304 m_undo.Clear(); |
| 298 ReadyImage(); | 305 UpdateCache(); |
| 306 UpdateListImage(); | |
| 299 } | 307 } |
| 300 | 308 |
| 301 /* 画像をリストコントロールに表示 */ | 309 /* 画像をリストコントロールに表示 */ |
| 302 void MyFrame::ReadyImage() | 310 void MyFrame::UpdateListImage() |
| 303 { | 311 { |
| 304 wxString workdir = m_dirPickerWork->GetPath(); | |
| 305 wxDir dir( workdir ); | |
| 306 if ( !dir.IsOpened() ) return; | |
| 307 // start-up iamge | 312 // start-up iamge |
| 308 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); | 313 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); |
| 309 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); | 314 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); |
| 310 m_bitmapName->SetBitmap( bmp ); | 315 m_bitmapName->SetBitmap( bmp ); |
| 311 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); | 316 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); |
| 312 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); | 317 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); |
| 313 m_bitmapHhsno->SetBitmap( bmp ); | 318 m_bitmapHhsno->SetBitmap( bmp ); |
| 314 | 319 |
| 315 // enum jpeg | 320 // 本処理 |
| 316 wxArrayString filenames; | |
| 317 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); | |
| 318 | |
| 319 m_listCtrlView->DeleteAllItems(); | 321 m_listCtrlView->DeleteAllItems(); |
| 320 m_imageList->RemoveAll(); | 322 m_imageList->RemoveAll(); |
| 321 wxListItem item; | 323 wxListItem item; |
| 322 wxString first; | |
| 323 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); | 324 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); |
| 324 pd.SetSize( wxSize(320,140) ); | 325 pd.SetSize( wxSize(320,140) ); |
| 325 float z; long l; | 326 |
| 326 for ( int i=0; i<n; i++ ) { | 327 wxArrayString keys; |
| 327 /* | 328 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) { |
| 328 wxFileName f( filenames[i] ); | 329 keys.Add(it->first); |
| 329 wxString filename = f.GetFullName(); | 330 } |
| 330 | 331 bool select = true; |
| 331 m_listCtrlView->InsertItem( i, filename ); | 332 keys.Sort(); |
| 332 m_listCtrlView->SetItem( i, 0, filename, i ); | 333 for ( int i=0; i<keys.GetCount(); i++ ) { |
| 333 | 334 CacheItem* ci = new CacheItem; |
| 334 wxImage image( filenames[i], wxBITMAP_TYPE_JPEG ); | 335 ci = CH[keys[i]]; |
| 335 wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) ); | 336 m_listCtrlView->InsertItem( i, ci->filename ); |
| 336 m_imageList->Add( bmp ); | 337 m_listCtrlView->SetItem( i, 0, ci->filename, i ); |
| 337 | 338 m_imageList->Add( ci->thumbnail ); |
| 338 if ( i == 0 ) { | 339 |
| 339 IsMarksheet( filenames[i], &z, &l ); | 340 if ( i == 0 ) { // 1枚目はマークシートのはず |
| 340 first = filenames[i]; | 341 wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG ); |
| 341 SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),z,l), 1 ); | 342 |
| 342 | |
| 343 wxImage marksheet( first, wxBITMAP_TYPE_JPEG ); | |
| 344 wxImage name_image; | 343 wxImage name_image; |
| 345 name_image = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) ); | 344 name_image = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) ); |
| 346 wxBitmap name_bmp = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) ); | 345 wxBitmap name_bmp = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) ); |
| 347 m_bitmapName->SetBitmap( name_bmp ); | 346 m_bitmapName->SetBitmap( name_bmp ); |
| 348 | 347 |
| 349 wxImage hhsno_image; | 348 wxImage hhsno_image; |
| 350 hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) ); | 349 hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) ); |
| 351 wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) ); | 350 wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) ); |
| 352 m_bitmapHhsno->SetBitmap( hhsno_bmp ); | 351 m_bitmapHhsno->SetBitmap( hhsno_bmp ); |
| 353 | 352 |
| 354 wxString hhsno = GuessHhs( first ); | 353 wxString hhsno = GuessHhs( ci->fullpath ); |
| 355 m_textCtrlGuess->SetValue( hhsno ); | 354 m_textCtrlGuess->SetValue( hhsno ); |
| 355 SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 ); | |
| 356 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | |
| 356 } | 357 } |
| 357 else { | 358 else { // 2枚目以降で初めてマークシートを認識したら,それ以降は選択しない |
| 358 if ( IsMarksheet( filenames[i], &z, &l ) ) { | 359 if ( ci->marksheet ) select = false; |
| 359 break; | 360 if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
| 360 } | |
| 361 } | 361 } |
| 362 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | 362 |
| 363 */ | |
| 364 | |
| 365 // write log | |
| 366 pd.Update( i+1, wxT("画像認識中") ); | 363 pd.Update( i+1, wxT("画像認識中") ); |
| 367 } | 364 } |
| 368 | 365 |
| 369 SetStatusText( wxEmptyString, 2 ); | 366 SetStatusText( wxEmptyString, 2 ); |
| 370 } | 367 } |
| 419 } | 416 } |
| 420 | 417 |
| 421 /* キャッシュ作成&更新 */ | 418 /* キャッシュ作成&更新 */ |
| 422 void MyFrame::UpdateCache() | 419 void MyFrame::UpdateCache() |
| 423 { | 420 { |
| 421 m_buttonDetect->Enable(false); | |
| 422 wxGetApp().WriteLog( wxT("start updating cache") ); | |
| 423 SetStatusText( wxT("rebuiling cache..."), 0 ); | |
| 424 | |
| 425 /* キャッシュ存在フラグOFF */ | |
| 426 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) { | |
| 427 CacheItem* ci = new CacheItem; | |
| 428 ci = it->second; | |
| 429 ci->exists = false; | |
| 430 } | |
| 431 | |
| 424 wxString workdir = m_dirPickerWork->GetPath(); | 432 wxString workdir = m_dirPickerWork->GetPath(); |
| 425 wxDir dir( workdir ); | 433 wxDir dir( workdir ); |
| 426 if ( !dir.IsOpened() ) return; | 434 if ( !dir.IsOpened() ) return; |
| 435 | |
| 427 wxArrayString filenames; | 436 wxArrayString filenames; |
| 428 | |
| 429 wxListItem item; | 437 wxListItem item; |
| 430 wxString first; | 438 |
| 431 float z; long l; | 439 /* キャッシュ作成 */ |
| 432 bool m; | |
| 433 | |
| 434 wxGetApp().WriteLog( wxT("start updating cache") ); | |
| 435 SetStatusText( wxT("rebuiling cache..."), 0 ); | |
| 436 | |
| 437 for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) { | |
| 438 CacheItem* ci = new CacheItem; | |
| 439 ci = i->second; | |
| 440 ci->exists = false; | |
| 441 } | |
| 442 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); | 440 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); |
| 443 for ( int i=0; i<n; i++ ) { | 441 for ( int i=0; i<n; i++ ) { |
| 442 wxString fullpath = filenames[i]; | |
| 443 wxFileName f( fullpath ); | |
| 444 wxString file = f.GetFullName(); | |
| 445 | |
| 444 CacheItem* ci = new CacheItem; | 446 CacheItem* ci = new CacheItem; |
| 445 if ( CH.count(filenames[i]) ) { | 447 /* キャッシュ済みのものはスキップ */ |
| 446 ci = CH[filenames[i]]; | 448 if ( CH.count(file) ) { |
| 449 ci = CH[file]; | |
| 447 ci->exists = true; | 450 ci->exists = true; |
| 448 continue; | 451 continue; |
| 449 } | 452 } |
| 450 ci->filename = filenames[i]; | 453 /* 新しいファイルはキャッシュ */ |
| 451 m = IsMarksheet( filenames[i], &z, &l ); | 454 float z; long l; bool m = IsMarksheet( fullpath, &z, &l ); |
| 452 wxImage image( filenames[i], wxBITMAP_TYPE_JPEG ); | 455 wxImage image( fullpath, wxBITMAP_TYPE_JPEG ); |
| 453 wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) ); | 456 wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) ); |
| 457 | |
| 458 ci->filename = file; | |
| 459 ci->fullpath = fullpath; | |
| 454 ci->marksheet = m; | 460 ci->marksheet = m; |
| 455 ci->z = z; | 461 ci->z = z; |
| 456 ci->l = l; | 462 ci->l = l; |
| 457 ci->exists = true; | 463 ci->exists = true; |
| 458 ci->thumbnail = bmp; | 464 ci->thumbnail = bmp; |
| 459 ci->modtime = wxEmptyString; // TODO. | 465 ci->modtime = wxEmptyString; // TODO. |
| 466 | |
| 460 CH[ci->filename] = ci; // add hash | 467 CH[ci->filename] = ci; // add hash |
| 461 wxGetApp().WriteLog( filenames[i] + wxString::Format(wxT(" z=%f l=%d m=%d"), z, l, m ? 1 : 0 ) ); | 468 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) ); |
| 462 } | 469 } |
| 463 for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) { | 470 |
| 471 /* 存在しないファイルはキャッシュから削除 */ | |
| 472 wxArrayString removelist; | |
| 473 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) { | |
| 464 CacheItem* ci = new CacheItem; | 474 CacheItem* ci = new CacheItem; |
| 465 ci = i->second; | 475 ci = it->second; |
| 466 if ( !ci->exists ) { | 476 if ( !ci->exists ) removelist.Add( ci->filename ); |
| 467 CH.erase(ci->filename); | 477 } |
| 468 wxGetApp().WriteLog( ci->filename + wxT(" removed.") ); | 478 for ( int i=0; i<removelist.GetCount(); i++ ) { |
| 469 } | 479 CH.erase(removelist[i]); |
| 470 } | 480 wxGetApp().WriteLog( removelist[i] + wxT(" removed.") ); |
| 471 | 481 } |
| 482 | |
| 483 m_buttonDetect->Enable(true); | |
| 472 SetStatusText( wxEmptyString, 0 ); | 484 SetStatusText( wxEmptyString, 0 ); |
| 473 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart | 485 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart |
| 474 } | 486 } |
| 475 | 487 |
| 476 // 以下,定型もの | 488 // 以下,定型もの |
