Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r1084 r1169 26 26 27 27 public class JoinNodeWayAction extends JosmAction { 28 29 30 31 28 public JoinNodeWayAction() { 29 super(tr("Join node to way"), "joinnodeway", tr("Join a node into the nearest way segments"), 30 Shortcut.registerShortcut("tools:joinnodeway", tr("Tool: {0}", tr("Join node to way")), KeyEvent.VK_J, Shortcut.GROUP_EDIT), true); 31 } 32 32 33 34 35 36 33 public void actionPerformed(ActionEvent e) { 34 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 35 if (sel.size() != 1 || !(sel.iterator().next() instanceof Node)) return; 36 Node node = (Node) sel.iterator().next(); 37 37 38 39 40 41 42 43 44 45 46 47 48 38 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 39 Main.map.mapView.getPoint(node.eastNorth)); 40 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 41 for (WaySegment ws : wss) { 42 List<Integer> is; 43 if (insertPoints.containsKey(ws.way)) { 44 is = insertPoints.get(ws.way); 45 } else { 46 is = new ArrayList<Integer>(); 47 insertPoints.put(ws.way, is); 48 } 49 49 50 51 52 53 54 50 if (ws.way.nodes.get(ws.lowerIndex) != node 51 && ws.way.nodes.get(ws.lowerIndex+1) != node) { 52 is.add(ws.lowerIndex); 53 } 54 } 55 55 56 57 58 59 60 61 62 63 64 56 Collection<Command> cmds = new LinkedList<Command>(); 57 for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) { 58 Way w = insertPoint.getKey(); 59 Way wnew = new Way(w); 60 List<Integer> is = insertPoint.getValue(); 61 pruneSuccsAndReverse(is); 62 for (int i : is) wnew.nodes.add(i+1, node); 63 cmds.add(new ChangeCommand(w, wnew)); 64 } 65 65 66 67 68 66 Main.main.undoRedo.add(new SequenceCommand(tr("Join Node and Line"), cmds)); 67 Main.map.repaint(); 68 } 69 69 70 71 70 private static void pruneSuccsAndReverse(List<Integer> is) { 71 //if (is.size() < 2) return; 72 72 73 74 75 76 77 78 79 80 81 82 83 73 HashSet<Integer> is2 = new HashSet<Integer>(); 74 for (int i : is) { 75 if (!is2.contains(i - 1) && !is2.contains(i + 1)) { 76 is2.add(i); 77 } 78 } 79 is.clear(); 80 is.addAll(is2); 81 Collections.sort(is); 82 Collections.reverse(is); 83 } 84 84 }
Note:
See TracChangeset
for help on using the changeset viewer.