Class LayoutBlock
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.jmrit.display.layoutEditor.LayoutBlock
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.lang.Comparable<NamedBean>,java.util.EventListener,PropertyChangeProvider,NamedBean
public class LayoutBlock extends AbstractNamedBean implements java.beans.PropertyChangeListener
A LayoutBlock is a group of track segments and turnouts on a LayoutEditor panel corresponding to a 'block'. LayoutBlock is a LayoutEditor specific extension of the JMRI Block object.LayoutBlocks may have an occupancy Sensor. The getOccupancy method returns the occupancy state of the LayoutBlock - OCCUPIED, EMPTY, or UNKNOWN. If no occupancy sensor is provided, UNKNOWN is returned. The occupancy sensor if there is one, is the same as the occupancy sensor of the corresponding JMRI Block.
The name of each Layout Block is the same as that of the corresponding block as defined in Layout Editor. A corresponding JMRI Block object is created when a LayoutBlock is created. The JMRI Block uses the name of the block defined in Layout Editor as its user name and a unique IBnnn system name. The JMRI Block object and its associated Path objects are useful in tracking a train around the layout. Blocks may be viewed in the Block Table.
A LayoutBlock may have an associated Memory object. This Memory object contains a string representing the current "value" of the corresponding JMRI Block object. If the value contains a train name, for example, displaying Memory objects associated with LayoutBlocks, and displayed near each Layout Block can follow a train around the layout, displaying its name when it is in the LayoutBlock.
LayoutBlocks are "cross-panel", similar to sensors and turnouts. A LayoutBlock may be used by more than one Layout Editor panel simultaneously. As a consequence, LayoutBlocks are saved with the configuration, not with a panel.
LayoutBlocks are used by TrackSegments, LevelXings, and LayoutTurnouts. LevelXings carry two LayoutBlock designations, which may be the same. LayoutTurnouts carry LayoutBlock designations also, one per turnout, except for double crossovers and slips which can have up to four.
LayoutBlocks carry a use count. The use count counts the number of track segments, layout turnouts, and levelcrossings which use the LayoutBlock. Only LayoutBlocks which have a use count greater than zero are saved when the configuration is saved.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classLayoutBlock.LayoutBlockEditAction-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanactive(package private) static intADDITIONstatic intEMPTY(package private) intmetricprotected java.util.List<javax.swing.JComboBox<java.lang.String>>neighbourDir(package private) static intNONEstatic intOCCUPIEDstatic java.lang.StringPROPERTY_HOPString property constant for hop.static java.lang.StringPROPERTY_LENGTHString property constant for length.static java.lang.StringPROPERTY_METRICString property constant for metric.static java.lang.StringPROPERTY_NEIGHBOUR_LENGTHString property constant for neighbour length.static java.lang.StringPROPERTY_NEIGHBOUR_METRICString property constant for neighbour metric.static java.lang.StringPROPERTY_NEIGHBOUR_PACKET_FLOWString property constant for neighbour packet flow.static java.lang.StringPROPERTY_PATHString property constant for path.static java.lang.StringPROPERTY_REDRAWString property constant for redraw.static java.lang.StringPROPERTY_ROUTINGString property constant for routing.static java.lang.StringPROPERTY_THROUGH_PATH_ADDEDString property constant for through path added.static java.lang.StringPROPERTY_THROUGH_PATH_REMOVEDString property constant for through path removed.static java.lang.StringPROPERTY_VALIDString property constant for valid.(package private) static intREMOVALstatic intRESERVED(package private) static intRXONLY(package private) static intRXTX(package private) static longtime(package private) static intTXONLY(package private) static intUPDATE-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description LayoutBlock(java.lang.String sName, java.lang.String uName)Creates a LayoutBlock object.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddAllThroughPaths()voidaddLayoutEditor(LayoutEditor panel)Keep track of LayoutEditor panels that are using this LayoutBlock.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Add aPropertyChangeListenerto the listener list.(package private) voidaddRouteFromNeighbour(LayoutBlock src, jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)(package private) voidaddRouteToNeighbours(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes ro)(package private) booleancheckIsRouteOnValidThroughPath(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes r)When a route is created, check to see if the through path that this route relates to is active.(package private) java.lang.StringdecodePacketFlow(int value)voiddecrementUse()voiddeleteLayoutEditor(LayoutEditor panel)voiddisableDeleteRouteLog()Deprecated, for removal: This API element is subject to removal in a future version.voideditLayoutBlock(java.awt.Component callingPane)voidenableDeleteRouteLog()Deprecated, for removal: This API element is subject to removal in a future version.java.util.List<Block>getActiveNextBlocks(Block source)(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.AdjacenciesgetAdjacency(Block blk)(package private) intgetAdjacencyPacketFlow(Block blk)java.lang.StringgetBeanType()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.(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.RoutesgetBestRouteByHop(Block dest)(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.RoutesgetBestRouteByLength(Block dest)(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.RoutesgetBestRouteByMetric(Block dest)BlockgetBlock()Get the Block corresponding to this LayoutBlock.java.awt.ColorgetBlockColor()Get the color for drawing items in this block.java.awt.ColorgetBlockExtraColor()intgetBlockHopCount(Block destination, Block nextBlock)Get the number of layout blocks to our destintation block going from the next directly connected block.floatgetBlockLength(Block destination, Block nextBlock)Get the distance to our desintation block going from the next directly connected block.intgetBlockMetric()Get the layout block metric costintgetBlockMetric(Block destination, Block nextBlock)Get the metric to our desintation block going from the next directly connected block.java.awt.ColorgetBlockOccupiedColor()(package private) intgetBlockStatus()(package private) java.lang.StringgetBlockStatusString()java.awt.ColorgetBlockTrackColor()intgetConnectedBlockRouteIndex(Block destBlock, int direction)(package private) java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes>getDestRoutes(Block dstBlock)Get a list of valid Routes to our destination blockjava.lang.StringgetId()LayoutEditorgetMaxConnectedPanel()Get the panel with the highest connectivity to this Layout Block.MemorygetMemory()Get Memory.java.lang.StringgetMemoryName()Returns Memory nameBlockgetNeighbourAtIndex(int i)Get the neighboring block at index i.intgetNeighbourDirection(int i)Get the direction of travel to neighbouring block at index i.intgetNeighbourDirection(Block neighbourBlock)intgetNeighbourDirection(LayoutBlock neigh)Get the direction of travel to our neighbouring block.(package private) intgetNeighbourIndex(jmri.jmrit.display.layoutEditor.LayoutBlock.Adjacencies adj)intgetNeighbourMetric(int i)Get the metric/cost to neighbouring block at index i.java.lang.StringgetNeighbourPacketFlowAsString(int i)Get the flow of traffic to and from neighbouring block at index i RXTX - Means Traffic can flow both ways between the blocks RXONLY - Means we can only receive traffic from our neighbour, we can not send traffic to it TXONLY - Means we do not receive traffic from our neighbour, but can send traffic to it.intgetNextBestBlock(Block previousBlock, Block destBlock, java.util.List<java.lang.Integer> excludeBlock, LayoutBlockConnectivityTools.Metric routingMethod)last index - the index of the last block we returned ie we last returned index 10, so we don't want to return it again.BlockgetNextBlock(Block destBlock, int direction)BlockgetNextBlock(Block previousBlock, Block destBlock)Used if we already know the block prior to our block, and the destination block. direction, is optional and is used where the previousBlock is equal to our block.intgetNextBlockByIndex(Block destBlock, int direction, int offSet)intgetNextBlockByIndex(Block previousBlock, Block destBlock, int offSet)(package private) java.lang.IntegergetNextPacketID()(package private) java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes>getNextRoutes(Block nxtBlock)Get a list of valid Routes via our next blockintgetNumberOfNeighbours()Get the number of neighbor blocks attached to this block.intgetNumberOfRoutes()Get the number of routes that the block has registered.intgetNumberOfThroughPaths()Get the number of valid through paths on this block.intgetOccupancy()Test block occupancy.SensorgetOccupancySensor()Get occupancy Sensor.java.lang.StringgetOccupancySensorName()Get occupancy Sensor name.intgetOccupiedSense()Get occupied sensor state.(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.RoutesgetRouteByDestBlock(Block blk)(package private) java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes>getRouteByNeighbour(Block blk)BlockgetRouteDestBlockAtIndex(int i)Get the destination block at route iintgetRouteDirectionAtIndex(int i)Get the direction of route i.intgetRouteHopCountAtIndex(int i)Get the hop count of route i.
The Hop count is the number of other blocks that we traverse to get to the destination(package private) intgetRouteIndex(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes r)floatgetRouteLengthAtIndex(int i)Get the length of route i.
The length is the combined length of all the blocks that we traverse to get to the destinationintgetRouteMetric(int i)Get the metric/cost at route iBlockgetRouteNextBlockAtIndex(int i)Get the next block at route iintgetRouteState(int i)Get the state (Occupied, unoccupied) of the destination layout block at index ijava.lang.StringgetRouteStateAsString(int i)Get the state of the destination layout block at index i as a string.booleangetRouteValid(int i)Is the route to the destination potentially valid from our block.intgetState()Provide generic access to internal state.BlockgetThroughPathDestination(int i)Get the destination block at index i(package private) java.util.List<Block>getThroughPathDestinationBySource(Block source)PathgetThroughPathDestinationPathAtIndex(int i)intgetThroughPathIndex(Block sourceBlock, Block destinationBlock)BlockgetThroughPathSource(int i)Get the source block at index i(package private) java.util.List<Block>getThroughPathSourceByDestination(Block dest)PathgetThroughPathSourcePathAtIndex(int i)java.util.List<NamedBeanUsageReport>getUsageReport(NamedBean bean)Get a list of references for the specified bean.intgetUseCount()booleangetUseExtraColor()(package private) jmri.jmrit.display.layoutEditor.LayoutBlock.RoutesgetValidRoute(Block nxtBlock, Block dstBlock)Get valid Routes, based upon the next block and destination block(package private) voidhandleBlockChange(java.beans.PropertyChangeEvent e)Handle tasks when block changesvoidincrementUse()voidinitializeLayoutBlock()Completes the creation of a LayoutBlock object by adding a Block to it.voidinitializeLayoutBlockRouting()booleanisActive()"active" is true if the object is still displayed, and should be stored.booleanisNeighbourMutual(int i)Is our neighbouring block at index i a mutual neighbour, ie both blocks have each other registered as neighbours and are exchanging information.booleanisOnPanel(LayoutEditor panel)booleanisRouteToDestValid(Block protecting, Block destination)Is the route to the destination block, going via our neighbouring block valid. ie Does the block have a route registered via neighbour "protecting" to the destination block.java.lang.BooleanisThroughPathActive(int i)Is the through path at index i active?(package private) booleanisValidNeighbour(Block blk)(package private) voidnotifiedNeighbourNoLongerMutual(LayoutBlock srcBlock)voidprintAdjacencies()Provide an output to the console of all our neighbouring blocks.voidprintRoutes()Provide an output to the console of all the remote blocks reachable from our block.voidprintRoutes(java.lang.String inBlockName)Provide an output to the console of how to reach a specific block from our block.voidprintValidThroughPaths()Provide an output to the console of all the valid paths through this block.voidpropertyChange(java.beans.PropertyChangeEvent e)voidredrawLayoutBlockPanels()Redraw panels using this layout block.voidrefreshValidRoutes()Go through all the routes and refresh the valid flag.(package private) voidremove()Remove this object from display and persistance.voidsetBlockExtraColor(java.awt.Color color)(package private) voidsetBlockMetric()Set the block metric based upon the track segment that the block is associated with if the (200 if Side, 50 if Main).voidsetBlockMetric(int m)Set a metric cost against a block, this is used in the calculation of a path between two location on the layout, a lower path cost is always preferred For Layout blocks defined as Mainline the default metric is 50.voidsetBlockOccupiedColor(java.awt.Color color)voidsetBlockTrackColor(java.awt.Color color)voidsetMemory(Memory m, java.lang.String name)voidsetMemoryName(java.lang.String name)Add Memory by name.voidsetOccupancySensorName(java.lang.String name)Add occupancy sensor by name.voidsetOccupiedSense(int sense)Set occupied sensor state.(package private) voidsetRoutesValid(Block nxtHopActive, boolean state)Set the valid flag for routes that are on a valid through path.voidsetState(int i)Does nothing, do not use.Dummy for completion of NamedBean interfacevoidsetSuppressNameUpdate(boolean set)Set/reset update of memory name when block goes from occupied to unoccupied or vice versa.voidsetUseExtraColor(boolean b)(package private) voidstateUpdate()protected voidupdateNeighbourPacketFlow(jmri.jmrit.display.layoutEditor.LayoutBlock.Adjacencies neighbour, int flow)(package private) booleanupdatePacketActedUpon(java.lang.Integer packetID)voidupdatePaths()Check/Update Path objects for the attached BlockvoidupdatePathsUsingPanel(LayoutEditor panel)Check/Update Path objects for the attached Block using the connectivity in the specified Layout Editor panel.(package private) voidupdateRoutesToNeighbours(java.util.List<Block> messageRecipients, jmri.jmrit.display.layoutEditor.LayoutBlock.Routes ro, jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)(package private) voidupdateRoutingInfo(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes route)(package private) voidupdateRoutingInfo(LayoutBlock src, jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)booleanuseDefaultMetric()voiduseDefaultMetric(boolean boo)MemoryvalidateMemory(java.lang.String memName, java.awt.Component openFrame)Validate that the memory name corresponds to an existing memory.SensorvalidateSensor(java.lang.String sensorName, java.awt.Component openFrame)Validate that the supplied occupancy sensor name corresponds to an existing sensor and is unique among all blocks.booleanvalidThroughPath(Block sourceBlock, Block destinationBlock)voidvetoableChange(java.beans.PropertyChangeEvent evt)-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, dispose, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.NamedBean
compareTo, getRecommendedToolTip
-
-
-
-
Field Detail
-
OCCUPIED
public static final int OCCUPIED
- See Also:
- Constant Field Values
-
EMPTY
public static final int EMPTY
- See Also:
- Constant Field Values
-
PROPERTY_REDRAW
public static final java.lang.String PROPERTY_REDRAW
String property constant for redraw.- See Also:
- Constant Field Values
-
PROPERTY_ROUTING
public static final java.lang.String PROPERTY_ROUTING
String property constant for routing.- See Also:
- Constant Field Values
-
PROPERTY_PATH
public static final java.lang.String PROPERTY_PATH
String property constant for path.- See Also:
- Constant Field Values
-
PROPERTY_THROUGH_PATH_ADDED
public static final java.lang.String PROPERTY_THROUGH_PATH_ADDED
String property constant for through path added.- See Also:
- Constant Field Values
-
PROPERTY_THROUGH_PATH_REMOVED
public static final java.lang.String PROPERTY_THROUGH_PATH_REMOVED
String property constant for through path removed.- See Also:
- Constant Field Values
-
PROPERTY_NEIGHBOUR_PACKET_FLOW
public static final java.lang.String PROPERTY_NEIGHBOUR_PACKET_FLOW
String property constant for neighbour packet flow.- See Also:
- Constant Field Values
-
PROPERTY_NEIGHBOUR_METRIC
public static final java.lang.String PROPERTY_NEIGHBOUR_METRIC
String property constant for neighbour metric.- See Also:
- Constant Field Values
-
PROPERTY_NEIGHBOUR_LENGTH
public static final java.lang.String PROPERTY_NEIGHBOUR_LENGTH
String property constant for neighbour length.- See Also:
- Constant Field Values
-
PROPERTY_VALID
public static final java.lang.String PROPERTY_VALID
String property constant for valid.- See Also:
- Constant Field Values
-
PROPERTY_LENGTH
public static final java.lang.String PROPERTY_LENGTH
String property constant for length.- See Also:
- Constant Field Values
-
PROPERTY_HOP
public static final java.lang.String PROPERTY_HOP
String property constant for hop.- See Also:
- Constant Field Values
-
PROPERTY_METRIC
public static final java.lang.String PROPERTY_METRIC
String property constant for metric.- See Also:
- Constant Field Values
-
neighbourDir
protected java.util.List<javax.swing.JComboBox<java.lang.String>> neighbourDir
-
active
boolean active
-
time
static long time
-
RESERVED
public static final int RESERVED
- See Also:
- Constant Field Values
-
ADDITION
static final int ADDITION
- See Also:
- Constant Field Values
-
UPDATE
static final int UPDATE
- See Also:
- Constant Field Values
-
REMOVAL
static final int REMOVAL
- See Also:
- Constant Field Values
-
RXTX
static final int RXTX
- See Also:
- Constant Field Values
-
RXONLY
static final int RXONLY
- See Also:
- Constant Field Values
-
TXONLY
static final int TXONLY
- See Also:
- Constant Field Values
-
NONE
static final int NONE
- See Also:
- Constant Field Values
-
metric
int metric
-
-
Constructor Detail
-
LayoutBlock
public LayoutBlock(java.lang.String sName, java.lang.String uName)
Creates a LayoutBlock object. Note: initializeLayoutBlock() must be called to complete the process. They are split so that loading of panel files will be independent of whether LayoutBlocks or Blocks are loaded first.- Parameters:
sName- System name of this LayoutBlockuName- User name of this LayoutBlock but also the user name of the associated Block
-
-
Method Detail
-
enableDeleteRouteLog
@Deprecated(since="5.11.2", forRemoval=true) public void enableDeleteRouteLog()Deprecated, for removal: This API element is subject to removal in a future version.
-
disableDeleteRouteLog
@Deprecated(since="5.11.2", forRemoval=true) public void disableDeleteRouteLog()Deprecated, for removal: This API element is subject to removal in a future version.
-
initializeLayoutBlock
public void initializeLayoutBlock()
Completes the creation of a LayoutBlock object by adding a Block to it. The block create process takes into account that the _bean register process considers IB1 and IB01 to be the same name which results in a silent failure.
-
initializeLayoutBlockRouting
public void initializeLayoutBlockRouting()
-
getId
public java.lang.String getId()
-
getBlockTrackColor
public java.awt.Color getBlockTrackColor()
-
setBlockTrackColor
public void setBlockTrackColor(java.awt.Color color)
-
getBlockOccupiedColor
public java.awt.Color getBlockOccupiedColor()
-
setBlockOccupiedColor
public void setBlockOccupiedColor(java.awt.Color color)
-
getBlockExtraColor
public java.awt.Color getBlockExtraColor()
-
setBlockExtraColor
public void setBlockExtraColor(java.awt.Color color)
-
getUseExtraColor
public boolean getUseExtraColor()
-
setUseExtraColor
public void setUseExtraColor(boolean b)
-
incrementUse
public void incrementUse()
-
decrementUse
public void decrementUse()
-
getUseCount
public int getUseCount()
-
addLayoutEditor
public void addLayoutEditor(LayoutEditor panel)
Keep track of LayoutEditor panels that are using this LayoutBlock.- Parameters:
panel- to keep track of
-
deleteLayoutEditor
public void deleteLayoutEditor(LayoutEditor panel)
-
isOnPanel
public boolean isOnPanel(LayoutEditor panel)
-
redrawLayoutBlockPanels
public void redrawLayoutBlockPanels()
Redraw panels using this layout block.
-
validateSensor
public Sensor validateSensor(java.lang.String sensorName, java.awt.Component openFrame)
Validate that the supplied occupancy sensor name corresponds to an existing sensor and is unique among all blocks. If valid, returns the sensor and sets the block sensor name in the block. Else returns null, and does nothing to the block.- Parameters:
sensorName- to checkopenFrame- determines theFramein which the dialog is displayed; ifnull, or if theparentComponenthas noFrame, a defaultFrameis used- Returns:
- the validated sensor
-
validateMemory
public Memory validateMemory(java.lang.String memName, java.awt.Component openFrame)
Validate that the memory name corresponds to an existing memory. If valid, returns the memory. Else returns null, and notifies the user.- Parameters:
memName- the memory nameopenFrame- the frame to display any error dialog in- Returns:
- the memory
-
getBlockColor
public java.awt.Color getBlockColor()
Get the color for drawing items in this block. Returns color based on block occupancy.- Returns:
- color for block
-
getMemoryName
public java.lang.String getMemoryName()
Returns Memory name- Returns:
- name of memory
-
setMemoryName
public void setMemoryName(java.lang.String name)
Add Memory by name.- Parameters:
name- for memory
-
getOccupancySensorName
public java.lang.String getOccupancySensorName()
Get occupancy Sensor name.- Returns:
- name of occupancy sensor
-
getOccupancySensor
public Sensor getOccupancySensor()
Get occupancy Sensor.If a sensor has not been assigned, try getting the sensor from the related block.
When setting the layout block sensor from the block itself using the OccupancySensorChange event, the automatic assignment has to be disabled for the sensor checking performed by
LayoutBlockManager.getBlockWithSensorAssigned(jmri.Sensor)- Returns:
- occupancy sensor or null
-
setOccupancySensorName
public void setOccupancySensorName(java.lang.String name)
Add occupancy sensor by name.- Parameters:
name- for senor to add
-
getOccupiedSense
public int getOccupiedSense()
Get occupied sensor state.- Returns:
- occupied sensor state, defaults to Sensor.ACTIVE
-
setOccupiedSense
public void setOccupiedSense(int sense)
Set occupied sensor state.- Parameters:
sense- eg. Sensor.INACTIVE
-
getOccupancy
public int getOccupancy()
Test block occupancy.- Returns:
- occupancy state
-
getState
public int getState()
Description copied from interface:NamedBeanProvide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (e.g. getCommandedState in Turnout). This is provided to make scripts easier to read.
-
setState
public void setState(int i)
Does nothing, do not use.Dummy for completion of NamedBean interface
-
getMaxConnectedPanel
public LayoutEditor getMaxConnectedPanel()
Get the panel with the highest connectivity to this Layout Block.- Returns:
- panel with most connections to this block
-
updatePaths
public void updatePaths()
Check/Update Path objects for the attached BlockIf multiple panels are present, Paths are set according to the panel with the highest connectivity (most LayoutConnectivity objects).
-
updatePathsUsingPanel
public void updatePathsUsingPanel(LayoutEditor panel)
Check/Update Path objects for the attached Block using the connectivity in the specified Layout Editor panel.- Parameters:
panel- to extract paths
-
handleBlockChange
void handleBlockChange(java.beans.PropertyChangeEvent e)
Handle tasks when block changes- Parameters:
e- propChgEvent
-
setSuppressNameUpdate
public void setSuppressNameUpdate(boolean set)
Set/reset update of memory name when block goes from occupied to unoccupied or vice versa. If set is true, name update is suppressed. If set is false, name update works normally.- Parameters:
set- true, update suppress. false, update normal
-
editLayoutBlock
public void editLayoutBlock(java.awt.Component callingPane)
-
remove
void remove()
Remove this object from display and persistance.
-
isActive
public boolean isActive()
"active" is true if the object is still displayed, and should be stored.- Returns:
- active
-
setBlockMetric
void setBlockMetric()
Set the block metric based upon the track segment that the block is associated with if the (200 if Side, 50 if Main). If the block is assigned against multiple track segments all with different types then the highest type will be used. In theory no reason why it couldn't be a compromise.
-
useDefaultMetric
public boolean useDefaultMetric()
-
useDefaultMetric
public void useDefaultMetric(boolean boo)
-
setBlockMetric
public void setBlockMetric(int m)
Set a metric cost against a block, this is used in the calculation of a path between two location on the layout, a lower path cost is always preferred For Layout blocks defined as Mainline the default metric is 50. For Layout blocks defined as a Siding the default metric is 200.- Parameters:
m- metric value
-
getBlockMetric
public int getBlockMetric()
Get the layout block metric cost- Returns:
- metric cost of block
-
addAllThroughPaths
public void addAllThroughPaths()
-
updateNeighbourPacketFlow
protected void updateNeighbourPacketFlow(jmri.jmrit.display.layoutEditor.LayoutBlock.Adjacencies neighbour, int flow)
-
notifiedNeighbourNoLongerMutual
void notifiedNeighbourNoLongerMutual(LayoutBlock srcBlock)
-
stateUpdate
void stateUpdate()
-
getBlockStatus
int getBlockStatus()
-
getBlockStatusString
java.lang.String getBlockStatusString()
-
getNextPacketID
java.lang.Integer getNextPacketID()
-
updatePacketActedUpon
boolean updatePacketActedUpon(java.lang.Integer packetID)
-
getActiveNextBlocks
public java.util.List<Block> getActiveNextBlocks(Block source)
-
getThroughPathSourcePathAtIndex
public Path getThroughPathSourcePathAtIndex(int i)
-
getThroughPathDestinationPathAtIndex
public Path getThroughPathDestinationPathAtIndex(int i)
-
validThroughPath
public boolean validThroughPath(Block sourceBlock, Block destinationBlock)
-
getThroughPathIndex
public int getThroughPathIndex(Block sourceBlock, Block destinationBlock)
-
decodePacketFlow
java.lang.String decodePacketFlow(int value)
-
printValidThroughPaths
public void printValidThroughPaths()
Provide an output to the console of all the valid paths through this block.
-
printAdjacencies
public void printAdjacencies()
Provide an output to the console of all our neighbouring blocks.
-
printRoutes
public void printRoutes()
Provide an output to the console of all the remote blocks reachable from our block.
-
printRoutes
public void printRoutes(java.lang.String inBlockName)
Provide an output to the console of how to reach a specific block from our block.- Parameters:
inBlockName- to find in route
-
getNextBlock
public Block getNextBlock(Block destBlock, int direction)
- Parameters:
destBlock- is the destination of the block we are followingdirection- is the direction of travel from the previous block- Returns:
- next block
-
getNextBlock
@CheckForNull public Block getNextBlock(Block previousBlock, Block destBlock)
Used if we already know the block prior to our block, and the destination block. direction, is optional and is used where the previousBlock is equal to our block.- Parameters:
previousBlock- start blockdestBlock- finish block- Returns:
- next block
-
getConnectedBlockRouteIndex
public int getConnectedBlockRouteIndex(Block destBlock, int direction)
-
getNextBlockByIndex
public int getNextBlockByIndex(Block destBlock, int direction, int offSet)
-
getNextBlockByIndex
public int getNextBlockByIndex(Block previousBlock, Block destBlock, int offSet)
-
getNextBestBlock
public int getNextBestBlock(Block previousBlock, Block destBlock, java.util.List<java.lang.Integer> excludeBlock, LayoutBlockConnectivityTools.Metric routingMethod)
last index - the index of the last block we returned ie we last returned index 10, so we don't want to return it again. The block returned will have a hopcount or metric equal to or greater than the one of the last block returned. if the exclude block list is empty this is the first time, it has been used. The parameters for the best last block are based upon the last entry in the excludedBlock list.- Parameters:
previousBlock- starting blockdestBlock- finish blockexcludeBlock- blocks to skiproutingMethod- value to match metric- Returns:
- next block
-
getRouteByDestBlock
@CheckForNull jmri.jmrit.display.layoutEditor.LayoutBlock.Routes getRouteByDestBlock(Block blk)
-
getRouteByNeighbour
@Nonnull java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes> getRouteByNeighbour(Block blk)
-
getAdjacencyPacketFlow
int getAdjacencyPacketFlow(Block blk)
-
isValidNeighbour
boolean isValidNeighbour(Block blk)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from class:AbstractNamedBeanAdd aPropertyChangeListenerto the listener list.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
addPropertyChangeListenerin classAbstractNamedBean- Parameters:
listener- The PropertyChangeListener to be added
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
getValidRoute
@CheckForNull jmri.jmrit.display.layoutEditor.LayoutBlock.Routes getValidRoute(Block nxtBlock, Block dstBlock)
Get valid Routes, based upon the next block and destination block- Parameters:
nxtBlock- next blockdstBlock- final block- Returns:
- routes that fit, or null
-
isRouteToDestValid
public boolean isRouteToDestValid(Block protecting, Block destination)
Is the route to the destination block, going via our neighbouring block valid. ie Does the block have a route registered via neighbour "protecting" to the destination block.- Parameters:
protecting- neighbour block that might protectdestination- block- Returns:
- true if we have valid path to block
-
getDestRoutes
java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes> getDestRoutes(Block dstBlock)
Get a list of valid Routes to our destination block- Parameters:
dstBlock- target to find- Returns:
- routes between this and dstBlock
-
getNextRoutes
java.util.List<jmri.jmrit.display.layoutEditor.LayoutBlock.Routes> getNextRoutes(Block nxtBlock)
Get a list of valid Routes via our next block- Parameters:
nxtBlock- target block- Returns:
- list of routes to target block
-
updateRoutingInfo
void updateRoutingInfo(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes route)
-
updateRoutingInfo
void updateRoutingInfo(@Nonnull LayoutBlock src, @Nonnull jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)
-
updateRoutesToNeighbours
void updateRoutesToNeighbours(java.util.List<Block> messageRecipients, jmri.jmrit.display.layoutEditor.LayoutBlock.Routes ro, jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)
-
getBestRouteByMetric
jmri.jmrit.display.layoutEditor.LayoutBlock.Routes getBestRouteByMetric(Block dest)
-
getBestRouteByHop
jmri.jmrit.display.layoutEditor.LayoutBlock.Routes getBestRouteByHop(Block dest)
-
getBestRouteByLength
jmri.jmrit.display.layoutEditor.LayoutBlock.Routes getBestRouteByLength(Block dest)
-
addRouteToNeighbours
void addRouteToNeighbours(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes ro)
-
addRouteFromNeighbour
void addRouteFromNeighbour(LayoutBlock src, jmri.jmrit.display.layoutEditor.LayoutBlock.RoutingPacket update)
-
getNeighbourDirection
public int getNeighbourDirection(LayoutBlock neigh)
Get the direction of travel to our neighbouring block.- Parameters:
neigh- neighbor block- Returns:
- direction to get to neighbor block
-
getNeighbourDirection
public int getNeighbourDirection(Block neighbourBlock)
-
getAdjacency
jmri.jmrit.display.layoutEditor.LayoutBlock.Adjacencies getAdjacency(Block blk)
-
getNumberOfNeighbours
public int getNumberOfNeighbours()
Get the number of neighbor blocks attached to this block.- Returns:
- count of neighbor
-
getNeighbourAtIndex
public Block getNeighbourAtIndex(int i)
Get the neighboring block at index i.- Parameters:
i- index to neighbor- Returns:
- neighbor block
-
getNeighbourDirection
public int getNeighbourDirection(int i)
Get the direction of travel to neighbouring block at index i.- Parameters:
i- index in neighbors- Returns:
- neighbor block
-
getNeighbourMetric
public int getNeighbourMetric(int i)
Get the metric/cost to neighbouring block at index i.- Parameters:
i- index in neighbors- Returns:
- metric of neighbor
-
getNeighbourPacketFlowAsString
public java.lang.String getNeighbourPacketFlowAsString(int i)
Get the flow of traffic to and from neighbouring block at index i RXTX - Means Traffic can flow both ways between the blocks RXONLY - Means we can only receive traffic from our neighbour, we can not send traffic to it TXONLY - Means we do not receive traffic from our neighbour, but can send traffic to it.- Parameters:
i- index in neighbors- Returns:
- direction of traffic
-
isNeighbourMutual
public boolean isNeighbourMutual(int i)
Is our neighbouring block at index i a mutual neighbour, ie both blocks have each other registered as neighbours and are exchanging information.- Parameters:
i- index of neighbor- Returns:
- true if both are mutual neighbors
-
getNeighbourIndex
int getNeighbourIndex(jmri.jmrit.display.layoutEditor.LayoutBlock.Adjacencies adj)
-
getNumberOfRoutes
public int getNumberOfRoutes()
Get the number of routes that the block has registered.- Returns:
- count of routes
-
getRouteDirectionAtIndex
public int getRouteDirectionAtIndex(int i)
Get the direction of route i.- Parameters:
i- index in routes- Returns:
- direction
-
getRouteDestBlockAtIndex
public Block getRouteDestBlockAtIndex(int i)
Get the destination block at route i- Parameters:
i- index in routes- Returns:
- dest block from route
-
getRouteNextBlockAtIndex
public Block getRouteNextBlockAtIndex(int i)
Get the next block at route i- Parameters:
i- index in routes- Returns:
- next block from route
-
getRouteHopCountAtIndex
public int getRouteHopCountAtIndex(int i)
Get the hop count of route i.
The Hop count is the number of other blocks that we traverse to get to the destination- Parameters:
i- index in routes- Returns:
- hop count
-
getRouteLengthAtIndex
public float getRouteLengthAtIndex(int i)
Get the length of route i.
The length is the combined length of all the blocks that we traverse to get to the destination- Parameters:
i- index in routes- Returns:
- length of block in route
-
getRouteMetric
public int getRouteMetric(int i)
Get the metric/cost at route i- Parameters:
i- index in routes- Returns:
- metric
-
getRouteState
public int getRouteState(int i)
Get the state (Occupied, unoccupied) of the destination layout block at index i- Parameters:
i- index in routes- Returns:
- state of block
-
getRouteValid
public boolean getRouteValid(int i)
Is the route to the destination potentially valid from our block.- Parameters:
i- index in route- Returns:
- true if route is valid
-
getRouteStateAsString
public java.lang.String getRouteStateAsString(int i)
Get the state of the destination layout block at index i as a string.- Parameters:
i- index in routes- Returns:
- dest status
-
getRouteIndex
int getRouteIndex(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes r)
-
getBlockHopCount
public int getBlockHopCount(Block destination, Block nextBlock)
Get the number of layout blocks to our destintation block going from the next directly connected block. If the destination block and nextblock are the same and the block is also registered as a neighbour then 1 is returned. If no valid route to the destination block can be found via the next block then -1 is returned. If more than one route exists to the destination then the route with the lowest count is returned.- Parameters:
destination- final blocknextBlock- adjcent block- Returns:
- hop count to final, -1 if not available
-
getBlockMetric
public int getBlockMetric(Block destination, Block nextBlock)
Get the metric to our desintation block going from the next directly connected block. If the destination block and nextblock are the same and the block is also registered as a neighbour then 1 is returned. If no valid route to the destination block can be found via the next block then -1 is returned. If more than one route exists to the destination then the route with the lowest count is returned.- Parameters:
destination- final blocknextBlock- adjcent block- Returns:
- metric to final block, -1 if not available
-
getBlockLength
public float getBlockLength(Block destination, Block nextBlock)
Get the distance to our desintation block going from the next directly connected block. If the destination block and nextblock are the same and the block is also registered as a neighbour then 1 is returned. If no valid route to the destination block can be found via the next block then -1 is returned. If more than one route exists to the destination then the route with the lowest count is returned.- Parameters:
destination- final blocknextBlock- adjcent block- Returns:
- length to final, -1 if not viable
-
getNumberOfThroughPaths
public int getNumberOfThroughPaths()
Get the number of valid through paths on this block.- Returns:
- count of paths through this block
-
getThroughPathSource
public Block getThroughPathSource(int i)
Get the source block at index i- Parameters:
i- index in throughPaths- Returns:
- source block
-
getThroughPathDestination
public Block getThroughPathDestination(int i)
Get the destination block at index i- Parameters:
i- index in throughPaths- Returns:
- final block
-
isThroughPathActive
public java.lang.Boolean isThroughPathActive(int i)
Is the through path at index i active?- Parameters:
i- index in path- Returns:
- active or not
-
getThroughPathSourceByDestination
@Nonnull java.util.List<Block> getThroughPathSourceByDestination(Block dest)
-
getThroughPathDestinationBySource
@Nonnull java.util.List<Block> getThroughPathDestinationBySource(Block source)
-
checkIsRouteOnValidThroughPath
boolean checkIsRouteOnValidThroughPath(jmri.jmrit.display.layoutEditor.LayoutBlock.Routes r)
When a route is created, check to see if the through path that this route relates to is active.- Parameters:
r- The route to check- Returns:
- true if that route is active
-
refreshValidRoutes
public void refreshValidRoutes()
Go through all the routes and refresh the valid flag.
-
setRoutesValid
void setRoutesValid(Block nxtHopActive, boolean state)
Set the valid flag for routes that are on a valid through path.- Parameters:
nxtHopActive- the start of the routestate- the state to set into the valid flag
-
vetoableChange
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException
Description copied from class:AbstractNamedBean- Specified by:
vetoableChangein interfaceNamedBean- Overrides:
vetoableChangein classAbstractNamedBean- Throws:
java.beans.PropertyVetoException
-
getUsageReport
public java.util.List<NamedBeanUsageReport> getUsageReport(NamedBean bean)
Description copied from interface:NamedBeanGet a list of references for the specified bean.- Specified by:
getUsageReportin interfaceNamedBean- Parameters:
bean- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
getBeanType
public java.lang.String getBeanType()
Description copied from interface:NamedBeanFor 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:
getBeanTypein interfaceNamedBean- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
-