// VisionUnitResult.h: interface for the CVisionUnitResult class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include <array>
#include <vector>
#include <string>

#include "VisionResult.h"

#ifdef BUILD_COMMDLL
#define COMMDLL_DLLCLASS __declspec(dllexport)
#else
#define COMMDLL_DLLCLASS __declspec(dllimport)
#endif

class COMMDLL_DLLCLASS CVisionUnitResult
{
public:
	enum ENCODER_RECORD {
		ENC_Z_POS,	// LaserZ / Pmi-Z
		ENC_X_POS,	// Mark Index X
		MAX_ENCODER_POS,
	};

	CVisionUnitResult(int nTotalGx = 1, int nTotalLx = 1);

	virtual ~CVisionUnitResult();

	void InitParameters(int nTotalGx = 1, int nTotalLx = 1);

	void SetTeachMode(bool bState);
	bool IsTeachMode();

	void SetImageTaken(bool bState);
	bool IsImageTaken();

	void SetResultCode(std::string csResultCode);
	std::string GetResultCode();

	void SetResultReady(bool bState);
	bool IsResultReady();

	void SetDecodedString(std::string csDecodeString, int nGx = 0, int nLx = 0);
	std::string  GetDecodedString(int nGx = 0, int nLx = 0);

	void	SetResultParams(int nParamNo, double dResult, int nGx = 0, int nLx = 0);
	double  GetResultParams(int nParamNo, int nGx = 0, int nLx = 0);
	void	GetResultParams(std::vector<double> &vecResultParam, int nGx = 0, int nLx = 0);
	//
	void	SetSubResultCodeParams(int nParamNo, std::string csSubResultCode, int nGx = 0, int nLx = 0);
	std::string  GetSubResultCodeParams(int nParamNo, int nGx = 0, int nLx = 0);
	void	GetSubResultCodeParams(std::vector<std::string> &vecSubResultCodeParam, int nGx = 0, int nLx = 0);
	//
	void	SetNominalDatas(int nParamNo, double dResult, int nGx = 0, int nLx = 0);
	double  GetNominalDatas(int nParamNo, int nGx = 0, int nLx = 0);
	void	GetNominalDatas(std::vector<double> &vecNominalData, int nGx = 0, int nLx = 0);
	//
    void	SetPviParams(int nParamNo, double dResult, int nGx = 0, int nLx = 0);
	double  GetPviParams(int nParamNo, int nGx = 0, int nLx = 0);

	void GetGxLxSetting(int &nTotalGx, int &nTotalLx);
	bool IsValidGxLx(int nGx, int nLx);

	void ResetAllData(std::string strDecodedString = _T(""), double dValue =0, std::string strSubResultCode =_T(""));

	CVisionUnitResult& operator=(const CVisionUnitResult& visionUnitResult);

	void SetResultValid(bool bState);
	bool IsResultValid();

	//
	void SetHostAck(int nAck)	{ m_nHostAck = nAck;  }
	int	 GetHostAck()			{ return m_nHostAck;  }

	void SetRejectCode(std::string csRejectCode)	{ m_strRejectCode = csRejectCode;  }
	std::string	 GetRejectCode()					{ return m_strRejectCode;  }

	void SetEncoderPos(int nItem, double dValue)			{ m_arrEncoderPos[nItem] = dValue;	}
	double GetEncoderPos(int nItem)							{ return m_arrEncoderPos[nItem];	}

	void ReleaseBuffer();

private:
	// Methods
	void InitBuffer();

	// Attributes
	int  m_nTotalGx;
	int	 m_nTotalLx;
	//
	bool m_bImageTaken;
	bool m_bTeachMode;
	bool m_bTrue;	// Result ready
	bool m_bResultValid;  // To indicate Valid result (Eg.: Partial Inspection)
	std::string m_strResultCode;

	CVisionResult **m_pVisionResult;

	// For Intel MARKTRAYMAP / PMI PCS validation
	int m_nHostAck;
	std::string m_strRejectCode;

	// For Encoder Recording
    std::array<double, MAX_ENCODER_POS> m_arrEncoderPos;
};

