Changeset 15696 in josm for trunk


Ignore:
Timestamp:
2020-01-13T00:11:29+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18020 - don't show way directions for boundary relations

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PublicTransportRouteTest.java

    r15522 r15696  
    6161        }
    6262
    63         final List<WayConnectionType> links = connectionTypeCalculator.updateLinks(membersToCheck);
     63        final List<WayConnectionType> links = connectionTypeCalculator.updateLinks(r, membersToCheck);
    6464        for (int i = 0; i < links.size(); i++) {
    6565            final WayConnectionType link = links.get(i);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java

    r15076 r15696  
    3232
    3333        reset();
    34         if (value == null)
    35             return this;
    36 
    37         this.value = (WayConnectionType) value;
    38         setToolTipText(((WayConnectionType) value).getTooltip());
    39         renderBackgroundForeground(getModel(table), null, isSelected);
     34        if (value != null) {
     35            this.value = (WayConnectionType) value;
     36            setToolTipText(((WayConnectionType) value).getTooltip());
     37            renderBackgroundForeground(getModel(table), null, isSelected);
     38        }
    4039        return this;
    4140    }
     
    6362        int w = 2;
    6463        int p = 2 + w + 1;
     64        int y1 = computePreviousY(g, xloop, xowloop, xoff, w, p);
     65        int y2 = computeNextY(g, ymax, xloop, xowloop, xoff, w, p);
     66
     67        /* vertical lines */
     68        if (value.onewayFollowsNext && value.onewayFollowsPrevious) {
     69            g.setColor(Color.black);
     70        } else {
     71            g.setColor(Color.lightGray);
     72        }
     73        if (value.isLoop) {
     74            g.drawLine(xoff+xloop, y1, xoff+xloop, y2);
     75        }
     76
     77        if (value.isOnewayHead) {
     78            setDotted(g);
     79            y1 = 7;
     80
     81            int[] xValues = {xoff - xowloop + 1, xoff - xowloop + 1, xoff};
     82            int[] yValues = {ymax, y1+1, 1};
     83            g.drawPolyline(xValues, yValues, 3);
     84            unsetDotted(g);
     85            g.drawLine(xoff + xowloop, y1+1, xoff, 1);
     86        }
     87
     88        if (value.isOnewayTail) {
     89            setDotted(g);
     90            y2 = ymax - 7;
     91
     92            int[] xValues = {xoff+1, xoff - xowloop + 1, xoff - xowloop + 1};
     93            int[] yValues = {ymax-1, y2, y1};
     94            g.drawPolyline(xValues, yValues, 3);
     95            unsetDotted(g);
     96            g.drawLine(xoff + xowloop, y2, xoff, ymax-1);
     97        }
     98
     99        if ((value.isOnewayLoopForwardPart || value.isOnewayLoopBackwardPart) && !value.isOnewayTail && !value.isOnewayHead) {
     100            setDotted(g);
     101            g.drawLine(xoff - xowloop+1, y1, xoff - xowloop+1, y2 + 1);
     102            unsetDotted(g);
     103        }
     104
     105        if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart) {
     106            g.drawLine(xoff, y1, xoff, y2);
     107        }
     108
     109        g.drawLine(xoff+xowloop, y1, xoff+xowloop, y2);
     110
     111        /* special icons */
     112        Image arrow = getArrow();
     113        if (value.direction == Direction.ROUNDABOUT_LEFT) {
     114            g.drawImage(ROUNDABOUT_LEFT, xoff-6, 1, null);
     115        } else if (value.direction == Direction.ROUNDABOUT_RIGHT) {
     116            g.drawImage(ROUNDABOUT_RIGHT, xoff-6, 1, null);
     117        }
     118
     119        if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart &&
     120                (arrow != null)) {
     121            g.drawImage(arrow, xoff-3, (y1 + y2) / 2 - 2, null);
     122        }
     123
     124        if (value.isOnewayLoopBackwardPart && value.isOnewayLoopForwardPart) {
     125            if (arrow == ARROW_DOWN) {
     126                arrow = ARROW_UP;
     127            } else if (arrow == ARROW_UP) {
     128                arrow = ARROW_DOWN;
     129            }
     130        }
     131
     132        if (arrow != null) {
     133            g.drawImage(arrow, xoff+xowloop-3, (y1 + y2) / 2 - 2, null);
     134        }
     135    }
     136
     137    private int computePreviousY(Graphics g, int xloop, int xowloop, int xoff, int w, int p) {
    65138        int y1;
    66         int y2;
    67139
    68140        if (value.linkPrev) {
     
    95167            }
    96168        }
     169        return y1;
     170    }
     171
     172    private int computeNextY(Graphics g, int ymax, int xloop, int xowloop, int xoff, int w, int p) {
     173        int y2;
    97174
    98175        if (value.linkNext) {
     
    126203            }
    127204        }
    128 
    129         /* vertical lines */
    130         if (value.onewayFollowsNext && value.onewayFollowsPrevious) {
    131             g.setColor(Color.black);
    132         } else {
    133             g.setColor(Color.lightGray);
    134         }
    135         if (value.isLoop) {
    136             g.drawLine(xoff+xloop, y1, xoff+xloop, y2);
    137         }
    138 
    139         if (value.isOnewayHead) {
    140             setDotted(g);
    141             y1 = 7;
    142 
    143             int[] xValues = {xoff - xowloop + 1, xoff - xowloop + 1, xoff};
    144             int[] yValues = {ymax, y1+1, 1};
    145             g.drawPolyline(xValues, yValues, 3);
    146             unsetDotted(g);
    147             g.drawLine(xoff + xowloop, y1+1, xoff, 1);
    148         }
    149 
    150         if (value.isOnewayTail) {
    151             setDotted(g);
    152             y2 = ymax - 7;
    153 
    154             int[] xValues = {xoff+1, xoff - xowloop + 1, xoff - xowloop + 1};
    155             int[] yValues = {ymax-1, y2, y1};
    156             g.drawPolyline(xValues, yValues, 3);
    157             unsetDotted(g);
    158             g.drawLine(xoff + xowloop, y2, xoff, ymax-1);
    159         }
    160 
    161         if ((value.isOnewayLoopForwardPart || value.isOnewayLoopBackwardPart) && !value.isOnewayTail && !value.isOnewayHead) {
    162             setDotted(g);
    163             g.drawLine(xoff - xowloop+1, y1, xoff - xowloop+1, y2 + 1);
    164             unsetDotted(g);
    165         }
    166 
    167         if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart) {
    168             g.drawLine(xoff, y1, xoff, y2);
    169         }
    170 
    171         g.drawLine(xoff+xowloop, y1, xoff+xowloop, y2);
    172 
    173         /* special icons */
    174         Image arrow;
    175         switch (value.direction) {
    176         case FORWARD:
    177             arrow = ARROW_DOWN;
    178             break;
    179         case BACKWARD:
    180             arrow = ARROW_UP;
    181             break;
    182         default:
    183             arrow = null;
    184         }
    185         if (value.direction == Direction.ROUNDABOUT_LEFT) {
    186             g.drawImage(ROUNDABOUT_LEFT, xoff-6, 1, null);
    187         } else if (value.direction == Direction.ROUNDABOUT_RIGHT) {
    188             g.drawImage(ROUNDABOUT_RIGHT, xoff-6, 1, null);
    189         }
    190 
    191         if (!value.isOnewayLoopForwardPart && !value.isOnewayLoopBackwardPart &&
    192                 (arrow != null)) {
    193             g.drawImage(arrow, xoff-3, (y1 + y2) / 2 - 2, null);
    194         }
    195 
    196         if (value.isOnewayLoopBackwardPart && value.isOnewayLoopForwardPart) {
    197             if (arrow == ARROW_DOWN) {
    198                 arrow = ARROW_UP;
    199             } else if (arrow == ARROW_UP) {
    200                 arrow = ARROW_DOWN;
    201             }
    202         }
    203 
    204         if (arrow != null) {
    205             g.drawImage(arrow, xoff+xowloop-3, (y1 + y2) / 2 - 2, null);
    206         }
     205        return y2;
     206    }
     207
     208    private Image getArrow() {
     209        if (!value.ignoreOneway) {
     210            switch (value.direction) {
     211            case FORWARD:
     212                return ARROW_DOWN;
     213            case BACKWARD:
     214                return ARROW_UP;
     215            default:
     216                break;
     217            }
     218        }
     219        return null;
    207220    }
    208221
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r15378 r15696  
    777777        try {
    778778            if (connectionType == null) {
    779                 connectionType = wayConnectionTypeCalculator.updateLinks(members);
     779                connectionType = wayConnectionTypeCalculator.updateLinks(relation, members);
    780780            }
    781781            return connectionType.get(i);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java

    r15076 r15696  
    3636        FORWARD, BACKWARD, ROUNDABOUT_LEFT, ROUNDABOUT_RIGHT, NONE;
    3737
     38        /**
     39         * Determines if the direction denotes a roundabout.
     40         * @return {@code true} if the direction denotes a roundabout
     41         */
    3842        public boolean isRoundabout() {
    3943            return this == ROUNDABOUT_RIGHT || this == ROUNDABOUT_LEFT;
     
    4347    /** True, if the element is part of a closed loop of ways. */
    4448    public boolean isLoop;
     49
     50    /** True, if all oneway features are ignored */
     51    public boolean ignoreOneway;
    4552
    4653    public boolean isOnewayLoopForwardPart;
     
    5461    public boolean onewayFollowsNext = true;
    5562
     63    /**
     64     * Constructs a valid instance.
     65     * @param linkPrev {@code true} if linked to the previous member
     66     * @param linkNext {@code true} if linked to the next member
     67     * @param direction the direction type
     68     */
    5669    public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
    5770        this.linkPrev = linkPrev;
     
    6275    }
    6376
     77    /**
     78     * Constructs a valid or invalid instance.
     79     * @param invalid {@code true} if the instance is invalid (i.e does not concern a complete way)
     80     */
    6481    public WayConnectionType(boolean invalid) {
    6582        this.invalid = invalid;
     
    7592    }
    7693
     94    /**
     95     * Determines if the connection type is valid (i.e. it concerns a complete way).
     96     * @return {@code true} if the connection type is valid (i.e. it concerns a complete way)
     97     */
    7798    public boolean isValid() {
    7899        return !invalid;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java

    r15586 r15696  
    1010
    1111import org.openstreetmap.josm.data.osm.Node;
     12import org.openstreetmap.josm.data.osm.Relation;
    1213import org.openstreetmap.josm.data.osm.RelationMember;
    1314import org.openstreetmap.josm.data.osm.Way;
     
    3031     */
    3132    public List<WayConnectionType> updateLinks(List<RelationMember> members) {
     33        return updateLinks(null, members);
     34    }
     35
     36    /**
     37     * refresh the cache of member WayConnectionTypes
     38     * @param r relation. Can be null, for plugins compatibility, but really shouldn't
     39     * @param members relation members
     40     * @return way connections
     41     * @since 15696
     42     */
     43    public List<WayConnectionType> updateLinks(Relation r, List<RelationMember> members) {
    3244        this.members = members;
    3345        final List<WayConnectionType> con = new ArrayList<>();
     
    4658        for (int i = 0; i < members.size(); ++i) {
    4759            try {
    48                 lastWct = updateLinksFor(con, lastWct, i);
     60                lastWct = updateLinksFor(r, con, lastWct, i);
    4961            } catch (RuntimeException e) {
    5062                int index = i;
     
    5870    }
    5971
    60     private WayConnectionType updateLinksFor(final List<WayConnectionType> con, WayConnectionType lastWct, int i) {
     72    private WayConnectionType updateLinksFor(Relation r, List<WayConnectionType> con, WayConnectionType lastWct, int i) {
    6173        final RelationMember m = members.get(i);
    6274        if (isNoHandleableWay(m)) {
     
    6779            firstGroupIdx = i;
    6880        } else {
    69             WayConnectionType wct = computeNextWayConnection(con, lastWct, i, m);
     81            WayConnectionType wct = computeNextWayConnection(r, con, lastWct, i, m);
    7082
    7183            if (!wct.linkPrev) {
     
    8496    }
    8597
    86     private WayConnectionType computeNextWayConnection(final List<WayConnectionType> con, WayConnectionType lastWct, int i,
     98    private WayConnectionType computeNextWayConnection(Relation r, List<WayConnectionType> con, WayConnectionType lastWct, int i,
    8799            final RelationMember m) {
    88100        WayConnectionType wct = new WayConnectionType(false);
    89101        wct.linkPrev = i > 0 && con.get(i-1) != null && con.get(i-1).isValid();
    90102        wct.direction = NONE;
    91 
    92         if (RelationSortUtils.isOneway(m)) {
     103        wct.ignoreOneway = isOnewayIgnored(r);
     104
     105        if (!wct.ignoreOneway && RelationSortUtils.isOneway(m)) {
    93106            handleOneway(lastWct, i, wct);
    94107        }
     
    121134        }
    122135
     136        if (!wct.ignoreOneway) {
     137            handleOnewayFollows(lastWct, i, m, wct);
     138        }
     139        con.set(i, wct);
     140        return wct;
     141    }
     142
     143    private static boolean isOnewayIgnored(Relation r) {
     144        return r != null && "boundary".equals(r.get("type"));
     145    }
     146
     147    protected void handleOnewayFollows(WayConnectionType lastWct, int i, final RelationMember m,
     148            WayConnectionType wct) {
    123149        if (lastWct != null && i > 0 && m.getMember() instanceof Way && members.get(i - 1).getMember() instanceof Way
    124150                && (m.getWay().isOneway() != 0 || members.get(i - 1).getWay().isOneway() != 0)) {
     
    135161            }
    136162        }
    137         con.set(i, wct);
    138         return wct;
    139163    }
    140164
Note: See TracChangeset for help on using the changeset viewer.