예제 #1
0
bool ScriptUnit::run()
{
    const QString &script = scriptText();
    if (script.isEmpty()) {
        Log.w("Empty script - nothing to evaluate");
        return false;
    }

    if (!fileName().isEmpty())
        save();

    // Do not destroy previous engine right after exiting this scope,
    // because script may still executes. So, destroy only when new run() is called
    m_engine.reset(m_factory->createEngine(this));
    QScriptValue result = m_engine->evaluate(script);
    if (!result.isError())
        return true;

    int line = result.property("lineNumber").toInt32();
    QString scriptError = QString("line %1: \"%2\"").arg(line).arg(result.toString());
    Log.w(scriptError);

    emit error(scriptError);

    return false;
}
예제 #2
0
bool ScriptUnit::saveToFile(const QString &filePath)
{
    QFile scriptFile(filePath);
    if (!scriptFile.open(QIODevice::WriteOnly)) {
        QString error = QString("Selected file %1 could not be opened!").arg(m_filePath);
        Log.w(error);
        return false;
    }

    QTextStream out(&scriptFile);
    out << scriptText();
    return true;
}
예제 #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RimCommandFactory::createCommandObjects(const caf::PdmObjectGroup& selectedObjects, std::vector<RimCommandObject*>* commandObjects)
{
    for (size_t i = 0; i < selectedObjects.objects.size(); i++)
    {
        caf::PdmObjectHandle* pdmObject = selectedObjects.objects[i];

        if (dynamic_cast<RimCalcScript*>(pdmObject))
        {
            RimCalcScript* calcScript = dynamic_cast<RimCalcScript*>(pdmObject);

            QFile file(calcScript->absolutePath);
            if (file.open(QIODevice::ReadOnly | QIODevice::Text))
            {
                QTextStream in(&file);
                QByteArray byteArray = file.readAll();
                QString scriptText(byteArray);

                RimCommandExecuteScript* command = new RimCommandExecuteScript;
                command->scriptText = scriptText;

                commandObjects->push_back(command);
            }
        }
        else if (dynamic_cast<RimEclipseStatisticsCase*>(pdmObject))
        {
            RimEclipseStatisticsCase* statisticsCase = dynamic_cast<RimEclipseStatisticsCase*>(pdmObject);

            RimCommandIssueFieldChanged* command = new RimCommandIssueFieldChanged;
            command->objectName = statisticsCase->uiName();
            command->fieldName = statisticsCase->m_calculateEditCommand.keyword();
            command->fieldValueToApply = "true";

            commandObjects->push_back(command);
        }
    }
}
graphScript::graphScript ( const string& scriptString )
{
    init();

    scriptText( scriptString );
}