#ifndef CPROCESS_HALFCUTKERF_H
#define CPROCESS_HALFCUTKERF_H

#include "cmprocess.h"
#include "cimagecontainer.h"
#include "cshape.h"
#include <QDataStream>
#include "cprecisetime.h"
#include "cprocess_kerf.h"

class CProcess_HalfCutKerf : public CMProcess
{
public:
    enum msg_id
    {
        PROCESS_Kerf_MSG_ID=MAX_PROCESS_MSG_ID,
        CALCUKERFPOS,   //计算Kerf的位置
        MOVEKERFPOS,    //移动到Kerf的位置
        KERF,
        SETKERFPOSMANUAL,   //手动测量Kerf位置
        TESTKERF,       //手动测试
        MAX_PROCESS_Kerf_MSG_ID,
    };
    CProcess_HalfCutKerf(const QString& name,int32_t id);
    QMMutexVector<KERFPARAM> m_vKerfParam;
    CMPointd m_CheckPos;    //检查的点位
    bool m_bHasSet;
	
	//计算Kerf检查的位置
    int CalcuKerfPos(int iSideID, int iLineID);
	//移动到Kerf的位置
    int MoveKerfPos();
	
    //kerf检查
    int Kerf(int iSideID, int iLineId);
	
	//手动更新Kerf的偏移位置
    int SetKerfPosManual(int iSideID, int iLineID);

	//设置关联的Kerf的参数
    void SetKerfParam(int iSideID);
	//分析识别的结果
    void AnalyseKerfResult(int iSideID, int iLineID, CImageContainer* pContainer);

    void CaptureImage(int iSideID, QString &str);
    void TestKerf(int iSideID);

    int32_t m_iKerfCamID;

    CImageContainer* m_imageContainer[2];	//Kerf检测的相机显示控件0 SideA
    void ClearContainer();

	virtual int32_t init_Process();




public:
    virtual void do_msg(int iID,QVariantList& vlInput,V_MsgOutput* pvlOutput) override;
    virtual void Serialize(QDataStream &stream, bool bwrite, int iVersion) override;
    void ReadRecipe(ConfigStreamReader& streamReader, int iVersion) override;
    void WriteRecipe(ConfigStreamWriter& streamWriter, int iVersion) override;

public:
    KERFPARAM *GetKerfParam( int iSideID);
    QVector<int>  VectorResult;
    void SearchLine(int iSideID,bool_t bAutoThres);

	//dRealOffset 切割道中心与相机中心点的偏移尺寸 在中心下方为负
	//dRealHeight 第一条线的尺寸mm
	//dRealHeight1 第二条线的尺寸mm
	//dRealGAP 两条线的中心点距离 只有一条线无效
    void GetKerfResult(double& dRealOffset,
                   double& dRealHeight ,
                   double& dRealHeight1,
                   double&  dRealGAP);
	//显示Kerf结果
    void ShowKerfResult(double  dRealOffset,
                         double  dRealHeight ,
                         double  dRealHeight1 ,
                         double  dRealGAP,
                         CImageContainer *pContainer);

    void SetKerfLight(int iSideID);

	//!< 根据WPDP的坐标，计算出线的位置的偏移并应用到定位的偏移
    double SetHairLineOffset(int iSideID, int iLineID, const CMPointd& WPDP, bool bApplyOffset, bool bManualSet=false);

    CPreciseTime m_KerfTime;
	double m_dKerfPower;
	double m_dKerfWidth;
	int m_iCurLineId;
	bool m_bAlignCheck;
};

#endif // CPROCESS_HALFCUTKERF_H
