Changeset 14653 in josm
- Timestamp:
- 2019-01-06T13:17:37+01:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r14650 r14653 25 25 import org.openstreetmap.josm.command.ChangeNodesCommand; 26 26 import org.openstreetmap.josm.command.Command; 27 import org.openstreetmap.josm.command.MoveCommand; 27 28 import org.openstreetmap.josm.command.SequenceCommand; 28 29 import org.openstreetmap.josm.data.UndoRedoHandler; 30 import org.openstreetmap.josm.data.coor.LatLon; 29 31 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 30 32 import org.openstreetmap.josm.data.osm.Node; … … 192 194 } 193 195 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 202 196 /** 203 197 * Assumes there is one tagged Node stored in selectedNode that it will try to unglue. … … 214 208 } 215 209 216 final Node n = new Node(selectedNode, true); 210 final Node unglued = new Node(selectedNode, true); 211 boolean moveSelectedNode = false; 217 212 218 213 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); 222 226 } 223 227 … … 225 229 MapView mv = MainApplication.getMap().mapView; 226 230 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 } 228 237 } 229 238 230 239 UndoRedoHandler.getInstance().add(new SequenceCommand(tr("Unglued Node"), cmds)); 231 getLayerManager().getEditDataSet().setSelected( n);240 getLayerManager().getEditDataSet().setSelected(moveSelectedNode ? selectedNode : unglued); 232 241 mv.repaint(); 233 242 } … … 371 380 /** 372 381 * put all newNodes into the same relation(s) that originalNode is in 382 * @param memberships where the memberships should be places 373 383 * @param originalNode original node to duplicate 374 384 * @param cmds List of commands that will contain the new "change relation" commands 375 385 * @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 } 379 391 // modify all relations containing the node 380 392 for (Relation r : OsmPrimitive.getFilteredList(originalNode.getReferrers(), Relation.class)) { … … 403 415 newRel.addMember(role.getValue() + 1, new RelationMember(role.getKey(), n)); 404 416 } 405 if (removeOldMember) { 417 if (ExistingBothNew.NEW.equals(memberships)) { 418 // remove old member 406 419 newRel.removeMember(role.getValue()); 407 420 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java
r14652 r14653 31 31 private final transient ExistingBothNewChoice memberships; 32 32 33 /** 34 * Represents the user choice: the existing node, the new nodes, or all of them 35 */ 33 36 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 } 35 46 } 36 47
Note:
See TracChangeset
for help on using the changeset viewer.