Changeset 3134 in josm for trunk/src/org
- Timestamp:
- 2010-03-14T15:05:55+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r2842 r3134 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others 1 //License: GPL. Copyright 2007 by Immanuel Scholz and others. See LICENSE file for details. 2 2 package org.openstreetmap.josm.actions; 3 3 … … 41 41 * Merges a collection of nodes into one node. 42 42 * 43 * The "surviving" node will be the one with the lowest positive id. 44 * (I.e. it was uploaded to the server and is the oldest one.) 45 * 46 * However we use the location of the node that was selected *last*. 47 * The "surviving" node will be moved to that location if it is 48 * different from the last selected node. 43 49 */ 44 50 public class MergeNodesAction extends JosmAction { … … 66 72 67 73 Node targetNode = selectTargetNode(selectedNodes); 68 Command cmd = mergeNodes(Main.main.getEditLayer(), selectedNodes, targetNode); 74 Node targetLocationNode = selectTargetLocationNode(selectedNodes); 75 Command cmd = mergeNodes(Main.main.getEditLayer(), selectedNodes, targetNode, targetLocationNode); 69 76 if (cmd != null) { 70 77 Main.main.undoRedo.add(cmd); … … 74 81 75 82 /** 83 * Select the location of the target node after merge. 84 * 85 * @param candidates the collection of candidate nodes 86 * @return the coordinates of this node are later used for the target node 87 */ 88 public static Node selectTargetLocationNode(LinkedHashSet<Node> candidates) { 89 Node targetNode = null; 90 for (Node n : candidates) { // pick last one 91 targetNode = n; 92 } 93 return targetNode; 94 } 95 96 /** 76 97 * Find which node to merge into (i.e. which one will be left) 77 * The last selected node will become the target node the remaining78 * nodes are merged to.79 98 * 80 99 * @param candidates the collection of candidate nodes … … 83 102 public static Node selectTargetNode(LinkedHashSet<Node> candidates) { 84 103 Node targetNode = null; 85 for (Node n : candidates) { // pick last one 86 targetNode = n; 104 Node lastNode = null; 105 for (Node n : candidates) { 106 if (!n.isNew()) { 107 if (targetNode == null) { 108 targetNode = n; 109 } else if (n.getId() < targetNode.getId()) { 110 targetNode = n; 111 } 112 } 113 lastNode = n; 114 } 115 if (targetNode == null) { 116 targetNode = lastNode; 87 117 } 88 118 return targetNode; 89 119 } 120 90 121 91 122 /** … … 160 191 } 161 192 193 public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode) { 194 return mergeNodes(layer, nodes, targetNode, targetNode); 195 } 196 162 197 /** 163 198 * Merges the nodes in <code>nodes</code> onto one of the nodes. Uses the dataset … … 167 202 * @param nodes the collection of nodes. Ignored if null. 168 203 * @param targetNode the target node the collection of nodes is merged to. Must not be null. 204 * @param targetLocationNode this node's location will be used for the targetNode. 169 205 * @throw IllegalArgumentException thrown if layer is null 170 206 */ 171 public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode) {207 public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode, Node targetLocationNode) { 172 208 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 173 209 CheckParameterUtil.ensureParameterNotNull(targetNode, "targetNode"); … … 220 256 // build the commands 221 257 // 258 if (targetNode != targetLocationNode) { 259 Node newTargetNode = new Node(targetNode); 260 newTargetNode.setCoor(targetLocationNode.getCoor()); 261 cmds.add(new ChangeCommand(targetNode, newTargetNode)); 262 } 222 263 if (!nodesToDelete.isEmpty()) { 223 264 cmds.add(new DeleteCommand(nodesToDelete));
Note:
See TracChangeset
for help on using the changeset viewer.