Ticket #10391: 10391.patch

File 10391.patch, 3.3 KB (added by qeef, 6 years ago)

Add support for "not element of" operator (∉)

  • src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    diff --git src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
    index 258bfe79e..c6241391b 100644
    TOKEN:  
    215215|   < FULLSTOP: "." >
    216216|   < DEG: "°" >
    217217|   < ELEMENT_OF: "∈" >
     218|   < NOT_ELEMENT_OF: "∉" >
    218219|   < CROSSING: "⧉" >
    219220|   < PERCENT: "%" >
    220221|   < COMMENT_START: "/*" > : COMMENT
    Selector child_selector() :  
    690691            |
    691692                <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; }
    692693            |
     694                <NOT_ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.NOT_ELEMENT_OF; }
     695            |
    693696                <CROSSING> { type = Selector.ChildOrParentSelectorType.CROSSING; }
    694697            )
    695698            w()
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    diff --git src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
    index 30f0007a8..441f41573 100644
    public interface Selector {  
    9393     * @see ChildOrParentSelector
    9494     */
    9595    enum ChildOrParentSelectorType {
    96         CHILD, PARENT, ELEMENT_OF, CROSSING, SIBLING
     96        CHILD, PARENT, ELEMENT_OF, NOT_ELEMENT_OF, CROSSING, SIBLING
    9797    }
    9898
    9999    /**
    public interface Selector {  
    312312
    313313        @Override
    314314        public boolean matches(Environment e) {
     315            if (ChildOrParentSelectorType.ELEMENT_OF == type ||
     316                    ChildOrParentSelectorType.NOT_ELEMENT_OF == type) {
     317                if (!left.matches(e))
     318                    return false;
     319                boolean is_element_of = false;
     320                // does exist any element in dataset that contains e.osm?
     321                for (IPrimitive p: e.osm.getDataSet().allPrimitives()) {
     322                    Environment ne = new Environment(p);
     323                    if (!right.matches(ne))
     324                        continue;
     325                    ContainsFinder cf = new ContainsFinder(ne);
     326                    if (e.osm instanceof IWay)
     327                        cf.visit((IWay) e.osm);
     328                    if (e.osm instanceof INode)
     329                        cf.visit((INode) e.osm);
     330                    if (ne.child == e.osm)
     331                        is_element_of = true;
     332                }
     333                Logging.log(Logging.LEVEL_INFO, "ELEMENT_OF is " + is_element_of, null);
     334                if (ChildOrParentSelectorType.ELEMENT_OF == type)
     335                    return is_element_of;
     336                else
     337                    return !is_element_of;
     338            }
    315339
    316340            if (!right.matches(e))
    317341                return false;
    318342
    319343            if (ChildOrParentSelectorType.ELEMENT_OF == type) {
    320 
     344/*
    321345                if (e.osm instanceof INode || e.osm.getDataSet() == null) {
    322346                    // nodes cannot contain elements
    323347                    return false;
    public interface Selector {  
    362386                }
    363387
    364388                return e.child != null;
    365 
     389*/
    366390            } else if (ChildOrParentSelectorType.CROSSING == type && e.osm instanceof IWay) {
    367391                e.parent = e.osm;
    368392                final CrossingFinder crossingFinder = new CrossingFinder(e);