#if !defined(AFX_RULESBACKGROUNDSTATIC_H__5D850AED_4896_4CA1_B96E_FEE219605892__INCLUDED_)
#define AFX_RULESBACKGROUNDSTATIC_H__5D850AED_4896_4CA1_B96E_FEE219605892__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// RulesBackgroundStatic.h : header file
//

#include "Rule.h"

#define   SINGLELINE_RULE_MAXCOUNT          10
#define   DOUBLELINE_RULE_MAXCOUNT          10
#define   MULTILINE_RULE_MAXCOUNT           1
#define   REGION_RULE_MAXCOUNT              1
#define   REGION_RULE_MAXTYPE               3

#define   REGION_POLYGON_MAXCOUNT           100

typedef enum
{
    EDITRULE_ACTION_NONE = 0,
    EDITRULE_ACTION_MOVE,
    EDITRULE_ACTION_MOVEING,
    EDITRULE_ACTION_HOTPOINT,
    EDITRULE_ACTION_PENCIL,
    EDITRULE_ACTION_PENCILING,
    EDITRULE_ACTION_ERASE,
    EDITRULE_ACTION_ERASEING,
    EDITRULE_ACTION_REGION_RECT,
    EDITRULE_ACTION_REGION_RECTING,
    EDITRULE_ACTION_REGION_FILL,
    EDITRULE_ACTION_REGION_POLYGON,
    EDITRULE_ACTION_REGION_POLYGONING,
    EDITRULE_ACTION_REGION_POLYGONOVER,
    EDITRULE_ACTION_OBJECT_MIN_AREA,
    EDITRULE_ACTION_OBJECT_MIN_AREAING,
    EDITRULE_ACTION_OBJECT_MAX_AREA,
    EDITRULE_ACTION_OBJECT_MAX_AREAING,
};

typedef enum
{
    NEWRULE_TYPE_SINGLELINE = 0,
    NEWRULE_TYPE_MULTISEGMENT,
    NEWRULE_TYPE_REGION,
};

/////////////////////////////////////////////////////////////////////////////
// CMyRulesStatic window

class CMyRulesStatic : public CStatic
{
// Construction
public:
	CMyRulesStatic();

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CMyRulesStatic)
	public:
	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
	protected:
	virtual void PreSubclassWindow();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CMyRulesStatic();

	// Generated message map functions
public:  
	BOOL        m_polylinefinish;
	CPoint      m_point;
    CRect       m_rect;                 
protected:  
	BOOL        ConnectChannel();
	BOOL        Replay();
	CMyRule*      AddRegionRule(int regionDrc,char *ruleName = NULL);
	CMyRule*      AddDoubleLineRule(CDoubleLineRule* pCopySrCMyRule = NULL,char *ruleName = NULL);
	CMyRule*      AddSingleLineRule(BOOL bMultiSegment,CSingleLineRule* pCopySrCMyRule = NULL,char *ruleName = NULL);

protected:
    CString     m_szDevname;                    /*设备名称      */
    CString     m_szUrl;                        /*设备IP地址    */
    UINT        m_port;                         /*设备端口      */
    UINT        m_ch;                           /*设备通道      */
    CString     m_szUsername;                   /*访问设备用户名*/
    CString     m_szPassword;                   /*访问设备密码  */
    LONG        m_hChan;                        /*通道句柄      */
	BOOL        m_bLinkOK;                      /*连接状态      */
    BOOL        m_bPause; 
	CMutex      m_hMutexSet;
protected:
    CRect       m_region_tmp_rect;
    POINT       m_region_tmp_polygon_point[REGION_POLYGON_MAXCOUNT];
    int         m_region_tmp_count;
    BOOL        m_bRegionRectValid;
public:
    CPen        m_pen_normal_line;
    CPen        m_pen_object_area;
    CBrush      m_brush_rule_region;
    CBrush      m_brush_msk_region;

    HCURSOR     m_hCursorArrow;
    HCURSOR     m_hCursorMove;
    HCURSOR     m_hCursorCross;
    HCURSOR     m_hCursorPencil;
    HCURSOR     m_hCursorErase;
    HCURSOR     m_hCursorFill;

    HBITMAP	    m_hBmpTargent;

protected:
    CPtrList    m_rulesList;                    /*规则链表 */

    CRect       m_object_min_area;              
    CRect       m_object_max_area;

    CRegionRule m_rule_shield_msk;

public:
    VSNETVABACKGROUND       m_vabackground;
    VSNETVAOBJECTAREA       m_vaobjectarea;
    VSNETVAALARMSETTING     m_vaalarmsettings;
	CMyRule*                m_pSelectRule;
protected:
    BOOL        m_bEnableEdit;
    int         m_editActionType;
    int         m_lineWidth;
	int         m_multilinecount;
    BOOL        m_bEditShieldMsk;
public:
	void EnableEdit(BOOL bEnable);
	void InitValue();
	void        Stop();
	BOOL        Pause();
	BOOL        Play();
	void        SetCameraLinkParam(LPCTSTR pDevname,LPCTSTR pUrl,UINT ch,UINT port,LPCTSTR pUsername,LPCTSTR pPsw);
	void        OnNetClientMsg(WPARAM wParam,LPARAM lParam);

	void        EditShieldMskRegion(BOOL bEditShieldMsk);
	void        DrawRegion(CDC* pDC, CRgn *pRgn, CBrush *pBkBrush, COLORREF bkColor);
	int         GetLineWidth();
	void        DrawRegionRule(CDC* pDC);
	int         ChangeRegionLineWidth(int index);
	BOOL        PtInPolygon(CPoint point);
	void        AddRegionPolyPoint(CPoint point);
	void        RegionCleanAll();
	void        SetEditActionType(int editAction);
	int         GetRegionRuleCount(int regionDrc);
	void        RefreshWindow(LPCRECT lpRect = NULL);
	CMyRule*    GetRuleByIndex(int index);
	BOOL        CopyRule(int index,int curcount = 0);
	void        SetCurSelRuleByIndex(int index);
	int         GetSingleLineRuleCount();
	int         GetMultiLineRuleCount();
	int         GetRulesCount();    
	void        LoadVAParam(int &iRet1, int &iRet2, int &iRet3);   
	BOOL        SaveVAParam(BOOL bSet = TRUE);
	BOOL        LoadRulesSettings();    
	BOOL        SaveRuelsSettings();
	BOOL        AddNextMultiSegment(CSingleLineRule* pSingleRule);
	void        OnKeyControl(int nVirtKey, BOOL bKeyDown);
	BOOL        DeleteRuleByIndex(int index);
	BOOL        SetSingleLineRuleDrc(int direction);
	BOOL        EnableRuleMove(BOOL bEnable);
	void        CleanRules();
	void        DrawRules(HDC hDC);
	BOOL        AddNewRule(int ruleType,char *ruleName = NULL);
	void        DrawArea(CPoint begin);//,UINT nFlags);
    void        SetCurRule(CMyRule* curRule);
	LONG		MessageOpen();
	int			MessageOpt(LONG handle,int opt,void* param1 = NULL,void* param2 = NULL,void*param3 = NULL);
	BOOL		MessageClose(LONG handle);
	//{{AFX_MSG(CMyRulesStatic)
	afx_msg void OnPaint();
	afx_msg void OnLButtonDblClk(UINT nFlags,CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnRButtonDown(UINT nFlags,CPoint point);
    afx_msg void OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    afx_msg void OnTimer(UINT nIDEvent);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_RULESBACKGROUNDSTATIC_H__5D850AED_4896_4CA1_B96E_FEE219605892__INCLUDED_)
