#ifndef __GRAPHWAVE_H_
#define __GRAPHWAVE_H_

#define  GRAPH_DOT_CIRCLE     0
#define  GRAPH_DOT_RECTANGLE  1
#define  GRAPH_DOT_ANGLE45    2
#define  GRAPH_DOT_ANGLE90    3
#define  GRAPH_DOT_DOT        4
#define  GRAPH_DOT_COORDINATE 5

#define TORQUEGRAPH_RANK_MAX   20

#define TORQUEGRAPH_CHANNEL_COUNT   6

#define TORQUEGRAPH_NULL                     0
#define TORQUEGRAPH_LINEFITTING              1
#define TORQUEGRAPH_CURVEFITTING             2
#define TORQUEGRAPH_PIECELINEINTERPOLATOIN   3
#define TORQUEGRAPH_POLYNOMIALINTERPOLATOIN  4
#define TORQUEGRAPH_SPLINE                   5


class  CGraphWave
{
protected://rivate:

	RECT  m_Rect;
	RECT  m_WaveRect;
	char  m_strCaption[40];
	char  m_strUnitV[20];
	char  m_strUnitH[20];


	float m_fsRangeX[2];
	float m_fsRangeY[2];

	int   m_nGraphForeColor;
	int   m_nGraphBackColor;
	int   m_nGraphLineColor;
	int   m_nTextColorX;
	int   m_nTextColorY;

private:

	BOOL  m_bGrid;
	int   m_nInternalX;
	int   m_nInternalY;

	int   m_nInternalBeiX;
	int   m_nInternalBeiY;

	BOOL  m_bLimitX;
	float m_fsRangeLimitX[2];


	BOOL  m_bVertMark;
	BOOL  m_bHorzMark;

	//float m_fStartX;
	//float m_fInternalX;
	long  m_lgWaveCount;
	int   m_nDotX;
	int   m_nDotY;
	float m_fBeiY;
	float m_fBeiX;
private:
	int   m_nSkipData;
public:
	void  SetSkipData(int nData);
	int   GetSkipData(int nData) {return(m_nSkipData);}
public:
	void  SetRect(RECT* pRc);
	void  SetRect(int nLeft,int nTop,int nRight,int nBottom);
	void  SetRectEx(int nX,int nY,int nWidth,int nHeight);
	void  ModifyCoordinate();
public:
	void  SetRangeX(float fLow,float fHigh);
	void  GetRangeX(float* pfLow,float* pfHigh){*pfLow = m_fsRangeX[0];*pfHigh = m_fsRangeX[1];}

	void  SetRangeY(float fLow,float fHigh);
	void  GetRangeY(float* pfLow,float* pfHigh){*pfLow = m_fsRangeY[0];*pfHigh = m_fsRangeY[1];}

	void  SetLimitRangeX(BOOL bLimit, float fMin, float fMax)
	{
		m_bLimitX = bLimit;
		m_fsRangeLimitX[0] = fMin;
		m_fsRangeLimitX[1] = fMax;
	}

	//void  SetLimits(float fLow,float fHigh);
	//void  GetLimits(float* pfLow,float* pfHigh);
	void  SetGrid(int bGrid){m_bGrid = bGrid;}
	BOOL  GetGrid(){return(m_bGrid);}
	//void  SetInternalX(float fInternalX){m_fInternalX = fInternalX;}
	//BOOL  GetInternalX(){return(m_fInternalX);}

	void  SetUnitH(char *pStr){_fstrcpy(m_strUnitH,pStr);}
	void  SetUnitV(char *pStr){_fstrcpy(m_strUnitV,pStr);}
	char* GetUnitH(){return(m_strUnitH);}
	char* GetUnitV(){return(m_strUnitV);}

	void  SetCaption(char *pStrCaption);

	RECT* GetRect(){return(&m_Rect);};
    RECT* GetWaveRect(){return(&m_WaveRect);}

	RECT  GetDataRect();
public:
	void  SetGraphForeColor(int nColor) {m_nGraphForeColor = nColor;}
	void  SetGraphBackColor(int nColor) {m_nGraphBackColor = nColor;}
	void  SetGraphLineColor(int nColor) {m_nGraphLineColor = nColor;}
	void  SetTextColor(int nColor){m_nTextColorX = m_nTextColorY = nColor;}
	void  SetTextColorX(int nColor){m_nTextColorX = nColor;}
	void  SetTextColorY(int nColor){m_nTextColorY = nColor;}

