Ticket #2602: josm.child-parent-search.patch
| File josm.child-parent-search.patch, 3.7 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/search/SearchCompiler.java
11 11 import java.util.regex.Pattern; 12 12 import java.util.regex.PatternSyntaxException; 13 13 14 import org.openstreetmap.josm.Main; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 17 import org.openstreetmap.josm.data.osm.Relation; 18 import org.openstreetmap.josm.data.osm.RelationMember; 17 19 import org.openstreetmap.josm.data.osm.User; 18 20 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 19 22 import org.openstreetmap.josm.tools.DateUtils; 20 23 21 24 /** … … 319 322 } 320 323 @Override public String toString() {return "untagged";} 321 324 } 325 326 /** 327 * Matches objects which are parents of a selected object. 328 */ 329 private static class Parent extends Match { 330 @Override public boolean match(OsmPrimitive osm) { 331 boolean isParent = false; 332 if (osm instanceof Way) { 333 for (Node n : ((Way)osm).nodes) 334 isParent |= n.selected; 335 } else if (osm instanceof Relation) { 336 for (RelationMember member : ((Relation)osm).members) { 337 if (member.member != null) 338 isParent |= member.member.selected; 339 } 340 } 341 return isParent; 342 } 343 @Override public String toString() {return "parent";} 344 } 345 346 /** 347 * Matches objects which are children of a selected object. 348 */ 349 private static class Child extends Match { 350 @Override public boolean match(OsmPrimitive osm) { 351 boolean isChild = false; 352 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.ds); 353 osm.visit(backRefs); 354 for (OsmPrimitive parent : backRefs.data) { 355 isChild |= parent.selected; 356 } 357 return isChild; 358 } 359 360 @Override public String toString() {return "child";} 361 } 322 362 323 363 public static class ParseError extends Exception { 324 364 public ParseError(String msg) { … … 407 447 return new Untagged(); 408 448 } else if (tok.equals("selected")) { 409 449 return new Selected(); 450 } else if (tok.equals("parent")) { 451 return new Parent(); 452 } else if (tok.equals("child")) { 453 return new Child(); 410 454 } else { 411 455 return new Any(tok); 412 456 } -
src/org/openstreetmap/josm/actions/search/SearchAction.java
93 93 + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>" 94 94 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>" 95 95 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>" 96 + "<li>"+tr("<b>child</b> - all children of selected objects")+"</li>" 97 + "<li>"+tr("<b>parent</b> - all parents of selected objects")+"</li>" 96 98 + "<li>"+tr("Use <b>|</b> or <b>OR</b> to combine with logical or")+"</li>" 97 99 + "<li>"+tr("Use <b>\"</b> to quote operators (e.g. if key contains :)")+"</li>" 98 100 + "<li>"+tr("Use <b>(</b> and <b>)</b> to group expressions")+"</li>"
