changeset 11:dfcf8c973219

Implement Cache maker.
author pyon@macmini
date Wed, 07 May 2014 20:38:57 +0900
parents 29021e6e1ebe
children 52958cd4a073
files Changes Makefile TODO doc/Searcher 03 の新機能.docx doc/Searcher 03 の新機能.pdf include/cache.h include/common.h include/db.h include/myframe.h include/preview.h src/cache.cpp src/db.cpp src/index.cpp src/myframe.cpp src/preview.cpp
diffstat 13 files changed, 205 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Apr 28 18:14:04 2014 +0900
+++ b/Changes	Wed May 07 20:38:57 2014 +0900
@@ -1,3 +1,13 @@
+version 03.12
+2014-05-13
+ Implement Cache maker.
+
+----
+version 03.11
+2014-05-03
+ Implement thumbmail in PreviewDialog.
+
+----
 version 03.10
 2014-05-01
  Suggestion function comes back.
--- a/Makefile	Mon Apr 28 18:14:04 2014 +0900
+++ b/Makefile	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 # Makefile for wxWidgets Application
-# Last Change: 05-Feb-2014.
+# Last Change: 30-Apr-2014.
 # by Takayuki Mutoh
 #
 
@@ -41,6 +41,7 @@
 	  $(OBJDIR)/bprint.o \
 	  $(OBJDIR)/db.o \
 	  $(OBJDIR)/marksheet.o \
+	  $(OBJDIR)/cache.o \
 	  $(OBJDIR)/wxsqlite3.o
 
 ifdef COMSPEC
@@ -66,7 +67,7 @@
 	-mkdir -p $(OBJDIR)
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
-$(OBJDIR)/myframe.o: myframe.cpp myframe.h common.h db.h marksheet.h bprint.h
+$(OBJDIR)/myframe.o: myframe.cpp myframe.h common.h db.h marksheet.h bprint.h cache.h preview.h kana.h hist.h
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
 $(OBJDIR)/about.o: about.cpp about.h common.h
@@ -78,6 +79,9 @@
 $(OBJDIR)/hist.o: hist.cpp hist.h common.h
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
+$(OBJDIR)/cache.o: cache.cpp cache.h common.h
+	$(CXX) -c $< -o $@ $(CXXFLAGS)
+
 $(OBJDIR)/index.o: index.cpp index.h common.h db.h
 	$(CXX) -c $< -o $@ $(CXXFLAGS)
 
Binary file doc/Searcher 03 の新機能.docx has changed
Binary file doc/Searcher 03 の新機能.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/cache.h	Wed May 07 20:38:57 2014 +0900
@@ -0,0 +1,40 @@
+// Filename   : cache.h
+// Last Change: 02-May-2014.
+//
+
+#ifndef __CACHE_H__
+#define __CACHE_H__
+
+#include "common.h"
+
+
+class CacheDialog : public wxDialog 
+{
+    DECLARE_EVENT_TABLE()
+	private:
+        wxString    m_rootdir;
+        int         m_width, m_height;
+	
+	protected:
+		wxDatePickerCtrl* m_datePickerBgn;
+		wxDatePickerCtrl* m_datePickerEnd;
+		wxButton*         m_buttonMake;
+		wxButton*         m_buttonClose;
+	
+	public:
+		CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ); 
+		~CacheDialog();
+        void Setting( wxString rootdir, int w, int h );
+        void OnMakeCache( wxCommandEvent& WXUNUSED(event) );
+        void MakeCache( wxString begin, wxString end );
+        void OnClose( wxCommandEvent& WXUNUSED(event) );
+};
+
+#endif //__CACHE_H__
+
+enum
+{
+    ID_MKCACHE = wxID_HIGHEST + 660,
+    ID_CLOSE,
+};
+
--- a/include/common.h	Mon Apr 28 18:14:04 2014 +0900
+++ b/include/common.h	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : common.h
-// Last Change: 23-Apr-2014.
+// Last Change: 30-Apr-2014.
 //
 #ifndef __COMMON_H__
 #define __COMMON_H__
