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