#include "machinetypefun.h"

MachineTypeFun::MachineTypeFun(QObject *parent) : QObject(parent)
{
    m_allParasList.clear();
    m_allOutCtrlList.clear();
    m_allShortCutList.clear();
    m_allAssistList.clear();
    m_allPatternSetList.clear();
    m_allParaSetList.clear();
    m_allEmbFunctionList.clear();
    m_allSensorList.clear();
    m_allErrorCodeAndStateList.clear();

    initAllSensorList();
}

MachineTypeFun::~MachineTypeFun()
{
    m_allParasList.clear();
    m_allOutCtrlList.clear();
    m_allShortCutList.clear();
    m_allAssistList.clear();
    m_allPatternSetList.clear();
    m_allParaSetList.clear();
    m_allEmbFunctionList.clear();
    m_allSensorList.clear();
    m_allErrorCodeAndStateList.clear();
}

//获取传感器列表
QList<SensorItem> MachineTypeFun::getSensorList()
{
    return m_allSensorList;
}

//获取错误代码列表
QList<ErrorCodeStateItem> MachineTypeFun::getErrorCodeAndStateList()
{
    return m_allErrorCodeAndStateList;
}

void MachineTypeFun::initAllSensorList()
{
    //所有传感器列表，字符为空
    m_allSensorList.clear();
    int addr, byteaddr, bitaddr;

    SensorItem item;

    for (addr = 0; addr < MAX_SENSOR_NUM; addr++)
    {
        byteaddr = addr / 8;
        bitaddr = addr % 8; //(0-7)
        item.setItemValue(byteaddr, bitaddr, "");
        m_allSensorList.append(item);
    }
}

QList<EmbFunctionItem> MachineTypeFun::getEmbFunctionListByFilter()
{
    return m_allEmbFunctionList;
}

QList<ParaSetItem> MachineTypeFun::getParaSetListByFilter()
{
    return m_allParaSetList;
}

QList<PatternSetItem> MachineTypeFun::getPatternSetListByFilter()
{
    return m_allPatternSetList;
}

QList<AssistItem> MachineTypeFun::getAssistListByFilter()
{
    return m_allAssistList;
}

QList<ShortCutItem> MachineTypeFun::getShortCutListByFilter()
{
    return m_allShortCutList;
}

QList<OutCtrlItem> MachineTypeFun::getOutCtrlListByFilter()
{
    return m_allOutCtrlList;
}

QList<ParaItem> MachineTypeFun::getParasListByMcSel()
{
    QList <ParaItem> paralist;
    int size = m_allParasList.size();

    for (int i = 0; i < size; i++)
    {
        const ParaItem & item = m_allParasList.at(i);
        paralist.append(item);
#if(0)
        if ((item.mcenSel & mcensel) != 0)
        {
            paralist.append(item);
        }
#endif
    }

    qStableSort(paralist.begin(), paralist.end(), comparePriority);
    return paralist;
}
