0
|
1 // Filename : myframe.cpp
|
11
|
2 // Last Change: 23-Oct-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 );
|
|
142
|
1
|
143 m_buttonDetect = new wxButton( this, ID_BUTTONDETECT, wxT("検知"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
144 bSizerButton->Add( m_buttonDetect, 0, wxALL, 5 );
|
0
|
145 m_buttonMove = new wxButton( this, ID_BUTTONMOVE, wxT("移動"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
146 bSizerButton->Add( m_buttonMove, 0, wxALL, 5 );
|
4
|
147 m_buttonMove->Enable(false);
|
5
|
148
|
0
|
149 m_buttonDel = new wxButton( this, ID_BUTTONDEL, wxT("削除"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
150 bSizerButton->Add( m_buttonDel, 0, wxALL, 5 );
|
|
151 m_buttonUndo = new wxButton( this, ID_BUTTONUNDO, wxT("戻す"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
152 bSizerButton->Add( m_buttonUndo, 0, wxALL, 5 );
|
4
|
153 m_buttonUndo->Enable(false);
|
0
|
154
|
|
155 bSizerManip->Add( bSizerButton, 0, wxALIGN_CENTER_VERTICAL, 5 );
|
|
156
|
|
157 bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 );
|
|
158
|
|
159 this->SetSizer( bSizerTop );
|
|
160 this->Layout();
|
|
161
|
|
162 // ステータスバー
|
3
|
163 int widths[] = { 150, 250, -1, 120 };
|
0
|
164 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
|
|
165 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
|
|
166 m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
167
|
|
168 this->Centre( wxBOTH );
|
11
|
169 m_timer.SetOwner( this, ID_TIMER );
|
0
|
170 }
|
|
171
|
|
172 // destructor
|
|
173 MyFrame::~MyFrame()
|
|
174 {
|
|
175 }
|
|
176
|
|
177 // Event Table
|
|
178 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
11
|
179 EVT_IDLE( MyFrame::OnIdle )
|
|
180 EVT_TIMER( ID_TIMER, MyFrame::OnTimer )
|
1
|
181 EVT_SIZE( MyFrame::OnWinSize )
|
|
182 EVT_MOVE( MyFrame::OnWinMove )
|
8
|
183 EVT_MENU( ID_MENUITEMPARAM, MyFrame::OnParam )
|
|
184 EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir )
|
|
185 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
|
186 EVT_BUTTON( ID_BUTTONNEXTTHU, MyFrame::OnNextThursday )
|
|
187 EVT_BUTTON( ID_BUTTONMKDIR, MyFrame::OnMakeDir )
|
|
188 EVT_BUTTON( ID_BUTTONDETECT, MyFrame::OnDetect )
|
|
189 EVT_BUTTON( ID_BUTTONMOVE, MyFrame::OnMove )
|
|
190 EVT_BUTTON( ID_BUTTONDEL, MyFrame::OnDelete )
|
|
191 EVT_BUTTON( ID_BUTTONUNDO, MyFrame::OnUndo )
|
3
|
192 EVT_LIST_ITEM_SELECTED( ID_LISTCTRLVIEW, MyFrame::GetImageInfo )
|
|
193 EVT_LIST_ITEM_ACTIVATED( ID_LISTCTRLVIEW, MyFrame::ViewLarge )
|
0
|
194 EVT_CLOSE( MyFrame::SaveConfig )
|
|
195 END_EVENT_TABLE()
|
|
196
|
|
197 // Event Handlers
|
8
|
198 /* 次の木曜日 */
|
|
199 void MyFrame::OnNextThursday(wxCommandEvent& WXUNUSED(event))
|
|
200 {
|
|
201 wxDateTime dt = m_datePicker->GetValue();
|
|
202 wxDateSpan ds( 0, 0, 0, 1 );
|
|
203 dt += ds;
|
|
204 dt.SetToNextWeekDay( wxDateTime::Thu );
|
|
205 m_datePicker->SetValue( dt );
|
|
206 }
|
|
207
|
0
|
208 /* 移動先フォルダ作成 */
|
3
|
209 void MyFrame::OnMakeDir(wxCommandEvent& WXUNUSED(event))
|
0
|
210 {
|
1
|
211 wxString to;
|
|
212 to.Append( m_comboBoxDrive->GetValue() );
|
|
213 to.Append( wxFILE_SEP_PATH );
|
|
214 wxDateTime dt = m_datePicker->GetValue();
|
|
215 to.Append( dt.Format(wxT("%Y%m%d")) );
|
|
216 to.Append( wxFILE_SEP_PATH );
|
|
217 to.Append( m_comboBoxCcn->GetValue() );
|
|
218 m_textCtrlDist->SetValue( to );
|
|
219
|
0
|
220 wxString ccn = m_comboBoxCcn->GetValue();
|
1
|
221 if ( to.Len() < 15 || ccn.IsEmpty() ) {
|
0
|
222 wxMessageBox(wxT("フォルダを指定してください."));
|
|
223 return;
|
|
224 }
|
|
225
|
1
|
226 wxStringTokenizer tkz( to, wxFILE_SEP_PATH );
|
0
|
227 wxString d;
|
|
228 while ( tkz.HasMoreTokens() ) {
|
|
229 d.Append( tkz.GetNextToken() );
|
|
230 d.Append( wxFILE_SEP_PATH );
|
|
231 if ( !wxDirExists( d ) ) wxMkdir( d );
|
|
232 }
|
4
|
233 m_buttonMove->Enable(true);
|
0
|
234
|
11
|
235 // TODO.
|
|
236 // make 申請書ふぉるだ
|
|
237
|
0
|
238 wxMessageBox(wxT("移動先フォルダ準備完了"));
|
1
|
239 wxString cmd = wxT("explorer ") + to;
|
0
|
240 wxExecute( cmd );
|
|
241 }
|
1
|
242 /* 検知 */
|
|
243 void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
|
|
244 {
|
12
|
245 UpdateCache();
|
|
246 UpdateListImage();
|
1
|
247 }
|
5
|
248
|
4
|
249 /* 選択したファイルを移動 */
|
5
|
250 void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event))
|
4
|
251 {
|
|
252 m_undo.Clear();
|
|
253 wxString workdir = m_dirPickerWork->GetPath();
|
|
254 wxString distdir = m_textCtrlDist->GetValue();
|
|
255 long item = -1;
|
|
256 for ( ;; ) {
|
|
257 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
258 if ( item == -1 ) break;
|
5
|
259 wxString hhsno = m_textCtrlGuess->GetValue();
|
|
260 if ( !wxDirExists( distdir + wxFILE_SEP_PATH + hhsno ) ) wxMkdir( distdir + wxFILE_SEP_PATH + hhsno );
|
|
261
|
|
262 wxString file = m_listCtrlView->GetItemText( item );
|
4
|
263 wxString from = workdir + wxFILE_SEP_PATH + file;
|
5
|
264 wxString to = distdir + wxFILE_SEP_PATH + hhsno + wxFILE_SEP_PATH + file;
|
4
|
265 wxRenameFile( from, to, true );
|
12
|
266
|
|
267 wxString movecmd = MOVECMD;
|
|
268 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
269 }
|
12
|
270 UpdateCache();
|
|
271 UpdateListImage();
|
4
|
272 m_buttonUndo->Enable(true);
|
|
273 }
|
|
274 /* 選択したファイルを削除 */
|
|
275 void MyFrame::OnDelete(wxCommandEvent& WXUNUSED(event))
|
|
276 {
|
|
277 m_undo.Clear();
|
|
278 wxString workdir = m_dirPickerWork->GetPath();
|
|
279 wxString trash = wxGetCwd() + wxFILE_SEP_PATH + wxT("trash");
|
|
280 long item = -1;
|
|
281 for ( ;; ) {
|
|
282 item = m_listCtrlView->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
283 if ( item == -1 ) break;
|
|
284 wxString file = m_listCtrlView->GetItemText( item );
|
|
285 wxString from = workdir + wxFILE_SEP_PATH + file;
|
|
286 wxString to = trash + wxFILE_SEP_PATH + file;
|
|
287 wxRenameFile( from, to, true );
|
12
|
288
|
|
289 wxString movecmd = MOVECMD;
|
|
290 m_undo.Insert( movecmd + wxT(" ") + to + wxT(" ") + from, 0 );
|
4
|
291 }
|
12
|
292 UpdateCache();
|
|
293 UpdateListImage();
|
4
|
294 m_buttonUndo->Enable(true);
|
|
295 }
|
|
296 /* アンドゥ */
|
|
297 void MyFrame::OnUndo(wxCommandEvent& WXUNUSED(event))
|
|
298 {
|
|
299 for ( int i=0; i<m_undo.GetCount(); i++ ) {
|
|
300 wxExecute( m_undo[i] );
|
|
301 }
|
|
302 wxMessageBox(wxT("戻し完了."));
|
|
303 m_buttonUndo->Enable(false);
|
|
304 m_undo.Clear();
|
12
|
305 UpdateCache();
|
|
306 UpdateListImage();
|
4
|
307 }
|
0
|
308
|
|
309 /* 画像をリストコントロールに表示 */
|
12
|
310 void MyFrame::UpdateListImage()
|
0
|
311 {
|
11
|
312 // start-up iamge
|
4
|
313 wxString notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("notfound.png");
|
|
314 wxBitmap bmp = wxBitmap( notfound, wxBITMAP_TYPE_PNG );
|
|
315 m_bitmapName->SetBitmap( bmp );
|
|
316 notfound = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0000000000.png");
|
|
317 bmp.LoadFile( notfound, wxBITMAP_TYPE_PNG );
|
|
318 m_bitmapHhsno->SetBitmap( bmp );
|
0
|
319
|
12
|
320 // 本処理
|
0
|
321 m_listCtrlView->DeleteAllItems();
|
|
322 m_imageList->RemoveAll();
|
|
323 wxListItem item;
|
4
|
324 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 7, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
325 pd.SetSize( wxSize(320,140) );
|
0
|
326
|
12
|
327 wxArrayString keys;
|
|
328 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
329 keys.Add(it->first);
|
|
330 }
|
|
331 bool select = true;
|
|
332 keys.Sort();
|
|
333 for ( int i=0; i<keys.GetCount(); i++ ) {
|
|
334 CacheItem* ci = new CacheItem;
|
|
335 ci = CH[keys[i]];
|
|
336 m_listCtrlView->InsertItem( i, ci->filename );
|
|
337 m_listCtrlView->SetItem( i, 0, ci->filename, i );
|
|
338 m_imageList->Add( ci->thumbnail );
|
3
|
339
|
12
|
340 if ( i == 0 ) { // 1枚目はマークシートのはず
|
|
341 wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG );
|
4
|
342
|
|
343 wxImage name_image;
|
|
344 name_image = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
|
|
345 wxBitmap name_bmp = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) );
|
|
346 m_bitmapName->SetBitmap( name_bmp );
|
|
347
|
|
348 wxImage hhsno_image;
|
|
349 hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) );
|
|
350 wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) );
|
|
351 m_bitmapHhsno->SetBitmap( hhsno_bmp );
|
|
352
|
12
|
353 wxString hhsno = GuessHhs( ci->fullpath );
|
4
|
354 m_textCtrlGuess->SetValue( hhsno );
|
12
|
355 SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
|
|
356 m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
357 }
|
12
|
358 else { // 2枚目以降で初めてマークシートを認識したら,それ以降は選択しない
|
|
359 if ( ci->marksheet ) select = false;
|
|
360 if ( select ) m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
|
3
|
361 }
|
|
362
|
6
|
363 pd.Update( i+1, wxT("画像認識中") );
|
0
|
364 }
|
1
|
365
|
4
|
366 SetStatusText( wxEmptyString, 2 );
|
0
|
367 }
|
|
368
|
1
|
369 /* 画像を選択 */
|
3
|
370 void MyFrame::GetImageInfo(wxListEvent& event)
|
1
|
371 {
|
11
|
372 /*
|
3
|
373 SetStatusText( wxEmptyString, 2 );
|
2
|
374 int i = event.GetIndex();
|
|
375
|
3
|
376 wxString filename = event.GetText();
|
|
377 wxString workdir = m_dirPickerWork->GetPath();
|
|
378 wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
|
|
379 float b; long l;
|
|
380 wxString msg;
|
|
381 if ( IsMarksheet( imagefile, &b, &l ) ) {
|
4
|
382 msg = wxT("perhaps marksheet !");
|
2
|
383 }
|
3
|
384 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, b, l ), 2 );
|
11
|
385 */
|
2
|
386 }
|
|
387
|
|
388 /* 画像のスクリーン表示*/
|
|
389 void MyFrame::ViewLarge(wxListEvent& event)
|
|
390 {
|
|
391 int i = event.GetIndex();
|
|
392 wxListItem item;
|
|
393 item.SetId(i);
|
|
394
|
|
395 wxString filename = event.GetText();
|
|
396 wxString workdir = m_dirPickerWork->GetPath();
|
|
397 wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
|
|
398
|
|
399 wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
|
|
400 wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) );
|
|
401 wxSplashScreen* splash = new wxSplashScreen( bmp,
|
|
402 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
|
403 3000, NULL, -1, wxDefaultPosition, wxDefaultSize,
|
|
404 wxSIMPLE_BORDER|wxSTAY_ON_TOP );
|
|
405 wxYield();
|
1
|
406 }
|
|
407
|
|
408 /* パラメータダイアログ */
|
|
409 void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event))
|
|
410 {
|
5
|
411 ParamDialog* pd = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") );
|
|
412 if ( pd->ShowModal() == wxID_OK ) {
|
6
|
413 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax );
|
5
|
414 }
|
|
415 pd->Destroy();
|
1
|
416 }
|
|
417
|
11
|
418 /* キャッシュ作成&更新 */
|
|
419 void MyFrame::UpdateCache()
|
|
420 {
|
12
|
421 m_buttonDetect->Enable(false);
|
11
|
422 wxGetApp().WriteLog( wxT("start updating cache") );
|
|
423 SetStatusText( wxT("rebuiling cache..."), 0 );
|
|
424
|
12
|
425 /* キャッシュ存在フラグOFF */
|
|
426 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
11
|
427 CacheItem* ci = new CacheItem;
|
12
|
428 ci = it->second;
|
11
|
429 ci->exists = false;
|
|
430 }
|
12
|
431
|
|
432 wxString workdir = m_dirPickerWork->GetPath();
|
|
433 wxDir dir( workdir );
|
|
434 if ( !dir.IsOpened() ) return;
|
|
435
|
|
436 wxArrayString filenames;
|
|
437 wxListItem item;
|
|
438
|
|
439 /* キャッシュ作成 */
|
11
|
440 unsigned int n = dir.GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
|
441 for ( int i=0; i<n; i++ ) {
|
12
|
442 wxString fullpath = filenames[i];
|
|
443 wxFileName f( fullpath );
|
|
444 wxString file = f.GetFullName();
|
|
445
|
11
|
446 CacheItem* ci = new CacheItem;
|
12
|
447 /* キャッシュ済みのものはスキップ */
|
|
448 if ( CH.count(file) ) {
|
|
449 ci = CH[file];
|
11
|
450 ci->exists = true;
|
|
451 continue;
|
|
452 }
|
12
|
453 /* 新しいファイルはキャッシュ */
|
|
454 float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
|
|
455 wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
|
11
|
456 wxBitmap bmp( image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH ) );
|
12
|
457
|
|
458 ci->filename = file;
|
|
459 ci->fullpath = fullpath;
|
11
|
460 ci->marksheet = m;
|
|
461 ci->z = z;
|
|
462 ci->l = l;
|
|
463 ci->exists = true;
|
|
464 ci->thumbnail = bmp;
|
|
465 ci->modtime = wxEmptyString; // TODO.
|
12
|
466
|
11
|
467 CH[ci->filename] = ci; // add hash
|
12
|
468 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
|
11
|
469 }
|
|
470
|
12
|
471 /* 存在しないファイルはキャッシュから削除 */
|
|
472 wxArrayString removelist;
|
|
473 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
474 CacheItem* ci = new CacheItem;
|
|
475 ci = it->second;
|
|
476 if ( !ci->exists ) removelist.Add( ci->filename );
|
|
477 }
|
|
478 for ( int i=0; i<removelist.GetCount(); i++ ) {
|
|
479 CH.erase(removelist[i]);
|
|
480 wxGetApp().WriteLog( removelist[i] + wxT(" removed.") );
|
|
481 }
|
|
482
|
|
483 m_buttonDetect->Enable(true);
|
11
|
484 SetStatusText( wxEmptyString, 0 );
|
|
485 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
|
|
486 }
|
|
487
|
0
|
488 // 以下,定型もの
|
11
|
489 void MyFrame::OnTimer(wxTimerEvent& event)
|
|
490 {
|
|
491 UpdateCache();
|
|
492 }
|
|
493 /* アイドリング */
|
|
494 void MyFrame::OnIdle(wxIdleEvent& event)
|
|
495 {
|
|
496 if ( !m_timer.IsRunning() ) {
|
|
497 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT );
|
|
498 }
|
|
499 event.RequestMore();
|
|
500 event.Skip();
|
|
501 }
|
|
502
|
0
|
503 /* アプリフォルダを開く */
|
|
504 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
505 {
|
5
|
506 wxString appdir = wxGetCwd();
|
0
|
507 wxString execmd = wxT("explorer ") + appdir;
|
|
508 wxExecute( execmd );
|
|
509 }
|
|
510
|
|
511 /* サイズ変更 */
|
1
|
512 void MyFrame::OnWinSize(wxSizeEvent& event)
|
0
|
513 {
|
|
514 this->Refresh( true, NULL );
|
|
515 TellLocation();
|
|
516 event.Skip();
|
|
517 }
|
|
518 /* ウィンドウ移動 */
|
1
|
519 void MyFrame::OnWinMove(wxMoveEvent& WXUNUSED(event))
|
0
|
520 {
|
|
521 TellLocation();
|
|
522 return;
|
|
523 }
|
|
524 /* ウィンドウ位置とサイズを表示 */
|
|
525 void MyFrame::TellLocation( void )
|
|
526 {
|
|
527 wxRect r = this->GetRect();
|
|
528 int x = r.GetX();
|
|
529 int y = r.GetY();
|
|
530 int w = r.GetWidth();
|
|
531 int h = r.GetHeight();
|
1
|
532 SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
|
0
|
533 }
|
|
534 /* 終了 */
|
|
535 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
536 {
|
|
537 Close(true);
|
|
538 }
|
|
539 /* 設定を保存 */
|
|
540 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
541 {
|
|
542 if ( !IsIconized() && !IsMaximized() ) {
|
|
543 wxGetApp().rect = this->GetRect();
|
|
544 }
|
|
545 wxGetApp().workdir = m_dirPickerWork->GetPath();
|
|
546
|
|
547 Destroy();
|
|
548 }
|
|
549
|