// DlgWizardSecond.cpp : implementation file
//

#include "stdafx.h"
#include "Smart_Smart.h"
#include "DlgWizardSecond.h"
#include "DlgIntelligentTime.h"
#include "Rule.h"
#include "DlgRuleSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgWizardSecond dialog
#define SETITEMSTATE(nID,state)\
    ((CButton*)GetDlgItem(nID))->SetCheck(state);\
    GetDlgItem(nID)->EnableWindow(!state)
extern void WINAPI DrawCallBack(HDC hDC,void *context);
extern CDlgSmartBasicSet*   g_dlgSmartBaseSet;
CDlgWizardSecond::CDlgWizardSecond(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgWizardSecond::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgWizardSecond)
	m_hovertime = 0;
	//}}AFX_DATA_INIT
	m_thirdway = NULL;
	
	m_hIcon_single_left   = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_SINGLE_LEFT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_SINGLE_LEFT);
    m_hIcon_single_right  = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_SINGLE_RIGHT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_SINGLE_RIGHT);
    m_hIcon_single_double = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_SINGLE_DOUBLE),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_SINGLE_DOUBLE);
	
    m_hIcon_multi_left    = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_MULTI_LEFT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_MULTI_LEFT);
    m_hIcon_multi_right   = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_MULTI_RIGHT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_MULTI_RIGHT);
    m_hIcon_multi_double  = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_MULTI_DOUBLE),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_MULTI_DOUBLE);
	
    m_hIcon_region_fill      = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_FILL),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_FILL);
    m_hIcon_region_pencil    = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_BRUSH),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_BRUSH);
    m_hIcon_region_line      = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_POLYGON),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_POLYGON);
    m_hIcon_region_erase     = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_ERASE),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_ERASE);
    m_hIcon_region_rect      = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_RECT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_RECT);
    m_hIcon_region_cleanall  = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_REGION_CLEANALL),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_REGION_CLEANALL);
	
    m_hIcon_select          = (HICON)::LoadImage(AfxGetInstanceHandle(),
		MAKEINTRESOURCE(IDI_ICON_SELECT),
		IMAGE_ICON,
		16,16,0);//AfxGetApp()->LoadIcon(IDI_ICON_SELECT);
	m_prevItemID = 0;

    m_ruleType = -1;
}


void CDlgWizardSecond::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgWizardSecond)
	DDX_Control(pDX, IDC_SLIDER_LINE_WIDTH, m_hSliderLineWidth);
	DDX_Control(pDX, IDC_STATIC_EDITIMG, m_myrulestatic);
	DDX_Text(pDX, IDC_EDIT_INFINITETIME, m_hovertime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgWizardSecond, CDialog)
	//{{AFX_MSG_MAP(CDlgWizardSecond)
	ON_BN_CLICKED(IDC_BTN_NEXT, OnBtnNext)
	ON_BN_CLICKED(IDC_BTN_PRO, OnBtnPro)
	ON_BN_CLICKED(IDC_BTN_CANCEL, OnBtnCancel)
	ON_WM_CLOSE()
	ON_WM_PAINT()
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER_LINE_WIDTH, OnCustomdrawSliderLineWidth)
	ON_WM_SHOWWINDOW()
	ON_WM_MOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgWizardSecond message handlers

