Changeset 33425 in osm for applications/editors/josm/plugins/pt_assistant
- Timestamp:
- 2017-07-04T23:09:33+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r33417 r33425 329 329 330 330 /** 331 * Carries out the second stage of the testing: sorting 331 * Carries out the second stage of the testing: sorting and segments 332 332 * 333 333 * @param r … … 341 341 List<TestError> routeCheckerErrors = routeChecker.getErrors(); 342 342 343 /*- At this point, there are 3 variants:344 *345 * 1) There are no errors => route is correct346 * 2) There is only a sorting error (can only be 1), but otherwise347 * correct.348 * 3) There are some other errors/gaps that cannot be fixed by349 * sorting => start further test (stop-by-stop)350 *351 * */352 353 if (!routeCheckerErrors.isEmpty()) {354 // Variant 2355 // If there is only the sorting error, add it356 this.errors.addAll(routeChecker.getErrors());357 }358 359 // if (!routeChecker.getHasGap()) {360 // // Variant 1361 // storeCorrectRouteSegments(r);362 // }363 364 // Variant 3:365 proceedAfterSorting(r);366 367 }368 369 /**370 * Carries out the stop-by-stop testing which includes building the route371 * data model.372 *373 * @param r374 * route relation375 */376 private void proceedAfterSorting(Relation r) {377 378 343 SegmentChecker segmentChecker = new SegmentChecker(r, this); 379 380 // Check if the creation of the route data model in the segment checker381 // worked. If it did not, it means the roles in the route relation do382 // not match the tags of the route members.383 if (!segmentChecker.getErrors().isEmpty()) {384 this.errors.addAll(segmentChecker.getErrors());385 }386 387 344 segmentChecker.performFirstStopTest(); 388 345 segmentChecker.performLastStopTest(); 389 346 segmentChecker.performStopNotServedTest(); 390 347 391 boolean sortingErrorFound = false; 392 for (TestError error : this.errors) { 393 if (error.getCode() == ERROR_CODE_SORTING 394 || error.getCode() == ERROR_CODE_PARTIAL_SORTING) { 395 sortingErrorFound = true; 396 break; 397 } 398 } 399 if (!sortingErrorFound) { 400 segmentChecker.performStopByStopTest(); 401 segmentChecker.findFixes(); 402 } 403 404 for (TestError error : segmentChecker.getErrors()) { 405 if (error.getCode() != PTAssistantValidatorTest.ERROR_CODE_RELATION_MEMBER_ROLES) { 406 this.errors.add(error); 407 } 348 //At this point, there are 3 variants: 349 if(routeCheckerErrors.isEmpty()) { 350 if (!routeChecker.getHasGap()) { 351 //There are no errors => route is correct 352 storeCorrectRouteSegments(r, segmentChecker.getManager(), 353 segmentChecker.getAssigner()); 354 } else { 355 // There are some other errors/gaps that cannot be fixed by 356 // sorting => start further test (stop-by-stop) 357 segmentChecker.performStopByStopTest(); 358 segmentChecker.findFixes(); 359 } 360 } else { 361 // There is only a sorting error (can only be 1), but otherwise 362 // correct 363 this.errors.addAll(routeChecker.getErrors()); 364 } 365 366 //add eventual errors found 367 if (!segmentChecker.getErrors().isEmpty()) { 368 this.errors.addAll(segmentChecker.getErrors()); 408 369 } 409 370 } … … 445 406 * route relation 446 407 */ 447 @SuppressWarnings("unused") 448 private void storeCorrectRouteSegments(Relation r) { 449 PTRouteDataManager manager = new PTRouteDataManager(r); 450 StopToWayAssigner assigner = new StopToWayAssigner(manager.getPTWays()); 408 private void storeCorrectRouteSegments(Relation r, 409 PTRouteDataManager manager, StopToWayAssigner assigner) { 451 410 if (manager.getPTStops().size() > 1) { 452 411 for (int i = 1; i < manager.getPTStops().size(); i++) { 453 PTStop s egmentStartStop = manager.getPTStops().get(i - 1);454 PTStop segmentEndStop = manager.getPTStops().get(i);455 Way s egmentStartWay = assigner.get(segmentStartStop);456 Way segmentEndWay = assigner.get(segmentEndStop);457 List<PTWay> waysBetweenStops = manager.getPTWaysBetween(s egmentStartWay, segmentEndWay);458 PTRouteSegment routeSegment = new PTRouteSegment(segmentStartStop, segmentEndStop, waysBetweenStops, r);459 SegmentChecker.addCorrectSegment(routeSegment);412 PTStop startStop = manager.getPTStops().get(i - 1); 413 PTStop endStop = manager.getPTStops().get(i); 414 Way startWay = assigner.get(startStop); 415 Way endWay = assigner.get(endStop); 416 List<PTWay> waysBetweenStops = manager.getPTWaysBetween(startWay, endWay); 417 SegmentChecker.addCorrectSegment( 418 new PTRouteSegment(startStop, endStop, waysBetweenStops, r)); 460 419 } 461 420 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r33417 r33425 66 66 super(relation, test); 67 67 68 this. manager = new PTRouteDataManager(relation);69 70 for (RelationMember rm : manager.getFailedMembers()) {68 this.setManager(new PTRouteDataManager(relation)); 69 70 for (RelationMember rm : getManager().getFailedMembers()) { 71 71 List<Relation> primitives = new ArrayList<>(1); 72 72 primitives.add(relation); … … 82 82 } 83 83 84 this. assigner = new StopToWayAssigner(manager.getPTWays());84 this.setAssigner(new StopToWayAssigner(getManager().getPTWays())); 85 85 86 86 } … … 100 100 * checking its correctness 101 101 * 102 * @param segment 103 * to add to the list of correct segments 102 * @param segment to add to the list of correct segments 104 103 */ 105 104 public static synchronized void addCorrectSegment(PTRouteSegment segment) { … … 125 124 public void performFirstStopTest() { 126 125 127 performEndStopTest( manager.getFirstStop());126 performEndStopTest(getManager().getFirstStop()); 128 127 129 128 } … … 131 130 public void performLastStopTest() { 132 131 133 performEndStopTest( manager.getLastStop());132 performEndStopTest(getManager().getLastStop()); 134 133 135 134 } … … 237 236 boolean contains = false; 238 237 239 List<PTWay> ptways = manager.getPTWays();238 List<PTWay> ptways = getManager().getPTWays(); 240 239 for (PTWay ptway : ptways) { 241 240 List<Way> ways = ptway.getWays(); … … 260 259 261 260 public void performStopNotServedTest() { 262 for (PTStop stop : manager.getPTStops()) {263 Way way = assigner.get(stop);261 for (PTStop stop : getManager().getPTStops()) { 262 Way way = getAssigner().get(stop); 264 263 if (way == null) { 265 264 createStopError(stop); … … 274 273 public void performStopByStopTest() { 275 274 276 if ( manager.getPTStopCount() < 2) {275 if (getManager().getPTStopCount() < 2) { 277 276 return; 278 277 } … … 281 280 282 281 // Check each route segment: 283 for (int i = 1; i < manager.getPTStopCount(); i++) {284 285 PTStop startStop = manager.getPTStops().get(i - 1);286 PTStop endStop = manager.getPTStops().get(i);287 288 Way startWay = assigner.get(startStop);289 Way endWay = assigner.get(endStop);290 if (startWay == null || endWay == null || (startWay == endWay && startWay == manager.getLastWay())) {282 for (int i = 1; i < getManager().getPTStopCount(); i++) { 283 284 PTStop startStop = getManager().getPTStops().get(i - 1); 285 PTStop endStop = getManager().getPTStops().get(i); 286 287 Way startWay = getAssigner().get(startStop); 288 Way endWay = getAssigner().get(endStop); 289 if (startWay == null || endWay == null || (startWay == endWay && startWay == getManager().getLastWay())) { 291 290 continue; 292 291 } 293 292 294 List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay);293 List<PTWay> segmentWays = getManager().getPTWaysBetween(startWay, endWay); 295 294 296 295 Node firstNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(segmentWays.get(0)); … … 319 318 PTWay wronglySortedPtway = existingWaySortingIsWrong(segmentWays.get(0), firstNode, 320 319 segmentWays.get(segmentWays.size() - 1)); 321 if (wronglySortedPtway == null) { // i.e. if the sorting is correct:320 if (wronglySortedPtway != null) { // i.e. if the sorting is wrong: 322 321 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation); 323 addCorrectSegment(routeSegment);324 } else { // i.e. if the sorting is wrong:325 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation);326 // TestError error = this.errors.get(this.errors.size() - 1);327 // wrongSegments.put(error, routeSegment);328 329 322 List<Relation> primitives = new ArrayList<>(1); 330 323 primitives.add(relation); … … 381 374 // 2) failing that, check which node this startWay shares with the 382 375 // following way: 383 PTWay nextWay = manager.getNextPTWay(startWay);376 PTWay nextWay = getManager().getNextPTWay(startWay); 384 377 if (nextWay == null) { 385 378 return null; 386 379 } 387 PTWay wayAfterNext = manager.getNextPTWay(nextWay);380 PTWay wayAfterNext = getManager().getNextPTWay(nextWay); 388 381 Node[] nextWayEndnodes = nextWay.getEndNodes(); 389 382 if ((startWayEndnodes[0] == nextWayEndnodes[0] && startWayEndnodes[1] == nextWayEndnodes[1]) … … 412 405 private boolean isDeadendNode(Node node) { 413 406 int count = 0; 414 for (PTWay ptway : manager.getPTWays()) {407 for (PTWay ptway : getManager().getPTWays()) { 415 408 List<Way> ways = ptway.getWays(); 416 409 for (Way way : ways) { … … 478 471 // matter which of the geometrically equal PTWays it finds 479 472 480 PTWay nextPTWayAccortingToExistingSorting = manager.getNextPTWay(current);473 PTWay nextPTWayAccortingToExistingSorting = getManager().getNextPTWay(current); 481 474 482 475 // if current contains an unsplit roundabout: 483 476 if (current.containsUnsplitRoundabout()) { 484 currentNode = manager.getCommonNode(current, nextPTWayAccortingToExistingSorting);477 currentNode = getManager().getCommonNode(current, nextPTWayAccortingToExistingSorting); 485 478 if (currentNode == null) { 486 479 … … 578 571 List<PTWay> nextPtways = new ArrayList<>(); 579 572 580 List<PTWay> ptways = manager.getPTWays();573 List<PTWay> ptways = getManager().getPTWays(); 581 574 582 575 for (PTWay ptway : ptways) { … … 643 636 644 637 for (Builder builder : wrongSegmentBuilders.keySet()) { 645 646 638 if (wrongSegmentBuilders.get(builder).getRelation() == this.relation) { 647 648 639 findFix(builder); 649 650 } 651 } 652 640 } 641 } 653 642 } 654 643 … … 1134 1123 } 1135 1124 1125 public PTRouteDataManager getManager() { 1126 return manager; 1127 } 1128 1129 public void setManager(PTRouteDataManager manager) { 1130 this.manager = manager; 1131 } 1132 1133 public StopToWayAssigner getAssigner() { 1134 return assigner; 1135 } 1136 1137 public void setAssigner(StopToWayAssigner assigner) { 1138 this.assigner = assigner; 1139 } 1140 1136 1141 }
Note:
See TracChangeset
for help on using the changeset viewer.