#include "cmwcaliworktableorginalsingle.h"
#include "ui_cmwcaliworktableorginalsingle.h"
#include "logic.h"
CMWCaliWorkTableOrginalSingle::CMWCaliWorkTableOrginalSingle(QWidget *parent) :
    CMWidget(parent),
    ui(new Ui::CMWCaliWtSingle)
{
    ui->setupUi(this);
	m_iWTID=WORKTABLE;
    m_iCHID=0;
}

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

void CMWCaliWorkTableOrginalSingle::MFresh()
{
	CWorkTable* pworkTable=GET_CHDIRECT(m_iWTID,CWorkTable);
    Q_ASSERT(pworkTable);
    CCoordTrans* pCoord=pworkTable->FindCoord(m_iCHID);
    Q_ASSERT(pCoord);
    ui->lineEdit_offsetX->setText(QString::number(pCoord->m_dOffsetX));
    ui->lineEdit_offsetY->setText(QString::number(pCoord->m_dOffsetY));

 }

void CMWCaliWorkTableOrginalSingle::MApply()
{
    CWorkTable* pworkTable=GET_CHANNEL(m_iWTID,WORKTABLE_DRIVER,CWorkTable);
    Q_ASSERT(pworkTable);
    CCoordTrans* pCoord=pworkTable->FindCoord(m_iCHID);
    Q_ASSERT(pCoord);
    pCoord->m_dOffsetX=ui->lineEdit_offsetX->text().toDouble();
    pCoord->m_dOffsetY=ui->lineEdit_offsetY->text().toDouble();


}

void CMWCaliWorkTableOrginalSingle::on_pushButton_firstPt_clicked()
{
    CMotorDriver* pMotorDriver=GET_CARD(MOTOR_DRIVER,CMotorDriver);
    axis1.tX=pMotorDriver->get_posdata(MOTORX,true);
    axis1.tY=pMotorDriver->get_posdata(MOTORY,true);
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_secondPt_clicked()
{
    CMotorDriver* pMotorDriver=GET_CARD(MOTOR_DRIVER,CMotorDriver);
    axis2.tX=pMotorDriver->get_posdata(MOTORX,true);
    axis2.tY=pMotorDriver->get_posdata(MOTORY,true);
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_clock90_clicked()
{
    V_MsgQueue msgqueue;
    m_gSystem.relmove_msg(90,MOTORW,msgqueue);
    m_gSystem.start_test(SM_MAIN, msgqueue,false);
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_countclock90_clicked()
{
    V_MsgQueue msgqueue;
	//多向反向移动0.1消除反向间隙
    m_gSystem.relmove_msg(-90.1,MOTORW,msgqueue);
	m_gSystem.relmove_msg(0.1, MOTORW,msgqueue);
    m_gSystem.start_test(SM_MAIN, msgqueue,false);
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_offsetxy_setcur_clicked()
{

    CMotorDriver* pMotorDriver=GET_CARD(MOTOR_DRIVER,CMotorDriver);

    CWorkTable* pworkTable=GET_CHANNEL(m_iWTID,WORKTABLE_DRIVER,CWorkTable);
    Q_ASSERT(pworkTable);
    CCoordTrans* pCoord=pworkTable->FindCoord(m_iCHID);
    Q_ASSERT(pCoord);

    pCoord->m_dOffsetX=pMotorDriver->get_posdata(MOTORX,true);
    pCoord->m_dOffsetY=pMotorDriver->get_posdata(MOTORY,true);

    MFresh();
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_offsetxy_Cali_clicked()
{
    CMWorkTableDriver* pworkTableDriver=GET_CARD(WORKTABLE_DRIVER,CMWorkTableDriver);
    Q_ASSERT(pworkTableDriver);
	pworkTableDriver->CaliCoord(m_iCHID,axis1,axis2);
    MFresh();
}

void CMWCaliWorkTableOrginalSingle::on_pushButton_offsetXYMoveTo_clicked()
{
	double dOffsetX=ui->lineEdit_offsetX->text().toDouble();
	double dOffsetY=ui->lineEdit_offsetY->text().toDouble();
    V_MsgQueue msgqueue;
    m_gSystem.absmove_xy_msg(dOffsetX,dOffsetY,msgqueue);
    m_gSystem.start_test(SM_MAIN, msgqueue,false);
}