void CDlgWizardSecond::OnBtnNext() 
{
	if (! m_first->m_rule)
	{
		if(((CSingleLineRule*)m_myrulestatic.m_pSelectRule)->m_Rule.m_sgline_beg_x == 0 &&
            ((CSingleLineRule*)m_myrulestatic.m_pSelectRule)->m_Rule.m_sgline_beg_x == 0 &&
			((CSingleLineRule*)m_myrulestatic.m_pSelectRule)->m_Rule.m_sgline_beg_x == 0 &&
			((CSingleLineRule*)m_myrulestatic.m_pSelectRule)->m_Rule.m_sgline_beg_x == 0 )
/*			if (IDNO == MessageBox("你还没有绘制规则，是否进入下一步？","温馨提示",MB_YESNO))
			{
				return;
			}
			*/       
		{
           AfxMessageBox("你还没有绘制规则!");
		   return;
		}
	}
	else
	{
		unsigned int   m_packed_msk[352*288/8/4];
        ((CRegionRule*)m_myrulestatic.m_pSelectRule)->GetRuleFromRgn((UINT*)&m_packed_msk);
        for (int i = 0; i < 352*288/8/4; i ++)
        {
			if (m_packed_msk[i])
			{
				break;
			}
        }
		if (i == 352*288/8/4)
		{
/*			if (IDNO == MessageBox("你还没有绘制规则，是否进入下一步？","温馨提示",MB_YESNO))
			{
				return;
			}
*/
			AfxMessageBox("你还没有绘制规则!");
		    return;
		}
	}
	UpdateData();
	// TODO: Add your control notification handler code here
	if (!m_thirdway)
	{
	   m_thirdway = new CDlgSmartTime();
	   m_thirdway->Create(IDD_DLG_SMALARM,g_dlgSmartBaseSet);
	}
	else
	{
       ShowWindow(SW_HIDE);
	}
	m_thirdway->ShowWindow(SW_SHOW);
//	m_thirdway->MoveWindow(g_dlgSmartBaseSet->m_prodlgpos);
}

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

    m_myrulestatic.EnableEdit(TRUE);
    m_myrulestatic.SetCameraLinkParam(g_dlgSmartBaseSet->m_username,g_dlgSmartBaseSet->m_url,0,g_dlgSmartBaseSet->m_port,
		g_dlgSmartBaseSet->m_username,g_dlgSmartBaseSet->m_password);

    m_first = (CDlgWizardFirst*)g_dlgSmartBaseSet->m_ptrsetways.GetAt(0);
	m_first->ShowWindow(SW_HIDE);
    m_myrulestatic.SetWindowPos(NULL,20,0,352,288,SWP_NOMOVE);

    ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT))->SetIcon(m_hIcon_select);
//  ((CButton*)GetDlgItem(IDC_BTN_REGION_FILL))->SetIcon(m_hIcon_region_fill);
    ((CButton*)GetDlgItem(IDC_BTN_REGION_PENCIL))->SetIcon(m_hIcon_region_pencil);
    ((CButton*)GetDlgItem(IDC_BTN_REGION_LINE))->SetIcon(m_hIcon_region_line);
    ((CButton*)GetDlgItem(IDC_BTN_REGION_ERASE))->SetIcon(m_hIcon_region_erase);
    ((CButton*)GetDlgItem(IDC_BTN_REGION_RECT))->SetIcon(m_hIcon_region_rect);
    ((CButton*)GetDlgItem(IDC_BTN_REGION_CLEANALL))->SetIcon(m_hIcon_region_cleanall);
    ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT))->SetIcon(m_hIcon_single_left);
	((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_RIGHT))->SetIcon(m_hIcon_single_right);
	((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_DOUBLE))->SetIcon(m_hIcon_single_double);
	
	g_dlgSmartBaseSet->m_ptrsetways.Add(this);
    
	CString   szToolTip;
    m_toolTip.Create(this);
	m_toolTip.Activate(TRUE);
	
    szToolTip.LoadString(IDS_STRING489);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT),szToolTip);
    szToolTip.LoadString(IDS_STRING490);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_SINGLE_DRC_RIGHT),szToolTip);
    szToolTip.LoadString(IDS_STRING491);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_SINGLE_DRC_DOUBLE),szToolTip);
    szToolTip.LoadString(IDS_STRING492);
