- Timestamp:
- 2015-04-17T23:06:34+02:00 (10 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r7509 r8206 38 38 */ 39 39 public Integer index = null; 40 41 /** 42 * count of nodes in parent way or members in parent relation. Must be != null in LINK context. 43 */ 44 public Integer count = null; 40 45 41 46 /** … … 69 74 this.source = other.source; 70 75 this.index = other.index; 76 this.count = other.count; 71 77 this.context = other.getContext(); 72 78 } … … 99 105 * @param parent the matching parent object 100 106 * @param index index of node in parent way or member in parent relation 107 * @param count count of nodes in parent way or members in parent relation 101 108 * @return A clone of this environment, with the specified parent, index, and context set to {@link Context#LINK} 102 109 * @since 6175 … … 104 111 * @see #index 105 112 */ 106 public Environment withParentAndIndexAndLinkContext(OsmPrimitive parent, int index ) {113 public Environment withParentAndIndexAndLinkContext(OsmPrimitive parent, int index, int count) { 107 114 Environment e = new Environment(this); 108 115 e.parent = parent; 109 116 e.index = index; 117 e.count = count; 110 118 e.context = Context.LINK; 111 119 return e; … … 128 136 * @param child the matching child object 129 137 * @param index index of node in parent way or member in parent relation 138 * @param count count of nodes in parent way or members in parent relation 130 139 * @return A clone of this environment, with the specified child, index, and context set to {@code Context#LINK} 131 140 * @since 6175 … … 133 142 * @see #index 134 143 */ 135 public Environment withChildAndIndexAndLinkContext(OsmPrimitive child, int index ) {144 public Environment withChildAndIndexAndLinkContext(OsmPrimitive child, int index, int count) { 136 145 Environment e = new Environment(this); 137 146 e.child = child; 138 147 e.index = index; 148 e.count = count; 139 149 e.context = Context.LINK; 140 150 return e; … … 144 154 * Creates a clone of this environment, with the specified index. 145 155 * @param index index of node in parent way or member in parent relation 156 * @param count count of nodes in parent way or members in parent relation 146 157 * @return A clone of this environment, with the specified index 147 158 * @see #index 148 159 */ 149 public Environment withIndex(int index ) {160 public Environment withIndex(int index, int count) { 150 161 Environment e = new Environment(this); 151 162 e.index = index; 163 e.count = count; 152 164 return e; 153 165 } … … 214 226 child = null; 215 227 index = null; 228 count = null; 216 229 } 217 230 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r7447 r8206 271 271 public boolean applies(Environment env) { 272 272 if (env.index == null) return false; 273 return op.eval(Integer.toString(env.index + 1), index); 273 if (index.startsWith("-")) { 274 return env.count != null && op.eval(Integer.toString(env.index - env.count), index); 275 } else { 276 return op.eval(Integer.toString(env.index + 1), index); 277 } 274 278 } 275 279 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r8086 r8206 150 150 Node n = w.getNode(i); 151 151 if (n.equals(e.osm)) { 152 if (link.matches(e.withParentAndIndexAndLinkContext(w, i ))) {152 if (link.matches(e.withParentAndIndexAndLinkContext(w, i, w.getNodesCount()))) { 153 153 e.parent = w; 154 154 e.index = i; 155 e.count = w.getNodesCount(); 155 156 return; 156 157 } … … 172 173 RelationMember m = r.getMember(i); 173 174 if (m.getMember().equals(e.osm)) { 174 if (link.matches(e.withParentAndIndexAndLinkContext(r, i ))) {175 if (link.matches(e.withParentAndIndexAndLinkContext(r, i, r.getMembersCount()))) { 175 176 e.parent = r; 176 177 e.index = i; 178 e.count = r.getMembersCount(); 177 179 return; 178 180 } … … 329 331 e.child = n; 330 332 e.index = i; 333 e.count = w.getNodesCount(); 331 334 e.parent = w; 332 335 return true; … … 346 349 Node n = wayNodes.get(i); 347 350 if (left.matches(e.withPrimitive(n))) { 348 if (link.matches(e.withChildAndIndexAndLinkContext(n, i))) { 351 if (link.matches(e.withChildAndIndexAndLinkContext(n, i, wayNodes.size()))) { 352 e = e.withChildAndIndexAndLinkContext(n, i, wayNodes.size()); 349 353 e.child = n; 350 354 e.index = i; 355 e.count = wayNodes.size(); 351 356 return true; 352 357 } … … 359 364 OsmPrimitive member = members.get(i).getMember(); 360 365 if (left.matches(e.withPrimitive(member))) { 361 if (link.matches(e.withChildAndIndexAndLinkContext(member, i ))) {366 if (link.matches(e.withChildAndIndexAndLinkContext(member, i, members.size()))) { 362 367 e.child = member; 363 368 e.index = i; 369 e.count = members.size(); 364 370 return true; 365 371 } -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy
r7081 r8206 77 77 r.addMember(new RelationMember("my_role", n)) 78 78 79 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0 ).withLinkContext()79 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0, r.membersCount).withLinkContext() 80 80 81 81 Condition cond = Condition.createKeyCondition("my_role", false, null, Context.LINK) … … 92 92 r.addMember(new RelationMember("my_role", n)) 93 93 94 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0 ).withLinkContext()94 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0, r.membersCount).withLinkContext() 95 95 96 96 Condition cond = Condition.createKeyCondition("another_role", false, null, Context.LINK) -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy
r7081 r8206 63 63 r.addMember(new RelationMember("my_role", n)) 64 64 65 Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0 )65 Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0, r.membersCount) 66 66 67 67 Condition cond = new Condition.RoleCondition("my_role", Op.EQ) … … 78 78 r.addMember(new RelationMember("my_role", n)) 79 79 80 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0 ).withLinkContext()80 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0, r.membersCount).withLinkContext() 81 81 82 82 Condition cond = Condition.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
Note:
See TracChangeset
for help on using the changeset viewer.