#ifndef CCASSETTE_H
#define CCASSETTE_H

#include "CChannel.h"
#include <QDateTime>
#define MAX_SLOT    25
enum SLOT_STATUS
{
	UNSCANED,
    NOWP,   //没有Wafer
	WPUNCUT,
	WPMALPOSED,	//错位
	WPOVERLAPPED,	//叠片
	SCANFAILED,
	TOGRAB,
	TOCOAT,
    WPCOAT,
    WPCOATFINISH,
	TOCUT,
    WPCUT,
    WPCUTFINISH,
	TOCLEAN,
    WPCLEAN,
    WPCLEANFINISH,
	TOUNLOAD,
    WPCUTTED,   //切割完毕
	WPABORT,
	WPCHECKING,
    WPCHECKED,
};

enum WPStatusExtern {
    kUNSCANED,
    kNOWP,   //没有Wafer
    kWPUNCUT,
    kWPMALPOSED,	//错位
    kWPOVERLAPPED,	//叠片
    kSCANFAILED,
    kTOGRAB,
    ToScaned,
    ToCoat,
    WaitCoat,
    CoatFinish,
    ToCheckCoat,
    WaitCheckCoat,
    CheckCoatFinish,
    ToCut,
    WaitCut,
    CutFinish,
    ToClean,
    WaitClean,
    CleanFinish,
    ToCheckCut,
    WaitCheckCut,
    CheckCutFinish,
    ToUnload,
    TaskFinished,
    Aborted,
};
enum SLOT_CHECK_STATUS
{
	NONEEDCHECK=0,			//不在检查中
	CHECKBEGIN,
	CHECKCOATING,		//检查涂覆中
	CHECKCOATFINISHED,
	CHECKCUTING,		//检查切割中
	CHECKCUTFINISHED
};
//Slot状态管理
typedef struct _tagCassSlot
{
    int32_t WPstatus; //Wafer的当前状态
    int32_t WpPosStatus;
	int index;			
    bool bEnableCut;        //是否需要进行加工
    bool bEnableCoat;       //启用涂覆
    bool bEnableClean;      //启用清洗
    bool bCutFinished;           //切割完成
    bool bCoatFinished;           //涂覆完成
    bool bCleanFinished;          //清洗完成
    bool bAbort;
	bool bCanAbort;
	SLOT_CHECK_STATUS CheckStatus;
	bool bNeedCheckCoat;	//需要检查涂覆
	bool bNeedCheckCut;		//需要检查切割
    bool bCheckCoatFinished;
    bool bCheckCutFinished;
	bool bIsFirst;			//是否首片 未使用，是否待加工的首片
    int nRecipeId;           //关联的RecipeID
    int nRecipeChildId;     //关联Recipe组中的子ID
    bool bProcessing;       //正在处理中
    bool bNeedRelocation;   //
    bool bHasWater;

	QString WaferID;
	QDateTime BeginDate;
	QDateTime EndDate;
    _tagCassSlot()
    {
        Reset();
        index=-1;
        bEnableCut=true;
		WaferID = "";
		bCanAbort = true;
        bIsFirst = false; 
        bCutFinished = false;
        bCoatFinished = false;
        bCleanFinished = false;
        bNeedCheckCut = false;
        bNeedCheckCoat = false;
        bCheckCoatFinished = false;
        bCheckCutFinished = false;
        bNeedRelocation = false;
        bHasWater = false;
    }
    void Reset()
    {
		CheckStatus = NONEEDCHECK;
        WPstatus=UNSCANED;
		bNeedCheckCoat = false;
		bNeedCheckCut = false;
        bAbort=false;
		bCanAbort=true;
		WaferID = "UnScaned";
        bCutFinished = false;
        bCoatFinished = false;
        bCleanFinished = false;
        bNeedCheckCut = false;
        bNeedCheckCoat = false;
        bCheckCoatFinished = false;
        bNeedRelocation = false;
        bHasWater = false;
    }
}CASSSLOT;

QDataStream &operator<<(QDataStream &out,const CASSSLOT& param);
QDataStream &operator>>(QDataStream &in, CASSSLOT& param);
class CCassette : public CChannel
{
public:
    CCassette(const QString& name,int32_t id);
	~CCassette();
private:
	bool m_bFirstFinished;
public:
    CASSSLOT vslots[MAX_SLOT]; //
    CASSSLOT m_CheckBoxWafer;
    //清空料盒中的Wafer状态为NoWafer
    void ResetSlots();

    //获取未切割的第一片
    CASSSLOT* GetFirstUnCutWafer();
	
	void SetNextUnCutWaferChecked();
    //获取第一片
    CASSSLOT *GetFirstWafer();

    CASSSLOT* GetCheckBoxWafer();
    //料盒内晶圆数量
    int  GetCassWaferNum();
	//料盒切割结束
    BOOL IsCassCutFinished();
	//还有未切割的料
	BOOL IsCassHasUnCutCell();

    bool IsSlotFirstInCass(CASSSLOT* pSlot);

    bool IsCassEmpty();

	//检查第一片检查是否完成
	bool IsFirstCheckFinished();
	void SetFirstCheckFinished(bool bFinshed);

	bool WriteRecoveredData();
	bool ReadRecoveredData();
    /**
     * 是否料盒中使用的Wafer，包括Checkbox Wafer.
     * 
     * \param pSlot
     * \return 
     */
    bool IsCasseteWafer(CASSSLOT* pSlot);
    QStringList ch_wp_status;
};

#endif // CCASSETTE_H
