// DlgIntelligentHighSet.cpp : implementation file
//

#include "stdafx.h"
#include "Smart_Fire.h"
#include "DlgIntelligentHighSet.h"
#include "DlgRuleSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgSmartHighSet dialog
extern CDlgSmartBasicSet*   g_dlgSmartBaseSet;

#define OPERATORERROR(temp,nIDS)\
	CString temp = _T("");\
	temp.LoadString(nIDS);\
	AfxMessageBox(temp);\
		return\

CDlgSmartHighSet::CDlgSmartHighSet(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSmartHighSet::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSmartHighSet)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgSmartHighSet::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSmartHighSet)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSmartHighSet, CDialog)
	//{{AFX_MSG_MAP(CDlgSmartHighSet)
	ON_BN_CLICKED(IDC_BTN_GETRULE, OnBtnGetrule)
	ON_BN_CLICKED(IDC_BTN_SETRULE, OnBtnSetrule)
	ON_BN_CLICKED(IDC_BTN_DEFAULT, OnBtnDefault)
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSmartHighSet message handlers

BOOL CDlgSmartHighSet::OnInitDialog() 
{
	CDialog::OnInitDialog();

//	CRect rc(0,0,0,0);
//	GetParent()->GetClientRect(&rc);
//	((CTabCtrl*)GetParent())->AdjustRect(FALSE,&rc);
//	MoveWindow(&rc);
	
	// TODO: Add extra initialization here
	GetBackParam();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgSmartHighSet::GetBackParam()
{
	if (g_dlgSmartBaseSet->LoadVAParam())
    {
        CString   szText;
        
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_bkgd);
        GetDlgItem(IDC_EDIT_FRM_BKGD)->SetWindowText(szText);
		
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_pixels);
        GetDlgItem(IDC_EDIT_FRM_PIXELS)->SetWindowText(szText);
		
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_object);
        GetDlgItem(IDC_EDIT_FRM_OBJECT)->SetWindowText(szText);
    }
	UpdateWindow();
}

void CDlgSmartHighSet::OnBtnGetrule() 
{
	// TODO: Add your control notification handler code here
	if(g_dlgSmartBaseSet == NULL)return;
	if (g_dlgSmartBaseSet->LoadVAParam())
    {
        CString   szText;
        
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_bkgd);
        GetDlgItem(IDC_EDIT_FRM_BKGD)->SetWindowText(szText);
		
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_pixels);
        GetDlgItem(IDC_EDIT_FRM_PIXELS)->SetWindowText(szText);
		
        szText.Format("%d", g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_object);
        GetDlgItem(IDC_EDIT_FRM_OBJECT)->SetWindowText(szText);
    }
	UpdateWindow();
}

void CDlgSmartHighSet::OnBtnSetrule() 
{
	// TODO: Add your control notification handler code here
	if(g_dlgSmartBaseSet == NULL)return;
	UpdateData();
	CString szText;
    GetDlgItem(IDC_EDIT_FRM_BKGD)->GetWindowText(szText);
    g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_bkgd = atoi(szText);

    if (g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_bkgd < 30 || 
		g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_bkgd > 50)
    {
	    OPERATORERROR(temp, IDS_STRING532);
    }

    GetDlgItem(IDC_EDIT_FRM_PIXELS)->GetWindowText(szText);
    g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_pixels = atoi(szText);

    if (g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_pixels < 1 || 
		g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_pixels > 100)
    {
        ::AfxMessageBox("背景的均值和方差更新的周期在1 ~ 100帧之间!");
        return;
    }
    
    GetDlgItem(IDC_EDIT_FRM_OBJECT)->GetWindowText(szText);
    g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_object = atoi(szText);

    if (g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_object < 100 || 
		g_dlgSmartBaseSet->m_rulesStatic.m_vabackground.m_frm_object > 200)
    {
        ::AfxMessageBox("静止目标融为背景所需的时间在100 ~ 200帧之间!");
        return;
    }
	g_dlgSmartBaseSet->m_rulesStatic.SaveVAParam(FALSE);
	CDialog::OnOK();
}

void CDlgSmartHighSet::OnBtnDefault() 
{
	// TODO: Add your control notification handler code here
	CString strdefault;
	strdefault.Format("%d", 30);
    GetDlgItem(IDC_EDIT_FRM_BKGD)->SetWindowText(strdefault);
	strdefault.Format("%d", 4);
    GetDlgItem(IDC_EDIT_FRM_PIXELS)->SetWindowText(strdefault);
	strdefault.Format("%d", 100);
    GetDlgItem(IDC_EDIT_FRM_OBJECT)->SetWindowText(strdefault);
	UpdateData(FALSE);
}

void CDlgSmartHighSet::OnBtnCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}
