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


Ignore:
Timestamp:
2008-07-10T11:48:15+02:00 (16 years ago)
Author:
stoecker
Message:

added patch by Andy Street to reduce creating new ways when unnecessary. Fixes #553.

File:
1 edited

Legend:

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

    r627 r699  
    148148                }
    149149
    150                 Way newWay = new Way(selectedWays.get(0));
     150                // Find the most appropriate way to modify.
     151
     152                // Eventually this might want to be the way with the longest
     153                // history or the longest selected way but for now just attempt
     154                // to reuse an existing id.
     155                Way modifyWay = selectedWays.peek();
     156                for (Way w : selectedWays) {
     157                        modifyWay = w;
     158                        if (w.id != 0) break;
     159                }
     160                Way newWay = new Way(modifyWay);
     161
    151162                newWay.nodes.clear();
    152163                newWay.nodes.addAll(nodeList);
     
    179190
    180191                LinkedList<Command> cmds = new LinkedList<Command>();
    181                 cmds.add(new DeleteCommand(selectedWays.subList(1, selectedWays.size())));
    182                 cmds.add(new ChangeCommand(selectedWays.peek(), newWay));
     192                LinkedList<Way> deletedWays = new LinkedList<Way>(selectedWays);
     193                deletedWays.remove(modifyWay);
     194                cmds.add(new DeleteCommand(deletedWays));
     195                cmds.add(new ChangeCommand(modifyWay, newWay));
    183196
    184197                // modify all relations containing the now-deleted ways
     
    197210                        }
    198211                        for (String role : rolesToReAdd) {
    199                                 newRel.members.add(new RelationMember(role, selectedWays.peek()));
     212                                newRel.members.add(new RelationMember(role, modifyWay));
    200213                        }
    201214                        cmds.add(new ChangeCommand(r, newRel));
    202215                }
    203216                Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds));
    204                 Main.ds.setSelected(selectedWays.peek());
     217                Main.ds.setSelected(modifyWay);
    205218        }
    206219
Note: See TracChangeset for help on using the changeset viewer.