#ifndef CPROCESS_LOCATE_H
#define CPROCESS_LOCATE_H

#include "cmprocess.h"
#include "logic_compdef.h"
#include "cimagecontainer.h"
#include "cprecisetime.h"

typedef struct _tagLocatePos
{
	CMPointd PixelResultPos;
	int32_t iCamID;
	BOOL bHasLocated;
	double dAngle;
	CMPointd WPDP;
    CMImage img;
	_tagLocatePos()
	{
		iCamID=CAM2X;
		dAngle=0;
		bHasLocated=FALSE;
        WPDP.Reset();
		PixelResultPos.Reset();
	}
}LOCATEPOS,*PLOCATEPOS;

typedef QMMutexVector<LOCATEPOS>  LOCATEVECTOR;
/*!
 * \brief The CProcess_Locate class
 * 定位
 */
class CProcess_Locate : public CMProcess
{
public:
	enum msg_id
	{
		PROCESS_LOCATE_MSG_ID=MAX_PROCESS_MSG_ID,
        CALCULOCATEVECTOR,
        MOVEPOS,
        SEARCHPOS,
		LOCATECELL,
        FITCELL,
        SETPOSMANUAL,
        SETLOCATELIGHT,
		SETLOCATECAM,
		MAX_PROCESS_LOCATE_MSG_ID,
	};
	CProcess_Locate(const QString& name,int32_t id);
	~CProcess_Locate();
    LOCATEVECTOR m_LocateVector;
    CImageContainer m_imageContainer[4];
    void ClearContainer();
    void do_msg(int iID,QVariantList& vlInput,V_MsgOutput* pvlOutput);
	int CalcuLocateVector( );
	int LocateCell();
	int FitCell( );
    int FitCellSimulator();

	void WriteRecipe(ConfigStreamWriter& streamWriter, int iVersion) override;


	void ReadRecipe(ConfigStreamReader& streamReader, int iVersion) override;

public:
	void MovePos( int iLocateIndex,int iAdjustIndex);
    bool SearchPos(int iLocateIndex, bool breport=false);
    void SetPosManual( int iLocateIndex);
	void SetLocateLight();
	void SetLocateCam();

    void CaptureImage(int iCamID, QString str,int iIndex,bool bSetMark);
public:
	int32_t m_iLocateCamID;
	int32_t m_iLocateLightDirectID;
    int32_t m_iLocateLightSideID;
    int32_t m_iCurLocateIndex;
public:
    void  AddStaticToolToCam(int iLocateIndex);
    CPreciseTime m_LocateTime;
    virtual void Serialize(QDataStream &stream, bool bwrite, int iVersion) override;
private:
	double get_nearnest_point(double angle,double dCenterX, double dCenterY, QList<CMPointd> lcenters, CMPointd& nearnestPt);
};

#endif // CPROCESS_LOCATE_H
