#include "cmwviewworktable.h"
#include "ui_cmwviewworktable.h"
#include "logic.h"
CMWViewWorkTable::CMWViewWorkTable(QWidget *parent) :
    CMWidget(parent),
    ui(new Ui::CMWViewWorkTable)
{
    ui->setupUi(this);
    m_iTimerInterval=30;
}

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

void CMWViewWorkTable::MInit()
{
    ui->widget_WT->MInit();
    ui->widget_WT_Z->MInit();
    ui->widget_Locate0->m_bContainerInside=false;
    ui->widget_Locate1->m_bContainerInside=false;
    ui->widget_Locate2->m_bContainerInside=false;
    ui->widget_Locate3->m_bContainerInside=false;

    ui->widget_Align_A_PT1->m_bContainerInside=false;
    ui->widget_Align_A_PT2->m_bContainerInside=false;
    ui->widget_Align_B_PT1->m_bContainerInside=false;
    ui->widget_Align_B_PT2->m_bContainerInside=false;

    ui->widget_Align_A_Base->m_bContainerInside=false;
    ui->widget_Align_B_Base->m_bContainerInside=false;

    ui->widget_Kerf_A->m_bContainerInside=false;
    ui->widget_Kerf_B->m_bContainerInside=false;

    CProcess_Locate* pLocate=GET_PROCESS(PROCESS_LOCATE,
                                         SM_MAIN,
                                         CProcess_Locate);
    CProcess_Level* pLevel=GET_PROCESS(PROCESS_LEVELING,
                                       SM_MAIN,
                                       CProcess_Level);
    CProcess_Kerf* pKerf=GET_PROCESS(PROCESS_KERFCHECK,
                                       SM_MAIN,
                                       CProcess_Kerf);

    ui->widget_Locate0->m_pContainer=&pLocate->m_imageContainer[0];
    ui->widget_Locate1->m_pContainer=&pLocate->m_imageContainer[1];
    ui->widget_Locate2->m_pContainer=&pLocate->m_imageContainer[2];
    ui->widget_Locate3->m_pContainer=&pLocate->m_imageContainer[3];


    ui->widget_Align_A_PT1->m_pContainer=&pLevel->m_imageContainerAlign[0][0];
    ui->widget_Align_A_PT2->m_pContainer=&pLevel->m_imageContainerAlign[0][1];
    ui->widget_Align_B_PT1->m_pContainer=&pLevel->m_imageContainerAlign[1][0];
    ui->widget_Align_B_PT2->m_pContainer=&pLevel->m_imageContainerAlign[1][1];

    ui->widget_Align_A_Base->m_pContainer=&pLevel->m_imageContainerBase[0];
    ui->widget_Align_B_Base->m_pContainer=&pLevel->m_imageContainerBase[1];


    ui->widget_Kerf_A->m_pContainer=&pKerf->m_imageContainer[0];
    ui->widget_Kerf_B->m_pContainer=&pKerf->m_imageContainer[1];
}

void CMWViewWorkTable::resizeEvent(QResizeEvent *)
{

}

void CMWViewWorkTable::MFresh()
{
//    CMWidget::MFresh();
	ui->widget_WT_Z->setVisible(false);
}

void CMWViewWorkTable::MTimeFresh()
{
    ui->widget_WT->MTimeFresh( );
    ui->widget_WT_Z->MTimeFresh( );
    ui->widget_Locate0->MTimeFresh();
    ui->widget_Locate1->MTimeFresh();
    ui->widget_Locate2->MTimeFresh();
    ui->widget_Locate3->MTimeFresh();

    ui->widget_Align_A_PT1->MTimeFresh();
    ui->widget_Align_A_PT2->MTimeFresh();
    ui->widget_Align_B_PT1->MTimeFresh();
    ui->widget_Align_B_PT2->MTimeFresh();

    ui->widget_Align_A_Base->MTimeFresh();
    ui->widget_Align_B_Base->MTimeFresh();

    ui->widget_Kerf_A->MTimeFresh();
    ui->widget_Kerf_B->MTimeFresh();

}

void CMWViewWorkTable::setCurrentTabIndex(int iTab)
{
    ui->tabWidget_WT->setCurrentIndex(iTab);
}

void CMWViewWorkTable::setResizeTabIndex(int iTab)
{
	if(iTab == 1){
		ui->widget_Locate0->ZoomFit();
		ui->widget_Locate1->ZoomFit();
		ui->widget_Locate2->ZoomFit();
		ui->widget_Locate3->ZoomFit();
	}else if(iTab == 2){
		ui->widget_Align_A_PT1->ZoomFit();
		ui->widget_Align_A_PT2->ZoomFit();
		ui->widget_Align_A_Base->ZoomFit();
		ui->widget_Kerf_A->ZoomFit();
	}else if(iTab == 3){
		ui->widget_Align_B_PT1->ZoomFit();
		ui->widget_Align_B_PT2->ZoomFit();
		ui->widget_Align_B_Base->ZoomFit();
		ui->widget_Kerf_B->ZoomFit();
	}
}

void CMWViewWorkTable::setKerfStyle(bool bKerf, int iSide)
{
	CCtrlMImg_OPenGL* pWidget = nullptr;
	if(iSide == SIDE_A)
		pWidget = ui->widget_Kerf_A;
	else if(iSide == SIDE_B){
		pWidget = ui->widget_Kerf_B;
	}

	if(pWidget == nullptr)return;
	if(bKerf){
		pWidget->ZoomOrginal();
	}else{
		pWidget->ZoomFit();
	}
}

void CMWViewWorkTable::setHalfcutKerfStyle(bool bKerf, int iSide)
{
	CCtrlMImg_OPenGL* pWidget = nullptr;
	if(iSide == SIDE_A)
		pWidget = ui->widget_Align_A_Base;
	else if(iSide == SIDE_B){
		pWidget = ui->widget_Align_B_Base;
	}

	if(pWidget == nullptr)return;
	if(bKerf){
		pWidget->ZoomOrginal();
	}else{
		pWidget->ZoomFit();
	}
}
