Changeset 25903 in osm for applications/editors/josm/plugins/ImproveWayAccuracy
- Timestamp:
- 2011-04-26T04:14:29+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ImproveWayAccuracy/src/org/openstreetmap/josm/plugins/iwa/IWAMode.java
r25901 r25903 346 346 } 347 347 348 if (ctrl ) {348 if (ctrl && candidateSegment != null) { 349 349 // Adding a new node to the highlighted segment 350 350 // Important: If there are other ways containing the same 351 351 // segment, a node must added to all of that ways. 352 if (candidateSegment != null) { 353 Collection<Command> virtualCmds = new LinkedList<Command>(); 354 355 // Creating a new node 356 Node virtualNode = new Node(mv.getEastNorth(mousePos.x, 357 mousePos.y)); 358 virtualCmds.add(new AddCommand(virtualNode)); 359 360 // Looking for candidateSegment copies in ways that are 361 // referenced 362 // by candidateSegment nodes 363 List<Way> firstNodeWays = OsmPrimitive.getFilteredList( 364 candidateSegment.getFirstNode().getReferrers(), 365 Way.class); 366 List<Way> secondNodeWays = OsmPrimitive.getFilteredList( 367 candidateSegment.getFirstNode().getReferrers(), 368 Way.class); 369 370 Collection<WaySegment> virtualSegments = new LinkedList<WaySegment>(); 371 for (Way w : firstNodeWays) { 372 List<Pair<Node, Node>> wpps = w.getNodePairs(true); 373 for (Way w2 : secondNodeWays) { 374 if (!w.equals(w2)) 375 continue; 376 // A way is referenced in both nodes. 377 // Checking if there is such segment 378 int i = -1; 379 for (Pair<Node, Node> wpp : wpps) { 380 ++i; 381 if ((wpp.a.equals(candidateSegment 382 .getFirstNode()) 383 && wpp.b.equals(candidateSegment 384 .getSecondNode()) || (wpp.b 385 .equals(candidateSegment.getFirstNode()) && wpp.a 386 .equals(candidateSegment 387 .getSecondNode())))) { 388 virtualSegments.add(new WaySegment(w, i)); 389 } 352 Collection<Command> virtualCmds = new LinkedList<Command>(); 353 354 // Creating a new node 355 Node virtualNode = new Node(mv.getEastNorth(mousePos.x, 356 mousePos.y)); 357 virtualCmds.add(new AddCommand(virtualNode)); 358 359 // Looking for candidateSegment copies in ways that are 360 // referenced 361 // by candidateSegment nodes 362 List<Way> firstNodeWays = OsmPrimitive.getFilteredList( 363 candidateSegment.getFirstNode().getReferrers(), 364 Way.class); 365 List<Way> secondNodeWays = OsmPrimitive.getFilteredList( 366 candidateSegment.getFirstNode().getReferrers(), 367 Way.class); 368 369 Collection<WaySegment> virtualSegments = new LinkedList<WaySegment>(); 370 for (Way w : firstNodeWays) { 371 List<Pair<Node, Node>> wpps = w.getNodePairs(true); 372 for (Way w2 : secondNodeWays) { 373 if (!w.equals(w2)) 374 continue; 375 // A way is referenced in both nodes. 376 // Checking if there is such segment 377 int i = -1; 378 for (Pair<Node, Node> wpp : wpps) { 379 ++i; 380 if ((wpp.a.equals(candidateSegment.getFirstNode()) 381 && wpp.b.equals(candidateSegment 382 .getSecondNode()) || (wpp.b 383 .equals(candidateSegment.getFirstNode()) && wpp.a 384 .equals(candidateSegment.getSecondNode())))) { 385 virtualSegments.add(new WaySegment(w, i)); 390 386 } 391 387 } 392 388 } 393 394 // Adding the node to all segments found395 for (WaySegment virtualSegment : virtualSegments) {396 Way w = virtualSegment.way;397 Way wnew = new Way(w);398 wnew.addNode(virtualSegment.lowerIndex + 1, virtualNode);399 virtualCmds.add(new ChangeCommand(w, wnew));400 }401 402 // Finishing the sequence command403 String text = trn("Add and a new node to way",404 "Add and a new node to {0} ways",405 virtualSegments.size(), virtualSegments.size());406 407 Main.main.undoRedo.add(new SequenceCommand(text,408 virtualCmds));409 389 } 410 } else { 390 391 // Adding the node to all segments found 392 for (WaySegment virtualSegment : virtualSegments) { 393 Way w = virtualSegment.way; 394 Way wnew = new Way(w); 395 wnew.addNode(virtualSegment.lowerIndex + 1, virtualNode); 396 virtualCmds.add(new ChangeCommand(w, wnew)); 397 } 398 399 // Finishing the sequence command 400 String text = trn("Add and a new node to way", 401 "Add and a new node to {0} ways", 402 virtualSegments.size(), virtualSegments.size()); 403 404 Main.main.undoRedo.add(new SequenceCommand(text, virtualCmds)); 405 406 } else if (candidateNode != null) { 411 407 // Moving the highlighted node 412 408 EastNorth nodeEN = candidateNode.getEastNorth();
Note:
See TracChangeset
for help on using the changeset viewer.