changeset 4:a505f7417742

v0.1 release
author pyon@macmini
date Thu, 06 Oct 2011 07:56:12 +0900
parents a5bddd859104
children 3b734fd6ee2b
files TODO include/common.h include/delwhite.h include/marksheet.h include/myframe.h makefile src/delwhite.cpp src/myframe.cpp
diffstat 8 files changed, 245 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/TODO	Tue Oct 04 07:43:08 2011 +0900
+++ b/TODO	Thu Oct 06 07:56:12 2011 +0900
@@ -2,6 +2,8 @@
  TODO
 ===========================================================================
 * Log : moved time, files, distination
+* Undo
+* Open Explorer
 
 ---------------------------------------------------------------------------
  Memo
--- a/include/common.h	Tue Oct 04 07:43:08 2011 +0900
+++ b/include/common.h	Thu Oct 06 07:56:12 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : common.h
-// Last Change: 03-Oct-2011.
+// Last Change: 05-Oct-2011.
 //
 #ifndef __COMMON__
 #define __COMMON__
@@ -14,6 +14,7 @@
     // mainframe
     ID_MAIN    = wxID_HIGHEST + 1,
 
+    ID_OPWORK,
     ID_WORKDIR,
     ID_DTWHITE,
     ID_DRIVE,
--- a/include/delwhite.h	Tue Oct 04 07:43:08 2011 +0900
+++ b/include/delwhite.h	Thu Oct 06 07:56:12 2011 +0900
@@ -1,21 +1,28 @@
 // Filename   : delwhite.h
-// Last Change: 03-Oct-2011.
+// Last Change: 04-Oct-2011.
 //
 #ifndef __DELWHITE__
 #define __DEWHITEL__
 
 #include "common.h"
 
-#include <wx/string.h>
-#include <wx/stattext.h>
-#include <wx/image.h>
-#include <wx/imaglist.h>
-#include <wx/sizer.h>
-#include <wx/textctrl.h>
-#include <wx/frame.h>
-#include <wx/listctrl.h>
-#include <wx/checkbox.h>
+#include "wx/wxprec.h"
 
+#ifndef WX_PRECOMP
+    #include <wx/string.h>
+    #include <wx/stattext.h>
+    #include <wx/image.h>
+    #include <wx/imaglist.h>
+    #include <wx/sizer.h>
+    #include <wx/textctrl.h>
+    #include <wx/frame.h>
+    #include <wx/listctrl.h>
+    #include <wx/checkbox.h>
+    #include <wx/utils.h>
+    #include <wx/dir.h>
+    #include <wx/file.h>
+#endif
+    
 ///////////////////////////////////////////////////////////////////////////////
 /// Class FrameDelWhite
 ///////////////////////////////////////////////////////////////////////////////
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/marksheet.h	Thu Oct 06 07:56:12 2011 +0900
@@ -0,0 +1,97 @@
+// Filename   : marksheet.h
+// Last Change: 05-Oct-2011.
+//
+#ifndef __MARKSHEET__
+#define __MARKSHEET__
+
+
+#include "wx/utils.h"
+#include "wx/file.h"
+#include "wx/string.h"
+#include "wx/image.h"
+
+bool IsBlack( int r, int g, int b ) 
+{
+    if ( r == 0 && g == 0 && b == 0 ) {
+        return true;
+    }
+    return false;
+};
+
+wxString GuessHhs( wxString& file ) 
+{
+    wxString hhs;
+    wxImage img( file, wxBITMAP_TYPE_JPEG );
+    int sx = 1800;  // start x
+    int sy = 315;;  // start y
+    int bw = 60;    // block width
+    int bh = 50;    // block height
+    int area = bw * bh;
+    int black = 0;
+    int x, y;
+    unsigned char r, g, b;
+
+    int max_n;
+    float max;
+    float bk;
+    for ( int c=0; c<10; c++ ) {
+        max = 0.0;
+        max_n = -1;
+        for ( int n=0; n<10; n++ ) {
+
+            for ( x=sx+bw*c; x<sx+bw*(c+1); x++ ) {
+                for ( y=sy+bh*n; y<sy+bh*(n+1); y++ ) {
+                    r = img.GetRed(   x, y );
+                    g = img.GetGreen( x, y );
+                    b = img.GetBlue(  x, y );
+                    if( IsBlack( (int)r, (int)g, (int)b ) ) black++;
+                }
+            }
+
+            bk = (float)black / area;
+            if ( max < bk ) {
+                max = bk;
+                max_n = n;
+            }
+            //wxPuts(wxString::Format(wxT("%d %f"),n,bk));
+            black = 0;
+        }
+        hhs.Append( wxString::Format( wxT("%d"), max_n ) );
+    }
+
+    return hhs;
+};
+
+bool IsMarksheet( wxString& file )
+{
+    wxImage img( file, wxBITMAP_TYPE_JPEG );
+    int black = 0;
+    int x = 2465;
+    int h = 3500;
+    unsigned char r, g, b;
+
+    for ( int y=0; y<h; y++ ) {
+        r = img.GetRed(   x, y );
+        g = img.GetGreen( x, y );
+        b = img.GetBlue(  x, y );
+        if( IsBlack( (int)r, (int)g, (int)b ) ) black++;
+    }
+    float z = (float)black / h;
+    float zmin = 0.103428 * 0.95;
+    float zmax = 0.103428 * 1.05;
+
+    wxFile f( file );
+    long l = f.Length();
+    float lmin = 2181468 * 0.95;
+    float lmax = 2181468 * 1.05;
+
+    //wxPuts(wxString::Format(wxT("z = %f, len = %d"),z,len));
+    if ( zmin < z && z < zmax
+      && lmin < l && l < lmax ) {
+        return true;
+    }
+    return false;
+};
+
+#endif // __MARKSHEET__
+
--- a/include/myframe.h	Tue Oct 04 07:43:08 2011 +0900
+++ b/include/myframe.h	Thu Oct 06 07:56:12 2011 +0900
@@ -1,25 +1,29 @@
 // Filename   : myframe.h
