#include "stable.h"
#include "cmwcamkerflaser.h"
#include "ui_cmwcamkerflaser.h"
#include "cmwcammorphology_h.h"
CMWCamKerfLaser::CMWCamKerfLaser(QWidget *parent,int32_t iCamID)
	:  CMWCamAlgorithm(parent,iCamID)
{
	ui = new Ui::CMWCamKerfLaser();
	ui->setupUi(this);
}

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

void CMWCamKerfLaser::MInit()
{
	CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
	Q_ASSERT(pCam);
	CAKerfCheck_H* pKerf=(CAKerfCheck_H*)
		pCam->Find_Algorithm(M_KERF_LASER);
	Q_ASSERT(pKerf);

	Variant* pparam[50]={0};
	pparam[0]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Rangemax);
	pparam[1]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Rangemin);
	pparam[2]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Threshold);
	pparam[3]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Mount);
	pparam[4]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Direct_x);
	pparam[5]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Maxlength);
	pparam[6]=pKerf->m_Variants.get_Variant(Var_KerfCheck_H_Minlength);

	ui->widget->MParamInit_list(pparam,7);
	mchildwidgets[(intptr_t)ui->widget]=ui->widget;


	CMWCamMorphology_h* pMWMorphology=new CMWCamMorphology_h(this);
	pMWMorphology->m_pAlgorithm=pKerf;
	pMWMorphology->m_iCamID=m_iCamID;
	ui->horizontalLayout_Morphology->addWidget(pMWMorphology);
	mchildwidgets[intptr_t(pMWMorphology)]=pMWMorphology;
}

void CMWCamKerfLaser::on_pushButton_Tool_clicked()
{
	MApply();
	CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
	Q_ASSERT(pCam);
	CAKerfCheck_H* pKerf=(CAKerfCheck_H*)
		pCam->Find_Algorithm(M_KERF_LASER);
	Q_ASSERT(pKerf);
	pKerf->showragion(&pCam->m_imageContainer);
}

void CMWCamKerfLaser::on_pushButton_Exe_clicked()
{
	V_MsgQueue msgqueue;
	msgqueue.pushback_Msg(VarMsg_Driver_ID,
		QObject::trUtf8("Kerf Check Sig"),
		QVariantList()
		<<CAM_DRIVER<<CCamDriver::EXE_ALGORITHM
		<<m_iCamID<<M_KERF_LASER,0);
	m_gSystem.start_test(SM_MAIN, msgqueue,false);
}

