Changeset 4464 in osm for applications/editors/josm/core_0.5/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
- Timestamp:
- 2007-09-05T23:55:17+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/core_0.5/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r4437 r4464 24 24 import org.openstreetmap.josm.data.osm.Node; 25 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 import org.openstreetmap.josm.data.osm.Segment;27 26 import org.openstreetmap.josm.data.osm.Way; 28 27 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; … … 38 37 * @see #deleteWithReferences(OsmPrimitive) 39 38 * 40 * Pressing Alt will select the way instead of a segment, as usual.41 *42 39 * If the user did not press Ctrl and the object has any references, the user 43 40 * is informed and nothing is deleted. … … 57 54 super(tr("Delete"), 58 55 "delete", 59 tr("Delete nodes , streets or segments."),56 tr("Delete nodes or ways."), 60 57 KeyEvent.VK_D, 61 58 mapFrame, … … 92 89 return; 93 90 94 OsmPrimitive sel = Main.map.mapView.getNearest(e.getPoint() , (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);91 OsmPrimitive sel = Main.map.mapView.getNearest(e.getPoint()); 95 92 if (sel == null) 96 93 return; … … 105 102 106 103 /** 107 * Delete the primitives and everything they reference s.104 * Delete the primitives and everything they reference. 108 105 * 109 * If a node is deleted, the node and all segments,ways andareas106 * If a node is deleted, the node and all ways and relations 110 107 * the node is part of are deleted as well. 111 108 * 112 * If a segment is deleted, all ways the segment is part of 113 * are deleted as well. No nodes are deleted. 109 * If a way is deleted, all relations the way is member of are also deleted. 114 110 * 115 * If a way is deleted, only the way and no segments or nodes are 116 * deleted. 117 * 118 * If an area is deleted, only the area gets deleted. 111 * If a way is deleted, only the way and no nodes are deleted. 119 112 * 120 113 * @param selection The list of all object to be deleted. … … 134 127 * inform the user and do not delete. 135 128 * 136 * If deleting a node which is part of exactly two segments, and both segments 137 * have no conflicting keys, join them and remove the node. 138 * If the two segments are part of the same way, remove the deleted segment 139 * from the way. 129 * If a node is to be deleted which is in the middle of exactly one way, 130 * the node is removed from the way's node list and after that removed 131 * itself. 140 132 * 141 133 * @param selection The objects to delete. … … 149 141 if (!selection.containsAll(v.data)) { 150 142 if (osm instanceof Node && joinIfPossible) { 151 String reason = deleteNodeAndJoin Segment((Node)osm);143 String reason = deleteNodeAndJoinWay((Node)osm); 152 144 if (reason != null && msgBox) { 153 145 JOptionPane.showMessageDialog(Main.parent,tr("Cannot delete node.")+" "+reason); … … 167 159 } 168 160 169 private String deleteNodeAndJoinSegment(Node n) { 170 ArrayList<Segment> segs = new ArrayList<Segment>(2); 171 for (Segment s : Main.ds.segments) { 172 if (!s.deleted && (s.from == n || s.to == n)) { 173 if (segs.size() > 1) 174 return tr("Used by more than two segments."); 175 segs.add(s); 176 } 177 } 178 if (segs.size() != 2) 179 return tr("Used by only one segment."); 180 Segment seg1 = segs.get(0); 181 Segment seg2 = segs.get(1); 182 if (seg1.from == seg2.to) { 183 Segment s = seg1; 184 seg1 = seg2; 185 seg2 = s; 186 } 187 if (seg1.from == seg2.from || seg1.to == seg2.to) 188 return tr("Wrong direction of segments."); 189 for (Entry<String, String> e : seg1.entrySet()) 190 if (seg2.keySet().contains(e.getKey()) && !seg2.get(e.getKey()).equals(e.getValue())) 191 return tr("Conflicting keys"); 192 ArrayList<Way> ways = new ArrayList<Way>(2); 161 private String deleteNodeAndJoinWay(Node n) { 162 ArrayList<Way> ways = new ArrayList<Way>(1); 193 163 for (Way w : Main.ds.ways) { 194 if (w.deleted) 195 continue; 196 if ((w.segments.contains(seg1) && !w.segments.contains(seg2)) || (w.segments.contains(seg2) && !w.segments.contains(seg1))) 197 return tr("Segments are part of different ways."); 198 if (w.segments.contains(seg1) && w.segments.contains(seg2)) 164 if (!w.deleted && w.nodes.contains(n)) { 199 165 ways.add(w); 200 166 } 201 Segment s = new Segment(seg1); 202 s.to = seg2.to; 203 if (s.keys == null) 204 s.keys = seg2.keys; 205 else if (seg2.keys != null) 206 s.keys.putAll(seg2.keys); 167 } 168 169 if (ways.size() > 1) 170 return tr("Used by more than one way."); 171 Way w = ways.get(0); 172 173 int i = w.nodes.indexOf(n); 174 if (w.nodes.lastIndexOf(n) != i) 175 return tr("Occurs more than once in the same way."); 176 if (i == 0 || i == w.nodes.size() - 1) 177 return tr("Is at the end of a way"); 178 179 Way wnew = new Way(w); 180 wnew.nodes.remove(i); 181 207 182 Collection<Command> cmds = new LinkedList<Command>(); 208 for (Way w : ways) { 209 Way copy = new Way(w); 210 copy.segments.remove(seg2); 211 cmds.add(new ChangeCommand(w, copy)); 212 } 213 cmds.add(new ChangeCommand(seg1, s)); 214 cmds.add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{n, seg2}))); 183 cmds.add(new ChangeCommand(w, wnew)); 184 cmds.add(new DeleteCommand(Collections.singleton(n))); 215 185 Main.main.undoRedo.add(new SequenceCommand(tr("Delete Node"), cmds)); 216 186 return null;
Note:
See TracChangeset
for help on using the changeset viewer.