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