Ignore:
Timestamp:
2013-08-27T11:42:13+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #2447 - Unnessary changes of a target node by dragging another node onto it

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r6130 r6202  
    2828import org.openstreetmap.josm.data.osm.Node;
    2929import org.openstreetmap.josm.data.osm.OsmPrimitive;
    30 import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3130import org.openstreetmap.josm.data.osm.TagCollection;
    3231import org.openstreetmap.josm.data.osm.Way;
     
    5049 * The "surviving" node will be moved to that location if it is
    5150 * different from the last selected node.
     51 *
     52 * @since 422
    5253 */
    5354public class MergeNodesAction extends JosmAction {
    5455
     56    /**
     57     * Constructs a new {@code MergeNodesAction}.
     58     */
    5559    public MergeNodesAction() {
    5660        super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into the oldest one."),
     
    247251    }
    248252
     253    /**
     254     * Merges the nodes in {@code nodes} at the specified node's location. Uses the dataset
     255     * managed by {@code layer} as reference.
     256     * @param layer layer the reference data layer. Must not be null
     257     * @param nodes the collection of nodes. Ignored if null
     258     * @param targetLocationNode this node's location will be used for the target node
     259     * @throws IllegalArgumentException thrown if {@code layer} is null
     260     */
    249261    public static void doMergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetLocationNode) {
    250262        if (nodes == null) {
     
    253265        Set<Node> allNodes = new HashSet<Node>(nodes);
    254266        allNodes.add(targetLocationNode);
    255         Node target = selectTargetNode(allNodes);
     267        Node target;
     268        if (nodes.contains(targetLocationNode) && !targetLocationNode.isNew()) {
     269            target = targetLocationNode; // keep existing targetLocationNode as target to avoid unnecessary changes (see #2447)
     270        } else {
     271            target = selectTargetNode(allNodes);
     272        }
    256273
    257274        Command cmd = mergeNodes(layer, nodes, target, targetLocationNode);
     
    262279    }
    263280
     281    /**
     282     * Merges the nodes in {@code nodes} at the specified node's location. Uses the dataset
     283     * managed by {@code layer} as reference.
     284     *
     285     * @param layer layer the reference data layer. Must not be null.
     286     * @param nodes the collection of nodes. Ignored if null.
     287     * @param targetLocationNode this node's location will be used for the targetNode.
     288     * @return The command necessary to run in order to perform action, or {@code null} if there is nothing to do
     289     * @throws IllegalArgumentException thrown if {@code layer} is null
     290     */
    264291    public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetLocationNode) {
    265292        if (nodes == null) {
     
    279306     * @param targetNode the target node the collection of nodes is merged to. Must not be null.
    280307     * @param targetLocationNode this node's location will be used for the targetNode.
     308     * @return The command necessary to run in order to perform action, or {@code null} if there is nothing to do
    281309     * @throws IllegalArgumentException thrown if layer is null
    282310     */
     
    287315            return null;
    288316        }
    289 
    290         Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes);
    291317
    292318        try {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r6084 r6202  
    817817
    818818    /**
    819      * Merges the selected nodes to the one closest to the given mouse position iff the control
     819     * Merges the selected nodes to the one closest to the given mouse position if the control
    820820     * key is pressed. If there is no such node, no action will be done and no error will be
    821821     * reported. If there is, it will execute the merge and add it to the undo buffer.
Note: See TracChangeset for help on using the changeset viewer.