Changeset 32497 in osm for applications/editors/josm
- Timestamp:
- 2016-07-01T18:00:34+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r32438 r32497 1 1 package org.openstreetmap.josm.plugins.pt_assistant.gui; 2 2 3 import java.awt.Graphics;4 3 import java.awt.Graphics2D; 5 4 import java.awt.KeyboardFocusManager; … … 164 163 Main.getLayerManager().addLayer(this); 165 164 } 166 Graphics g = paintVisitor.getGraphics(); 167 paintVisitor = new PTAssistantPaintVisitor(g, Main.map.mapView); 165 168 166 for (OsmPrimitive primitive : primitives) { 169 167 paintVisitor.visit(primitive); 170 171 168 } 169 172 170 Main.map.repaint(); 173 171 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r32477 r32497 5 5 import java.awt.Graphics; 6 6 import java.awt.Point; 7 import java.util.ArrayList; 7 8 import java.util.HashMap; 8 9 import java.util.List; … … 18 19 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 19 20 21 import com.sun.org.apache.regexp.internal.recompile; 22 20 23 public class PTAssistantPaintVisitor extends PaintVisitor { 21 24 … … 34 37 public void visit(Relation r) { 35 38 39 // first, draw primitives: 40 for (RelationMember rm : r.getMembers()) { 41 42 if (RouteUtils.isPTStop(rm)) { 43 44 drawStop(rm.getMember()); 45 46 47 } else if (RouteUtils.isPTWay(rm)) { 48 if (rm.isWay()) { 49 visit(rm.getWay()); 50 } else if (rm.isRelation()) { 51 visit(rm.getRelation()); 52 } else { 53 // if the relation has members that do not fit with the 54 // PT_Assistant data model, do nothing 55 } 56 } else { 57 // if the relation has members that do not fit with the 58 // PT_Assistant data model, do nothing 59 } 60 } 61 62 // in the end, draw labels: 36 63 HashMap<Long, String> stopOrderMap = new HashMap<>(); 37 38 64 int stopCount = 1; 39 65 40 66 for (RelationMember rm : r.getMembers()) { 41 42 // if (rm.getMember().isIncomplete() && (rm.isNode() ||43 // rm.hasRole("stop") || rm.hasRole("stop_entry_only")44 // || rm.hasRole("stop_exit_only") || rm.hasRole("platform") ||45 // rm.hasRole("platform_entry_only")46 // || rm.hasRole("platform_exit_only"))) {47 //48 // if (stopOrderMap.containsKey(rm.getUniqueId())) {49 // label = stopOrderMap.get(rm.getUniqueId());50 // label = label + ";" + stopCount;51 // } else {52 //53 // }54 // }55 56 67 if (RouteUtils.isPTStop(rm) || (rm.getMember().isIncomplete() && (rm.isNode() || rm.hasRole("stop") 57 68 || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only") || rm.hasRole("platform") 58 69 || rm.hasRole("platform_entry_only") || rm.hasRole("platform_exit_only")))) { 59 70 60 71 String label = ""; 61 72 … … 76 87 stopOrderMap.put(rm.getUniqueId(), label); 77 88 drawStopLabel(rm.getMember(), label); 78 if (!rm.getMember().isIncomplete()) {79 drawStop(rm.getMember(), label);80 }81 82 89 stopCount++; 83 84 } else if (RouteUtils.isPTWay(rm)) {85 if (rm.isWay()) {86 visit(rm.getWay());87 } else if (rm.isRelation()) {88 visit(rm.getRelation());89 } else {90 // if the relation has members that do not fit with the91 // PT_Assistant data model, do nothing92 }93 } else {94 // if the relation has members that do not fit with the95 // PT_Assistant data model, do nothing96 90 } 97 91 } … … 245 239 } 246 240 247 // g.drawLine((int) (p1.x - cosT), (int) (p1.y - sinT), (int) (p2.x +248 // cosT), (int) (p2.y - sinT));249 // g.drawLine((int) (p1.x - cosT), (int) (p1.y + sinT), (int) (p2.x -250 // cosT), (int) (p2.y + sinT));251 252 241 } 253 242 … … 269 258 } 270 259 271 protected void drawStop(OsmPrimitive primitive , String label) {260 protected void drawStop(OsmPrimitive primitive) { 272 261 273 262 // find the point to which the stop visualization will be linked: … … 304 293 g.setFont(stringFont); 305 294 g.drawString(label, p.x + 20, p.y - 20); 306 307 // get the parents of the primitive that are routes: 295 296 // draw the ref values of all parent routes: 297 List<String> parentsLabelList = new ArrayList<>(); 308 298 String parentsLabel = ""; 309 for (OsmPrimitive parent: primitive.getReferrers()) { 299 for (OsmPrimitive parent : primitive.getReferrers()) { 310 300 if (parent.getType().equals(OsmPrimitiveType.RELATION)) { 311 301 Relation relation = (Relation) parent; 312 302 if (RouteUtils.isTwoDirectionRoute(relation)) { 313 parentsLabel = parentsLabel + relation.get("ref") + ";"; 314 } 315 } 316 } 303 304 boolean stringFound = false; 305 for (String s : parentsLabelList) { 306 if (s.equals(relation.get("ref"))) { 307 stringFound = true; 308 } 309 } 310 if (!stringFound) { 311 parentsLabel = parentsLabel + relation.get("ref") + ";"; 312 parentsLabelList.add(relation.get("ref")); 313 } 314 315 } 316 } 317 } 318 317 319 if (!parentsLabel.equals("")) { 318 320 // remove the last semicolon: 319 parentsLabel = parentsLabel.substring(0, parentsLabel.length() -1);320 g.setColor(new Color( 200, 200, 200));321 parentsLabel = parentsLabel.substring(0, parentsLabel.length() - 1); 322 g.setColor(new Color(150, 150, 150)); 321 323 Font parentLabelFont = new Font("SansSerif", Font.ITALIC, 20); 322 324 g.setFont(parentLabelFont); 323 325 g.drawString(parentsLabel, p.x + 20, p.y); 324 326 } 325 326 } 327 328 // protected void drawStopParentLabel(OsmPrimitive primitive, String label) { 329 // // find the point to which the stop visualization will be linked: 330 // Node n = new Node(primitive.getBBox().getCenter()); 331 // 332 // Point p = mv.getPoint(n); 333 // 334 // g.setColor(Color.WHITE); 335 // Font stringFont = new Font("SansSerif", Font.PLAIN, 24); 336 // g.setFont(stringFont); 337 // g.drawString(label, p.x - 20, p.y - 20); 338 // } 339 340 protected Graphics getGraphics() { 341 return this.g; 327 342 328 } 343 329 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/DirectionTest.java
r32427 r32497 88 88 highlighted.add(waysToCheck.get(i).getWay()); 89 89 errors.add(new TestError(this, Severity.WARNING, 90 tr("PT: Route passes a oneway road in wrong direction"), ERROR_CODE_DIRECTION, primitives, 90 tr("PT: Route passes a oneway road in the wrong direction"), ERROR_CODE_DIRECTION, primitives, 91 91 highlighted)); 92 92 return; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32438 r32497 69 69 } 70 70 71 // if (!Main.getLayerManager().containsLayer(layer)) {72 // Main.getLayerManager().addLayer(layer);73 // }74 // layer.clear();75 // layer.addPrimitive(r);76 71 77 72 // Check individual ways using the oneway direction test and the road 78 73 // type test: 79 74 WayChecker wayChecker = new WayChecker(r, this); 75 if (!r.hasIncompleteMembers()) { 76 wayChecker.performDirectionTest(); 77 wayChecker.performRoadTypeTest(); 78 } 80 79 this.errors.addAll(wayChecker.getErrors()); 81 80 … … 170 169 // Check if the relation is correct, or only has a wrong sorting order: 171 170 RouteChecker routeChecker = new RouteChecker(r, this); 171 routeChecker.performSortingTest(); 172 172 List<TestError> routeCheckerErrors = routeChecker.getErrors(); 173 173 … … 236 236 List<Command> commands = new ArrayList<>(); 237 237 238 if (testError.getCode() == ERROR_CODE_ DIRECTION || testError.getCode() == ERROR_CODE_ROAD_TYPE238 if (testError.getCode() == ERROR_CODE_ROAD_TYPE 239 239 || testError.getCode() == ERROR_CODE_CONSTRUCTION) { 240 commands.add(fixErrorByRemovingWay(testError)); 240 commands.add(WayChecker.fixErrorByRemovingWay(testError)); 241 } 242 243 if (testError.getCode() == ERROR_CODE_DIRECTION) { 244 commands.add(WayChecker.fixErrorByZooming(testError)); 241 245 } 242 246 243 247 if (testError.getCode() == ERROR_CODE_SORTING) { 244 commands.add(fixSortingError(testError)); 248 commands.add(RouteChecker.fixSortingError(testError)); 245 249 } 246 250 … … 282 286 } 283 287 284 private Command fixErrorByRemovingWay(TestError testError) { 285 286 if (testError.getCode() != ERROR_CODE_ROAD_TYPE && testError.getCode() != ERROR_CODE_DIRECTION) { 287 return null; 288 } 289 290 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 291 Relation originalRelation = (Relation) primitives.iterator().next(); 292 Collection<?> highlighted = testError.getHighlighted(); 293 Way wayToRemove = (Way) highlighted.iterator().next(); 294 295 Relation modifiedRelation = new Relation(originalRelation); 296 List<RelationMember> modifiedRelationMembers = new ArrayList<>(originalRelation.getMembersCount() - 1); 297 298 // copy PT stops first, PT ways last: 299 for (RelationMember rm : originalRelation.getMembers()) { 300 if (RouteUtils.isPTStop(rm)) { 301 302 if (rm.getRole().equals("stop_position")) { 303 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 304 RelationMember newMember = new RelationMember("stop", rm.getNode()); 305 modifiedRelationMembers.add(newMember); 306 } else { // if it is a way: 307 RelationMember newMember = new RelationMember("stop", rm.getWay()); 308 modifiedRelationMembers.add(newMember); 309 } 310 } else { 311 // if the relation member does not have the role 312 // "stop_position": 313 modifiedRelationMembers.add(rm); 314 } 315 316 } 317 } 318 319 // now copy PT ways: 320 for (RelationMember rm : originalRelation.getMembers()) { 321 if (RouteUtils.isPTWay(rm)) { 322 Way wayToCheck = rm.getWay(); 323 if (wayToCheck != wayToRemove) { 324 if (rm.getRole().equals("forward") || rm.getRole().equals("backward")) { 325 RelationMember modifiedMember = new RelationMember("", wayToCheck); 326 modifiedRelationMembers.add(modifiedMember); 327 } else { 328 modifiedRelationMembers.add(rm); 329 } 330 } 331 } 332 } 333 334 modifiedRelation.setMembers(modifiedRelationMembers); 335 336 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 337 338 return changeCommand; 339 } 340 341 private Command fixSortingError(TestError testError) { 342 if (testError.getCode() != ERROR_CODE_SORTING) { 343 return null; 344 } 345 346 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 347 Relation originalRelation = (Relation) primitives.iterator().next(); 348 349 // separate ways from stops (because otherwise the order of 350 // stops/platforms can be messed up by the sorter: 351 List<RelationMember> members = originalRelation.getMembers(); 352 final List<RelationMember> stops = new ArrayList<>(); 353 final List<RelationMember> ways = new ArrayList<>(); 354 for (RelationMember member : members) { 355 if (RouteUtils.isPTWay(member)) { 356 if (member.getRole().equals("")) { 357 ways.add(member); 358 } else { 359 RelationMember modifiedMember = new RelationMember("", member.getWay()); 360 ways.add(modifiedMember); 361 } 362 363 } else { // stops: 364 if (member.getRole().equals("stop_positon")) { 365 // it is not expected that stop_positions could 366 // be relations 367 if (member.getType().equals(OsmPrimitiveType.NODE)) { 368 RelationMember modifiedMember = new RelationMember("stop", member.getNode()); 369 stops.add(modifiedMember); 370 } else { // if it is a primitive of type way: 371 RelationMember modifiedMember = new RelationMember("stop", member.getWay()); 372 stops.add(modifiedMember); 373 } 374 } else { // if it is not a stop_position: 375 stops.add(member); 376 } 377 378 } 379 } 380 381 // sort the ways: 382 RelationSorter sorter = new RelationSorter(); 383 List<RelationMember> sortedWays = sorter.sortMembers(ways); 384 385 // create a new relation to pass to the command: 386 Relation sortedRelation = new Relation(originalRelation); 387 List<RelationMember> sortedRelationMembers = new ArrayList<>(members.size()); 388 for (RelationMember rm : stops) { 389 sortedRelationMembers.add(rm); 390 } 391 for (RelationMember rm : sortedWays) { 392 sortedRelationMembers.add(rm); 393 } 394 sortedRelation.setMembers(sortedRelationMembers); 395 396 ChangeCommand changeCommand = new ChangeCommand(originalRelation, sortedRelation); 397 398 return changeCommand; 399 400 } 288 // private Command fixErrorByRemovingWay(TestError testError) { 289 // 290 // if (testError.getCode() != ERROR_CODE_ROAD_TYPE && testError.getCode() != ERROR_CODE_DIRECTION) { 291 // return null; 292 // } 293 // 294 // Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 295 // Relation originalRelation = (Relation) primitives.iterator().next(); 296 // Collection<?> highlighted = testError.getHighlighted(); 297 // Way wayToRemove = (Way) highlighted.iterator().next(); 298 // 299 // Relation modifiedRelation = new Relation(originalRelation); 300 // List<RelationMember> modifiedRelationMembers = new ArrayList<>(originalRelation.getMembersCount() - 1); 301 // 302 // // copy PT stops first, PT ways last: 303 // for (RelationMember rm : originalRelation.getMembers()) { 304 // if (RouteUtils.isPTStop(rm)) { 305 // 306 // if (rm.getRole().equals("stop_position")) { 307 // if (rm.getType().equals(OsmPrimitiveType.NODE)) { 308 // RelationMember newMember = new RelationMember("stop", rm.getNode()); 309 // modifiedRelationMembers.add(newMember); 310 // } else { // if it is a way: 311 // RelationMember newMember = new RelationMember("stop", rm.getWay()); 312 // modifiedRelationMembers.add(newMember); 313 // } 314 // } else { 315 // // if the relation member does not have the role 316 // // "stop_position": 317 // modifiedRelationMembers.add(rm); 318 // } 319 // 320 // } 321 // } 322 // 323 // // now copy PT ways: 324 // for (RelationMember rm : originalRelation.getMembers()) { 325 // if (RouteUtils.isPTWay(rm)) { 326 // Way wayToCheck = rm.getWay(); 327 // if (wayToCheck != wayToRemove) { 328 // if (rm.getRole().equals("forward") || rm.getRole().equals("backward")) { 329 // RelationMember modifiedMember = new RelationMember("", wayToCheck); 330 // modifiedRelationMembers.add(modifiedMember); 331 // } else { 332 // modifiedRelationMembers.add(rm); 333 // } 334 // } 335 // } 336 // } 337 // 338 // modifiedRelation.setMembers(modifiedRelationMembers); 339 // 340 // ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 341 // 342 // return changeCommand; 343 // } 344 // 345 // private Command fixSortingError(TestError testError) { 346 // if (testError.getCode() != ERROR_CODE_SORTING) { 347 // return null; 348 // } 349 // 350 // Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 351 // Relation originalRelation = (Relation) primitives.iterator().next(); 352 // 353 // // separate ways from stops (because otherwise the order of 354 // // stops/platforms can be messed up by the sorter: 355 // List<RelationMember> members = originalRelation.getMembers(); 356 // final List<RelationMember> stops = new ArrayList<>(); 357 // final List<RelationMember> ways = new ArrayList<>(); 358 // for (RelationMember member : members) { 359 // if (RouteUtils.isPTWay(member)) { 360 // if (member.getRole().equals("")) { 361 // ways.add(member); 362 // } else { 363 // RelationMember modifiedMember = new RelationMember("", member.getWay()); 364 // ways.add(modifiedMember); 365 // } 366 // 367 // } else { // stops: 368 // if (member.getRole().equals("stop_positon")) { 369 // // it is not expected that stop_positions could 370 // // be relations 371 // if (member.getType().equals(OsmPrimitiveType.NODE)) { 372 // RelationMember modifiedMember = new RelationMember("stop", member.getNode()); 373 // stops.add(modifiedMember); 374 // } else { // if it is a primitive of type way: 375 // RelationMember modifiedMember = new RelationMember("stop", member.getWay()); 376 // stops.add(modifiedMember); 377 // } 378 // } else { // if it is not a stop_position: 379 // stops.add(member); 380 // } 381 // 382 // } 383 // } 384 // 385 // // sort the ways: 386 // RelationSorter sorter = new RelationSorter(); 387 // List<RelationMember> sortedWays = sorter.sortMembers(ways); 388 // 389 // // create a new relation to pass to the command: 390 // Relation sortedRelation = new Relation(originalRelation); 391 // List<RelationMember> sortedRelationMembers = new ArrayList<>(members.size()); 392 // for (RelationMember rm : stops) { 393 // sortedRelationMembers.add(rm); 394 // } 395 // for (RelationMember rm : sortedWays) { 396 // sortedRelationMembers.add(rm); 397 // } 398 // sortedRelation.setMembers(sortedRelationMembers); 399 // 400 // ChangeCommand changeCommand = new ChangeCommand(originalRelation, sortedRelation); 401 // 402 // return changeCommand; 403 // 404 // } 401 405 402 406 private void performDummyTest(Relation r) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java
r32427 r32497 4 4 5 5 import java.util.ArrayList; 6 import java.util.Collection; 6 7 import java.util.List; 7 8 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.command.Command; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 9 13 import org.openstreetmap.josm.data.osm.Relation; … … 35 39 this.hasGap = false; 36 40 37 performSortingTest();38 39 41 } 40 42 41 pr ivatevoid performSortingTest() {43 protected void performSortingTest() { 42 44 43 45 final List<RelationMember> waysToCheck = new ArrayList<>(); … … 108 110 109 111 } 112 113 protected static Command fixSortingError(TestError testError) { 114 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_SORTING) { 115 return null; 116 } 117 118 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 119 Relation originalRelation = (Relation) primitives.iterator().next(); 120 121 // separate ways from stops (because otherwise the order of 122 // stops/platforms can be messed up by the sorter: 123 List<RelationMember> members = originalRelation.getMembers(); 124 final List<RelationMember> stops = new ArrayList<>(); 125 final List<RelationMember> ways = new ArrayList<>(); 126 for (RelationMember member : members) { 127 if (RouteUtils.isPTWay(member)) { 128 if (member.getRole().equals("")) { 129 ways.add(member); 130 } else { 131 RelationMember modifiedMember = new RelationMember("", member.getWay()); 132 ways.add(modifiedMember); 133 } 134 135 } else { // stops: 136 if (member.getRole().equals("stop_positon")) { 137 // it is not expected that stop_positions could 138 // be relations 139 if (member.getType().equals(OsmPrimitiveType.NODE)) { 140 RelationMember modifiedMember = new RelationMember("stop", member.getNode()); 141 stops.add(modifiedMember); 142 } else { // if it is a primitive of type way: 143 RelationMember modifiedMember = new RelationMember("stop", member.getWay()); 144 stops.add(modifiedMember); 145 } 146 } else { // if it is not a stop_position: 147 stops.add(member); 148 } 149 150 } 151 } 152 153 // sort the ways: 154 RelationSorter sorter = new RelationSorter(); 155 List<RelationMember> sortedWays = sorter.sortMembers(ways); 156 157 // create a new relation to pass to the command: 158 Relation sortedRelation = new Relation(originalRelation); 159 List<RelationMember> sortedRelationMembers = new ArrayList<>(members.size()); 160 for (RelationMember rm : stops) { 161 sortedRelationMembers.add(rm); 162 } 163 for (RelationMember rm : sortedWays) { 164 sortedRelationMembers.add(rm); 165 } 166 sortedRelation.setMembers(sortedRelationMembers); 167 168 ChangeCommand changeCommand = new ChangeCommand(originalRelation, sortedRelation); 169 170 return changeCommand; 171 172 } 110 173 111 174 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32417 r32497 4 4 5 5 import java.util.ArrayList; 6 import java.util.Collection; 6 7 import java.util.List; 7 8 9 import org.openstreetmap.josm.command.ChangeCommand; 10 import org.openstreetmap.josm.command.Command; 11 import org.openstreetmap.josm.command.SelectCommand; 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 9 14 import org.openstreetmap.josm.data.osm.OsmUtils; … … 30 35 super(relation, test); 31 36 32 if (!relation.hasIncompleteMembers()) { 33 this.performDirectionTest(); 34 this.performRoadTypeTest(); 35 } 36 37 38 } 39 40 private void performRoadTypeTest() { 37 } 38 39 protected void performRoadTypeTest() { 41 40 42 41 if (!relation.hasTag("route", "bus") && !relation.hasTag("route", "trolleybus") … … 133 132 } 134 133 135 pr ivatevoid performDirectionTest() {134 protected void performDirectionTest() { 136 135 137 136 List<RelationMember> waysToCheck = new ArrayList<>(); … … 172 171 highlighted.add(waysToCheck.get(i).getWay()); 173 172 TestError e = new TestError(this.test, Severity.WARNING, 174 tr("PT: Route passes a oneway road in wrong direction"), 173 tr("PT: Route passes a oneway road in the wrong direction"), 175 174 PTAssitantValidatorTest.ERROR_CODE_DIRECTION, primitives, highlighted); 176 175 this.errors.add(e); … … 191 190 * @return true if the way is suitable for buses, false otherwise. 192 191 */ 193 p ublicboolean isWaySuitableForBuses(Way way) {192 private boolean isWaySuitableForBuses(Way way) { 194 193 if (way.hasTag("highway", "motorway") || way.hasTag("highway", "trunk") || way.hasTag("highway", "primary") 195 194 || way.hasTag("highway", "secondary") || way.hasTag("highway", "tertiary") … … 211 210 return false; 212 211 } 213 212 213 protected static Command fixErrorByRemovingWay(TestError testError) { 214 215 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE && testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 216 return null; 217 } 218 219 Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 220 Relation originalRelation = (Relation) primitives.iterator().next(); 221 Collection<?> highlighted = testError.getHighlighted(); 222 Way wayToRemove = (Way) highlighted.iterator().next(); 223 224 Relation modifiedRelation = new Relation(originalRelation); 225 List<RelationMember> modifiedRelationMembers = new ArrayList<>(originalRelation.getMembersCount() - 1); 226 227 // copy PT stops first, PT ways last: 228 for (RelationMember rm : originalRelation.getMembers()) { 229 if (RouteUtils.isPTStop(rm)) { 230 231 if (rm.getRole().equals("stop_position")) { 232 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 233 RelationMember newMember = new RelationMember("stop", rm.getNode()); 234 modifiedRelationMembers.add(newMember); 235 } else { // if it is a way: 236 RelationMember newMember = new RelationMember("stop", rm.getWay()); 237 modifiedRelationMembers.add(newMember); 238 } 239 } else { 240 // if the relation member does not have the role 241 // "stop_position": 242 modifiedRelationMembers.add(rm); 243 } 244 245 } 246 } 247 248 // now copy PT ways: 249 for (RelationMember rm : originalRelation.getMembers()) { 250 if (RouteUtils.isPTWay(rm)) { 251 Way wayToCheck = rm.getWay(); 252 if (wayToCheck != wayToRemove) { 253 if (rm.getRole().equals("forward") || rm.getRole().equals("backward")) { 254 RelationMember modifiedMember = new RelationMember("", wayToCheck); 255 modifiedRelationMembers.add(modifiedMember); 256 } else { 257 modifiedRelationMembers.add(rm); 258 } 259 } 260 } 261 } 262 263 modifiedRelation.setMembers(modifiedRelationMembers); 264 265 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 266 267 return changeCommand; 268 } 269 270 271 protected static Command fixErrorByZooming(TestError testError) { 272 273 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) { 274 return null; 275 } 276 277 // Collection<? extends OsmPrimitive> primitives = testError.getPrimitives(); 278 // Relation originalRelation = (Relation) primitives.iterator().next(); 279 Collection<?> highlighted = testError.getHighlighted(); 280 Way wayToHighlight = (Way) highlighted.iterator().next(); 281 ArrayList<OsmPrimitive> primitivesToHighlight = new ArrayList<>(1); 282 primitivesToHighlight.add(wayToHighlight); 283 284 SelectCommand command = new SelectCommand(primitivesToHighlight); 285 286 return command; 287 288 } 289 214 290 }
Note:
See TracChangeset
for help on using the changeset viewer.