
#include "cmworktable.h"
#include "logic_local_def.h"
#include "csystem_external.h"
CMWorkTable::CMWorkTable(const QString &name, int32_t id)
    :CWorkTable(name,id)
{
    mChCoords[CAM2X]=CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[CAM2X]),CAM2X);
    mChCoords[CAM6X]=CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[CAM6X]),CAM6X);
#ifdef __USE_THIRD_CAMERA__
	mChCoords[CAMKerf]=CCoordTrans(QObject::trUtf8("Coord_%1").arg(m_gSystem.m_mapNameList[CAMKerf]),CAMKerf);
#endif
    mChCoords[LASERPATH_D_NARROW]=CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[LASERPATH_D_NARROW]),LASERPATH_D_NARROW);
    mChCoords[LASERPATH_D_WIDE]=CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[LASERPATH_D_WIDE]),LASERPATH_D_WIDE);

    mChCoords[LASERPATH_S_NARROW] = CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[LASERPATH_S_NARROW]), LASERPATH_S_NARROW);

    mChCoords[LASERPATH_L_NARROW] = CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[LASERPATH_L_NARROW]), LASERPATH_L_NARROW);

    mChCoords[DistanceSensor] = CCoordTrans(QObject::trUtf8("Coord_%1").arg(_SysExt_Instance.m_mapNameList[DistanceSensor]),DistanceSensor);

    mFoucsPoss[CAM2X]=FOUCSPOSINFO();
    mFoucsPoss[CAM6X]=FOUCSPOSINFO();
#ifdef __USE_THIRD_CAMERA__
	mFoucsPoss[CAMKerf]=FOUCSPOSINFO();
#endif
    mFoucsPoss[LASERPATH_D_NARROW]=FOUCSPOSINFO();
    mFoucsPoss[LASERPATH_D_WIDE] = FOUCSPOSINFO();
    mFoucsPoss[LASERPATH_S_NARROW] = FOUCSPOSINFO();
    mFoucsPoss[LASERPATH_L_NARROW] = FOUCSPOSINFO();
    mFoucsPoss[DistanceSensor] = FOUCSPOSINFO();

    //上料 X Y Z W
    m_Variants.add_Variant(Var_MWorkTable_Load_X_ID,
                           QObject::trUtf8("Load_X"),double(50),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Load_Y_ID,
                           QObject::trUtf8("Load_Y"),double(200),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Load_Z_ID,
                           QObject::trUtf8("Load_Z"),double(30),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Load_W_ID,
                           QObject::trUtf8("Load_W"),double(15),false,
                           Variant::TOXML);
    //下料 X Y Z W
    m_Variants.add_Variant(Var_MWorkTable_Unload_X_ID,
                           QObject::trUtf8("UnLoad_X"),double(50),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Unload_Y_ID,
                           QObject::trUtf8("UnLoad_Y"),double(-10),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Unload_Z_ID,
                           QObject::trUtf8("UnLoad_Z"),double(30),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Unload_W_ID,
                           QObject::trUtf8("UnLoad_W"),double(15),false,
                           Variant::TOXML);
	m_Variants.add_Variant(Var_MWorkTable_Unload_W_OFFSET_ID,
							QObject::trUtf8("UnLoad_W_OFFSET"),double(0),false,
							Variant::TOXML);

    //手动上料位
    m_Variants.add_Variant(Var_MWorkTable_Manual_LoadX_ID,
                           QObject::trUtf8("Manual_LoadX"),double(5),false,
                           Variant::TOXML);
    m_Variants.add_Variant(Var_MWorkTable_Manual_LoadY_ID,
                           QObject::trUtf8("Manual_LoadY"),double(-200),false,
                           Variant::TOXML);

    //焦距
    m_FoucsVariants.add_Variant(Var_MWorkTable_FoucsPos_ID,
                           QObject::trUtf8("FoucsPos"),double(-30),false,
                           Variant::TOXML);
    m_FoucsVariants.add_Variant(Var_MWorkTable_CaliSpd_ID,
                           QObject::trUtf8("CaliSpd"),double(0.5),false,
                           Variant::TOXML);
    m_FoucsVariants.add_Variant(Var_MWorkTable_CaliSpdMin_ID,
                           QObject::trUtf8("CaliSpdMin"),double(0.1),false,
                           Variant::TOXML);
    m_FoucsVariants.add_Variant(Var_MWorkTable_CaliRange_ID,
                           QObject::trUtf8("CaliRange"),double(0.3),false,
                           Variant::TOXML);
    m_FoucsVariants.add_Variant(Var_MWorkTable_CaliRangeMin_ID,
                           QObject::trUtf8("CaliRangeMin"),double(0.06),false,
                           Variant::TOXML);

}

CMWorkTable::~CMWorkTable()
{

}

QDomElement CMWorkTable::WriteConfig(QDomDocument &doc, QDomElement &root)
{
    QDomElement elem=CWorkTable::WriteConfig(doc,root);
    CHCOORDMAP::iterator ii=mChCoords.begin();
    for(;ii!=mChCoords.end();ii++)
    {
        ii->WriteConfig( doc, elem);
    }
    FOUCSPOSMAP::iterator jj=mFoucsPoss.begin();
    for(;jj!=mFoucsPoss.end();jj++)
    {
        m_FoucsVariants.get_VData(Var_MWorkTable_FoucsPos_ID)->setValue(jj->dFoucsPos);
        m_FoucsVariants.get_VData(Var_MWorkTable_CaliSpd_ID)->setValue(jj->dCaliSpd);
        m_FoucsVariants.get_VData(Var_MWorkTable_CaliSpdMin_ID)->setValue(jj->dCaliSpdMin);
        m_FoucsVariants.get_VData(Var_MWorkTable_CaliRange_ID)->setValue(jj->dCaliRange);
        m_FoucsVariants.get_VData(Var_MWorkTable_CaliRangeMin_ID)->setValue(jj->dCaliRangeMin);

        QDomElement elem1=AppandRootDom(doc,QObject::trUtf8("%1_FoucsParam")
                                        .arg(_SysExt_Instance.m_mapNameList[jj.key()]),elem);
        m_FoucsVariants.WriteConfig(doc,elem1);
    }
    return elem;
}

int CMWorkTable::ReadConfig(QDomElement &root)
{
    int iIndex=CWorkTable::ReadConfig(root);
    QDomNodeList List =  root.childNodes();
    Q_ASSERT(iIndex<List.size());

    CHCOORDMAP::iterator ii=mChCoords.begin();
    for(;ii!=mChCoords.end();ii++)
    {
        ii->ReadConfig( List.at(iIndex).toElement());
        iIndex++;
    }
    FOUCSPOSMAP::iterator jj=mFoucsPoss.begin();
    for(;jj!=mFoucsPoss.end();jj++)
    {
        m_FoucsVariants.ReadConfig(List.at(iIndex).toElement());
        iIndex++;
        jj->dFoucsPos=m_FoucsVariants.get_VData(Var_MWorkTable_FoucsPos_ID)->toDouble();
        jj->dCaliSpd=m_FoucsVariants.get_VData(Var_MWorkTable_CaliSpd_ID)->toDouble();
        jj->dCaliSpdMin=m_FoucsVariants.get_VData(Var_MWorkTable_CaliSpdMin_ID)->toDouble();
        jj->dCaliRange=m_FoucsVariants.get_VData(Var_MWorkTable_CaliRange_ID)->toDouble();
        jj->dCaliRangeMin=m_FoucsVariants.get_VData(Var_MWorkTable_CaliRangeMin_ID)->toDouble();

    }
    return iIndex;
}

