#include "cmwcamfindage_h.h"
#include "ui_cmwcamfindage_h.h"
#include "logic.h"
#include "cmwcammorphology_h.h"
CMWCamFindAge_H::CMWCamFindAge_H(QWidget *parent,int32_t iCamID) :
    CMWCamAlgorithm(parent,iCamID),
    ui(new Ui::CMWCamFindAge_H)
{
    ui->setupUi(this);
}

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

void CMWCamFindAge_H::MInit()
{
    CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
    Q_ASSERT(pCam);
    CAFindEage_H* pFindEage=(CAFindEage_H*)
            pCam->Find_Algorithm(M_FINDEAGE);
    Q_ASSERT(pFindEage);

    Variant* pparam[50]={0};
    pparam[0]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_Alpha_ID);
    pparam[1]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_Low_ID);
    pparam[2]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_High_ID);
    pparam[3]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_MinLength_ID);
    pparam[4]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_MaxLength_ID);
    pparam[5]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_MinOpenDis_ID);
    pparam[6]=pFindEage->m_Variants.get_Variant(Var_FindEage_H_Polarity_ID);
    ui->widget->MParamInit_list(pparam,7);
    mchildwidgets[(uintptr_t)ui->widget]=ui->widget;

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

void CMWCamFindAge_H::on_pushButton_Tool_clicked()
{
    CCam* pCam=GET_CHDIRECT(m_iCamID,CCam);
    Q_ASSERT(pCam);
    CAFindEage_H* pFindEage=(CAFindEage_H*)
            pCam->Find_Algorithm(M_FINDEAGE);
    Q_ASSERT(pFindEage);
    pFindEage->showragion_static(&pCam->m_imageContainer);
    //pFindEage->showragion_active(&pCam->m_imageContainer);
}

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