// DialogBaseParamSetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "8949G1VC.h"
#include "DialogBaseParamSetDlg.h"
#include "CtrlCardSingletion.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogBaseParamSetDlg dialog


CDialogBaseParamSetDlg::CDialogBaseParamSetDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogBaseParamSetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialogBaseParamSetDlg)
	m_nPulseModeX = -1;
	m_nPulseModeY = -1;
	m_nPulseModeZ = -1;
	m_nPulseModeA = -1;
	m_nPLimitModeX = -1;
	m_nPLimitModeY = -1;
	m_nPLimitModeZ = -1;
	m_nPLimitModeA = -1;
	m_nNLimitModeX = -1;
	m_nNLimitModeY = -1;
	m_nNLimitModeZ = -1;
	m_nNLimitModeA = -1;
	m_nStop0ModeX = -1;
	m_nStop0ModeY = -1;
	m_nStop0ModeZ = -1;
	m_nStop0ModeA = -1;
	m_nStop1ModeX = -1;
	m_nStop1ModeY = -1;
	m_nStop1ModeZ = -1;
	m_nStop1ModeA = -1;
	m_nEffectLogicX = -1;
	m_nEffectLogicY = -1;
	m_nEffectLogicZ = -1;
	m_nEffectLogicA = -1;
	m_nHardStop = -1;
	m_nHardLogic = -1;

	m_checkstop1 = FALSE;
	//}}AFX_DATA_INIT
	
}


void CDialogBaseParamSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogBaseParamSetDlg)
	DDX_Radio(pDX, IDC_RADIO_X_PULSEMODE1, m_nPulseModeX);
	DDX_Radio(pDX, IDC_RADIO_Y_PULSEMODE1, m_nPulseModeY);
	DDX_Radio(pDX, IDC_RADIO_Z_PULSEMODE1, m_nPulseModeZ);
	DDX_Radio(pDX, IDC_RADIO_A_PULSEMODE1, m_nPulseModeA);
	DDX_Radio(pDX, IDC_RADIO_PLIMITMODE_X1, m_nPLimitModeX);
	DDX_Radio(pDX, IDC_RADIO_PLIMITMODE_Y1, m_nPLimitModeY);
	DDX_Radio(pDX, IDC_RADIO_PLIMITMODE_Z1, m_nPLimitModeZ);
	DDX_Radio(pDX, IDC_RADIO_PLIMITMODE_A1, m_nPLimitModeA);
	DDX_Radio(pDX, IDC_RADIO_NLIMITMODE_X1, m_nNLimitModeX);
	DDX_Radio(pDX, IDC_RADIO_NLIMITMODE_Y1, m_nNLimitModeY);
	DDX_Radio(pDX, IDC_RADIO_NLIMITMODE_Z1, m_nNLimitModeZ);
	DDX_Radio(pDX, IDC_RADIO_NLIMITMODE_A1, m_nNLimitModeA);
	DDX_Radio(pDX, IDC_RADIO_STOP0MODE_X1, m_nStop0ModeX);
	DDX_Radio(pDX, IDC_RADIO_STOP0MODE_Y1, m_nStop0ModeY);
	DDX_Radio(pDX, IDC_RADIO_STOP0MODE_Z1, m_nStop0ModeZ);
	DDX_Radio(pDX, IDC_RADIO_STOP0MODE_A1, m_nStop0ModeA);
	DDX_Radio(pDX, IDC_RADIO_STOP1MODE_X1, m_nStop1ModeX);
	DDX_Radio(pDX, IDC_RADIO_STOP1MODE_Y1, m_nStop1ModeY);
	DDX_Radio(pDX, IDC_RADIO_STOP1MODE_Z1, m_nStop1ModeZ);
	DDX_Radio(pDX, IDC_RADIO_STOP1MODE_A1, m_nStop1ModeA);
	DDX_Radio(pDX, IDC_RADIO_EFFECTLOGIC_X1, m_nEffectLogicX);
	DDX_Radio(pDX, IDC_RADIO_EFFECTLOGIC_Y1, m_nEffectLogicY);
	DDX_Radio(pDX, IDC_RADIO_EFFECTLOGIC_Z1, m_nEffectLogicZ);
	DDX_Radio(pDX, IDC_RADIO_EFFECTLOGIC_A1, m_nEffectLogicA);
	DDX_Radio(pDX, IDC_RADIO_HARDSTOP1, m_nHardStop);
	DDX_Radio(pDX, IDC_RADIO_HARDLOGIC1, m_nHardLogic);

	DDX_Check(pDX, IDC_CHECK1, m_checkstop1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogBaseParamSetDlg, CDialog)
	//{{AFX_MSG_MAP(CDialogBaseParamSetDlg)
	ON_BN_CLICKED(IDC_BUTTON_BASEPARAMSET_BACK, OnButtonBaseparamsetBack)
	ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogBaseParamSetDlg message handlers
