changeset 12:6ed3b64ed39a

finish 'UpdateListImage'.
author pyon@macmini
date Sun, 23 Oct 2011 20:29:33 +0900
parents 9b0840b0be7e
children df439f9831d2
files .hgignore TODO include/cache.h include/common.h include/myframe.h src/myframe.cpp
diffstat 6 files changed, 93 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Oct 23 07:43:34 2011 +0900
+++ b/.hgignore	Sun Oct 23 20:29:33 2011 +0900
@@ -10,3 +10,4 @@
 *.conf
 log
 *~
+*.jpg
--- a/TODO	Sun Oct 23 07:43:34 2011 +0900
+++ b/TODO	Sun Oct 23 20:29:33 2011 +0900
@@ -2,6 +2,9 @@
  TODO
 ======================================================================
 * d&d image
+* ccn folder make
+* error check hhsno
+* hhs explore
 
 ----------------------------------------------------------------------
  Memo
--- a/include/cache.h	Sun Oct 23 07:43:34 2011 +0900
+++ b/include/cache.h	Sun Oct 23 20:29:33 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : cache.h
-// Last Change: 22-Oct-2011.
+// Last Change: 23-Oct-2011.
 //
 #ifndef __cache__
 #define __cache__
@@ -8,7 +8,7 @@
 {
 public:
     wxString filename;  // key
-    wxString fullpathname; 
+    wxString fullpath; 
     wxString modtime;
     float    z;
     long     l;
@@ -17,6 +17,5 @@
     bool     exists;
 };
 
-
 #endif // __cache__
 
--- a/include/common.h	Sun Oct 23 07:43:34 2011 +0900
+++ b/include/common.h	Sun Oct 23 20:29:33 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : common.h
-// Last Change: 22-Oct-2011.
+// Last Change: 23-Oct-2011.
 //
 #ifndef __COMMON__
 #define __COMMON__
@@ -61,5 +61,12 @@
     // param
 
 };
+
+#if defined(__WXMSW__)
+    #define MOVECMD wxT("move")
+#else
+    #define MOVECMD wxT("mv")
+#endif
+
 #endif  // __COMMON__
 
--- a/include/myframe.h	Sun Oct 23 07:43:34 2011 +0900
+++ b/include/myframe.h	Sun Oct 23 20:29:33 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.h
-// Last Change: 22-Oct-2011.
+// Last Change: 23-Oct-2011.
 //
 
 #ifndef __myframe__
@@ -64,7 +64,7 @@
         void OnMoveAndDetect(wxCommandEvent& event);
         void OnDelete(wxCommandEvent& event);
         void OnUndo(wxCommandEvent& event);
-        void ReadyImage(void);
+        void UpdateListImage(void);
         void UpdateCache(void);
         // $B0J2<!$Dj7?$b$N(B
         void OnTimer(wxTimerEvent& event);
--- a/src/myframe.cpp	Sun Oct 23 07:43:34 2011 +0900
+++ b/src/myframe.cpp	Sun Oct 23 20:29:33 2011 +0900
@@ -242,7 +242,8 @@
 /* 検知 */
 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
 {
-    ReadyImage();
+    UpdateCache();
+    UpdateListImage();
 }
 
 /* 選択したファイルを移動 */
@@ -262,9 +263,12 @@
         wxString from = workdir + wxFILE_SEP_PATH + file;
         wxString to   = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file;
         wxRenameFile( from, to, true );
-        m_undo.Insert( wxT("move ") + to + wxT(" ") + from, 0 );
+
+        wxString movecmd = MOVECMD;
+        m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
     }
-    ReadyImage();
+    UpdateCache();
+    UpdateListImage();
     m_buttonUndo->Enable(true);
 }
 /* 選択したファイルを削除 */
@@ -281,9 +285,12 @@
         wxString from = workdir + wxFILE_SEP_PATH + file;
         wxString to   = trash   + wxFILE_SEP_PATH + file;
         wxRenameFile( from, to, true );
-        m_undo.Insert( wxT("move ") + to + wxT(" ") + from, 0 );
+
+        wxString movecmd = MOVECMD;
+        m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
     }
-    ReadyImage();
+    UpdateCache();
+    UpdateListImage();
     m_buttonUndo->Enable(true);
 }
 /* アンドゥ */
@@ -295,15 +302,13 @@
     wxMessageBox(wxT("戻し完了."));
     m_buttonUndo->Enable(false);
     m_undo.Clear();
-    ReadyImage();
+    UpdateCache();
+    UpdateListImage();
 }
 
 /* 画像をリストコントロールに表示 */
-void MyFrame::ReadyImage()
+void MyFrame::UpdateListImage()
 {
-    wxString workdir = m_dirPickerWork->GetPath();
-    wxDir dir( workdir );
-    if ( !dir.IsOpened() ) return;
     // start-up iamge
     wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png");
     wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG );
@@ -312,35 +317,29 @@
     bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG );
     m_bitmapHhsno->SetBitmap( bmp );
 
-    // enum jpeg
-    wxArrayString filenames;
-    unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
-
+    // 本処理
     m_listCtrlView->DeleteAllItems();
     m_imageList->RemoveAll();
     wxListItem item;
-    wxString first;
     wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
     pd.SetSize( wxSize(320,140) );
