Changeset 306 in josm
- Timestamp:
- 2007-08-21T23:03:00+02:00 (17 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r301 r306 9 9 import java.util.ArrayList; 10 10 import java.util.Collection; 11 import java.util.Collections; 11 12 import java.util.HashMap; 12 13 import java.util.LinkedList; … … 101 102 if (s == null) 102 103 return; 103 104 if ((e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) == 0) { 104 105 // see if another segment is also near 106 Segment other = Main.map.mapView.getNearestSegment(e.getPoint(), Collections.singleton(s)); 107 108 if (other == null && (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) == 0) { 105 109 // moving the new point to the perpendicular point 106 110 EastNorth A = s.from.eastNorth; … … 116 120 Collection<Command> cmds = new LinkedList<Command>(); 117 121 cmds.add(c); 118 Segment s1 = new Segment(s); 119 s1.to = n; 120 Segment s2 = new Segment(s.from, s.to); 121 s2.from = n; 122 if (s.keys != null) 123 s2.keys = new HashMap<String, String>(s.keys); 124 125 cmds.add(new ChangeCommand(s, s1)); 126 cmds.add(new AddCommand(s2)); 127 128 // Add the segment to every way 129 for (Way wold : Main.ds.ways) { 130 if (wold.segments.contains(s)) { 131 Way wnew = new Way(wold); 132 Collection<Segment> segs = new ArrayList<Segment>(wnew.segments); 133 wnew.segments.clear(); 134 for (Segment waySeg : segs) { 135 wnew.segments.add(waySeg); 136 if (waySeg == s) 137 wnew.segments.add(s2); 138 } 139 cmds.add(new ChangeCommand(wold, wnew)); 140 } 141 } 142 143 c = new SequenceCommand(tr("Add node into segment"), cmds); 122 123 // split the first segment 124 splitSegmentAtNode(s, n, cmds); 125 126 // if a second segment was found, split that as well 127 if (other != null) splitSegmentAtNode(other, n, cmds); 128 129 c = new SequenceCommand(tr((other == null) ? 130 "Add node into segment" : "Add common node into two segments"), cmds); 144 131 } 145 132 … … 194 181 return way; 195 182 } 183 184 private void splitSegmentAtNode(Segment s, Node n, Collection<Command> cmds) { 185 Segment s1 = new Segment(s); 186 s1.to = n; 187 Segment s2 = new Segment(s.from, s.to); 188 s2.from = n; 189 if (s.keys != null) 190 s2.keys = new HashMap<String, String>(s.keys); 191 192 cmds.add(new ChangeCommand(s, s1)); 193 cmds.add(new AddCommand(s2)); 194 195 // Add the segment to every way 196 for (Way wold : Main.ds.ways) { 197 if (wold.segments.contains(s)) { 198 Way wnew = new Way(wold); 199 Collection<Segment> segs = new ArrayList<Segment>(wnew.segments); 200 wnew.segments.clear(); 201 for (Segment waySeg : segs) { 202 wnew.segments.add(waySeg); 203 if (waySeg == s) 204 wnew.segments.add(s2); 205 } 206 cmds.add(new ChangeCommand(wold, wnew)); 207 } 208 } 209 } 196 210 } -
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r298 r306 4 4 import java.awt.Point; 5 5 import java.util.Collection; 6 import java.util.Collections; 6 7 import java.util.HashSet; 8 import java.util.List; 7 9 8 10 import javax.swing.JComponent; … … 172 174 173 175 /** 174 * @return the nearest segment to the screen point given. 176 * @return the nearest segment to the screen point given 177 * 178 * @param p the point for which to search the nearest segment. 175 179 */ 176 180 public final Segment getNearestSegment(Point p) { 181 List<Segment> e = Collections.emptyList(); 182 return getNearestSegment(p, e); 183 } 184 185 /** 186 * @return the nearest segment to the screen point given that is not 187 * in ignoreThis. 188 * 189 * @param p the point for which to search the nearest segment. 190 * @param ignore a collection of segments which are not to be returned. Must not be null. 191 */ 192 public final Segment getNearestSegment(Point p, Collection<Segment> ignore) { 177 193 Segment minPrimitive = null; 178 194 double minDistanceSq = Double.MAX_VALUE; 179 195 // segments 180 196 for (Segment ls : Main.ds.segments) { 181 if (ls.deleted || ls.incomplete) 197 if (ls.deleted || ls.incomplete || ignore.contains(ls)) 182 198 continue; 183 199 Point A = getPoint(ls.from.eastNorth);
Note:
See TracChangeset
for help on using the changeset viewer.