// [12/13/2012 Administrator]:初始化数据
void CDialogBaseParamSetDlg::InitData()
{
	// 输出脉冲方式  0-脉冲＋脉冲   1－脉冲＋方向  默认模式为脉冲＋方向   
	m_nPulseModeX = 1;
	m_nPulseModeY = 1;
	m_nPulseModeZ = 1;
	m_nPulseModeA = 1;
	// 正限位模式设定 0-正限位有效   1－正限位无效    默认模式为正限位有效 
	m_nPLimitModeX = 0;
	m_nPLimitModeY = 0;
	m_nPLimitModeZ = 0;
	m_nPLimitModeA = 0;
	// 负限位模式设定 0-负限位有效   1－负限位无效    默认模式为负限位有效 
	m_nNLimitModeX = 0;
	m_nNLimitModeY = 0;
	m_nNLimitModeZ = 0;
	m_nNLimitModeA = 0;
	// STOP0模式设定  0-无效   1－有效          默认模式为无效      
	m_nStop0ModeX = 0;
	m_nStop0ModeY = 0;
	m_nStop0ModeZ = 0;
	m_nStop0ModeA = 0;
	// STOP1模式设定  0-无效   1－有效          默认模式为无效  
	m_nStop1ModeX = 0;
	m_nStop1ModeY = 0;
	m_nStop1ModeZ = 0;
	m_nStop1ModeA = 0;
	// 电平模式设定 此为限位、STOP0、STOP1模式下电平设定0-低电平有效  1－高电平有效    默认模式为低电平效     
	m_nEffectLogicX = 0;
	m_nEffectLogicY = 0;
	m_nEffectLogicZ = 0;
	m_nEffectLogicA = 0;
	// 硬件停止设定 此为硬件停止功能设定 m_nHardStop 0-无效   1-有效  m_nHardLogic 0-低电平  1-高电平 默认为无效
	m_nHardStop = 0;
	m_nHardLogic = 0;
	// 锁存计数器模式

	
	UpdateData(FALSE);
	return;
}

BOOL CDialogBaseParamSetDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	InitData();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogBaseParamSetDlg::OnButtonBaseparamsetBack() 
{
	// TODO: Add your control notification handler code here
	InitData();
	UpdateData(FALSE);
	
	int nPulseMode[] = {m_nPulseModeX, m_nPulseModeY, m_nPulseModeZ, m_nPulseModeA};
	int nPLimitMode[] = {m_nPLimitModeX, m_nPLimitModeY, m_nPLimitModeZ, m_nPLimitModeA};
	int nNLimitMode[] = {m_nNLimitModeX, m_nNLimitModeY, m_nNLimitModeZ, m_nNLimitModeA};
	int nStop0Mode[] = {m_nStop0ModeX, m_nStop0ModeY, m_nStop0ModeZ, m_nStop0ModeA};
	int nStop1Mode[] = {m_nStop1ModeX, m_nStop1ModeY, m_nStop1ModeZ, m_nStop1ModeA};
	int nEffectLogic[] = {m_nEffectLogicX, m_nEffectLogicY, m_nEffectLogicZ, m_nEffectLogicA};
	
	for (int i=1; i<4+1; i++)
	{
		// 脉冲输出方式设置
		CCtrlCardSingletion::Instance()->SetupPulseMode(i, nPulseMode[i-1]);
		// 限位模式设置
		CCtrlCardSingletion::Instance()->SetupLimitMode(i, nPLimitMode[i-1], nNLimitMode[i-1], nEffectLogic[i-1]);
		// STOP0信号模式设置

		if(m_checkstop1)
		{
			// STOP1信号模式设置
			CCtrlCardSingletion::Instance()->SetupStop1Mode(i, nStop1Mode[i-1], nEffectLogic[i-1],1);
		}else
		{
			// STOP0信号模式设置
			CCtrlCardSingletion::Instance()->SetupStop0Mode(i, nStop0Mode[i-1], nEffectLogic[i-1],1);
		}
	}
	
	CCtrlCardSingletion::Instance()->SetupHardStop(m_nHardStop, m_nHardLogic);
	
	MessageBox("Restore default settings successfully！","notice");
}



