Class LayoutBlockConnectivityTools

java.lang.Object
jmri.jmrit.display.layoutEditor.LayoutBlockConnectivityTools

public final class LayoutBlockConnectivityTools
extends Object
These are a series of layout block connectivity tools that can be used when the advanced layout block routing has been enabled. These tools can determine if a path from a source to destination bean is valid. If a route between two layout blocks is usable and free.
  • Field Details

  • Constructor Details

  • Method Details

    • checkValidDest

      public boolean checkValidDest​(NamedBean sourceBean, NamedBean destBean, LayoutBlockConnectivityTools.Routing pathMethod) throws JmriException
      Determines if a pair of NamedBeans (Signalhead, Signalmast or Sensor) assigned to a block boundary are reachable.
      Called by SignallingPanel using MASTTOMAST.

      Search all of the layout editor panels to find the facing and protecting layout blocks for each bean. Call the 3 block+list version of checkValidDest() to finish the checks.

      Parameters:
      sourceBean - The source bean.
      destBean - The destination bean.
      pathMethod - Indicates the type of path: Signal head, signal mast or sensor.
      Returns:
      true if source and destination beans are reachable.
      Throws:
      JmriException - if no blocks can be found that related to the named beans.
    • getLayoutBlocks

      public List<LayoutBlock> getLayoutBlocks​(NamedBean sourceBean, NamedBean destBean, boolean validateOnly, LayoutBlockConnectivityTools.Routing pathMethod) throws JmriException
      The is used in conjunction with the layout block routing protocol, to discover a clear path from a source layout block through to a destination layout block. By specifying the sourceLayoutBlock and protectingLayoutBlock or sourceLayoutBlock+1, a direction of travel can then be determined, eg east to west, south to north etc.

      Parameters:
      sourceBean - The source bean (SignalHead, SignalMast or Sensor) assigned to a block boundary that we are starting from.
      destBean - The destination bean.
      validateOnly - When set false, the system will not use layout blocks that are set as either reserved(useExtraColor set) or occupied, if it finds any then it will try to find an alternative path When set false, no block state checking is performed.
      pathMethod - Performs a check to see if any signal heads/masts are in the path, if there are then the system will try to find an alternative path. If set to NONE, then no checking is performed.
      Returns:
      an List of all the layoutblocks in the path.
      Throws:
      JmriException - if it can not find a valid path or the routing has not been enabled.
    • getBeansInPath

      public List<NamedBean> getBeansInPath​(List<LayoutBlock> blocklist, LayoutEditor panel, Class<?> T)
      Returns a list of NamedBeans (Signalhead, Signalmast or Sensor) that are assigned to block boundaries in a given list.
      Parameters:
      blocklist - The list of block in order that need to be checked.
      panel - (Optional) panel that the blocks need to be checked against
      T - (Optional) the class that we want to check against, either Sensor, SignalMast or SignalHead, set null will return any.
      Returns:
      the list of NamedBeans
    • checkValidDest

      public boolean checkValidDest​(LayoutBlock currentBlock, LayoutBlock nextBlock, LayoutBlock destBlock, LayoutBlock destProBlock, LayoutBlockConnectivityTools.Routing pathMethod) throws JmriException
      Determines if one set of blocks is reachable from another set of blocks based upon the directions of the set of blocks. Convert the destination protected block to an array list. Call the 3 block+list version of checkValidDest() to finish the checks.

      Parameters:
      currentBlock - The facing layout block for the source signal or sensor.
      nextBlock - The protected layout block for the source signal or sensor.
      destBlock - The facing layout block for the destination signal mast or sensor.
      destProBlock - The protected destination block.
      pathMethod - Indicates the type of path: Signal head, signal mast or sensor.
      Returns:
      true if a path to the destination is valid.
      Throws:
      JmriException - if any Block is null;
    • checkValidDest

      public boolean checkValidDest​(LayoutBlock currentBlock, LayoutBlock nextBlock, LayoutBlock destBlock, List<LayoutBlock> destBlockn1, LayoutBlockConnectivityTools.Routing pathMethod) throws JmriException
      Determines if one set of blocks is reachable from another set of blocks based upon the directions of the set of blocks.

      This is used to help with identifying items such as signalmasts located at positionable points or turnouts are facing in the same direction as other given signalmasts.

      Given the current block and the next block we can work out the direction of travel. Given the destBlock and the next block on, we can determine the whether the destBlock comes before the destBlock+1.

      Note: This version is internally called by other versions that pre-process external calls.

      Parameters:
      currentBlock - The facing layout block for the source signal or sensor.
      nextBlock - The protected layout block for the source signal or sensor.
      destBlock - The facing layout block for the destination signal mast or sensor.
      destBlockn1 - A list of protected destination blocks. Can be empty if the destination is at an end bumper.
      pathMethod - Indicates the type of path: Signal head, signal mast or sensor.
      Returns:
      true if a path to the destination is valid.
      Throws:
      JmriException - if any layout block is null or advanced routing is not enabled.
    • getLayoutBlocks

      public List<LayoutBlock> getLayoutBlocks​(LayoutBlock sourceLayoutBlock, LayoutBlock destinationLayoutBlock, LayoutBlock protectingLayoutBlock, boolean validateOnly, LayoutBlockConnectivityTools.Routing pathMethod) throws JmriException
      This used in conjunction with the layout block routing protocol, to discover a clear path from a source layout block through to a destination layout block. By specifying the sourceLayoutBlock and protectingLayoutBlock or sourceLayoutBlock+1, a direction of travel can then be determined, eg east to west, south to north etc.

      Parameters:
      sourceLayoutBlock - The layout block that we are starting from, can also be considered as the block facing a signal.
      destinationLayoutBlock - The layout block that we want to get to
      protectingLayoutBlock - The next layout block connected to the source block, this can also be considered as the block being protected by a signal
      validateOnly - When set false, the system will not use layout blocks that are set as either reserved(useExtraColor set) or occupied, if it finds any then it will try to find an alternative path When set true, no block state checking is performed.
      pathMethod - Performs a check to see if any signal heads/masts are in the path, if there are then the system will try to find an alternative path. If set to NONE, then no checking is performed.
      Returns:
      an List of all the layoutblocks in the path.
      Throws:
      JmriException - if it can not find a valid path or the routing has not been enabled.
    • findBestHop

      int findBestHop​(Block preBlock, Block currentBlock, Block destBlock, int direction, List<Integer> offSet, boolean validateOnly, LayoutBlockConnectivityTools.Routing pathMethod)
    • discoverValidBeanPairs

      Discovers valid pairs of beans type T assigned to a layout editor. If no bean type is provided, then either SignalMasts or Sensors are discovered If no editor is provided, then all editors are considered
      Parameters:
      editor - the layout editor panel
      T - the type
      pathMethod - Determine whether or not we should reject pairs if there are other beans in the way. Constant values of NONE, ANY, MASTTOMAST, HEADTOHEAD
      Returns:
      the valid pairs
    • discoverPairDest

      Returns a list of valid destination beans reachable from a given source bean.
      Parameters:
      source - Either a SignalMast or Sensor
      editor - The layout editor that the source is located on, if null, then all editors are considered
      T - The class of the remote destination, if null, then both SignalMasts and Sensors are considered
      pathMethod - Determine whether or not we should reject pairs if there are other beans in the way. Constant values of NONE, ANY, MASTTOMAST, HEADTOHEAD
      Returns:
      A list of all reachable NamedBeans
      Throws:
      JmriException - occurring during nested readAll operation
    • discoverPairDest

      Throws:
      JmriException
    • generateBlocksWithBeans