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();
}
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;
}
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"));
}
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"));
}
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"));
}
Aggregations