Package jmri

Class 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.
    Although useful constants are defined, you don't have to restrict to those, and there's no assumption that they have to be opposites; NORTH for "to" does not imply SOUTH for "from". This allows you to e.g. handle a piece of curved track where you can be going LEFT at one point and UP at another. The constants are defined as bits, so you can use more than one at a time, for example a direction can simultanously be EAST and RIGHT if desired. What that means needs to be defined by whatever object is using this Path.

    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.

    • 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 destination
        toBlockDirection - direction to next block
        fromBlockDirection - 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 destination
        toBlockDirection - direction to next block
        fromBlockDirection - direction from prior block
        setting - the setting to add
    • Method Detail

      • 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 class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(Path obj)
        Specified by:
        compareTo in interface java.lang.Comparable<Path>
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.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 point
        p2 - 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