Changeset 16886 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-08-12T22:17:36+02:00 (4 years ago)
Author:
simon04
Message:

fix #19633 - Route relations with split start do not show links as expected in the relation editor (patch by matthijskooijman)

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationNodeMap.java

    r16630 r16886  
    177177    private Integer popForwardOnewayPart(Integer way) {
    178178        if (onewayMap.ways.containsKey(way)) {
    179             for (Node n : onewayMap.ways.get(way)) {
    180                 Integer i = findAdjacentWay(onewayMap, n);
    181                 if (i == null) {
    182                     continue;
    183                 }
    184 
    185                 lastOnewayNode = processBackwardIfEndOfLoopReached(i);
    186                 if (lastOnewayNode != null)
    187                     return popBackwardOnewayPart(firstOneway);
    188 
    189                 deleteWayNode(onewayMap, i, n);
    190                 return i;
    191             }
     179            Node exitNode = onewayMap.ways.get(way).iterator().next();
     180
     181            if (checkIfEndOfLoopReached(exitNode)) {
     182                lastOnewayNode = exitNode;
     183                return popBackwardOnewayPart(firstOneway);
     184            }
     185
     186            Integer i = deleteAndGetAdjacentNode(onewayMap, exitNode);
     187            if (i != null) return i;
     188
     189            // When our forward route ends in a dead end try to start
     190            // the backward route anyway from the split point
     191            // (firstOneWay), to support routes with split a split start
     192            // or end.
     193            lastOnewayNode = exitNode;
     194            return popBackwardOnewayPart(firstOneway);
    192195        }
    193196
     
    196199    }
    197200
    198     private Node processBackwardIfEndOfLoopReached(Integer way) { //find if we didn't reach end of the loop (and process backward part)
    199         if (onewayReverseMap.ways.containsKey(way)) {
    200             for (Node n : onewayReverseMap.ways.get(way)) {
    201                 if (map.nodes.containsKey(n)
    202                         || (onewayMap.nodes.containsKey(n) && onewayMap.nodes.get(n).size() > 1))
    203                     return n;
    204                 if (firstCircular != null && firstCircular == n)
    205                     return firstCircular;
    206             }
    207         }
    208         return null;
     201    // Check if the given node can be the end of the loop (i.e. it has
     202    // an outgoing bidirectional or multiple outgoing oneways, or we
     203    // looped back to our first circular node)
     204    private boolean checkIfEndOfLoopReached(Node n) {
     205        if (map.nodes.containsKey(n)
     206                || (onewayMap.nodes.containsKey(n) && onewayMap.nodes.get(n).size() > 1))
     207            return true;
     208        if (firstCircular != null && firstCircular == n)
     209            return true;
     210        return false;
    209211    }
    210212
     
    267269        } else {
    268270            done(way);
    269         }
    270         nw.ways.get(way).remove(n);
     271            // For bidirectional ways, remove the entry node, so
     272            // subsequent lookups will only return the other node(s) as
     273            // valid exit nodes.
     274            nw.ways.get(way).remove(n);
     275        }
    271276    }
    272277
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java

    r15747 r16886  
    146146
    147147        if (!wct.linkPrev) {
    148             wct.direction = determineDirectionOfFirst(i, m);
     148            wct.direction = determineDirectionOfFirst(i, m, false);
    149149            if (RelationSortUtils.isOneway(m)) {
    150150                wct.isOnewayLoopForwardPart = true;
     
    218218    }
    219219
    220     private Direction determineDirectionOfFirst(final int i, final RelationMember m) {
     220    private Direction determineDirectionOfFirst(final int i, final RelationMember m, boolean reversed) {
    221221        Direction result = RelationSortUtils.roundaboutType(m);
    222222        if (result != NONE)
     
    224224
    225225        if (RelationSortUtils.isOneway(m)) {
    226             if (RelationSortUtils.isBackward(m)) return BACKWARD;
     226            if (RelationSortUtils.isBackward(m) != reversed) return BACKWARD;
    227227            else return FORWARD;
    228228        } else { /** guess the direction and see if it fits with the next member */
     
    248248            }
    249249
     250            // Support split-start routes. When the current way does
     251            // not fit as forward or backward and we have no backward
     252            // ways yet (onewayBeginning) and the most recent oneway
     253            // head starts a new segment (!linkPrev), instead of
     254            // disconnecting the current way, make it the start of the
     255            // backward route. To render properly, unset isOnewayHead on
     256            // the most recent head (since the current backward way does
     257            // no longer start there).
     258            if (dirFW == NONE && dirBW == NONE && RelationSortUtils.isOneway(m) && !wct.isOnewayHead) {
     259                WayConnectionType prevHead = null;
     260                for (int j = i - 1; j >= 0; --j) {
     261                    if (con.get(j).isOnewayHead) {
     262                        prevHead = con.get(j);
     263                        break;
     264                    }
     265                }
     266
     267                if (prevHead != null && !prevHead.linkPrev) {
     268                    dirBW = determineDirectionOfFirst(i, m, true);
     269                    prevHead.isOnewayHead = false;
     270                }
     271            }
     272
    250273            if (dirBW != NONE) {
    251274                onewayBeginning = false;
     
    269292            if (dirFW == NONE && dirBW == NONE) {
    270293                wct.linkPrev = false;
    271                 if (RelationSortUtils.isOneway(m)) {
    272                     wct.isOnewayHead = true;
    273                     lastForwardWay = i-1;
    274                     lastBackwardWay = i-1;
    275                 } else {
    276                     lastForwardWay = UNCONNECTED;
    277                     lastBackwardWay = UNCONNECTED;
    278                 }
     294                wct.isOnewayHead = true;
     295                lastForwardWay = i-1;
     296                lastBackwardWay = i-1;
    279297                onewayBeginning = true;
    280298            }
Note: See TracChangeset for help on using the changeset viewer.