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 SummaryFields Modifier and Type Field Description static intCCWCounter-clockwisestatic intCWClockwisestatic intDOWNDownward, e.g. on a schematic diagram or CTC panelstatic intEASTEastwardstatic intLEFTLeftward, e.g. on a schematic diagram or CTC panelstatic intNONEDirection not known or not specified.static intNORTHNorthwardstatic intNORTH_EASTNorth-Eaststatic intNORTH_WESTNorth-Weststatic intRIGHTRightward, e.g. on a schematic diagram or CTC panelstatic intSOUTHSouthwardstatic intSOUTH_EASTSouth-Eaststatic intSOUTH_WESTSouth-Weststatic intUPUpward, e.g. on a schematic diagram or CTC panelstatic intWESTWestward
 - 
Constructor SummaryConstructors 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 SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSetting(BeanSetting t)booleancheckPathSet()Check that the Path can be traversed.voidclearSettings()intcompareTo(Path obj)static intcomputeDirection(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Compute octagonal direction of vector from p1 to p2.static java.lang.StringdecodeDirection(int d)Decode the direction constants into a human-readable form.booleanequals(java.lang.Object obj)BlockgetBlock()intgetFromBlockDirection()floatgetLength()Get actual stored length.floatgetLengthCm()Get length in centimeters.floatgetLengthIn()Get length in inches.floatgetLengthMm()Get length in millimeters.java.util.List<BeanSetting>getSettings()intgetToBlockDirection()inthashCode()voidremoveSetting(BeanSetting t)static intreverseDirection(int inDir)Get the reverse octagonal direction.voidsetBlock(Block b)voidsetFromBlockDirection(int d)voidsetLength(float l)Set path length.voidsetToBlockDirection(int d)java.lang.StringtoString()
 
- 
- 
- 
Field Detail- 
NONEpublic 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
 
 - 
NORTHpublic static final int NORTH Northward- See Also:
- Constant Field Values
 
 - 
SOUTHpublic static final int SOUTH Southward- See Also:
- Constant Field Values
 
 - 
EASTpublic static final int EAST Eastward- See Also:
- Constant Field Values
 
 - 
WESTpublic static final int WEST Westward- See Also:
- Constant Field Values
 
 - 
NORTH_EASTpublic static final int NORTH_EAST North-East- See Also:
- Constant Field Values
 
 - 
SOUTH_EASTpublic static final int SOUTH_EAST South-East- See Also:
- Constant Field Values
 
 - 
SOUTH_WESTpublic static final int SOUTH_WEST South-West- See Also:
- Constant Field Values
 
 - 
NORTH_WESTpublic static final int NORTH_WEST North-West- See Also:
- Constant Field Values
 
 - 
CWpublic static final int CW Clockwise- See Also:
- Constant Field Values
 
 - 
CCWpublic static final int CCW Counter-clockwise- See Also:
- Constant Field Values
 
 - 
LEFTpublic static final int LEFT Leftward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
 
 - 
RIGHTpublic static final int RIGHT Rightward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
 
 - 
UPpublic static final int UP Upward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
 
 - 
DOWNpublic static final int DOWN Downward, e.g. on a schematic diagram or CTC panel- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Pathpublic Path() Create an object with default directions of NONE, and no setting element.
 - 
Pathpublic Path(Block dest, int toBlockDirection, int fromBlockDirection) Convenience constructor to set the destination/source block and directions in one call.- Parameters:
- dest- the destination
- toBlockDirection- direction to next block
- fromBlockDirection- direction from prior block
 
 - 
Pathpublic 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 destination
- toBlockDirection- direction to next block
- fromBlockDirection- direction from prior block
- setting- the setting to add
 
 
- 
 - 
Method Detail- 
addSettingpublic void addSetting(BeanSetting t) 
 - 
getSettingspublic java.util.List<BeanSetting> getSettings() 
 - 
removeSettingpublic void removeSetting(BeanSetting t) 
 - 
clearSettingspublic void clearSettings() 
 - 
getToBlockDirectionpublic int getToBlockDirection() 
 - 
setToBlockDirectionpublic void setToBlockDirection(int d) 
 - 
getFromBlockDirectionpublic int getFromBlockDirection() 
 - 
setFromBlockDirectionpublic void setFromBlockDirection(int d) 
 - 
checkPathSetpublic 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.
 
 - 
decodeDirectionpublic static java.lang.String decodeDirection(int d) Decode the direction constants into a human-readable form.- Parameters:
- d- the direction
- Returns:
- the direction description
 
 - 
setLengthpublic void setLength(float l) Set path length. Length may override the block length default.- Parameters:
- l- length in millimeters
 
 - 
getLengthpublic float getLength() Get actual stored length.- Returns:
- length in millimeters or 0
 
 - 
getLengthMmpublic float getLengthMm() Get length in millimeters.- Returns:
- the stored length if greater than 0 or the block length
 
 - 
getLengthCmpublic float getLengthCm() Get length in centimeters.- Returns:
- the stored length if greater than 0 or the block length
 
 - 
getLengthInpublic float getLengthIn() Get length in inches.- Returns:
- the stored length if greater than 0 or the block length
 
 - 
equalspublic boolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
compareTopublic int compareTo(Path obj) - Specified by:
- compareToin interface- java.lang.Comparable<Path>
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
computeDirectionpublic 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 point
- p2- the second point
- Returns:
- the octagonal direction from p1 to p2
 
 - 
reverseDirectionpublic 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
 
 
- 
 
-