#pragma once
#include "dt.h"
#include <map>
#include "CMatrixCommon.h"
#include "CManageDB.h"

#ifdef WAFER_MATRIX_EXPORTS
#define WAFER_CMATRIX_DLL_API __declspec(dllexport)
#else
#define WAFER_CMATRIX_DLL_API //__declspec(dllimport)
#endif

using namespace ns_db;

namespace ns_mat
{
	typedef struct
	{
		UINT nDieMatrixId;							//��Բ����Id
		UINT nDieRow;								//�̾����ھ�����������
		UINT nDieCol;								//�̾����ھ�����������
		UINT iDieIndex;								//����Point��ID
		bool bDisable;								//�����õ�,��ͬ����Ч��
		PICK_DIE_STATUS eStatus;					//��Ƭ״̬
		XY_DOUBLE_STRUCT stPosition;				//�������õ�λ��
	} WAFER_MATRIX_POINT_INFO_STRUCT;

	class  WAFER_CMATRIX_DLL_API CWaferMatrix
	{
	public:
		CWaferMatrix(INT iModuleType, string strModuleName);
		LONG LoadMatrix(MATRIX_SEARCH_DIR dir);			//����λ�ú�index

		UINT GetCurrentIndex();							//��ȡ��ǰindex
		LONG SetCurrentIndex(UINT nIndex);				//���õ�ǰindex

		UINT GetNextIndex();							//��ȡ�ӵ�ǰ�㿪ʼ���¸���
		UINT GetPrevIndex();							//��ȡ�ӵ�ǰ�㿪ʼ���ϸ���

		UINT GetAmount();								//��ȡ����

		LONG SetPintInfoStatus(UINT nPtIndex, PICK_DIE_STATUS eStatus);

		//��ȡָ����Բ��λ����Ϣ
		LONG GetPintInfoByIndex(UINT nPtIndex, WAFER_MATRIX_POINT_INFO_STRUCT& stPointInfo);
		LONG GetAllPintInfo(vector<WAFER_MATRIX_POINT_INFO_STRUCT>& stPointInfo);

	private:
		static std::mutex m_MatrixMutex;
		bool bIsInitSuccess;

		int m_nModuleType;
		string m_strModuleName;

		//��ǰ��
		UINT m_iCurrentBondIndex;
		//��������
		UINT m_iBondAmount;

		CProduct* m_pCProduct = nullptr;

		//vector<PROGRAM_DIE_MATRIX_STRUCT> m_vetDieMatrix;
		vector<PROGRAM_WAFER_MATRIX_STRUCT> m_vetWaferMatrix;

		map<int, WAFER_MATRIX_POINT_INFO_STRUCT> m_mapWaferMatrixInfo;

	private:

		void SortDir_Z();
		void SortDir_S();

	};

}