//  m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_FILL),szToolTip);
//  szToolTip.LoadString(IDS_STRING493);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_ERASE),szToolTip);
    szToolTip.LoadString(IDS_STRING494);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_CLEANALL),szToolTip);
    szToolTip.LoadString(IDS_STRING495);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_LINE),szToolTip);
    szToolTip.LoadString(IDS_STRING496);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_PENCIL),szToolTip);
    szToolTip.LoadString(IDS_STRING497);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_REGION_RECT),szToolTip);
    szToolTip.LoadString(IDS_STRING498);
    m_toolTip.AddTool(GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT),szToolTip);
	szToolTip.LoadString(IDS_STRING499);
	m_toolTip.AddTool(&m_hSliderLineWidth,szToolTip);
    
	m_hSliderLineWidth.SetRange(1,50);
	m_hSliderLineWidth.SetPos(1);

    GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT)->ShowWindow(SW_SHOW);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgWizardSecond::OnBtnPro() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	ShowWindow(SW_HIDE);
	m_first->ShowWindow(SW_SHOW);
//	m_first->MoveWindow(g_dlgSmartBaseSet->m_prodlgpos);
}
void CDlgWizardSecond::OnEditBtnClicked(int nBtnID)
{
    BOOL    bProcess = FALSE;

    switch( nBtnID )
    {
    case IDC_BTN_PLAY:
        m_myrulestatic.Play();
		PreparePloyRule(m_first->m_rule);
   		SETITEMSTATE(IDC_BTN_PLAY,TRUE);
		SETITEMSTATE(IDC_BTN_PAUSE,FALSE);
        return;
        break;
    
    case IDC_BTN_PAUSE:
        m_myrulestatic.Pause();   
        SETITEMSTATE(IDC_BTN_PLAY,FALSE);
        SETITEMSTATE(IDC_BTN_PAUSE,TRUE);
        return;
        break;
    case IDC_BTN_SINGLE_DRC_LEFT:
        m_myrulestatic.SetSingleLineRuleDrc(LINE_DRC_LEFT);
        bProcess = TRUE;
        break;

    case IDC_BTN_SINGLE_DRC_RIGHT:
        m_myrulestatic.SetSingleLineRuleDrc(LINE_DRC_RIGHT);
        bProcess = TRUE;
        break;
    
    case IDC_BTN_SINGLE_DRC_DOUBLE:
		m_myrulestatic.SetSingleLineRuleDrc(LINE_DRC_DOUBLE);
		bProcess = TRUE;
        break;
    case IDC_BTN_SINGLE_DRC_SELECT:
        {
            BOOL bMove = (((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT))->GetCheck());
            if( !m_myrulestatic.EnableRuleMove( bMove ) )
            {
                ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT))->SetCheck(!bMove);
            }
        }
        break;
    case IDC_BTN_REGION_PENCIL:
		m_myrulestatic.SetEditActionType(EDITRULE_ACTION_PENCIL);
		bProcess = TRUE;
        break;
    case IDC_BTN_REGION_ERASE:
		m_myrulestatic.SetEditActionType(EDITRULE_ACTION_ERASE);
		bProcess = TRUE;
        break;
    case IDC_BTN_REGION_CLEANALL:
        m_myrulestatic.RegionCleanAll();
        break;
    case IDC_BTN_REGION_RECT:
        m_myrulestatic.SetEditActionType(EDITRULE_ACTION_REGION_RECT);
        bProcess = TRUE;
        break;
    case IDC_BTN_REGION_FILL:
		if(m_myrulestatic.m_polylinefinish)
		{
			m_myrulestatic.SetEditActionType(EDITRULE_ACTION_REGION_FILL);
			m_myrulestatic.m_polylinefinish = FALSE;
			bProcess = TRUE;
		}
		else
		{
			AfxMessageBox("所绘制的封闭线没有完成，请完成后再填充！");
			SETITEMSTATE(IDC_BTN_REGION_FILL,FALSE);
			GetDlgItem(IDC_BTN_REGION_FILL)->UpdateWindow();
			bProcess = FALSE;
		}
        break;
    case IDC_BTN_REGION_LINE:
        m_myrulestatic.SetEditActionType(EDITRULE_ACTION_REGION_POLYGON);
        bProcess = TRUE;
        break;
    case IDC_BTN_MINAREA:
		m_myrulestatic.SetEditActionType(EDITRULE_ACTION_OBJECT_MIN_AREA);
        break;
    case IDC_BTN_MAXAREA:
		m_myrulestatic.SetEditActionType(EDITRULE_ACTION_OBJECT_MAX_AREA);
    }
    if( !bProcess ) return;
    
    if( m_prevItemID != 0 )
    {
        SETITEMSTATE(m_prevItemID,FALSE);
    }

    SETITEMSTATE(nBtnID,TRUE);
    m_prevItemID = nBtnID;

	if(nBtnID == IDC_BTN_REGION_PENCIL || nBtnID == IDC_BTN_REGION_ERASE)
		GetDlgItem(IDC_SLIDER_LINE_WIDTH)->ShowWindow(SW_SHOW);
	else
		GetDlgItem(IDC_SLIDER_LINE_WIDTH)->ShowWindow(SW_HIDE);
}

