Ignore:
Timestamp:
2012-01-21T05:22:02+01:00 (13 years ago)
Author:
joshdoe
Message:

utilsplugin2: fix bugs in ReplaceGeometry and avoid core version bump

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java

    r27505 r27516  
    7070        }
    7171        Node nodeToReplace = null;
    72         // see if we need to replace a node in the replacement way
     72        // see if we need to replace a node in the replacement way to preserve connection in history
    7373        if (!node.isNew()) {
    7474            // Prepare a list of nodes that are not used anywhere except in the way
    7575            Collection<Node> nodePool = getUnimportantNodes(way);
    7676            nodeToReplace = findNearestNode(node, nodePool);
    77         }
    78        
     77
     78            if (nodeToReplace == null && !nodePool.isEmpty()) {
     79                // findNearestNode failed, just pick the first unimportant node
     80                nodeToReplace = nodePool.iterator().next();
     81            }
     82        }
     83
    7984        List<Command> commands = new ArrayList<Command>();
    8085        AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) node.getKeys();
    81        
     86
    8287        // replace sacrificial node in way with node that is being upgraded
    8388        if (nodeToReplace != null) {
     
    8590            int idx = wayNodes.indexOf(nodeToReplace);
    8691            wayNodes.set(idx, node);
    87             if (idx == 0) {
     92            if (idx == 0 && way.isClosed()) {
    8893                // node is at start/end of way
    8994                wayNodes.set(wayNodes.size() - 1, node);
     
    9297            commands.add(new MoveCommand(node, nodeToReplace.getCoor()));
    9398            commands.add(new DeleteCommand(nodeToReplace));
    94            
     99
    95100            // delete tags from node
    96101            if (!nodeTags.isEmpty()) {
    97                 AbstractMap<String, String> nodeTagsToDelete = new HashMap<String, String>();
    98102                for (String key : nodeTags.keySet()) {
    99                     nodeTagsToDelete.put(key, null);
     103                    commands.add(new ChangePropertyCommand(node, key, null));
    100104                }
    101                 commands.add(new ChangePropertyCommand(Arrays.asList(node), nodeTagsToDelete));
     105
    102106            }
    103107        } else {
     
    108112        // Copy tags from node
    109113        // TODO: use merge tag conflict dialog instead
    110         commands.add(new ChangePropertyCommand(Arrays.asList(way), nodeTags));
    111        
     114        for (String key : nodeTags.keySet()) {
     115            commands.add(new ChangePropertyCommand(way, key, nodeTags.get(key)));
     116        }
     117
    112118        getCurrentDataSet().setSelected(way);
    113        
     119
    114120        Main.main.undoRedo.add(new SequenceCommand(
    115121                tr("Replace geometry for way {0}", way.getDisplayName(DefaultNameFormatter.getInstance())),
     
    209215    /**
    210216     * Create a list of nodes that are not used anywhere except in the way.
     217     *
    211218     * @param way
    212219     * @return
    213220     */
    214     public Collection<Node> getUnimportantNodes(Way way) {
     221    protected Collection<Node> getUnimportantNodes(Way way) {
    215222        Set<Node> nodePool = new HashSet<Node>();
    216223        Area a = getCurrentDataSet().getDataSourceArea();
Note: See TracChangeset for help on using the changeset viewer.