Class DefaultSection
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.DefaultSection
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>
,PropertyChangeProvider
,NamedBean
,Section
public class DefaultSection extends AbstractNamedBean implements Section
Sections represent a group of one or more connected Blocks that may be allocated to a train traveling in a given direction.A Block may be in multiple Sections. All Blocks contained in a given section must be unique. Blocks are kept in order--the first block is connected to the second, the second is connected to the third, etc.
A Block in a Section must be connected to the Block before it (if there is one) and to the Block after it (if there is one), but may not be connected to any other Block in the Section. This restriction is enforced when a Section is created, and checked when a Section is loaded from disk.
A Section has a "direction" defined by the sequence in which Blocks are added to the Section. A train may run through a Section in either the forward direction (from first block to last block) or reverse direction (from last block to first block).
A Section has one or more EntryPoints. Each EntryPoint is a Path of one of the Blocks in the Section that defines a connection to a Block outside of the Section. EntryPoints are grouped into two lists: "forwardEntryPoints" - entry through which will result in a train traveling in the "forward" direction "reverseEntryPoints" - entry through which will result in a train traveling in the "reverse" direction Note that "forwardEntryPoints" are also reverse exit points, and vice versa.
A Section has one of the following states" FREE - available for allocation by a dispatcher FORWARD - allocated for travel in the forward direction REVERSE - allocated for travel in the reverse direction
A Section has an occupancy. A Section is OCCUPIED if any of its Blocks is OCCUPIED. A Section is UNOCCUPIED if all of its Blocks are UNOCCUPIED
A Section of may be allocated to only one train at a time, even if the trains are travelling in the same direction. If a Section has sufficient space for multiple trains travelling in the same direction it should be broken up into multiple Sections so the trains can follow each other through the original Section.
A Section may not contain any reverse loops. The track that is reversed in a reverse loop must be in a separate Section.
Each Section optionally carries two direction sensors, one for the forward direction and one for the reverse direction. These sensors force signals for travel in their respective directions to "RED" when they are active. When the Section is free, both the sensors are Active. These internal sensors follow the state of the Section, permitting signals to function normally in the direction of allocation.
Each Section optionally carries two stopping sensors, one for the forward direction and one for the reverse direction. These sensors change to active when a train traversing the Section triggers its sensing device. Stopping sensors are physical layout sensors, and may be either point sensors or occupancy sensors for short blocks at the end of the Section. A stopping sensor is used during automatic running to stop a train that has reached the end of its allocated Section. This is needed, for example, to allow a train to enter a passing siding and clear the track behind it. When not running automatically, these sensors may be used to light panel lights to notify the dispatcher that the train has reached the end of the Section.
This Section implementation provides for delayed initialization of blocks and direction sensors to be independent of order of items in panel files.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
Nested classes/interfaces inherited from interface jmri.Section
Section.SectionType
-
-
Field Summary
Fields Modifier and Type Field Description protected NamedBeanHandleManager
nbhm
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
Fields inherited from interface jmri.Section
DYNAMICADHOC, FORWARD, FREE, OCCUPIED, REVERSE, SIGNALMASTLOGIC, UNOCCUPIED, USERDEFINED
-
-
Constructor Summary
Constructors Constructor Description DefaultSection(java.lang.String systemName)
DefaultSection(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addBlock(Block b)
Add a Block to the Section.void
addToForwardList(EntryPoint ep)
void
addToReverseList(EntryPoint ep)
void
clearNameInUnoccupiedBlocks()
Clear the block values for blocks in this Section.boolean
connectsToBlock(Block b)
boolean
containsBlock(Block b)
void
delayedAddBlock(java.lang.String blockName)
void
delayedSetForwardBlockingSensorName(java.lang.String forwardSensor)
void
delayedSetForwardStoppingSensorName(java.lang.String forwardSensor)
void
delayedSetReverseBlockingSensorName(java.lang.String reverseSensor)
void
delayedSetReverseStoppingSensorName(java.lang.String reverseSensor)
int
getActualLength()
Gets the actual length of the Section without any scalingjava.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.java.lang.String
getBeginBlockName()
Block
getBlockBySequenceNumber(int seqNumber)
Get Block by its Sequence number in the Section.java.util.List<Block>
getBlockList()
Get a list of blocks in this sectionint
getBlockSequenceNumber(Block b)
Get the sequence number of a Block.java.lang.String
getEndBlockName()
Block
getEntryBlock()
EntryPoint
getEntryPointFromBlock(Block b, int dir)
Get the EntryPoint for entry from the specified Block for travel in the specified direction.EntryPoint
getEntryPointFromSection(Section s, int dir)
Get the EntryPoint for entry from the specified Section for travel in specified direction.java.util.List<EntryPoint>
getEntryPointList()
Block
getExitBlock()
EntryPoint
getExitPointToBlock(Block b, int dir)
Get the EntryPoint for exit to the specified Block for travel in the specified direction.EntryPoint
getExitPointToSection(Section s, int dir)
Get the EntryPoint for exit to specified Section for travel in the specified direction.Sensor
getForwardBlockingSensor()
java.lang.String
getForwardBlockingSensorName()
java.util.List<EntryPoint>
getForwardEntryPointList()
Sensor
getForwardStoppingSensor()
java.lang.String
getForwardStoppingSensorName()
Block
getLastBlock()
float
getLengthF(boolean meters, Scale scale)
Get the scale length of Section.int
getLengthI(boolean meters, Scale scale)
Block
getNextBlock()
int
getNumBlocks()
Gets the number of Blocks in this Sectionint
getOccupancy()
Get the occupancy of a Section.Sensor
getReverseBlockingSensor()
java.lang.String
getReverseBlockingSensorName()
java.util.List<EntryPoint>
getReverseEntryPointList()
Sensor
getReverseStoppingSensor()
java.lang.String
getReverseStoppingSensorName()
Section.SectionType
getSectionType()
Get Section Type.int
getState()
Get the state of the Section.java.util.List<NamedBeanUsageReport>
getUsageReport(NamedBean bean)
Get a list of references for the specified bean.(package private) void
handleBlockChange(java.beans.PropertyChangeEvent e)
Handle change in occupancy of a Block in the Section.boolean
isForwardEntryPoint(EntryPoint ep)
boolean
isReverseEntryPoint(EntryPoint ep)
int
placeDirectionSensors()
Place direction sensors in SSL for all Signal Heads in this Section if the Sensors are not already present in the SSL.void
removeAllBlocksFromSection()
Remove all Blocks, Block Listeners, and Entry Pointsvoid
removeEntryPoint(EntryPoint ep)
void
setAlternateColor(boolean set)
Set/reset the display to use alternate color for unoccupied blocks in this section.void
setAlternateColorFromActiveBlock(boolean set)
Set/reset the display to use alternate color for unoccupied blocks in this Section.Sensor
setForwardBlockingSensorName(java.lang.String forwardSensor)
Sensor
setForwardStoppingSensorName(java.lang.String forwardSensor)
void
setNameFromActiveBlock(java.lang.Object value)
void
setNameInBlocks(java.lang.Object value)
Set the block values for blocks in this Section.void
setNameInBlocks(java.lang.String name)
Set the block values for blocks in this Section.Sensor
setReverseBlockingSensorName(java.lang.String reverseSensor)
Sensor
setReverseStoppingSensorName(java.lang.String reverseSensor)
void
setSectionType(Section.SectionType type)
Set Section Type.void
setState(int state)
Set the state of the Section.void
suppressNameUpdate(boolean set)
Suppress the update of a memory variable when a block goes to unoccupied, so the text set above doesn't get wiped out.java.lang.String
validate()
Validate the Section.void
vetoableChange(java.beans.PropertyChangeEvent evt)
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, 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
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, dispose, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
nbhm
protected NamedBeanHandleManager nbhm
-
-
Constructor Detail
-
DefaultSection
public DefaultSection(java.lang.String systemName, java.lang.String userName)
-
DefaultSection
public DefaultSection(java.lang.String systemName)
-
-
Method Detail
-
getState
public int getState()
Get the state of the Section. UNKNOWN, FORWARD, REVERSE, FREE
-
setState
public void setState(int state)
Set the state of the Section. FREE, FORWARD or REVERSE.
UNKNOWN state not accepted here.
-
getOccupancy
public int getOccupancy()
Get the occupancy of a Section.- Specified by:
getOccupancy
in interfaceSection
- Returns:
Section.OCCUPIED
,Section.UNOCCUPIED
, or the state of the first block that is neither occupied or unoccupied
-
getForwardBlockingSensorName
public java.lang.String getForwardBlockingSensorName()
- Specified by:
getForwardBlockingSensorName
in interfaceSection
-
getForwardBlockingSensor
public Sensor getForwardBlockingSensor()
- Specified by:
getForwardBlockingSensor
in interfaceSection
-
setForwardBlockingSensorName
public Sensor setForwardBlockingSensorName(java.lang.String forwardSensor)
- Specified by:
setForwardBlockingSensorName
in interfaceSection
-
delayedSetForwardBlockingSensorName
public void delayedSetForwardBlockingSensorName(java.lang.String forwardSensor)
- Specified by:
delayedSetForwardBlockingSensorName
in interfaceSection
-
getReverseBlockingSensorName
public java.lang.String getReverseBlockingSensorName()
- Specified by:
getReverseBlockingSensorName
in interfaceSection
-
setReverseBlockingSensorName
public Sensor setReverseBlockingSensorName(java.lang.String reverseSensor)
- Specified by:
setReverseBlockingSensorName
in interfaceSection
-
delayedSetReverseBlockingSensorName
public void delayedSetReverseBlockingSensorName(java.lang.String reverseSensor)
- Specified by:
delayedSetReverseBlockingSensorName
in interfaceSection
-
getReverseBlockingSensor
public Sensor getReverseBlockingSensor()
- Specified by:
getReverseBlockingSensor
in interfaceSection
-
getLastBlock
public Block getLastBlock()
- Specified by:
getLastBlock
in interfaceSection
-
getForwardStoppingSensorName
public java.lang.String getForwardStoppingSensorName()
- Specified by:
getForwardStoppingSensorName
in interfaceSection
-
getForwardStoppingSensor
@CheckForNull public Sensor getForwardStoppingSensor()
- Specified by:
getForwardStoppingSensor
in interfaceSection
-
setForwardStoppingSensorName
public Sensor setForwardStoppingSensorName(java.lang.String forwardSensor)
- Specified by:
setForwardStoppingSensorName
in interfaceSection
-
delayedSetForwardStoppingSensorName
public void delayedSetForwardStoppingSensorName(java.lang.String forwardSensor)
- Specified by:
delayedSetForwardStoppingSensorName
in interfaceSection
-
getReverseStoppingSensorName
public java.lang.String getReverseStoppingSensorName()
- Specified by:
getReverseStoppingSensorName
in interfaceSection
-
setReverseStoppingSensorName
@CheckForNull public Sensor setReverseStoppingSensorName(java.lang.String reverseSensor)
- Specified by:
setReverseStoppingSensorName
in interfaceSection
-
delayedSetReverseStoppingSensorName
public void delayedSetReverseStoppingSensorName(java.lang.String reverseSensor)
- Specified by:
delayedSetReverseStoppingSensorName
in interfaceSection
-
getReverseStoppingSensor
@CheckForNull public Sensor getReverseStoppingSensor()
- Specified by:
getReverseStoppingSensor
in interfaceSection
-
addBlock
public boolean addBlock(Block b)
Add a Block to the Section. Block and sequence number must be unique within the Section. Block sequence numbers are set automatically as blocks are added.
-
delayedAddBlock
public void delayedAddBlock(java.lang.String blockName)
- Specified by:
delayedAddBlock
in interfaceSection
-
handleBlockChange
void handleBlockChange(java.beans.PropertyChangeEvent e)
Handle change in occupancy of a Block in the Section.- Parameters:
e
- event with change
-
getBlockList
@Nonnull public java.util.List<Block> getBlockList()
Get a list of blocks in this section- Specified by:
getBlockList
in interfaceSection
- Returns:
- a list of blocks
-
getNumBlocks
public int getNumBlocks()
Gets the number of Blocks in this Section- Specified by:
getNumBlocks
in interfaceSection
- Returns:
- the number of blocks
-
getLengthF
public float getLengthF(boolean meters, Scale scale)
Get the scale length of Section. Length of the Section is calculated by summing the lengths of all Blocks in the section. If all Block lengths have not been entered, length will not be correct.- Specified by:
getLengthF
in interfaceSection
- Parameters:
meters
- true to return length in meters, false to use feetscale
- the scale; one ofScale
- Returns:
- the scale length
-
getLengthI
public int getLengthI(boolean meters, Scale scale)
- Specified by:
getLengthI
in interfaceSection
-
getActualLength
public int getActualLength()
Gets the actual length of the Section without any scaling- Specified by:
getActualLength
in interfaceSection
- Returns:
- the real length in millimeters
-
getBlockBySequenceNumber
@CheckForNull public Block getBlockBySequenceNumber(int seqNumber)
Get Block by its Sequence number in the Section.- Specified by:
getBlockBySequenceNumber
in interfaceSection
- Parameters:
seqNumber
- the sequence number- Returns:
- the block or null if the sequence number is invalid
-
getBlockSequenceNumber
public int getBlockSequenceNumber(Block b)
Get the sequence number of a Block.- Specified by:
getBlockSequenceNumber
in interfaceSection
- Parameters:
b
- the block to get the sequence of- Returns:
- the sequence number of b or -1 if b is not in the Section
-
removeAllBlocksFromSection
public void removeAllBlocksFromSection()
Remove all Blocks, Block Listeners, and Entry Points- Specified by:
removeAllBlocksFromSection
in interfaceSection
-
getEntryBlock
@CheckForNull public Block getEntryBlock()
- Specified by:
getEntryBlock
in interfaceSection
-
getNextBlock
@CheckForNull public Block getNextBlock()
- Specified by:
getNextBlock
in interfaceSection
-
getExitBlock
@CheckForNull public Block getExitBlock()
- Specified by:
getExitBlock
in interfaceSection
-
containsBlock
public boolean containsBlock(Block b)
- Specified by:
containsBlock
in interfaceSection
-
connectsToBlock
public boolean connectsToBlock(Block b)
- Specified by:
connectsToBlock
in interfaceSection
-
getBeginBlockName
public java.lang.String getBeginBlockName()
- Specified by:
getBeginBlockName
in interfaceSection
-
getEndBlockName
public java.lang.String getEndBlockName()
- Specified by:
getEndBlockName
in interfaceSection
-
addToForwardList
public void addToForwardList(EntryPoint ep)
- Specified by:
addToForwardList
in interfaceSection
-
addToReverseList
public void addToReverseList(EntryPoint ep)
- Specified by:
addToReverseList
in interfaceSection
-
removeEntryPoint
public void removeEntryPoint(EntryPoint ep)
- Specified by:
removeEntryPoint
in interfaceSection
-
getForwardEntryPointList
public java.util.List<EntryPoint> getForwardEntryPointList()
- Specified by:
getForwardEntryPointList
in interfaceSection
-
getReverseEntryPointList
public java.util.List<EntryPoint> getReverseEntryPointList()
- Specified by:
getReverseEntryPointList
in interfaceSection
-
getEntryPointList
public java.util.List<EntryPoint> getEntryPointList()
- Specified by:
getEntryPointList
in interfaceSection
-
isForwardEntryPoint
public boolean isForwardEntryPoint(EntryPoint ep)
- Specified by:
isForwardEntryPoint
in interfaceSection
-
isReverseEntryPoint
public boolean isReverseEntryPoint(EntryPoint ep)
- Specified by:
isReverseEntryPoint
in interfaceSection
-
getEntryPointFromSection
@CheckForNull public EntryPoint getEntryPointFromSection(Section s, int dir)
Get the EntryPoint for entry from the specified Section for travel in specified direction.- Specified by:
getEntryPointFromSection
in interfaceSection
- Parameters:
s
- the sectiondir
- the direction of travel; one ofSection.FORWARD
orSection.REVERSE
- Returns:
- the entry point or null if not found
-
getExitPointToSection
@CheckForNull public EntryPoint getExitPointToSection(Section s, int dir)
Get the EntryPoint for exit to specified Section for travel in the specified direction.- Specified by:
getExitPointToSection
in interfaceSection
- Parameters:
s
- the sectiondir
- the direction of travel; one ofSection.FORWARD
orSection.REVERSE
- Returns:
- the entry point or null if not found
-
getEntryPointFromBlock
@CheckForNull public EntryPoint getEntryPointFromBlock(Block b, int dir)
Get the EntryPoint for entry from the specified Block for travel in the specified direction.- Specified by:
getEntryPointFromBlock
in interfaceSection
- Parameters:
b
- the blockdir
- the direction of travel; one ofSection.FORWARD
orSection.REVERSE
- Returns:
- the entry point or null if not found
-
getExitPointToBlock
@CheckForNull public EntryPoint getExitPointToBlock(Block b, int dir)
Get the EntryPoint for exit to the specified Block for travel in the specified direction.- Specified by:
getExitPointToBlock
in interfaceSection
- Parameters:
b
- the blockdir
- the direction of travel; one ofSection.FORWARD
orSection.REVERSE
- Returns:
- the entry point or null if not found
-
placeDirectionSensors
public int placeDirectionSensors()
Place direction sensors in SSL for all Signal Heads in this Section if the Sensors are not already present in the SSL.Only anchor point block boundaries that have assigned signals are considered. Only turnouts that have assigned signals are considered. Only level crossings that have assigned signals are considered. Turnouts and anchor points without signals are counted, and reported in warning messages during this procedure, if there are any missing signals.
If this method has trouble, an error message is placed in the log describing the trouble.
- Specified by:
placeDirectionSensors
in interfaceSection
- Returns:
- the number or errors placing sensors; 1 is returned if no direction sensor is defined for this section
-
validate
public java.lang.String validate()
Validate the Section. This checks block connectivity, warns of redundant EntryPoints, and otherwise checks internal consistency of the Section. An appropriate error message is logged if a problem is found. This method assumes that Block Paths are correctly initialized.
-
setAlternateColor
public void setAlternateColor(boolean set)
Set/reset the display to use alternate color for unoccupied blocks in this section. If Layout Editor panel is not present, Layout Blocks will not be present, and nothing will be set.- Specified by:
setAlternateColor
in interfaceSection
- Parameters:
set
- true to use alternate unoccupied color; false otherwise
-
setAlternateColorFromActiveBlock
public void setAlternateColorFromActiveBlock(boolean set)
Set/reset the display to use alternate color for unoccupied blocks in this Section. If the Section already contains an active block, then the alternative color will be set from the active block, if no active block is found or we are clearing the alternative color then all the blocks in the Section will be set. If Layout Editor panel is not present, Layout Blocks will not be present, and nothing will be set.- Specified by:
setAlternateColorFromActiveBlock
in interfaceSection
- Parameters:
set
- true to use alternate unoccupied color; false otherwise
-
setNameInBlocks
public void setNameInBlocks(java.lang.String name)
Set the block values for blocks in this Section.- Specified by:
setNameInBlocks
in interfaceSection
- Parameters:
name
- the value to set all blocks to
-
setNameInBlocks
public void setNameInBlocks(java.lang.Object value)
Set the block values for blocks in this Section.- Specified by:
setNameInBlocks
in interfaceSection
- Parameters:
value
- the name to set block values to
-
setNameFromActiveBlock
public void setNameFromActiveBlock(java.lang.Object value)
- Specified by:
setNameFromActiveBlock
in interfaceSection
-
clearNameInUnoccupiedBlocks
public void clearNameInUnoccupiedBlocks()
Clear the block values for blocks in this Section.- Specified by:
clearNameInUnoccupiedBlocks
in interfaceSection
-
suppressNameUpdate
public void suppressNameUpdate(boolean set)
Suppress the update of a memory variable when a block goes to unoccupied, so the text set above doesn't get wiped out.- Specified by:
suppressNameUpdate
in interfaceSection
- Parameters:
set
- true to suppress the update; false otherwise
-
setSectionType
public void setSectionType(Section.SectionType type)
Set Section Type.- USERDEFINED - Default Save all the information.
- SIGNALMASTLOGIC - Save only the name, blocks will be added by the SignalMast logic.
- DYNAMICADHOC - Created on an as required basis, not to be saved.
- Specified by:
setSectionType
in interfaceSection
- Parameters:
type
- constant of section type.
-
getSectionType
public Section.SectionType getSectionType()
Get Section Type. Defaults to USERDEFINED.- Specified by:
getSectionType
in interfaceSection
- Returns:
- constant of section type.
-
getBeanType
public java.lang.String getBeanType()
Description copied from interface:NamedBean
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 interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
vetoableChange
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException
Description copied from class:AbstractNamedBean
- Specified by:
vetoableChange
in interfaceNamedBean
- Overrides:
vetoableChange
in classAbstractNamedBean
- Throws:
java.beans.PropertyVetoException
-
getUsageReport
public java.util.List<NamedBeanUsageReport> getUsageReport(NamedBean bean)
Description copied from interface:NamedBean
Get a list of references for the specified bean.- Specified by:
getUsageReport
in interfaceNamedBean
- Parameters:
bean
- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
-