Ignore:
Timestamp:
2012-11-13T14:19:52+01:00 (11 years ago)
Author:
simon04
Message:

fix #7262 - allow searching for position in way.

The search keyword nth: have been added in order to
search for the n-th member of relations and/or n-th node of ways.
Also, nth%: is supported which searches for every n-th item, respectively.

Location:
trunk/src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r5441 r5578  
    433433                , GBC.eol());
    434434            right.add(new SearchKeywordRow(hcbSearchString)
    435                 .addTitle(tr("relations"))
     435                .addTitle(tr("related objects"))
    436436                .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building")
    437437                .addKeyword("parent <i>expr</i>", "parent ", tr("all parents of objects matching the expression"), "parent bus_stop")
     438                .addKeyword("nth:<i>7</i>", "nth: ", tr("n-th member of relation and/or n-th node of way"), "nth:5 (child type:relation)")
     439                .addKeyword("nth%:<i>7</i>", "nth: ", tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)")
    438440                , GBC.eol());
    439441            right.add(new SearchKeywordRow(hcbSearchString)
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r5184 r5578  
    101101                "changeset", "nodes", "tags", "areasize", "modified", "selected",
    102102                "incomplete", "untagged", "closed", "new", "indownloadarea",
    103                 "allindownloadarea", "inview", "allinview", "timestamp");
     103                "allindownloadarea", "inview", "allinview", "timestamp", "nth", "nth%");
    104104
    105105        @Override
     
    138138                else if ("areasize".equals(keyword))
    139139                    return new AreaSize(tokenizer);
     140                else if ("nth".equals(keyword))
     141                    return new Nth(tokenizer, false);
     142                else if ("nth%".equals(keyword))
     143                    return new Nth(tokenizer, true);
    140144                else if ("timestamp".equals(keyword)) {
    141145                    String rangeS = " " + tokenizer.readTextOrNumber() + " "; // add leading/trailing space in order to get expected split (e.g. "a--" => {"a", ""})
     
    785789        @Override public String toString() {
    786790            return "role=" + role;
     791        }
     792    }
     793
     794    /**
     795     * Matches the n-th object of a relation and/or the n-th node of a way.
     796     */
     797    private static class Nth extends Match {
     798
     799        private final int nth;
     800        private final boolean modulo;
     801
     802        public Nth(PushbackTokenizer tokenizer, boolean modulo) throws ParseError {
     803            this((int) tokenizer.readNumber(tr("Primitive id expected")), modulo);
     804        }
     805
     806        private Nth(int nth, boolean modulo) {
     807            this.nth = nth;
     808            this.modulo = modulo;
     809        }
     810
     811        @Override
     812        public boolean match(OsmPrimitive osm) {
     813            for (OsmPrimitive p : osm.getReferrers()) {
     814                Integer idx = null;
     815                if (p instanceof Way) {
     816                    Way w = (Way) p;
     817                    idx = w.getNodes().indexOf(osm);
     818                } else if (p instanceof Relation) {
     819                    Relation r = (Relation) p;
     820                    idx = r.getMemberPrimitivesList().indexOf(osm);
     821                }
     822                if (idx != null) {
     823                    if (idx.intValue() == nth || (modulo && idx.intValue() % nth == 0)) {
     824                        return true;
     825                    }
     826                }
     827            }
     828            return false;
    787829        }
    788830    }
Note: See TracChangeset for help on using the changeset viewer.