Changeset 18384 in osm
- Timestamp:
- 2009-10-31T02:26:30+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java
r18194 r18384 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.geom.Area; 5 6 import java.awt.geom.Point2D; 6 7 import java.util.*; 7 8 9 import org.openstreetmap.josm.Main; 8 10 import org.openstreetmap.josm.command.ChangeCommand; 9 11 import org.openstreetmap.josm.command.Command; … … 11 13 import org.openstreetmap.josm.data.osm.Node; 12 14 import org.openstreetmap.josm.data.osm.Way; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 16 import org.openstreetmap.josm.plugins.validator.Severity; 14 17 import org.openstreetmap.josm.plugins.validator.Test; … … 27 30 28 31 private boolean fixable = false; 29 32 30 33 /** 31 34 * Constructor … … 38 41 39 42 @Override 40 public void visit(Way w )43 public void visit(Way way) 41 44 { 42 if(!w .isUsable() || w.isClosed())45 if(!way.isUsable() || way.isClosed()) 43 46 return; 44 47 45 String natural = w .get("natural");48 String natural = way.get("natural"); 46 49 if(natural == null || !natural.equals("coastline")) 47 50 return; 48 51 49 Node f = w.firstNode();50 Node l = w.lastNode();51 Way prev = null;52 Way next = null;52 Node firstNode = way.firstNode(); 53 Node lastNode = way.lastNode(); 54 Way previousWay = null; 55 Way nextWay = null; 53 56 54 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(f )) {57 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(firstNode)) { 55 58 natural = parent.get("natural"); 56 if (parent instanceof Way && !w .equals(parent) && (natural != null && "coastline".equals(natural))) {57 prev = (Way)parent;59 if (parent instanceof Way && !way.equals(parent) && (natural != null && "coastline".equals(natural))) { 60 previousWay = (Way)parent; 58 61 break; 59 62 } 60 63 } 61 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(l )) {64 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(lastNode)) { 62 65 natural = parent.get("natural"); 63 if (parent instanceof Way && !w .equals(parent) && (natural != null && "coastline".equals(natural))) {64 next = (Way)parent;66 if (parent instanceof Way && !way.equals(parent) && (natural != null && "coastline".equals(natural))) { 67 nextWay = (Way)parent; 65 68 break; 66 69 } … … 69 72 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 70 73 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 71 primitives.add(w );74 primitives.add(way); 72 75 73 if (prev == null || next == null) { 74 if (prev == null) 75 highlight.add(f); 76 if (next == null) 77 highlight.add(l); 76 OsmDataLayer layer = Main.map.mapView.getEditLayer(); 77 Area downloadedArea = null; 78 if (layer != null) 79 downloadedArea = layer.data.getDataSourceArea(); 78 80 79 errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"), 80 UNCONNECTED_COASTLINE, primitives, highlight)); 81 if (previousWay == null || nextWay == null) { 82 boolean firstNodeUnconnected = false; 83 boolean lastNodeUnconnected = false; 84 85 if (previousWay == null && (downloadedArea == null || downloadedArea.contains(firstNode.getCoor()))) { 86 firstNodeUnconnected = true; 87 highlight.add(firstNode); 88 } 89 if (nextWay == null && (downloadedArea == null || downloadedArea.contains(lastNode.getCoor()))) { 90 lastNodeUnconnected = true; 91 highlight.add(lastNode); 92 } 93 94 if (firstNodeUnconnected || lastNodeUnconnected) 95 errors.add(new TestError(this, Severity.ERROR, tr("Unconnected coastline"), 96 UNCONNECTED_COASTLINE, primitives, highlight)); 81 97 } 82 98 83 boolean f uo = (prev != null && !f.equals(prev.lastNode()));84 boolean l uo = (next != null && !l.equals(next.firstNode()));99 boolean firstNodeUnordered = (previousWay != null && !firstNode.equals(previousWay.lastNode())); 100 boolean lastNodeUnordered = (nextWay != null && !lastNode.equals(nextWay.firstNode())); 85 101 86 if (f uo || luo) {87 if (f uo && luo) {102 if (firstNodeUnordered || lastNodeUnordered) { 103 if (firstNodeUnordered && lastNodeUnordered && !previousWay.equals(nextWay)) { 88 104 errors.add(new TestError(this, Severity.ERROR, tr("Reversed coastline"), 89 105 REVERSED_COASTLINE, primitives)); 90 106 91 107 } else { 92 if (f uo)93 highlight.add(f );94 if (l uo)95 highlight.add(l );108 if (firstNodeUnordered) 109 highlight.add(firstNode); 110 if (lastNodeUnordered) 111 highlight.add(lastNode); 96 112 97 113 errors.add(new TestError(this, Severity.ERROR, tr("Unordered coastline"), … … 104 120 public Command fixError(TestError testError) { 105 121 if (isFixable(testError)) { 106 Way w = (Way) testError.getPrimitives().iterator().next();107 Way wnew = new Way(w);122 Way way = (Way) testError.getPrimitives().iterator().next(); 123 Way newWay = new Way(way); 108 124 109 List<Node> nodesCopy = wnew.getNodes();125 List<Node> nodesCopy = newWay.getNodes(); 110 126 Collections.reverse(nodesCopy); 111 wnew.setNodes(nodesCopy);127 newWay.setNodes(nodesCopy); 112 128 113 return new ChangeCommand(w , wnew);129 return new ChangeCommand(way, newWay); 114 130 } 115 131
Note:
See TracChangeset
for help on using the changeset viewer.