-// Last Change: 03-Oct-2011.
+// Last Change: 05-Oct-2011.
 //
 #ifndef MYFRAME
 #define MYFRAME
 #include "wx/wxprec.h"
 
 #ifndef WX_PRECOMP
-    #include "wx/wx.h"
+    #include <wx/wx.h>
     #include <wx/icon.h>
+    #include <wx/dir.h>
     #include <wx/menu.h>
     #include <wx/string.h>
     #include <wx/statusbr.h>
-    #include "wx/stattext.h"
+    #include <wx/stattext.h>
     #include <wx/button.h>
-    #include "wx/datectrl.h"
+    #include <wx/datectrl.h>
     #include <wx/dateevt.h>
-    #include "wx/textctrl.h"
-    #include "wx/filepicker.h"
+    #include <wx/textctrl.h>
+    #include <wx/filepicker.h>
+    #include <wx/filename.h>
     #include <wx/listctrl.h>
-    #include "wx/dir.h"
-    #include "wx/stdpaths.h"
+    #include <wx/dir.h>
+    #include <wx/file.h>
+    #include <wx/tokenzr.h>
+    #include <wx/stdpaths.h>
     #include <wx/sizer.h>
     #include <wx/combobox.h>
     #include <wx/frame.h>
@@ -59,9 +63,11 @@
     void OnMove( wxMoveEvent& event );
     void OnQuit( wxCommandEvent& event );
     void OnAbout( wxCommandEvent& event );
+    void OnOpenWorkDir(wxCommandEvent& event);
     void OnDetectWhite( wxCommandEvent& event );
     void SetDir( wxCommandEvent& event );
     void MakeDir( wxCommandEvent& event );
+    void MoveImages( wxCommandEvent& event );
     void SaveConfig( wxCloseEvent& event );
     void TellLocation( void );
 };
--- a/makefile	Tue Oct 04 07:43:08 2011 +0900
+++ b/makefile	Thu Oct 06 07:56:12 2011 +0900
@@ -1,6 +1,6 @@
 #
 # Makefile for wxWidgets Application
-#  Last Change: 01-Oct-2011.
+#  Last Change: 06-Oct-2011.
 #  by Takayuki Mutoh
 #
 
@@ -102,7 +102,7 @@
 	-mkdir -p $(OBJDIR)
 	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
-$(OBJDIR)/myframe.o: myframe.cpp myframe.h symbol.h common.h
+$(OBJDIR)/myframe.o: myframe.cpp myframe.h marksheet.h symbol.h common.h
 	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
 $(OBJDIR)/delwhite.o: delwhite.cpp delwhite.h common.h
--- a/src/delwhite.cpp	Tue Oct 04 07:43:08 2011 +0900
+++ b/src/delwhite.cpp	Thu Oct 06 07:56:12 2011 +0900
@@ -1,18 +1,9 @@
 // Filename   : delwhite.cpp
