- Timestamp:
- 2014-01-03T12:30:28+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj
r6607 r6609 80 80 | < CARET: "^" > 81 81 | < FULLSTOP: "." > 82 | < CONTAINS: "∋" >82 | < ELEMENT_OF: "∈" > 83 83 | < COMMENT_START: "/*" > : COMMENT 84 84 | < UNEXPECTED_CHAR : ~[] > // avoid TokenMgrErrors because they are hard to recover from … … 277 277 ( ( c=condition(Context.LINK) | c=class_or_pseudoclass(Context.LINK) ) { conditions.add(c); } )* 278 278 | 279 < CONTAINS> { type = Selector.ChildOrParentSelectorType.CONTAINS; }279 <ELEMENT_OF> { type = Selector.ChildOrParentSelectorType.ELEMENT_OF; } 280 280 ) 281 281 { selLink = new LinkSelector(conditions); } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r6607 r6609 2 2 package org.openstreetmap.josm.gui.mappaint.mapcss; 3 3 4 import java.util.Collection; 4 5 import java.util.Collections; 5 6 import java.util.List; … … 9 10 import org.openstreetmap.josm.data.osm.Node; 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 13 import org.openstreetmap.josm.data.osm.Relation; 12 14 import org.openstreetmap.josm.data.osm.RelationMember; … … 15 17 import org.openstreetmap.josm.gui.mappaint.Environment; 16 18 import org.openstreetmap.josm.gui.mappaint.Range; 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 17 20 import org.openstreetmap.josm.tools.Geometry; 18 21 import org.openstreetmap.josm.tools.Pair; … … 36 39 37 40 public static enum ChildOrParentSelectorType { 38 CHILD, PARENT, CONTAINS41 CHILD, PARENT, ELEMENT_OF 39 42 } 40 43 … … 149 152 private class ContainsFinder extends AbstractVisitor { 150 153 private final Environment e; 151 private final List<Node> nodes;152 154 153 155 private ContainsFinder(Environment e) { 154 156 this.e = e; 155 if (e.osm instanceof Node) { 156 nodes = Collections.singletonList((Node) e.osm); 157 } else if (e.osm instanceof Way) { 158 nodes = ((Way) e.osm).getNodes(); 159 } else { 160 throw new IllegalArgumentException("Relations not supported"); 161 } 157 CheckParameterUtil.ensureThat(!(e.osm instanceof Node), "Nodes not supported"); 162 158 } 163 159 164 160 @Override 165 161 public void visit(Node n) { 162 if (e.parent == null && right.matches(e.withPrimitive(n))) { 163 if (e.osm instanceof Way && Geometry.nodeInsidePolygon(n, ((Way) e.osm).getNodes()) 164 || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isNodeInsideMultiPolygon(n, (Relation) e.osm, null)) { 165 e.parent = n; 166 } 167 } 166 168 } 167 169 168 170 @Override 169 171 public void visit(Way w) { 170 if (e.parent == null && left.matches(e.withPrimitive(w))) { 171 if (nodes.size() == 1 172 ? Geometry.nodeInsidePolygon(nodes.get(0), w.getNodes()) 173 : Geometry.PolygonIntersection.FIRST_INSIDE_SECOND.equals(Geometry.polygonIntersection(nodes, w.getNodes()))) { 172 if (e.parent == null && right.matches(e.withPrimitive(w))) { 173 if (e.osm instanceof Way && Geometry.PolygonIntersection.FIRST_INSIDE_SECOND.equals(Geometry.polygonIntersection(w.getNodes(), ((Way) e.osm).getNodes())) 174 || e.osm instanceof Relation && ((Relation) e.osm).isMultipolygon() && Geometry.isPolygonInsideMultiPolygon(w.getNodes(), (Relation) e.osm, null)) { 174 175 e.parent = w; 175 e.index = 0;176 176 } 177 177 } … … 180 180 @Override 181 181 public void visit(Relation r) { 182 if (e.parent == null && left.matches(e.withPrimitive(r))) { 183 if (r.isMultipolygon() && Geometry.isPolygonInsideMultiPolygon(nodes, r, null)) { 184 e.parent = r; 185 e.index = 0; 182 } 183 184 public void visit(Collection<? extends OsmPrimitive> primitives) { 185 for (OsmPrimitive p : primitives) { 186 if (e.parent != null) { 187 // abort if first match has been found 188 break; 189 } else if (!e.osm.equals(p)) { 190 p.accept(this); 186 191 } 187 192 } … … 191 196 @Override 192 197 public boolean matches(Environment e) { 198 193 199 if (!right.matches(e)) 194 200 return false; 195 201 196 if (ChildOrParentSelectorType.CONTAINS.equals(type)) { 197 final OsmPrimitive rightPrimitive = e.osm; 202 if (ChildOrParentSelectorType.ELEMENT_OF.equals(type)) { 203 204 if (e.osm instanceof Node) { 205 // nodes cannot contain elements 206 return false; 207 } 208 e.child = e.osm; 209 198 210 final ContainsFinder containsFinder = new ContainsFinder(e); 199 for (final OsmPrimitive p : rightPrimitive.getDataSet().allPrimitives()) { 200 if (rightPrimitive.equals(p)) { 201 continue; 202 } 203 p.accept(containsFinder); 204 if (e.parent != null) { 205 e.osm = rightPrimitive; 206 return true; 207 } 208 } 211 if (right instanceof GeneralSelector) { 212 if (((GeneralSelector) right).matchesBase(OsmPrimitiveType.NODE)) { 213 containsFinder.visit(e.osm.getDataSet().searchNodes(e.osm.getBBox())); 214 } 215 if (((GeneralSelector) right).matchesBase(OsmPrimitiveType.WAY)) { 216 containsFinder.visit(e.osm.getDataSet().searchWays(e.osm.getBBox())); 217 } 218 } else { 219 // use slow test 220 containsFinder.visit(e.osm.getDataSet().allPrimitives()); 221 } 222 223 return e.parent != null; 224 209 225 } else if (ChildOrParentSelectorType.CHILD.equals(type)) { 210 226 MatchingReferrerFinder collector = new MatchingReferrerFinder(e); … … 357 373 } 358 374 359 public boolean matchesBase( Environment e){360 if ( e.osm instanceof Node) {375 public boolean matchesBase(OsmPrimitiveType type) { 376 if (OsmPrimitiveType.NODE.equals(type)) { 361 377 return base.equals("node") || base.equals("*"); 362 } else if ( e.osm instanceof Way) {378 } else if (OsmPrimitiveType.WAY.equals(type)) { 363 379 return base.equals("way") || base.equals("area") || base.equals("*"); 364 } else if (e.osm instanceof Relation) { 365 if (base.equals("area")) { 366 return ((Relation) e.osm).isMultipolygon(); 367 } else if (base.equals("relation")) { 368 return true; 369 } else if (base.equals("canvas")) { 370 return e.osm.get("#canvas") != null; 371 } 380 } else if (OsmPrimitiveType.RELATION.equals(type)) { 381 return base.equals("area") || base.equals("relation") || base.equals("canvas"); 372 382 } 373 383 return false; 384 } 385 386 public boolean matchesBase(OsmPrimitive p) { 387 if (!matchesBase(p.getType())) { 388 return false; 389 } else { 390 if (p instanceof Relation) { 391 if (base.equals("area")) { 392 return ((Relation) p).isMultipolygon(); 393 } else if (base.equals("canvas")) { 394 return p.get("#canvas") != null; 395 } 396 } 397 return true; 398 } 399 } 400 401 public boolean matchesBase(Environment e) { 402 return matchesBase(e.osm); 374 403 } 375 404
Note:
See TracChangeset
for help on using the changeset viewer.