BOOL CDlgWizardSecond::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (HIWORD(wParam) == BN_CLICKED)
    {
        OnEditBtnClicked(LOWORD(wParam));
    }
	return CDialog::OnCommand(wParam, lParam);
}

void CDlgWizardSecond::OnBtnCancel() 
{
	// TODO: Add your control notification handler code here
	g_dlgSmartBaseSet->m_ioperatestate = -1;
	g_dlgSmartBaseSet->m_cureditrule.pos = -1;
	g_dlgSmartBaseSet->m_cureditrule.ruletype = -1;
	m_myrulestatic.Stop();
	g_dlgSmartBaseSet->SetBtnState(FALSE);
	if (m_myrulestatic.m_pSelectRule != NULL)
	{
		delete m_myrulestatic.m_pSelectRule;
		m_myrulestatic.m_pSelectRule = NULL;
	}

	//g_dlgSmartBaseSet->m_ptrsetways.RemoveAt(1);
	g_dlgSmartBaseSet->PostMessage(WM_SMWND_DESTOY);
	//DestroyWindow();
	//delete this;
	//CDialog::OnCancel();
}

void CDlgWizardSecond::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	g_dlgSmartBaseSet->m_ioperatestate = -1;
	g_dlgSmartBaseSet->SetBtnState(FALSE);
	OnBtnCancel();
	CDialog::OnClose();
}

BOOL CDlgWizardSecond::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_MOUSEMOVE)
	{
        m_toolTip.Activate(TRUE);
	}
	else if (pMsg->message == WM_KEYUP)
	{
		g_dlgSmartBaseSet->SetBtnState(FALSE);
        m_myrulestatic.OnKeyControl(pMsg->wParam, pMsg->message == WM_KEYDOWN);
    }
	m_toolTip.RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

