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

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

#define  AddParam1(idx, node, motorId, paraId) pparam[idx] = node##->m_Variants.get_Variant(paraId);iID[idx] =motorId|(CMotorDriver::ABSMOVE_TYPE<<16);idx++;
#define  AddParam2(idx, node, motorId, paraId) pparam[idx] = node##->m_Variants.get_Variant(paraId);iID[idx] =0;idx++;
#define  AddParam3(idx, node, motorId, paraId) pparam[idx] = node##.m_Variants.get_Variant(paraId);iID[idx] =0;idx++;

void CMWCaliTrans::MInit()
{

    CProcess_Trans* pTrans=GET_PROCESS(PROCESS_TRANS,
                                       SM_TRANS,
                                       CProcess_Trans);
    Q_ASSERT(pTrans);

    CMWorkTable* pWorkTable=GET_CHDIRECT(WORKTABLE,CMWorkTable);
    Q_ASSERT(pWorkTable);

	int idx = 0;
    Variant* pparam[80]={0};
	int iID[80]={0};

	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosWait);
    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosLocationPushPrepare);
    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosLocationReady);
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosLocation);
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosPushReadyUnload);
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosScanBarcode);
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosWaferExistCheck);
	//AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosPutRail);
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosCassOutReady)
	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosCassOut);

    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosHCoat);
    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosHClean);
    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosRailNear);
    AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosRailFar);

	//AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Trans_PosClawCoat);

	AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Claw_PosCheckBoxOut);
	
	//AddParam1(idx, pTrans, MOTORA_CLAW, Var_Process_Trans_PosTransHLock);


	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_RailNear_PosOpenMax);
	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_RailNear_PosOpen);
	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_Trans_PosRailOpenPull);
	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_Trans_PosRailClosePull);
	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_Trans_PosRailCloseReady);
	AddParam1(idx, pTrans, MOTORB1_LOCK, Var_Process_RailNear_PosClose);
	
	AddParam1(idx, pTrans, MOTORB2_RAIL, Var_Process_RailFar_PosOpenMax);
    AddParam1(idx, pTrans, MOTORB2_RAIL, Var_Process_RailFar_PosOpen);
    AddParam1(idx, pTrans, MOTORB2_RAIL, Var_Process_RailFar_PosClose);
    
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosVWait);
    AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosRailNearReady);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosRailNear);
    
    AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosRailFarReady);
    AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosRailFar);
    
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosPickupWafer);
    AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosPutdownWafer);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosVCoatFinish);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosVCoatFinishLow);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosTransVCoat);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosVCleanFinish);
	AddParam1(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_PosTransVClean);
	//AddParam2(idx, pTrans, nullptr, Var_Process_Claw_Offset_DisClawLocation);
	//AddParam2(idx, pTrans, nullptr, Var_Process_Trans_GrapVOffset);
	AddParam2(idx, pTrans, nullptr, Var_Process_Claw_Offset_DisCassUnLoad);
	//AddParam2(idx, pTrans, nullptr, Var_Process_Trans_DisClawCheckBoxUnLoadOffset);
	AddParam2(idx, pTrans, MOTORD_TRANS, Var_Process_Trans_StepSleepTime);

	AddParam1(idx, pWorkTable, MOTORX, Var_MWorkTable_Load_X_ID);
	AddParam1(idx, pWorkTable, MOTORY, Var_MWorkTable_Load_Y_ID);
	AddParam1(idx, pWorkTable, MOTORZ, Var_MWorkTable_Load_Z_ID);
	AddParam1(idx, pWorkTable, MOTORW, Var_MWorkTable_Load_W_ID);

	AddParam1(idx, pWorkTable, MOTORX, Var_MWorkTable_Unload_X_ID);
	AddParam1(idx, pWorkTable, MOTORY, Var_MWorkTable_Unload_Y_ID);
	AddParam1(idx, pWorkTable, MOTORZ, Var_MWorkTable_Unload_Z_ID);
	AddParam1(idx, pWorkTable, MOTORW, Var_MWorkTable_Unload_W_ID);
	AddParam1(idx, pWorkTable, MOTORW, Var_MWorkTable_Unload_W_OFFSET_ID);

	AddParam1(idx, pWorkTable, MOTORX, Var_MWorkTable_Manual_LoadX_ID);
	AddParam1(idx, pWorkTable, MOTORY, Var_MWorkTable_Manual_LoadY_ID);

	AddParam3(idx, m_gSystem, nullptr, Var_AllSystem_Vacumm_TimeLimit_ID);
	AddParam3(idx, m_gSystem, nullptr, Var_AllSystem_Vacumm_BreakTimeLimit_ID);
	AddParam3(idx, m_gSystem, nullptr, Var_AllSystem_CellExistCheckTime_ID);

	AddParam2(idx, pTrans, nullptr, Var_Process_Trans_CleanGetWaferWaitTimeMs);

	AddParam1(idx, pTrans, MOTORH1_UPDOWN, Var_Process_Load_PosVWait);
	AddParam1(idx, pTrans, MOTORH1_UPDOWN, Var_Process_Load_PosVWT);
	//AddParam1(idx, pTrans, MOTORH1_UPDOWN, Var_Process_Load_PosVCoatFinish);
	//AddParam1(idx, pTrans, MOTORH1_UPDOWN, Var_Process_Load_PosVCoatFinishLow);
	AddParam1(idx, pTrans, MOTORH1_UPDOWN, Var_Process_Load_PosVRail);

	AddParam1(idx, pTrans, MOTORH2_TRANS, Var_Process_Load_PosHWait);
	AddParam1(idx, pTrans, MOTORH2_TRANS, Var_Process_Load_PosHWT);
	AddParam1(idx, pTrans, MOTORH2_TRANS, Var_Process_Load_PosHCoat);

	AddParam1(idx, pTrans, MOTORJ1_UPDOWN, Var_Process_Unload_PosVWait);
	AddParam1(idx, pTrans, MOTORJ1_UPDOWN, Var_Process_Unload_PosVWT);
	AddParam1(idx, pTrans, MOTORJ1_UPDOWN, Var_Process_Unload_PosVRail);
	

	AddParam1(idx, pTrans, MOTORJ2_TRANS, Var_Process_Unload_PosHWait);
	AddParam1(idx, pTrans, MOTORJ2_TRANS, Var_Process_Unload_PosHWT);
	AddParam1(idx, pTrans, MOTORJ2_TRANS, Var_Process_Unload_PosHClean);
	

    ui->widget->MParamInit_list(pparam,idx,iID);
    mchildwidgets[(uintptr_t)ui->widget]=ui->widget;
}


