Newer
Older
TIAS_Imager2 / TIAS_Imager2 / TIAS_Imager2View.cpp

// TIAS_Imager2View.cpp : CTIAS_Imager2View クラスの実装
//

#include "stdafx.h"
// SHARED_HANDLERS は、プレビュー、サムネイル、および検索フィルター ハンドラーを実装している ATL プロジェクトで定義でき、
// そのプロジェクトとのドキュメント コードの共有を可能にします。
#ifndef SHARED_HANDLERS
#include "TIAS_Imager2.h"
#endif

#include "TIAS_Imager2Doc.h"
#include "TIAS_Imager2View.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CTIAS_Imager2View

IMPLEMENT_DYNCREATE(CTIAS_Imager2View, CFormView)

BEGIN_MESSAGE_MAP(CTIAS_Imager2View, CFormView)
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BTN_ONESHOT, &CTIAS_Imager2View::OnBnClickedBtnOneshot)
	ON_BN_CLICKED(IDC_BTN_LONGSHOT, &CTIAS_Imager2View::OnBnClickedBtnLongshot)
	ON_BN_CLICKED(IDC_BTN_SHORTSHOT, &CTIAS_Imager2View::OnBnClickedBtnShortshot)
	ON_BN_CLICKED(IDC_BTN_CALIB, &CTIAS_Imager2View::OnBnClickedBtnCalib)
	ON_BN_CLICKED(IDC_BTN_SHOKEN, &CTIAS_Imager2View::OnBnClickedBtnShoken)
	ON_BN_CLICKED(IDC_BTN_ABORT, &CTIAS_Imager2View::OnBnClickedBtnAbort)
END_MESSAGE_MAP()

// CTIAS_Imager2View コンストラクション
CTIAS_Imager2View::CTIAS_Imager2View()
	: CFormView(CTIAS_Imager2View::IDD)
	, m_xvEdtID(_T(""))
	, m_xvGender(0)
{
	// ビットマップ情報の生成
	ZeroMemory(&m_Bih, sizeof(BITMAPINFOHEADER));
	m_Bih.biSize		= sizeof(BITMAPINFOHEADER);
	m_Bih.biWidth		= 640;
	m_Bih.biHeight		= 512; // 負の値を指定すると上下反転
	m_Bih.biBitCount	= 24;
	m_Bih.biPlanes		= 1;
	m_Bih.biCompression	= BI_RGB;
}

// CTIAS_Imager2View デストラクション
CTIAS_Imager2View::~CTIAS_Imager2View()
{
	m_FontBtn.DeleteObject();
}

// DDX
void CTIAS_Imager2View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDT_ID, m_xvEdtID);
	DDX_Radio(pDX, IDC_RAD_GENDERM, m_xvGender);
}

// ウインドウ生成前の設定
BOOL CTIAS_Imager2View::PreCreateWindow(CREATESTRUCT& cs)
{
	return CFormView::PreCreateWindow(cs);
}

// ウインドウ初期化
void CTIAS_Imager2View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit(FALSE);

	// コントロール初期化
	m_FontBtn.CreatePointFont(140, _T("MS ゴシック"));
	GetDlgItem(IDC_BTN_ONESHOT)->SetFont(&m_FontBtn);
	CString buf;
	int fps = (int)theApp.Imager()->GetRecordFps();
	int numShort = theApp.Imager()->GetNumShotsShort();
	int numLong  = theApp.Imager()->GetNumShotsLong();
	buf.Format(_T("舌裏撮影\n%d秒%d枚"), numShort / fps, numShort);
	GetDlgItem(IDC_BTN_SHORTSHOT)->SetWindowText(buf);
	GetDlgItem(IDC_BTN_SHORTSHOT)->SetFont(&m_FontBtn);
	buf.Format(_T("舌表撮影\n%d秒%d枚"), numLong / fps, numLong);
	GetDlgItem(IDC_BTN_LONGSHOT)->SetWindowText(buf);
	GetDlgItem(IDC_BTN_LONGSHOT)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_BTN_CALIB)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_BTN_SHOKEN)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_TXT_ID)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_EDT_ID)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_RAD_GENDERM)->SetFont(&m_FontBtn);
	GetDlgItem(IDC_RAD_GENDERF)->SetFont(&m_FontBtn);

	m_xvGender = 0;
	UpdateData(FALSE);

	// タイマー起動
	SetTimer(REDRAW_TIMER, 33, NULL);
}

// CTIAS_Imager2View メッセージ ハンドラー

