- Timestamp:
- 2010-10-28T16:54:32+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r3177 r3643 12 12 import java.util.HashMap; 13 13 import java.util.HashSet; 14 import java.util.Iterator; 14 15 import java.util.LinkedList; 15 16 import java.util.List; … … 37 38 return; 38 39 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 39 if (sel.size() != 1 || !(sel.iterator().next() instanceof Node)) return; 40 Node node = (Node) sel.iterator().next(); 40 if (sel.size() < 1) return; 41 41 42 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 43 Main.map.mapView.getPoint(node), OsmPrimitive.isSelectablePredicate); 44 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 45 for (WaySegment ws : wss) { 46 List<Integer> is; 47 if (insertPoints.containsKey(ws.way)) { 48 is = insertPoints.get(ws.way); 49 } else { 50 is = new ArrayList<Integer>(); 51 insertPoints.put(ws.way, is); 42 Collection<Command> cmds = new LinkedList<Command>(); 43 44 for (OsmPrimitive osm : sel) { 45 if (!(osm instanceof Node)) continue; 46 Node node = (Node) osm; 47 48 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 49 Main.map.mapView.getPoint(node), OsmPrimitive.isSelectablePredicate); 50 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 51 for (WaySegment ws : wss) { 52 List<Integer> is; 53 if (insertPoints.containsKey(ws.way)) { 54 is = insertPoints.get(ws.way); 55 } else { 56 is = new ArrayList<Integer>(); 57 insertPoints.put(ws.way, is); 58 } 59 60 if (ws.way.getNode(ws.lowerIndex) != node 61 && ws.way.getNode(ws.lowerIndex+1) != node) { 62 is.add(ws.lowerIndex); 63 } 52 64 } 53 65 54 if (ws.way.getNode(ws.lowerIndex) != node 55 && ws.way.getNode(ws.lowerIndex+1) != node) { 56 is.add(ws.lowerIndex); 66 for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) { 67 List<Integer> is = insertPoint.getValue(); 68 if (is.size() == 0) 69 continue; 70 71 Way w = insertPoint.getKey(); 72 List<Node> nodesToAdd = w.getNodes(); 73 pruneSuccsAndReverse(is); 74 for (int i : is) { 75 nodesToAdd.add(i+1, node); 76 } 77 Way wnew = new Way(w); 78 wnew.setNodes(nodesToAdd); 79 cmds.add(new ChangeCommand(w, wnew)); 57 80 } 58 81 } 59 60 Collection<Command> cmds = new LinkedList<Command>(); 61 for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) { 62 List<Integer> is = insertPoint.getValue(); 63 if (is.size() == 0) 64 continue; 65 66 Way w = insertPoint.getKey(); 67 List<Node> nodesToAdd = w.getNodes(); 68 pruneSuccsAndReverse(is); 69 for (int i : is) { 70 nodesToAdd.add(i+1, node); 71 } 72 Way wnew = new Way(w); 73 wnew.setNodes(nodesToAdd); 74 cmds.add(new ChangeCommand(w, wnew)); 75 } 76 77 if (cmds.size() == 0) 78 return; 79 82 if (cmds.size() == 0) return; 80 83 Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds)); 81 84 Main.map.repaint();
Note:
See TracChangeset
for help on using the changeset viewer.