void CDialogBaseParamSetDlg::OnButtonOk() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	
	
	int nPulseMode[] = {m_nPulseModeX, m_nPulseModeY, m_nPulseModeZ, m_nPulseModeA};
	int nPLimitMode[] = {m_nPLimitModeX, m_nPLimitModeY, m_nPLimitModeZ, m_nPLimitModeA};
	int nNLimitMode[] = {m_nNLimitModeX, m_nNLimitModeY, m_nNLimitModeZ, m_nNLimitModeA};
	int nStop0Mode[] = {m_nStop0ModeX, m_nStop0ModeY, m_nStop0ModeZ, m_nStop0ModeA};
	int nStop1Mode[] = {m_nStop1ModeX, m_nStop1ModeY, m_nStop1ModeZ, m_nStop1ModeA};
	int nEffectLogic[] = {m_nEffectLogicX, m_nEffectLogicY, m_nEffectLogicZ, m_nEffectLogicA};
	
	for (int i=1; i<5; i++)
	{
		// 脉冲输出方式设置
		CCtrlCardSingletion::Instance()->SetupPulseMode(i, nPulseMode[i-1]);
		// 限位模式设置
		CCtrlCardSingletion::Instance()->SetupLimitMode(i, nPLimitMode[i-1], nNLimitMode[i-1], nEffectLogic[i-1]);
		


		if(m_checkstop1)
		{
 			// STOP1信号模式设置
			CCtrlCardSingletion::Instance()->SetupStop1Mode(i, nStop1Mode[i-1], nEffectLogic[i-1],1);
		}else
 		{
			// STOP0信号模式设置
			CCtrlCardSingletion::Instance()->SetupStop0Mode(i, nStop0Mode[i-1], nEffectLogic[i-1],1);
 		}
		
		
		
	}
	
	CCtrlCardSingletion::Instance()->SetupHardStop(m_nHardStop, m_nHardLogic);
	
	MessageBox("set up Successed！", "setup tips");	

	return;




}





void CDialogBaseParamSetDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	if(((CButton*)GetDlgItem(IDC_CHECK1))->GetCheck()==1)
	{
		
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_X1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_X2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Y1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Y2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Z1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Z2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_A1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_A2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_X1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_X2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Y1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Y2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Z1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Z2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_A1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_A2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_STC_BASEPARAMSET_STOP0))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_STC_BASEPARAMSET_STOP1))->EnableWindow(TRUE);
		
		
		
		
	}
	else
	{
		
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_X1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_X2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Y1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Y2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Z1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_Z2))->EnableWindow(FALSE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_A1))->EnableWindow(FALSE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP1MODE_A2))->EnableWindow(FALSE);
		
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_X1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_X2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Y1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Y2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Z1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_Z2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_A1))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_RADIO_STOP0MODE_A2))->EnableWindow(TRUE);
		
		((CEdit*)GetDlgItem(IDC_STC_BASEPARAMSET_STOP0))->EnableWindow(TRUE);
		((CEdit*)GetDlgItem(IDC_STC_BASEPARAMSET_STOP1))->EnableWindow(FALSE);
		
	}    
	
}



