Ticket #18670: 18670.2.patch
File 18670.2.patch, 6.2 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/actions/UnGlueAction.java
108 108 } 109 109 // If there aren't enough ways, maybe the user wanted to unglue the nodes 110 110 // (= copy tags to a new node) 111 if (!selfCrossing) 112 if ( checkForUnglueNode(selection)) {111 if (!selfCrossing) { 112 if (selection.size() == 1 && selectedNode.isTagged()) { 113 113 unglueOneNodeAtMostOneWay(e); 114 114 } else { 115 115 errorTime = Notification.TIME_SHORT; 116 116 errMsg = tr("This node is not glued to anything else."); 117 117 } 118 } 118 119 } else { 119 120 // and then do the work. 120 121 unglueWays(); … … 245 246 } 246 247 247 248 /** 248 * Checks if selection is suitable for ungluing. This is the case when there's a single,249 * tagged node selected that's part of at least one way (ungluing an unconnected node does250 * not make sense. Due to the call order in actionPerformed, this is only called when the251 * node is only part of one or less ways.252 *253 * @param selection The selection to check against254 * @return {@code true} if selection is suitable255 */256 private boolean checkForUnglueNode(Collection<? extends OsmPrimitive> selection) {257 if (selection.size() != 1)258 return false;259 OsmPrimitive n = (OsmPrimitive) selection.toArray()[0];260 if (!(n instanceof Node))261 return false;262 if (((Node) n).getParentWays().isEmpty())263 return false;264 265 selectedNode = (Node) n;266 return selectedNode.isTagged();267 }268 269 /**270 249 * Checks if the selection consists of something we can work with. 271 250 * Checks only if the number and type of items selected looks good. 272 251 * … … 291 270 for (OsmPrimitive p : selection) { 292 271 if (p instanceof Node) { 293 272 selectedNode = (Node) p; 294 if (size == 1 || selectedWay != null)295 return size == 1 || selectedWay.containsNode(selectedNode);273 if (size == 1 || (selectedWay != null && selectedWay.containsNode(selectedNode))) 274 return true; 296 275 } else if (p instanceof Way) { 297 276 selectedWay = (Way) p; 298 277 if (size == 2 && selectedNode != null) … … 359 338 * @param w parent way 360 339 * @param cmds List of commands that will contain the new "add node" command 361 340 * @param newNodes List of nodes that will contain the new node 362 * @return new way The modified way. Change command mus be handled by the caller341 * @return new way The modified way. Change command must be handled by the caller 363 342 */ 364 343 private static Way modifyWay(Node originalNode, Way w, List<Command> cmds, List<Node> newNodes) { 365 344 // clone the node for the way … … 460 439 if (wayWithSelectedNode == null) { 461 440 parentWays.removeFirst(); 462 441 } 442 Set<Way> warnParents = new HashSet<>(); 463 443 for (Way w : parentWays) { 444 if (w.isFirstLastNode(selectedNode)) 445 warnParents.add(w); 464 446 cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes))); 465 447 } 466 notifyWayPartOfRelation( parentWays);448 notifyWayPartOfRelation(warnParents); 467 449 } else { 468 cmds.add(new ChangeCommand(selectedWay, modifyWay(selectedNode, selectedWay, cmds, newNodes)));469 notifyWayPartOfRelation(Collections.singleton(selectedWay));450 Way modWay = modifyWay(selectedNode, selectedWay, cmds, newNodes); 451 addCheckedChangeNodesCmd(cmds, selectedWay, modWay.getNodes()); 470 452 } 471 453 472 454 if (dialog != null) { … … 527 509 // selectedNode doesn't need unglue 528 510 return false; 529 511 } 530 cmds.add(new ChangeNodesCommand(way, newNodes)); 531 notifyWayPartOfRelation(Collections.singleton(way)); 512 addCheckedChangeNodesCmd(cmds, way, newNodes); 532 513 try { 533 514 final PropertiesMembershipChoiceDialog dialog = PropertiesMembershipChoiceDialog.showIfNecessary( 534 515 Collections.singleton(selectedNode), false); … … 568 549 } 569 550 allNewNodes.addAll(newNodes); 570 551 } 571 cmds.add(new ChangeCommand(selectedWay, tmpWay));// only one changeCommand for a way, else garbage will happen572 notifyWayPartOfRelation(Collections.singleton(selectedWay));552 // only one changeCommand for a way, else garbage will happen 553 addCheckedChangeNodesCmd(cmds, selectedWay, tmpWay.getNodes()); 573 554 574 555 UndoRedoHandler.getInstance().add(new SequenceCommand( 575 556 trn("Dupe {0} node into {1} nodes", "Dupe {0} nodes into {1} nodes", … … 577 558 getLayerManager().getEditDataSet().setSelected(allNewNodes); 578 559 } 579 560 561 private void addCheckedChangeNodesCmd(List<Command> cmds, Way w, List<Node> nodes) { 562 boolean relationCheck = w.firstNode() != nodes.get(0) || w.lastNode() != nodes.get(nodes.size() - 1); 563 cmds.add(new ChangeNodesCommand(w, nodes)); 564 if (relationCheck) { 565 notifyWayPartOfRelation(Collections.singleton(w)); 566 } 567 } 568 580 569 @Override 581 570 protected void updateEnabledState() { 582 571 updateEnabledStateOnCurrentSelection(); -
test/unit/org/openstreetmap/josm/actions/UnGlueActionTest.java
30 30 */ 31 31 @Rule 32 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 33 public JOSMTestRules test = new JOSMTestRules().main() ;33 public JOSMTestRules test = new JOSMTestRules().main().projection().preferences(); 34 34 35 35 /** 36 36 * Setup test.