	int   GetGraphForeColor() {return(m_nGraphForeColor);}
	int   GetGraphBackColor() {return(m_nGraphBackColor);}
	int   GetGraphLineColor() {return(m_nGraphLineColor);}
	int   GetTextColorX(){return(m_nTextColorX);}
	int   GetTextColorY(){return(m_nTextColorY);}
	int   GetTextColor(){return(m_nTextColorX);}
	void  SetBeiY(float fBeiY){m_fBeiY = fBeiY;}
	void  SetBeiX(float fBeiX){m_fBeiX = fBeiX;}

	float GetCoordinateXY(float fX1,float fY1,float fX2,float fY2,float fX);

	//void  DisplayDeltaXY(int nWidth, int nHeight);
	void  ShowGrid();
	void  ShowFrame(BOOL bFrame = TRUE, BOOL bGraph = TRUE);

	void  KernelDrawWave(int nDataStyle, BYTE* pbyData,int nCount,int nMode,int nColor);

	void  DrawWave(float*pfData,int nCount,int nMode,int nColor);
	void  DrawWave(WORD *pwData,int nCount,int nMode,int nColor);
	//void  DrawLineX(float fData, int nCount, int nMode, int nColor);
	//void  DrawLineY(float fData, int nCount, int nMode, int nColor);
	//void  DrawLineKB(float fK, float fB, float fStartX, float fEndX, int nMode, int nColor);

	//void  DrawWave(CXmsMemory *pXmsMemory, long lgStart, long lgCount,int nMode,int nColor);
public:
	void  SetHorzMark(BOOL bMark){m_bHorzMark = bMark;}
	void  SetVertMark(BOOL bMark){m_bVertMark = bMark;}
public:
	//void   SetStartX(float fX) {m_fStartX = fX;}
	//float  GetStartX(){return(m_fStartX);}
	void   SetWaveCount(long lgCount){m_lgWaveCount = lgCount;}
	long   GetWaveCount(){return(m_lgWaveCount);}
	void   SetInternalCountX(int nCount){m_nInternalX = nCount;}
	int    GetInternalCountX(){return(m_nInternalX);}
	void   SetInternalCountY(int nCount){m_nInternalY = nCount;}
	int    GetInternalCountY(){return(m_nInternalY);}

	void   SetInternalCountBeiX(int nCount){m_nInternalBeiX = nCount;}
	void   SetInternalCountBeiY(int nCount){m_nInternalBeiY = nCount;}

public:
	void   SetDotX(int nDot){m_nDotX = nDot;}
	void   SetDotY(int nDot){m_nDotY = nDot;}
	int    GetDotX(){return(m_nDotX);}
	int    GetDotY(){return(m_nDotY);}
public:
	void   DisplayHAndV(BOOL bCaption=TRUE);

	void   DrawLineH(float fY, int nColor);
	void   DrawLineV(float fX, int nColor);

	void   DrawDot(float fX, float fY, int nHalfSize, int nColor, int nStyle);
    //void   CalcXY(int nScreenX, int nScreenY, float* pfX, float* pfY);
    //void   CalcXY2(float fX, float fY, int* pnScreenX, int* pnScreenY);

	//void   NewMoveTo(float fX, float fY);
	//void   NewLineTo(float fX, float fY);

	void SetGraphSub_Float(float fDC);
	void SetGraphSub_Word(WORD wDC);

public:
	CGraphWave();
	~CGraphWave();
};



struct TOQUEGRAPH_ATTRIB
{
    int nStyle;
    int nRank;
    double dbR;
    double dbsA[1 + TORQUEGRAPH_RANK_MAX];
    void* pUser;
};

