Class Path
- java.lang.Object
-
- jmri.Path
-
- All Implemented Interfaces:
java.lang.Comparable<Path>
- Direct Known Subclasses:
OPath
public class Path extends java.lang.Object implements java.lang.Comparable<Path>
Represents a particular set of NamedBean (usually turnout) settings to put a path through trackwork to a Block.Directions are defined for traffic along this path "to" the block, and "from" the block. Being more specific:
- The "to" direction is the direction that a train is going when it traverses this path "to" the final block.
- The "from" direction is the direction that a train is going when it traverses this path "from" the final block.
This implementation handles paths with a list of bean settings. This has been extended from the initial implementation.
The length of the path may also optionally be entered if desired. This attribute is for use in automatic running of trains. Length should be the actual length of model railroad track in the path. It is always stored here in millimeter units. A length of 0.0 indicates no entry of length by the user. If there is no entry the length of the block the path is in will be returned. An Entry is only needed when there are paths of greatly different lengths in the block.
-
-
Field Summary
Fields Modifier and Type Field Description static int
CCW
Counter-clockwisestatic int
CW
Clockwisestatic int
DOWN
Downward, e.g. on a schematic diagram or CTC panelstatic int
EAST
Eastwardstatic int
LEFT
Leftward, e.g. on a schematic diagram or CTC panelstatic int
NONE
Direction not known or not specified.static int
NORTH
Northwardstatic int
NORTH_EAST
North-Eaststatic int
NORTH_WEST
North-Weststatic int
RIGHT
Rightward, e.g. on a schematic diagram or CTC panelstatic int
SOUTH
Southwardstatic int
SOUTH_EAST
South-Eaststatic int
SOUTH_WEST
South-Weststatic int
UP
Upward, e.g. on a schematic diagram or CTC panelstatic int
WEST
Westward
-
Constructor Summary
Constructors Constructor Description Path()
Create an object with default directions of NONE, and no setting element.Path(Block dest, int toBlockDirection, int fromBlockDirection)
Convenience constructor to set the destination/source block and directions in one call.Path(Block dest, int toBlockDirection, int fromBlockDirection, BeanSetting setting)
Convenience constructor to set the destination/source block, directions and a single setting element in one call.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSetting(BeanSetting t)
boolean
checkPathSet()
Check that the Path can be traversed.void
clearSettings()
int
compareTo(Path obj)
static int
computeDirection(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Compute octagonal direction of vector from p1 to p2.static java.lang.String
decodeDirection(int d)
Decode the direction constants into a human-readable form.boolean
equals(java.lang.Object obj)
Block
getBlock()
int
getFromBlockDirection()
float
getLength()
Get actual stored length.float
getLengthCm()
Get length in centimeters.float
getLengthIn()
Get length in inches.float
getLengthMm()
Get length in millimeters.java.util.List<BeanSetting>
getSettings()
int
getToBlockDirection()
int
hashCode()
void
removeSetting(BeanSetting t)
static int
reverseDirection(int inDir)
Get the reverse octagonal direction.void
setBlock(Block b)
void
setFromBlockDirection(int d)
void
setLength(float l)
Set path length.void
setToBlockDirection(int d)
java.lang.String
toString()
-
-
-
Field Detail
-
NONE
public static final int NONE
Direction not known or not specified. May also represent "stopped", in the sense of not moving in any direction.- See Also:
- Constant Field Values
-
NORTH
public static final int NORTH
Northward- See Also:
- Constant Field Values
-
SOUTH
public static final int SOUTH
Southward- See Also:
- Constant Field Values
-
EAST
public static final int EAST
Eastward- See Also:
- Constant Field Values
-
WEST
public static final int WEST
Westward- See Also:
- Constant Field Values
-
NORTH_EAST
public static final int NORTH_EAST
North-East- See Also:
- Constant Field Values
-
SOUTH_EAST
public static final int SOUTH_EAST
South-East- See Also:
- Constant Field Values
-
SOUTH_WEST
public static final int SOUTH_WEST
South-West- See Also:
- Constant Field Values
-
NORTH_WEST
public static final int NORTH_WEST
North-West- See Also:
- Constant Field Values
-
CW
public static final int CW
Clockwise- See Also:
- Constant Field Values
-
CCW
public static final int CCW
Counter-clockwise- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
Leftward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
Rightward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
-
UP
public static final int UP
Upward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
-
DOWN
public static final int DOWN
Downward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Path
public Path()
Create an object with default directions of NONE, and no setting element.
-
Path
public Path(Block dest, int toBlockDirection, int fromBlockDirection)
Convenience constructor to set the destination/source block and directions in one call.- Parameters:
dest
- the destinationtoBlockDirection
- direction to next blockfromBlockDirection
- direction from prior block
-
Path
public Path(Block dest, int toBlockDirection, int fromBlockDirection, BeanSetting setting)
Convenience constructor to set the destination/source block, directions and a single setting element in one call.- Parameters:
dest
- the destinationtoBlockDirection
- direction to next blockfromBlockDirection
- direction from prior blocksetting
- the setting to add
-
-
Method Detail
-
addSetting
public void addSetting(BeanSetting t)
-
getSettings
public java.util.List<BeanSetting> getSettings()
-
removeSetting
public void removeSetting(BeanSetting t)
-
clearSettings
public void clearSettings()
-
getToBlockDirection
public int getToBlockDirection()
-
setToBlockDirection
public void setToBlockDirection(int d)
-
getFromBlockDirection
public int getFromBlockDirection()
-
setFromBlockDirection
public void setFromBlockDirection(int d)
-
checkPathSet
public boolean checkPathSet()
Check that the Path can be traversed. This means that any path elements are set to the proper state, e.g. that the Turnouts on this path are set to the proper CLOSED or OPEN status.- Returns:
- true if the path can be traversed; always true if no path elements (BeanSettings) are defined.
-
decodeDirection
public static java.lang.String decodeDirection(int d)
Decode the direction constants into a human-readable form.- Parameters:
d
- the direction- Returns:
- the direction description
-
setLength
public void setLength(float l)
Set path length. Length may override the block length default.- Parameters:
l
- length in millimeters
-
getLength
public float getLength()
Get actual stored length.- Returns:
- length in millimeters or 0
-
getLengthMm
public float getLengthMm()
Get length in millimeters.- Returns:
- the stored length if greater than 0 or the block length
-
getLengthCm
public float getLengthCm()
Get length in centimeters.- Returns:
- the stored length if greater than 0 or the block length
-
getLengthIn
public float getLengthIn()
Get length in inches.- Returns:
- the stored length if greater than 0 or the block length
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
compareTo
public int compareTo(Path obj)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Path>
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
computeDirection
public static int computeDirection(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
Compute octagonal direction of vector from p1 to p2.Note: the octagonal (8) directions are: North, North-East, East, South-East, South, South-West, West and North-West
- Parameters:
p1
- the first pointp2
- the second point- Returns:
- the octagonal direction from p1 to p2
-
reverseDirection
public static int reverseDirection(int inDir)
Get the reverse octagonal direction.- Parameters:
inDir
- the direction- Returns:
- the reverse direction or 0 if inDir is not a direction
-
-