void CDlgWizardSecond::PreparePloyRule(int ruleType)
{
	int operatestate = g_dlgSmartBaseSet->m_ioperatestate;
	RULETYPEPOS temp;
	memset(&temp, 0, sizeof(RULETYPEPOS));
	temp.pos = -1;
	temp.ruletype = -1;
    memcpy(&temp, &g_dlgSmartBaseSet->m_cureditrule, sizeof(RULETYPEPOS));
   switch (ruleType)
   {
      case LINERULE:
		  {
			  CSingleLineRule* singleline = new CSingleLineRule;
        	  if (operatestate == 3 && ruleType == temp.ruletype)
        	  {
				  VSNETVASINGLELINERULE lineinfo;
				  memset(&lineinfo, 0, sizeof(VSNETVASINGLELINERULE));
				  lineinfo.m_sgline_beg_x = g_dlgSmartBaseSet->m_singleRules.m_lines[temp.pos].m_sgline_beg_x;
				  lineinfo.m_sgline_beg_y = g_dlgSmartBaseSet->m_singleRules.m_lines[temp.pos].m_sgline_beg_y;
				  lineinfo.m_sgline_drc = g_dlgSmartBaseSet->m_singleRules.m_lines[temp.pos].m_sgline_drc;
				  lineinfo.m_sgline_end_x = g_dlgSmartBaseSet->m_singleRules.m_lines[temp.pos].m_sgline_end_x;
				  lineinfo.m_sgline_end_y = g_dlgSmartBaseSet->m_singleRules.m_lines[temp.pos].m_sgline_end_y;
				  if (((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT))->GetCheck() && lineinfo.m_sgline_drc != 0)
				  {
                      ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT))->SetCheck(0);
				  }
				  ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT + lineinfo.m_sgline_drc))->SetCheck(1);
				  singleline->SetRule(&lineinfo);
				  if (! lineinfo.m_sgline_beg_x && ! lineinfo.m_sgline_beg_y &&
					  ! lineinfo.m_sgline_end_x && ! lineinfo.m_sgline_end_y)
				  {
                     singleline->m_bInitDraw = FALSE;
				  }
        	  }
			  m_myrulestatic.SetCurRule(singleline);
   	          break;
		  }
	  case REGIONINRULE:
		  {
			  CRegionRule* region = new CRegionRule(0);
			  VSNETVAREGIONERULE reginfo;
			  memset(&reginfo, 0, sizeof(VSNETVAREGIONERULE));
			  reginfo.m_region_valid = 1;
			  if (! operatestate)
			  {
				  region->GetRuleFromRgn((UINT*)&reginfo.m_packed_msk);
			  }
			  else if (operatestate == 3 && temp.ruletype)
			  { 
                  memcpy(reginfo.m_packed_msk, g_dlgSmartBaseSet->m_regionInRule.m_packed_msk, sizeof(reginfo.m_packed_msk));
			  }
			  region->SetRule(&reginfo);
			  m_myrulestatic.SetCurRule(region);
   	          break;

		  }
	  case REGIONOUTRULE:
		  {
			  CRegionRule* region = new CRegionRule(1);
			  VSNETVAREGIONERULE reginfo;
			  memset(&reginfo, 0, sizeof(VSNETVAREGIONERULE));
			  reginfo.m_region_valid = 1;
			  if (! operatestate)
			  {
				  region->GetRuleFromRgn((UINT*)&reginfo.m_packed_msk);
			  }
			  else if (operatestate == 3 && temp.ruletype)
			  {
                  memcpy(reginfo.m_packed_msk, g_dlgSmartBaseSet->m_regionOutRule.m_packed_msk, sizeof(reginfo.m_packed_msk));
			  }
			  region->SetRule(& reginfo);
			  m_myrulestatic.SetCurRule(region);
   	          break;
		  }
	  case REGIONHOVERRULE:
		  {
			  CRegionRule* region = new CRegionRule(2);
			  VSNETVAREGIONERULE reginfo;
			  memset(&reginfo, 0, sizeof(VSNETVAREGIONERULE));
			  reginfo.m_region_valid = 1;
			  if (! operatestate)
			  {
                  region->GetRuleFromRgn((UINT*)&reginfo.m_packed_msk);
			  }
			  else if (operatestate == 3 && temp.ruletype)
			  {
                   memcpy(reginfo.m_packed_msk, g_dlgSmartBaseSet->m_regionHoverRule.m_packed_msk, sizeof(reginfo.m_packed_msk));	  
			  }
			  region->SetRule(&reginfo);
			  m_myrulestatic.SetCurRule(region);
   	          break;
		  }
	  default:
		  break;
   }
}

void CDlgWizardSecond::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
 	// TODO: Add your message handler code here
	// Do not call CDialog::OnPaint() for painting messages
}
void CDlgWizardSecond::OnCustomdrawSliderLineWidth(NMHDR* pNMHDR, LRESULT* pResult)
{
	m_myrulestatic.ChangeRegionLineWidth(m_hSliderLineWidth.GetPos());	
	*pResult = 0;
}

void CDlgWizardSecond::OnOK() 
{
	// TODO: Add extra validation here
	g_dlgSmartBaseSet->SetBtnState(TRUE);
	//CDialog::OnOK();
}

void CDlgWizardSecond::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	//CDialog::OnCancel();
}

