0
|
1 // Filename : myframe.cpp
|
24
|
2 // Last Change: 02-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
|
|
158 m_listCtrlDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
|
|
159 wxListItem itemCol;
|
|
160 itemCol.SetText( wxT("通番") );
|
|
161 m_listCtrlDir->InsertColumn( 0, itemCol );
|
|
162 m_listCtrlDir->SetColumnWidth( 0, 50 );
|
|
163 itemCol.SetText( wxT("被保険者番号") );
|
|
164 m_listCtrlDir->InsertColumn( 1, itemCol );
|
|
165 m_listCtrlDir->SetColumnWidth( 1, 100 );
|
|
166 itemCol.SetText( wxT("ファイル数") );
|
|
167 m_listCtrlDir->InsertColumn( 2, itemCol );
|
|
168 m_listCtrlDir->SetColumnWidth( 2, 60 );
|
|
169
|
|
170 bSizerButton->Add( m_listCtrlDir, 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 )
|
11
|
196 EVT_IDLE( MyFrame::OnIdle )
|
|
197 EVT_TIMER( ID_TIMER, MyFrame::OnTimer )
|
1
|
198 EVT_SIZE( MyFrame::OnWinSize )
|
|
199 EVT_MOVE( MyFrame::OnWinMove )
|
8
|
200 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam )
|
|
201 EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir )
|
|
202 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
23
|
203 EVT_LIST_ITEM_SELECTED( ID_LISTCTRLVIEW, MyFrame::OnItemSelected )
|
|
204 EVT_LIST_ITEM_DESELECTED( ID_LISTCTRLVIEW, MyFrame::OnItemDeselected )
|
|
205 EVT_LIST_ITEM_ACTIVATED( ID_LISTCTRLVIEW, MyFrame::ViewLarge )
|
8
|
206 EVT_BUTTON( ID_BUTTONNEXTTHU, MyFrame::OnNextThursday )
|
|
207 EVT_BUTTON( ID_BUTTONMKDIR, MyFrame::OnMakeDir )
|
|
208 EVT_BUTTON( ID_BUTTONDETECT, MyFrame::OnDetect )
|
|
209 EVT_BUTTON( ID_BUTTONMOVE, MyFrame::OnMove )
|
|
210 EVT_BUTTON( ID_BUTTONDEL, MyFrame::OnDelete )
|
|
211 EVT_BUTTON( ID_BUTTONUNDO, MyFrame::OnUndo )
|
21
|
212 EVT_LIST_ITEM_ACTIVATED( ID_LISTCTRLDIR, MyFrame::OnOpenHhsDir )
|
0
|
213 EVT_CLOSE( MyFrame::SaveConfig )
|
|
214 END_EVENT_TABLE()
|
|
215
|
|
216 // Event Handlers
|
8
|
217 /* 次の木曜日 */
|
|
218 void MyFrame::OnNextThursday(wxCommandEvent& WXUNUSED(event))
|
|
219 {
|
|
220 wxDateTime dt = m_datePicker->GetValue();
|
|
221 wxDateSpan ds( 0, 0, 0, 1 );
|
|
222 dt += ds;
|
|
223 dt.SetToNextWeekDay( wxDateTime::Thu );
|
|
224 m_datePicker->SetValue( dt );
|
|
225 }
|
|
226
|
0
|
227 /* 移動先フォルダ作成 */
|
3
|
228 void MyFrame::OnMakeDir(wxCommandEvent& WXUNUSED(event))
|
0
|
229 {
|
1
|
230 wxString to;
|
|
231 to.Append( m_comboBoxDrive->GetValue() );
|
|
232 to.Append( wxFILE_SEP_PATH );
|
|
233 wxDateTime dt = m_datePicker->GetValue();
|
|
234 to.Append( dt.Format(wxT("%Y%m%d")) );
|
|
235 to.Append( wxFILE_SEP_PATH );
|
|
236 to.Append( m_comboBoxCcn->GetValue() );
|
|
237 m_textCtrlDist->SetValue( to );
|
|
238
|
0
|
239 wxString ccn = m_comboBoxCcn->GetValue();
|
1
|
240 if ( to.Len() < 15 || ccn.IsEmpty() ) {
|
0
|
241 wxMessageBox(wxT("フォルダを指定してください."));
|
|
242 return;
|
|
243 }
|
|
244
|
1
|
245 wxStringTokenizer tkz( to, wxFILE_SEP_PATH );
|
0
|
246 wxString d;
|
|
247 while ( tkz.HasMoreTokens() ) {
|
|
248 d.Append( tkz.GetNextToken() );
|
|
249 d.Append( wxFILE_SEP_PATH );
|
|
250 if ( !wxDirExists( d ) ) wxMkdir( d );
|
|
251 }
|
4
|
252 m_buttonMove->Enable(true);
|
0
|
253
|
11
|
254 // TODO.
|
|
255 // make 申請書ふぉるだ
|
|
256
|
0
|
257 wxMessageBox(wxT("移動先フォルダ準備完了"));
|
1
|
258 wxString cmd = wxT("explorer ") + to;
|
0
|
259 wxExecute( cmd );
|
|
260 }
|
1
|
261 /* 検知 */
|
|
262 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
|
|
263 {
|
12
|
264 UpdateCache();
|
|
265 UpdateListImage();
|
1
|
266 }
|
5
|
267
|
4
|
268 /* 選択したファイルを移動 */
|
5
|
269 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event))
|
4
|
270 {
|
|
271 m_undo.Clear();
|
|
272 wxString workdir = m_dirPickerWork->GetPath();
|
|
273 wxString distdir = m_textCtrlDist->GetValue();
|
|
274 long item = -1;
|
|
275 for ( ;; ) {
|
|
276 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
277 if ( item == -1 ) break;
|
5
|
278 wxString hhsno = m_textCtrlGuess->GetValue();
|
|
279 if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno );
|
|
280
|
|
281 wxString file = m_listCtrlView->GetItemText( item );
|
4
|
282 wxString from = workdir + wxFILE_SEP_PATH + file;
|
5
|
283 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file;
|
4
|
284 wxRenameFile( from, to, true );
|
12
|
285
|
|
286 wxString movecmd = MOVECMD;
|
|
287 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
288 }
|
12
|
289 UpdateCache();
|
|
290 UpdateListImage();
|
4
|
291 m_buttonUndo->Enable(true);
|
|
292 }
|
|
293 /* 選択したファイルを削除 */
|
|
294 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
|
295 {
|
|
296 m_undo.Clear();
|
|
297 wxString workdir = m_dirPickerWork->GetPath();
|
|
298 wxString trash = wxGetCwd() + wxFILE_SEP_PATH + wxT("trash");
|
|
299 long item = -1;
|
|
300 for ( ;; ) {
|
|
301 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
302 if ( item == -1 ) break;
|
|
303 wxString file = m_listCtrlView->GetItemText( item );
|
|
304 wxString from = workdir + wxFILE_SEP_PATH + file;
|
|
305 wxString to = trash + wxFILE_SEP_PATH + file;
|
|
306 wxRenameFile( from, to, true );
|
12
|
307
|
|
308 wxString movecmd = MOVECMD;
|
|
309 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
310 }
|
12
|
311 UpdateCache();
|
|
312 UpdateListImage();
|
4
|
313 m_buttonUndo->Enable(true);
|
|
314 }
|
|
315 /* アンドゥ */
|
|
316 void MyFrame::OnUndo(wxCommandEvent& WXUNUSED(event))
|
|
317 {
|
|
318 for ( int i=0; i<m_undo.GetCount(); i++ ) {
|
|
319 wxExecute( m_undo[i] );
|
|
320 }
|
|
321 wxMessageBox(wxT("戻し完了."));
|
|
322 m_buttonUndo->Enable(false);
|
|
323 m_undo.Clear();
|
12
|
324 UpdateCache();
|
|
325 UpdateListImage();
|
4
|
326 }
|
0
|
327
|
|
328 /* 画像をリストコントロールに表示 */
|
12
|
329 void MyFrame::UpdateListImage()
|
0
|
330 {
|
11
|
331 // start-up iamge
|
4
|
332 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png");
|
|
333 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG );
|
|
334 m_bitmapName->SetBitmap( bmp );
|
|
335 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png");
|
|
336 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG );
|
|
337 m_bitmapHhsno->SetBitmap( bmp );
|
0
|
338
|
12
|
339 // 本処理
|
0
|
340 m_listCtrlView->DeleteAllItems();
|
|
341 m_imageList->RemoveAll();
|
|
342 wxListItem item;
|
24
|
343 m_textCtrlGuess->SetBackgroundColour(*wxWHITE);
|
23
|
344
|
4
|
345 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
346 pd.SetSize( wxSize(320,140) );
|
0
|
347
|
12
|
348 wxArrayString keys;
|
|
349 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
350 keys.Add(it->first);
|
|
351 }
|
|
352 keys.Sort();
|
23
|
353 // イメージリストを作成
|
|
354 for ( int i=0; i<keys.GetCount(); i++ ) { // item image
|
|
355 CacheItem* ci = new CacheItem;
|
|
356 ci = CH[keys[i]];
|
|
357 m_imageList->Add( ci->thumbnail );
|
|
358 }
|
|
359 for ( int i=0; i<keys.GetCount(); i++ ) { // item selected image
|
|
360 CacheItem* ci = new CacheItem;
|
|
361 ci = CH[keys[i]];
|
|
362 m_imageList->Add( ci->selthumbnail );
|
|
363 }
|
|
364 // アイテム作成
|
|
365 bool select = true; // flag
|
12
|
366 for ( int i=0; i<keys.GetCount(); i++ ) {
|
|
367 CacheItem* ci = new CacheItem;
|
|
368 ci = CH[keys[i]];
|
23
|
369 m_listCtrlView->InsertItem( i, ci->filename, i );
|
12
|
370 m_listCtrlView->SetItem( i, 0, ci->filename, i );
|
3
|
371
|
12
|
372 if ( i == 0 ) { // 1枚目はマークシートのはず
|
|
373 wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG );
|
4
|
374
|
|
375 wxImage name_image;
|
|
376 name_image = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
|
|
377 wxBitmap name_bmp = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) );
|
|
378 m_bitmapName->SetBitmap( name_bmp );
|
|
379
|
|
380 wxImage hhsno_image;
|
|
381 hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) );
|
|
382 wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) );
|
|
383 m_bitmapHhsno->SetBitmap( hhsno_bmp );
|
|
384
|
12
|
385 wxString hhsno = GuessHhs( ci->fullpath );
|
4
|
386 m_textCtrlGuess->SetValue( hhsno );
|
24
|
387 wxString name;
|
|
388 int judge = IsHhsno( hhsno, name );
|
|
389 if ( judge == 0 ) m_textCtrlGuess->SetBackgroundColour(*wxRED); // not hhsno-style
|
|
390 //else if ( judge == 1 ) m_textCtrlGuess->SetBackgroundColour(wxT("YELLOW")); // not in DB
|
12
|
391 SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
|
|
392 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
393 }
|
12
|
394 else { // 2枚目以降で初めてマークシートを認識したら,それ以降は選択しない
|
|
395 if ( ci->marksheet ) select = false;
|
|
396 if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
397 }
|
|
398
|
6
|
399 pd.Update( i+1, wxT("画像認識中") );
|
0
|
400 }
|
1
|
401
|
23
|
402 // 選択したものは青い画像を使う
|
|
403 long i = -1;
|
|
404 for ( ;; ) {
|
|
405 i = m_listCtrlView->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
406 if ( i == -1 ) break;
|
|
407 m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() );
|
|
408 }
|
|
409
|
4
|
410 SetStatusText( wxEmptyString, 2 );
|
0
|
411 }
|
|
412
|
23
|
413 /* 画像を選択したとき画像の情報をステータスバーに表示 */
|
|
414 void MyFrame::OnItemSelected(wxListEvent& event)
|
1
|
415 {
|
23
|
416 int i = event.GetIndex();
|
|
417 m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() ); // 青い画像
|
|
418
|
13
|
419 if ( m_listCtrlView->GetSelectedItemCount() != 1 ) return;
|
3
|
420 SetStatusText( wxEmptyString, 2 );
|
2
|
421
|
3
|
422 wxString filename = event.GetText();
|
13
|
423 CacheItem* ci = new CacheItem;
|
|
424 ci = CH[filename];
|
3
|
425 wxString msg;
|
13
|
426 if ( ci->marksheet ) msg = wxT("perhaps marksheet !");
|
|
427 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, ci->z, ci->l ), 2 );
|
2
|
428 }
|
23
|
429 void MyFrame::OnItemDeselected(wxListEvent& event)
|
|
430 {
|
|
431 int i = event.GetIndex();
|
|
432 m_listCtrlView->SetItemImage( i, i );
|
|
433 }
|
2
|
434
|
|
435 /* 画像のスクリーン表示*/
|
|
436 void MyFrame::ViewLarge(wxListEvent& event)
|
|
437 {
|
|
438 int i = event.GetIndex();
|
|
439 wxListItem item;
|
|
440 item.SetId(i);
|
|
441
|
|
442 wxString filename = event.GetText();
|
|
443 wxString workdir = m_dirPickerWork->GetPath();
|
|
444 wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
|
|
445
|
|
446 wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
|
|
447 wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) );
|
|
448 wxSplashScreen* splash = new wxSplashScreen( bmp,
|
|
449 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
|
450 3000, NULL, -1, wxDefaultPosition, wxDefaultSize,
|
|
451 wxSIMPLE_BORDER|wxSTAY_ON_TOP );
|
|
452 wxYield();
|
1
|
453 }
|
|
454
|
|
455 /* パラメータダイアログ */
|
|
456 void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event))
|
|
457 {
|
5
|
458 ParamDialog* pd = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") );
|
|
459 if ( pd->ShowModal() == wxID_OK ) {
|
6
|
460 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax );
|
5
|
461 }
|
|
462 pd->Destroy();
|
1
|
463 }
|
|
464
|
11
|
465 /* キャッシュ作成&更新 */
|
|
466 void MyFrame::UpdateCache()
|
|
467 {
|
24
|
468 double zmin, zmax; long lmin, lmax;
|
|
469 wxGetApp().zmin.ToDouble( &zmin );
|
|
470 wxGetApp().zmax.ToDouble( &zmax );
|
|
471 wxGetApp().lmin.ToLong( &lmin );
|
|
472 wxGetApp().lmax.ToLong( &lmax );
|
|
473
|
12
|
474 m_buttonDetect->Enable(false);
|
11
|
475 wxGetApp().WriteLog( wxT("start updating cache") );
|
|
476 SetStatusText( wxT("rebuiling cache..."), 0 );
|
24
|
477 wxStopWatch sw;
|
|
478 sw.Start(0);
|
11
|
479
|
12
|
480 /* キャッシュ存在フラグOFF */
|
|
481 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
11
|
482 CacheItem* ci = new CacheItem;
|
12
|
483 ci = it->second;
|
11
|
484 ci->exists = false;
|
|
485 }
|
12
|
486
|
|
487 wxString workdir = m_dirPickerWork->GetPath();
|
|
488 wxDir dir( workdir );
|
|
489 if ( !dir.IsOpened() ) return;
|
|
490
|
|
491 wxArrayString filenames;
|
|
492 wxListItem item;
|
|
493
|
|
494 /* キャッシュ作成 */
|
11
|
495 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
|
496 for ( int i=0; i<n; i++ ) {
|
12
|
497 wxString fullpath = filenames[i];
|
|
498 wxFileName f( fullpath );
|
|
499 wxString file = f.GetFullName();
|
|
500
|
11
|
501 CacheItem* ci = new CacheItem;
|
12
|
502 /* キャッシュ済みのものはスキップ */
|
|
503 if ( CH.count(file) ) {
|
|
504 ci = CH[file];
|
11
|
505 ci->exists = true;
|
|
506 continue;
|
|
507 }
|
12
|
508 /* 新しいファイルはキャッシュ */
|
24
|
509 //float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
|
|
510 float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax );
|
12
|
511 wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
|
23
|
512 wxImage thumbnail = image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH );
|
|
513 wxBitmap bmp( thumbnail );
|
|
514 unsigned char *data = thumbnail.GetData();
|
24
|
515 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
|
516 wxBitmap bmp_mask( thumbnail );
|
12
|
517
|
23
|
518 ci->filename = file;
|
|
519 ci->fullpath = fullpath;
|
|
520 ci->marksheet = m;
|
|
521 ci->z = z;
|
|
522 ci->l = l;
|
|
523 ci->exists = true;
|
|
524 ci->thumbnail = bmp;
|
|
525 ci->selthumbnail = bmp_mask;
|
|
526 ci->modtime = wxEmptyString; // TODO.
|
12
|
527
|
11
|
528 CH[ci->filename] = ci; // add hash
|
24
|
529 SetStatusText( wxString::Format( wxT("rebuiling cache...(%.1fsec passed)"), (float)sw.Time()/1000 ), 0 );
|
12
|
530 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
|
11
|
531 }
|
|
532
|
12
|
533 /* 存在しないファイルはキャッシュから削除 */
|
|
534 wxArrayString removelist;
|
|
535 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
536 CacheItem* ci = new CacheItem;
|
|
537 ci = it->second;
|
|
538 if ( !ci->exists ) removelist.Add( ci->filename );
|
|
539 }
|
|
540 for ( int i=0; i<removelist.GetCount(); i++ ) {
|
|
541 CH.erase(removelist[i]);
|
|
542 wxGetApp().WriteLog( removelist[i] + wxT(" removed.") );
|
|
543 }
|
|
544
|
|
545 m_buttonDetect->Enable(true);
|
11
|
546 SetStatusText( wxEmptyString, 0 );
|
|
547 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
|
|
548 }
|
|
549
|
21
|
550 /* 被保険者を開く */
|
|
551 void MyFrame::OnOpenHhsDir(wxListEvent& event)
|
|
552 {
|
|
553 wxString hhsdir = m_textCtrlDist->GetValue();
|
|
554 hhsdir.Append( wxFILE_SEP_PATH );
|
|
555
|
|
556 wxListItem item = event.GetItem();
|
|
557 item.SetColumn(1);
|
|
558 item.SetMask(wxLIST_MASK_TEXT);
|
|
559 m_listCtrlDir->GetItem( item );
|
|
560 hhsdir.Append( item.GetText() );
|
|
561 wxString execmd = wxT("explorer ") + hhsdir;
|
|
562 wxExecute( execmd );
|
|
563 }
|
|
564
|
0
|
565 // 以下,定型もの
|
11
|
566 void MyFrame::OnTimer(wxTimerEvent& event)
|
|
567 {
|
|
568 UpdateCache();
|
|
569 }
|
|
570 /* アイドリング */
|
|
571 void MyFrame::OnIdle(wxIdleEvent& event)
|
|
572 {
|
|
573 if ( !m_timer.IsRunning() ) {
|
|
574 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT );
|
|
575 }
|
|
576 event.RequestMore();
|
|
577 event.Skip();
|
|
578 }
|
|
579
|
0
|
580 /* アプリフォルダを開く */
|
|
581 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
582 {
|
5
|
583 wxString appdir = wxGetCwd();
|
0
|
584 wxString execmd = wxT("explorer ") + appdir;
|
|
585 wxExecute( execmd );
|
|
586 }
|
|
587
|
|
588 /* サイズ変更 */
|
1
|
589 void MyFrame::OnWinSize(wxSizeEvent& event)
|
0
|
590 {
|
|
591 this->Refresh( true, NULL );
|
|
592 TellLocation();
|
|
593 event.Skip();
|
|
594 }
|
|
595 /* ウィンドウ移動 */
|
1
|
596 void MyFrame::OnWinMove(wxMoveEvent& WXUNUSED(event))
|
0
|
597 {
|
|
598 TellLocation();
|
|
599 return;
|
|
600 }
|
|
601 /* ウィンドウ位置とサイズを表示 */
|
|
602 void MyFrame::TellLocation( void )
|
|
603 {
|
|
604 wxRect r = this->GetRect();
|
|
605 int x = r.GetX();
|
|
606 int y = r.GetY();
|
|
607 int w = r.GetWidth();
|
|
608 int h = r.GetHeight();
|
1
|
609 SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
|
0
|
610 }
|
|
611 /* 終了 */
|
|
612 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
613 {
|
|
614 Close(true);
|
|
615 }
|
|
616 /* 設定を保存 */
|
|
617 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
618 {
|
|
619 if ( !IsIconized() && !IsMaximized() ) {
|
|
620 wxGetApp().rect = this->GetRect();
|
|
621 }
|
|
622 wxGetApp().workdir = m_dirPickerWork->GetPath();
|
|
623
|
|
624 Destroy();
|
|
625 }
|
|
626
|