Exemplo n.º 1
0
quint64 CommandHandler::findOperationId(const OperationExpression& expr) const {

    QSqlQuery db(kernel()->database());
    QSqlQuery db2(kernel()->database());
    QString query = QString("select * from mastercatalog where resource like '%1%' ").arg(expr.metaUrl().toString());
    if (db.exec(query)) {
        while ( db.next()){
            quint64 itemid = db.value("itemid").toLongLong();
            query = QString("select * from catalogitemproperties where itemid=%1").arg(itemid);
            if (db2.exec(query)) {
                std::map<QString, QString> values;
                while ( db2.next()){
                    QSqlRecord rec = db2.record();
                    values[rec.value("propertyname").toString()] = rec.value("propertyvalue").toString();
                }
                QString parmcount = values["inparameters"];
                if ( !expr.matchesParameterCount(parmcount))
                    continue;
                bool found = true;
                long index;
                if ( (index = parmcount.indexOf('+')) != -1) {
                    index = parmcount.left(index).toUInt();
                } else
                    index = 10000;
                for(long i=0; i < expr.parameterCount(); ++i) {
                    int n = min(i+1, index);
                    QString key = QString("pin_%1_type").arg(n);
                    IlwisTypes tpExpr = expr.parm(i).valuetype();
                    auto iter = values.find(key);
                    if ( iter == values.end()){
                        found = false;
                        break;
                    }
                    IlwisTypes tpMeta = (*iter).second.toULongLong();
                    if ( (tpMeta & tpExpr) == 0 && tpExpr != i64UNDEF) {
                        found = false;
                        break;
                    }

                }
                if ( found)
                    return itemid;
            }
        }
    }
    ERROR2(ERR_NO_INITIALIZED_2,"metadata",expr.name());
    return i64UNDEF;
}
Exemplo n.º 2
0
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index)  {
    const Parameter& parm = expr.parm(index);
    DataDefinition def;
    QString parmvalue = parm.value().toLower();

    quint64 gcid = mastercatalog()->name2id(parmvalue, itRASTER);
    if ( gcid != i64UNDEF) {
        IRasterCoverage cov;
        if(cov.prepare(gcid)) {
            def = cov->datadef();
            _coverages[index - 1] = cov.get<Coverage>();
        }
    } else {
        bool ok;
        _number[index - 1] =parmvalue.toDouble(&ok);
        if ( ok){
            def.domain().prepare("value");
        } else {
            std::vector<QString> bools = {"true","false","yes","no","?"};
            auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower());
            if ( iter != bools.end()) {
                int v = 0;
                if ( parmvalue == "?" )
                    v= 2;
                else if ( parmvalue == "yes" || parmvalue == "true")
                    v = 1;
                _number[index - 1] = v;
                IDomain dm;
                dm.prepare("boolean");
                def.domain(dm);
            }
        }
    }
    return def;
}
Exemplo n.º 3
0
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index)  {
    const Parameter& parm = expr.parm(index);
    DataDefinition def;
    QString parmvalue = parm.value();
    IlwisTypes ptype = parm.valuetype();
    if (hasType(ptype,itRASTER)) {
        IRasterCoverage cov;
        if (cov.prepare(parmvalue)) {
            def = cov->datadef();
            _coverages[index - 1] = cov.as<Coverage>();
        }
    } else {
        bool ok;
        _number[index - 1] = parmvalue.toDouble(&ok);
        if ( ok){
            IDomain dom("code=domain:value");
            def.domain(dom);
        } else {
            std::vector<QString> bools = {"true","false","yes","no","?"};
            auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower());
            if ( iter != bools.end()) {
                int v = 0;
                if ( parmvalue == "?" )
                    v= 2;
                else if ( parmvalue == "yes" || parmvalue == "true")
                    v = 1;
                _number[index - 1] = v;
                IDomain dm;
                dm.prepare("boolean");
                def.domain(dm);
            }
        }
    }
    return def;
}
void startApplication( OperationExpression opExpr, OperationCatalogModel *operationCatalogModel){

    QString result;
    std::future<bool> resultApplication = std::async(runApplication, opExpr,&result) ;

    if(!resultApplication.get()) {
        throw ErrorObject(TR("running %1 failed").arg(opExpr.name()));
    }
    emit operationCatalogModel->updateCatalog(QUrl("ilwis://internalcatalog")); // TODO
}
Exemplo n.º 5
0
DataDefinition IfOperation::findOutputDataDef(const OperationExpression &expr ) {
    IDomain dm;
    QString domName = expr.parm(0,false).domain();
    if ( domName != sUNDEF && domName != "") {
        if( dm.prepare(domName))
            return DataDefinition(dm);
    }
    DataDefinition def1 = findParameterDataDef(expr,1);
    DataDefinition def2 = findParameterDataDef(expr,2);

    return DataDefinition::merge(def1,def2);
}
Exemplo n.º 6
0
std::vector<QString> GenerateScriptNode::executeOperation(const OperationExpression &expression, const std::map<quint64, int> &idmap, QStringList& script, const QString& whitespace)
{
    auto getValue = [&](const WorkFlowParameter& parm, const OperationExpression& expression, const std::map<quint64, int>& idmap)-> QVariant{
        auto iter = idmap.find(parm.id());
        if  ( iter != idmap.end())       {
            int idx = (*iter).second;
            QString value =  expression.parm(idx).value();
            if ( hasType(parm.valueType(), itILWISOBJECT)){
                if ( value.indexOf("?input") != 0){
                    if ( value.indexOf("://") != -1){
                        value = "'"     + value + "'";
                    }
                }
            }
            return value;
        }
        return parameterValue(parm.order());
    };
    int inputCount = _node->inputCount();
    for(int i=0; i < inputCount; ++i){
        WorkFlowParameter& parameter = _node->inputRef(i);
        if ( parameterValue(i) == sUNDEF){
            if (parameter.inputLink()) {
                GenerateScriptNode exNode(parameter.inputLink());
                auto outs = exNode.execute(expression, idmap, script,whitespace);
                if ( parameter.outputParameterIndex() < outs.size())
                    _parameterValues[i] = outs[parameter.outputParameterIndex()];
            }
        }
    }

    SPOperationNode opNode = std::static_pointer_cast<OperationNode>(_node);
    IOperationMetaData metadata = opNode->operation();
    QString expr = "ilwis.Engine.do('"+ metadata->name()  + "',";
    QString parms;
    for(int i=0; i < inputCount; ++i){
        WorkFlowParameter& inParam = _node->inputRef(i);
        if ( parms != "")
            parms += ",";
        if ( hasType(inParam.valueType(),itILWISOBJECT)){
            parms += getValue(inParam, expression, idmap).toString();
        }else if ( hasType(inParam.valueType(), itINTEGER | itFLOAT | itDOUBLE )) {
            QString val = getValue(inParam,expression, idmap).toString();
            bool ok;
            val.toDouble(&ok); // some parms can be strings or numbers; we test what it actually is
            if (!ok)
                val = "\'" + val + "\'";
            parms += val;
        } else if (hasType(inParam.valueType(),itSTRING)){
            parms += "\'" + getValue(inParam,expression, idmap).toString() + "\'";
        }else
            parms += getValue(inParam,expression, idmap).toString();
    }
    std::vector<QString> names;
    QString nameslist;
    for(int i=0; i < opNode->operation()->outputParameterCount(); ++i){
        QString name = opNode->operation()->name() + "_" + QString::number(_node->id()) + "_" + QString::number(i);
        names.push_back(name);
        nameslist = nameslist + (i==0 ? "" : ",") + name;
    }
    expr = nameslist + (nameslist!="" ? "=" : "") + expr;
    expr = expr + parms + ")";
    if(!script.contains(expr)){

        script.append(whitespace + expr);
    }

    return names;

}