@@ -43,6 +43,7 @@
 #include <wx/dir.h>
 #include <wx/print.h>
 #include <wx/html/htmprint.h>
+#include <wx/datectrl.h>
 #include <wx/xrc/xmlres.h>
 
 #endif
--- a/include/db.h	Mon Apr 28 18:14:04 2014 +0900
+++ b/include/db.h	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : db.h
-// Last Change: 05-Feb-2014.
+// Last Change: 02-May-2014.
 //
 #ifndef __DB_H__
 #define __DB_H__
@@ -26,6 +26,8 @@
 wxArrayString GetCcnByDate( wxString date );
 // 合議体から被保険者番号を取得
 wxArrayString GetHhsNoByCcn( wxString ccn, wxString date );
+// 範囲日時のパスを取得
+wxArrayString GetPathes( wxString from, wxString to );
 // インデックスを更新
 void UpdateIndex( wxString datadir, wxString date );
 // DBの整合性をチェック
--- a/include/myframe.h	Mon Apr 28 18:14:04 2014 +0900
+++ b/include/myframe.h	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.h
-// Last Change: 28-Apr-2014.
+// Last Change: 30-Apr-2014.
 //
 #ifndef __MYFRAME_H__
 #define __MYFRAME_H__
@@ -94,6 +94,7 @@
 		
         void OnBPrintMode( wxCommandEvent& WXUNUSED(event) );
         void OnIndex( wxCommandEvent& WXUNUSED(event) );
+        void OnCache( wxCommandEvent& WXUNUSED(event) );
         void LoadParam( void );
         void OnDBBackup( wxCommandEvent& WXUNUSED(event) );
         void OnMaskParam( wxCommandEvent& WXUNUSED(event) );
