#pragma once

#include "cncobj.h"

#define  DEF_POLYLINE_VERTEX_COUNT    127

class CNCCLS_API CCutPolyline :	public CCncObj
{
public:
	CCutPolyline();
	virtual ~CCutPolyline(void);

	//@2 机械坐标
	virtual double GetMacLength();
//	virtual RvPoint_f64 GetStartMacPos() ; 
//	virtual RvPoint_f64 GetEndMacPos();
	virtual RvPoint_f64 GetReferMacPos();

	virtual int GetMacPosCount();
	virtual RvPoint_f64 GetMacPosAt(int index) ;
	virtual RvPoint_f64* GetMacPosArray() ;
	virtual void SetMacPosAt(int index, RvPoint_f64 pos) ;
	//virtual RvPoint GetCounterCamPos(int index);
	//end of @2

	virtual RvPoint_f  GetCamPosAt(int index) ;
	virtual void     SetCamPosAt(int index, RvPoint_f pos);

	virtual void UpdateCamPos();
	virtual void UpdateMacPos();
	 
	
	void   SetMacPosCount(int cnt);

public:
	
	//@1相机坐标
	void   SetVertexCount(int cnt); 
	int    GetVertexCount(){ return m_nVertexCount; };
	void   SetVertexPos(int index, RvPoint_f  pos);
	void   SetVertexArray(RvPoint_f* pArr, int count);

	RvPoint_f  GetVertexPos(int index);

	double  GetLength();

	//end of @1

public :
		BOOL  m_bClosed;
public:
	virtual void Show(CDelegate* pDelegate, int mode,BOOL bForce);

	//virtual void Move(double xOffset, double yOffset);

	virtual void  ShowExtender(CDelegate* pDelegate,CLeadMark* pMark);
	virtual void  ShowGrabber(CDelegate* pDelegate, CLeadMark* pMark);	
	virtual CUCObj* Clone( CUCObj* twin);

	virtual BOOL Serialize(HANDLE device, BOOL bIn );
	 
	virtual void Move(double dx, double dy) ;

	virtual void Scale(double scale);
    virtual void Scale(double scaleX, double scaleY);
    virtual void Rotate(double cx, double cy, double angle);



//for delegate use only
public:
	virtual int    HitTest(CDelegate* pDelegate,GPoint point) ; 
	//virtual GRect  GetGrabberRect(BOOL bActualSize) ;

	virtual GRect  GetExtenderRect(CDelegate* pDelegate,int index, RvSize size) ;
	virtual GRect  GetCurRect() ;

	virtual void ShowSketch(CDelegate* pDelegate, CSketchMark* pMark,  HGPD hGpd,  int grabType, GPoint grabPos)  ;

	virtual BOOL OnPositionChange( HGPD hOri, HGPD hCur, HGPD hNew, GPoint grabPos, RvOffset &offset) ;
	virtual BOOL OnExtenderChange( HGPD hCur, HGPD hNew, int index, GPoint &curPos) ;

	virtual void OnEndTrack(CDelegate* pDelegate,HGPD hCur,  GPoint point, int nHitTest) ;

	virtual void DestroyGraphicDescriptor(HGPD hGpd)  ;
	virtual HGPD CreateGraphicDescriptor(CDelegate* pDelegate) ;
	virtual void CopyGraphicDescriptor(const HGPD src, HGPD dest);

protected:

	void UpdateMachRect(void);
	void UpdateRect();

	RV_HANDLE DrawCutter(CDelegate* pDelegate,   float radius, RV_HANDLE hStroke);

	double CalcAngle(double x0, double y0, double x1, double y1 );
	RV_HANDLE DrawPolylinePath(HGDC dc,  const GPoint* pVertArr, int nVertCount, double offset, RV_HANDLE hStroke);

private:
	typedef struct _cut_polyline_graphic_descriptor{

		//GPoint p0,p1,p2; 
		GPoint* pt; 

	}GdCutPolyline;

	int    m_nVertexCount;

	RvPoint_f* m_pVerTexes;

	//机械坐标地址
	RvPoint_f64* m_cps;

};
