Changeset 2818 in josm
- Timestamp:
- 2010-01-11T21:25:29+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r2512 r2818 3 3 package org.openstreetmap.josm.actions; 4 4 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 6 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;7 7 8 8 import java.awt.event.ActionEvent; … … 11 11 import java.util.HashMap; 12 12 import java.util.List; 13 import java.util.ListIterator;14 13 import java.util.Map; 15 14 … … 18 17 import org.openstreetmap.josm.data.coor.EastNorth; 19 18 import org.openstreetmap.josm.data.osm.NodeData; 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 20 20 import org.openstreetmap.josm.data.osm.PrimitiveData; 21 21 import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy; … … 23 23 import org.openstreetmap.josm.data.osm.RelationMemberData; 24 24 import org.openstreetmap.josm.data.osm.WayData; 25 import org.openstreetmap.josm.gui.ExtendedDialog; 25 26 import org.openstreetmap.josm.gui.layer.Layer; 26 27 import org.openstreetmap.josm.tools.Shortcut; … … 43 44 /* Find the middle of the pasteBuffer area */ 44 45 double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; 46 boolean incomplete = false; 45 47 for (PrimitiveData data : pasteBuffer.getAll()) { 46 48 if (data instanceof NodeData) { … … 53 55 if (north < minNorth) { minNorth = north; } 54 56 } 57 if (data.isIncomplete()) { 58 incomplete = true; 59 } 60 } 61 62 // Allow to cancel paste if there are incomplete primitives 63 if (incomplete) { 64 if (!confirmDeleteIncomplete()) return; 55 65 } 56 66 … … 72 82 // Make a copy of pasteBuffer and map from old id to copied data id 73 83 List<PrimitiveData> bufferCopy = new ArrayList<PrimitiveData>(); 74 Map<Long, Long> newIds = new HashMap<Long, Long>(); 75 for (PrimitiveData data:pasteBuffer.getAll()) { 84 Map<Long, Long> newNodeIds = new HashMap<Long, Long>(); 85 Map<Long, Long> newWayIds = new HashMap<Long, Long>(); 86 Map<Long, Long> newRelationIds = new HashMap<Long, Long>(); 87 for (PrimitiveData data: pasteBuffer.getAll()) { 88 if (data.isIncomplete()) { 89 continue; 90 } 76 91 PrimitiveData copy = data.makeCopy(); 77 92 copy.clearOsmId(); 78 newIds.put(data.getId(), copy.getId()); 93 if (data instanceof NodeData) { 94 newNodeIds.put(data.getId(), copy.getId()); 95 } else if (data instanceof WayData) { 96 newWayIds.put(data.getId(), copy.getId()); 97 } else if (data instanceof RelationData) { 98 newRelationIds.put(data.getId(), copy.getId()); 99 } 79 100 bufferCopy.add(copy); 80 101 } … … 88 109 } 89 110 } else if (data instanceof WayData) { 90 ListIterator<Long> it = ((WayData)data).getNodes().listIterator(); 91 while (it.hasNext()) { 92 it.set(newIds.get(it.next())); 111 List<Long> newNodes = new ArrayList<Long>(); 112 for (Long oldNodeId: ((WayData)data).getNodes()) { 113 Long newNodeId = newNodeIds.get(oldNodeId); 114 if (newNodeId != null) { 115 newNodes.add(newNodeId); 116 } 93 117 } 118 ((WayData)data).setNodes(newNodes); 94 119 } else if (data instanceof RelationData) { 95 ListIterator<RelationMemberData> it = ((RelationData)data).getMembers().listIterator(); 96 while (it.hasNext()) { 97 RelationMemberData member = it.next(); 98 it.set(new RelationMemberData(member.getRole(), member.getMemberType(), newIds.get(member.getMemberId()))); 120 List<RelationMemberData> newMembers = new ArrayList<RelationMemberData>(); 121 for (RelationMemberData member: ((RelationData)data).getMembers()) { 122 OsmPrimitiveType memberType = member.getMemberType(); 123 Long newId = null; 124 switch (memberType) { 125 case NODE: 126 newId = newNodeIds.get(member.getMemberId()); 127 break; 128 case WAY: 129 newId = newWayIds.get(member.getMemberId()); 130 break; 131 case RELATION: 132 newId = newRelationIds.get(member.getMemberId()); 133 break; 134 } 135 if (newId != null) { 136 newMembers.add(new RelationMemberData(member.getRole(), memberType, newId)); 137 } 99 138 } 139 ((RelationData)data).setMembers(newMembers); 100 140 } 101 141 } … … 105 145 Main.main.undoRedo.add(new AddPrimitivesCommand(bufferCopy)); 106 146 Main.map.mapView.repaint(); 147 } 148 149 protected boolean confirmDeleteIncomplete() { 150 ExtendedDialog ed = new ExtendedDialog(Main.parent, 151 tr("Delete incomplete members?"), 152 new String[] {tr("Paste without incomplete members"), tr("Cancel")}); 153 ed.setButtonIcons(new String[] {"dialogs/relation/deletemembers.png", "cancel.png"}); 154 ed.setContent(tr("The copied data contains incomplete primitives. " 155 + "When pasting the incomplete primitives are removed. " 156 + "Do you want to paste the data without the incomplete primitives?")); 157 ed.showDialog(); 158 return ed.getValue() == 1; 107 159 } 108 160 -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r2405 r2818 54 54 } 55 55 56 @Override 56 57 public OsmPrimitiveType getType() { 57 58 return OsmPrimitiveType.NODE; 58 59 } 59 60 60 } -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r2615 r2818 197 197 return id <= 0; 198 198 } 199 200 public abstract OsmPrimitiveType getType(); 199 201 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r2405 r2818 7 7 public class RelationData extends PrimitiveData { 8 8 9 private finalList<RelationMemberData> members = new ArrayList<RelationMemberData>();9 private List<RelationMemberData> members = new ArrayList<RelationMemberData>(); 10 10 11 11 public RelationData() { … … 22 22 } 23 23 24 public void setMembers(List<RelationMemberData> memberData) { 25 members = new ArrayList<RelationMemberData>(memberData); 26 } 27 24 28 @Override 25 29 public RelationData makeCopy() { … … 32 36 } 33 37 38 @Override 34 39 public OsmPrimitiveType getType() { 35 40 return OsmPrimitiveType.RELATION; 36 41 } 37 38 42 } -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r2405 r2818 7 7 public class WayData extends PrimitiveData { 8 8 9 private finalList<Long> nodes = new ArrayList<Long>();9 private List<Long> nodes = new ArrayList<Long>(); 10 10 11 11 public WayData() { … … 22 22 } 23 23 24 public void setNodes(List<Long> nodes) { 25 this.nodes = new ArrayList<Long>(nodes); 26 } 27 24 28 @Override 25 29 public WayData makeCopy() { … … 32 36 } 33 37 38 @Override 34 39 public OsmPrimitiveType getType() { 35 40 return OsmPrimitiveType.WAY; 36 41 } 37 38 42 }
Note:
See TracChangeset
for help on using the changeset viewer.