@@ -123,6 +124,7 @@
 enum {
     ID_MNBPNT = wxID_HIGHEST + 10,
     ID_MNINDEX,
+    ID_MNCACHE,
     ID_MNDBBKUP,
     ID_MNMASKPARAM,
     ID_MNMARKPARAM,
--- a/include/preview.h	Mon Apr 28 18:14:04 2014 +0900
+++ b/include/preview.h	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : preview.h
-// Last Change: 28-Apr-2014.
+// Last Change: 01-May-2014.
 //
 
 #ifndef __PREVIEW_H__
@@ -44,7 +44,6 @@
     DECLARE_EVENT_TABLE()
 	private:
         wxString          m_preview;
-        wxString          m_dir;
         wxArrayString     m_imagefiles;
         wxArrayString     m_cachefiles;
 	
@@ -60,6 +59,7 @@
 		~PreviewDialog();
 	
         void SetFiles( wxArrayString imagefiles, wxArrayString cachefiles );
+        void SetPreviewSize( void );
         void SetPreviewImage( int n );
         void OnPrint( wxCommandEvent& event );
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cache.cpp	Wed May 07 20:38:57 2014 +0900
@@ -0,0 +1,93 @@
+// Filename   : cache.cpp
+// Last Change: 07-May-2014.
+//
+
+#include "cache.h"
+#include "db.h"
+
+CacheDialog::CacheDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
+    : wxDialog( parent, id, title, pos, size, style )
+{
+	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
+	
+	wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
+	
+	m_datePickerBgn = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT );
+	bSizerTop->Add( m_datePickerBgn, 0, wxALL, 5 );
+	
+	m_datePickerEnd = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DEFAULT );
+	bSizerTop->Add( m_datePickerEnd, 0, wxALL, 5 );
+	
+	m_buttonMake = new wxButton( this, ID_MKCACHE, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 );
+	bSizerTop->Add( m_buttonMake, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
+	
+	m_buttonClose = new wxButton( this, ID_CLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
+	m_buttonClose->SetDefault(); 
+	bSizerTop->Add( m_buttonClose, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );
+	
+	this->SetSizer( bSizerTop );
+	this->Layout();
+	bSizerTop->Fit( this );
+	
+	this->Centre( wxBOTH );
+}
+
+CacheDialog::~CacheDialog()
+{
+}
+
+// Event Table
+BEGIN_EVENT_TABLE( CacheDialog, wxDialog )
+    EVT_BUTTON( ID_MKCACHE, CacheDialog::OnMakeCache )
+    EVT_BUTTON( ID_CLOSE,   CacheDialog::OnClose )
+END_EVENT_TABLE()
+
+// Event Handlers & Functions
+void CacheDialog::Setting( wxString rootdir, int w, int h )
+{
+    m_rootdir = rootdir;
+    m_width   = w;
+    m_height  = h;
+}
+
+void CacheDialog::OnMakeCache( wxCommandEvent& WXUNUSED(event) )	
+{
+    wxDateTime b = m_datePickerBgn->GetValue();
+    wxDateTime e = m_datePickerEnd->GetValue();
+    
+    MakeCache( b.Format( wxT("%Y%m%d")), e.Format( wxT("%Y%m%d")) );
+}
+
+void CacheDialog::MakeCache( wxString from, wxString to )
+{
+    wxArrayString path = GetPathes( from, to );
+    wxString cachedir = wxGetCwd() + wxFILE_SEP_PATH + wxT("cache");
+
+    for ( int i = 0; i < path.GetCount(); i++ ) {
+
+        wxArrayString files;
+        wxDir::GetAllFiles( path[i], &files, wxT("*.*"), wxDIR_DEFAULT );
+
+        for ( int j = 0; j < files.GetCount(); j++ ) {
+            wxImage image( files[j], wxBITMAP_TYPE_JPEG );
+            wxImage output = image.Scale( m_width, m_height, wxIMAGE_QUALITY_HIGH );
+
+            wxString buf = files[j];
+            buf.Replace( m_rootdir, cachedir, false );
+            buf = buf.BeforeLast( '.' ) + wxT(".png");
+
+            wxFileName tf( buf );
+            if ( !tf.Exists() ) tf.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
+            output.SaveFile( buf, wxBITMAP_TYPE_PNG );
+        }
+
+    }
+
+    wxMessageBox( wxT("cache updated.") );
+}
+
+void CacheDialog::OnClose( wxCommandEvent& WXUNUSED(event) )
+{
+    Close();
+}
+
--- a/src/db.cpp	Mon Apr 28 18:14:04 2014 +0900
+++ b/src/db.cpp	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : db.cpp
-// Last Change: 16-Apr-2014.
+// Last Change: 02-May-2014.
 //
 
 #include "db.h"
@@ -229,6 +229,31 @@
     return data;
 }
 