void CDlgWizardSecond::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	if (bShow && nStatus == 0)
    {
        //当调用ShowWindow(SW_SHOW)时，需判断规则类型是否发生了改变
        if (m_first->m_rule != m_ruleType)
        {
            //清除之前设置的规则
            if (m_ruleType != -1)
            {
                CleanRules();
            }

            //更新规则类型
            m_ruleType = m_first->m_rule;

            //重新根据规则类型设置GUI状态
            SetGUIStateByRuleType();

            //重新启动播放
            PostMessage(WM_COMMAND,MAKEWPARAM(IDC_BTN_PLAY,BN_CLICKED),0);
        }
    }
}

void CDlgWizardSecond::SetGUIStateByRuleType()
{   
    //取消之前按下按钮的选中状态
    if (m_prevItemID != 0)
    {
        SETITEMSTATE(m_prevItemID,FALSE);
    }

    if (m_ruleType == 0)
    {
        //规则类型为警戒跨越线
        GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT)->ShowWindow(SW_SHOW);
        GetDlgItem(IDC_BTN_SINGLE_DRC_RIGHT)->ShowWindow(SW_SHOW);
        GetDlgItem(IDC_BTN_SINGLE_DRC_DOUBLE)->ShowWindow(SW_SHOW);
        ((CButton*)GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT))->SetCheck(1);
        m_prevItemID = IDC_BTN_SINGLE_DRC_LEFT;
        GetDlgItem(IDC_BTN_REGION_RECT)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_BTN_REGION_PENCIL)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_BTN_REGION_LINE)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_BTN_REGION_ERASE)->ShowWindow(SW_HIDE);
        GetDlgItem(IDC_BTN_REGION_CLEANALL)->ShowWindow(SW_HIDE);
    }
	else
	{
       //其他类型规则
	   GetDlgItem(IDC_BTN_SINGLE_DRC_SELECT)->EnableWindow(FALSE);
	   GetDlgItem(IDC_BTN_SINGLE_DRC_LEFT)->ShowWindow(SW_HIDE);
       GetDlgItem(IDC_BTN_SINGLE_DRC_RIGHT)->ShowWindow(SW_HIDE);
	   GetDlgItem(IDC_BTN_SINGLE_DRC_DOUBLE)->ShowWindow(SW_HIDE);
	   GetDlgItem(IDC_BTN_REGION_RECT)->ShowWindow(SW_SHOW);
	   GetDlgItem(IDC_BTN_REGION_PENCIL)->ShowWindow(SW_SHOW);
	   GetDlgItem(IDC_BTN_REGION_LINE)->ShowWindow(SW_SHOW);
	   GetDlgItem(IDC_BTN_REGION_ERASE)->ShowWindow(SW_SHOW);
	   GetDlgItem(IDC_BTN_REGION_CLEANALL)->ShowWindow(SW_SHOW);
	}

    //规则类型为徘徊
    GetDlgItem(IDC_STATIC_ROAM)->ShowWindow(m_ruleType == 3);
    GetDlgItem(IDC_STATIC_ROAMSET)->ShowWindow(m_ruleType == 3);
	GetDlgItem(IDC_STATIC_ROAMSET1)->ShowWindow(m_ruleType == 3);
	GetDlgItem(IDC_EDIT_INFINITETIME)->ShowWindow(m_ruleType == 3);

    if (m_ruleType == 3)
    {
		m_hovertime = g_dlgSmartBaseSet->m_regionHoverRule.m_hovertime;
        UpdateData(FALSE);
    }
}

void CDlgWizardSecond::CleanRules()
{
    m_myrulestatic.CleanRules();
    m_myrulestatic.InitValue();
}

void CDlgWizardSecond::OnMove(int x, int y) 
{
	CDialog::OnMove(x, y);
	
	// TODO: Add your message handler code here
//	CRect rect;
//	GetWindowRect(&rect);
   // g_dlgSmartBaseSet->m_prodlgpos = rect;
}
