Search in sources :

Example 16 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class ActionRule method resolveType.

public int resolveType(int cacheId, Element el, TypeResult result) {
    Element element = el;
    if (expression != null) {
        numEval++;
        if (!expression.eval(cacheId, element))
            return cacheId;
        numTrue++;
        // There is another reason we need to copy: since there will be
        if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
            element = element.copy();
        }
    }
    // an action will be performed, so we may have to invalidate the cache
    boolean invalidate_cache = false;
    for (Action a : actions) {
        if (a.perform(element)) {
            invalidate_cache = true;
        }
    }
    if (invalidate_cache)
        cacheId++;
    if (type != null && finalizeRule != null) {
        if (el == element && type.isContinueSearch())
            // if there is a continue statement changes performed in
            // the finalize block must not be persistent
            element = element.copy();
        // there is a type so first execute the finalize rules
        if (type.getDefaultName() != null)
            element.addTag("mkgmap:default_name", type.getDefaultName());
        cacheId = finalizeRule.resolveType(cacheId, element, finalizeTypeResult);
    }
    result.add(element, type);
    return cacheId;
}
Also used : Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element)

Example 17 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class ActionRule method resolveType.

public void resolveType(Element el, TypeResult result) {
    Element element = el;
    if (expression != null) {
        numEval++;
        if (!expression.eval(element))
            return;
        numTrue++;
        // There is another reason we need to copy: since there will be
        if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
            element = element.copy();
        }
    }
    for (Action a : actions) a.perform(element);
    if (type != null && finalizeRule != null) {
        if (el == element && type.isContinueSearch())
            // if there is a continue statement changes performed in
            // the finalize block must not be persistent
            element = element.copy();
        // there is a type so first execute the finalize rules
        if (type.getDefaultName() != null)
            element.addTag("mkgmap:default_name", type.getDefaultName());
        finalizeRule.resolveType(element, finalizeTypeResult);
    }
    result.add(element, type);
}
Also used : Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element)

Example 18 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class RuleFileReader method readIf.

private boolean readIf(TokenScanner scanner, ExpressionReader expressionReader) {
    // Take the 'if' token
    Token tok = scanner.nextToken();
    scanner.skipSpace();
    // If 'if'' is being used as a keyword then it is followed by a '('.
    Token next = scanner.peekToken();
    if (next.getType() == TokType.SYMBOL && next.isValue("(")) {
        Op origExpr = expressionReader.readConditions();
        scanner.validateNext("then");
        // add rule expr { set <ifVar> = true }
        String ifVar = getNextIfVar();
        ArrayList<Action> actions = new ArrayList<>(1);
        actions.add(new AddTagAction(ifVar, "true", true));
        ActionList actionList = new ActionList(actions, Collections.singleton(ifVar + "=true"));
        saveRule(scanner, origExpr, actionList, null);
        // create expression (<ifVar> = true)
        EqualsOp safeExpr = new EqualsOp();
        safeExpr.setFirst(new GetTagFunction(ifVar));
        safeExpr.setSecond(new ValueOp("true"));
        Op[] ifExpressions = { origExpr, safeExpr };
        ifStack.addLast(ifExpressions);
        return true;
    } else {
        // Wrong syntax for if statement, so push back token to allow a possible expression to be read
        scanner.pushToken(tok);
    }
    return false;
}
Also used : Op(uk.me.parabola.mkgmap.osmstyle.eval.Op) ValueOp(uk.me.parabola.mkgmap.osmstyle.eval.ValueOp) EqualsOp(uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp) NotOp(uk.me.parabola.mkgmap.osmstyle.eval.NotOp) EqualsOp(uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp) DeleteAction(uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction) AddTagAction(uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) AddTagAction(uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction) ValueOp(uk.me.parabola.mkgmap.osmstyle.eval.ValueOp) ArrayList(java.util.ArrayList) GetTagFunction(uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction) Token(uk.me.parabola.mkgmap.scan.Token) ActionList(uk.me.parabola.mkgmap.osmstyle.actions.ActionList)

Aggregations

Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)18 Element (uk.me.parabola.mkgmap.reader.osm.Element)15 Test (org.junit.Test)13 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)3 AddTagAction (uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction)2 DeleteAction (uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction)2 ArrayList (java.util.ArrayList)1 ActionList (uk.me.parabola.mkgmap.osmstyle.actions.ActionList)1 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)1 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)1 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)1 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)1 GetTagFunction (uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction)1 Token (uk.me.parabola.mkgmap.scan.Token)1