class CTorqueGraph:public CGraphWave
{
private:
	TOQUEGRAPH_ATTRIB m_TorquegraphAttrib;
	int   m_nChannels;
	float m_fsChannelY[TORQUEGRAPH_CHANNEL_COUNT][2];
	char  m_strChannelCaption[TORQUEGRAPH_CHANNEL_COUNT][40];
	int   m_nsChannelTextColor[TORQUEGRAPH_CHANNEL_COUNT];
	float m_fsChannelBeiY[TORQUEGRAPH_CHANNEL_COUNT];

public:
       void  SetTorquegraphAttribUser(void* pUser) {m_TorquegraphAttrib.pUser = pUser;}
       void* GetTorquegraphAttribUser() {return (m_TorquegraphAttrib.pUser);}
public:
       void SetChannelBeiY(int nChannel, float fBeiY);
       void  SetChannelTextColor(int nChannel, int nColor);
       void  SetChannelCount(int nCount);
       void  SetChannelY(int nChannel, float fMin, float fMaxY, int nTextColor = BLACK);
       void  GetChannelY(int nChannel, float* pfMin, float* pfMax)
	   {
	*pfMin = m_fsChannelY[nChannel][0];
	*pfMax = m_fsChannelY[nChannel][1];
	   }
	   void  SetChannelCaption(int nChannel , char* pStrCaption);
	   char* GetChannelCaption(int nChannel, char* buf)
	   {
			::_fstrcpy(buf, m_strChannelCaption[nChannel]);
			return(buf);
	   }
       RECT  InitChannelWave(int nChannel);
public:
       void  ShowGridEx();
       void  ShowFrameEx(BOOL bFrame = TRUE, BOOL bGraph = TRUE);

public:
       TOQUEGRAPH_ATTRIB* GetTorquegraphAttrib()
       {
		return (&m_TorquegraphAttrib);
       }
       void  SetTorquegraphAttrib(int nStyle, int nRank);
	   void  DrawDot(int nChannel, float fDataX, float fDataY, int nHalfSize, int nColor, int nStyle);
	void   DrawLineH(int nChannel, float fY, int nColor);
	void   DrawLineV(int nChannel, float fX, int nColor);

	   //void  CalcXY(int nChannel, int nScreenX, int nScreenY, float* pfX, float* pfY);
       //void  CalcXY2(int nChannel, float fX, float fY, int* pnScreenX, int* pnScreenY);

		//void   NewMoveTo(int nChannel, float fX, float fY);
		//void   NewLineTo(int nChannel, float fX, float fY);

	//void  DrawLineX(int nChannel, float fData, int nCount, int nMode, int nColor);
	//void  DrawLineY(int nChannel, float fData, int nCount, int nMode, int nColor);
	//void  DrawLineKB(int nChannel, float fK, float fB, float fStartX, float fEndX, int nMode, int nColor);

	   void  DrawWave(float*pfData,int nCount,int nMode,int nColor)
       {
			CGraphWave::DrawWave(pfData, nCount ,nMode, nColor);
       }

	   void  DrawWave(WORD *pwData,int nCount,int nMode,int nColor)
       {
			CGraphWave::DrawWave(pwData, nCount ,nMode, nColor);
       }

	   void  DrawWave(int nChannel, float* pfDataX, float* pfDataY, int nCount,int nMode,int nColor, BOOL bDraw = TRUE);
	   void  DrawWave(int nChannel, float*pfData,int nCount,int nMode,int nColor);
	   void  DrawWave(int nChannel, WORD *pwData,int nCount,int nMode,int nColor);

	   void  DrawWaveSub(int nChannel, float*pfData,int nCount,float fDC, int nMode,int nColor);
	   void  DrawWaveSub(int nChannel, WORD *pwData,int nCount,WORD  wDC, int nMode,int nColor);


	   void  ShowFrame(BOOL bAll = TRUE);

	   void   DisplayHAndV(BOOL bCaption=TRUE);
public:
    CTorqueGraph();
    ~CTorqueGraph();
};

void FAR AfxDebugGraphWave(WORD* pwWave,  int nCount);
void FAR AfxDebugGraphWave(WORD* pwWave, int nCount,
	WORD* pwWave2, int nCount2);
void FAR AfxDebugGraphWave(float* pfWave, int nCount, float fBei);
void FAR AfxDebugGraphWave(float* pfWave1, int nCount1, float fBei1,
	float* pfWave2, int nCount2, float fBei2 = 1.0f);

double      GetZhengTai_Right(double dbK);


void SetDebugGraphWaveLen(int nLen);
int GetDebugGraphWaveLen();

#endif