- Timestamp:
- 2009-07-19T10:39:10+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r1706 r1809 53 53 public SplitWayAction() { 54 54 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), 55 Shortcut.registerShortcut("tools:splitway", tr("Tool: {0}", tr("Split Way")), KeyEvent.VK_P, Shortcut.GROUP_EDIT), true);55 Shortcut.registerShortcut("tools:splitway", tr("Tool: {0}", tr("Split Way")), KeyEvent.VK_P, Shortcut.GROUP_EDIT), true); 56 56 DataSet.selListeners.add(this); 57 57 } … … 77 77 Visitor splitVisitor = new AbstractVisitor() { 78 78 public void visit(Node n) { 79 if (selectedNodes == null) 79 if (selectedNodes == null) { 80 80 selectedNodes = new LinkedList<Node>(); 81 } 81 82 selectedNodes.add(n); 82 83 } … … 89 90 }; 90 91 91 for (OsmPrimitive p : selection) 92 for (OsmPrimitive p : selection) { 92 93 p.visit(splitVisitor); 94 } 93 95 94 96 // If only nodes are selected, try to guess which way to split. This works if there … … 98 100 for (Node n : selectedNodes) { 99 101 for (Way w : Main.ds.ways) { 100 if (w.deleted || w.incomplete) continue; 102 if (w.deleted || w.incomplete) { 103 continue; 104 } 101 105 int last = w.nodes.size()-1; 102 if(last <= 0) continue; // zero or one node ways 106 if(last <= 0) { 107 continue; // zero or one node ways 108 } 103 109 Boolean circular = w.nodes.get(0).equals(w.nodes.get(last)); 104 110 int i = 0; … … 115 121 if (wayOccurenceCounter.isEmpty()) { 116 122 JOptionPane.showMessageDialog(Main.parent, 117 trn("The selected node is not in the middle of any way.",118 "The selected nodes are not in the middle of any way.",119 selectedNodes.size()));123 trn("The selected node is not in the middle of any way.", 124 "The selected nodes are not in the middle of any way.", 125 selectedNodes.size())); 120 126 return; 121 127 } … … 125 131 if (selectedWay != null) { 126 132 JOptionPane.showMessageDialog(Main.parent, 127 trn("There is more than one way using the node you selected. Please select the way also.",128 "There is more than one way using the nodes you selected. Please select the way also.",129 selectedNodes.size()));133 trn("There is more than one way using the node you selected. Please select the way also.", 134 "There is more than one way using the nodes you selected. Please select the way also.", 135 selectedNodes.size())); 130 136 return; 131 137 } … … 136 142 if (selectedWay == null) { 137 143 JOptionPane.showMessageDialog(Main.parent, 138 tr("The selected nodes do not share the same way."));144 tr("The selected nodes do not share the same way.")); 139 145 return; 140 146 } 141 147 142 // If a way and nodes are selected, verify that the nodes are part of the way.148 // If a way and nodes are selected, verify that the nodes are part of the way. 143 149 } else if (selectedWay != null && selectedNodes != null) { 144 150 … … 149 155 if (!nds.isEmpty()) { 150 156 JOptionPane.showMessageDialog(Main.parent, 151 trn("The selected way does not contain the selected node.",152 "The selected way does not contain all the selected nodes.",153 selectedNodes.size()));157 trn("The selected way does not contain the selected node.", 158 "The selected way does not contain all the selected nodes.", 159 selectedNodes.size())); 154 160 return; 155 161 } … … 175 181 } else if (p instanceof Node) { 176 182 node = true; 177 } else {183 } else 178 184 return false; 179 }180 185 } 181 186 return node; … … 227 232 228 233 if (wayChunks.size() < 2) { 229 if(wayChunks.get(0).get(0) == wayChunks.get(0).get(wayChunks.get(0).size()-1)) 234 if(wayChunks.get(0).get(0) == wayChunks.get(0).get(wayChunks.get(0).size()-1)) { 230 235 JOptionPane.showMessageDialog(Main.parent, tr("You must select two or more nodes to split a circular way.")); 231 else236 } else { 232 237 JOptionPane.showMessageDialog(Main.parent, tr("The way cannot be split at the selected nodes. (Hint: Select nodes in the middle of the way.)")); 238 } 233 239 return; 234 240 } … … 267 273 // now copy all relations to new way also 268 274 for (Relation r : Main.ds.relations) { 269 if (r.deleted || r.incomplete) continue; 275 if (r.deleted || r.incomplete) { 276 continue; 277 } 270 278 Relation c = null; 271 279 String type = ""; 272 280 int i = 0; 273 281 274 if(r.keys != null) 282 if(r.keys != null) { 275 283 type = r.keys.get("type"); 284 } 276 285 277 286 for (RelationMember rm : r.members) { … … 279 288 if (rm.member == selectedWay) 280 289 { 281 if(!("route".equals(type)) && !("multipolygon".equals(type))) 290 if(!("route".equals(type)) && !("multipolygon".equals(type))) { 282 291 warnme = true; 283 if (c == null) 292 } 293 if (c == null) { 284 294 c = new Relation(r); 295 } 285 296 286 297 int j = i; 287 boolean backwards = rm.role.equals("backward");298 boolean backwards = "backward".equals(rm.role); 288 299 for(Way wayToAdd : newWays) 289 300 { … … 291 302 em.member = wayToAdd; 292 303 em.role = rm.role; 293 if(em.role .length() > 0 && !("multipolygon".equals(type)))304 if(em.role != null && em.role.length() > 0 && !("multipolygon".equals(type))) { 294 305 warnmerole = true; 306 } 295 307 296 308 j++; 297 if (backwards) 309 if (backwards) { 298 310 c.members.add(i, em); 299 else311 } else { 300 312 c.members.add(j, em); 313 } 301 314 } 302 315 i = j; … … 306 319 } 307 320 308 if (c != null) 321 if (c != null) { 309 322 commandList.add(new ChangeCommand(r, c)); 310 } 311 if(warnmerole) 323 } 324 } 325 if(warnmerole) { 312 326 JOptionPane.showMessageDialog(Main.parent, tr("A role based relation membership was copied to all new ways.\nYou should verify this and correct it when necessary.")); 313 else if(warnme)327 } else if(warnme) { 314 328 JOptionPane.showMessageDialog(Main.parent, tr("A relation membership was copied to all new ways.\nYou should verify this and correct it when necessary.")); 329 } 315 330 316 331 NameVisitor v = new NameVisitor(); 317 332 v.visit(selectedWay); 318 333 Main.main.undoRedo.add( 319 new SequenceCommand(tr("Split way {0} into {1} parts",320 v.name, wayChunks.size()),321 commandList));334 new SequenceCommand(tr("Split way {0} into {1} parts", 335 v.name, wayChunks.size()), 336 commandList)); 322 337 Main.ds.setSelected(newSelection); 323 338 }
Note:
See TracChangeset
for help on using the changeset viewer.