#include "cmwcaliworktablecoord.h"
#include "ui_cmwcaliworktablecoord.h"
#include "cmwcaliworktablecoordsingle.h"
#include "logic.h"
CMWCaliWorkTableCoord::CMWCaliWorkTableCoord(QWidget *parent) :
    CMWidget(parent),
    ui(new Ui::CMWCaliWorkTableCoord)
{
    ui->setupUi(this);
}

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

void CMWCaliWorkTableCoord::MInit()
{
    CMWorkTable* pWorkTable=GET_CHDIRECT(WORKTABLE,CMWorkTable);
    Q_ASSERT(pWorkTable);
    CMWorkTable::CHCOORDMAP::iterator ii
            = pWorkTable->mChCoords.begin();

    QList<int> lstCoords;
    lstCoords.push_back(CAM2X);
    lstCoords.push_back(CAM6X);
#ifdef __USE_D_NARROW__
    lstCoords.push_back(LASERPATH_D_NARROW);
#endif
#ifdef __USE_S_NARROW__
    lstCoords.push_back(LASERPATH_S_NARROW);
#endif
#ifdef __USE_L_NARROW__
    lstCoords.push_back(LASERPATH_L_NARROW);
#endif
#ifdef __USE_D_WIDE__
    lstCoords.push_back(LASERPATH_D_WIDE);
#endif

    QMap<int, int> mapAddsCoords;
    for (int i = 0; i < lstCoords.count(); i++)
    {
        int iCoordId = lstCoords[i];
        if (pWorkTable->mChCoords.contains(iCoordId))
        {
            CMWCaliWorkTableCoordSingle* pWidget =
                new CMWCaliWorkTableCoordSingle(ui->tabWidget, iCoordId);

            pWidget->MInit();
            ui->tabWidget->addTab(pWidget, m_gSystem.m_mapNameList[iCoordId]);
            mchildwidgets[intptr_t(pWidget)] = pWidget;

            mapAddsCoords[iCoordId, iCoordId];
        }
    }

    for(;ii!=pWorkTable->mChCoords.end();ii++)
    {

        if (mapAddsCoords.contains(ii.key()))
        {
            continue;
        }

#ifndef __USE_S_NARROW__
        if (ii.key() == LASERPATH_S_NARROW)
        {
            continue;
        }
#endif
#ifndef __USE_D_NARROW__
        if (ii.key() == LASERPATH_D_NARROW)
        {
            continue;
        }
#endif
#ifndef __USE_L_NARROW__
        if (ii.key() == LASERPATH_L_NARROW)
        {
            continue;
        }
#endif
#ifndef __USE_D_WIDE__
        if (ii.key() == LASERPATH_D_WIDE)
        {
            continue;
        }
#endif
        CMWCaliWorkTableCoordSingle* pWidget=
                new CMWCaliWorkTableCoordSingle(ui->tabWidget,ii.key());

        pWidget->MInit();
        ui->tabWidget->addTab(pWidget,m_gSystem.m_mapNameList[ii.key()]);
        mchildwidgets[intptr_t(pWidget)]=pWidget;
    }
}
