Mercurial > mercurial > hgweb_mover2.cgi
comparison src/myframe.cpp @ 11:9b0840b0be7e
cache done.
| author | pyon@macmini |
|---|---|
| date | Sun, 23 Oct 2011 07:43:34 +0900 |
| parents | 1fda3a06c39b |
| children | 6ed3b64ed39a |
comparison
equal
deleted
inserted
replaced
| 10:1fda3a06c39b | 11:9b0840b0be7e |
|---|---|
| 1 // Filename : myframe.cpp | 1 // Filename : myframe.cpp |
| 2 // Last Change: 21-Oct-2011. | 2 // Last Change: 23-Oct-2011. |
| 3 // | 3 // |
| 4 | 4 |
| 5 #include "main.h" | 5 #include "main.h" |
| 6 #include "myframe.h" | 6 #include "myframe.h" |
| 7 #include "param.h" | 7 #include "param.h" |
| 8 #include "dndfile.h" | 8 #include "dndfile.h" |
| 9 #include "marksheet.h" | 9 #include "marksheet.h" |
| 10 #include "cache.h" | |
| 11 | 10 |
| 12 // resources | 11 // resources |
| 13 // the application icon (under Windows and OS/2 it is in resources and even | 12 // the application icon (under Windows and OS/2 it is in resources and even |
| 14 // though we could still include the XPM here it would be unused) | 13 // though we could still include the XPM here it would be unused) |
| 15 #if !defined(__WXMSW__) && !defined(__WXPM__) | 14 #if !defined(__WXMSW__) && !defined(__WXPM__) |
| 165 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP ); | 164 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP ); |
| 166 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); | 165 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); |
| 167 m_statusBar->SetStatusText( wxEmptyString, 0 ); | 166 m_statusBar->SetStatusText( wxEmptyString, 0 ); |
| 168 | 167 |
| 169 this->Centre( wxBOTH ); | 168 this->Centre( wxBOTH ); |
| 170 | 169 m_timer.SetOwner( this, ID_TIMER ); |
| 171 Cache cache; | |
| 172 } | 170 } |
| 173 | 171 |
| 174 // destructor | 172 // destructor |
| 175 MyFrame::~MyFrame() | 173 MyFrame::~MyFrame() |
| 176 { | 174 { |
| 177 } | 175 } |
| 178 | 176 |
| 179 // Event Table | 177 // Event Table |
| 180 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) | 178 BEGIN_EVENT_TABLE( MyFrame, wxFrame ) |
| 179 EVT_IDLE( MyFrame::OnIdle ) | |
| 180 EVT_TIMER( ID_TIMER, MyFrame::OnTimer ) | |
| 181 EVT_SIZE( MyFrame::OnWinSize ) | 181 EVT_SIZE( MyFrame::OnWinSize ) |
| 182 EVT_MOVE( MyFrame::OnWinMove ) | 182 EVT_MOVE( MyFrame::OnWinMove ) |
| 183 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam ) | 183 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam ) |
| 184 EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir ) | 184 EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir ) |
| 185 EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) | 185 EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) |
| 230 d.Append( wxFILE_SEP_PATH ); | 230 d.Append( wxFILE_SEP_PATH ); |
| 231 if ( !wxDirExists( d ) ) wxMkdir( d ); | 231 if ( !wxDirExists( d ) ) wxMkdir( d ); |
| 232 } | 232 } |
| 233 m_buttonMove->Enable(true); | 233 m_buttonMove->Enable(true); |
| 234 | 234 |
| 235 // TODO. | |
| 236 // make 申請書ふぉるだ | |
| 237 | |
| 235 wxMessageBox(wxT("移動先フォルダ準備完了")); | 238 wxMessageBox(wxT("移動先フォルダ準備完了")); |
| 236 wxString cmd = wxT("explorer ") + to; | 239 wxString cmd = wxT("explorer ") + to; |
| 237 wxExecute( cmd ); | 240 wxExecute( cmd ); |
| 238 } | 241 } |
| 239 /* 検知 */ | 242 /* 検知 */ |
| 299 void MyFrame::ReadyImage() | 302 void MyFrame::ReadyImage() |
| 300 { | 303 { |
| 301 wxString workdir = m_dirPickerWork->GetPath(); | 304 wxString workdir = m_dirPickerWork->GetPath(); |
| 302 wxDir dir( workdir ); | 305 wxDir dir( workdir ); |
| 303 if ( !dir.IsOpened() ) return; | 306 if ( !dir.IsOpened() ) return; |
| 307 // start-up iamge | |
| 304 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); | 308 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); |
| 305 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); | 309 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); |
| 306 m_bitmapName->SetBitmap( bmp ); | 310 m_bitmapName->SetBitmap( bmp ); |
| 307 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); | 311 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); |
| 308 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); | 312 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); |
| 309 m_bitmapHhsno->SetBitmap( bmp ); | 313 m_bitmapHhsno->SetBitmap( bmp ); |
| 310 | 314 |
| 315 // enum jpeg | |
| 311 wxArrayString filenames; | 316 wxArrayString filenames; |
| 312 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); | 317 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); |
| 313 | 318 |
| 314 m_listCtrlView->DeleteAllItems(); | 319 m_listCtrlView->DeleteAllItems(); |
| 315 m_imageList->RemoveAll(); | 320 m_imageList->RemoveAll(); |
| 317 wxString first; | 322 wxString first; |
| 318 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); | 323 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); |
| 319 pd.SetSize( wxSize(320,140) ); | 324 pd.SetSize( wxSize(320,140) ); |
| 320 float z; long l; | 325 float z; long l; |
| 321 for ( int i=0; i<n; i++ ) { | 326 for ( int i=0; i<n; i++ ) { |
| 327 /* | |
| 322 wxFileName f( filenames[i] ); | 328 wxFileName f( filenames[i] ); |
| 323 wxString filename = f.GetFullName(); | 329 wxString filename = f.GetFullName(); |
| 324 | 330 |
| 325 m_listCtrlView->InsertItem( i, filename ); | 331 m_listCtrlView->InsertItem( i, filename ); |
| 326 m_listCtrlView->SetItem( i, 0, filename, i ); | 332 m_listCtrlView->SetItem( i, 0, filename, i ); |
| 352 if ( IsMarksheet( filenames[i], &z, &l ) ) { | 358 if ( IsMarksheet( filenames[i], &z, &l ) ) { |
| 353 break; | 359 break; |
| 354 } | 360 } |
| 355 } | 361 } |
| 356 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); | 362 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); |
| 363 */ | |
| 357 | 364 |
| 358 // write log | 365 // write log |
| 359 pd.Update( i+1, wxT("画像認識中") ); | 366 pd.Update( i+1, wxT("画像認識中") ); |
| 360 } | 367 } |
| 361 | 368 |
| 363 } | 370 } |
| 364 | 371 |
| 365 /* 画像を選択 */ | 372 /* 画像を選択 */ |
| 366 void MyFrame::GetImageInfo(wxListEvent& event) | 373 void MyFrame::GetImageInfo(wxListEvent& event) |
| 367 { | 374 { |
| 375 /* | |
| 368 SetStatusText( wxEmptyString, 2 ); | 376 SetStatusText( wxEmptyString, 2 ); |
| 369 int i = event.GetIndex(); | 377 int i = event.GetIndex(); |
| 370 | 378 |
| 371 wxString filename = event.GetText(); | 379 wxString filename = event.GetText(); |
| 372 wxString workdir = m_dirPickerWork->GetPath(); | 380 wxString workdir = m_dirPickerWork->GetPath(); |
| 375 wxString msg; | 383 wxString msg; |
| 376 if ( IsMarksheet( imagefile, &b, &l ) ) { | 384 if ( IsMarksheet( imagefile, &b, &l ) ) { |
| 377 msg = wxT("perhaps marksheet !"); | 385 msg = wxT("perhaps marksheet !"); |
| 378 } | 386 } |
| 379 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, b, l ), 2 ); | 387 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, b, l ), 2 ); |
| 388 */ | |
| 380 } | 389 } |
| 381 | 390 |
| 382 /* 画像のスクリーン表示*/ | 391 /* 画像のスクリーン表示*/ |
| 383 void MyFrame::ViewLarge(wxListEvent& event) | 392 void MyFrame::ViewLarge(wxListEvent& event) |
| 384 { | 393 { |
| 407 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax ); | 416 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax ); |
| 408 } | 417 } |
| 409 pd->Destroy(); | 418 pd->Destroy(); |
| 410 } | 419 } |
| 411 | 420 |
| 421 /* キャッシュ作成&更新 */ | |
| 422 void MyFrame::UpdateCache() | |
| 423 { | |
| 424 wxString workdir = m_dirPickerWork->GetPath(); | |
| 425 wxDir dir( workdir ); | |
| 426 if ( !dir.IsOpened() ) return; | |
| 427 wxArrayString filenames; | |
| 428 | |
| 429 wxListItem item; | |
| 430 wxString first; | |
| 431 float z; long l; | |
| 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 ); | |
| 443 for ( int i=0; i<n; i++ ) { | |
| 444 CacheItem* ci = new CacheItem; | |
| 445 if ( CH.count(filenames[i]) ) { | |
| 446 ci = CH[filenames[i]]; | |
| 447 ci->exists = true; | |
| 448 continue; | |
| 449 } | |
| 450 ci->filename = filenames[i]; | |
| 451 m = IsMarksheet( filenames[i], &z, &l ); | |
| 452 wxImage image( filenames[i], wxBITMAP_TYPE_JPEG ); | |
| 453 wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) ); | |
| 454 ci->marksheet = m; | |
| 455 ci->z = z; | |
| 456 ci->l = l; | |
| 457 ci->exists = true; | |
| 458 ci->thumbnail = bmp; | |
| 459 ci->modtime = wxEmptyString; // TODO. | |
| 460 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 ) ); | |
| 462 } | |
| 463 for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) { | |
| 464 CacheItem* ci = new CacheItem; | |
| 465 ci = i->second; | |
| 466 if ( !ci->exists ) { | |
| 467 CH.erase(ci->filename); | |
| 468 wxGetApp().WriteLog( ci->filename + wxT(" removed.") ); | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 SetStatusText( wxEmptyString, 0 ); | |
| 473 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart | |
| 474 } | |
| 475 | |
| 412 // 以下,定型もの | 476 // 以下,定型もの |
| 477 void MyFrame::OnTimer(wxTimerEvent& event) | |
| 478 { | |
| 479 UpdateCache(); | |
| 480 } | |
| 481 /* アイドリング */ | |
| 482 void MyFrame::OnIdle(wxIdleEvent& event) | |
| 483 { | |
| 484 if ( !m_timer.IsRunning() ) { | |
| 485 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); | |
| 486 } | |
| 487 event.RequestMore(); | |
| 488 event.Skip(); | |
| 489 } | |
| 490 | |
| 413 /* アプリフォルダを開く */ | 491 /* アプリフォルダを開く */ |
| 414 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event)) | 492 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event)) |
| 415 { | 493 { |
| 416 wxString appdir = wxGetCwd(); | 494 wxString appdir = wxGetCwd(); |
| 417 wxString execmd = wxT("explorer ") + appdir; | 495 wxString execmd = wxT("explorer ") + appdir; |
