On Wed, 19 Aug 2009 23:18:02 +0200
Felix Hartmann <[email protected]> wrote:

> Could you or someone try to modify this patch so that it compiles 
> against mkgmap 1140.

Try attached.

Not been tested, so please verify it works as expected.

Cheers,

Mark

diff --git a/src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java b/src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java
index bf00c85..91bdbee 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/ActionRule.java
@@ -52,7 +52,7 @@ public class ActionRule implements Rule {
 		this.type = null;
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		if (expression == null || expression.eval(el)) {
 			for (Action a : actions)
 				a.perform(el);
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java b/src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java
index cbbb913..b7b5248 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/ExpressionRule.java
@@ -28,22 +28,22 @@ import uk.me.parabola.mkgmap.reader.osm.Rule;
  * @author Steve Ratcliffe
  */
 public class ExpressionRule implements Rule {
-	private final Op exression;
+	private final Op expression;
 	private final GType gtype;
 
-	public ExpressionRule(Op exression, GType gtype) {
-		this.exression = exression;
+	public ExpressionRule(Op expression, GType gtype) {
+		this.expression = expression;
 		this.gtype = gtype;
 	}
 
-	public GType resolveType(Element el) {
-		if (exression.eval(el))
+	public GType resolveType(Element el, GType pre) {
+		if (expression.eval(el))
 			return gtype;
 
 		return null;
 	}
 
 	public String toString() {
-		return exression.toString() + ' ' + gtype;
+		return expression.toString() + ' ' + gtype;
 	}
 }
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java b/src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java
index 836547d..315c4ad 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/FixedRule.java
@@ -32,7 +32,7 @@ public class FixedRule implements Rule {
 		this.gtype = gtype;
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		return gtype;
 	}
 
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java b/src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java
index e93539e..33ce15e 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/RuleSet.java
@@ -63,14 +63,14 @@ public class RuleSet implements Rule {
 		return rules.entrySet();
 	}
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		GType foundType = null;
 		for (String tagKey : el) {
 			Rule rule = rules.get(tagKey);
 			if (rule != null) {
-				GType type = rule.resolveType(el);
+				GType type = rule.resolveType(el, pre);
 				if (type != null) {
-					if (foundType == null || type.isBetterPriority(foundType)) {
+					if ((foundType == null || type.isBetterPriority(foundType)) && (pre == null || pre.isBetterPriority(type))) {
 						foundType = type;
 					}
 				}
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java b/src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java
index 6b46871..72b5a59 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/SequenceRule.java
@@ -34,9 +34,9 @@ import uk.me.parabola.mkgmap.reader.osm.Rule;
 public class SequenceRule implements Rule, Iterable<Rule> {
 	private final List<Rule> ruleList = new ArrayList<Rule>();
 
-	public GType resolveType(Element el) {
+	public GType resolveType(Element el, GType pre) {
 		for (Rule r : ruleList) {
-			GType type = r.resolveType(el);
+			GType type = r.resolveType(el, pre);
 			if (type != null)
 				return type;
 		}
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
index 8ae3b94..ca81ccd 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
@@ -245,26 +245,36 @@ public class StyledConverter implements OsmConverter {
 			foundType = makeGTypeFromTags(way);
 			if(foundType == null)
 				return;
+			if (foundType.getFeatureKind() == GType.POLYLINE) {
+				if(foundType.isRoad())
+					addRoad(way, foundType);
+				else
+					addLine(way, foundType);
+			}
+			else
+				addShape(way, foundType);
 		}
 		else {
 			preConvertRules(way);
 
-			foundType = wayRules.resolveType(way);
-			if (foundType == null)
-				return;
 
-			postConvertRules(way, foundType);
-		}
+			do {
+				foundType = wayRules.resolveType(way, foundType);
+				if (foundType == null)
+					return;
+  
+				postConvertRules(way, foundType);
 
-		if (foundType.getFeatureKind() == GType.POLYLINE) {
-		    if(foundType.isRoad() &&
-			   !MapElement.hasExtendedType(foundType.getType()))
-				addRoad(way, foundType);
-		    else
-				addLine(way, foundType);
+				if (foundType.getFeatureKind() == GType.POLYLINE) {
+					if(foundType.isRoad())
+						addRoad(way, foundType);
+					else
+						addLine(way, foundType);
+				}
+				else
+					addShape(way, foundType);
+			} while (!foundType.isFinal());
 		}
-		else
-			addShape(way, foundType);
 	}
 
 	/**
@@ -280,18 +290,21 @@ public class StyledConverter implements OsmConverter {
 			foundType = makeGTypeFromTags(node);
 			if(foundType == null)
 				return;
+			addPoint(node, foundType);
 		}
 		else {
 			preConvertRules(node);
 
-			foundType = nodeRules.resolveType(node);
-			if (foundType == null)
-				return;
+			do {
+				foundType = nodeRules.resolveType(node, foundType);
+				if (foundType == null)
+					return;
 
-			postConvertRules(node, foundType);
-		}
+				postConvertRules(node, foundType);
 
-		addPoint(node, foundType);
+				addPoint(node, foundType);
+			} while (!foundType.isFinal());
+		}
 	}
 
 	/**
@@ -347,7 +360,7 @@ public class StyledConverter implements OsmConverter {
 	public void convertRelation(Relation relation) {
 		// Relations never resolve to a GType and so we ignore the return
 		// value.
-		relationRules.resolveType(relation);
+		relationRules.resolveType(relation, null);
 
 		if(relation instanceof RestrictionRelation) {
 			RestrictionRelation rr = (RestrictionRelation)relation;
@@ -380,7 +393,7 @@ public class StyledConverter implements OsmConverter {
 
 		clipper.clipShape(shape, collector);
 		
-		GType pointType = nodeRules.resolveType(way);
+		GType pointType = nodeRules.resolveType(way, null);
 		
 		if(pointType != null)
 			shape.setPoiType(pointType.getType());
diff --git a/src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java b/src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java
index 5dd987b..0c5c193 100644
--- a/src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java
+++ b/src/uk/me/parabola/mkgmap/osmstyle/TypeReader.java
@@ -58,6 +58,10 @@ public class TypeReader {
 				gt.setRoadSpeed(nextIntValue(ts));
 			} else if (w.equals("copy")) {
 				// reserved word.  not currently used
+			} else if (w.equals("continue")) {
+				gt.setContinue();
+			} else if (w.equals("stop")) {
+				gt.setFinal();
 			} else {
 				throw new SyntaxException(ts, "Unrecognised type command '" + w + '\'');
 			}
diff --git a/src/uk/me/parabola/mkgmap/reader/osm/GType.java b/src/uk/me/parabola/mkgmap/reader/osm/GType.java
index fc35e84..9df318d 100644
--- a/src/uk/me/parabola/mkgmap/reader/osm/GType.java
+++ b/src/uk/me/parabola/mkgmap/reader/osm/GType.java
@@ -58,6 +58,11 @@ public class GType {
 
 	private boolean road;
 
+	// control flag, whether this element defines
+	// the final conversion, or whether we shall search
+	// for further matching elements
+	private boolean FinalElement = true;
+	
 	public GType(int featureKind, String type) {
 		priority = nextPriority();
 		this.featureKind = featureKind;
@@ -190,6 +195,18 @@ public class GType {
 		return road;
 	}
 
+	public void setFinal() {
+		FinalElement = true;
+	}
+	
+	public void setContinue() {
+		FinalElement = false;
+	}
+	
+	public boolean isFinal() {
+		return FinalElement;
+	}
+	
 	public static void push() {
 		nextPriority += PRIORITY_PUSH;
 	}
diff --git a/src/uk/me/parabola/mkgmap/reader/osm/Rule.java b/src/uk/me/parabola/mkgmap/reader/osm/Rule.java
index 106ac7d..b709c67 100644
--- a/src/uk/me/parabola/mkgmap/reader/osm/Rule.java
+++ b/src/uk/me/parabola/mkgmap/reader/osm/Rule.java
@@ -29,7 +29,8 @@ public interface Rule {
 	 * represent it.
 	 *
 	 * @param el The element as read from an OSM xml file in 'tag' format.
+	 * @param pre The previous garmin type generated from the element.
 	 * @return Enough information to represent this as a garmin type.
 	 */
-	public GType resolveType(Element el);
+	public GType resolveType(Element el, GType pre);
 }
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to