// 画面更新
void CTIAS_Imager2View::OnPaint()
{
	CPaintDC dc(this);
	RECT r, wr;
	GetClientRect(&r);	// クライアント領域サイズ
	GetWindowRect(&wr);	// ウィンドウサイズ

	// 画像描画
	BYTE *buf = theApp.Imager()->GetStream(m_Bih.biWidth, m_Bih.biHeight);
	if (buf) {
		const int dispWmax = r.bottom * 4 / 5;
		int dispW = r.bottom * abs(m_Bih.biWidth) / abs(m_Bih.biHeight);
		if (dispW > dispWmax) dispW = dispWmax;
		SetStretchBltMode(dc.GetSafeHdc(), COLORONCOLOR);
		StretchDIBits(dc.GetSafeHdc(), 
			0, 0, dispW, r.bottom,
			0, 0, abs(m_Bih.biWidth), abs(m_Bih.biHeight), buf, 
			(BITMAPINFO*)&m_Bih, DIB_RGB_COLORS, SRCCOPY);
	}

	// ステータスバー更新
	CString str(_T(""));
	str.AppendFormat(_T("[Win:%dx%d, Cli:%dx%d] "),
		wr.right - wr.left, wr.bottom - wr.top, r.right, r.bottom);
	str.Append(theApp.Imager()->GetStatusText());
	((CMainFrame*)AfxGetMainWnd())->SetStatusMsg(CMainFrame::SBAR_MSG, str);
	((CMainFrame*)AfxGetMainWnd())->SetStatusMsg(CMainFrame::SBAR_FPS, theApp.Imager()->GetFpsText());

	// イベント処理
	this->EventProc();
}

// 画面更新タイマー
void CTIAS_Imager2View::OnTimer(UINT_PTR nIDEvent)
{
	if (nIDEvent == REDRAW_TIMER) Invalidate(FALSE);

	CFormView::OnTimer(nIDEvent);
}

// ワンショット撮影
void CTIAS_Imager2View::OnBnClickedBtnOneshot()
{
	if (!this->BeginProc()) return;
	theApp.Imager()->TakeOne();
}

// 長時間撮影
void CTIAS_Imager2View::OnBnClickedBtnLongshot()
{
	if (!this->BeginProc()) return;
	theApp.Imager()->TakeLong();
}

// 短時間撮影
void CTIAS_Imager2View::OnBnClickedBtnShortshot()
{
	if (!this->BeginProc()) return;
	theApp.Imager()->TakeShort();
}

// 中断ボタン
void CTIAS_Imager2View::OnBnClickedBtnAbort()
{
	theApp.Imager()->Abort();
}

// 校正
void CTIAS_Imager2View::OnBnClickedBtnCalib()
{
	this->BeginProc(FALSE, FALSE);
	m_CalibRecoded = FALSE;
	theApp.Imager()->StartCalibrate();
}

// 所見入力ボタン
void CTIAS_Imager2View::OnBnClickedBtnShoken()
{
	if (!this->BeginProc()) return;
	this->EnableControls(TRUE);
	theApp.Imager()->ShokenForm();
}

// ウインドウ破棄時
void CTIAS_Imager2View::OnDestroy()
{
	CFormView::OnDestroy();

	theApp.Imager()->CloseApp();
}

// イベント処理
void CTIAS_Imager2View::EventProc()
{
	switch (theApp.Imager()->GetEvent()) {
	case CImager::EV_CALIB_DONE:
		if (!m_CalibRecoded)  {
			m_CalibRecoded = TRUE;
			theApp.Imager()->TakeOne();
		}
		if (theApp.Imager()->GetStatus() == CImager::ST_PREVIEW) this->EnableControls(TRUE);
		break;
	case CImager::EV_MEAS_DONE:
		this->EnableControls(TRUE);
		break;
	case CImager::EV_SAVE_DONE:
		this->EnableControls(TRUE);
		break;
	case CImager::EV_ABORT:
		this->EnableControls(TRUE);
		break;
	case CImager::EV_CALIB_FAILED:
		GetDlgItem(IDC_BTN_CALIB)->EnableWindow(TRUE);
		break;
	}
}

// 処理開始
BOOL CTIAS_Imager2View::BeginProc(BOOL bNeedCheck, BOOL bAbortable)
{
	theApp.Imager()->ResetEvent();

	if (bNeedCheck) {
		UpdateData();
		if (m_xvEdtID.GetLength() < 1) {
			AfxMessageBox(_T("被験者IDを入力してください"));
			return FALSE;
		}
		theApp.Imager()->SetSubject(m_xvEdtID, m_xvGender);
	}

	this->EnableControls(FALSE, bAbortable);

	return TRUE;
}

// コントロールの有効・無効化
void CTIAS_Imager2View::EnableControls(BOOL bEnable, BOOL bAbortable)
{
	GetDlgItem(IDC_EDT_ID)->EnableWindow(bEnable);
	GetDlgItem(IDC_RAD_GENDERM)->EnableWindow(bEnable);
	GetDlgItem(IDC_RAD_GENDERF)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_ONESHOT)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_CALIB)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_SHOKEN)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_LONGSHOT)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_SHORTSHOT)->EnableWindow(bEnable);

	if (bAbortable || bEnable) {
		GetDlgItem(IDC_BTN_ABORT)->EnableWindow(!bEnable);
	}
}