+/* 範囲日時のパスを取得 */
+wxArrayString GetPathes( wxString from, wxString to )
+{
+    wxArrayString path;
+
+    wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
+    wxSQLite3Database ccndb;
+    ccndb.Open( gszFile );
+
+    wxSQLite3Statement stmt = ccndb.PrepareStatement( "SELECT path FROM path WHERE date >= ? AND date <= ?" );
+    stmt.Bind( 1, from );
+    stmt.Bind( 2, to   );
+    wxSQLite3ResultSet q = stmt.ExecuteQuery();
+
+    if ( !q.IsNull(0) ) {
+        while ( q.NextRow() ) {
+            path.Add( q.GetString(0) );
+        }
+    }
+    stmt.Finalize();
+    ccndb.Close();
+
+    return path;
+}
+
 /* 合議体から被保険者番号を取得 */
 wxArrayString GetHhsNoByCcn( wxString ccn, wxString date ) 
 {
--- a/src/myframe.cpp	Mon Apr 28 18:14:04 2014 +0900
+++ b/src/myframe.cpp	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.cpp
-// Last Change: 28-Apr-2014.
+// Last Change: 02-May-2014.
 //
 #include "main.h"
 #include "db.h"
@@ -8,6 +8,7 @@
 #include "hist.h"
 #include "preview.h"
 #include "index.h"
+#include "cache.h"
 #include "param.h"
 #include "marksheet.h"
 #include "myframe.h"
@@ -226,6 +227,9 @@
 	wxMenuItem* m_menuItemIndex = new wxMenuItem( m_menuFile, ID_MNINDEX, wxString( wxT("インデックス\tF11") ) , wxT("Update index"), wxITEM_NORMAL );
 	m_menuFile->Append( m_menuItemIndex );
 
+	wxMenuItem* m_menuItemCache = new wxMenuItem( m_menuFile, ID_MNCACHE, wxString( wxT("キャッシュ\tF9") ) , wxT("Make cache"), wxITEM_NORMAL );
+	m_menuFile->Append( m_menuItemCache );
+
     m_menuFile->AppendSeparator(); // ----
 
 	wxMenuItem* m_menuItemBkup = new wxMenuItem( m_menuFile, ID_MNDBBKUP, wxString( wxT("DBバックアップ(&B)") ) , wxT("Backup databases"), wxITEM_NORMAL );
@@ -342,6 +346,7 @@
     EVT_MENU( wxID_EXIT,      MyFrame::OnQuit )
     EVT_MENU( ID_MNBPNT,      MyFrame::OnBPrintMode )
     EVT_MENU( ID_MNINDEX,     MyFrame::OnIndex )
+    EVT_MENU( ID_MNCACHE,     MyFrame::OnCache )
     EVT_MENU( ID_MNDBBKUP,    MyFrame::OnDBBackup )
     EVT_MENU( ID_MNMASKPARAM, MyFrame::OnMaskParam )
     EVT_MENU( ID_MNMARKPARAM, MyFrame::OnMarkParam )
@@ -552,6 +557,17 @@
     index->SetRootdir( rootdir );
     index->ShowModal();
 }
+/* キャッシュ作成ダイアログ */
+void MyFrame::OnCache( wxCommandEvent& WXUNUSED(event) )
+{
+    wxString rootdir;
+    config->SetPath( wxT("/Index") );
+    config->Read( wxT("rootdir"), &rootdir );
+
+    CacheDialog* cache = new CacheDialog( this, wxID_ANY, wxT("キャッシュ作成"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxSTAY_ON_TOP );
+    cache->Setting( rootdir, THUMB_W, THUMB_H );
+    cache->ShowModal();
+}
 /* マークシートパラメータ設定ダイアログ */
 void MyFrame::OnMarkParam( wxCommandEvent& WXUNUSED(event) )
 {
--- a/src/preview.cpp	Mon Apr 28 18:14:04 2014 +0900
+++ b/src/preview.cpp	Wed May 07 20:38:57 2014 +0900
@@ -1,5 +1,5 @@
 // Filename   : preview.cpp
-// Last Change: 28-Apr-2014.
+// Last Change: 01-May-2014.
 //
 
 #include "preview.h"
@@ -102,7 +102,7 @@
 
 	m_buttonPrint = new wxButton( this, ID_PRINT, wxT("印刷"), wxDefaultPosition, wxDefaultSize, 0 );
 	bSizerMenu->Add( m_buttonPrint, 0, wxALL, 5 );
-	bSizerMenu->Add( 0, 0, 1, 0, 5 );
+	bSizerMenu->Add( 0, 0, 0, 0, 5 );
 	
 	m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
 	m_buttonClose->SetDefault(); 
@@ -136,6 +136,7 @@
     wxBitmap bmp( img.Scale( w, h, wxIMAGE_QUALITY_HIGH ) );
     m_bitmap->SetBitmap( bmp );
 
+    m_scrolledWindow->Scroll( 0, 0 );
     m_scrolledWindow->SetScrollbars( 10, 10, 0, h/10 );
     m_preview = m_imagefiles[n];
 }