Changeset 4843 in osm for applications/editors/josm
- Timestamp:
- 2007-10-07T13:25:21+02:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator
- Files:
-
- 2 added
- 6 deleted
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/ErrorLayer.java
r4086 r4843 51 51 * Draw all primitives in this layer but do not draw modified ones (they 52 52 * are drawn by the edit layer). 53 * Draw nodes last to overlap the segments they belong to.53 * Draw nodes last to overlap the ways they belong to. 54 54 */ 55 55 @SuppressWarnings("unchecked") -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/GridLayer.java
r4162 r4843 22 22 23 23 /** 24 * A debug layer for testing the grid cells a segment orway crosses.24 * A debug layer for testing the grid cells a way crosses. 25 25 * 26 26 * @author frsantos … … 166 166 } 167 167 168 public void visit(Segment s)169 {170 for( Point2D p : Util.getSegmentCells(s, gridDetail))171 {172 drawCell( p.getX(), p.getY() );173 }174 }175 176 168 public void visit(Way w) 177 169 { 178 for( Segment s : w.segments ) 179 visit(s); 170 Node lastN = null; 171 for (Node n : w.nodes) { 172 if (lastN == null) { 173 lastN = n; 174 continue; 175 } 176 for (Point2D p : Util.getSegmentCells(lastN, n, gridDetail)) { 177 drawCell( p.getX(), p.getY() ); 178 } 179 lastN = n; 180 } 180 181 } 181 182 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
r4162 r4843 46 46 { 47 47 DuplicateNode.class, 48 DuplicateSegment.class, 49 SingleNodeSegment.class, 48 OverlappingWays.class, 50 49 UntaggedNode.class, 51 TaggedSegment.class,52 50 UntaggedWay.class, 53 UnorderedWay.class,54 51 SpellCheck.class, 55 OrphanSegment.class, 56 ReusedSegment.class, 57 CrossingSegments.class, 52 DuplicatedWayNodes.class, 53 CrossingWays.class, 58 54 SimilarNamedWays.class, 59 55 Coastlines.class, -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/Test.java
r4087 r4843 20 20 * A test is a primitive visitor, so that it can access to all data to be 21 21 * validated. These primitives are always visited in the same order: nodes 22 * first, then segments, and ways last.22 * first, then ways. 23 23 * 24 24 * @author frsantos … … 115 115 /** 116 116 * Visits all primitives to be tested. These primitives are always visited 117 * in the same order: nodes first, then segments, and ways last.117 * in the same order: nodes first, then ways. 118 118 * 119 119 * @param selection The primitives to be tested … … 129 129 130 130 public void visit(Node n) {} 131 132 public void visit(Segment s) {}133 131 134 132 public void visit(Way w) {} -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/TestError.java
r3037 r4843 251 251 * @param color The color 252 252 */ 253 public void drawSegment( Segment s, Color color)254 { 255 Point p1 = mv.getPoint( s.from.eastNorth);256 Point p2 = mv.getPoint( s.to.eastNorth);253 public void drawSegment(Node n1, Node n2, Color color) 254 { 255 Point p1 = mv.getPoint(n1.eastNorth); 256 Point p2 = mv.getPoint(n2.eastNorth); 257 257 g.setColor(color); 258 258 … … 292 292 } 293 293 294 /**295 * Draw just a line between the points.296 * White if selected (as always) or green otherwise.297 */298 public void visit(Segment ls)299 {300 if( isSegmentVisible(ls) )301 drawSegment(ls, severity.getColor());302 }303 304 294 public void visit(Way w) 305 295 { 306 for (Segment ls : w.segments) 307 { 308 if (isSegmentVisible(ls)) 296 Node lastN = null; 297 for (Node n : w.nodes) { 298 if (lastN == null) { 299 lastN = n; 300 continue; 301 } 302 if (isSegmentVisible(lastN, n)) 309 303 { 310 drawSegment(l s, severity.getColor());304 drawSegment(lastN, n, severity.getColor()); 311 305 } 312 } 306 lastN = n; 307 } 313 308 } 314 309 … … 330 325 * @return true if the segment is visible 331 326 */ 332 protected boolean isSegmentVisible(Segment ls) { 333 if (ls.incomplete) return false; 334 Point p1 = mv.getPoint(ls.from.eastNorth); 335 Point p2 = mv.getPoint(ls.to.eastNorth); 327 protected boolean isSegmentVisible(Node n1, Node n2) { 328 Point p1 = mv.getPoint(n1.eastNorth); 329 Point p2 = mv.getPoint(n2.eastNorth); 336 330 if ((p1.x < 0) && (p2.x < 0)) return false; 337 331 if ((p1.y < 0) && (p2.y < 0)) return false; -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/Coastlines.java
r4029 r4843 7 7 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Segment;10 9 import org.openstreetmap.josm.data.osm.Way; 11 10 import org.openstreetmap.josm.plugins.validator.Severity; … … 72 71 continue; 73 72 74 int numSegments1 = w.segments.size(); 75 Segment start1 = w.segments.get(0); 76 Segment end1 = numSegments1 > 1 ? w.segments.get(numSegments1 - 1) : start1; 77 78 int numSegments2 = w2.segments.size(); 79 Segment start2 = w2.segments.get(0); 80 Segment end2 = numSegments2 > 1 ? w2.segments.get(numSegments2 - 1) : start2; 81 82 if( start1.from.equals(start2.from) || end1.to.equals(end2.to)) 73 if( w.nodes.get(0).equals(w2.nodes.get(0)) || w.nodes.get(w.nodes.size() - 1).equals(w2.nodes.get(w2.nodes.size() - 1))) 83 74 { 84 75 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/CrossingWays.java
r4815 r4843 17 17 * @author frsantos 18 18 */ 19 public class Crossing Segments extends Test19 public class CrossingWays extends Test 20 20 { 21 /** All segments, grouped by cells */21 /** All way segments, grouped by cells */ 22 22 Map<Point2D,List<ExtendedSegment>> cellSegments; 23 23 /** The already detected errors */ 24 Bag<Segment,Segment> errorSegments;24 HashSet<WaySegment> errorSegments; 25 25 26 26 /** 27 27 * Constructor 28 28 */ 29 public Crossing Segments()29 public CrossingWays() 30 30 { 31 super(tr("Crossing roads."),32 tr("This test checks if two roads, railways or waterways crosses in the same layer, but are not connected by a node."));31 super(tr("Crossing ways."), 32 tr("This test checks if two roads, railways or waterways crosses in the same layer, but are not connected by a node.")); 33 33 } 34 34 … … 38 38 { 39 39 cellSegments = new HashMap<Point2D,List<ExtendedSegment>>(1000); 40 errorSegments = new Bag<Segment,Segment>();40 errorSegments = new HashSet<WaySegment>(); 41 41 } 42 42 … … 62 62 63 63 String layer1 = w.get("layer"); 64 for(Segment s : w.segments) 65 { 66 if( s.incomplete ) 67 continue; 68 69 ExtendedSegment es1 = new ExtendedSegment(s, layer1, railway1, coastline1); 70 List<List<ExtendedSegment>> cellSegments = getSegments(s); 64 65 int nodesSize = w.nodes.size(); 66 for (int i = 0; i < nodesSize - 1; i++) { 67 WaySegment ws = new WaySegment(w, i); 68 ExtendedSegment es1 = new ExtendedSegment(ws, layer1, railway1, coastline1); 69 List<List<ExtendedSegment>> cellSegments = getSegments(es1.n1, es1.n2); 71 70 for( List<ExtendedSegment> segments : cellSegments) 72 71 { 73 72 for( ExtendedSegment es2 : segments) 74 73 { 75 if( errorSegments.contains(s, es2.s) || errorSegments.contains(es2.s,s))74 if (errorSegments.contains(ws) && errorSegments.contains(es2.ws)) 76 75 continue; 77 76 … … 79 78 String railway2 = es2.railway; 80 79 String coastline2 = es2.coastline; 81 if( (layer1 != null || layer2 != null) && (layer1 == null || !layer1.equals(layer2)))80 if (layer1 == null ? layer2 != null : !layer1.equals(layer2)) 82 81 continue; 83 82 … … 89 88 90 89 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 91 primitives.add(es1. s);92 primitives.add(es2. s);93 errors.add( new TestError(this, Severity.WARNING, tr("Crossing roads"), primitives) );90 primitives.add(es1.ws.way); 91 primitives.add(es2.ws.way); 92 errors.add( new TestError(this, Severity.WARNING, tr("Crossing ways"), primitives) ); 94 93 } 95 94 segments.add(es1); … … 99 98 100 99 /** 101 * Returns all the cells this segment crosses .Each cell contains the list100 * Returns all the cells this segment crosses. Each cell contains the list 102 101 * of segments already processed 103 102 * 104 * @param s The segment 103 * @param n1 The first node. 104 * @param n2 The second node. 105 105 * @return A list with all the cells the segment crosses. 106 106 */ 107 public List<List<ExtendedSegment>> getSegments( Segment s)107 public List<List<ExtendedSegment>> getSegments(Node n1, Node n2) 108 108 { 109 109 List<List<ExtendedSegment>> cells = new ArrayList<List<ExtendedSegment>>(); 110 for( Point2D cell : Util.getSegmentCells( s, 10000) )110 for( Point2D cell : Util.getSegmentCells(n1, n2, 10000) ) 111 111 { 112 112 List<ExtendedSegment> segments = cellSegments.get( cell ); … … 123 123 124 124 /** 125 * A segment is a line with the formula "y = a*x+b"125 * A way segment with some additional information 126 126 * @author frsantos 127 127 */ 128 class ExtendedSegment128 private class ExtendedSegment 129 129 { 130 /** The segment */ 131 Segment s; 130 public Node n1, n2; 131 132 public WaySegment ws; 132 133 133 134 /** The layer */ 134 String layer;135 public String layer; 135 136 136 137 /** The railway type */ 137 p rivateString railway;138 public String railway; 138 139 139 140 /** The coastline type */ 140 p rivateString coastline;141 public String coastline; 141 142 142 143 /** 143 144 * Constructor 144 * @param s Thesegment145 * @param ws The way segment 145 146 * @param layer The layer of the way this segment is in 146 147 * @param railway The railway type of the way this segment is in 147 148 * @param coastline The coastlyne typo of the way the segment is in 148 149 */ 149 public ExtendedSegment( Segments, String layer, String railway, String coastline)150 public ExtendedSegment(WaySegment ws, String layer, String railway, String coastline) 150 151 { 151 this.s = s; 152 this.ws = ws; 153 this.n1 = ws.way.nodes.get(ws.lowerIndex); 154 this.n2 = ws.way.nodes.get(ws.lowerIndex + 1); 152 155 this.layer = layer; 153 156 this.railway = railway; … … 162 165 public boolean intersects(ExtendedSegment s2) 163 166 { 164 Node n1From = this.s.from; 165 Node n1To = this.s.to; 166 Node n2From = s2.s.from; 167 Node n2To = s2.s.to; 168 if( n1From.equals(n2From) || n1To.equals(n2To) || 169 n1From.equals(n2To) || n1To.equals(n2From) ) 167 if( n1.equals(s2.n1) || n2.equals(s2.n2) || 168 n1.equals(s2.n2) || n2.equals(s2.n1) ) 170 169 { 171 170 return false; 172 171 } 173 172 174 return Line2D.linesIntersect(n1From.eastNorth.east(), 175 n1From.eastNorth.north(), 176 n1To.eastNorth.east(), 177 n1To.eastNorth.north(), 178 n2From.eastNorth.east(), 179 n2From.eastNorth.north(), 180 n2To.eastNorth.east(), 181 n2To.eastNorth.north()); 173 return Line2D.linesIntersect( 174 n1.eastNorth.east(), n1.eastNorth.north(), 175 n2.eastNorth.east(), n2.eastNorth.north(), 176 s2.n1.eastNorth.east(), s2.n1.eastNorth.north(), 177 s2.n2.eastNorth.east(), s2.n2.eastNorth.north()); 182 178 } 183 179 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/DuplicateNode.java
r2788 r4843 113 113 } 114 114 } 115 116 // Since some segment may disappear, we need to track those too 117 Collection<OsmPrimitive> seglist = new ArrayList<OsmPrimitive>(); 118 119 // Now do the merging 115 120 116 Collection<Command> cmds = new LinkedList<Command>(); 121 for (final Segment s : Main.ds.segments)122 {123 if( s.deleted || s.incomplete )124 continue;125 if( !nodes.contains( s.from ) && !nodes.contains( s.to ) )126 continue;127 128 Segment newseg = new Segment(s);129 if( nodes.contains( s.from ) )130 newseg.from = target;131 if( nodes.contains( s.to ) )132 newseg.to = target;133 117 134 // Is this node now a NULL node? 135 if( newseg.from == newseg.to ) 136 seglist.add(s); 137 else 138 cmds.add(new ChangeCommand(s,newseg)); 139 } 140 141 if( seglist.size() > 0 ) // Some segments to be deleted? 142 { 143 // We really want to delete this, but we must check if it is part of a way first 144 for (final Way w : Main.ds.ways) 145 { 146 Way newway = null; 147 if( w.deleted ) 148 continue; 149 for (final OsmPrimitive o : seglist ) 150 { 151 Segment s = (Segment)o; 152 if( w.segments.contains(s) ) 153 { 154 if( newway == null ) 155 newway = new Way(w); 156 newway.segments.remove(s); 157 } 158 } 159 if( newway != null ) // Made changes? 160 { 161 // If no segments left, delete the way 162 if( newway.segments.size() == 0 ) 163 cmds.add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{w}))); 164 else 165 cmds.add(new ChangeCommand(w,newway)); 166 } 167 } 168 cmds.add(new DeleteCommand(seglist)); 169 } 118 // Now search the ways for occurences of the nodes we are about to 119 // merge and replace them with the 'target' node 120 for (Way w : Main.ds.ways) { 121 if (w.deleted) continue; 122 // FIXME: use some fancy method from java.util.Collections and 123 // List.replace 124 Way wnew = null; 125 int len = w.nodes.size(); 126 for (int i = 0; i < len; i++) { 127 if (!nodes.contains(w.nodes.get(i))) continue; 128 if (wnew == null) wnew = new Way(w); 129 wnew.nodes.set(i, target); 130 } 131 if (wnew != null) { 132 cmds.add(new ChangeCommand(w, wnew)); 133 } 134 } 170 135 171 136 cmds.add(new DeleteCommand(nodes)); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SpellCheck.java
r4087 r4843 207 207 { 208 208 checkPrimitive(n); 209 }210 211 212 @Override213 public void visit(Segment s)214 {215 checkPrimitive(s);216 209 } 217 210 … … 460 453 boolean checkFixmes = Main.pref.getBoolean(PREF_CHECK_FIXMES, true); 461 454 prefCheckFixmes = new JCheckBox(tr("Check for FIXMES."), checkFixmes); 462 prefCheckFixmes.setToolTipText(tr("Looks for nodes , segmentsor ways with FIXME in any property value."));455 prefCheckFixmes.setToolTipText(tr("Looks for nodes or ways with FIXME in any property value.")); 463 456 testPanel.add(prefCheckFixmes, GBC.std().insets(40,0,0,0)); 464 457 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedNode.java
r2591 r4843 9 9 import org.openstreetmap.josm.command.DeleteCommand; 10 10 import org.openstreetmap.josm.data.osm.Node; 11 import org.openstreetmap.josm.data.osm.Way; 11 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.Segment;13 13 import org.openstreetmap.josm.plugins.validator.Severity; 14 14 import org.openstreetmap.josm.plugins.validator.Test; 15 15 import org.openstreetmap.josm.plugins.validator.TestError; 16 16 /** 17 * Checks for untagged nodes that are in no segment17 * Checks for untagged nodes that are in no way 18 18 * 19 19 * @author frsantos … … 33 33 { 34 34 super(tr("Untagged nodes."), 35 tr("This test checks for untagged nodes that are not part of any segment."));35 tr("This test checks for untagged nodes that are not part of any way.")); 36 36 } 37 37 … … 46 46 { 47 47 // If there is a partial selection, it may be false positives if a 48 // node is selected, but not the container segment. So, in this 49 // case, we must visit all segments, selected or not. 50 51 for (OsmPrimitive p : selection) 52 { 53 if( !p.deleted ) 54 { 55 if( !partialSelection || p instanceof Node ) 56 p.visit(this); 57 } 58 } 59 60 if( partialSelection ) 61 { 62 for( Segment s : Main.ds.segments) 63 visit(s); 48 // node is selected, but not the container way. So, in this 49 // case, we must visit all ways, selected or not. 50 if (partialSelection) { 51 for (OsmPrimitive p : selection) { 52 if (!p.deleted && p instanceof Node) { 53 p.visit(this); 54 } 55 } 56 for (Way w : Main.ds.ways) { 57 visit(w); 58 } 59 } else { 60 for (OsmPrimitive p : selection) { 61 if (!p.deleted) { 62 p.visit(this); 63 } 64 } 64 65 } 65 66 } … … 84 85 85 86 @Override 86 public void visit( Segment s)87 public void visit(Way w) 87 88 { 88 emptyNodes.remove(s.from); 89 emptyNodes.remove(s.to); 89 for (Node n : w.nodes) { 90 emptyNodes.remove(n); 91 } 90 92 } 91 93 -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UntaggedWay.java
r4033 r4843 87 87 } 88 88 89 if( w. segments.size() == 0 )89 if( w.nodes.size() == 0 ) 90 90 { 91 91 errors.add( new TestError(this, Severity.ERROR, tr("Empty ways"), w, EMPTY_WAY) ); -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/AgregatePrimitivesVisitor.java
r2590 r4843 11 11 * A visitor that aggregates all primitives it visits. 12 12 * <p> 13 * The primitives are sorted according to their tyep: first Nodes, then 14 * Segments, and Ways last. 13 * The primitives are sorted according to their tyep: first nodes, then ways. 15 14 * 16 15 * @author frsantos … … 49 48 } 50 49 51 public void visit(Segment s)52 {53 aggregatedData.add(s);54 if( s.from != null ) visit(s.from);55 if( s.to != null ) visit(s.to);56 }57 58 50 public void visit(Way w) 59 51 { 60 52 aggregatedData.add(w); 61 for (Segment s : w.segments)62 visit( s);53 for (Node n : w.nodes) 54 visit(n); 63 55 } 64 56 65 57 /** 66 * A comparator that orders Nodes first, then Segments and Ways last.58 * A comparator that orders nodes first, ways last. 67 59 * 68 60 * @author frsantos … … 79 71 { 80 72 return o2 instanceof Way ? o1.hashCode() - o2.hashCode() : 1; 81 } 82 else // o1 is a segment 83 { 84 if( o2 instanceof Node ) return 1; 85 if( o2 instanceof Way ) return -1; 73 } else { 86 74 return o1.hashCode() - o2.hashCode(); 87 75 } -
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/Util.java
r4162 r4843 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.osm.Segment;16 15 import org.openstreetmap.josm.data.osm.Way; 16 import org.openstreetmap.josm.data.osm.Node; 17 17 import org.openstreetmap.josm.plugins.*; 18 18 import org.openstreetmap.josm.plugins.validator.PreferenceEditor; … … 242 242 public static List<List<Way>> getWaysInCell(Way w, Map<Point2D,List<Way>> cellWays) 243 243 { 244 int numSegments = w.segments.size(); 245 if( numSegments == 0) 244 if (w.nodes.size() == 0) 246 245 return Collections.emptyList(); 247 246 248 Segment start = w.segments.get(0); 249 Segment end = start; 250 if( numSegments > 1 ) 251 { 252 end = w.segments.get(numSegments - 1); 253 } 254 255 if( start.incomplete || end.incomplete ) 256 return Collections.emptyList(); 247 Node n1 = w.nodes.get(0); 248 Node n2 = w.nodes.get(w.nodes.size() - 1); 257 249 258 250 List<List<Way>> cells = new ArrayList<List<Way>>(2); … … 261 253 262 254 // First, round coordinates 263 long x0 = Math.round( start.from.eastNorth.east() * 10000);264 long y0 = Math.round( start.from.eastNorth.north() * 10000);265 long x1 = Math.round( end.to.eastNorth.east()* 10000);266 long y1 = Math.round( end.to.eastNorth.north()* 10000);255 long x0 = Math.round(n1.eastNorth.east() * 10000); 256 long y0 = Math.round(n1.eastNorth.north() * 10000); 257 long x1 = Math.round(n2.eastNorth.east() * 10000); 258 long y1 = Math.round(n2.eastNorth.north() * 10000); 267 259 268 260 // Start of the way … … 292 284 293 285 // Then floor coordinates, in case the way is in the border of the cell. 294 x0 = (long)Math.floor( start.from.eastNorth.east() * 10000);295 y0 = (long)Math.floor( start.from.eastNorth.north() * 10000);296 x1 = (long)Math.floor( end.to.eastNorth.east()* 10000);297 y1 = (long)Math.floor( end.to.eastNorth.north()* 10000);286 x0 = (long)Math.floor(n1.eastNorth.east() * 10000); 287 y0 = (long)Math.floor(n1.eastNorth.north() * 10000); 288 x1 = (long)Math.floor(n2.eastNorth.east() * 10000); 289 y1 = (long)Math.floor(n2.eastNorth.north() * 10000); 298 290 299 291 // Start of the way … … 329 321 330 322 /** 331 * Returns the coordinates of all cells in a grid that a segment goes through. 323 * Returns the coordinates of all cells in a grid that a line between 2 324 * nodes intersects with. 332 325 * 333 * @param s The segment 334 * @param gridDetail The detail of the grid. Bigger values give smaller cells, but a bigger number of them. 326 * @param n1 The first node. 327 * @param n2 The second node. 328 * @param gridDetail The detail of the grid. Bigger values give smaller 329 * cells, but a bigger number of them. 335 330 * @return A list with the coordinates of all cells 336 331 */ 337 public static List<Point2D> getSegmentCells( Segment s, int gridDetail)332 public static List<Point2D> getSegmentCells(Node n1, Node n2, int gridDetail) 338 333 { 339 334 List<Point2D> cells = new ArrayList<Point2D>(); 340 double x0 = s.from.eastNorth.east() * gridDetail;341 double x1 = s.to.eastNorth.east()* gridDetail;342 double y0 = s.from.eastNorth.north()* gridDetail + 1;343 double y1 = s.to.eastNorth.north()* gridDetail + 1;335 double x0 = n1.eastNorth.east() * gridDetail; 336 double x1 = n2.eastNorth.east() * gridDetail; 337 double y0 = n1.eastNorth.north() * gridDetail + 1; 338 double y1 = n2.eastNorth.north() * gridDetail + 1; 344 339 345 340 if( x0 > x1 )
Note:
See TracChangeset
for help on using the changeset viewer.