#pragma once

#include "cncobj.h"

#define CSU_VERTEX_COUNT   4


class CNCCLS_API CCutShapeU: public CCncObj
{
public:
	CCutShapeU(void);
	virtual ~CCutShapeU(void);
	 
	//@1相机坐标
	void       SetVertexPos(int index, RvPoint_f  pos);
	RvPoint_f  GetVertexPos(int index);
	//RvPoint  GetCounterCamPos(int index);
	//End of @1

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

	RvPoint_f64  GetArcMacCenter();

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

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

 
	//将第3点规范成垂直距离点
	static RvPoint_f  CalcPoint3(RvPoint_f p1, RvPoint_f p2, RvPoint_f outer);
	static RvPoint_f64  CalcPoint3(RvPoint_f64 p1, RvPoint_f64 p2, RvPoint_f64 outer);
	//第3点已经是垂直距离点
	static RvPoint_f  CalcPoint4(RvPoint_f p1, RvPoint_f p2, RvPoint_f p3);
	static RvPoint_f64  CalcPoint4(RvPoint_f64 p1, RvPoint_f64 p2, RvPoint_f64 p3);
	 
public:
	virtual void Show(CDelegate* pDelegate, int mode,BOOL bForce);


	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:


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

	BOOL CheckArc(CDelegate* pDelegate, GPoint&  center, int  radius, double startAngle, double endAngle, GPoint& _hit );

	BOOL CalcArcCenter(RvPoint_f64&p1,RvPoint_f64&p2,RvPoint_f64&p3, RvPoint_f64* pCenter);
	
	double CalcAngle(double x0, double y0, double x1, double y1 );
	RV_HANDLE DrawShapeUPath(HGDC dc,  const RvPoint_f* pVertArr, int nVertCount, float offset, RV_HANDLE hStroke);

	void UpdateRect();
private:
	typedef struct _cut_shape_u_graphic_descriptor{
		GPoint p0,p1,p2 ,p3   ;   
	}GdCutShapeU;

	RvPoint_f   m_vertexes[CSU_VERTEX_COUNT ];  //图像坐标
	RvPoint_f64 m_cps[CSU_VERTEX_COUNT ];       //机械坐标

};

