Changeset 20365 in osm for applications/editors
- Timestamp:
- 2010-03-08T09:25:09+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java
r18092 r20365 239 239 } 240 240 241 @SuppressWarnings("unchecked") 241 242 public void visitHighlighted(ValidatorVisitor v) { 242 243 for (Object o : highlighted) { … … 245 246 else if (o instanceof WaySegment) 246 247 v.visit((WaySegment) o); 248 else if (o instanceof List<?>) { 249 v.visit((List<Node>)o); 250 } 247 251 } 248 252 } … … 288 292 } 289 293 290 /** 291 * Draws a line around the segment 292 * 293 * @param s The segment 294 * @param color The color 295 */ 296 public void drawSegment(Node n1, Node n2, Color color) { 297 Point p1 = mv.getPoint(n1); 298 Point p2 = mv.getPoint(n2); 294 public void drawSegment(Point p1, Point p2, Color color) { 299 295 g.setColor(color); 300 296 … … 322 318 323 319 /** 320 * Draws a line around the segment 321 * 322 * @param s The segment 323 * @param color The color 324 */ 325 public void drawSegment(Node n1, Node n2, Color color) { 326 drawSegment(mv.getPoint(n1), mv.getPoint(n2), color); 327 } 328 329 /** 324 330 * Draw a small rectangle. 325 331 * White if selected (as always) or red otherwise. … … 333 339 334 340 public void visit(Way w) { 335 Node lastN = null; 336 for (Node n : w.getNodes()) { 337 if (lastN == null) { 338 lastN = n; 339 continue; 340 } 341 if (isSegmentVisible(lastN, n)) { 342 drawSegment(lastN, n, severity.getColor()); 343 } 344 lastN = n; 345 } 341 visit(w.getNodes()); 346 342 } 347 343 … … 389 385 return true; 390 386 } 387 388 public void visit(List<Node> nodes) { 389 Node lastN = null; 390 for (Node n : nodes) { 391 if (lastN == null) { 392 lastN = n; 393 continue; 394 } 395 if (n.isDrawable() && isSegmentVisible(lastN, n)) { 396 drawSegment(lastN, n, severity.getColor()); 397 } 398 lastN = n; 399 } 400 } 391 401 } 392 402 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorDialog.java
r19335 r20365 18 18 import java.util.HashSet; 19 19 import java.util.LinkedList; 20 import java.util.List; 20 21 import java.util.Set; 21 22 … … 35 36 import org.openstreetmap.josm.data.SelectionChangedListener; 36 37 import org.openstreetmap.josm.data.osm.DataSet; 38 import org.openstreetmap.josm.data.osm.Node; 37 39 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 40 import org.openstreetmap.josm.data.osm.WaySegment; … … 432 434 visit(ws.way.getNodes().get(ws.lowerIndex)); 433 435 visit(ws.way.getNodes().get(ws.lowerIndex + 1)); 436 } 437 438 public void visit(List<Node> nodes) { 439 for (Node n: nodes) { 440 visit(n); 441 } 434 442 } 435 443 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ValidatorVisitor.java
r13497 r20365 1 1 package org.openstreetmap.josm.plugins.validator; 2 2 3 import java.util.List; 4 5 import org.openstreetmap.josm.data.osm.Node; 3 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 4 7 import org.openstreetmap.josm.data.osm.WaySegment; … … 6 9 public interface ValidatorVisitor { 7 10 void visit(OsmPrimitive p); 8 9 11 void visit(WaySegment ws); 12 void visit(List<Node> nodes); 10 13 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/MultipolygonTest.java
r19335 r20365 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.geom.GeneralPath; 6 import java.util.ArrayList; 7 import java.util.Collection; 8 import java.util.Collections; 9 import java.util.List; 10 5 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.data.osm.Node; 6 13 import org.openstreetmap.josm.data.osm.Relation; 7 14 import org.openstreetmap.josm.data.osm.RelationMember; 15 import org.openstreetmap.josm.data.osm.Way; 8 16 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon; 9 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon. PolyData;17 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.JoinedWay; 10 18 import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.PolyData.Intersection; 11 19 import org.openstreetmap.josm.plugins.validator.Severity; … … 22 30 protected static final int CROSSING_WAYS = 1606; 23 31 32 private final List<List<Node>> nonClosedWays = new ArrayList<List<Node>>(); 33 24 34 public MultipolygonTest() { 25 35 super(tr("Multipolygon"), … … 27 37 } 28 38 39 private List<List<Node>> joinWays(Collection<Way> ways) { 40 List<List<Node>> result = new ArrayList<List<Node>>(); 41 List<Way> waysToJoin = new ArrayList<Way>(); 42 for (Way way: ways) { 43 if (way.isClosed()) { 44 result.add(way.getNodes()); 45 } else { 46 waysToJoin.add(way); 47 } 48 } 49 50 for (JoinedWay jw: Multipolygon.joinWays(waysToJoin)) { 51 if (!jw.isClosed()) { 52 nonClosedWays.add(jw.getNodes()); 53 } 54 result.add(jw.getNodes()); 55 } 56 return result; 57 } 58 59 private GeneralPath createPath(List<Node> nodes) { 60 GeneralPath result = new GeneralPath(); 61 result.moveTo((float)nodes.get(0).getCoor().lat(), (float)nodes.get(0).getCoor().lon()); 62 for (int i=1; i<nodes.size(); i++) { 63 Node n = nodes.get(i); 64 result.lineTo((float)n.getCoor().lat(), (float)n.getCoor().lon()); 65 } 66 return result; 67 } 68 69 private List<GeneralPath> createPolygons(List<List<Node>> joinedWays) { 70 List<GeneralPath> result = new ArrayList<GeneralPath>(); 71 for (List<Node> way: joinedWays) { 72 if (way.size() >= 3) { 73 result.add(createPath(way)); 74 } 75 } 76 return result; 77 } 78 79 private Intersection getPolygonIntersection(GeneralPath outer, List<Node> inner) { 80 boolean inside = false; 81 boolean outside = false; 82 83 for (Node n: inner) { 84 boolean contains = outer.contains(n.getCoor().lat(), n.getCoor().lon()); 85 inside = inside | contains; 86 outside = outside | !contains; 87 if (inside & outside) { 88 return Intersection.CROSSING; 89 } 90 } 91 92 return inside?Intersection.INSIDE:Intersection.OUTSIDE; 93 } 94 29 95 @Override 30 96 public void visit(Relation r) { 97 nonClosedWays.clear(); 31 98 if ("multipolygon".equals(r.get("type"))) { 32 99 checkMembersAndRoles(r); … … 34 101 Multipolygon polygon = new Multipolygon(Main.map.mapView); 35 102 polygon.load(r); 36 37 if (polygon.hasNonClosedWays()) {38 errors.add( new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY, r));39 }40 103 41 104 if (polygon.getOuterWays().isEmpty()) { … … 49 112 } 50 113 51 for (PolyData pdInner: polygon.getInnerPolygons()) { 52 PolyData pdOuter = polygon.findOuterPolygon(pdInner, polygon.getOuterPolygons()); 53 if (pdOuter == null) { 54 errors.add(new TestError(this, Severity.WARNING, tr("Multipolygon inner way is outside."), INNER_WAY_OUTSIDE, r)); 55 } else if (pdOuter.contains(pdInner.poly) == Intersection.CROSSING) { 56 errors.add(new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"), CROSSING_WAYS, r)); 114 List<List<Node>> innerWays = joinWays(polygon.getInnerWays()); // Side effect - sets nonClosedWays 115 List<List<Node>> outerWays = joinWays(polygon.getOuterWays()); 116 117 if (!nonClosedWays.isEmpty()) { 118 errors.add( new TestError(this, Severity.WARNING, tr("Multipolygon is not closed"), NON_CLOSED_WAY, Collections.singletonList(r), nonClosedWays)); 119 } 120 121 // For painting is used Polygon class which works with ints only. For validation we need more precision 122 List<GeneralPath> outerPolygons = createPolygons(outerWays); 123 for (List<Node> pdInner: innerWays) { 124 boolean outside = true; 125 boolean crossing = false; 126 List<Node> outerWay = null; 127 for (int i=0; i<outerWays.size(); i++) { 128 GeneralPath outer = outerPolygons.get(i); 129 Intersection intersection = getPolygonIntersection(outer, pdInner); 130 outside = outside & intersection == Intersection.OUTSIDE; 131 if (intersection == Intersection.CROSSING) { 132 crossing = true; 133 outerWay = outerWays.get(i); 134 } 135 } 136 if (outside | crossing) { 137 List<List<Node>> highlights = new ArrayList<List<Node>>(); 138 highlights.add(pdInner); 139 if (outside) { 140 errors.add(new TestError(this, Severity.WARNING, tr("Multipolygon inner way is outside."), INNER_WAY_OUTSIDE, Collections.singletonList(r), highlights)); 141 } else if (crossing) { 142 highlights.add(outerWay); 143 errors.add(new TestError(this, Severity.WARNING, tr("Intersection between multipolygon ways"), CROSSING_WAYS, Collections.singletonList(r), highlights)); 144 } 57 145 } 58 146 }
Note:
See TracChangeset
for help on using the changeset viewer.