-// Last Change: 03-Oct-2011.
+// Last Change: 05-Oct-2011.
 //
 
 #include "delwhite.h"
 
-// for all others, include the necessary headers (this file is usually all you
-// need because it includes almost all "standard" wxWidgets headers)
-#ifndef WX_PRECOMP
-    #include "wx/utils.h"
-    #include "wx/dir.h"
-    #include "wx/file.h"
-#endif
-
-
 // constructor
 FrameDelWhite::FrameDelWhite( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
 {
@@ -71,6 +62,22 @@
 
 void FrameDelWhite::DeleteImage(wxCommandEvent& WXUNUSED(event))
 {
+    wxDateTime now = wxDateTime::Now();
+    wxString trash = wxGetCwd() + wxFILE_SEP_PATH + wxT("trash") + wxFILE_SEP_PATH + now.Format(wxT("%Y%m%d%H%M%S"));
+    wxMkdir( trash );
+
+    long item = -1;
+    for ( ; ; ) {
+        item = m_listCtrl->GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
+        if ( item == -1 )
+            break;
+        wxString file = m_listCtrl->GetItemText( item );
+        
+        wxString from = m_dir + wxFILE_SEP_PATH + file;
+        wxString to   = trash + wxFILE_SEP_PATH + file;
+        wxRenameFile( from, to, false );
+    }
+    LoadImages();
     return;
 }
 
--- a/src/myframe.cpp	Tue Oct 04 07:43:08 2011 +0900
+++ b/src/myframe.cpp	Thu Oct 06 07:56:12 2011 +0900
@@ -1,10 +1,11 @@
 // Filename   : mainframe.cpp
-// Last Change: 03-Oct-2011.
+// Last Change: 05-Oct-2011.
 //
 #include "symbol.h"
 #include "common.h"
 #include "myframe.h"
 #include "delwhite.h"
+#include "marksheet.h"
 #include "main.h"
 
 // resources
@@ -47,8 +48,10 @@
 	m_menubar  = new wxMenuBar();
 
 	m_menuFile = new wxMenu();
+    m_menuFile->Append( ID_OPWORK, wxT("作業フォルダを開く"), wxT("Open work folder") );
+    m_menuFile->AppendSeparator(); //----
     m_menuFile->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") );
-    //m_menuFile->AppendSeparator(); //----
+    m_menuFile->AppendSeparator(); //----
     m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") );
 
 	m_menubar->Append( m_menuFile, wxT("ファイル(&F)") ); 
@@ -126,20 +129,28 @@
 	bSizerDoMove->Add( m_textCtrlMoveDir, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
 	
 	m_buttonDoMove = new wxButton( this, ID_DOMOVE, wxT("画像移動"), wxDefaultPosition, wxDefaultSize, 0 );
-	m_buttonDoMove->Enable( false );
 	
 	bSizerDoMove->Add( m_buttonDoMove, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
 	
 	bSizerTop->Add( bSizerDoMove, 0, wxEXPAND, 5 );
 	
 	m_listCtrl = new wxListCtrl( this, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
+    wxListItem itemCol;
+    itemCol.SetText( wxT("通番") );
+    m_listCtrl->InsertColumn( 0, itemCol );
+    m_listCtrl->SetColumnWidth( 0, 100 );
+    itemCol.SetText( wxT("被保険者番号") );
+    m_listCtrl->InsertColumn( 1, itemCol );
+    m_listCtrl->SetColumnWidth( 1, 180 );
+    itemCol.SetText( wxT("ファイル数") );
+    m_listCtrl->InsertColumn( 2, itemCol );
+    m_listCtrl->SetColumnWidth( 1, 100 );
 	bSizerTop->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
 	
 	this->SetSizer( bSizerTop );
 	this->Layout();
 	
 	this->Centre( wxBOTH );
-    //this->SetDefaultItem(m_buttonDetWhite);
     m_buttonDetWhite->SetFocus();
 }
 
@@ -154,9 +165,11 @@
     EVT_MOVE( MyFrame::OnMove )
     EVT_MENU( wxID_EXIT,  MyFrame::OnQuit )
     EVT_MENU( wxID_ABOUT, MyFrame::OnAbout )
+    EVT_MENU( ID_OPWORK,  MyFrame::OnOpenWorkDir )
     EVT_BUTTON( ID_DTWHITE, MyFrame::OnDetectWhite )
-    EVT_BUTTON( ID_STDIR, MyFrame::SetDir )
-    EVT_BUTTON( ID_MKDIR, MyFrame::MakeDir )
+    EVT_BUTTON( ID_STDIR,   MyFrame::SetDir )
+    EVT_BUTTON( ID_MKDIR,   MyFrame::MakeDir )
+    EVT_BUTTON( ID_DOMOVE,  MyFrame::MoveImages )
     EVT_CLOSE( MyFrame::SaveConfig )
 END_EVENT_TABLE()
 
@@ -229,20 +242,89 @@
     m_textCtrlMoveDir->SetValue( dir );
 }
 
+/* 移動先フォルダ作成 */
 void MyFrame::MakeDir(wxCommandEvent& WXUNUSED(event))
 {
+    wxString dirname = m_textCtrlMoveDir->GetValue();
+    wxString ccn = m_comboBoxCcn->GetValue();
+    if ( dirname.Len() < 15 || ccn.IsEmpty() ) {
+        wxMessageBox(wxT("フォルダを指定してください."));
+        return;
+    }
+
+    wxStringTokenizer tkz( dirname, wxFILE_SEP_PATH );
+    wxString d;
+    while ( tkz.HasMoreTokens() ) {
+        d.Append( tkz.GetNextToken() );
+        d.Append( wxFILE_SEP_PATH );
+        if ( !wxDirExists( d ) ) wxMkdir( d );
+    }
 }
 
-/* アプリケーションフォルダを開く */
-/*
-void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
+/* 画像移動 */
+void MyFrame::MoveImages(wxCommandEvent& WXUNUSED(event))
 {
-    wxStandardPaths appdir;
-    wxString execmd = wxT("explorer ") + appdir.GetDataDir();
+    wxString dirname = m_textCtrlMoveDir->GetValue();
+    wxString ccn = m_comboBoxCcn->GetValue();
+    if ( dirname.IsEmpty() || ccn.IsEmpty() ) {
+        wxMessageBox(wxT("フォルダを指定してください."));
+        return;
+    }
+
+    dirname.Append( wxFILE_SEP_PATH );
+    if ( !wxDirExists( dirname ) ) {
+        wxMessageBox(wxT("フォルダが存在しません."));
+        return;
+    }
+
+    wxString workdir = m_dirPickerWork->GetPath();
+    wxDir dir( workdir );
+    if ( !dir.IsOpened() ) return;
+
+    wxString filename;
+    bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );
+
+    int cnt=0, r=0;
+    wxString hhs;
+    m_listCtrl->DeleteAllItems();
+    while ( cout ) {
+        wxString from = workdir + wxFILE_SEP_PATH + filename;
+        if ( IsMarksheet( from ) ) {
+            hhs = GuessHhs( from );
+            wxString d = dirname + hhs;
+            wxMkdir( d );
+            m_listCtrl->InsertItem( r, wxString::Format(wxT("%d"),r+1) );
+            m_listCtrl->SetItem( r,   1, hhs, -1 ); // 被保険者番号
+            m_listCtrl->SetItem( r-1, 2, wxString::Format(wxT("%d"),cnt), -1 ); // ファイル数
+            if ( r % 2 ) m_listCtrl->SetItemBackgroundColour( r, wxColour(wxT("WHEAT")) );
+            r++;
+            cnt=0;
+        }
+        if ( hhs.IsEmpty() ) {
+            wxMessageBox(wxT("マークシートの画像ファイルを確認してください."));
+            return;
+        }
+        wxString to = dirname + wxFILE_SEP_PATH + hhs + wxFILE_SEP_PATH + filename;
+        wxRenameFile( from, to, false );
+        // write log
+        cout = dir.GetNext( &filename );
+        cnt++;
+    }
+    m_listCtrl->SetItem( r-1, 2, wxString::Format(wxT("%d"),cnt), -1 ); // ファイル数
+    if ( cnt < 5 ) m_listCtrl->SetItemTextColour( r, *wxRED );
+
+    wxString cmd = wxT("explorer ") + dirname;
+    wxExecute( cmd );
+}
+
+/* 作業フォルダを開く */
+void MyFrame::OnOpenWorkDir(wxCommandEvent& WXUNUSED(event))
+{
+    wxString workdir = m_dirPickerWork->GetPath();
+    wxString execmd = wxT("explorer ") + workdir;
     wxExecute( execmd );
     return;
 }
-*/
 
 
 /* 設定を保存 */