Changeset 14653 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2019-01-06T13:17:37+01:00 (5 years ago)
Author:
simon04
Message:

fix #16874 – Keep the id on the POI if unglueing

When unglueing a node from a way, retain the history on the node which gets assigned the tags.

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

Legend:

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

    r14650 r14653  
    2525import org.openstreetmap.josm.command.ChangeNodesCommand;
    2626import org.openstreetmap.josm.command.Command;
     27import org.openstreetmap.josm.command.MoveCommand;
    2728import org.openstreetmap.josm.command.SequenceCommand;
    2829import org.openstreetmap.josm.data.UndoRedoHandler;
     30import org.openstreetmap.josm.data.coor.LatLon;
    2931import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    3032import org.openstreetmap.josm.data.osm.Node;
     
    192194    }
    193195
    194     private static void updateMemberships(ExistingBothNew memberships, Node existingNode, List<Node> newNodes, Collection<Command> cmds) {
    195         if (ExistingBothNew.BOTH.equals(memberships)) {
    196             fixRelations(existingNode, cmds, newNodes, false);
    197         } else if (ExistingBothNew.NEW.equals(memberships)) {
    198             fixRelations(existingNode, cmds, newNodes, true);
    199         }
    200     }
    201 
    202196    /**
    203197     * Assumes there is one tagged Node stored in selectedNode that it will try to unglue.
     
    214208        }
    215209
    216         final Node n = new Node(selectedNode, true);
     210        final Node unglued = new Node(selectedNode, true);
     211        boolean moveSelectedNode = false;
    217212
    218213        List<Command> cmds = new LinkedList<>();
    219         cmds.add(new AddCommand(selectedNode.getDataSet(), n));
    220         if (dialog != null) {
    221             update(dialog, selectedNode, Collections.singletonList(n), cmds);
     214        cmds.add(new AddCommand(selectedNode.getDataSet(), unglued));
     215        if (dialog != null && ExistingBothNew.NEW.equals(dialog.getTags())) {
     216            // unglued node gets the ID and history, thus replace way node with a fresh one
     217            final Way way = selectedNode.getParentWays().get(0);
     218            final List<Node> newWayNodes = way.getNodes();
     219            newWayNodes.replaceAll(n -> selectedNode.equals(n) ? unglued : n);
     220            cmds.add(new ChangeNodesCommand(way, newWayNodes));
     221            updateMemberships(dialog.getMemberships().opposite(), selectedNode, Collections.singletonList(unglued), cmds);
     222            updateProperties(dialog.getTags().opposite(), selectedNode, Collections.singletonList(unglued), cmds);
     223            moveSelectedNode = true;
     224        } else if (dialog != null) {
     225            update(dialog, selectedNode, Collections.singletonList(unglued), cmds);
    222226        }
    223227
     
    225229        MapView mv = MainApplication.getMap().mapView;
    226230        if (e.getSource() instanceof JPanel) {
    227             n.setCoor(mv.getLatLon(mv.lastMEvent.getX(), mv.lastMEvent.getY()));
     231            final LatLon latLon = mv.getLatLon(mv.lastMEvent.getX(), mv.lastMEvent.getY());
     232            if (moveSelectedNode) {
     233                cmds.add(new MoveCommand(selectedNode, latLon));
     234            } else {
     235                unglued.setCoor(latLon);
     236            }
    228237        }
    229238
    230239        UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Unglued Node"), cmds));
    231         getLayerManager().getEditDataSet().setSelected(n);
     240        getLayerManager().getEditDataSet().setSelected(moveSelectedNode ? selectedNode : unglued);
    232241        mv.repaint();
    233242    }
     
    371380    /**
    372381     * put all newNodes into the same relation(s) that originalNode is in
     382     * @param memberships where the memberships should be places
    373383     * @param originalNode original node to duplicate
    374384     * @param cmds List of commands that will contain the new "change relation" commands
    375385     * @param newNodes List of nodes that contain the new node
    376      * @param removeOldMember whether the membership of the "old node" should be removed
    377      */
    378     private static void fixRelations(Node originalNode, Collection<Command> cmds, List<Node> newNodes, boolean removeOldMember) {
     386     */
     387    private static void updateMemberships(ExistingBothNew memberships, Node originalNode, List<Node> newNodes, Collection<Command> cmds) {
     388        if (ExistingBothNew.OLD.equals(memberships)) {
     389            return;
     390        }
    379391        // modify all relations containing the node
    380392        for (Relation r : OsmPrimitive.getFilteredList(originalNode.getReferrers(), Relation.class)) {
     
    403415                            newRel.addMember(role.getValue() + 1, new RelationMember(role.getKey(), n));
    404416                        }
    405                         if (removeOldMember) {
     417                        if (ExistingBothNew.NEW.equals(memberships)) {
     418                            // remove old member
    406419                            newRel.removeMember(role.getValue());
    407420                        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java

    r14652 r14653  
    3131    private final transient ExistingBothNewChoice memberships;
    3232
     33    /**
     34     * Represents the user choice: the existing node, the new nodes, or all of them
     35     */
    3336    public enum ExistingBothNew {
    34         OLD, BOTH, NEW
     37        OLD, BOTH, NEW;
     38
     39        /**
     40         * Returns the opposite/inverted user choice.
     41         * @return the opposite/inverted user choice
     42         */
     43        public ExistingBothNew opposite() {
     44            return equals(OLD) ? NEW : equals(NEW) ? OLD : this;
     45        }
    3546    }
    3647
Note: See TracChangeset for help on using the changeset viewer.