#include "cmwcamblob_h.h"
#include "ui_cmwcamblob_h.h"
#include "cablob_h.h"
#include "cmallsystem.h"
#include "logic.h"
#include "cmwcammorphology_h.h"
CMWCamBlob_H::CMWCamBlob_H(QWidget *parent, int32_t iCamID) :
	CMWCamAlgorithm(parent,iCamID),
    ui(new Ui::CAlgorithmBlob_H)
{
	ui->setupUi(this);
}

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

void CMWCamBlob_H::MInit()
{
	CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
	Q_ASSERT(pCam);
	CABlob_H* pBlob=(CABlob_H*)pCam->Find_Algorithm(M_BLOB);
    Q_ASSERT(pBlob);

    Variant* pparam[50]={0};
    pparam[0]=pBlob->m_Variants.get_Variant(Var_Blob_H_MinGray_ID);
    pparam[1]=pBlob->m_Variants.get_Variant(Var_Blob_H_MaxGray_ID);
    pparam[2]=pBlob->m_Variants.get_Variant(Var_Blob_H_MinArea_ID);
    pparam[3]=pBlob->m_Variants.get_Variant(Var_Blob_H_MaxArea_ID);

    ui->widget->MParamInit_list(pparam,4);
    mchildwidgets[(int)ui->widget]=ui->widget;

    CMWCamMorphology_h* pMWMorphology=new CMWCamMorphology_h(this);
    pMWMorphology->m_pAlgorithm=pBlob;
    ui->horizontalLayout_Morphology->addWidget(pMWMorphology);
    mchildwidgets[int(pMWMorphology)]=pMWMorphology;

}

void CMWCamBlob_H::on_pushButton_Tool_clicked()
{
	CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
	Q_ASSERT(pCam);
	CABlob_H* pBlob=(CABlob_H*)pCam->Find_Algorithm(M_BLOB);
    Q_ASSERT(pBlob);
	pBlob->showragion_active(&pCam->m_imageContainer);
}

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

void CMWCamBlob_H::on_pushButton_ROI_clicked()
{
    CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
    Q_ASSERT(pCam);
    CABlob_H* pBlob=(CABlob_H*)pCam->Find_Algorithm(M_BLOB);
    Q_ASSERT(pBlob);

    pCam->m_imageContainer.addShape(&pBlob->m_rect_ROI,
                                    CImageContainer::ACTIVE_SHAPE);

}
