#ifndef CMWORKTABLEDRIVER_H
#define CMWORKTABLEDRIVER_H
#include "cmpoint.h"
#include "cworktabledriver.h"
#include "logic_compdef.h"
#include "export_worktable_driver.h"
class WORKTABLE_DRIVER_EXPORT CMWorkTableDriver : public CWorkTableDriver {
public:
    enum msg_id {
        MWORKTABLEDRIVER_MSG_ID = MAX_WORKTABLEDRIVER_MSG_ID,
        MEASTABLEFOUCSPOS,          //相机自动测量焦距
        MEASTABLEFOUCSPOSOFFSET,    //测量平台偏差
        MEASWAFERTHICK,             //芯片厚度测量
        MOVETODEFOUCSPOS,           //移动到Focus偏移值
        LOADPOS,                    //上料位
        UNLOADPOS,                  //下料位
        MANUALLOADPOS,              //手动加载位
        MAX_MWORKTABLEDRIVER_MSG_ID,
    };
    CMWorkTableDriver(const QString& name, int32_t id);
    virtual ~CMWorkTableDriver();

public://XY
	//WT为逻辑坐标
    //计算坐标点
    void CaliCoord(int32_t iChid, const CMPointd& axis1, const CMPointd& axis2,
                   int32_t iTableID = WORKTABLE);
    //坐标点转换
    void AxisToWt(int32_t iChid, const CMPointd& axis, CMPointd& wt,
                  int32_t iTableID = WORKTABLE);
    //当前轴坐标转到WT逻辑坐标
    void CurAxisToWt(int32_t iChid, CMPointd& wt, bool bfresh,
                     int32_t iTableID = WORKTABLE);
	//WT逻辑坐标转到轴坐标
    void WtToAxis(int32_t iChid, const CMPointd& wt, CMPointd& axis,
                  int32_t iTableID = WORKTABLE);
    //相机坐标转换为WT逻辑坐标
    void CamToWt(int32_t iChid, const CMPointd& axis,
                 const CMPointd& campixel, CMPointd& wt,
                 int32_t iTableID = WORKTABLE);
	//Wt逻辑坐标转相机坐标
    void WtToCam(int32_t iChid,
                 const CMPointd& axis, const CMPointd& wt, CMPointd& campixel,
                 int32_t iTableID = WORKTABLE);

    void CurCamToWt(int32_t iCamChId, const CMPointd& campixel, CMPointd& wt, bool bfresh,
                    int32_t iTableID = WORKTABLE);
    void CurWtToCam(int32_t iChid, const CMPointd& wt, CMPointd& campixel, bool bfresh,
                    int32_t iTableID = WORKTABLE);
	//通过WT做中转
    void Axis1toAxis2(int32_t iChid1, const CMPointd& axis1, int32_t iChid2, CMPointd& axis2,
                      int32_t iTableID = WORKTABLE);
    void CurAxis1toAxis2(int32_t iChid1, int32_t iChid2, CMPointd& axis2, bool bfresh,
                         int32_t iTableID = WORKTABLE);

public:
    /*!
     * 测量平台的焦点位置，最终以相机6X为准
     * 开始可以使用低倍初步找一次焦点位置
     * \param iChid
     * \param iTableID
     * \return
     */
    int32_t MeasTableFoucsPos(int32_t iChid,
                              int32_t iTableID = WORKTABLE);
    /*!
     * 测量平台偏差
     *
     * \param iChid
     * \param iTableID
     * \return
     */
    int32_t MeasTableFoucsPosOffset(int32_t iChid,
                                    int32_t iTableID = WORKTABLE);
    //测量晶圆厚度
    double MeasWaferThick(int32_t iChid,
                          int32_t iTableID = WORKTABLE);
    //测量晶圆厚度
    int32_t MeasWaferThickDiff(int32_t iChid,
                               int32_t iTableID = WORKTABLE);
    /*!
     * 移动到焦点偏移dDeFoucs(向上为正)位置
     *
     * \param iChid
     * \param dDeFoucs
     * \param iTableID
     * \return
     */
    int32_t MoveToDeFoucsPos(int32_t iChid, double dDeFoucs,
                             int32_t iTableID = WORKTABLE);
    /*!
     * 移动Z轴到切深位置
     *
     * \param iChid
     * \param ddepth 切深
     * \param iTableID
     * \return
     */
    int32_t MoveToCutDepthPos(int32_t iChid, double ddepth,
                              int32_t iTableID = WORKTABLE);

    /*!
     * 运动Z并取得焦点的Z轴位置
     *
     * \param iChid
     * \param dDeFoucsDis 0 则表示运动并查找平台的焦点位置
     * \param iTableID
     * \param iStep
     * \return
     */
    double FoucsChannel(int32_t iChid, double dDeFoucsDis,
                        int32_t iTableID = WORKTABLE, int iStep = 0);

    /*!
     * 计算dPosZ与iChild焦点坐标的距离，向上为正
     *
     * \param iChid
     * \param dPosZ
     * \param iTableID
     * \return
     */
    double ZPosToDefoucsDis(int32_t iChid, double dPosZ,
                            int32_t iTableID = WORKTABLE);

    /*!
     * 计算Z轴关联的目标iChild在向上为正的偏移dDefocus上的Z轴位置
     *
     * \param iChid
     * \param dDefoucs
     * \param iTableID
     * \return 计算出的Z轴坐标
     */
    double DefoucsDisToZPos(int32_t iChid, double dDefoucs,
                            int32_t iTableID = WORKTABLE);

public:
    //移动到上料位
    int32_t LoadPos(int32_t iTableID = WORKTABLE);
    //移动到下料位
    int32_t UnLoadPos(int32_t iTableID = WORKTABLE);
    //移动到手动上料位
    int32_t ManualLoadPos(int32_t iTableID = WORKTABLE);
    void do_msg(int iID, QVariantList& vlInput, V_MsgOutput* pvlOutput);
};

#endif // CMWORKTABLEDRIVER_H
