Changeset 6927 in josm


Ignore:
Timestamp:
2014-03-24T00:48:17+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9667 - Verify addresses interpolation range/values via MapCSS (patch by simon04)

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6908 r6927  
    341341        }
    342342
     343        public String child_tag(String key) {
     344            return env.child == null ? null : env.child.get(key);
     345        }
     346
    343347        /**
    344348         * Determines whether the object has a tag with the given key.
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6897 r6927  
    368368    (
    369369        (
    370             ( <GREATER> { type = Selector.ChildOrParentSelectorType.CHILD; } | <LESS> { type = Selector.ChildOrParentSelectorType.PARENT; } )
     370            (
     371                <GREATER> { type = Selector.ChildOrParentSelectorType.CHILD; }
     372            |
     373                <LESS> { type = Selector.ChildOrParentSelectorType.PARENT; }
     374            |
     375                <PLUS> { type = Selector.ChildOrParentSelectorType.SIBLING; }
     376            )
    371377            ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { conditions.add(c); } )*
    372378        |
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r6897 r6927  
    3939
    4040    public static enum ChildOrParentSelectorType {
    41         CHILD, PARENT, ELEMENT_OF, CROSSING
     41        CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING
    4242    }
    4343
     
    258258                }
    259259                return e.child != null;
     260            } else if (ChildOrParentSelectorType.SIBLING.equals(type)) {
     261                if (e.osm instanceof Node) {
     262                    for (Way w : Utils.filteredCollection(e.osm.getReferrers(), Way.class)) {
     263                        final int i = w.getNodes().indexOf(e.osm);
     264                        if (i - 1 >= 0) {
     265                            final Node n = w.getNode(i - 1);
     266                            final Environment e2 = e.withPrimitive(n).withParent(w).withChild(e.osm);
     267                            if (left.matches(e2)) {
     268                                if (link.matches(e2.withLinkContext())) {
     269                                    e.child = n;
     270                                    e.index = i;
     271                                    e.parent = w;
     272                                    return true;
     273                                }
     274                            }
     275                        }
     276                    }
     277                }
    260278            } else if (ChildOrParentSelectorType.CHILD.equals(type)) {
    261279                MatchingReferrerFinder collector = new MatchingReferrerFinder(e);
  • trunk/src/org/openstreetmap/josm/gui/preferences/validator/ValidatorTagCheckerRulesPreference.java

    r6897 r6927  
    137137            List<ExtendedSourceEntry> def = new ArrayList<ExtendedSourceEntry>();
    138138           
     139            addDefault(def, "addresses",    tr("Addresses"),           tr("Checks for errors on addresses"));
    139140            addDefault(def, "combinations", tr("Tag combinations"),    tr("Checks for missing tag or suspicious combinations"));
    140141            addDefault(def, "deprecated",   tr("Deprecated features"), tr("Checks for deprecated features"));
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy

    r6859 r6927  
    55import org.openstreetmap.TestUtils
    66import org.openstreetmap.josm.Main
    7 import org.openstreetmap.josm.data.Preferences
     7import org.openstreetmap.josm.data.coor.LatLon
     8import org.openstreetmap.josm.data.osm.DataSet
    89import org.openstreetmap.josm.data.osm.OsmPrimitive
    910import org.openstreetmap.josm.data.osm.Way
     11import org.openstreetmap.josm.data.projection.Projections
    1012import org.openstreetmap.josm.gui.mappaint.Environment
    1113import org.openstreetmap.josm.gui.mappaint.MultiCascade
    1214import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
    1315import org.openstreetmap.josm.tools.ColorHelper
    14 import org.openstreetmap.josm.tools.Utils
    1516
    1617import java.awt.Color
     
    3435    @Before
    3536    public void setUp() throws Exception {
    36         Main.pref = new Preferences()
     37        Main.initApplicationPreferences()
     38        Main.setProjection(Projections.getProjectionByCode("EPSG:3857"));
    3739    }
    3840
     
    252254        assert ColorHelper.html2color("#12345678") == new Color(0x12, 0x34, 0x56, 0x78)
    253255    }
     256
     257    @Test
     258    public void testSiblingSelector() throws Exception {
     259        def s1 = (Selector.ChildOrParentSelector) getParser("*[a?][parent_tag(\"highway\")=\"unclassified\"] + *[b?]").child_selector()
     260        def ds = new DataSet()
     261        def n1 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1, 2))
     262        n1.put("a", "true")
     263        def n2 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1.1, 2.2))
     264        n2.put("b", "true")
     265        def w = new Way()
     266        w.put("highway", "unclassified")
     267        ds.addPrimitive(n1)
     268        ds.addPrimitive(n2)
     269        ds.addPrimitive(w)
     270        w.addNode(n1)
     271        w.addNode(n2)
     272
     273        def e = new Environment().withPrimitive(n2)
     274        assert s1.matches(e)
     275        assert e.osm == n2
     276        assert e.child == n1
     277        assert e.parent == w
     278        assert !s1.matches(new Environment().withPrimitive(n1))
     279        assert !s1.matches(new Environment().withPrimitive(w))
     280    }
     281
     282    @Test
     283    public void testSiblingSelectorInterpolation() throws Exception {
     284        def s1 = (Selector.ChildOrParentSelector) getParser(
     285                "*[tag(\"addr:housenumber\") > child_tag(\"addr:housenumber\")][regexp_test(\"even|odd\", parent_tag(\"addr:interpolation\"))]" +
     286                        " + *[addr:housenumber]").child_selector()
     287        def ds = new DataSet()
     288        def n1 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1, 2))
     289        n1.put("addr:housenumber", "10")
     290        def n2 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1.1, 2.2))
     291        n2.put("addr:housenumber", "100")
     292        def n3 = new org.openstreetmap.josm.data.osm.Node(new LatLon(1.2, 2.3))
     293        n3.put("addr:housenumber", "20")
     294        def w = new Way()
     295        w.put("addr:interpolation", "even")
     296        ds.addPrimitive(n1)
     297        ds.addPrimitive(n2)
     298        ds.addPrimitive(n3)
     299        ds.addPrimitive(w)
     300        w.addNode(n1)
     301        w.addNode(n2)
     302        w.addNode(n3)
     303
     304        assert s1.right.matches(new Environment().withPrimitive(n3))
     305        assert s1.left.matches(new Environment().withPrimitive(n2).withChild(n3).withParent(w))
     306        assert s1.matches(new Environment().withPrimitive(n3))
     307        assert !s1.matches(new Environment().withPrimitive(n1))
     308        assert !s1.matches(new Environment().withPrimitive(n2))
     309        assert !s1.matches(new Environment().withPrimitive(w))
     310    }
    254311}
Note: See TracChangeset for help on using the changeset viewer.