0
|
1 // Filename : myframe.cpp
|
34
|
2 // Last Change: 12-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
|
33
|
60 m_menubarFile->Append( m_menuFile, wxT("ファイル") );
|
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 );
|
33
|
127 m_bitmapName = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(LOGO_W,LOGO_H), 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 );
|
33
|
134 m_bitmapHhsno = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(HHSN_W,HHSN_H), 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"));
|
33
|
156 bSizerManip->Add( m_listCtrlView, 1, wxALL|wxEXPAND, 5 );
|
27
|
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 );
|
34
|
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 }
|
34
|
482 // 画像ファイル数が多ければ,おそらく申請書
|
|
483 if ( keys.GetCount() > 32 ) {
|
|
484 int n = m_comboBoxCcn->GetCurrentSelection();
|
|
485 wxString ccndir, dummy; wxArrayString array;
|
|
486 GetCCnArrayInfo( array, n, dummy, ccndir );
|
|
487 m_textCtrlGuess->SetValue( ccndir );
|
|
488 }
|
1
|
489
|
23
|
490 // 選択したものは青い画像を使う
|
|
491 long i = -1;
|
|
492 for ( ;; ) {
|
|
493 i = m_listCtrlView->GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
|
494 if ( i == -1 ) break;
|
|
495 m_listCtrlView->SetItemImage( i, i+m_listCtrlView->GetItemCount() );
|
|
496 }
|
|
497
|
4
|
498 SetStatusText( wxEmptyString, 2 );
|
0
|
499 }
|
|
500
|
23
|
501 /* 画像を選択したとき画像の情報をステータスバーに表示 */
|
|
502 void MyFrame::OnItemSelected(wxListEvent& event)
|
1
|
503 {
|
23
|
504 int i = event.GetIndex();
|
34
|
505 int m = m_listCtrlView->GetSelectedItemCount();
|
|
506 m_listCtrlView->SetItemImage( i, i+m ); // 青い画像
|
23
|
507
|
34
|
508 if ( m != 1 ) {
|
|
509 SetStatusText( wxString::Format(wxT("%d files selected."),m), 2 );
|
|
510 return;
|
|
511 }
|
2
|
512
|
3
|
513 wxString filename = event.GetText();
|
13
|
514 CacheItem* ci = new CacheItem;
|
|
515 ci = CH[filename];
|
3
|
516 wxString msg;
|
13
|
517 if ( ci->marksheet ) msg = wxT("perhaps marksheet !");
|
|
518 SetStatusText( wxString::Format(wxT("selected image : z = %f, l = %d ...")+msg, ci->z, ci->l ), 2 );
|
2
|
519 }
|
23
|
520 void MyFrame::OnItemDeselected(wxListEvent& event)
|
|
521 {
|
|
522 int i = event.GetIndex();
|
|
523 m_listCtrlView->SetItemImage( i, i );
|
34
|
524 SetStatusText( wxString::Format(wxT("%d files selected."),m_listCtrlView->GetSelectedItemCount()), 2 );
|
23
|
525 }
|
2
|
526
|
|
527 /* 画像のスクリーン表示*/
|
|
528 void MyFrame::ViewLarge(wxListEvent& event)
|
|
529 {
|
|
530 int i = event.GetIndex();
|
|
531 wxListItem item;
|
|
532 item.SetId(i);
|
|
533
|
|
534 wxString filename = event.GetText();
|
|
535 wxString workdir = m_dirPickerWork->GetPath();
|
|
536 wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
|
|
537
|
|
538 wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
|
|
539 wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) );
|
|
540 wxSplashScreen* splash = new wxSplashScreen( bmp,
|
|
541 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
|
|
542 3000, NULL, -1, wxDefaultPosition, wxDefaultSize,
|
|
543 wxSIMPLE_BORDER|wxSTAY_ON_TOP );
|
|
544 wxYield();
|
1
|
545 }
|
|
546
|
|
547 /* パラメータダイアログ */
|
|
548 void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event))
|
|
549 {
|
5
|
550 ParamDialog* pd = new ParamDialog( NULL, wxID_ANY, wxT("Setting Parameters") );
|
|
551 if ( pd->ShowModal() == wxID_OK ) {
|
6
|
552 pd->NewParam( wxGetApp().lmin, wxGetApp().lmax, wxGetApp().zmin, wxGetApp().zmax );
|
5
|
553 }
|
|
554 pd->Destroy();
|
1
|
555 }
|
|
556
|
11
|
557 /* キャッシュ作成&更新 */
|
|
558 void MyFrame::UpdateCache()
|
|
559 {
|
24
|
560 double zmin, zmax; long lmin, lmax;
|
|
561 wxGetApp().zmin.ToDouble( &zmin );
|
|
562 wxGetApp().zmax.ToDouble( &zmax );
|
|
563 wxGetApp().lmin.ToLong( &lmin );
|
|
564 wxGetApp().lmax.ToLong( &lmax );
|
|
565
|
12
|
566 m_buttonDetect->Enable(false);
|
11
|
567 wxGetApp().WriteLog( wxT("start updating cache") );
|
24
|
568 wxStopWatch sw;
|
|
569 sw.Start(0);
|
11
|
570
|
12
|
571 /* キャッシュ存在フラグOFF */
|
|
572 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
11
|
573 CacheItem* ci = new CacheItem;
|
12
|
574 ci = it->second;
|
11
|
575 ci->exists = false;
|
|
576 }
|
12
|
577
|
|
578 wxString workdir = m_dirPickerWork->GetPath();
|
|
579 wxArrayString filenames;
|
|
580 wxListItem item;
|
|
581
|
|
582 /* キャッシュ作成 */
|
26
|
583 unsigned int n = wxDir::GetAllFiles( workdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
11
|
584 for ( int i=0; i<n; i++ ) {
|
12
|
585 wxString fullpath = filenames[i];
|
|
586 wxFileName f( fullpath );
|
|
587 wxString file = f.GetFullName();
|
|
588
|
11
|
589 CacheItem* ci = new CacheItem;
|
12
|
590 /* キャッシュ済みのものはスキップ */
|
|
591 if ( CH.count(file) ) {
|
|
592 ci = CH[file];
|
11
|
593 ci->exists = true;
|
|
594 continue;
|
|
595 }
|
12
|
596 /* 新しいファイルはキャッシュ */
|
24
|
597 //float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
|
|
598 float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax );
|
12
|
599 wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
|
27
|
600 wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH );
|
23
|
601 wxBitmap bmp( thumbnail );
|
|
602 unsigned char *data = thumbnail.GetData();
|
27
|
603 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
|
604 wxBitmap bmp_mask( thumbnail );
|
12
|
605
|
23
|
606 ci->filename = file;
|
|
607 ci->fullpath = fullpath;
|
|
608 ci->marksheet = m;
|
|
609 ci->z = z;
|
|
610 ci->l = l;
|
|
611 ci->exists = true;
|
|
612 ci->thumbnail = bmp;
|
|
613 ci->selthumbnail = bmp_mask;
|
|
614 ci->modtime = wxEmptyString; // TODO.
|
12
|
615
|
11
|
616 CH[ci->filename] = ci; // add hash
|
26
|
617 SetStatusText( wxString::Format( wxT("rebuiling cache...( %d/%d :%.1fsec passed )"), i+1, n, (float)sw.Time()/1000 ), 0 );
|
12
|
618 wxGetApp().WriteLog( file + wxT(" appended.") + wxString::Format(wxT(" ( m=%d z=%f l=%d )"), m ? 1 : 0, z, l ) );
|
11
|
619 }
|
|
620
|
12
|
621 /* 存在しないファイルはキャッシュから削除 */
|
|
622 wxArrayString removelist;
|
|
623 for ( CacheHash::iterator it=CH.begin(); it != CH.end(); ++it ) {
|
|
624 CacheItem* ci = new CacheItem;
|
|
625 ci = it->second;
|
|
626 if ( !ci->exists ) removelist.Add( ci->filename );
|
|
627 }
|
|
628 for ( int i=0; i<removelist.GetCount(); i++ ) {
|
|
629 CH.erase(removelist[i]);
|
|
630 wxGetApp().WriteLog( removelist[i] + wxT(" removed.") );
|
|
631 }
|
|
632
|
|
633 m_buttonDetect->Enable(true);
|
11
|
634 SetStatusText( wxEmptyString, 0 );
|
|
635 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT ); // restart
|
|
636 }
|
|
637
|
26
|
638 /* 被保険者フォルダを列挙 */
|
|
639 void MyFrame::ListHhsDir()
|
|
640 {
|
|
641 wxString distdir = m_textCtrlDist->GetValue();
|
|
642 wxString hhsdir;
|
|
643 wxString buf;
|
|
644
|
|
645 m_listCtrlHhsDir->DeleteAllItems();
|
|
646 for ( int i=0; i<m_hhsList.GetCount(); i++ ) {
|
|
647 hhsdir = distdir + wxFILE_SEP_PATH + m_hhsList[i];
|
|
648 wxArrayString filenames;
|
34
|
649 unsigned int n = 0;
|
|
650 if ( wxDirExists( hhsdir ) ) n = wxDir::GetAllFiles( hhsdir, &filenames, wxT("*.jpg"), wxDIR_FILES );
|
26
|
651
|
|
652 m_listCtrlHhsDir->InsertItem( i, -1 );
|
|
653 buf.Printf(wxT("%d"),i+1);
|
|
654 m_listCtrlHhsDir->SetItem( i, 0, buf, -1 );
|
|
655 m_listCtrlHhsDir->SetItem( i, 1, m_hhsList[i], -1 );
|
|
656 buf.Printf(wxT("%d"),n);
|
|
657 m_listCtrlHhsDir->SetItem( i, 2, buf, -1 );
|
34
|
658 m_listCtrlHhsDir->SetItem( i, 3, GetHhsName( m_hhsList[i]), -1 );
|
26
|
659 if ( i % 2 ) m_listCtrlHhsDir->SetItemBackgroundColour( i, wxColour(wxT("WHEAT")) );
|
|
660 }
|
|
661 }
|
|
662
|
|
663 /* 被保険者フォルダを開く */
|
21
|
664 void MyFrame::OnOpenHhsDir(wxListEvent& event)
|
|
665 {
|
26
|
666 wxString hhsdir;
|
|
667 hhsdir.Append( m_textCtrlDist->GetValue() );
|
21
|
668 hhsdir.Append( wxFILE_SEP_PATH );
|
|
669
|
27
|
670 int i = event.GetIndex();
|
|
671 wxListItem item;
|
|
672 item.SetId(i);
|
|
673
|
21
|
674 item.SetColumn(1);
|
|
675 item.SetMask(wxLIST_MASK_TEXT);
|
26
|
676 m_listCtrlHhsDir->GetItem( item );
|
21
|
677 hhsdir.Append( item.GetText() );
|
|
678 wxString execmd = wxT("explorer ") + hhsdir;
|
|
679 wxExecute( execmd );
|
|
680 }
|
|
681
|
32
|
682 /* 以下,定型もの ***********************************************/
|
11
|
683 void MyFrame::OnTimer(wxTimerEvent& event)
|
|
684 {
|
|
685 UpdateCache();
|
|
686 }
|
26
|
687
|
11
|
688 /* アイドリング */
|
|
689 void MyFrame::OnIdle(wxIdleEvent& event)
|
|
690 {
|
|
691 if ( !m_timer.IsRunning() ) {
|
|
692 m_timer.Start( 20*1000, wxTIMER_ONE_SHOT );
|
|
693 }
|
|
694 event.RequestMore();
|
|
695 event.Skip();
|
|
696 }
|
|
697
|
0
|
698 /* アプリフォルダを開く */
|
|
699 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
700 {
|
5
|
701 wxString appdir = wxGetCwd();
|
0
|
702 wxString execmd = wxT("explorer ") + appdir;
|
|
703 wxExecute( execmd );
|
|
704 }
|
|
705
|
|
706 /* サイズ変更 */
|
1
|
707 void MyFrame::OnWinSize(wxSizeEvent& event)
|
0
|
708 {
|
|
709 this->Refresh( true, NULL );
|
|
710 TellLocation();
|
|
711 event.Skip();
|
|
712 }
|
|
713 /* ウィンドウ移動 */
|
1
|
714 void MyFrame::OnWinMove(wxMoveEvent& WXUNUSED(event))
|
0
|
715 {
|
|
716 TellLocation();
|
|
717 return;
|
|
718 }
|
|
719 /* ウィンドウ位置とサイズを表示 */
|
|
720 void MyFrame::TellLocation( void )
|
|
721 {
|
|
722 wxRect r = this->GetRect();
|
|
723 int x = r.GetX();
|
|
724 int y = r.GetY();
|
|
725 int w = r.GetWidth();
|
|
726 int h = r.GetHeight();
|
1
|
727 SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
|
0
|
728 }
|
|
729 /* 終了 */
|
|
730 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
731 {
|
|
732 Close(true);
|
|
733 }
|
|
734 /* 設定を保存 */
|
|
735 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
736 {
|
|
737 if ( !IsIconized() && !IsMaximized() ) {
|
|
738 wxGetApp().rect = this->GetRect();
|
|
739 }
|
|
740 wxGetApp().workdir = m_dirPickerWork->GetPath();
|
|
741
|
|
742 Destroy();
|
|
743 }
|
|
744
|