source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java@ 15076

Last change on this file since 15076 was 15076, checked in by Don-vip, 5 years ago

fix #17501 - Detect if a oneway in a relation may be going in the wrong direction (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.sort;
3
4import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.NONE;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7/**
8 * A class used by the {@link RelationSorter} to store if two ways are already connected
9 */
10public class WayConnectionType {
11
12 /** True, if the corresponding primitive is not a way or the way is incomplete */
13 private final boolean invalid;
14
15 /** True, if linked to the previous member. */
16 public boolean linkPrev;
17 /** True, if linked to the next member. */
18 public boolean linkNext;
19
20 /**
21 * direction is FORWARD if the first node of this way is connected to the previous way
22 * and / or the last node of this way is connected to the next way.
23 * direction is BACKWARD if it is the other way around.
24 * direction has a ONEWAY value, if it is tagged as such and it is connected
25 * to the previous / next member.
26 * ONEWAY_FORWARD == the first node of the oneway is the last node of the previous way
27 * ONEWAY_BACKWARD == the last node of the oneway is the last node of the previous way
28 * direction has a ROUNDABOUT value, if it is tagged as such and it is somehow
29 * connected to the previous / next member.
30 * If there is no connection to the previous or next member, then
31 * direction has the value NONE.
32 */
33 public Direction direction;
34
35 public enum Direction {
36 FORWARD, BACKWARD, ROUNDABOUT_LEFT, ROUNDABOUT_RIGHT, NONE;
37
38 public boolean isRoundabout() {
39 return this == ROUNDABOUT_RIGHT || this == ROUNDABOUT_LEFT;
40 }
41 }
42
43 /** True, if the element is part of a closed loop of ways. */
44 public boolean isLoop;
45
46 public boolean isOnewayLoopForwardPart;
47 public boolean isOnewayLoopBackwardPart;
48 public boolean isOnewayHead;
49 public boolean isOnewayTail;
50
51 /** False, if the way is oneway and it doesn't follow the flow of the previous member */
52 public boolean onewayFollowsPrevious = true;
53 /** True, if the way is oneway and it doesn't follow the flow of the next member */
54 public boolean onewayFollowsNext = true;
55
56 public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
57 this.linkPrev = linkPrev;
58 this.linkNext = linkNext;
59 this.isLoop = false;
60 this.direction = direction;
61 invalid = false;
62 }
63
64 public WayConnectionType(boolean invalid) {
65 this.invalid = invalid;
66 }
67
68 /** construct invalid instance */
69 public WayConnectionType() {
70 this.linkPrev = false;
71 this.linkNext = false;
72 this.isLoop = false;
73 this.direction = NONE;
74 invalid = true;
75 }
76
77 public boolean isValid() {
78 return !invalid;
79 }
80
81 @Override
82 public String toString() {
83 return "[P "+linkPrev+" ;N "+linkNext+" ;D "+direction+" ;L "+isLoop+
84 " ;FP " + isOnewayLoopForwardPart+";BP " + isOnewayLoopBackwardPart+
85 ";OH " + isOnewayHead+";OT " + isOnewayTail+']';
86 }
87
88 /**
89 * Returns the tooltip to display when hovering over the relation member.
90 * @return The tooltip, never null.
91 * @since 10248
92 */
93 public String getTooltip() {
94 boolean onewayGood = onewayFollowsPrevious && onewayFollowsNext;
95 if (!isValid())
96 return "";
97 else if (linkPrev && linkNext && onewayGood)
98 return tr("way is connected");
99 else if (linkPrev && linkNext && !onewayGood)
100 return tr("way is connected but has a wrong oneway direction");
101 else if (linkPrev && onewayGood)
102 return tr("way is connected to previous relation member");
103 else if (linkPrev && !onewayGood)
104 return tr("way is connected to previous relation member but has a wrong oneway direction");
105 else if (linkNext && onewayGood)
106 return tr("way is connected to next relation member");
107 else if (linkNext && !onewayGood)
108 return tr("way is connected to next relation member but has a wrong oneway direction");
109 else
110 return tr("way is not connected to previous or next relation member");
111 }
112}
Note: See TracBrowser for help on using the repository browser.