view src/myframe.cpp @ 2:e4ba3cc9b4b1

large view ok.
author pyon@macmini
date Sat, 15 Oct 2011 22:03:00 +0900
parents b47bd4618c16
children 870860d435a1
line wrap: on
line source

// Filename   : myframe.cpp
// Last Change: 15-Oct-2011.
//

#include "main.h"
#include "myframe.h"
#include "marksheet.h"

//////////////////////////////////////////////////////////////////////////
// frame constructor
MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
    this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
    // set the frame icon
    //SetIcon(wxICON(sample));
	
    // メニューバー
	m_menubarFile = new wxMenuBar();
	m_menuFile = new wxMenu();
	wxMenuItem* m_menuItemParam;
	m_menuItemParam = new wxMenuItem( m_menuFile, ID_MENUITEMPARAM, wxString( wxT("パラメータ(&P)") ) , wxEmptyString, wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemParam );
	
	wxMenuItem* m_menuItemAppDIr;
	m_menuItemAppDIr = new wxMenuItem( m_menuFile, ID_MENUITEMAPPDIR, wxString( wxT("アプリフォルダを開く(&O)") ) , wxEmptyString, wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemAppDIr );
	
	wxMenuItem* m_separator;
	m_separator = m_menuFile->AppendSeparator();    // ----
	
	wxMenuItem* m_menuItemQuit;
	m_menuItemQuit = new wxMenuItem( m_menuFile, ID_MENUITEMQUIT, wxString( wxT("終了(&X)") ) , wxEmptyString, wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemQuit );
	
	m_menubarFile->Append( m_menuFile, wxT("ファイル(&F)") ); 
	
	this->SetMenuBar( m_menubarFile );
	
    // コントロール	
	wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
	
	wxBoxSizer* bSizerFrom = new wxBoxSizer( wxHORIZONTAL );
	
	m_staticTextWork = new wxStaticText( this, wxID_ANY, wxT("作業フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerFrom->Add( m_staticTextWork, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_dirPickerWork = new wxDirPickerCtrl( this, wxID_ANY, wxGetApp().workdir, wxT("Select a folder"), wxDefaultPosition, wxDefaultSize, wxDIRP_DEFAULT_STYLE );
	bSizerFrom->Add( m_dirPickerWork, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	bSizerTop->Add( bSizerFrom, 0, wxEXPAND, 5 );
	
	wxBoxSizer* bSizerDist = new wxBoxSizer( wxHORIZONTAL );
	
	m_staticTextDist = new wxStaticText( this, wxID_ANY, wxT("保存フォルダ"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerDist->Add( m_staticTextDist, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_textCtrlDist = new wxTextCtrl( this, ID_TEXTCTRLDIST, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_textCtrlDist->SetMaxLength( 15 ); 
	bSizerDist->Add( m_textCtrlDist, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	bSizerDist->Add( 0, 0, 1, wxEXPAND, 5 );
	
	m_staticTextDrive = new wxStaticText( this, wxID_ANY, wxT("ドライブ"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerDist->Add( m_staticTextDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
    wxArrayString drives;
    drives.Add(wxT("C:"));
    drives.Add(wxT("Y:"));
    drives.Add(wxT("Z:"));
	m_comboBoxDrive = new wxComboBox( this, wxID_ANY, wxT("C:"), wxDefaultPosition, wxSize(50,-1), drives, 0 ); 
	bSizerDist->Add( m_comboBoxDrive, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT("開催日"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerDist->Add( m_staticTextDate, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN );
	bSizerDist->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT("合議体"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerDist->Add( m_staticTextCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
    wxArrayString ccns;
	ccns.Add(wxT("角館1")); ccns.Add(wxT("角館2")); ccns.Add(wxT("角館3")); ccns.Add(wxT("角館4"));
	ccns.Add(wxT("西仙1")); ccns.Add(wxT("西仙2")); ccns.Add(wxT("西仙3"));
	ccns.Add(wxT("千畑1")); ccns.Add(wxT("千畑2")); ccns.Add(wxT("千畑3"));
	ccns.Add(wxT("大曲1")); ccns.Add(wxT("大曲2")); ccns.Add(wxT("大曲3")); ccns.Add(wxT("大曲4")); ccns.Add(wxT("大曲5")); ccns.Add(wxT("大曲6"));
	ccns.Add(wxT("六郷1")); ccns.Add(wxT("六郷2")); ccns.Add(wxT("六郷3"));
	m_comboBoxCcn = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(100,-1), ccns, 0 ); 
	bSizerDist->Add( m_comboBoxCcn, 0, wxALL, 5 );
	
	m_buttonMkDir = new wxButton( this, ID_BUTTONMKDIR, wxT("適用"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerDist->Add( m_buttonMkDir, 0, wxALL, 5 );
	
	
	bSizerTop->Add( bSizerDist, 0, wxEXPAND, 5 );
	
	wxBoxSizer* bSizerManip = new wxBoxSizer( wxHORIZONTAL );
	
	wxBoxSizer* bSizerGuess = new wxBoxSizer( wxVERTICAL );
	
	m_staticTextName = new wxStaticText( this, wxID_ANY, wxT("氏名"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerGuess->Add( m_staticTextName, 0, wxTOP|wxLEFT, 5 );
	m_bitmapName = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(320,95), 0 );
	bSizerGuess->Add( m_bitmapName, 0, wxALL, 5 );
	
	m_staticTextHhsno = new wxStaticText( this, wxID_ANY, wxT("被保険者番号"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerGuess->Add( m_staticTextHhsno, 0, wxTOP|wxLEFT, 5 );
	m_bitmapHHsno = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(320,54), 0 );
	bSizerGuess->Add( m_bitmapHHsno, 0, wxALL, 5 );
	
	m_staticTextGuess = new wxStaticText( this, wxID_ANY, wxT("推定値"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerGuess->Add( m_staticTextGuess, 0, wxTOP|wxLEFT, 5 );
	m_textCtrlGuess = new wxTextCtrl( this, ID_TEXTCTRLGUESS, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
	m_textCtrlGuess->SetMaxLength( 10 ); 
	bSizerGuess->Add( m_textCtrlGuess, 0, wxALL, 5 );
	
	bSizerManip->Add( bSizerGuess, 0, wxEXPAND, 5 );
	
	m_listCtrlView = new wxListCtrl( this, ID_LISTCTRLVIEW, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
    m_listCtrlView->SetBackgroundColour(wxT("LIGHT GREY"));
	bSizerManip->Add( m_listCtrlView, 1, wxALL|wxEXPAND, 5 );
    m_imageList = new wxImageList( 189, 267 );
    m_listCtrlView->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL );
	
	wxBoxSizer* bSizerButton = new wxBoxSizer( wxVERTICAL );
	
	m_buttonDetect = new wxButton( this, ID_BUTTONDETECT, wxT("検知"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerButton->Add( m_buttonDetect, 0, wxALL, 5 );
	m_buttonMove = new wxButton( this, ID_BUTTONMOVE, wxT("移動"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerButton->Add( m_buttonMove, 0, wxALL, 5 );
	m_buttonMD = new wxButton( this, ID_BUTTONMD, wxT("移動&検知"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerButton->Add( m_buttonMD, 0, wxALL, 5 );
	m_buttonDel = new wxButton( this, ID_BUTTONDEL, wxT("削除"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerButton->Add( m_buttonDel, 0, wxALL, 5 );
	m_buttonUndo = new wxButton( this, ID_BUTTONUNDO, wxT("戻す"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerButton->Add( m_buttonUndo, 0, wxALL, 5 );
	
	bSizerManip->Add( bSizerButton, 0, wxALIGN_CENTER_VERTICAL, 5 );
	
	bSizerTop->Add( bSizerManip, 1, wxEXPAND, 5 );
	
	this->SetSizer( bSizerTop );
	this->Layout();

    // ステータスバー
    int widths[] = { -1, 150, 200, 120 };
    m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
    m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
    m_statusBar->SetStatusText( wxEmptyString, 0 );
	
	this->Centre( wxBOTH );
}

// destructor
MyFrame::~MyFrame()
{
}

// Event Table
BEGIN_EVENT_TABLE( MyFrame, wxFrame )
    EVT_SIZE( MyFrame::OnWinSize )
    EVT_MOVE( MyFrame::OnWinMove )
    EVT_MENU( ID_MENUITEMPARAM,  MyFrame::OnParam )
    EVT_MENU( ID_MENUITEMAPPDIR, MyFrame::OnOpenAppDir )
    EVT_MENU( wxID_EXIT,         MyFrame::OnQuit )
    EVT_BUTTON( ID_BUTTONDETECT, MyFrame::OnDetect )
    EVT_BUTTON( ID_BUTTONMOVE,   MyFrame::OnMove )
    EVT_BUTTON( ID_BUTTONMD,     MyFrame::OnMoveAndDetect )
    //EVT_BUTTON( ID_BUTTONDEL,  MyFrame::Delete )
    //EVT_BUTTON( ID_BUTTONUNDO, MyFrame::Undo )
    //EVT_LIST_ITEM_MIDDLE_CLICK( ID_LISTCTRLVIEW, MyFrame::ToggleSelect )
    EVT_LIST_ITEM_RIGHT_CLICK( ID_LISTCTRLVIEW, MyFrame::ToggleSelect )
    EVT_LIST_ITEM_ACTIVATED(   ID_LISTCTRLVIEW, MyFrame::ViewLarge )
    EVT_CLOSE( MyFrame::SaveConfig )
END_EVENT_TABLE()

// Event Handlers
/* 移動先フォルダ作成 */
void MyFrame::MakeDir(wxCommandEvent& WXUNUSED(event))
{
    wxString to;
    to.Append( m_comboBoxDrive->GetValue() );
    to.Append( wxFILE_SEP_PATH );
    wxDateTime dt = m_datePicker->GetValue();
    to.Append( dt.Format(wxT("%Y%m%d")) );
    to.Append( wxFILE_SEP_PATH );
    to.Append( m_comboBoxCcn->GetValue() );
    m_textCtrlDist->SetValue( to );

    wxString ccn = m_comboBoxCcn->GetValue();
    if ( to.Len() < 15 || ccn.IsEmpty() ) {
        wxMessageBox(wxT("フォルダを指定してください."));
        return;
    }

    wxStringTokenizer tkz( to, wxFILE_SEP_PATH );
    wxString d;
    while ( tkz.HasMoreTokens() ) {
        d.Append( tkz.GetNextToken() );
        d.Append( wxFILE_SEP_PATH );
        if ( !wxDirExists( d ) ) wxMkdir( d );
    }

    wxMessageBox(wxT("移動先フォルダ準備完了"));
    wxString cmd = wxT("explorer ") + to;
    wxExecute( cmd );
}

/* 移動 */
void MyFrame::OnMove(wxCommandEvent& WXUNUSED(event))
{
    MoveImage();
}
/* 検知 */
void MyFrame::OnDetect(wxCommandEvent& WXUNUSED(event))
{
    ReadyImage();
}
/* 移動し検知 */
void MyFrame::OnMoveAndDetect(wxCommandEvent& WXUNUSED(event))
{
    MoveImage();
    ReadyImage();
}

/* 画像をリストコントロールに表示 */
void MyFrame::ReadyImage()
{
    wxString workdir = m_dirPickerWork->GetPath();
    wxDir dir( workdir );
    if ( !dir.IsOpened() ) return;

    wxString filename;
    bool cout = dir.GetFirst( &filename, wxT("*.jpg"), wxDIR_FILES );

    int i = 0;
    m_listCtrlView->DeleteAllItems();
    m_imageList->RemoveAll();
    wxListItem item;
    wxString first;
    float b; long l;
    while ( cout ) {
        if ( i > 7 ) break;

        wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
        if ( i == 0 ) {
            IsMarksheet( imagefile, &b, &l );
            first = imagefile;
            SetStatusText( wxString::Format(wxT("z = %f, l = %d"),b,l), 2 );
        }
        if ( i > 1 && IsMarksheet( imagefile, &b, &l ) ) cout = false;

        item.SetId(i);
        item.SetMask(wxLIST_MASK_STATE|wxLIST_MASK_TEXT|wxLIST_MASK_IMAGE);
        item.SetStateMask(wxLIST_STATE_SELECTED);
        item.SetState(wxLIST_STATE_SELECTED);
        item.SetImage(i);
        item.SetText(filename);
        m_listCtrlView->InsertItem( item );
        m_listCtrlView->SetItem( item );

        wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
        wxBitmap bmp( image.Scale( 189, 267, wxIMAGE_QUALITY_HIGH ) );
        m_imageList->Add( bmp );
        // write log
        i++;
        cout = dir.GetNext( &filename );
    }

    wxImage marksheet( first, wxBITMAP_TYPE_JPEG );
    wxImage name_image;
    name_image  = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
    wxBitmap name_bmp  = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) );
    m_bitmapName->SetBitmap( name_bmp );

    wxImage hhsno_image;
    hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) );
    wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) );
    m_bitmapHHsno->SetBitmap( hhsno_bmp );

    wxString hhsno = GuessHhs( first );
    m_textCtrlGuess->SetValue( hhsno );
}

/* 画像移動 */
void MyFrame::MoveImage()
{
    wxString distdir = m_textCtrlDist->GetValue();
    wxString ccn = m_comboBoxCcn->GetValue();
    if ( distdir.IsEmpty() || ccn.IsEmpty() ) {
        wxMessageBox(wxT("フォルダを指定してください."));
        return;
    }

    distdir.Append( wxFILE_SEP_PATH );
    if ( !wxDirExists( distdir ) ) {
        wxMessageBox(wxT("フォルダが存在しません."));
        return;
    }

    /*
    wxString to = distdir + wxFILE_SEP_PATH + hhs + wxFILE_SEP_PATH + filename;
    wxRenameFile( from, to, false );
    */
}

/* 画像を選択 */
void MyFrame::ToggleSelect(wxListEvent& event)
{
    SetStatusText( wxEmptyString, 1 );
    int i = event.GetIndex();
    wxListItem item;
    item.SetId(i);

    //item.SetMask(wxLIST_MASK_STATE);
    if ( item.GetState() & wxLIST_STATE_SELECTED ) {
        wxMessageBox(wxT("a"));
        item.SetState(~wxLIST_STATE_SELECTED);
    }
    else {
        item.SetStateMask(wxLIST_STATE_SELECTED);
        wxString filename = event.GetText();
        wxString workdir = m_dirPickerWork->GetPath();
        wxString imagefile = workdir + wxFILE_SEP_PATH + filename;
        float b; long l;
        if ( IsMarksheet( imagefile, &b, &l ) ) {
            SetStatusText( wxString::Format(wxT("z = %f, l = %d"),b,l), 1 );
        }
    }
    m_listCtrlView->SetItem( item );
}

/* 画像のスクリーン表示*/
void MyFrame::ViewLarge(wxListEvent& event)
{
    int i = event.GetIndex();
    wxListItem item;
    item.SetId(i);

    wxString filename = event.GetText();
    wxString workdir = m_dirPickerWork->GetPath();
    wxString imagefile = workdir + wxFILE_SEP_PATH + filename;

    wxImage image( imagefile, wxBITMAP_TYPE_JPEG );
    wxBitmap bmp( image.Scale( 707, 1000, wxIMAGE_QUALITY_HIGH ) );
    wxSplashScreen* splash = new wxSplashScreen( bmp,
            wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
            3000, NULL, -1, wxDefaultPosition, wxDefaultSize,
            wxSIMPLE_BORDER|wxSTAY_ON_TOP );
    wxYield();
}

/* パラメータダイアログ */
void MyFrame::OnParam(wxCommandEvent& WXUNUSED(event))
{
}

// 以下,定型もの
/* アプリフォルダを開く */
void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
{
    wxString appdir = m_dirPickerWork->GetPath();
    wxString execmd = wxT("explorer ") + appdir;
    wxExecute( execmd );
}

/* サイズ変更 */
void MyFrame::OnWinSize(wxSizeEvent& event)
{
    this->Refresh( true, NULL );
    TellLocation();
    event.Skip();
}
/* ウィンドウ移動 */
void MyFrame::OnWinMove(wxMoveEvent& WXUNUSED(event))
{
    TellLocation();
    return;
}
/* ウィンドウ位置とサイズを表示 */
void MyFrame::TellLocation( void ) 
{
    wxRect r = this->GetRect();
    int x = r.GetX();
    int y = r.GetY();
    int w = r.GetWidth();
    int h = r.GetHeight();
    SetStatusText( wxString::Format(wxT("(%d,%d) %dx%d"),x,y,w,h), 3 );
}
/* 終了 */
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(true);
}
/* 設定を保存 */
void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
{
    if ( !IsIconized() && !IsMaximized() ) {
        wxGetApp().rect = this->GetRect();
    }
    wxGetApp().workdir = m_dirPickerWork->GetPath();

    Destroy();
}