0
|
1 // Filename : myframe.cpp
|
27
|
2 // Last Change: 05-Nov-2011.
|
0
|
3 //
|
|
4
|
|
5 #include "main.h"
|
|
6 #include "myframe.h"
|
5
|
7 #include "param.h"
|
6
|
8 #include "dndfile.h"
|
10
|
9 #include "marksheet.h"
|
0
|
10
|
27
|
11 #define LOGO_W 288
|
|
12 #define LOGO_H 86
|
|
13 #define HHSN_W 288
|
|
14 #define HHSN_H 49
|
|
15 #define THUMB_W 160
|
|
16 #define THUMB_H 226
|
|
17
|
5
|
18 // resources
|
|
19 // the application icon (under Windows and OS/2 it is in resources and even
|
|
20 // though we could still include the XPM here it would be unused)
|
|
21 #if !defined(__WXMSW__) && !defined(__WXPM__)
|
|
22 #include "sample.xpm"
|
|
23 #endif
|
|
24
|
0
|
25 //////////////////////////////////////////////////////////////////////////
|
|
26 // frame constructor
|
|
27 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
|
|
28 {
|
|
29 this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
|
|
30 // set the frame icon
|
5
|
31 SetIcon(wxICON(sample));
|
0
|
32
|
|
33 // メニューバー
|
|
34 m_menubarFile = new wxMenuBar();
|
|
35 m_menuFile = new wxMenu();
|
29
|
36
|
|
37 wxMenuItem* m_menuItemDetect;
|
|
38 m_menuItemDetect = new wxMenuItem( m_menuFile, ID_MENUITEMDETECT, wxString( wxT("検知\tF5") ) , wxEmptyString, wxITEM_NORMAL );
|
|
39 m_menuFile->Append( m_menuItemDetect );
|
|
40
|
|
41 wxMenuItem* m_menuItemMove;
|
|
42 m_menuItemMove = new wxMenuItem( m_menuFile, ID_MENUITEMMOVE, wxString( wxT("移動\tF7") ) , wxEmptyString, wxITEM_NORMAL );
|
|
43 m_menuFile->Append( m_menuItemMove );
|
|
44
|
|
45 m_menuFile->AppendSeparator(); // ----
|
0
|
46 wxMenuItem* m_menuItemParam;
|
29
|
47 m_menuItemParam = new wxMenuItem( m_menuFile, ID_MENUITEMPARAM, wxString( wxT("パラメータ\tAlt+P") ) , wxEmptyString, wxITEM_NORMAL );
|
0
|
48 m_menuFile->Append( m_menuItemParam );
|
|
49
|
|
50 wxMenuItem* m_menuItemAppDIr;
|
29
|
51 m_menuItemAppDIr = new wxMenuItem( m_menuFile, ID_MENUITEMAPPDIR, wxString( wxT("アプリフォルダを開く\tCtrl+O") ) , wxEmptyString, wxITEM_NORMAL );
|
0
|
52 m_menuFile->Append( m_menuItemAppDIr );
|
|
53
|
29
|
54 m_menuFile->AppendSeparator(); // ----
|
0
|
55
|
|
56 wxMenuItem* m_menuItemQuit;
|
29
|
57 m_menuItemQuit = new wxMenuItem( m_menuFile, wxID_EXIT, wxString( wxT("終了\tAlt+X") ) , wxEmptyString, wxITEM_NORMAL );
|
0
|
58 m_menuFile->Append( m_menuItemQuit );
|
|
59
|
29
|
60 m_menubarFile->Append( m_menuFile, wxT("ファイル\tAlt+F") );
|
0
|
61
|
|
62 this->SetMenuBar( m_menubarFile );
|
|
63
|
|
64 // コントロール
|
|
65 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
|
|
66
|
|
67 wxBoxSizer* bSizerFrom = new wxBoxSizer( wxHORIZONTAL );
|
|
68
|
|
69 m_staticTextWork = new wxStaticText( this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
70 bSizerFrom->Add( m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
71
|
|
72 m_dirPickerWork = new wxDirPickerCtrl( this, wxID_ANY, wxGetApp().workdir, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
|
|
73 bSizerFrom->Add( m_dirPickerWork, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
74
|
|
75 bSizerTop->Add( bSizerFrom, 0, wxEXPAND, 5 );
|
|
76
|
1
|
77 wxBoxSizer* bSizerDist = new wxBoxSizer( wxHORIZONTAL );
|
|
78
|
|
79 m_staticTextDist = new wxStaticText( this, wxID_ANY, wxT("保存フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
80 bSizerDist->Add( m_staticTextDist, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
81
|
|
82 m_textCtrlDist = new wxTextCtrl( this, ID_TEXTCTRLDIST, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
83 m_textCtrlDist->SetMaxLength( 15 );
|
|
84 bSizerDist->Add( m_textCtrlDist, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
85 bSizerDist->Add( 0, 0, 1, wxEXPAND, 5 );
|
0
|
86
|
|
87 m_staticTextDrive = new wxStaticText( this, wxID_ANY, wxT("ドライブ"), wxDefaultPosition, wxDefaultSize, 0 );
|
1
|
88 bSizerDist->Add( m_staticTextDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
89
|
|
90 wxArrayString drives;
|
|
91 drives.Add(wxT("C:"));
|
|
92 drives.Add(wxT("Y:"));
|
|
93 drives.Add(wxT("Z:"));
|
|
94 m_comboBoxDrive = new wxComboBox( this, wxID_ANY, wxT("C:"), wxDefaultPosition, wxSize(50,-1), drives, 0 );
|
1
|
95 bSizerDist->Add( m_comboBoxDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
96
|
|
97 m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT("開催日"), wxDefaultPosition, wxDefaultSize, 0 );
|
1
|
98 bSizerDist->Add( m_staticTextDate, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
99
|
|
100 m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN );
|
1
|
101 bSizerDist->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
8
|
102
|
|
103 m_buttonNextThu = new wxButton( this, ID_BUTTONNEXTTHU, wxT("次木 >>"), wxDefaultPosition, wxSize(60,-1), 0 );
|
|
104 bSizerDist->Add( m_buttonNextThu, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
105
|
|
106 m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT("合議体"), wxDefaultPosition, wxDefaultSize, 0 );
|
1
|
107 bSizerDist->Add( m_staticTextCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
108
|
|
109 wxArrayString ccns;
|
|
110 ccns.Add(wxT("角館1")); ccns.Add(wxT("角館2")); ccns.Add(wxT("角館3")); ccns.Add(wxT("角館4"));
|
|
111 ccns.Add(wxT("西仙1")); ccns.Add(wxT("西仙2")); ccns.Add(wxT("西仙3"));
|
|
112 ccns.Add(wxT("千畑1")); ccns.Add(wxT("千畑2")); ccns.Add(wxT("千畑3"));
|
|
113 ccns.Add(wxT("大曲1")); ccns.Add(wxT("大曲2")); ccns.Add(wxT("大曲3")); ccns.Add(wxT("大曲4")); ccns.Add(wxT("大曲5")); ccns.Add(wxT("大曲6"));
|
|
114 ccns.Add(wxT("六郷1")); ccns.Add(wxT("六郷2")); ccns.Add(wxT("六郷3"));
|
|
115 m_comboBoxCcn = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100,-1), ccns, 0 );
|
1
|
116 bSizerDist->Add( m_comboBoxCcn, 0, wxALL, 5 );
|
0
|
117
|
|
118 m_buttonMkDir = new wxButton( this, ID_BUTTONMKDIR, wxT("適用"), wxDefaultPosition, wxDefaultSize, 0 );
|
1
|
119 bSizerDist->Add( m_buttonMkDir, 0, wxALL, 5 );
|
0
|
120
|
|
121 bSizerTop->Add( bSizerDist, 0, wxEXPAND, 5 );
|
|
122
|
|
123 wxBoxSizer* bSizerManip = new wxBoxSizer( wxHORIZONTAL );
|
|
124
|
27
|
125 wxBoxSizer* bSizerRecog = new wxBoxSizer( wxVERTICAL );
|
0
|
126
|
|
127 m_staticTextName = new wxStaticText( this, wxID_ANY, wxT("氏名"), wxDefaultPosition, wxDefaultSize, 0 );
|
27
|
128 bSizerRecog->Add( m_staticTextName, 0, wxTOP|wxLEFT, 5 );
|
4
|
129 wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png");
|
|
130 wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG );
|
|
131 m_bitmapName = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(320,95), 0 );
|
27
|
132 bSizerRecog->Add( m_bitmapName, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
|
0
|
133
|
|
134 m_staticTextHhsno = new wxStaticText( this, wxID_ANY, wxT("被保険者番号"), wxDefaultPosition, wxDefaultSize, 0 );
|
27
|
135 bSizerRecog->Add( m_staticTextHhsno, 0, wxTOP|wxLEFT, 5 );
|
4
|
136 logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0123456789.png");
|
|
137 bmp.LoadFile( logo, wxBITMAP_TYPE_PNG );
|
|
138 m_bitmapHhsno = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(320,54), 0 );
|
27
|
139 bSizerRecog->Add( m_bitmapHhsno, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
|
0
|
140
|
|
141 m_staticTextGuess = new wxStaticText( this, wxID_ANY, wxT("推定値"), wxDefaultPosition, wxDefaultSize, 0 );
|
27
|
142 bSizerRecog->Add( m_staticTextGuess, 0, wxTOP|wxLEFT, 5 );
|
|
143
|
|
144 wxBoxSizer* bSizerGuess = new wxBoxSizer( wxHORIZONTAL );
|
|
145
|
0
|
146 m_textCtrlGuess = new wxTextCtrl( this, ID_TEXTCTRLGUESS, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
|
|
147 m_textCtrlGuess->SetMaxLength( 10 );
|
|
148 bSizerGuess->Add( m_textCtrlGuess, 0, wxALL, 5 );
|
27
|
149
|
|
150 m_textCtrlName = new wxTextCtrl( this, ID_TEXTCTRLNAME, wxEmptyString, wxDefaultPosition, wxSize(140,-1), 0 );
|
|
151 m_textCtrlName->SetBackgroundColour(wxT("LIGHT GREY"));
|
|
152 bSizerGuess->Add( m_textCtrlName, 0, wxALL, 5 );
|
0
|
153
|
27
|
154 bSizerRecog->Add( bSizerGuess, 0, wxEXPAND, 5 );
|
|
155
|
|
156 bSizerManip->Add( bSizerRecog, 0, wxEXPAND|wxLEFT, 5 );
|
0
|
157
|
|
158 m_listCtrlView = new wxListCtrl( this, ID_LISTCTRLVIEW, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
|
1
|
159 m_listCtrlView->SetBackgroundColour(wxT("LIGHT GREY"));
|
27
|
160 bSizerManip->Add( m_listCtrlView, 1, wxTOP|wxRIGHT|wxBOTTOM|wxEXPAND, 5 );
|
|
161 m_imageList = new wxImageList( THUMB_W, THUMB_H );
|
0
|
162 m_listCtrlView->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL );
|
6
|
163 //m_listCtrlView->SetDropTarget( new DnDFile(m_dirPickerWork) );
|
|
164 this->SetDropTarget( new DnDFile(m_dirPickerWork) );
|
0
|
165
|
|
166 wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL );
|
21
|
167 wxGridSizer* gSizer = new wxGridSizer( 2, 2, 0, 0 );
|
0
|
168
|
21
|
169 m_buttonMove = new wxButton( this, ID_BUTTONMOVE, wxT("移動"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
170 gSizer->Add( m_buttonMove, 0, wxALL, 5 );
|
|
171 m_buttonMove->Enable(false);
|
1
|
172 m_buttonDetect = new wxButton( this, ID_BUTTONDETECT, wxT("検知"), wxDefaultPosition, wxDefaultSize, 0 );
|
21
|
173 gSizer->Add( m_buttonDetect, 0, wxALL, 5 );
|
5
|
174
|
0
|
175 m_buttonDel = new wxButton( this, ID_BUTTONDEL, wxT("削除"), wxDefaultPosition, wxDefaultSize, 0 );
|
21
|
176 gSizer->Add( m_buttonDel, 0, wxALL, 5 );
|
0
|
177 m_buttonUndo = new wxButton( this, ID_BUTTONUNDO, wxT("戻す"), wxDefaultPosition, wxDefaultSize, 0 );
|
21
|
178 gSizer->Add( m_buttonUndo, 0, wxALL, 5 );
|
4
|
179 m_buttonUndo->Enable(false);
|
21
|
180
|
|
181 bSizerButton->Add( gSizer, 0, wxALL, 5 );
|
|
182
|
27
|
183 m_listCtrlHhsDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxSize(280,-1), wxLC_REPORT|wxLC_SINGLE_SEL );
|
21
|
184 wxListItem itemCol;
|
|
185 itemCol.SetText( wxT("通番") );
|
26
|
186 m_listCtrlHhsDir->InsertColumn( 0, itemCol );
|
27
|
187 m_listCtrlHhsDir->SetColumnWidth( 0, 40 );
|
21
|
188 itemCol.SetText( wxT("被保険者番号") );
|
26
|
189 m_listCtrlHhsDir->InsertColumn( 1, itemCol );
|
27
|
190 m_listCtrlHhsDir->SetColumnWidth( 1, 90 );
|
|
191 itemCol.SetText( wxT("枚数") );
|
26
|
192 m_listCtrlHhsDir->InsertColumn( 2, itemCol );
|
27
|
193 m_listCtrlHhsDir->SetColumnWidth( 2, 40 );
|
|
194 itemCol.SetText( wxT("氏名") );
|
|
195 m_listCtrlHhsDir->InsertColumn( 3, itemCol );
|
|
196 m_listCtrlHhsDir->SetColumnWidth( 3, 90 );
|
21
|
197
|
26
|
198 bSizerButton->Add( m_listCtrlHhsDir, 1, wxEXPAND|wxALL, 5 );
|
0
|
199
|
21
|
200 bSizerManip->Add( bSizerButton, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
|
0
|
201
|
|
202 bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 );
|
|
203
|
|
204 this->SetSizer( bSizerTop );
|
|
205 this->Layout();
|
|
206
|
|
207 // ステータスバー
|
24
|
208 int widths[] = { 250, 250, -1, 120 };
|
0
|
209 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
|
|
210 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
|
|
211 m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
212
|
|
213 this->Centre( wxBOTH );
|
11
|
214 m_timer.SetOwner( this, ID_TIMER );
|
0
|
215 }
|
|
216
|
|
217 // destructor
|
|
218 MyFrame::~MyFrame()
|
|
219 {
|
|
220 }
|
|
221
|
|
222 // Event Table
|
|
223 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
11
|
224 EVT_IDLE( MyFrame::OnIdle )
|
|
225 EVT_TIMER( ID_TIMER, MyFrame::OnTimer )
|
1
|
226 EVT_SIZE( MyFrame::OnWinSize )
|
|
227 EVT_MOVE( MyFrame::OnWinMove )
|
29
|
228 EVT_MENU( ID_MENUITEMDETECT, MyFrame::OnDetect )
|
|
229 EVT_MENU( ID_MENUITEMMOVE, MyFrame::OnMove )
|
8
|
230 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam )
|
|
231 EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir )
|
|
232 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
23
|
233 EVT_LIST_ITEM_SELECTED( ID_LISTCTRLVIEW, MyFrame::OnItemSelected )
|
|
234 EVT_LIST_ITEM_DESELECTED( ID_LISTCTRLVIEW, MyFrame::OnItemDeselected )
|
|
235 EVT_LIST_ITEM_ACTIVATED( ID_LISTCTRLVIEW, MyFrame::ViewLarge )
|
8
|
236 EVT_BUTTON( ID_BUTTONNEXTTHU, MyFrame::OnNextThursday )
|
|
237 EVT_BUTTON( ID_BUTTONMKDIR, MyFrame::OnMakeDir )
|
|
238 EVT_BUTTON( ID_BUTTONDETECT, MyFrame::OnDetect )
|
|
239 EVT_BUTTON( ID_BUTTONMOVE, MyFrame::OnMove )
|
|
240 EVT_BUTTON( ID_BUTTONDEL, MyFrame::OnDelete )
|
|
241 EVT_BUTTON( ID_BUTTONUNDO, MyFrame::OnUndo )
|
21
|
242 EVT_LIST_ITEM_ACTIVATED( ID_LISTCTRLDIR, MyFrame::OnOpenHhsDir )
|
0
|
243 EVT_CLOSE( MyFrame::SaveConfig )
|
|
244 END_EVENT_TABLE()
|
|
245
|
|
246 // Event Handlers
|
8
|
247 /* 次の木曜日 */
|
|
248 void MyFrame::OnNextThursday(wxCommandEvent& WXUNUSED(event))
|
|
249 {
|
|
250 wxDateTime dt = m_datePicker->GetValue();
|
|
251 wxDateSpan ds( 0, 0, 0, 1 );
|
|
252 dt += ds;
|
|
253 dt.SetToNextWeekDay( wxDateTime::Thu );
|
|
254 m_datePicker->SetValue( dt );
|
|
255 }
|
|
256
|
0
|
257 /* 移動先フォルダ作成 */
|
3
|
258 void MyFrame::OnMakeDir(wxCommandEvent& WXUNUSED(event))
|
0
|
259 {
|
1
|
260 wxString to;
|
|
261 to.Append( m_comboBoxDrive->GetValue() );
|
|
262 to.Append( wxFILE_SEP_PATH );
|
|
263 wxDateTime dt = m_datePicker->GetValue();
|
|
264 to.Append( dt.Format(wxT("%Y%m%d")) );
|
|
265 to.Append( wxFILE_SEP_PATH );
|
|
266 to.Append( m_comboBoxCcn->GetValue() );
|
|
267 m_textCtrlDist->SetValue( to );
|
|
268
|
0
|
269 wxString ccn = m_comboBoxCcn->GetValue();
|
1
|
270 if ( to.Len() < 15 || ccn.IsEmpty() ) {
|
0
|
271 wxMessageBox(wxT("フォルダを指定してください."));
|
|
272 return;
|
|
273 }
|
|
274
|
1
|
275 wxStringTokenizer tkz( to, wxFILE_SEP_PATH );
|
0
|
276 wxString d;
|
|
277 while ( tkz.HasMoreTokens() ) {
|
|
278 d.Append( tkz.GetNextToken() );
|
|
279 d.Append( wxFILE_SEP_PATH );
|
|
280 if ( !wxDirExists( d ) ) wxMkdir( d );
|
|
281 }
|
4
|
282 m_buttonMove->Enable(true);
|
0
|
283
|
11
|
284 // TODO.
|
|
285 // make 申請書ふぉるだ
|
|
286
|
0
|
287 wxMessageBox(wxT("移動先フォルダ準備完了"));
|
1
|
288 wxString cmd = wxT("explorer ") + to;
|
0
|
289 wxExecute( cmd );
|
|
290 }
|
1
|
291 /* 検知 */
|
|
292 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
|
|
293 {
|
29
|
294 UpdateCache();
|
|
295 UpdateListImage();
|
26
|
296 }
|
|
297
|
|
298 /* 移動 */
|
|
299 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event))
|
|
300 {
|
29
|
301 wxString distdir = m_textCtrlDist->GetValue();
|
|
302 if ( distdir.IsEmpty() ) return;
|
|
303
|
|
304 MoveImages();
|
|
305 UpdateCache();
|
|
306 UpdateListImage();
|
|
307 ListHhsDir();
|
|
308 m_buttonUndo->Enable(true);
|
1
|
309 }
|
5
|
310
|
4
|
311 /* 選択したファイルを移動 */
|
26
|
312 void MyFrame::MoveImages()
|
4
|
313 {
|
|
314 m_undo.Clear();
|
|
315 wxString workdir = m_dirPickerWork->GetPath();
|
|
316 wxString distdir = m_textCtrlDist->GetValue();
|
26
|
317 wxString hhsno = m_textCtrlGuess->GetValue();
|
|
318
|
|
319 m_hhsList.Remove(hhsno);
|
|
320 m_hhsList.Add(hhsno);
|
4
|
321 long item = -1;
|
|
322 for ( ;; ) {
|
|
323 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
324 if ( item == -1 ) break;
|
5
|
325 if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno );
|
|
326
|
|
327 wxString file = m_listCtrlView->GetItemText( item );
|
4
|
328 wxString from = workdir + wxFILE_SEP_PATH + file;
|
5
|
329 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file;
|
4
|
330 wxRenameFile( from, to, true );
|
12
|
331
|
|
332 wxString movecmd = MOVECMD;
|
|
333 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
334 }
|
|
335 }
|
|
336 /* 選択したファイルを削除 */
|
|
337 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
|
338 {
|
|
339 m_undo.Clear();
|
|
340 wxString workdir = m_dirPickerWork->GetPath();
|
|
341 wxString trash = wxGetCwd() + wxFILE_SEP_PATH + wxT("trash");
|
|
342 long item = -1;
|
|
343 for ( ;; ) {
|
|
344 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
345 if ( item == -1 ) break;
|
|
346 wxString file = m_listCtrlView->GetItemText( item );
|
|
347 wxString from = workdir + wxFILE_SEP_PATH + file;
|
|
348 wxString to = trash + wxFILE_SEP_PATH + file;
|
|
349 wxRenameFile( from, to, true );
|
12
|
350
|
|
351 wxString movecmd = MOVECMD;
|
|
352 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
353 }
|
12
|
354 UpdateCache();
|
|
355 UpdateListImage();
|
4
|
356 m_buttonUndo->Enable(true);
|
|
357 }
|
|
358 /* アンドゥ */
|
|
359 void MyFrame::OnUndo(wxCommandEvent& WXUNUSED(event))
|
|
360 {
|
|
361 for ( int i=0; i<m_undo.GetCount(); i++ ) {
|
|
362 wxExecute( m_undo[i] );
|
|
363 }
|
|
364 wxMessageBox(wxT("戻し完了."));
|
|
365 m_buttonUndo->Enable(false);
|
|
366 m_undo.Clear();
|
12
|
367 UpdateCache();
|
|
368 UpdateListImage();
|
26
|
369 ListHhsDir();
|
4
|
370 }
|
0
|
371
|
|
372 /* 画像をリストコントロールに表示 */
|
12
|
373 void MyFrame::UpdateListImage()
|
0
|
374 {
|
11
|
375 // start-up iamge
|
4
|
376 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png");
|
|
377 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG );
|
|
378 m_bitmapName->SetBitmap( bmp );
|
|
379 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png");
|
|
380 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG );
|
|
381 m_bitmapHhsno->SetBitmap( bmp );
|
0
|
382
|
12
|
383 // 本処理
|
0
|
384 m_listCtrlView->DeleteAllItems();
|
|
385 m_imageList->RemoveAll();
|
|
386 wxListItem item;
|
24
|
387 m_textCtrlGuess->SetBackgroundColour(*wxWHITE);
|
23
|
388
|
4
|
389 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
390 pd.SetSize( wxSize(320,140) );
|
0
|
391
|
12
|
392 wxArrayString keys;
|
|
393 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
394 keys.Add(it->first);
|
|
395 }
|
|
396 keys.Sort();
|
23
|
397 // イメージリストを作成
|
|
398 for ( int i=0; i<keys.GetCount(); i++ ) { // item image
|
|
399 CacheItem* ci = new CacheItem;
|
|
400 ci = CH[keys[i]];
|
|
401 m_imageList->Add( ci->thumbnail );
|
|
402 }
|
|
403 for ( int i=0; i<keys.GetCount(); i++ ) { // item selected image
|
|
404 CacheItem* ci = new CacheItem;
|
|
405 ci = CH[keys[i]];
|
|
406 m_imageList->Add( ci->selthumbnail );
|
|
407 }
|
|
408 // アイテム作成
|
|
409 bool select = true; // flag
|
12
|
410 for ( int i=0; i<keys.GetCount(); i++ ) {
|
|
411 CacheItem* ci = new CacheItem;
|
|
412 ci = CH[keys[i]];
|
23
|
413 m_listCtrlView->InsertItem( i, ci->filename, i );
|
12
|
414 m_listCtrlView->SetItem( i, 0, ci->filename, i );
|
3
|
415
|
12
|
416 if ( i == 0 ) { // 1枚目はマークシートのはず
|
|
417 wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG );
|
4
|
418
|
27
|
419 // 氏名画像を表示
|
4
|
420 wxImage name_image;
|
|
421 name_image = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
|
27
|
422 wxBitmap name_bmp = ( name_image.Scale( LOGO_W, LOGO_H, wxIMAGE_QUALITY_HIGH ) );
|
4
|
423 m_bitmapName->SetBitmap( name_bmp );
|
|
424
|
27
|
425 // 被保険者番号画像を表示
|
4
|
426 wxImage hhsno_image;
|
|
427 hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) );
|
27
|
428 wxBitmap hhsno_bmp = ( hhsno_image.Scale( HHSN_W, HHSN_H, wxIMAGE_QUALITY_HIGH ) );
|
4
|
429 m_bitmapHhsno->SetBitmap( hhsno_bmp );
|
|
430
|
12
|
431 wxString hhsno = GuessHhs( ci->fullpath );
|
4
|
432 m_textCtrlGuess->SetValue( hhsno );
|
24
|
433 wxString name;
|
|
434 int judge = IsHhsno( hhsno, name );
|
|
435 if ( judge == 0 ) m_textCtrlGuess->SetBackgroundColour(*wxRED); // not hhsno-style
|
27
|
436 else if ( judge == 1 ) m_textCtrlGuess->SetBackgroundColour(wxT("YELLOW")); // not in DB
|
|
437 m_textCtrlName->SetValue( name );
|
|
438
|
12
|
439 SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
|
|
440 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
441 }
|
12
|
442 else { // 2枚目以降で初めてマークシートを認識したら,それ以降は選択しない
|
|
443 if ( ci->marksheet ) select = false;
|
|
444 if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
445 }
|
|
446
|
6
|
447 pd.Update( i+1, wxT("画像認識中") );
|
0
|
448 }
|
1
|
449
|
23
|
450 // 選択したものは青い画像を使う
|
|
451 long i = -1;
|
|
452 for ( ;; ) {
|
|
453 i = m_listCtrlView->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
454 if ( i == -1 ) break;
|
|
455 m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() );
|
|
456 }
|
|
457
|
4
|
458 SetStatusText( wxEmptyString, 2 );
|
0
|
459 }
|
|
460
|
23
|
461 /* 画像を選択したとき画像の情報をステータスバーに表示 */
|
|
462 void MyFrame::OnItemSelected(wxListEvent& event)
|
1
|
463 {
|
23
|
464 int i = event.GetIndex();
|
|
465 m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() ); // 青い画像
|
|
466
|
13
|
467 if ( m_listCtrlView->GetSelectedItemCount() != 1 ) return;
|
3
|
468 SetStatusText( wxEmptyString, 2 );
|
2
|
469
|
3
|
470 wxString filename = event.GetText();
|
13
|
471 CacheItem* ci = new CacheItem;
|
|
472 ci = CH[filename];
|
3
|
473 wxString msg;
|
13
|
474 if ( ci->marksheet ) msg = wxT("perhaps marksheet !");
|
|
475 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, ci->z, ci->l ), 2 );
|
2
|
476 }
|
23
|
477 void MyFrame::OnItemDeselected(wxListEvent& event)
|
|
478 {
|
|
479 int i = event.GetIndex();
|
|
480 m_listCtrlView->SetItemImage( i, i );
|
|
481 }
|
2
|
482
|
|
483 /* 画像のスクリーン表示*/
|
|
484 void MyFrame::ViewLarge(wxListEvent& event)
|
|
485 {
|
|
486 int i = event.GetIndex();
|
|
487 wxListItem item;
|
|
488 item.SetId(i);
|
|
489
|
|
490 wxString filename = event.GetText();
|
|
491 wxString workdir = m_dirPickerWork->GetPath();
|
|
492 wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
|
|
493
|
|
494 wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
|
|
495 wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) );
|
|
496 wxSplashScreen* splash = new wxSplashScreen( bmp,
|
|
497 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
|
498 3000, NULL, -1, wxDefaultPosition, wxDefaultSize,
|
|
499 wxSIMPLE_BORDER|wxSTAY_ON_TOP );
|
|
500 wxYield();
|
1
|
501 }
|
|
502
|
|
503 /* パラメータダイアログ */
|
|
504 void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event))
|
|
505 {
|
5
|
506 ParamDialog* pd = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") );
|
|
507 if ( pd->ShowModal() == wxID_OK ) {
|
6
|
508 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax );
|
5
|
509 }
|
|
510 pd->Destroy();
|
1
|
511 }
|
|
512
|
11
|
513 /* キャッシュ作成&更新 */
|
|
514 void MyFrame::UpdateCache()
|
|
515 {
|
24
|
516 double zmin, zmax; long lmin, lmax;
|
|
517 wxGetApp().zmin.ToDouble( &zmin );
|
|
518 wxGetApp().zmax.ToDouble( &zmax );
|
|
519 wxGetApp().lmin.ToLong( &lmin );
|
|
520 wxGetApp().lmax.ToLong( &lmax );
|
|
521
|
12
|
522 m_buttonDetect->Enable(false);
|
11
|
523 wxGetApp().WriteLog( wxT("start updating cache") );
|
24
|
524 wxStopWatch sw;
|
|
525 sw.Start(0);
|
11
|
526
|
12
|
527 /* キャッシュ存在フラグOFF */
|
|
528 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
11
|
529 CacheItem* ci = new CacheItem;
|
12
|
530 ci = it->second;
|
11
|
531 ci->exists = false;
|
|
532 }
|
12
|
533
|
|
534 wxString workdir = m_dirPickerWork->GetPath();
|
|
535 wxArrayString filenames;
|
|
536 wxListItem item;
|
|
537
|
|
538 /* キャッシュ作成 */
|
26
|
539 unsigned int n = wxDir::GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
11
|
540 for ( int i=0; i<n; i++ ) {
|
12
|
541 wxString fullpath = filenames[i];
|
|
542 wxFileName f( fullpath );
|
|
543 wxString file = f.GetFullName();
|
|
544
|
11
|
545 CacheItem* ci = new CacheItem;
|
12
|
546 /* キャッシュ済みのものはスキップ */
|
|
547 if ( CH.count(file) ) {
|
|
548 ci = CH[file];
|
11
|
549 ci->exists = true;
|
|
550 continue;
|
|
551 }
|
12
|
552 /* 新しいファイルはキャッシュ */
|
24
|
553 //float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
|
|
554 float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax );
|
12
|
555 wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
|
27
|
556 wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH );
|
23
|
557 wxBitmap bmp( thumbnail );
|
|
558 unsigned char *data = thumbnail.GetData();
|
27
|
559 for ( int y=0; y<THUMB_H; y++ ) for ( int x=0; x<THUMB_W; x++ ) data[(y*THUMB_W+x)*3+2] = 255; // 文字色:黒(0,0,0)->青(0,0.255)
|
23
|
560 wxBitmap bmp_mask( thumbnail );
|
12
|
561
|
23
|
562 ci->filename = file;
|
|
563 ci->fullpath = fullpath;
|
|
564 ci->marksheet = m;
|
|
565 ci->z = z;
|
|
566 ci->l = l;
|
|
567 ci->exists = true;
|
|
568 ci->thumbnail = bmp;
|
|
569 ci->selthumbnail = bmp_mask;
|
|
570 ci->modtime = wxEmptyString; // TODO.
|
12
|
571
|
11
|
572 CH[ci->filename] = ci; // add hash
|
26
|
573 SetStatusText( wxString::Format( wxT("rebuiling cache...( %d/%d :%.1fsec passed )"), i+1, n, (float)sw.Time()/1000 ), 0 );
|
12
|
574 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
|
11
|
575 }
|
|
576
|
12
|
577 /* 存在しないファイルはキャッシュから削除 */
|
|
578 wxArrayString removelist;
|
|
579 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
580 CacheItem* ci = new CacheItem;
|
|
581 ci = it->second;
|
|
582 if ( !ci->exists ) removelist.Add( ci->filename );
|
|
583 }
|
|
584 for ( int i=0; i<removelist.GetCount(); i++ ) {
|
|
585 CH.erase(removelist[i]);
|
|
586 wxGetApp().WriteLog( removelist[i] + wxT(" removed.") );
|
|
587 }
|
|
588
|
|
589 m_buttonDetect->Enable(true);
|
11
|
590 SetStatusText( wxEmptyString, 0 );
|
|
591 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
|
|
592 }
|
|
593
|
26
|
594 /* 被保険者フォルダを列挙 */
|
|
595 void MyFrame::ListHhsDir()
|
|
596 {
|
|
597 wxString distdir = m_textCtrlDist->GetValue();
|
|
598 wxString hhsdir;
|
|
599 wxString buf;
|
|
600
|
|
601 m_listCtrlHhsDir->DeleteAllItems();
|
|
602 for ( int i=0; i<m_hhsList.GetCount(); i++ ) {
|
|
603 hhsdir = distdir + wxFILE_SEP_PATH + m_hhsList[i];
|
|
604 wxArrayString filenames;
|
|
605 unsigned int n = wxDir::GetAllFiles( hhsdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
|
606
|
|
607 m_listCtrlHhsDir->InsertItem( i, -1 );
|
|
608 buf.Printf(wxT("%d"),i+1);
|
|
609 m_listCtrlHhsDir->SetItem( i, 0, buf, -1 );
|
|
610 m_listCtrlHhsDir->SetItem( i, 1, m_hhsList[i], -1 );
|
|
611 buf.Printf(wxT("%d"),n);
|
|
612 m_listCtrlHhsDir->SetItem( i, 2, buf, -1 );
|
|
613 if ( i % 2 ) m_listCtrlHhsDir->SetItemBackgroundColour( i, wxColour(wxT("WHEAT")) );
|
|
614 }
|
|
615 }
|
|
616
|
|
617 /* 被保険者フォルダを開く */
|
21
|
618 void MyFrame::OnOpenHhsDir(wxListEvent& event)
|
|
619 {
|
26
|
620 wxString hhsdir;
|
|
621 hhsdir.Append( m_textCtrlDist->GetValue() );
|
21
|
622 hhsdir.Append( wxFILE_SEP_PATH );
|
|
623
|
27
|
624 int i = event.GetIndex();
|
|
625 wxListItem item;
|
|
626 item.SetId(i);
|
|
627
|
21
|
628 item.SetColumn(1);
|
|
629 item.SetMask(wxLIST_MASK_TEXT);
|
26
|
630 m_listCtrlHhsDir->GetItem( item );
|
21
|
631 hhsdir.Append( item.GetText() );
|
|
632 wxString execmd = wxT("explorer ") + hhsdir;
|
|
633 wxExecute( execmd );
|
|
634 }
|
|
635
|
0
|
636 // 以下,定型もの
|
11
|
637 void MyFrame::OnTimer(wxTimerEvent& event)
|
|
638 {
|
|
639 UpdateCache();
|
|
640 }
|
26
|
641
|
11
|
642 /* アイドリング */
|
|
643 void MyFrame::OnIdle(wxIdleEvent& event)
|
|
644 {
|
|
645 if ( !m_timer.IsRunning() ) {
|
|
646 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT );
|
|
647 }
|
|
648 event.RequestMore();
|
|
649 event.Skip();
|
|
650 }
|
|
651
|
0
|
652 /* アプリフォルダを開く */
|
|
653 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
654 {
|
5
|
655 wxString appdir = wxGetCwd();
|
0
|
656 wxString execmd = wxT("explorer ") + appdir;
|
|
657 wxExecute( execmd );
|
|
658 }
|
|
659
|
|
660 /* サイズ変更 */
|
1
|
661 void MyFrame::OnWinSize(wxSizeEvent& event)
|
0
|
662 {
|
|
663 this->Refresh( true, NULL );
|
|
664 TellLocation();
|
|
665 event.Skip();
|
|
666 }
|
|
667 /* ウィンドウ移動 */
|
1
|
668 void MyFrame::OnWinMove(wxMoveEvent& WXUNUSED(event))
|
0
|
669 {
|
|
670 TellLocation();
|
|
671 return;
|
|
672 }
|
|
673 /* ウィンドウ位置とサイズを表示 */
|
|
674 void MyFrame::TellLocation( void )
|
|
675 {
|
|
676 wxRect r = this->GetRect();
|
|
677 int x = r.GetX();
|
|
678 int y = r.GetY();
|
|
679 int w = r.GetWidth();
|
|
680 int h = r.GetHeight();
|
1
|
681 SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
|
0
|
682 }
|
|
683 /* 終了 */
|
|
684 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
685 {
|
|
686 Close(true);
|
|
687 }
|
|
688 /* 設定を保存 */
|
|
689 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
690 {
|
|
691 if ( !IsIconized() && !IsMaximized() ) {
|
|
692 wxGetApp().rect = this->GetRect();
|
|
693 }
|
|
694 wxGetApp().workdir = m_dirPickerWork->GetPath();
|
|
695
|
|
696 Destroy();
|
|
697 }
|
|
698
|