// DevCtrlDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "NetSDKDemo.h"
#include "DevCtrlDlg.h"
#include "DevListDlg.h"
#include "NetSDKDemoDlg.h"
// CDevCtrlDlg 对话框

IMPLEMENT_DYNAMIC(CDevCtrlDlg, CDialog)

struct  OtherFunc
{
	char *pStrDescribe;
	char *pStrXml;
};
#define MAX_OTHERFUNC 34
OtherFunc g_OtherFunc[] = 
{
	{_T("    自动聚焦    "), _T("<xml>\n<cmd>FocusAutoOn</cmd>\n</xml>")},
	{_T("    手动聚焦    "), _T("<xml>\n<cmd>FocusAutoOff</cmd>\n</xml>")},

	{_T("    自动光圈    "), _T("<xml>\n<cmd>IrisAutoOn</cmd>\n</xml>")},
	{_T("    手动光圈    "), _T("<xml>\n<cmd>IrisAutoOff</cmd>\n</xml>")},
	
	{_T("    线扫起点    "), _T("<xml>\n<cmd>ScanBegin</cmd>\n</xml>")},
	{_T("    线扫终点    "), _T("<xml>\n<cmd>ScanEnd</cmd>\n</xml>")},
	
	{_T("    开启线扫    "), _T("<xml>\n<cmd>ScanOn</cmd>\n</xml>")},
	{_T("    关闭线扫    "), _T("<xml>\n<cmd>ScanOff</cmd>\n</xml>")},

	{_T("    开始巡视    "), _T("<xml>\n<cmd>Orbit</cmd>\n</xml>")},
	{_T("    巡视停止    "), _T("<xml>\n<cmd>stop</cmd>\n</xml>")},

	{_T("    黑白模式    "), _T("<xml>\n<cmd>BLCOff</cmd>\n</xml>")},
	{_T("    彩色模式    "), _T("<xml>\n<cmd>BLCOn</cmd>\n</xml>")},

	{_T("    镜像开    "), _T("<xml>\n<cmd>MirrorOn</cmd>\n</xml>")},
	{_T("    镜像关    "), _T("<xml>\n<cmd>MirrorOff</cmd>\n</xml>")},

	{_T("    图像冻结开    "), _T("<xml>\n<cmd>FreezeOn</cmd>\n</xml>")},
	{_T("    图像冻结关    "), _T("<xml>\n<cmd>FreezeOff</cmd>\n</xml>")},

	{_T("    数字变倍开    "), _T("<xml>\n<cmd>StepsZOn</cmd>\n</xml>")},
	{_T("    数字变倍关    "), _T("<xml>\n<cmd>StepsZOff</cmd>\n</xml>")},

	{_T("    屏显开    "), _T("<xml>\n<cmd>ScreenOn</cmd>\n</xml>")},
	{_T("    屏显关    "), _T("<xml>\n<cmd>ScreenOff</cmd>\n</xml>")},

	{_T("    低照度开    "), _T("<xml>\n<cmd>Min.SenOn</cmd>\n</xml>")},
	{_T("    低照度关    "), _T("<xml>\n<cmd>Min.SenOff</cmd>\n</xml>")},

	{_T("    背光补偿开    "), _T("<xml>\n<cmd>ILLOn</cmd>\n</xml>")},
	{_T("    背光补偿关    "), _T("<xml>\n<cmd>ILLOff</cmd>\n</xml>")},

	{_T("    相机复位    "), _T("<xml>\n<cmd>CamReset</cmd>\n</xml>")},

	{_T("    白平衡自动    "), _T("<xml>\n<cmd>AWBOn</cmd>\n</xml>")},
	{_T("    白平衡手动    "), _T("<xml>\n<cmd>AWBOff</cmd>\n</xml>")},

	{_T("    白平衡R    "), _T("<xml>\n<cmd>RWB</cmd>\n</xml>")},
	{_T("    白平衡B    "), _T("<xml>\n<cmd>BWB</cmd>\n</xml>")},

	{_T("    白平衡M    "), _T("<xml>\n<cmd>MWB</cmd>\n</xml>")},
	{_T("    白平衡G    "), _T("<xml>\n<cmd>GWB</cmd>\n</xml>")},

	{_T("    初始设置    "), _T("<xml>\n<cmd>InitSet</cmd>\n</xml>")},

	{_T("    控制菜单    "), _T("<xml>\n<cmd>Menu</cmd>\n</xml>")},

	{ NULL, NULL },

};

CDevCtrlDlg::CDevCtrlDlg(CRect rcWnd, CWnd* pParent /*=NULL*/)
	: CDialog(CDevCtrlDlg::IDD, pParent)
	,m_rcClient(0, 0, rcWnd.Width(), rcWnd.Height())
{

}

CDevCtrlDlg::~CDevCtrlDlg()
{
	DestroyWindow();
}

void CDevCtrlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_GROUP_DEVCTRL, m_ctlGroup);
	DDX_Control(pDX, IDC_CB_PANSPEED, m_ctlPanSpeed);
	DDX_Control(pDX, IDC_CB_TILTSPEED, m_ctlTiltSpeed);
	DDX_Control(pDX, IDC_CB_PRESET, m_ctlPresetNum);
	DDX_Control(pDX, IDC_CB_OTHER, m_ctlOtherFunc);
}


