AMPIC887AxisCollection AMPIC887ConsoleCommandParser::axesFromCommandString(const QString &axisArguments,
        AMPIC887AxisCollection::InitializationState stateIfEmpty)
{

    QStringList axisArgumentList = commandArguments(axisArguments);

    if(axisArgumentList.isEmpty()) {
        return AMPIC887AxisCollection(stateIfEmpty);

    }

    AMPIC887AxisCollection axes(AMPIC887AxisCollection::EmptyCollection);

    for(int iAxis = 0, argCount = axisArgumentList.count();
            iAxis < argCount;
            ++iAxis) {

        QString axisString = axisArgumentList.at(iAxis);

        if(axisString.length() != 1) {
            axes.append(AMGCS2::UnknownAxis);
        } else {
            axes.append(AMGCS2Support::characterToAxis(axisString.at(0)));
        }
    }

    return axes;
}
AMPIC887AxisMap<double> AMPIC887ConsoleCommandParser::axisMapFromCommandString(
    const QString &commandString, bool* parseSuccess)
{
    QStringList argumentList = commandArguments(commandString);

    AMPIC887AxisMap<double> axisValueMap;
    int argumentCount = argumentList.count();

    // Ensure argument list isn't empty and has arguments in groups of two.
    if((argumentCount == 0) || (argumentCount % 2) != 0) {
        if(parseSuccess) {
            (*parseSuccess) = false;
        }
        return axisValueMap;
    }

    // Axis values are provided in pairs, and are not valid unless both are
    // there. As such we iterate through two at a time.
    for(int iAxis = 0, iValue = 1;
            iAxis < argumentCount && iValue < argumentCount;
            iAxis += 2, iValue += 2) {

        QString axisString = argumentList.at(iAxis);
        QString valueString = argumentList.at(iValue);

        AMGCS2::Axis axis;
        if(axisString.length() == 1) {
            axis = AMGCS2Support::characterToAxis(axisString.at(0));
        } else {
            axis = AMGCS2::UnknownAxis;
        }

        bool localParseSuccess = false;
        double parsedValue = valueString.toDouble(&localParseSuccess);

        if(!localParseSuccess) {
            // If parse fails we have to return an empty map
            if(parseSuccess) {
                (*parseSuccess) = false;
            }
            axisValueMap.clear();
            return axisValueMap;
        }

        axisValueMap.insert(axis, parsedValue);
    }

    if(parseSuccess) {
        (*parseSuccess) = true;
    }
    return axisValueMap;
}
void AMPIC887ConsoleCommandParser::handleRecordConfigInput(const QString &commandString)
{
    QStringList argumentList = commandArguments(commandString);

    QList<int> tableIdList;

    foreach(QString argumentString, argumentList) {

        bool parseSuccess = false;
        int currentArgumentTableId = argumentString.toInt(&parseSuccess);
        if(parseSuccess) {
            tableIdList.append(currentArgumentTableId);
        } else {
            tableIdList.append(-1);
        }
    }
void AMPIC887ConsoleCommandParser::handleSetRecordTriggerInput(const QString &commandString)
{
    QStringList argsList = commandArguments(commandString);

    QString recordTriggerString;
    if(argsList.count() >= 1) {
        recordTriggerString = argsList.at(0);
    }

    bool parseSuccess = false;
    int recordTriggerCode = recordTriggerString.toInt(&parseSuccess);
    if(!parseSuccess) {
        recordTriggerCode = -1;
    }

    emit setRecordTriggerCommandIssued(AMGCS2Support::intCodeToDataRecordTrigger(recordTriggerCode));
}
double AMPIC887ConsoleCommandParser::doubleValueFromCommandString(
    const QString &commandString, bool *parseSuccess)
{
    QStringList arguments = commandArguments(commandString);

    if(arguments.isEmpty()) {
        if(parseSuccess) {
            (*parseSuccess) = false;
        }
        return 0;
    }

    QString stringValue = arguments.at(0);
    double doubleValue = stringValue.toDouble(parseSuccess);

    return doubleValue;
}
void CommandRegistry::FireEvent( const std::string& functionName, ConsoleLog* log )
{
    ConsoleCommandArgs commandArguments(functionName);

    auto foundIter = GetCommandRegistryIter(commandArguments.m_argsList[0] );
    if( foundIter == registeredCommands.end() )
    {
        if( log != nullptr )
        {
            log->ConsolePrint( "Error: " + commandArguments.m_argsList[0] + " could not be found!",Vector4f(1.f,0.f,0.f,1.f), true );
        }
    }
    else
    {
        foundIter->second( commandArguments );
    }
}
void AMPIC887ConsoleCommandParser::handleSetSoftLimitStatusInput(const QString &commandString)
{
    QStringList argumentList = commandArguments(commandString);

    AMPIC887AxisMap<bool> axisValueMap;
    int argumentCount = argumentList.count();

    // Ensure argument list isn't empty and has arguments in groups of two.
    if((argumentCount == 0) || (argumentCount % 2) != 0) {
        return;
    }

    // Axis values are provided in pairs, and are not valid unless both are
    // there. As such we iterate through two at a time.
    for(int iAxis = 0, iValue = 1;
            iAxis < argumentCount && iValue < argumentCount;
            iAxis += 2, iValue += 2) {

        QString axisString = argumentList.at(iAxis);
        QString valueString = argumentList.at(iValue);

        AMGCS2::Axis axis;
        if(axisString.length() == 1) {
            axis = AMGCS2Support::characterToAxis(axisString.at(0));
        } else {
            axis = AMGCS2::UnknownAxis;
        }

        bool parsedValue;
        if(valueString == "0" ||
                valueString.toLower() == "false") {
            parsedValue = false;
        } else if (valueString == "1" ||
                   valueString.toLower() == "true") {
            parsedValue = true;
        } else {

            return;
        }

        axisValueMap.insert(axis, parsedValue);
    }

    emit setSoftLimitStatesCommandIssued(axisValueMap);
}
void AMPIC887ConsoleCommandParser::handleSetCommandLevelInput(const QString &commandString)
{
    QStringList argsList = commandArguments(commandString);

    QString commandLevelString;
    if(argsList.count() >= 1) {
        commandLevelString = argsList.at(0);
    }

    bool parseSuccess = false;
    int commandLevelCode = commandLevelString.toInt(&parseSuccess);
    if(!parseSuccess) {
        commandLevelCode = -1;
    }

    QString passwordString;
    if(argsList.count() >= 2) {
        passwordString = argsList.at(1);
    }

    emit setCommandLevelCommandIssued(AMGCS2Support::intCodeToCommandLevel(commandLevelCode),
                                      passwordString);
}
bool AMPIC887ConsoleCommandParser::boolValueFromCommandString(const QString &commandString, bool *parseSuccess)
{
    QStringList arguments = commandArguments(commandString);

    if(arguments.isEmpty()) {
        if(parseSuccess) {
            (*parseSuccess) = false;
        }
        return false;
    }

    QString stringValue = arguments.at(0);
    if(stringValue == "0" ||
            stringValue.toLower() == "false") {

        if(parseSuccess) {
            (*parseSuccess) = true;
            return false;
        }

    } else if(stringValue == "1" ||
              stringValue.toLower() == "true") {

        if(parseSuccess) {
            (*parseSuccess) = true;
            return true;
        }
    }


    if(parseSuccess) {
        (*parseSuccess) = false;
    }

    return false;
}