Changeset 22411 in osm
- Timestamp:
- 2010-07-21T19:55:15+02:00 (14 years ago)
- Location:
- applications/editors/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reverter/src/reverter/DataSetToCmd.java
r21807 r22411 8 8 9 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.command.ChangeNodesCommand;11 10 import org.openstreetmap.josm.command.Command; 12 11 import org.openstreetmap.josm.data.conflict.Conflict; 13 12 import org.openstreetmap.josm.data.conflict.ConflictCollection; 14 import org.openstreetmap.josm.data.osm.*; 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.Relation; 17 import org.openstreetmap.josm.data.osm.RelationMember; 18 import org.openstreetmap.josm.data.osm.Way; 15 19 16 20 /** … … 38 42 } 39 43 40 /**41 * Merges a primitive <code>other</code> of type <P> onto my primitives.42 *43 * @param <P> the type of the other primitive44 * @param source the other primitive45 */46 private void mergePrimitive(OsmPrimitive source) {47 if (source.isIncomplete()) return;48 if (!source.isVisible()) return;49 OsmPrimitive target = getMergeTarget(source);50 if (target.getVersion() == 0)51 throw new IllegalStateException(tr("Target of type {0} with id {1} has invalid version",52 target.getType(), target.getUniqueId()));53 OsmPrimitive newTarget;54 switch(target.getType()) {55 case NODE: newTarget = new Node((Node)target); break;56 case WAY: newTarget = new Way((Way)target); break;57 case RELATION: newTarget = new Relation((Relation)target); break;58 default: throw new AssertionError();59 }60 newTarget.mergeFrom(source);61 newTarget.setOsmId(target.getId(), (int)target.getVersion());62 newTarget.setVisible(target.isVisible());63 newTarget.setDeleted(false);64 cmds.add(new ChangeCommand(target,newTarget));65 }66 67 44 private OsmPrimitive getMergeTarget(OsmPrimitive mergeSource) { 68 45 OsmPrimitive p = targetDataSet.getPrimitiveById(mergeSource.getId(), mergeSource.getType()); … … 72 49 return p; 73 50 } 74 75 /** 76 * Postprocess the dataset and fix all merged references to point to the actual 77 * data. 78 */ 79 public void fixReferences() { 80 for (Way w : sourceDataSet.getWays()) { 81 mergeNodeList(w); 82 } 83 for (Relation r : sourceDataSet.getRelations()) { 84 mergeRelationMembers(r); 85 } 51 52 private void mergePrimitive(OsmPrimitive source, OsmPrimitive target, OsmPrimitive newTarget) { 53 newTarget.mergeFrom(source); 54 newTarget.setOsmId(target.getId(), (int)target.getVersion()); 55 newTarget.setVisible(target.isVisible()); 56 newTarget.setDeleted(false); 86 57 } 87 58 88 59 /** 89 * Merges the node list of a source way onto its target way. 60 * Merges the source node onto its target node. 61 * 62 * @param source the source way 63 */ 64 private void mergeNode(Node source) { 65 if (source.isIncomplete()) return; 66 if (!source.isVisible()) return; 67 Node target = (Node)getMergeTarget(source); 68 69 Node newTarget = new Node(target); 70 mergePrimitive(source, target, newTarget); 71 cmds.add(new ChangeCommand(target,newTarget)); 72 } 73 74 /** 75 * Merges the source way onto its target way. 90 76 * 91 77 * @param source the source way … … 94 80 * 95 81 */ 96 private void merge NodeList(Way source) throws IllegalStateException {82 private void mergeWay(Way source) throws IllegalStateException { 97 83 if (source.isIncomplete()) return; 98 84 if (!source.isVisible()) return; … … 111 97 newNodes.add(targetNode); 112 98 } 113 cmds.add(new ChangeNodesCommand(target,newNodes)); 99 Way newTarget = new Way(target); 100 mergePrimitive(source, target, newTarget); 101 newTarget.setNodes(newNodes); 102 cmds.add(new ChangeCommand(target,newTarget)); 114 103 } 115 104 116 105 /** 117 * Merges the relation members of asource relation onto the corresponding target relation.106 * Merges the source relation onto the corresponding target relation. 118 107 * @param source the source relation 119 108 * @throws IllegalStateException thrown if there is no corresponding target relation … … 121 110 * members in source 122 111 */ 123 private void mergeRelation Members(Relation source) throws IllegalStateException {112 private void mergeRelation(Relation source) throws IllegalStateException { 124 113 if (source.isIncomplete()) return; 125 114 if (!source.isVisible()) return; … … 143 132 newMembers.add(new RelationMember(sourceMember.getRole(), targetMember)); 144 133 } 145 Relation newRelation = new Relation(target); 134 Relation newRelation = new Relation(target); 135 mergePrimitive(source, target, newRelation); 146 136 newRelation.setMembers(newMembers); 147 137 cmds.add(new ChangeCommand(target,newRelation)); … … 149 139 private void merge() { 150 140 for (Node node: sourceDataSet.getNodes()) { 151 merge Primitive(node);141 mergeNode(node); 152 142 } 153 143 for (Way way: sourceDataSet.getWays()) { 154 merge Primitive(way);144 mergeWay(way); 155 145 } 156 146 for (Relation relation: sourceDataSet.getRelations()) { 157 merge Primitive(relation);147 mergeRelation(relation); 158 148 } 159 fixReferences();160 149 } 161 150
Note:
See TracChangeset
for help on using the changeset viewer.