/*-----------------------------------------------------------------------*/
/*   FS-MTS  1.0  Ver.                                                   */
/*   Copyright (C) 2000 FIRST SAIL                                       */
/*   All Rights Reserved                                                 */
/*   Warning:                                                            */
/*       This program author is GuoHeng,this system is protected         */
/*   by copyright law and international Treaties . Unauthorized          */
/*   reproduction of  distribution of this  system, or any portion       */
/*   of it , may result in severe civil and criminal penalties ,         */
/*   and will be prosecuted to the maximum extern possible under         */
/*   the law.                                                            */
/*                                                                       */
/*   Update Date:2002-06-25                                              */
/*   Update Time:22:35:00                                                */
/*-----------------------------------------------------------------------*/

#ifndef _SPC_H_
#define _SPC_H_

#include <Print.h>

#define MIN_SPC_SAMPLES  2
#define MAX_SPC_SAMPLES  25


#define SPC_STYLE_NULL 0
#define SPC_STYLE_X    1
#define SPC_STYLE_R    2
#define MAX_SPC_SAMPLE    25
#define SpcErr            9999.99f
#define SPC_CONTROL_XR1   0
#define SPC_CONTROL_XS1   1
#define SPC_CONTROL_XR2   2
#define SPC_CONTROL_XS2   3

#define MAX_STATICGRAPHICPIE_DATA_COUNT  512
class  CSpc
{
private:
//	static  BOOL  m_bDot;
private:
	DWORD m_dwXmsLocation;
public:
	int   m_nSpcControlStyle;
private:
	int   m_nLeft;
	int   m_nTop;
	int   m_nWidth;
	int   m_nHeight;
private:
	int   m_nBackColor;
	int   m_nTextColor;
	int   m_nLimitColor;
	int   m_nAlertColor;
	int   m_nBarColor;
	int   m_nWaveColor;
	int   m_nLampNormalColor;
	int   m_nLampAlertColor;
private:
	float m_fLimitHigh;
	float m_fLimitLow;
	float m_fAverageX;
	float m_fAverageR;
	int   m_nSampling;
	int   m_nControl;
	int   m_nStyle;
	int   m_nID;
	int   m_nClearCount;
	BOOL  m_bClear;
	char  m_strName[GRID_CHARACTER_MAX];
	char  m_strUnit[UNIT_CHARACTER_MAX];
private:
	int    m_nFail;
	BOOL   m_bPass;
private:
	BOOL   m_bCompact;
	BOOL   m_bDisplayWave;
	int    m_nMaxWaveCount;
	int    m_nWaveCount;
	float  m_fScaleY;
	int    m_nMoveStyle;
private:
	float  m_fTorlanceX;
	float  m_fTorlanceR;
	float  m_fTorlanceCount;
public:
	void   SetXmsLocation(DWORD dwValue){m_dwXmsLocation=dwValue;}
	DWORD  GetXmsLocation(){return(m_dwXmsLocation);}
        CXmsMemory* GetXmsMemory();
	static BOOL  LoadXms(DWORD dwByte);
	static BOOL  FreeXms();
public:
	void  SetLeft(int nValue){m_nLeft=nValue;}
	void  SetTop(int nValue){m_nTop=nValue;}
	void  SetWidth(int nValue){m_nWidth=nValue;}
	void  SetHeight(int nValue){m_nHeight=nValue;}
	void  SetCoordinateAttrib(int nValue1,int nValue2,int nValue3,int nValue4){m_nLeft=nValue1,m_nTop=nValue2,m_nWidth=nValue3,m_nHeight=nValue4;}
	int   GetLeft(){return(m_nLeft);}
	int   GetTop(){return(m_nTop);}
	int   GetWidth(){return(m_nWidth);}
	int   GetHeight(){return(m_nHeight);}
public:
	void  SetBackColor(int nColor){m_nBackColor=nColor;}
	void  SetTextColor(int nColor){m_nTextColor=nColor;}
	void  SetLimitColor(int nColor){m_nLimitColor=nColor;}
	void  SetAlertColor(int nColor){m_nAlertColor=nColor;}
	void  SetBarColor(int nColor){m_nBarColor=nColor;}
	void  SetWaveColor(int nColor){m_nWaveColor=nColor;}
	void  SetLampNormalColor(int nColor){m_nLampNormalColor=nColor;}
	void  SetLampAlertColor(int nColor){m_nLampAlertColor =nColor;}
public:
	void  SetLimitHigh(float fValue){m_fLimitHigh=fValue;}
	void  SetLimitLow(float fValue){m_fLimitLow  =fValue;}
	void  SetAverageX(float fValue){m_fAverageX=fValue;}
	void  SetAverageR(float fValue){m_fAverageR=fValue;}
	void  SetSampling(int nValue){m_nSampling=nValue;}
	void  SetControl(int nValue ){m_nControl =nValue;}
	void  SetStyle(int nValue){m_nStyle=nValue;}
	float GetLimitHigh(){return(m_fLimitHigh);}
	float GetLimitLow(){return(m_fLimitLow);}
	float GetAverageX(){return(m_fAverageX);};
	float GetAverageR(){return(m_fAverageR);};
	int   GetSampling(){return(m_nSampling);};
	int   GetControl(){return(m_nControl);};
	int   GetStyle(){return(m_nStyle);}
	void  SetID(int nValue){m_nID=nValue;}
	int   GetID(){return(m_nID);}
	void  SetName(char *pStr){_fstrcpy(m_strName,pStr);}
	char* GetName(){return(m_strName);}
	void  SetUnit(char *pStr){_fstrcpy(m_strUnit,pStr);}
	char* GetUnit(){return(m_strUnit);}
	BOOL  GetClearFlags(){return(m_bClear);}
	void  SetClearFlags(BOOL bClear){m_bClear=bClear;}
	int   GetClearCount(){return(m_nClearCount);};
	void  SetClearCount(int nValue){m_nClearCount=nValue;}
	int   GetFail(){return(m_nFail);}
	void  SetFail(int nValue){m_nFail=nValue;}
public:
	void  SetWaveCount(int nValue){m_nWaveCount=nValue;}
	void  SetMaxWaveCount(int nValue);
	int   GetWaveCount(){return(m_nWaveCount);}
	int   GetMaxWaveCount(){return(m_nMaxWaveCount);}
	float*GetWave();
	float GetDisplay(){return(m_bDisplayWave);}
	void  SetScaleY(float fValue){m_fScaleY=fValue;}
	float GetScaleY(){return(m_fScaleY);}
	void  SetMoveStyle(int nValue){m_nMoveStyle=nValue;}
	float GetMoveStyle(){return(m_nMoveStyle);}
	void  SetCompact(BOOL bValue){m_bCompact=bValue;}
	BOOL  GetCompact(){return(m_bCompact);}
	//BOOL  LoadWaveFromDataFile(int nTestItem,BOOL bRequery);
	//BOOL  LoadWaveFromSpcFile(int nTestItem ,int nModelIndex,BOOL bRequery);
	//BOOL  SaveWaveToSpcFile(int nTestItem ,int nModelIndex,BOOL bRequery);

