Changeset 32715 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-26T03:35:26+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32656 r32715 79 79 if (member.getMember().hasTag("highway", "bus_stop") 80 80 || member.getMember().hasTag("public_transport", "platform") 81 || member.getMember().hasTag("highway", "platform") || member.getMember().hasTag("railway", "platform")) { 81 || member.getMember().hasTag("highway", "platform") 82 || member.getMember().hasTag("railway", "platform")) { 82 83 if (platform == null) { 83 84 platform = member.getMember(); … … 146 147 BBox platformBBox = new BBox(ax, ay, bx, by); 147 148 148 // Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes(); 149 // Collection<Node> allNodes = 150 // Main.getLayerManager().getEditDataSet().getNodes(); 149 151 Collection<Node> allNodes = platform.getDataSet().getNodes(); 150 152 for (Node currentNode : allNodes) { … … 157 159 } 158 160 161 /** 162 * Checks if this stop equals to other by comparing if they have the same 163 * stop_position or a platform 164 * 165 * @param other PTStop to be compared 166 * @return true if equal, false otherwise 167 */ 168 public boolean equalsStop(PTStop other) { 169 170 if (other == null) { 171 return false; 172 } 173 174 if (this.stopPosition != null && (this.stopPosition == other.getStopPosition() || this.stopPosition == other.getPlatform())) { 175 return true; 176 } 177 178 if (this.platform != null && (this.platform == other.getPlatform() || this.platform == other.getStopPosition())) { 179 return true; 180 } 181 182 return false; 183 } 184 159 185 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r32707 r32715 348 348 return true; 349 349 } 350 351 if (testError.getCode() == ERROR_CODE_STOP_BY_STOP && SegmentChecker.isFixable(testError)) { 352 return true; 353 } 354 350 355 return false; 351 356 } … … 372 377 || testError.getCode() == ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) { 373 378 commands.add(NodeChecker.fixError(testError)); 379 } 380 381 if (testError.getCode() == ERROR_CODE_STOP_BY_STOP) { 382 commands.add(SegmentChecker.fixError(testError)); 374 383 } 375 384 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32710 r32715 4 4 5 5 import java.util.ArrayList; 6 import java.util.HashMap; 6 7 import java.util.List; 7 8 9 import org.openstreetmap.josm.command.ChangeCommand; 8 10 import org.openstreetmap.josm.command.Command; 9 11 import org.openstreetmap.josm.data.coor.LatLon; 10 12 import org.openstreetmap.josm.data.osm.Node; 11 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 15 import org.openstreetmap.josm.data.osm.Relation; 13 16 import org.openstreetmap.josm.data.osm.RelationMember; … … 20 23 import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop; 21 24 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 25 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 22 26 import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner; 23 27 … … 33 37 /* PTRouteSegments that have been validated and are correct */ 34 38 private static List<PTRouteSegment> correctSegments = new ArrayList<PTRouteSegment>(); 39 40 /* PTRouteSegments that are wrong, stored in case the user calls the fix */ 41 private static HashMap<TestError, PTRouteSegment> wrongSegments = new HashMap<TestError, PTRouteSegment>(); 35 42 36 43 /* Manager of the PTStops and PTWays of the current route */ … … 213 220 214 221 public void performStopByStopTest() { 215 222 216 223 if (manager.getPTStopCount() < 2) { 217 224 return; … … 228 235 if (startWay == null) { 229 236 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 237 if (i == 0) { 238 createStopError(startStop); 239 } 230 240 continue; 231 241 } 232 242 if (endWay == null) { 233 243 this.firstNodeOfRouteSegmentInDirectionOfTravel = null; 244 if (i != 0) { 245 createStopError(endStop); 246 } 234 247 continue; 235 248 } 236 // FIXME: throw error if cannot find the corresponding way (which 237 // means that the stop is too far away from way) 249 238 250 List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay); 239 251 … … 245 257 segmentWays.get(0)); 246 258 if (this.firstNodeOfRouteSegmentInDirectionOfTravel == null) { 247 // TODO: throw error248 259 continue; 249 260 } … … 255 266 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); 256 267 correctSegments.add(routeSegment); 257 } 258 } 259 268 } else { 269 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays); 270 TestError error = this.errors.get(this.errors.size() - 1); 271 wrongSegments.put(error, routeSegment); 272 } 273 } 274 } 275 276 /** 277 * Creates a TestError and adds it to the list of errors for a stop that is 278 * not served. 279 * 280 * @param stop 281 */ 282 private void createStopError(PTStop stop) { 283 List<Relation> primitives = new ArrayList<>(1); 284 primitives.add(relation); 285 List<OsmPrimitive> highlighted = new ArrayList<>(); 286 OsmPrimitive stopPrimitive = stop.getPlatform(); 287 if (stopPrimitive == null) { 288 stopPrimitive = stop.getStopPosition(); 289 } 290 highlighted.add(stopPrimitive); 291 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop not served"), 292 PTAssistantValidatorTest.ERROR_CODE_STOP_NOT_SERVED, primitives, highlighted); 293 this.errors.add(e); 260 294 } 261 295 … … 395 429 /** 396 430 * Will return the same node if the way is an unsplit roundabout 431 * 397 432 * @param way 398 433 * @param node … … 414 449 /** 415 450 * Does not work correctly for unsplit roundabouts 451 * 416 452 * @param ptway 417 453 * @param node … … 457 493 458 494 if (ptway != currentWay) { 459 for (Way way : ptway.getWays()) {495 for (Way way : ptway.getWays()) { 460 496 if (way.containsNode(nextNodeInDirectionOfTravel)) { 461 497 nextPtways.add(ptway); … … 469 505 } 470 506 507 protected static boolean isFixable(TestError testError) { 508 509 if (testError.getCode() == PTAssistantValidatorTest.ERROR_CODE_STOP_BY_STOP) { 510 511 PTRouteSegment wrongSegment = wrongSegments.get(testError); 512 PTRouteSegment correctSegment = null; 513 // TODO: now just the first correctSegment is taken over. Change 514 // that 515 // the segment is selected. 516 for (PTRouteSegment segment : correctSegments) { 517 if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop()) 518 && wrongSegment.getLastStop().equalsStop(segment.getLastStop())) { 519 correctSegment = segment; 520 // System.out.println("correct segment found: " + 521 // correctSegment.getFirstStop().getPlatform().getId()); 522 break; 523 } 524 } 525 526 return correctSegment != null; 527 } 528 529 return false; 530 531 } 532 471 533 protected static Command fixError(TestError testError) { 472 534 473 // FIXME 535 PTRouteSegment wrongSegment = wrongSegments.get(testError); 536 PTRouteSegment correctSegment = null; 537 // TODO: now just the first correctSegment is taken over. Change that 538 // the segment is selected. 539 for (PTRouteSegment segment : correctSegments) { 540 if (wrongSegment.getFirstStop().equalsStop(segment.getFirstStop()) 541 && wrongSegment.getLastStop().equalsStop(segment.getLastStop())) { 542 correctSegment = segment; 543 break; 544 } 545 } 546 547 if (correctSegment != null) { 548 // TODO: ask user if the change should be undertaken 549 Relation originalRelation = (Relation) testError.getPrimitives().iterator().next(); 550 Relation modifiedRelation = new Relation(originalRelation); 551 List<RelationMember> originalRelationMembers = originalRelation.getMembers(); 552 List<RelationMember> modifiedRelationMembers = new ArrayList<>(); 553 554 // copy stops first: 555 for (RelationMember rm: originalRelationMembers) { 556 if (RouteUtils.isPTStop(rm)) { 557 if (rm.getRole().equals("stop_position")) { 558 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 559 RelationMember newMember = new RelationMember("stop", rm.getNode()); 560 modifiedRelationMembers.add(newMember); 561 } else { // if it is a way: 562 RelationMember newMember = new RelationMember("stop", rm.getWay()); 563 modifiedRelationMembers.add(newMember); 564 } 565 } else { 566 // if the relation member does not have the role 567 // "stop_position": 568 modifiedRelationMembers.add(rm); 569 } 570 } 571 } 572 573 // copy PTWays next: 574 List<RelationMember> waysOfOriginalRelation = new ArrayList<>(); 575 for (RelationMember rm: originalRelation.getMembers()) { 576 if (RouteUtils.isPTWay(rm)) { 577 waysOfOriginalRelation.add(rm); 578 } 579 } 580 581 for (int i = 0; i < waysOfOriginalRelation.size(); i++) { 582 if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) { 583 // if (waysOfOriginalRelation.get(i) == wrongSegment.getPTWays().get(0)) { 584 modifiedRelationMembers.addAll(correctSegment.getPTWays()); 585 i = i + wrongSegment.getPTWays().size() - 1; 586 } else { 587 modifiedRelationMembers.add(waysOfOriginalRelation.get(i)); 588 } 589 } 590 591 592 modifiedRelation.setMembers(modifiedRelationMembers); 593 // TODO: change the data model too 594 ChangeCommand changeCommand = new ChangeCommand(originalRelation, modifiedRelation); 595 return changeCommand; 596 } 474 597 475 598 return null;
Note:
See TracChangeset
for help on using the changeset viewer.