Changeset 27516 in osm for applications/editors/josm/plugins/utilsplugin2
- Timestamp:
- 2012-01-21T05:22:02+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java
r27505 r27516 70 70 } 71 71 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 73 73 if (!node.isNew()) { 74 74 // Prepare a list of nodes that are not used anywhere except in the way 75 75 Collection<Node> nodePool = getUnimportantNodes(way); 76 76 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 79 84 List<Command> commands = new ArrayList<Command>(); 80 85 AbstractMap<String, String> nodeTags = (AbstractMap<String, String>) node.getKeys(); 81 86 82 87 // replace sacrificial node in way with node that is being upgraded 83 88 if (nodeToReplace != null) { … … 85 90 int idx = wayNodes.indexOf(nodeToReplace); 86 91 wayNodes.set(idx, node); 87 if (idx == 0 ) {92 if (idx == 0 && way.isClosed()) { 88 93 // node is at start/end of way 89 94 wayNodes.set(wayNodes.size() - 1, node); … … 92 97 commands.add(new MoveCommand(node, nodeToReplace.getCoor())); 93 98 commands.add(new DeleteCommand(nodeToReplace)); 94 99 95 100 // delete tags from node 96 101 if (!nodeTags.isEmpty()) { 97 AbstractMap<String, String> nodeTagsToDelete = new HashMap<String, String>();98 102 for (String key : nodeTags.keySet()) { 99 nodeTagsToDelete.put(key, null);103 commands.add(new ChangePropertyCommand(node, key, null)); 100 104 } 101 commands.add(new ChangePropertyCommand(Arrays.asList(node), nodeTagsToDelete)); 105 102 106 } 103 107 } else { … … 108 112 // Copy tags from node 109 113 // 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 112 118 getCurrentDataSet().setSelected(way); 113 119 114 120 Main.main.undoRedo.add(new SequenceCommand( 115 121 tr("Replace geometry for way {0}", way.getDisplayName(DefaultNameFormatter.getInstance())), … … 209 215 /** 210 216 * Create a list of nodes that are not used anywhere except in the way. 217 * 211 218 * @param way 212 219 * @return 213 220 */ 214 p ublicCollection<Node> getUnimportantNodes(Way way) {221 protected Collection<Node> getUnimportantNodes(Way way) { 215 222 Set<Node> nodePool = new HashSet<Node>(); 216 223 Area a = getCurrentDataSet().getDataSourceArea();
Note:
See TracChangeset
for help on using the changeset viewer.