Changeset 8343 in josm for trunk/src/org


Ignore:
Timestamp:
2015-05-10T00:55:10+02:00 (10 years ago)
Author:
Balaitous
Message:

see #10748 - Move and connect way to an external node with shape retention

  • When only one node is selected at same time as ways, keeps intact the shape.
  • Add test case.
File:
1 edited

Legend:

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

    r8338 r8343  
    856856            return;
    857857
     858        if (selNodes.size() == 1) {
     859            // Move all selected primitive to preserve shape #10748
     860            Collection<OsmPrimitive> selection =
     861                getCurrentDataSet().getSelectedNodesAndWays();
     862            Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection);
     863            Command c = getLastCommand();
     864            getCurrentDataSet().beginUpdate();
     865            if (c instanceof MoveCommand
     866                && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) {
     867                Node selectedNode = selNodes.iterator().next();
     868                EastNorth selectedEN = selectedNode.getEastNorth();
     869                EastNorth targetEN = target.getEastNorth();
     870                ((MoveCommand) c).moveAgain(targetEN.getX() - selectedEN.getX(),
     871                                            targetEN.getY() - selectedEN.getY());
     872            }
     873            getCurrentDataSet().endUpdate();
     874        }
     875
    858876        Collection<Node> nodesToMerge = new LinkedList<>(selNodes);
    859877        nodesToMerge.add(target);
    860         MergeNodesAction.doMergeNodes(Main.main.getEditLayer(), nodesToMerge, target);
     878        mergeNodes(Main.main.getEditLayer(), nodesToMerge, target);
     879    }
     880
     881    /**
     882     * Merge nodes using {@code MergeNodesAction}.
     883     * Can be overridden for testing purpose.
     884     * @param layer layer the reference data layer. Must not be null
     885     * @param nodes the collection of nodes. Ignored if null
     886     * @param targetLocationNode this node's location will be used for the target node
     887     */
     888    public void mergeNodes(OsmDataLayer layer, Collection<Node> nodes,
     889                           Node targetLocationNode) {
     890        MergeNodesAction.doMergeNodes(layer, nodes, targetLocationNode);
    861891    }
    862892
Note: See TracChangeset for help on using the changeset viewer.