Changeset 306 in josm for src/org/openstreetmap/josm/actions
- Timestamp:
- 2007-08-21T23:03:00+02:00 (18 years ago)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.