Changeset 2565 in josm
- Timestamp:
- 2009-12-03T20:26:00+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r2323 r2565 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;6 6 7 7 import java.awt.event.ActionEvent; … … 24 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;27 26 import org.openstreetmap.josm.tools.Shortcut; 28 27 … … 173 172 if (a1 < 999) { 174 173 // if it is, delete it 175 CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet()); 176 refs.initialize(); 177 refs.visit(n1); 178 if (refs.getData().isEmpty() || ((refs.getData().size() == 1) && (refs.getData().contains(existingWay)))) { 174 List<OsmPrimitive> parents = n1.getReferrers(); 175 if (parents.isEmpty() || ((parents.size() == 1) && (parents.contains(existingWay)))) { 179 176 cmds.add(new DeleteCommand(n1)); 180 177 } -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r2512 r2565 25 25 import org.openstreetmap.josm.command.DeleteCommand; 26 26 import org.openstreetmap.josm.command.SequenceCommand; 27 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;28 27 import org.openstreetmap.josm.data.osm.Node; 29 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 import org.openstreetmap.josm.data.osm.RelationToChildReference; 30 30 import org.openstreetmap.josm.data.osm.TagCollection; 31 31 import org.openstreetmap.josm.data.osm.Way; 32 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;33 32 import org.openstreetmap.josm.gui.DefaultNameFormatter; 34 33 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 90 89 91 90 /** 92 * Merges the nodes in <code>node</code> onto one of the nodes. Uses the dataset93 * managed by <code>layer</code> as reference.94 *95 * @param layer the reference data layer. Must not be null.96 * @param nodes the collection of nodes. Ignored if null.97 * @param targetNode the target node the collection of nodes is merged to. Must not be null.98 * @throws IllegalArgumentException thrown if layer is null99 * @throws IllegalArgumentException thrown if targetNode is null100 *101 */102 public static Command mergeNodes(OsmDataLayer layer, Collection<Node> nodes, Node targetNode) throws IllegalArgumentException{103 if (layer == null)104 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes"));105 if (targetNode == null)106 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "targetNode"));107 108 if (nodes == null)109 return null;110 nodes.remove(null); // just in case111 BackreferencedDataSet backreferences = new BackreferencedDataSet();112 return mergeNodes(layer,backreferences, nodes, targetNode);113 }114 115 /**116 91 * Fixes the parent ways referring to one of the nodes. 117 92 * … … 119 94 * which is referred to by a relation. 120 95 * 121 * @param backreferences the backreference data set122 96 * @param nodesToDelete the collection of nodes to be deleted 123 97 * @param targetNode the target node the other nodes are merged to 124 98 * @return a list of commands; null, if the ways could not be fixed 125 99 */ 126 protected static List<Command> fixParentWays( BackreferencedDataSet backreferences,Collection<OsmPrimitive> nodesToDelete, Node targetNode) {100 protected static List<Command> fixParentWays(Collection<OsmPrimitive> nodesToDelete, Node targetNode) { 127 101 List<Command> cmds = new ArrayList<Command>(); 128 102 Set<Way> waysToDelete = new HashSet<Way>(); 129 103 130 for (Way w: OsmPrimitive.getFilteredList( backreferences.getParents(nodesToDelete), Way.class)) {104 for (Way w: OsmPrimitive.getFilteredList(OsmPrimitive.getReferrer(nodesToDelete), Way.class)) { 131 105 ArrayList<Node> newNodes = new ArrayList<Node>(w.getNodesCount()); 132 106 for (Node n: w.getNodes()) { … … 145 119 } 146 120 if (newNodes.size() < 2) { 147 if ( backreferences.getParents(w).isEmpty()) {121 if (w.getReferrers().isEmpty()) { 148 122 waysToDelete.add(w); 149 123 } else { … … 171 145 return null; 172 146 } 173 } else if(newNodes.size() < 2 && backreferences.getParents(w).isEmpty()) {147 } else if(newNodes.size() < 2 && w.getReferrers().isEmpty()) { 174 148 waysToDelete.add(w); 175 149 } else { … … 187 161 /** 188 162 * Merges the nodes in <code>nodes</code> onto one of the nodes. Uses the dataset 189 * managed by <code>layer</code> as reference. <code>backreferences</code> is a precomputed 190 * collection of all parent/child references in the dataset. 163 * managed by <code>layer</code> as reference. 191 164 * 192 165 * @param layer layer the reference data layer. Must not be null. 193 * @param backreferences if null, backreferences are first computed from layer.data; otherwise194 * backreferences.getSource() == layer.data must be true195 166 * @param nodes the collection of nodes. Ignored if null. 196 167 * @param targetNode the target node the collection of nodes is merged to. Must not be null. 197 168 * @throw IllegalArgumentException thrown if layer is null 198 * @throw IllegalArgumentException thrown if backreferences.getSource() != layer.data199 169 */ 200 public static Command mergeNodes(OsmDataLayer layer, BackreferencedDataSet backreferences,Collection<Node> nodes, Node targetNode) {170 public static Command mergeNodes(OsmDataLayer layer,Collection<Node> nodes, Node targetNode) { 201 171 if (layer == null) 202 172 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "nodes")); … … 205 175 if (nodes == null) 206 176 return null; 207 if (backreferences == null) { 208 backreferences = new BackreferencedDataSet(); 209 } 210 211 Set<RelationToChildReference> relationToNodeReferences = backreferences.getRelationToChildReferences(nodes); 177 178 179 Set<RelationToChildReference> relationToNodeReferences = RelationToChildReference.getRelationToChildReferences(nodes); 212 180 213 181 // build the tag collection … … 245 213 Collection<Way> waysToDelete= new HashSet<Way>(); 246 214 List<Command> wayFixCommands = fixParentWays( 247 backreferences,248 215 nodesToDelete, 249 216 targetNode -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r2510 r2565 20 20 import org.openstreetmap.josm.data.osm.User; 21 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;23 22 import org.openstreetmap.josm.tools.DateUtils; 24 23 … … 33 32 private static String rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}"); 34 33 private PushbackTokenizer tokenizer; 35 private CollectBackReferencesVisitor childBackRefs;36 34 37 35 public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) { … … 39 37 this.regexSearch = regexSearch; 40 38 this.tokenizer = tokenizer; 41 childBackRefs = new CollectBackReferencesVisitor(true);42 39 } 43 40 … … 527 524 private static class Child extends Match { 528 525 private final Match parent; 529 private final CollectBackReferencesVisitor childBackRefs; 530 531 public Child(Match m, CollectBackReferencesVisitor childBackRefs) { 526 527 public Child(Match m) { 532 528 // "child" (null) should mean the same as "child()" 533 529 // (Always). I.e. match everything … … 537 533 parent = m; 538 534 } 539 this.childBackRefs = childBackRefs;540 535 } 541 536 542 537 @Override public boolean match(OsmPrimitive osm) { 543 538 boolean isChild = false; 544 childBackRefs.initialize(); 545 osm.visit(childBackRefs); 546 for (OsmPrimitive p : childBackRefs.getData()) { 539 for (OsmPrimitive p : osm.getReferrers()) { 547 540 isChild |= parent.match(p); 548 541 } … … 651 644 return new Selected(); 652 645 else if (tok.equals("child")) 653 return new Child(parseParens() , childBackRefs);646 return new Child(parseParens()); 654 647 else if (tok.equals("parent")) 655 648 return new Parent(parseParens()); -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r2521 r2565 24 24 import org.openstreetmap.josm.Main; 25 25 import org.openstreetmap.josm.actions.SplitWayAction; 26 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;27 26 import org.openstreetmap.josm.data.osm.Node; 28 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 28 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 30 29 import org.openstreetmap.josm.data.osm.Relation; 30 import org.openstreetmap.josm.data.osm.RelationToChildReference; 31 31 import org.openstreetmap.josm.data.osm.Way; 32 32 import org.openstreetmap.josm.data.osm.WaySegment; 33 import org.openstreetmap.josm.data.osm.BackreferencedDataSet.RelationToChildReference;34 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor;35 33 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 36 34 import org.openstreetmap.josm.gui.DefaultNameFormatter; … … 218 216 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "layer")); 219 217 if (selection == null || selection.isEmpty()) return null; 220 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data); 221 v.initialize(); 222 for (OsmPrimitive osm : selection) { 223 osm.visit(v); 224 } 225 v.getData().addAll(selection); 226 if (v.getData().isEmpty()) 218 Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection); 219 parents.addAll(selection); 220 221 if (parents.isEmpty()) 227 222 return null; 228 if (!checkAndConfirmOutlyingDeletes(layer, v.getData()) && !silent)223 if (!checkAndConfirmOutlyingDeletes(layer,parents) && !silent) 229 224 return null; 230 return new DeleteCommand(layer, v.getData());225 return new DeleteCommand(layer,parents); 231 226 } 232 227 … … 246 241 * <li>it is not referred to by other non-deleted primitives outside of <code>primitivesToDelete</code></li> 247 242 * <ul> 248 * @param backreferences backreference data structure249 243 * @param layer the layer in whose context primitives are deleted 250 244 * @param primitivesToDelete the primitives to delete … … 252 246 * can be deleted too 253 247 */ 254 protected static Collection<Node> computeNodesToDelete( BackreferencedDataSet backreferences,OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) {248 protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) { 255 249 Collection<Node> nodesToDelete = new HashSet<Node>(); 256 250 for (Way way : OsmPrimitive.getFilteredList(primitivesToDelete, Way.class)) { … … 259 253 continue; 260 254 } 261 Collection<OsmPrimitive> referringPrimitives = backreferences.getParents(n);255 Collection<OsmPrimitive> referringPrimitives = n.getReferrers(); 262 256 referringPrimitives.removeAll(primitivesToDelete); 263 257 int count = 0; … … 314 308 return null; 315 309 316 BackreferencedDataSet backreferences = new BackreferencedDataSet();317 310 Set<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection); 318 311 Collection<Way> waysToBeChanged = new HashSet<Way>(); … … 321 314 // delete untagged nodes only referenced by primitives in primitivesToDelete, 322 315 // too 323 Collection<Node> nodesToDelete = computeNodesToDelete( backreferences,layer, primitivesToDelete);316 Collection<Node> nodesToDelete = computeNodesToDelete(layer, primitivesToDelete); 324 317 primitivesToDelete.addAll(nodesToDelete); 325 318 } … … 328 321 return null; 329 322 330 waysToBeChanged.addAll(OsmPrimitive.getFilteredSet( backreferences.getParents(primitivesToDelete), Way.class));323 waysToBeChanged.addAll(OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Way.class)); 331 324 332 325 Collection<Command> cmds = new LinkedList<Command>(); … … 345 338 // 346 339 if (!silent) { 347 Set<RelationToChildReference> references = backreferences.getRelationToChildReferences(primitivesToDelete);340 Set<RelationToChildReference> references = RelationToChildReference.getRelationToChildReferences(primitivesToDelete); 348 341 Iterator<RelationToChildReference> it = references.iterator(); 349 342 while(it.hasNext()) { … … 364 357 // remove the objects from their parent relations 365 358 // 366 Iterator<Relation> iterator = OsmPrimitive.getFilteredSet( backreferences.getParents(primitivesToDelete), Relation.class).iterator();359 Iterator<Relation> iterator = OsmPrimitive.getFilteredSet(OsmPrimitive.getReferrer(primitivesToDelete), Relation.class).iterator(); 367 360 while (iterator.hasNext()) { 368 361 Relation cur = iterator.next(); -
trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
r2512 r2565 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.conflict.ConflictCollection; 19 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;20 19 import org.openstreetmap.josm.data.osm.Node; 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 51 50 private Set<OsmPrimitive> origVersionsOfTouchedPrimitives; 52 51 53 /**54 * the data structure with child->parent references55 */56 private BackreferencedDataSet backreferenceDataSet;57 58 52 protected void init(Collection<OsmPrimitive> toPurge) { 59 53 this.toPurge = toPurge; … … 141 135 protected void removeReferecesToPrimitive(OsmPrimitive child, Set<OsmPrimitive> hive) { 142 136 hive.remove(child); 143 for (OsmPrimitive parent: this.backreferenceDataSet.getParents(child)) {137 for (OsmPrimitive parent: child.getReferrers()) { 144 138 if (toPurge.contains(parent)) 145 139 // parent itself is to be purged. This method is going to be … … 177 171 @Override 178 172 public boolean executeCommand() { 179 if (backreferenceDataSet == null) {180 backreferenceDataSet = new BackreferencedDataSet();181 }182 173 HashSet<OsmPrimitive> hive = new HashSet<OsmPrimitive>(); 183 174 … … 198 189 } 199 190 } 200 // we don't need this any more201 backreferenceDataSet = null;202 191 return super.executeCommand(); 203 192 } … … 231 220 super.undoCommand(); 232 221 } 233 234 /**235 * Use to inject a backreference data set used when the command236 * is executed.237 *238 * @param ds the backreference data set239 */240 public void setBackreferenceDataSet(BackreferencedDataSet ds) {241 this.backreferenceDataSet = ds;242 }243 222 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2512 r2565 149 149 } 150 150 151 /** 152 * Replies the collection of referring primitives for the primitives in <code>primitives</code>. 153 * 154 * @param primitives the collection of primitives. 155 * @return the collection of referring primitives for the primitives in <code>primitives</code>; 156 * empty set if primitives is null or if there are no referring primitives 157 */ 158 static public Set<OsmPrimitive> getReferrer(Collection<? extends OsmPrimitive> primitives) { 159 HashSet<OsmPrimitive> ret = new HashSet<OsmPrimitive>(); 160 if (primitives == null || primitives.isEmpty()) return ret; 161 for (OsmPrimitive p: primitives) { 162 ret.addAll(p.getReferrers()); 163 } 164 return ret; 165 } 166 167 151 168 /* mappaint data */ 152 169 public ElemStyle mappaintStyle = null; -
trunk/src/org/openstreetmap/josm/gui/actionsupport/DeleteFromRelationConfirmationDialog.java
r2512 r2565 2 2 package org.openstreetmap.josm.gui.actionsupport; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static org.openstreetmap.josm.tools.I18n.trn; … … 38 39 import org.openstreetmap.josm.data.osm.NameFormatter; 39 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 40 import org.openstreetmap.josm.data.osm. BackreferencedDataSet.RelationToChildReference;41 import org.openstreetmap.josm.data.osm.RelationToChildReference; 41 42 import org.openstreetmap.josm.gui.DefaultNameFormatter; 42 43 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 46 47 import org.openstreetmap.josm.tools.ImageProvider; 47 48 import org.openstreetmap.josm.tools.WindowGeometry; 48 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;49 49 50 50 /** … … 264 264 RelationToChildReference ref = data.get(rowIndex); 265 265 switch(columnIndex) { 266 267 268 269 270 271 266 case 0: return ref.getChild(); 267 case 1: return ref.getParent(); 268 case 2: return ref.getPosition(); 269 case 3: return ref.getRole(); 270 default: 271 assert false: "Illegal column index"; 272 272 } 273 273 return null; -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
r2512 r2565 18 18 import org.openstreetmap.josm.data.osm.Relation; 19 19 import org.openstreetmap.josm.data.osm.RelationMember; 20 import org.openstreetmap.josm.data.osm. BackreferencedDataSet.RelationToChildReference;20 import org.openstreetmap.josm.data.osm.RelationToChildReference; 21 21 22 22 /** … … 92 92 RelationMemberConflictDecision d = decisions.get(row); 93 93 switch(column) { 94 95 96 97 98 94 case 0: /* relation */ return d.getRelation(); 95 case 1: /* pos */ return Integer.toString(d.getPos() + 1); // position in "user space" starting at 1 96 case 2: /* role */ return d.getRole(); 97 case 3: /* original */ return d.getOriginalPrimitive(); 98 case 4: /* decision */ return d.getDecision(); 99 99 } 100 100 return null; … … 105 105 RelationMemberConflictDecision d = decisions.get(row); 106 106 switch(column) { 107 108 109 110 111 112 113 107 case 2: /* role */ 108 d.setRole((String)value); 109 break; 110 case 4: /* decision */ 111 d.decide((RelationMemberConflictDecisionType)value); 112 refresh(); 113 break; 114 114 } 115 115 fireTableDataChanged(); … … 233 233 } else { 234 234 switch(decision.getDecision()) { 235 236 237 238 239 240 241 242 243 244 245 246 235 case KEEP: 236 rmNew = new RelationMember(decision.getRole(),newPrimitive); 237 modifiedRelation.addMember(rmNew); 238 isChanged |= ! rm.equals(rmNew); 239 break; 240 case REMOVE: 241 isChanged = true; 242 // do nothing 243 break; 244 case UNDECIDED: 245 // FIXME: this is an error 246 break; 247 247 } 248 248 } … … 278 278 } 279 279 switch(decision.getDecision()) { 280 281 282 283 284 285 286 287 280 case REMOVE: return true; 281 case KEEP: 282 if (!relation.getMember(i).getRole().equals(decision.getRole())) 283 return true; 284 if (relation.getMember(i).getMember() != newPrimitive) 285 return true; 286 case UNDECIDED: 287 // FIXME: handle error 288 288 } 289 289 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r2512 r2565 49 49 import org.openstreetmap.josm.data.gpx.GpxTrack; 50 50 import org.openstreetmap.josm.data.gpx.WayPoint; 51 import org.openstreetmap.josm.data.osm.BackreferencedDataSet;52 51 import org.openstreetmap.josm.data.osm.DataSet; 53 52 import org.openstreetmap.josm.data.osm.DataSetMerger; … … 394 393 */ 395 394 protected PurgePrimitivesCommand buildPurgeCommand() { 396 BackreferencedDataSet ds = new BackreferencedDataSet();397 395 ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>(); 398 396 conflictLoop: for (Conflict<?> c: conflicts) { … … 416 414 // gets purged. 417 415 // 418 for (OsmPrimitive parent: ds.getParents(c.getMy())) {416 for (OsmPrimitive parent: c.getMy().getReferrers()) { 419 417 if (parent.isModified() && parent instanceof Way) { 420 418 continue conflictLoop; … … 426 424 if (toPurge.isEmpty()) return null; 427 425 PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge); 428 cmd.setBackreferenceDataSet(ds);429 426 return cmd; 430 427 }
Note:
See TracChangeset
for help on using the changeset viewer.