-    float z; long l;
-    for ( int i=0; i<n; i++ ) {
-        /*
-        wxFileName f( filenames[i] );
-        wxString filename = f.GetFullName();
-
-        m_listCtrlView->InsertItem( i, filename );
-        m_listCtrlView->SetItem( i, 0, filename, i );
 
-        wxImage image( filenames[i], wxBITMAP_TYPE_JPEG );
-        wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) );
-        m_imageList->Add( bmp );
+    wxArrayString keys;
+    for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
+        keys.Add(it->first);
+    }
+    bool select = true;
+    keys.Sort();
+    for ( int i=0; i<keys.GetCount(); i++ ) {
+        CacheItem* ci = new CacheItem;
+        ci = CH[keys[i]];
+        m_listCtrlView->InsertItem( i, ci->filename  );
+        m_listCtrlView->SetItem( i, 0, ci->filename, i );
+        m_imageList->Add( ci->thumbnail );
 
-        if ( i == 0 ) {
-            IsMarksheet( filenames[i], &z, &l );
-            first = filenames[i];
-            SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),z,l), 1 );
+        if ( i == 0 ) { // 1枚目はマークシートのはず
+            wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG );
 
-            wxImage marksheet( first, wxBITMAP_TYPE_JPEG );
             wxImage name_image;
             name_image  = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
             wxBitmap name_bmp  = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) );
@@ -351,18 +350,16 @@
             wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) );
             m_bitmapHhsno->SetBitmap( hhsno_bmp );
 
-            wxString hhsno = GuessHhs( first );
+            wxString hhsno = GuessHhs( ci->fullpath );
             m_textCtrlGuess->SetValue( hhsno );
+            SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
+            m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
         }
-        else {
-            if ( IsMarksheet( filenames[i], &z, &l ) ) {
-                break;
-            }
+        else {  // 2枚目以降で初めてマークシートを認識したら,それ以降は選択しない
+            if ( ci->marksheet ) select = false;
+            if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
         }
-        m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
-        */
 
-        // write log
         pd.Update( i+1, wxT("画像認識中") );
     }
 
@@ -421,54 +418,69 @@
 /* キャッシュ作成&更新 */
 void MyFrame::UpdateCache()
 {
-    wxString workdir = m_dirPickerWork->GetPath();
-    wxDir dir( workdir );
-    if ( !dir.IsOpened() ) return;
-    wxArrayString filenames;
-
-    wxListItem item;
-    wxString first;
-    float z; long l;
-    bool m;
-
+    m_buttonDetect->Enable(false);
     wxGetApp().WriteLog( wxT("start updating cache") );
     SetStatusText( wxT("rebuiling cache..."), 0 );
 
-    for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) {
+    /* キャッシュ存在フラグOFF */
+    for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
         CacheItem* ci = new CacheItem;
-        ci = i->second;
+        ci = it->second;
         ci->exists = false;
     }
+
+    wxString workdir = m_dirPickerWork->GetPath();
+    wxDir dir( workdir );
+    if ( !dir.IsOpened() ) return;
+
+    wxArrayString filenames;
+    wxListItem item;
+
+    /* キャッシュ作成 */
     unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
     for ( int i=0; i<n; i++ ) {
+        wxString fullpath = filenames[i];
+        wxFileName f( fullpath );
+        wxString file = f.GetFullName();
+
         CacheItem* ci = new CacheItem;
-        if ( CH.count(filenames[i]) ) {
-            ci = CH[filenames[i]];
+        /* キャッシュ済みのものはスキップ */
+        if ( CH.count(file) ) {
+            ci = CH[file];
             ci->exists = true;
             continue;
         }
-        ci->filename = filenames[i];
-        m = IsMarksheet( filenames[i], &z, &l );
-        wxImage image( filenames[i], wxBITMAP_TYPE_JPEG );
+        /* 新しいファイルはキャッシュ */
+        float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
+        wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
         wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) );
+
+        ci->filename  = file;
+        ci->fullpath  = fullpath;
         ci->marksheet = m;
         ci->z         = z;
         ci->l         = l;
         ci->exists    = true;
         ci->thumbnail = bmp;
         ci->modtime   = wxEmptyString; // TODO.
+
         CH[ci->filename] = ci;  // add hash
-        wxGetApp().WriteLog( filenames[i] + wxString::Format(wxT(" z=%f l=%d m=%d"), z, l, m ? 1 : 0 ) );
-    }
-    for ( CacheHash::iterator i=CH.begin(); i != CH.end(); ++i ) {
-        CacheItem* ci = new CacheItem;
-        ci = i->second;
-        if ( !ci->exists ) {
-            CH.erase(ci->filename);
-            wxGetApp().WriteLog( ci->filename + wxT(" removed.") );
-        }
+        wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
     }
 
+    /* 存在しないファイルはキャッシュから削除 */
+    wxArrayString removelist;
+    for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
+        CacheItem* ci = new CacheItem;
+        ci = it->second;
+        if ( !ci->exists ) removelist.Add( ci->filename );
+    }
+    for ( int i=0; i<removelist.GetCount(); i++ ) {
+        CH.erase(removelist[i]);
+        wxGetApp().WriteLog( removelist[i] + wxT(" removed.") );
+    }
+
+    m_buttonDetect->Enable(true);
     SetStatusText( wxEmptyString, 0 );
     m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
 }