	BOOL  GetPass();
	BOOL  MallocWave();
	BOOL  FreeWave();
	BOOL  AddWave(float fValue);
	BOOL  PrintWave();
	void  DrawLamp();
	void  DrawSpcWave();
	void  ShowBox(BOOL bAverage=FALSE);
	float GetAverage(int nIndex,int nCount);
	float GetDelta(int nIndex,int nCount);
	static float GetAverage(float *pfWave,int nCount);
	static float GetDelta(float *pfWave,int nCount);
	static BOOL  CaculateSpcAverage(float *pfData,int nCount,int nSample,float *pfAverage,float *pfTolerance);
	static BOOL  CaculateSpcTolerance(float *pfData,int nCount,int nSample,float *pfAverage,float *pfTolerance);
	static float GetLineCoordinateXY(float fX1,float fY1,float fX2,float fY2,float fValue);
	static void  DrawWave(int nX,int nY,int nWidth,int /*nHeight*/,float fScaleX,float fScaleY,WORD wFlags,WORD *pwWaveData,int nCount,BOOL bPurge,int nForeColor,int nBackColor=BLACK);
	static void  SetDot(BOOL bDot);// {m_bDot=bDot;}
public:
	void  ShowFrame();
	static BOOL  DrawWaveBox(int nX,int nY,int nWidth,int nHeight,int nColor,BOOL bFlags=FALSE,BOOL bDrawGrid=TRUE,BOOL bMiddleLine=TRUE);
public:
	void SetTorlanceX(float fTorlanceX){ m_fTorlanceX = fTorlanceX;}
	void SetTorlanceR(float fTorlanceR){ m_fTorlanceR = fTorlanceR;}
	void SetTorlanceCount(float fTorlanceCount){ m_fTorlanceCount = fTorlanceCount;}

	float GetTorlanceX(){return(m_fTorlanceX);}
	float GetTorlanceR(){return(m_fTorlanceR);}
	float GetTorlanceCount() { return(m_fTorlanceCount);}
public:
	CSpc();
	~CSpc();
};

typedef struct _tagSPC_HEAD
{
	WORD   wItemCount;
	WORD   wInternal;
}SPC_HEAD;


typedef struct tagSPC_FILE_HEAD
{
	int    nSampling;
	int    nMoveSpcStyle;
	int    nCompact;
	int    nXControl;
	int    nRControl;
	int    nReserval;
	float  fsAverage[MAX_TEST_ITEM_COUNT][2];
	float  fsTorlance[MAX_TEST_ITEM_COUNT][2];
	float  fTorlanceCount;
	int    nsCount[MAX_TEST_ITEM_COUNT];
}SPC_FILE_HEAD;

char*  SetDisplayBufferSpc(char *buf,float fValue);
void FAR SpcSetting();
BOOL FAR SpcPassword();
//1L*sizeof(float)*MAX_STATICGRAPHICPIE_DATA_COUNT
#endif