BEGIN_MESSAGE_MAP(CDevCtrlDlg, CDialog)
	ON_BN_CLICKED(IDC_BTN_PRESET_SET, &CDevCtrlDlg::OnBnClickedBtnPresetSet)
	ON_BN_CLICKED(IDC_BTN_PRESET_CALL, &CDevCtrlDlg::OnBnClickedBtnPresetCall)
	ON_BN_CLICKED(IDC_BTN_PRESET_DEL, &CDevCtrlDlg::OnBnClickedBtnPresetDel)
	ON_BN_CLICKED(IDC_BTN_OTHER_CALL, &CDevCtrlDlg::OnBnClickedBtnOtherCall)
END_MESSAGE_MAP()


// CDevCtrlDlg 消息处理程序

BOOL CDevCtrlDlg::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此添加专用代码和/或调用基类
 
	return CDialog::PreCreateWindow(cs);
}

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

	// TODO:  在此添加额外的初始化
	
	m_ctlGroup.MoveWindow(CRect(m_rcClient.left+2, m_rcClient.top,m_rcClient.Width()-2, m_rcClient.Height()-2));
	m_ctlPanSpeed.SetCurSel(5);
	m_ctlTiltSpeed.SetCurSel(5);
	m_ctlPresetNum.ResetContent();
	CString strPreset;
	for (int i=1; i<=255; i++)
	{
		strPreset.Format("%d", i);
		m_ctlPresetNum.InsertString(i-1, strPreset.GetBuffer());
	}
	m_ctlPresetNum.SetCurSel(0);
	
	m_ctlOtherFunc.ResetContent();
	for (int i=0; i<MAX_OTHERFUNC; i++)
	{	
		if (g_OtherFunc[i].pStrXml)
			m_ctlOtherFunc.InsertString(i,g_OtherFunc[i].pStrDescribe);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

BOOL CDevCtrlDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	if(pMsg->message == WM_LBUTTONDOWN)
	{
		
		CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();
		int iP = m_ctlPanSpeed.GetCurSel() + 1; //水平
		int iT = m_ctlTiltSpeed.GetCurSel() + 1;//垂直
		
			// PT
		if (pMsg->hwnd == GetDlgItem(IDC_BTN_UP)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(TILT_UP, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_DOWN)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(TILT_DOWN, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_LEFT)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(PAN_LEFT, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_RIGHT)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(PAN_RIGHT, iP, iT);
		}
			// ZOOM
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_ZOOMIN)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(ZOOM_IN, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_ZOOMOUT)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(ZOOM_OUT, iP, iT);
		}
			// FOCUS
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_FOCUS_FAR)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(FOCUS_FAR, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_FOCUS_NEAR)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(FOCUS_NEAR, iP, iT);
		}
			// IRIS
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_IRIS_BIG)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(IRIS_OPEN, iP, iT);
		}
		else if (pMsg->hwnd == GetDlgItem(IDC_BTN_IRIS_SMALL)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(IRIS_CLOSE, iP, iT);
		}

	}

	else if (pMsg->message == WM_LBUTTONUP)
	{
		CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();
		if (
			/* PT */
			pMsg->hwnd == GetDlgItem(IDC_BTN_UP)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_RIGHT)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_DOWN)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_LEFT)->m_hWnd
			/* Zoom */
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_ZOOMOUT)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_ZOOMIN)->m_hWnd
			/* Focus */
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_FOCUS_FAR)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_FOCUS_NEAR)->m_hWnd
			/* Iris */
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_IRIS_BIG)->m_hWnd
			|| pMsg->hwnd == GetDlgItem(IDC_BTN_IRIS_SMALL)->m_hWnd)
		{
			pNetSDKDemoDlg->PTZCtrl(STOPACTION, 0, 0);
		}
	}

	if (pMsg->message == WM_KEYDOWN)
	{
		if(pMsg->wParam == 13)
			return TRUE;
 		if (pMsg->wParam == 27)
		{
			::PostMessage(GetParent()->m_hWnd, WM_KEYDOWN, 27, 0);
 			return TRUE;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CDevCtrlDlg::OnBnClickedBtnPresetSet()
{
	// TODO: 在此添加控件通知处理程序代码
	CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();

	int iPresetNum = m_ctlPresetNum.GetCurSel()+1;

	pNetSDKDemoDlg->PresetCtrl(SET_PRESET, iPresetNum);
	
}

void CDevCtrlDlg::OnBnClickedBtnPresetCall()
{
	// TODO: 在此添加控件通知处理程序代码
	CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();

	int iPresetNum = m_ctlPresetNum.GetCurSel()+1;

	pNetSDKDemoDlg->PresetCtrl(GOTO_PRESET, iPresetNum);

}

void CDevCtrlDlg::OnBnClickedBtnPresetDel()
{
	// TODO: 在此添加控件通知处理程序代码
	CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();

	int iPresetNum = m_ctlPresetNum.GetCurSel()+1;

	pNetSDKDemoDlg->PresetCtrl(CLE_PRESET, iPresetNum);
}

void CDevCtrlDlg::OnBnClickedBtnOtherCall()
{
	// TODO: 在此添加控件通知处理程序代码
	CNetSDKDemoDlg *pNetSDKDemoDlg = (CNetSDKDemoDlg *)theApp.m_pMainWnd;//(CNetSDKDemoDlg *)GetParent();
	int iIndex = m_ctlOtherFunc.GetCurSel();
	if (iIndex < MAX_OTHERFUNC)
	{
		if (g_OtherFunc[iIndex].pStrXml)
		{
			pNetSDKDemoDlg->XMLCtrl(g_OtherFunc[iIndex].pStrXml);
		}
	}
}