void CMWCaliTrans::MFresh()
{
	CMWidget::MFresh();

	ui->btnMoveWtUnloadPos->setVisible(false);
	ui->btnMoveWtLoadPos->setVisible(false);
	ui->btnMoveLoadWtPos->setVisible(false);
	ui->btnMoveLoadCoatPos->setVisible(false);
	ui->btnMovUnloadWtPos->setVisible(false);
	ui->btnMovUnloadCleanPos->setVisible(false);
}

void CMWCaliTrans::on_pushButton_MoveInitPos_clicked()
{
    V_MsgQueue msgqueue;
    msgqueue.pushback_Msg(VarMsg_Process_ID,
                          QObject::trUtf8("Move Trans init Pos Sig"),
                          QVariantList()
                          <<PROCESS_TRANS<<CProcess_Trans::MOVEINITPOS ,0);
    m_gSystem.start_test(SM_TRANS, msgqueue);
}

void CMWCaliTrans::on_btnExport_clicked()
{
	ui->widget->ExportParas();
}

void CMWCaliTrans::on_btnMoveWtLoadPos_clicked()
{
}

void CMWCaliTrans::on_btnMoveWtUnloadPos_clicked()
{

}

void CMWCaliTrans::on_btnMoveLoadWtPos_clicked()
{

}

void CMWCaliTrans::on_btnMoveLoadCoatPos_clicked()
{

}

void CMWCaliTrans::on_btnMovUnloadWtPos_clicked()
{

}

void CMWCaliTrans::on_btnMovUnloadCleanPos_clicked()
{

}
