Class DefaultSignalMastLogic

    • Constructor Detail

      • DefaultSignalMastLogic

        public DefaultSignalMastLogic​(@Nonnull
                                      SignalMast source)
        Initialise a Signal Mast Logic for a given source Signal Mast.
        Parameters:
        source - The Signal Mast we are configuring an SML for
    • Method Detail

      • replaceSourceMast

        public void replaceSourceMast​(SignalMast oldMast,
                                      SignalMast newMast)
        Replace the existing source Signal Mast with another signal mast. This is for use with such tools as the Layout Editor where a signal mast in a certain location can be replaced with another, while the remainder of the configuration stays the same.
        Specified by:
        replaceSourceMast in interface SignalMastLogic
        Parameters:
        oldMast - Signal Mast currently configured as the source mast
        newMast - Signal Mast to act as the replacement source mast
      • replaceDestinationMast

        public void replaceDestinationMast​(SignalMast oldMast,
                                           SignalMast newMast)
        Replace the existing destination Signal Mast with another signal mast. This is for use with such tools as the Layout Editor where a signalmast in a certain location can be replaced with another, while the remainder of the configuration stays the same.
        Specified by:
        replaceDestinationMast in interface SignalMastLogic
        Parameters:
        oldMast - Signal Mast currently configured as the destination mast
        newMast - Signal Mast to act as the replacement destination mast
      • isDestinationValid

        public boolean isDestinationValid​(SignalMast dest)
        Check if signal mast is a destination signal mast in one of the logics
        Specified by:
        isDestinationValid in interface SignalMastLogic
        Parameters:
        dest - controlled signal mast
        Returns:
        true if destination is a destination mast in this object
      • getComment

        public java.lang.String getComment​(SignalMast dest)
        Get the comment set on this SML.
        Specified by:
        getComment in interface SignalMastLogic
        Parameters:
        dest - the mast to get the comment from
        Returns:
        the comment or an empty string
      • setComment

        public void setComment​(java.lang.String comment,
                               SignalMast dest)
        Set the comment for this SML.
        Specified by:
        setComment in interface SignalMastLogic
        Parameters:
        comment - text to add as comment
        dest - signal mast to add comment to
      • isEnabled

        public boolean isEnabled​(SignalMast dest)
        Query if the Signal Mast Logic from the current source signal mast to the specified destination signal mast is enabled.
        Specified by:
        isEnabled in interface SignalMastLogic
        Parameters:
        dest - controlled signal mast
        Returns:
        true if enabled
      • isActive

        public boolean isActive​(SignalMast dest)
        Query if the Signal Mast Logic from the current source signal mast to the destination signal mast is active.
        Specified by:
        isActive in interface SignalMastLogic
        Parameters:
        dest - controlled signal mast
        Returns:
        true if active; false otherwise
      • removeDestination

        public boolean removeDestination​(SignalMast dest)
        Remove the destination signal mast as a pair in this SML.
        Specified by:
        removeDestination in interface SignalMastLogic
        Parameters:
        dest - controlled signal mast
        Returns:
        true if there are no more destination signal masts
      • useLayoutEditor

        public void useLayoutEditor​(boolean boo,
                                    SignalMast destination)
                             throws JmriException
        Set whether this logic should use the details stored in the Layout Editor to determine which blocks, turnouts will make up the logic between the source and destination signal mast.
        Specified by:
        useLayoutEditor in interface SignalMastLogic
        Parameters:
        boo - Use the Layout Editor details to determine logic details
        destination - the Destination Signal Mast
        Throws:
        JmriException - if a path on the layout editor is not valid
      • useLayoutEditor

        public boolean useLayoutEditor​(SignalMast destination)
        Query if we are using the Layout Editor panels to build the signal mast logic, blocks, turnouts.
        Specified by:
        useLayoutEditor in interface SignalMastLogic
        Parameters:
        destination - Destination Signal Mast
        Returns:
        true if we are using the Layout Editor to build the signal mast logic.
      • useLayoutEditorDetails

        public void useLayoutEditorDetails​(boolean turnouts,
                                           boolean blocks,
                                           SignalMast destination)
                                    throws JmriException
        Set whether this logic should use the information from the Layout Editor for either blocks or turnouts.
        Specified by:
        useLayoutEditorDetails in interface SignalMastLogic
        Parameters:
        turnouts - set false if not to use the turnout information gathered from the layout editor
        blocks - set false if not to use the block information gathered from the layout editor
        destination - Destination Signal Mast
        Throws:
        JmriException - if a path on the layout editor is not valid
      • useLayoutEditorBlocks

        public boolean useLayoutEditorBlocks​(SignalMast destination)
        Query if we are using the Layout Editor block information in the signal mast logic.
        Specified by:
        useLayoutEditorBlocks in interface SignalMastLogic
        Parameters:
        destination - Destination Signal Mast
        Returns:
        true if we are using the block information from the Layout Editor.
      • useLayoutEditorTurnouts

        public boolean useLayoutEditorTurnouts​(SignalMast destination)
        Query if we are using the Layout Editor turnout information in the signal mast logic.
        Specified by:
        useLayoutEditorTurnouts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        true if we are using the turnout information from the Layout Editor.
      • allowTurnoutLock

        public void allowTurnoutLock​(boolean lock,
                                     SignalMast destination)
        Sets whether we should lock all turnouts between the source and destination signal masts when the logic goes active, to prevent them from being changed. This is dependant upon the hardware allowing for this.
        Specified by:
        allowTurnoutLock in interface SignalMastLogic
        Parameters:
        lock - set true if the system should lock the turnout.
        destination - controlled signal mast
      • setTurnouts

        public void setTurnouts​(java.util.Hashtable<NamedBeanHandle<Turnout>,​java.lang.Integer> turnouts,
                                SignalMast destination)
        Set the states that each control turnout must be in for the source signal mast not to be set to a Stop aspect.
        Specified by:
        setTurnouts in interface SignalMastLogic
        Parameters:
        turnouts - A list of named turnouts and their respective set to state to check
        destination - controlled signal mast
      • setAutoTurnouts

        public void setAutoTurnouts​(java.util.Hashtable<Turnout,​java.lang.Integer> turnouts,
                                    SignalMast destination)
        Set which turnouts must be set to a given state for the signal mast not to be set to a Stop aspect. These Turnouts are not stored in the panel file.
        Specified by:
        setAutoTurnouts in interface SignalMastLogic
        Parameters:
        turnouts - map of turnouts and their respective set to state
        destination - controlled signal mast
      • setBlocks

        public void setBlocks​(java.util.Hashtable<Block,​java.lang.Integer> blocks,
                              SignalMast destination)
        Set which blocks must be in a given state for the signal mast not to be set to a Stop aspect.
        Specified by:
        setBlocks in interface SignalMastLogic
        Parameters:
        blocks - map of Blocks and their respective set to state
        destination - controlled signal mast
      • setAutoBlocks

        public void setAutoBlocks​(java.util.LinkedHashMap<Block,​java.lang.Integer> blocks,
                                  SignalMast destination)
        Set which blocks must be in a given state for the signal mast not to be set to a Stop aspect. These blocks are not stored in the panel file.
        Specified by:
        setAutoBlocks in interface SignalMastLogic
        Parameters:
        blocks - map of Blocks and their respective set to state to be checked
        destination - controlled signal mast
      • setMasts

        public void setMasts​(java.util.Hashtable<SignalMast,​java.lang.String> masts,
                             SignalMast destination)
        Set which control signal masts must be in a given state before our source mast can be set.
        Specified by:
        setMasts in interface SignalMastLogic
        Parameters:
        masts - map of control signal masts and respective set to states to be checked
        destination - controlled signal mast
      • setAutoMasts

        public void setAutoMasts​(java.util.Hashtable<SignalMast,​java.lang.String> masts,
                                 SignalMast destination)
        Set which control signal masts must be in a given state before our source mast can be set. These Signal Masts are not stored in the panel file.
        Specified by:
        setAutoMasts in interface SignalMastLogic
        Parameters:
        masts - list of control signal masts and their respective set to state to be checked
        destination - controlled signal mast
      • setSensors

        public void setSensors​(java.util.Hashtable<NamedBeanHandle<Sensor>,​java.lang.Integer> sensors,
                               SignalMast destination)
        Set which sensors must be in a given state before our source signal mast can be set.
        Specified by:
        setSensors in interface SignalMastLogic
        Parameters:
        sensors - The Sensors to be checked
        destination - controlled signal mast
      • addSensor

        public void addSensor​(java.lang.String sensorName,
                              int state,
                              SignalMast destination)
        Add an individual control Sensor and its set to state to the Signal Mast Logic.
        Specified by:
        addSensor in interface SignalMastLogic
        Parameters:
        sensorName - The sensor to be removed
        state - Integer representing the state the control Sensor should be in
        destination - controlled signal mast
      • removeSensor

        public void removeSensor​(java.lang.String sensorName,
                                 SignalMast destination)
        Remove an individual control Sensor from the Signal Mast Logic.
        Specified by:
        removeSensor in interface SignalMastLogic
        Parameters:
        sensorName - The sensor to be removed
        destination - controlled signal mast
      • getBlocks

        public java.util.List<BlockgetBlocks​(SignalMast destination)
        Return the Layout Blocks that have been defined by the user to control the SML to the destination mast.
        Specified by:
        getBlocks in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Block objects
      • getAutoBlocks

        public java.util.List<BlockgetAutoBlocks​(SignalMast destination)
        Return all the blocks that have been detected as being in use for this logic. This includes blocks on level xings that are not directly in the path but do have an effect on the logic.
        Specified by:
        getAutoBlocks in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Block objects
      • getAutoBlocksBetweenMasts

        public java.util.List<BlockgetAutoBlocksBetweenMasts​(SignalMast destination)
        Return a list of blocks just that have been detected as being directly between the source and destination mast. The order of the blocks in the list is the order in which they are connected.
        Specified by:
        getAutoBlocksBetweenMasts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of block objects
      • getTurnouts

        public java.util.List<TurnoutgetTurnouts​(SignalMast destination)
        Return the Turnouts that have been defined by the user to control the SML to the destination mast.
        Specified by:
        getTurnouts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Turnout objects
      • getAutoTurnouts

        public java.util.List<TurnoutgetAutoTurnouts​(SignalMast destination)
        Return only the turnouts that have been detected as being directly between the source and destination mast. The order of the turnouts in the list is the order in which they are connected.
        Specified by:
        getAutoTurnouts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of turnout objects
      • getSensors

        public java.util.List<SensorgetSensors​(SignalMast destination)
        Return the Sensors that have been defined by the user to control the SML to the destination mast.
        Specified by:
        getSensors in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Sensor objects
      • getNamedSensors

        public java.util.List<NamedBeanHandle<Sensor>> getNamedSensors​(SignalMast destination)
        Return the Sensors that have been defined by the user to control the SML to the destination mast as NamedBeanHandles.
        Specified by:
        getNamedSensors in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Sensor NamedBeanHandles
      • getSignalMasts

        public java.util.List<SignalMastgetSignalMasts​(SignalMast destination)
        Return the Signal Masts that have been defined by the user to control the SML to the destination mast.
        Specified by:
        getSignalMasts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of Signal Mast objects
      • getAutoMasts

        public java.util.List<SignalMastgetAutoMasts​(SignalMast destination)
        Return a list of control masts that have been automatically detected as being directly between the source and destination mast. The order of the control masts in the list is the order in which they are connected.
        Specified by:
        getAutoMasts in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
        Returns:
        A list of signal mast objects
      • initialise

        public void initialise​(SignalMast destination)
        Initialise the signal mast after all the parameters have been set.
        Specified by:
        initialise in interface SignalMastLogic
        Parameters:
        destination - controlled signal mast
      • setupLayoutEditorTurnoutDetails

        public java.util.LinkedHashMap<Block,​java.lang.Integer> setupLayoutEditorTurnoutDetails​(java.util.List<LayoutBlock> blks,
                                                                                                      SignalMast destination)
        Set the auto turnouts based upon a given list of layout blocks for a specific destination mast.
        Specified by:
        setupLayoutEditorTurnoutDetails in interface SignalMastLogic
        Parameters:
        blks - List of Layout Blocks.
        destination - Destination Signal Mast
        Returns:
        A LinkedHashMap of the original blocks and their required state, plus any blocks found on double cross-overs that also need to be un-occupied.
      • checkStates

        boolean checkStates()
        Check if routes to the destination Signal Mast are clear.
        Returns:
        true if the path to the next signal is clear
      • areBlocksIncluded

        public boolean areBlocksIncluded​(java.util.List<Block> blks)
        Returns true if any of the blocks in the supplied list are included in any of the logics that set this signal.
        Specified by:
        areBlocksIncluded in interface SignalMastLogic
        Parameters:
        blks - A list of Layout Blocks to query against
        Returns:
        whether all supplied blocks are in at least one of the logics
      • getBlockState

        public int getBlockState​(Block block,
                                 SignalMast destination)
        Return the Set To State of a control block as it is configured between the source and destination mast.
        Specified by:
        getBlockState in interface SignalMastLogic
        Parameters:
        block - The Control Layout Block
        destination - controlled signal mast
        Returns:
        Integer representing the state the control block should be in
      • isBlockIncluded

        public boolean isBlockIncluded​(Block block,
                                       SignalMast destination)
        Check whether the Block is part of at least one of the logics.
        Specified by:
        isBlockIncluded in interface SignalMastLogic
        Parameters:
        block - a layout block
        destination - controlled signal mast
        Returns:
        true if block is included in any of the Signal Mast Logics that set destination
      • isTurnoutIncluded

        public boolean isTurnoutIncluded​(Turnout turnout,
                                         SignalMast destination)
        Check if a turnout is part of at least one of the logics that set a signal mast.
        Specified by:
        isTurnoutIncluded in interface SignalMastLogic
        Parameters:
        turnout - the turnout to check
        destination - controlled signal mast
        Returns:
        true if turnout is included in any of the Signal Mast Logics that set destination
      • isSensorIncluded

        public boolean isSensorIncluded​(Sensor sensor,
                                        SignalMast destination)
        Check if a sensor is part of at least one of the logics that set a SignalMast.
        Specified by:
        isSensorIncluded in interface SignalMastLogic
        Parameters:
        sensor - the sensor to check
        destination - controlled signal
        Returns:
        true if sensor is included in any of the Signal Mast Logics that set destination
      • isSignalMastIncluded

        public boolean isSignalMastIncluded​(SignalMast signal,
                                            SignalMast destination)
        Check if a signal mast is part of at least one of the logics that set another signal mast.
        Specified by:
        isSignalMastIncluded in interface SignalMastLogic
        Parameters:
        signal - the signal mast to check
        destination - controlled signal mast
        Returns:
        true if signal is included in any of the Signal Mast Logics that set destination
      • getAutoBlockState

        public int getAutoBlockState​(Block block,
                                     SignalMast destination)
        Return the Set State of a control block as it is configured between the source and destination mast.
        Specified by:
        getAutoBlockState in interface SignalMastLogic
        Parameters:
        block - The Control Layout Block.
        destination - controlled signal mast
        Returns:
        The int value representing the occupancy state that the block should show
      • getSensorState

        public int getSensorState​(Sensor sensor,
                                  SignalMast destination)
        Return the Set To State of a control Sensor as it is configured between the source and destination mast.
        Specified by:
        getSensorState in interface SignalMastLogic
        Parameters:
        sensor - The Control Sensor
        destination - controlled signal mast
        Returns:
        Integer representing the state the control Sensor should be in
      • getTurnoutState

        public int getTurnoutState​(Turnout turnout,
                                   SignalMast destination)
        Return the Set State of a control Turnout as it is configured between the source and destination mast.
        Specified by:
        getTurnoutState in interface SignalMastLogic
        Parameters:
        turnout - The Control Turnout
        destination - controlled signal mast
        Returns:
        Integer representing the state the control Sensor should be in
      • getAutoTurnoutState

        public int getAutoTurnoutState​(Turnout turnout,
                                       SignalMast destination)
        Return the Set State of a control turnout as it is configured between the source and destination mast.
        Specified by:
        getAutoTurnoutState in interface SignalMastLogic
        Parameters:
        turnout - The Control Turnout
        destination - controlled signal mast
        Returns:
        The name of the Aspect the Control Mast should display
      • getSignalMastState

        public java.lang.String getSignalMastState​(SignalMast mast,
                                                   SignalMast destination)
        Return the Set To State (Aspect) of a control Signal Mast as it is configured between the source and destination mast.
        Specified by:
        getSignalMastState in interface SignalMastLogic
        Parameters:
        mast - The Control Signal Mast
        destination - controlled signal mast
        Returns:
        Integer representing the state the control Signal Mast should be in
      • getAutoSignalMastState

        public java.lang.String getAutoSignalMastState​(SignalMast mast,
                                                       SignalMast destination)
        Return the Set State (Aspect) of a control mast as it is configured between the source and destination mast.
        Specified by:
        getAutoSignalMastState in interface SignalMastLogic
        Parameters:
        mast - The Control Signal Mast
        destination - controlled signal mast
        Returns:
        The name of the Aspect the Control Mast should display
      • getMaximumSpeed

        public float getMaximumSpeed​(SignalMast destination)
        Get the Maximum Speed set for the destination Signal Mast in this SML.
        Specified by:
        getMaximumSpeed in interface SignalMastLogic
        Parameters:
        destination - the destination mast
        Returns:
        A number representing the speed
      • setSignalAppearance

        void setSignalAppearance()
        Before going active or checking that we can go active, wait 500ms for things to settle down to help prevent a race condition.
      • setMastAppearance

        void setMastAppearance()
        Evaluate the destination signal mast Aspect and set ours accordingly.
      • setConflictingLogic

        public void setConflictingLogic​(SignalMast sm,
                                        LevelXing lx)
        Add control elements for a SML pair containing a destination signal mast that itself is skipped as it is incompatible with an SML around a level crossing.
        Specified by:
        setConflictingLogic in interface SignalMastLogic
        Parameters:
        sm - The destination Signal Mast
        lx - The LevelXing Layout Editor element
      • removeConflictingLogic

        public void removeConflictingLogic​(SignalMast sm,
                                           LevelXing lx)
        Remove control elements for a SML pair containing a destination signal mast that itself is incompatible with an SML around a level crossing.
        Specified by:
        removeConflictingLogic in interface SignalMastLogic
        Parameters:
        sm - The destination Signal Mast
        lx - The LevelXing Layout Editor element
      • getBeanType

        public java.lang.String getBeanType()
        For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
        Specified by:
        getBeanType in interface NamedBean
        Returns:
        a string of the bean type, eg Turnout, Sensor etc
      • getState

        public int getState()
        No valid integer state, always return a constant.
        Specified by:
        getState in interface NamedBean
        Returns:
        Always zero
      • setState

        public void setState​(int i)
        Description copied from interface: NamedBean
        Provide generic access to internal state.

        This generally shouldn't be used by Java code; use the class-specific form instead (e.g. setCommandedState in Turnout). This is provided to make scripts access easier to read.

        Specified by:
        setState in interface NamedBean
        Parameters:
        i - the state