Changeset 32751 in osm for applications


Ignore:
Timestamp:
2016-08-01T19:49:55+02:00 (8 years ago)
Author:
darya
Message:

automated overshoot fix added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r32747 r32751  
    631631                initialFix.add(startPTWay);
    632632                initialFixes.add(initialFix);
    633                 List<PTWay> fix = findWaysForFix(initialFixes, initialFix, previousNode, endPTWay).get(0);
    634 
    635                 if (!fix.isEmpty() && fix.get(fix.size() - 1).equals(endPTWay)) {
    636                         wrongSegment.addFixVariant(fix);
    637                 }
    638 
    639         }
    640 
    641         /**
    642          *
     633
     634                List<List<PTWay>> allFixes = findWaysForFix(initialFixes, initialFix, previousNode, endPTWay);
     635                for (List<PTWay> fix : allFixes) {
     636                        if (!fix.isEmpty() && fix.get(fix.size() - 1).equals(endPTWay)) {
     637                                wrongSegment.addFixVariant(fix);
     638                        }
     639                }
     640               
     641
     642        }
     643
     644        /**
     645         * Recursive method to parse the route segment
    643646         * @param allFixes
    644647         * @param currentFix
     
    647650         * @return
    648651         */
    649         private List<List<PTWay>> findWaysForFix (List<List<PTWay>> allFixes, List<PTWay> currentFix, Node previousNode,
     652        private List<List<PTWay>> findWaysForFix(List<List<PTWay>> allFixes, List<PTWay> currentFix, Node previousNode,
    650653                        PTWay endWay) {
    651654
     
    653656                Node nextNode = getOppositeEndNode(currentWay, previousNode);
    654657
    655                 List<PTWay> potentialNextWays = this.findNextPTWaysInDirectionOfTravel(currentWay, nextNode);
    656                 List<PTWay> nextWays = new ArrayList<>();
    657                 for (PTWay potentianNextWay : potentialNextWays) {
    658                         if (unusedWays.contains(potentianNextWay)) {
    659                                 nextWays.add(potentianNextWay);
     658                List<PTWay> nextWays = this.findNextPTWaysInDirectionOfTravel(currentWay, nextNode);
     659               
     660                if (nextWays.size() > 1) {
     661                        for (int i = 1; i < nextWays.size(); i++) {
     662                                List<PTWay> newFix = new ArrayList<>();
     663                                newFix.addAll(currentFix);
     664                                newFix.add(nextWays.get(i));
     665                                allFixes.add(newFix);
     666                                if (!nextWays.get(i).equals(endWay) && !currentFix.contains(nextWays.get(i))) {
     667                                        allFixes = findWaysForFix(allFixes, newFix, nextNode, endWay);
     668                                }
    660669                        }
    661670                }
    662671
    663672                if (!nextWays.isEmpty()) {
     673                        boolean contains = currentFix.contains(nextWays.get(0));
    664674                        currentFix.add(nextWays.get(0));
    665                         if (!nextWays.get(0).equals(endWay)) {
     675                        if (!nextWays.get(0).equals(endWay) && !contains) {
    666676                                allFixes = findWaysForFix(allFixes, currentFix, nextNode, endWay);
    667677                        }
    668678                }
    669679
    670 //              if (nextWays.size() > 1) {
    671 //                      for (int i = 1; i < nextWays.size(); i++) {
    672 //                              List<PTWay> newList = new ArrayList<>();
    673 //                              newList.addAll(currentFix);
    674 //                              newList.add(nextWays.get(i));
    675 //                              allFixes.add(newList);
    676 //                              // TODO: go on
    677 //                      }
    678 //              }
     680
    679681
    680682                return allFixes;
     
    758760
    759761                } else if (!wrongSegment.getFixVariants().isEmpty()) {
     762                       
    760763                        // 2) try to fix by using the sort & remove method:
    761764                        // TODO: ask user if the change should be undertaken
     
    794797                        for (int i = 0; i < waysOfOriginalRelation.size(); i++) {
    795798                                if (waysOfOriginalRelation.get(i).getWay() == wrongSegment.getPTWays().get(0).getWays().get(0)) {
    796                                         for (PTWay ptway : wrongSegment.getFixVariants().get(0)) {
     799                                        for (PTWay ptway : wrongSegment.getFixVariants().get(0)) { // FIXME
    797800                                                if (ptway.getRole().equals("forward") || ptway.getRole().equals("backward")) {
    798801                                                        modifiedRelationMembers.add(new RelationMember("", ptway.getMember()));
     
    811814                                }
    812815                        }
     816                       
    813817                        modifiedRelation.setMembers(modifiedRelationMembers);
    814818                        // TODO: change the data model too
Note: See TracChangeset for help on using the changeset viewer.