#pragma once

#include "gauge.h"
#include <cali\AreaCal.h>
#include <cali\CurveCal.h>
 

#define CD_MAX_CIRCLE_COUNT 2


class GAUGE_API CCircleDetect :	public CAreaCal
{
public:
	CCircleDetect(void);
	virtual ~CCircleDetect(void);

	virtual void Show(CDelegate* pDelegate, int mode,BOOL bForce);	 
	virtual CUCObj* Clone( CUCObj* twin) ;
	virtual BOOL Serialize(HANDLE device, BOOL bIn );
	 
	//virtual CDelegate* BindDelegate(CDelegate* pDelegate);

	virtual void Reset();
	virtual void Move(double dx, double dy) ;

	virtual void BeginAlign();
	virtual void Offset(double dx, double dy, int dir = RV_DIR_BOTH)  ;
	virtual void Unbias(double cx, double cy, double angle) ;
	virtual void EndAlign(BOOL bUpdate);
	//virtual void MoveEx(double dx, double dy, double cx, double cy, double angle) ;
	
	virtual BOOL  Create(/*CDelegate* pDelegate=NULL,*/ const TCHAR* strName = NULL, UINT id =-1, int style = RV_UC_DEFAULT_STYLE) ;
	virtual void  Destroy(/*BOOL bEraseStroke=FALSE*/) ;

	virtual void  SetShape(int shape); 
	virtual void  SetDisplayStyle(int style);
	virtual void  SetStyle(int style);
 
	virtual void    SetBodyColor(GRgb& val);

	virtual RV_BOOL Inspect(int* pErrCode=NULL) ;

	float  GetSampleGrain();
	void   SetSampleGrain(float angle);

	BOOL IsResultValid() { return m_bValidResult;}

	double      GetRadius(int index);
	RvPoint_f   GetCenter(int index);
	double      GetRatio(int index);
	int         GetCount(){ return m_nDetectedCount; };
	 

	CCurveCal* GetCurveCal(){ return &m_curveCal; };
	 
public:
	virtual void OnEndTrack(CDelegate* pDelegate, HGPD hCur,  GPoint point, int type)  ;

public:
	
	BOOL     m_bCheckRing;   //检测圆环
	//int      m_nSubPixelLevel; 
	float    m_nRatioThresh; //圆度阈值
	 

protected:
	//下面为临时变量
	int        m_nDetectedCount; //检测到的圆
	CD_RESULT*  m_pResultArray;
	BOOL       m_bValidResult;
	float     m_nSampleGrain;  

private:
	void LayoutCut();
	
	RV_HANDLE DrawMarks(HGDC dc, CD_RESULT*  pBoxArr, int arrSize, RV_HANDLE hStroke);

	CCurveCal m_curveCal;
	

};

