Search in sources :

Example 1 with Action

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

the class ActionRule method toString.

public String toString() {
    StringBuilder fmt = new StringBuilder();
    if (expression != null)
        fmt.append(expression);
    fmt.append(" {");
    for (Action a : actions) fmt.append(a);
    fmt.append("}");
    if (type != null) {
        fmt.append(' ');
        fmt.append(type);
    }
    return fmt.toString();
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action)

Example 2 with Action

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

the class RuleFileReader method possiblyChanged.

/**
 * Check if the expression depends on tags modified by an action in the action list.
 * @param expr the expression to check
 * @param actionList the ActionList
 * @return true if the value of the expression depends on one or more of the changeable tags
 */
private boolean possiblyChanged(Op expr, ActionList actionList) {
    Set<String> evaluated = expr.getEvaluatedTagKeys();
    if (evaluated.isEmpty())
        return false;
    for (String tagKey : evaluated) {
        for (String s : actionList.getChangeableTags()) {
            int pos = s.indexOf("=");
            String key = pos > 0 ? s.substring(0, pos) : s;
            if (tagKey.equals(key)) {
                return true;
            }
        }
        for (Action a : actionList.getList()) {
            if (a instanceof DeleteAction) {
                if (a.toString().contains(tagKey)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : DeleteAction(uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction) AddTagAction(uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) DeleteAction(uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction)

Example 3 with Action

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

the class ActionReaderTest method testApplyAction.

/**
 * The apply action works on the members of relations.
 */
@Test
public void testApplyAction() {
    List<Action> actions = readActionsFromString("{apply {" + "add route=bike;" + "set foo=bar; }" + "}\n");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    assertNull("Tag not set on relation", rel.getTag("route"));
    // Will be set on all members as there is no role filter.
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    Element el2 = elements.get(1).getValue();
    assertEquals("route tag added to second", "bike", el2.getTag("route"));
    assertEquals("foo tag set to second", "bar", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 4 with Action

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

the class ActionReaderTest method testSimpleSet.

@Test
public void testSimpleSet() {
    List<Action> actions = readActionsFromString("{set park=yes}");
    assertEquals("one action", 1, actions.size());
    Element el = stdElementRun(actions);
    assertEquals("park overwritten", "yes", el.getTag("park"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 5 with Action

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

the class ActionReaderTest method testApplyWithRole.

/**
 * You can have a role filter, so that the actions are only applied
 * to members with the given role.
 */
@Test
public void testApplyWithRole() {
    List<Action> actions = readActionsFromString("{apply role=bar {" + "add route=bike;" + "set foo=bar; }}");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    // Wrong role, so not applied.
    Element el2 = elements.get(1).getValue();
    assertNull("route tag not added to second element (role=foo)", el2.getTag("route"));
    assertNull("foo tag not set in second element (role=foo)", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

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