Changeset 359 in josm for trunk/src/org/openstreetmap/josm/actions/mapmode
- Timestamp:
- 2007-10-11T14:02:42+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r358 r359 11 11 import java.util.Collections; 12 12 import java.util.HashMap; 13 import java.util.HashSet; 14 import java.util.Map; 13 15 import java.util.LinkedList; 16 import java.util.List; 14 17 15 18 import javax.swing.JOptionPane; … … 80 83 Collection<Command> cmds = new LinkedList<Command>(); 81 84 82 Way reuseWay = null, replacedWay = null; 85 ArrayList<Way> reuseWays = new ArrayList<Way>(), 86 replacedWays = new ArrayList<Way>(); 83 87 boolean newNode = false; 84 88 Node n = Main.map.mapView.getNearestNode(e.getPoint()); … … 94 98 cmds.add(new AddCommand(n)); 95 99 96 WaySegment ws = Main.map.mapView.getNearestWaySegment(e.getPoint()); 97 if (ws != null) { 98 replacedWay = ws.way; 99 reuseWay = splitWaySegmentAtNode(ws, n, cmds); 100 // Insert the node into all the nearby way segments 101 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint()); 102 Map<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 103 for (WaySegment ws : wss) { 104 List<Integer> is; 105 if (insertPoints.containsKey(ws.way)) { 106 is = insertPoints.get(ws.way); 107 } else { 108 is = new ArrayList<Integer>(); 109 insertPoints.put(ws.way, is); 110 } 111 112 is.add(ws.lowerIndex); 113 } 114 for (Map.Entry<Way, List<Integer>> insertPoint : insertPoints.entrySet()) { 115 Way w = insertPoint.getKey(); 116 List<Integer> is = insertPoint.getValue(); 117 118 Way wnew = new Way(w); 119 120 pruneSuccsAndReverse(is); 121 for (int i : is) wnew.nodes.add(i + 1, n); 122 123 cmds.add(new ChangeCommand(insertPoint.getKey(), wnew)); 124 replacedWays.add(insertPoint.getKey()); 125 reuseWays.add(wnew); 100 126 } 101 127 } … … 111 137 cmds.add(new AddCommand(way)); 112 138 } else { 113 if (way == replacedWay) { 114 way = reuseWay; 139 int i; 140 if ((i = replacedWays.indexOf(way)) != -1) { 141 way = reuseWays.get(i); 115 142 } else { 116 143 Way wnew = new Way(way); … … 133 160 return; // We didn't do anything. 134 161 } else if (!extendedWay) { 135 if (reuseWay == null) {162 if (reuseWays.isEmpty()) { 136 163 title = tr("Add node"); 137 164 } else { … … 140 167 } else if (!newNode) { 141 168 title = tr("Connect existing way to node"); 142 } else if (reuseWay == null) {169 } else if (reuseWays.isEmpty()) { 143 170 title = tr("Add a new node to an existing way"); 144 171 } else { … … 171 198 return way; 172 199 } 173 174 private Way splitWaySegmentAtNode(WaySegment ws, Node n, Collection<Command> cmds) { 175 Way wnew = new Way(ws.way); 176 wnew.nodes.add(ws.lowerIndex + 1, n); 177 cmds.add(new ChangeCommand(ws.way, wnew)); 178 return wnew; 200 201 private static void pruneSuccsAndReverse(List<Integer> is) { 202 //if (is.size() < 2) return; 203 204 HashSet<Integer> is2 = new HashSet<Integer>(); 205 for (int i : is) { 206 if (!is2.contains(i - 1) && !is2.contains(i + 1)) { 207 is2.add(i); 208 } 209 } 210 is.clear(); 211 is.addAll(is2); 212 Collections.sort(is); 213 Collections.reverse(is); 179 214 } 180 215 }
Note:
See TracChangeset
for help on using the changeset viewer.