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

Last change on this file since 15732 was 15732, checked in by simon04, 4 years ago

see #18503 - Relation editor: compute wayConnection for type=superroute

This basic implementation only considers route segments without a role
(as specified for public_transport:version=2; no forward/backward)
and does not take roundabouts into account.

  • Property svn:eol-style set to native
File size: 5.0 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 /**
39 * Determines if the direction denotes a roundabout.
40 * @return {@code true} if the direction denotes a roundabout
41 */
42 public boolean isRoundabout() {
43 return this == ROUNDABOUT_RIGHT || this == ROUNDABOUT_LEFT;
44 }
45 }
46
47 /** True, if the element is part of a closed loop of ways. */
48 public boolean isLoop;
49
50 /** True, if all oneway features are ignored */
51 public boolean ignoreOneway;
52
53 public boolean isOnewayLoopForwardPart;
54 public boolean isOnewayLoopBackwardPart;
55 public boolean isOnewayHead;
56 public boolean isOnewayTail;
57
58 /** False, if the way is oneway and it doesn't follow the flow of the previous member */
59 public boolean onewayFollowsPrevious = true;
60 /** True, if the way is oneway and it doesn't follow the flow of the next member */
61 public boolean onewayFollowsNext = true;
62
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 */
69 public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
70 this.linkPrev = linkPrev;
71 this.linkNext = linkNext;
72 this.isLoop = false;
73 this.direction = direction;
74 invalid = false;
75 }
76
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 */
81 public WayConnectionType(boolean invalid) {
82 this.linkPrev = false;
83 this.linkNext = false;
84 this.isLoop = false;
85 this.direction = NONE;
86 this.invalid = invalid;
87 }
88
89 /** construct invalid instance */
90 public WayConnectionType() {
91 this(true);
92 }
93
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 */
98 public boolean isValid() {
99 return !invalid;
100 }
101
102 @Override
103 public String toString() {
104 return "[P "+linkPrev+" ;N "+linkNext+" ;D "+direction+" ;L "+isLoop+
105 " ;FP " + isOnewayLoopForwardPart+";BP " + isOnewayLoopBackwardPart+
106 ";OH " + isOnewayHead+";OT " + isOnewayTail+']';
107 }
108
109 /**
110 * Returns the tooltip to display when hovering over the relation member.
111 * @return The tooltip, never null.
112 * @since 10248
113 */
114 public String getTooltip() {
115 boolean onewayGood = onewayFollowsPrevious && onewayFollowsNext;
116 if (!isValid())
117 return "";
118 else if (linkPrev && linkNext && onewayGood)
119 return tr("way is connected");
120 else if (linkPrev && linkNext && !onewayGood)
121 return tr("way is connected but has a wrong oneway direction");
122 else if (linkPrev && onewayGood)
123 return tr("way is connected to previous relation member");
124 else if (linkPrev && !onewayGood)
125 return tr("way is connected to previous relation member but has a wrong oneway direction");
126 else if (linkNext && onewayGood)
127 return tr("way is connected to next relation member");
128 else if (linkNext && !onewayGood)
129 return tr("way is connected to next relation member but has a wrong oneway direction");
130 else
131 return tr("way is not connected to previous or next relation member");
132 }
133}
Note: See TracBrowser for help on using the repository browser.