#ifndef CPROCESS_COATCLEAN_H
#define CPROCESS_COATCLEAN_H

#include "cmprocess.h"
#include "cprecisetime.h"
//涂敷类型
enum CoatType {
    INIT_COAT,
    COAT,
    COAT_M,
    WATER_SOAK,
    WASH,
    DRY,    //仅旋转Spin
    DRY_M,  //旋转吹气
    FCLN,   //清洗铁环
    FCLN_DRY,
    WAIT,
    OPEN_CURTAIN,
    CLOSE_CURTAIN,
    MAXCOATTYPE,
};
//清洗类型
enum CleanType {
    INIT_CLEAN,
    WASHING,			//二流体清洗
    AIR,
    SPIN,
    WASH_NOAIR,
    OPEN_PROTECT,		//打开保护罩
    CLOSE_PROTECT,
    MAXCLEANTYPE,
};

extern const char* CoatName[];
extern const char* CleanName[];
typedef struct _tagCoatCleanStep {
    int32_t iType;
    double dTime;
    int	iRPM;
    double dSpayNum;
    double dSpaySpd;
    double dCenterSpeed;
    double dEageSpeed;
    double dCenterWaitTime;
    double dCoatPreSpyNum;
    int iCoatPreSpyWaitTime;
    double dBumpNum;
    double dPreSpayNum;
    _tagCoatCleanStep()
    {
        iType = 1;             //类型
        dTime = 0;             //时间
        iRPM = 0;              //转速
        dSpayNum = 5;        //胶量
        dSpaySpd = 0.2;        //喷胶速度
        dCenterSpeed = 1;    //CoatM中心速度
        dEageSpeed = 10;      //CoatM边界速度
        dCenterWaitTime = 2000; //CoatM中心等待时间
        dCoatPreSpyNum = 0;
        iCoatPreSpyWaitTime = 0;
        dBumpNum = 0;
        dPreSpayNum = 0;
    }
}COATCLEANSTEP, *PCOATCLEANSTEP;
enum COATCLEAN_ACTION_TYPE {
    NORMAL_ACTION = 1,    //正常清洗
    CLEANTABLE_ACTION,  //清洗台子
    CLEANCOATFLUID_ACTION,	//清洗涂胶液
};
typedef QMMutexVector<COATCLEANSTEP> COATCLEANSTEPVECTOR;
//清洗涂敷基类
class CProcess_CoatClean : public CMProcess {
public:
    enum msg_id {
        PROCESS_COATCLEAN_MSG_ID = MAX_PROCESS_MSG_ID,
        ALL_ACTION_BEFORE,      //所有操作开始前执行
        SINGLE_ACTION_BEFORE,   //单步操作开始前执行
        SINGLE_ACTION_WAIT,     //
        SINGLE_ACTION_AFTER,    //单步操作结束后行
        ALL_ACTION_AFTER,       //所有操作结束后执行
        INIT_POS,               //初始化位置
        SPINDLE_UP,             //主轴抬起
        MAX_PROCESS_COATCLEAN_MSG_ID,
    };
    CProcess_CoatClean(const QString& name, int32_t id);

    COATCLEANSTEPVECTOR m_vCoatCleanStep;		//涂敷的步骤 
    COATCLEANSTEPVECTOR m_vCleanTableStep;		//清洗平台的步骤
    COATCLEANSTEPVECTOR m_vCleanTableRing;		//清洗平台周围的步骤
    CPreciseTime m_COAT_CLEAN_TIME;

    virtual QString GetActionName(int iActionID);
    int m_iActionType;
    int m_iCurStep;
    bool GetCoatCleanStep(int iActionType, int iStepIndex, COATCLEANSTEP& step);
    void do_msg(int iID, QVariantList& vlInput, V_MsgOutput* pvlOutput) override;
    virtual void Init_Pos();
    virtual void SpindleUp(bool bUp, bool bAfterChecked = false);
    virtual bool  isSpindleHomed();

    virtual void SetdefaultSpeed(bool bSetSpindle = true);

    bool AssertAcuireRes(int vsmId, uint resId, QString info);
    bool ReleaseRes(int vsmId, uint resId);
public:
    virtual void all_action_before(int iActionType, int iStep);
    virtual void single_action_before(int iActionType, int32_t iType, double dTime, int iRPM, int iStep);
    virtual bool single_action_wait(int iActionType, int32_t iType, double dTime, int iRPM, int iStep);
    virtual void single_action_after(int iActionType, int32_t iType, double dTime, int iRPM, int iStep);
    virtual void all_action_after(int iActionType, int iStep);

    virtual void ReadCleanTable(const QString filePath, COATCLEANSTEPVECTOR& coatStepTable);
    virtual void WriteCleanTable(const QString filePath, COATCLEANSTEPVECTOR& coatStepTable);
    virtual void ReadWriteCleanTable(bool bWrite);
    virtual void Serialize(QDataStream &stream, bool bwrite, int iVersion) override;
    virtual void ReadRecipe(ConfigStreamReader& streamReader, int iVersion) override;
    virtual void WriteRecipe(ConfigStreamWriter& streamWriter, int iVersion) override;

};

ConfigStreamWriter &operator<<(ConfigStreamWriter& out, const COATCLEANSTEP& var);
ConfigStreamReader &operator >> (ConfigStreamReader& in, COATCLEANSTEP& var);

#endif // CPROCESS_COATCLEAN_H
