#pragma once


 


#include "ElemView.h"

#include <indx\mark.h>


#include "MarkLocater.h"
  
typedef void ( *MV_START_JOG_AXIS_FUNC)(void*, bool, int, int );
typedef void ( *MV_STOP_JOG_AXIS_FUNC)(void*);



//class CGlobalView;

//#define AV_EVENT_SELECT_UC       1
//#define AV_EVENT_SELCHANGE_UC   (1<<1)
//#define AV_EVENT_POSCHANGE_UC   (1<<2)
//#define AV_EVENT_SZECHANGE_UC   (1<<3)


//#define AV_EVENT_ALL         ( AV_EVENT_SELECT_UC | AV_EVENT_SELCHANGE_UC | AV_EVENT_POSCHANGE_UC | AV_EVENT_SZECHANGE_UC)



class  CNCCLS_API  CMobileView :	public CElemView
{
public:
	CMobileView(void);
	virtual ~CMobileView(void);
	
	//SUB MODE
	enum
	{
		SM_DEFAULT = 0 ,     //默认, 可以添加对象
		SM_ADD_CNCOBJ,       //添加CNC对象
		SM_MODIFY_CNCOBJ,    //修改CNC对象，位置和删除
		SM_LEARN_MARK  ,     //mark校正
		SM_MULTI_COPY,      //矩阵复制	
		_SM_RUMTIME     ,     //保留: 正在运行
		_SM_ALIGN_CNCOBJ  ,   //保留: 偏移矫正
		_SM_TRAY_OFFSET ,     //保留: 托盘偏移
		_SM_SIMULATE,         //保留: 观察运行		
	};
	 
	virtual BOOL Create(HWND hParentWnd, const char* strWindowName, int sightWidth, int sightHeight, GRect& rect);
	virtual void Destroy();

	//virtual void SetDesignMode(CDelegate::DESIGN_MODE mode, BOOL bRefresh =FALSE) ;
	virtual void SetAddinType(int type, BOOL bRefresh);

	virtual void Refresh(REFRESH_TYPE type);

	//void SetLocater(CMarkLocater*  pLocater, BOOL bRefresh);
	//CMarkLocater* GetLocater();

	void SetFlexMarkOuterSize(int cx, int cy, BOOL bRefresh);
	RvSize  GetFlexMarkOuterSize( );

	void SetFlexMarkInnerSize(int cx, int cy, BOOL bRefresh);
	
	void SetFlexMarkPos(int x, int y, BOOL bRefresh=TRUE);
	void GetFlexMarkPos(int &x, int &y);

	void SetSubMode(int mode,BOOL bRefresh =FALSE);
	int  GetSubMode(){ return m_nSubMode; };
 
	void SetCrossApperance(GRgb color, int thick);

	void SetFlexMarkApperance(GRgb color, int thick);

	//CNC添加模式时用
	BOOL IsInAddition();
	BOOL IsTracePosEnough();
	BOOL AddNewTracePos(RvPoint_f64 pos, BOOL bRefresh);
	int  GetTracePosCount();
	RvPoint_f64* GetMachPosArray(){ return m_arrMacPos; };
	void  ClearAllTracePos(BOOL bRefresh);

	//更新相机控制点坐标，即图像坐标
	void UpdateCamTracePos(RvPoint_f64 curPos, BOOL bRefresh);

	BOOL  IsAxisMovinig(){
	    return m_bAxisMoving;
	}

	int RevokeAddition(BOOL bRefresh);

	void EnableResizeMark(BOOL flag, BOOL bRefresh);
	BOOL IsMarkResizable();

public:
	//CRobot*    m_pRobot;
	//WORD       m_nAxisX;
	//WORD       m_nAxisY;
	CRobotSpaceMapE1* m_pRobotMap ;
	 
	void*  m_pUserData;
	MV_START_JOG_AXIS_FUNC m_pfnStartJogAxis;
	MV_START_JOG_AXIS_FUNC m_pfnChangeJogAxis;
	MV_STOP_JOG_AXIS_FUNC  m_pfnStopJogAxis;

protected:
	RvImage m_image;
	BOOL    m_bOpened;
	CMark   m_flexMark;
	int     m_nSubMode;

	//CMarkLocater* _m_pMarkLocater; //去掉没有用，目前仅为了兼容
	//CLabel m_lblTips;
	//CLabel m_lblUndo;
	//CLabel m_lblReset;	

public:
	virtual BOOL EventProc(RV_HANDLE hObj, UINT uEvent, WPARAM wParam, LPARAM lParam);
	virtual BOOL MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);
	
protected:
	
	BOOL HandleMatrixCopyMsg( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);
	BOOL HandleDefaultMsg( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);
	BOOL HandleModifyMsg( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);
	//BOOL HandleLearnMarkMsg( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam , LRESULT* pResult);

	BOOL TryTraceNextPos();

	void UpdateTipsbar(BOOL bRefresh);

private:
	void DrawFlexMark(HGDC dc,   BOOL bForce);
	void DrawTrace(HGDC dc,   BOOL bForce);
	void DrawAddinLabels(HGDC dc,   BOOL bForce);
	//void DrawMarkLocater(HGDC dc,   BOOL bForce);
	 
		
	BOOL  m_bResizeMark;  
	BOOL  m_bAxisMoving;

	RvPoint_f64 m_arrMacPos[MAX_VERTEX_COUNT];

	 
};

