#include "cmwmanualmeas.h"
#include "ui_cmwmanualmeas.h"
#include "logic.h"
CMWManualMeas::CMWManualMeas(QWidget *parent) :
    CMWidget(parent),
    ui(new Ui::CMWManualMeas)
{
    ui->setupUi(this);
}

CMWManualMeas::~CMWManualMeas()
{
    delete ui;
}

void CMWManualMeas::MFresh()
{
    if(m_iCurCamID!=CAM2X&&m_iCurCamID!=CAM6X&&m_iCurCamID!=CAMKerf)
    {
        showShieldWindow(true,
                    QObject::trUtf8("Switch to any cam."));
        return;
    }
    showShieldWindow(false);

	if(m_gSystem.IsSMAutoRun(SM_MAIN))
		setEnabled(false);

    
	CMWidget::MFresh();
	
	ui->pushButton_TableMeasDiff->setVisible(false);
}

void CMWManualMeas::MTimeFresh()
{
    if( m_iCurCamID!=m_gSystem.m_iCurChID )
    {
        m_iCurCamID=m_gSystem.m_iCurChID;
        MFresh();
    }
}

void CMWManualMeas::on_pushButton_CellMeas_clicked()
{
    V_MsgQueue msgqueue;
    msgqueue.pushback_Msg(VarMsg_Driver_ID,
                          QObject::trUtf8("Meas Cell Thick Sig"),
                          QVariantList()
                          <<WORKTABLE_DRIVER<<CMWorkTableDriver::MEASWAFERTHICK
                          <<m_iCurCamID,0);
    m_gSystem.start_test(SM_MAIN, msgqueue,true);
}


void CMWManualMeas::on_pushButton_TableMeasDiff_clicked()
{
    V_MsgQueue msgqueue;
    msgqueue.pushback_Msg(VarMsg_Driver_ID,
                          QObject::trUtf8("Meas Table Offset Sig"),
                          QVariantList()
                          <<WORKTABLE_DRIVER<<CMWorkTableDriver::MEASTABLEFOUCSPOSOFFSET
                          <<m_iCurCamID,0);
    m_gSystem.start_test(SM_MAIN, msgqueue,true);
}

void CMWManualMeas::on_btnMoveToRotate_clicked()
{
    CMPointd axis;
    CMWorkTableDriver* pWorkTableDriver = GET_CARD(
        WORKTABLE_DRIVER, CMWorkTableDriver);
    CMPointd wt(m_WTRecord.tY, -m_WTRecord.tX);
    pWorkTableDriver->WtToAxis(m_iCurCamID, wt, axis);
    //m_gSystem.absmove_xy(axis.tX,axis.tY);

    V_MsgQueue msgqueue;
    m_gSystem.absmove_xy_msg(axis.tX, axis.tY, msgqueue);
    m_gSystem.start_test(SM_MAIN, msgqueue, true);
}

void CMWManualMeas::on_pushButton_PosMark_clicked()
{
    CMWorkTableDriver* pWorkTableDriver=GET_CARD(
                WORKTABLE_DRIVER,CMWorkTableDriver);
    pWorkTableDriver->CurAxisToWt(m_iCurCamID,m_WTMark,true);
}

void CMWManualMeas::on_pushButton_PosMeas_clicked()
{
    CMPointd wt;
    CMWorkTableDriver* pWorkTableDriver=GET_CARD(
                WORKTABLE_DRIVER,CMWorkTableDriver);
    pWorkTableDriver->CurAxisToWt(m_iCurCamID,wt,true);
    ui->lineEdit_XDis->setText(QString::number(wt.tX-m_WTMark.tX,'f',3));
    ui->lineEdit_YDis->setText(QString::number(wt.tY-m_WTMark.tY,'f',3));
}

void CMWManualMeas::on_pushButton_PosRecord_clicked()
{
    CMWorkTableDriver* pWorkTableDriver=GET_CARD(
                WORKTABLE_DRIVER,CMWorkTableDriver);
    pWorkTableDriver->CurAxisToWt(m_iCurCamID,m_WTRecord,true);
}


void CMWManualMeas::on_pushButton_MoveToRecord_clicked()
{
    CMPointd axis;
    CMWorkTableDriver* pWorkTableDriver=GET_CARD(
                WORKTABLE_DRIVER,CMWorkTableDriver);
    pWorkTableDriver->WtToAxis(m_iCurCamID,m_WTRecord,axis);
    //m_gSystem.absmove_xy(axis.tX,axis.tY);

	V_MsgQueue msgqueue;
	m_gSystem.absmove_xy_msg(axis.tX, axis.tY, msgqueue);
	m_gSystem.start_test(SM_MAIN, msgqueue,true);
}
