001 // License: GPL. For details, see LICENSE file.
002 package org.openstreetmap.josm.gui.dialogs.relation;
003
004 import static org.openstreetmap.josm.gui.dialogs.relation.WayConnectionType.Direction.NONE;
005 import static org.openstreetmap.josm.tools.I18n.tr;
006
007 public class WayConnectionType {
008
009 /** True, if the corresponding primitive is not a way or the way is incomplete */
010 private final boolean invalid;
011
012 /** True, if linked to the previous / next member. */
013 public boolean linkPrev;
014 public boolean linkNext;
015
016 /**
017 * direction is FORWARD if the first node of this way is connected to the previous way
018 * and / or the last node of this way is connected to the next way.
019 * direction is BACKWARD if it is the other way around.
020 * direction has a ROUNDABOUT value, if it is tagged as such and it is somehow
021 * connected to the previous / next member.
022 * If there is no connection to the previous or next member, then
023 * direction has the value NONE.
024 */
025 public Direction direction;
026
027 public enum Direction {
028 FORWARD, BACKWARD, ROUNDABOUT_LEFT, ROUNDABOUT_RIGHT, NONE;
029
030 public boolean isRoundabout() {
031 return this == ROUNDABOUT_RIGHT || this == ROUNDABOUT_LEFT;
032 }
033 }
034
035 /** True, if the element is part of a closed loop of ways. */
036 public boolean isLoop;
037
038 public boolean isOnewayLoopForwardPart = false;
039 public boolean isOnewayLoopBackwardPart = false;
040 public boolean isOnewayHead = false;
041 public boolean isOnewayTail = false;
042
043 public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
044 this.linkPrev = linkPrev;
045 this.linkNext = linkNext;
046 this.isLoop = false;
047 this.direction = direction;
048 invalid = false;
049 }
050
051 public WayConnectionType(boolean invalid){
052 this.invalid = invalid;
053 }
054
055 /** construct invalid instance */
056 public WayConnectionType() {
057 this.linkPrev = false;
058 this.linkNext = false;
059 this.isLoop = false;
060 this.direction = NONE;
061 invalid = true;
062 }
063
064 public boolean isValid() {
065 return !invalid;
066 }
067
068 @Override
069 public String toString() {
070 return "[P "+linkPrev+" ;N "+linkNext+" ;D "+direction+" ;L "+isLoop+
071 " ;FP " + isOnewayLoopForwardPart+";BP " + isOnewayLoopBackwardPart+
072 ";OH " + isOnewayHead+";OT " + isOnewayTail+"]";
073 }
074
075 public String getToolTip() {
076 if (!isValid())
077 return "";
078 else if (linkPrev && linkNext)
079 return tr("way is connected");
080 else if (linkPrev)
081 return tr("way is connected to previous relation member");
082 else if (linkNext)
083 return tr("way is connected to next relation member");
084 else
085 return tr("way is not connected to previous or next relation member");
086 }
087 }