Changeset 27972 in osm
- Timestamp:
- 2012-03-02T15:21:09+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryAction.java
r27971 r27972 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.actions.JosmAction; 11 import org.openstreetmap.josm.actions.MergeNodesAction; 11 12 import org.openstreetmap.josm.command.*; 12 13 import org.openstreetmap.josm.data.osm.Node; … … 56 57 57 58 try { 58 replace (firstObject, secondObject);59 replaceWithNew(firstObject, secondObject); 59 60 } catch (IllegalArgumentException ex) { 60 61 JOptionPane.showMessageDialog(Main.parent, … … 63 64 64 65 } 65 public boolean replace(OsmPrimitive firstObject, OsmPrimitive secondObject) { 66 if (firstObject instanceof Way && secondObject instanceof Way) { 67 return replaceWayWithWay(Arrays.asList((Way) firstObject, (Way) secondObject)); 68 } else if (firstObject instanceof Node && secondObject instanceof Node) { 69 throw new IllegalArgumentException(tr("To replace a node with a node, use the node merge tool.")); 66 67 /** 68 * Replace new or uploaded object with new object 69 * 70 * @param firstObject 71 * @param secondObject 72 * @return 73 */ 74 public boolean replaceWithNew(OsmPrimitive firstObject, OsmPrimitive secondObject) { 75 if (firstObject instanceof Node && secondObject instanceof Node) { 76 return replaceNodeWithNew((Node) firstObject, (Node) secondObject); 77 } else if (firstObject instanceof Way && secondObject instanceof Way) { 78 return replaceWayWithNew(Arrays.asList((Way) firstObject, (Way) secondObject)); 70 79 } else if (firstObject instanceof Node) { 71 return replaceNode((Node) firstObject, secondObject);80 return upgradeNode((Node) firstObject, secondObject); 72 81 } else if (secondObject instanceof Node) { 73 return replaceNode((Node) secondObject, firstObject);82 return upgradeNode((Node) secondObject, firstObject); 74 83 } else { 75 throw new IllegalArgumentException(tr("This tool can only replace a node with a way, a node with a multipolygon, or a way with a way.")); 76 } 77 } 78 79 /** 80 * Replace or upgrade a node to a way or multipolygon 84 throw new IllegalArgumentException(tr("This tool can only replace a node, upgrade a node to a way or a multipolygon, or replace a way with a way.")); 85 } 86 } 87 88 /** 89 * Replace a new or uploaded node with a new node 90 * @param firstNode 91 * @param secondNode 92 * @return 93 */ 94 public boolean replaceNodeWithNew(Node firstNode, Node secondNode) { 95 if (firstNode.isNew() && !secondNode.isNew()) 96 return replaceNode(secondNode, firstNode); 97 else if (!firstNode.isNew() && secondNode.isNew()) 98 return replaceNode(firstNode, secondNode); 99 else 100 // both nodes are new OR uploaded, act like MergeNodes, moving first 101 // node to second 102 return replaceNode(firstNode, secondNode); 103 } 104 105 /** 106 * Replace a node with another node (similar to MergeNodesAction) 107 * 108 * @param subjectNode 109 * @param referenceNode 110 * @return 111 */ 112 public boolean replaceNode(Node subjectNode, Node referenceNode) { 113 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) { 114 JOptionPane.showMessageDialog(Main.parent, tr("Node belongs to way(s), cannot replace."), 115 TITLE, JOptionPane.INFORMATION_MESSAGE); 116 return false; 117 } 118 // FIXME: handle different layers 119 List<Command> commands = new ArrayList<Command>(); 120 commands.add(MergeNodesAction.mergeNodes(Main.main.getEditLayer(), Arrays.asList(subjectNode, referenceNode), referenceNode)); 121 122 Main.main.undoRedo.add(new SequenceCommand( 123 tr("Replace geometry for node {0}", subjectNode.getDisplayName(DefaultNameFormatter.getInstance())), 124 commands)); 125 return true; 126 } 127 128 /** 129 * Upgrade a node to a way or multipolygon 81 130 * 82 131 * @param subjectNode node to be replaced 83 132 * @param referenceObject object with greater spatial quality 84 133 */ 85 public boolean replaceNode(Node subjectNode, OsmPrimitive referenceObject) {134 public boolean upgradeNode(Node subjectNode, OsmPrimitive referenceObject) { 86 135 if (!OsmPrimitive.getFilteredList(subjectNode.getReferrers(), Way.class).isEmpty()) { 87 136 JOptionPane.showMessageDialog(Main.parent, tr("Node belongs to way(s), cannot replace."), … … 164 213 } 165 214 166 public boolean replaceWayWith Way(List<Way> selection) {215 public boolean replaceWayWithNew(List<Way> selection) { 167 216 // determine which way will be replaced and which will provide the geometry 168 217 boolean overrideNewCheck = false;
Note:
See TracChangeset
for help on using the changeset viewer.