Mercurial > mercurial > hgweb_mover2.cgi
changeset 35:405e08552527 v2.4 v2.6
auto-detect on/off
author | pyon@macmini |
---|---|
date | Thu, 17 Nov 2011 21:03:30 +0900 |
parents | 51e522f34598 |
children | 73116df23be8 |
files | .hgignore TODO include/common.h include/main.h include/myframe.h src/main.cpp src/myframe.cpp |
diffstat | 7 files changed, 125 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sat Nov 12 13:18:03 2011 +0900 +++ b/.hgignore Thu Nov 17 21:03:30 2011 +0900 @@ -9,5 +9,7 @@ .DS_Store *.conf log +*.bak *~ *.jpg +include/wx/*
--- a/TODO Sat Nov 12 13:18:03 2011 +0900 +++ b/TODO Thu Nov 17 21:03:30 2011 +0900 @@ -1,17 +1,13 @@ ====================================================================== TODO ====================================================================== -v2.4 -* hhs name from db +v2.7 +* d&d image +* help -v2.5 +v2.8 * twain -v2.6 -* d&d image -* auto cache rebuild off -* help - ---------------------------------------------------------------------- Memo ----------------------------------------------------------------------
--- a/include/common.h Sat Nov 12 13:18:03 2011 +0900 +++ b/include/common.h Thu Nov 17 21:03:30 2011 +0900 @@ -1,5 +1,5 @@ // Filename : common.h -// Last Change: 05-Nov-2011. +// Last Change: 17-Nov-2011. // #ifndef __COMMON__ #define __COMMON__ @@ -45,6 +45,7 @@ ID_MENUBARFILE, ID_MENUITEMDETECT, ID_MENUITEMMOVE, + ID_MENUITEMAUTOD, ID_MENUITEMPARAM, ID_MENUITEMAPPDIR, @@ -64,15 +65,7 @@ ID_TIMER, // param - - // dirview }; -#if defined(__WXMSW__) - #define MOVECMD wxT("move") -#else - #define MOVECMD wxT("mv") -#endif - #endif // __COMMON__
--- a/include/main.h Sat Nov 12 13:18:03 2011 +0900 +++ b/include/main.h Thu Nov 17 21:03:30 2011 +0900 @@ -1,5 +1,5 @@ // Filename : main.h -// Last Change: 12-Nov-2011. +// Last Change: 17-Nov-2011. // #include "wx/wx.h" #include "wx/config.h" @@ -8,8 +8,8 @@ #define MYAPPNAME wxT("AMover2") #define VER 2 -#define REV 5 -#define BLD 20111114 +#define REV 6 +#define BLD 20111121 // private classes // Define a new application type, each program should derive a class from wxApp @@ -28,6 +28,7 @@ wxFileConfig *config; wxString conf_file; + wxString log_file; wxRect rect; wxString workdir;
--- a/include/myframe.h Sat Nov 12 13:18:03 2011 +0900 +++ b/include/myframe.h Thu Nov 17 21:03:30 2011 +0900 @@ -1,5 +1,5 @@ // Filename : myframe.h -// Last Change: 06-Nov-2011. +// Last Change: 17-Nov-2011. // #ifndef __myframe__ @@ -18,6 +18,9 @@ wxTimer m_timer; wxArrayString m_hhsList; CacheHash CH; + bool autodetect_mode; + bool by_autodetect; + bool cache_changed; protected: wxMenuBar* m_menubarFile; @@ -52,6 +55,8 @@ wxButton* m_buttonMove; wxButton* m_buttonDel; wxButton* m_buttonUndo; + + wxProgressDialog* pd; public: MyFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL ); @@ -63,14 +68,16 @@ void OnItemSelected(wxListEvent& event); void OnItemDeselected(wxListEvent& event); void ViewLarge(wxListEvent& event); + void ToggleAutoDetect(wxCommandEvent& event); void OnDetect(wxCommandEvent& event); void OnMove(wxCommandEvent& event); void OnDelete(wxCommandEvent& event); void OnUndo(wxCommandEvent& event); - void UpdateListImage(void); - void UpdateCache(void); - void ListHhsDir(void); - void MoveImages(void); + void UpdateListImage( void ); + void UpdateCache( void ); + void ClearGuess( void ); + void ListHhsDir( void ); + void MoveImages( void ); void OnOpenHhsDir(wxListEvent& event); void GetCCnArrayInfo(wxArrayString& array, int n, wxString& nName, wxString& nDir); // $B0J2<!$Dj7?$b$N(B
--- a/src/main.cpp Sat Nov 12 13:18:03 2011 +0900 +++ b/src/main.cpp Thu Nov 17 21:03:30 2011 +0900 @@ -1,5 +1,5 @@ // Filename : main.cpp -// Last Change: 26-Oct-2011. +// Last Change: 16-Nov-2011. // #include "common.h" @@ -90,18 +90,25 @@ void MyApp::InitLog() { wxDateTime now = wxDateTime::Now(); + log_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("log"); + + if ( wxFileExists( log_file ) ) { + wxString log_bak = log_file + wxT(".bak"); + wxRenameFile( log_file, log_bak, true ); + } + wxTextFile logfile; - logfile.Open(wxT("log")); - logfile.Clear(); + logfile.Create( log_file ); logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + wxT("[Application start...]") ); logfile.Write(); logfile.Close(); } + void MyApp::WriteLog( wxString msg ) { wxDateTime now = wxDateTime::Now(); wxTextFile logfile; - logfile.Open(wxT("log")); + logfile.Open( log_file ); logfile.AddLine( now.Format(wxT("%Y-%m-%d %H:%M:%S ")) + msg ); logfile.Write(); logfile.Close();
--- a/src/myframe.cpp Sat Nov 12 13:18:03 2011 +0900 +++ b/src/myframe.cpp Thu Nov 17 21:03:30 2011 +0900 @@ -1,5 +1,5 @@ // Filename : myframe.cpp -// Last Change: 12-Nov-2011. +// Last Change: 17-Nov-2011. // #include "main.h" @@ -15,6 +15,13 @@ #define THUMB_W 160 #define THUMB_H 226 +#if defined(__WXMSW__) + #define MOVECMD wxT("move") +#else + #define MOVECMD wxT("mv") +#endif + + // resources // the application icon (under Windows and OS/2 it is in resources and even // though we could still include the XPM here it would be unused) @@ -43,6 +50,12 @@ m_menuFile->Append( m_menuItemMove ); m_menuFile->AppendSeparator(); // ---- + wxMenuItem* m_menuItemAutoDetect; + m_menuItemAutoDetect = new wxMenuItem( m_menuFile, ID_MENUITEMAUTOD, wxString( wxT("自動検知\tF2") ) , wxEmptyString, wxITEM_CHECK ); + m_menuFile->Append( m_menuItemAutoDetect ); + m_menuItemAutoDetect->Check(true); + + m_menuFile->AppendSeparator(); // ---- wxMenuItem* m_menuItemParam; m_menuItemParam = new wxMenuItem( m_menuFile, ID_MENUITEMPARAM, wxString( wxT("パラメータ\tAlt+P") ) , wxEmptyString, wxITEM_NORMAL ); m_menuFile->Append( m_menuItemParam ); @@ -207,7 +220,13 @@ m_statusBar->SetStatusText( wxEmptyString, 0 ); this->Centre( wxBOTH ); + + autodetect_mode = true; m_timer.SetOwner( this, ID_TIMER ); + + pd = new wxProgressDialog( wxT("進行状況"), wxT("処理開始..."), 100, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); + pd->SetSize( wxSize(320,140) ); + pd->Update( 100, wxEmptyString ); } // destructor @@ -223,6 +242,7 @@ EVT_MOVE( MyFrame::OnWinMove ) EVT_MENU( ID_MENUITEMDETECT, MyFrame::OnDetect ) EVT_MENU( ID_MENUITEMMOVE, MyFrame::OnMove ) + EVT_MENU( ID_MENUITEMAUTOD, MyFrame::ToggleAutoDetect ) EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam ) EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir ) EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) @@ -240,6 +260,12 @@ END_EVENT_TABLE() // Event Handlers & Functions +void MyFrame::ToggleAutoDetect(wxCommandEvent& event) +{ + if ( event.IsChecked() ) autodetect_mode = true; + else autodetect_mode = false; +} + void MyFrame::GetCCnArrayInfo(wxArrayString& array , int n, wxString& nName, wxString& nDir) { if ( n == -1 ) { @@ -316,6 +342,7 @@ if ( !wxDirExists( d ) ) wxMkdir( d ); m_buttonMove->Enable(true); + m_listCtrlHhsDir->DeleteAllItems(); wxMessageBox(wxT("移動先フォルダ準備完了")); wxString cmd = wxT("explorer ") + to; @@ -324,9 +351,21 @@ /* 検知 */ void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event)) { + by_autodetect = false; UpdateCache(); + ClearGuess(); UpdateListImage(); } +void MyFrame::ClearGuess() +{ + // start-up iamge + wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); + wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); + m_bitmapName->SetBitmap( bmp ); + notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); + bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); + m_bitmapHhsno->SetBitmap( bmp ); +} /* 移動 */ void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event)) @@ -336,6 +375,7 @@ MoveImages(); UpdateCache(); + ClearGuess(); UpdateListImage(); ListHhsDir(); m_buttonUndo->Enable(true); @@ -347,7 +387,16 @@ m_undo.Clear(); wxString workdir = m_dirPickerWork->GetPath(); wxString distdir = m_textCtrlDist->GetValue(); - wxString hhsno = m_textCtrlGuess->GetValue(); + wxString hhsno = m_textCtrlGuess->GetValue(); + + wxString hhsdir = distdir + wxFILE_SEP_PATH + hhsno; + if ( !wxDirExists( hhsdir ) ) { + wxMkdir( hhsdir ); + wxGetApp().WriteLog( wxT("created distination directory - ") + hhsdir ); + } + else { + wxGetApp().WriteLog( wxT("set distination directory - ") + hhsdir ); + } m_hhsList.Remove(hhsno); m_hhsList.Add(hhsno); @@ -355,14 +404,16 @@ for ( ;; ) { item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if ( item == -1 ) break; - if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno ); - wxString file = m_listCtrlView->GetItemText( item ); + wxString file = m_listCtrlView->GetItemText( item ); wxString from = workdir + wxFILE_SEP_PATH + file; - wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file; + wxString to = hhsdir + wxFILE_SEP_PATH + file; wxRenameFile( from, to, true ); + wxGetApp().WriteLog( wxT("moved : ") + file ); wxString movecmd = MOVECMD; + from.Replace( wxT("\\"), wxT("\\\\"), true ); + to.Replace( wxT("\\"), wxT("\\\\"), true ); m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 ); } } @@ -380,11 +431,15 @@ wxString from = workdir + wxFILE_SEP_PATH + file; wxString to = trash + wxFILE_SEP_PATH + file; wxRenameFile( from, to, true ); + wxGetApp().WriteLog( wxT("deleted : ") + file ); wxString movecmd = MOVECMD; + from.Replace( wxT("\\"), wxT("\\\\"), true ); + to.Replace( wxT("\\"), wxT("\\\\"), true ); m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 ); } UpdateCache(); + ClearGuess(); UpdateListImage(); m_buttonUndo->Enable(true); } @@ -405,13 +460,7 @@ /* 画像をリストコントロールに表示 */ void MyFrame::UpdateListImage() { - // start-up iamge - wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png"); - wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG ); - m_bitmapName->SetBitmap( bmp ); - notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png"); - bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG ); - m_bitmapHhsno->SetBitmap( bmp ); + if ( !cache_changed && by_autodetect ) return; // 本処理 m_listCtrlView->DeleteAllItems(); @@ -419,28 +468,28 @@ wxListItem item; m_textCtrlGuess->SetBackgroundColour(*wxWHITE); - wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); - pd.SetSize( wxSize(320,140) ); + if ( by_autodetect ) pd->Update( 0, wxT("処理開始") ); wxArrayString keys; for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) { keys.Add(it->first); } keys.Sort(); - // イメージリストを作成 - for ( int i=0; i<keys.GetCount(); i++ ) { // item image + int kc = keys.GetCount(); + // イメージリストを作成(サムネイル) + for ( int i=0; i<kc; i++ ) { // item image CacheItem* ci = new CacheItem; ci = CH[keys[i]]; m_imageList->Add( ci->thumbnail ); } - for ( int i=0; i<keys.GetCount(); i++ ) { // item selected image + for ( int i=0; i<kc; i++ ) { // item selected image CacheItem* ci = new CacheItem; ci = CH[keys[i]]; m_imageList->Add( ci->selthumbnail ); } // アイテム作成 bool select = true; // flag - for ( int i=0; i<keys.GetCount(); i++ ) { + for ( int i=0; i<kc; i++ ) { CacheItem* ci = new CacheItem; ci = CH[keys[i]]; m_listCtrlView->InsertItem( i, ci->filename, i ); @@ -477,10 +526,10 @@ if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); } - pd.Update( i+1, wxT("画像認識中") ); + if ( !by_autodetect ) pd->Update( (int)(100/kc*(i+1)), wxT("画像認識中") ); } // 画像ファイル数が多ければ,おそらく申請書 - if ( keys.GetCount() > 32 ) { + if ( kc > 32 ) { int n = m_comboBoxCcn->GetCurrentSelection(); wxString ccndir, dummy; wxArrayString array; GetCCnArrayInfo( array, n, dummy, ccndir ); @@ -495,6 +544,7 @@ m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() ); } + by_autodetect = false; SetStatusText( wxEmptyString, 2 ); } @@ -539,7 +589,7 @@ wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) ); wxSplashScreen* splash = new wxSplashScreen( bmp, wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, - 3000, NULL, -1, wxDefaultPosition, wxDefaultSize, + 2500, NULL, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER|wxSTAY_ON_TOP ); wxYield(); } @@ -547,11 +597,11 @@ /* パラメータダイアログ */ void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event)) { - ParamDialog* pd = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") ); - if ( pd->ShowModal() == wxID_OK ) { - pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax ); + ParamDialog* parad = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") ); + if ( parad->ShowModal() == wxID_OK ) { + parad->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax ); } - pd->Destroy(); + parad->Destroy(); } /* キャッシュ作成&更新 */ @@ -580,6 +630,7 @@ wxListItem item; /* キャッシュ作成 */ + cache_changed = false; unsigned int n = wxDir::GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); for ( int i=0; i<n; i++ ) { wxString fullpath = filenames[i]; @@ -594,7 +645,6 @@ continue; } /* 新しいファイルはキャッシュ */ - //float z; long l; bool m = IsMarksheet( fullpath, &z, &l ); float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax ); wxImage image( fullpath, wxBITMAP_TYPE_JPEG ); wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH ); @@ -614,6 +664,7 @@ ci->modtime = wxEmptyString; // TODO. CH[ci->filename] = ci; // add hash + cache_changed = true; SetStatusText( wxString::Format( wxT("rebuiling cache...( %d/%d :%.1fsec passed )"), i+1, n, (float)sw.Time()/1000 ), 0 ); wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) ); } @@ -627,12 +678,13 @@ } for ( int i=0; i<removelist.GetCount(); i++ ) { CH.erase(removelist[i]); + cache_changed = true; wxGetApp().WriteLog( removelist[i] + wxT(" removed.") ); } m_buttonDetect->Enable(true); SetStatusText( wxEmptyString, 0 ); - m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart + m_timer.Start( 2*1000, wxTIMER_ONE_SHOT ); // restart } /* 被保険者フォルダを列挙 */ @@ -644,18 +696,18 @@ m_listCtrlHhsDir->DeleteAllItems(); for ( int i=0; i<m_hhsList.GetCount(); i++ ) { + unsigned int n = 0; + wxArrayString dummy; hhsdir = distdir + wxFILE_SEP_PATH + m_hhsList[i]; - wxArrayString filenames; - unsigned int n = 0; - if ( wxDirExists( hhsdir ) ) n = wxDir::GetAllFiles( hhsdir, &filenames, wxT("*.jpg"), wxDIR_FILES ); + if ( wxDirExists( hhsdir ) ) n = wxDir::GetAllFiles( hhsdir, &dummy, wxT("*.jpg"), wxDIR_FILES ); m_listCtrlHhsDir->InsertItem( i, -1 ); buf.Printf(wxT("%d"),i+1); - m_listCtrlHhsDir->SetItem( i, 0, buf, -1 ); - m_listCtrlHhsDir->SetItem( i, 1, m_hhsList[i], -1 ); + m_listCtrlHhsDir->SetItem( i, 0, buf, -1 ); // No + m_listCtrlHhsDir->SetItem( i, 1, m_hhsList[i], -1 ); // Hhsno buf.Printf(wxT("%d"),n); - m_listCtrlHhsDir->SetItem( i, 2, buf, -1 ); - m_listCtrlHhsDir->SetItem( i, 3, GetHhsName( m_hhsList[i]), -1 ); + m_listCtrlHhsDir->SetItem( i, 2, buf, -1 ); // file count + m_listCtrlHhsDir->SetItem( i, 3, GetHhsName( m_hhsList[i]), -1 ); // name if ( i % 2 ) m_listCtrlHhsDir->SetItemBackgroundColour( i, wxColour(wxT("WHEAT")) ); } } @@ -664,8 +716,7 @@ void MyFrame::OnOpenHhsDir(wxListEvent& event) { wxString hhsdir; - hhsdir.Append( m_textCtrlDist->GetValue() ); - hhsdir.Append( wxFILE_SEP_PATH ); + hhsdir = m_textCtrlDist->GetValue() + wxFILE_SEP_PATH; int i = event.GetIndex(); wxListItem item; @@ -682,7 +733,10 @@ /* 以下,定型もの ***********************************************/ void MyFrame::OnTimer(wxTimerEvent& event) { + if ( !autodetect_mode ) return; + by_autodetect = true; UpdateCache(); + UpdateListImage(); } /* アイドリング */