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 NamedBeanHandleManagernbhm-
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
-
Fields inherited from interface jmri.Section
DYNAMICADHOC, FORWARD, FREE, OCCUPIED, PROPERTY_OCCUPANCY, 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 booleanaddBlock(Block b)Add a Block to the Section.voidaddToForwardList(EntryPoint ep)voidaddToReverseList(EntryPoint ep)voidclearNameInUnoccupiedBlocks()Clear the block values for blocks in this Section.booleanconnectsToBlock(Block b)booleancontainsBlock(Block b)voiddelayedAddBlock(java.lang.String blockName)voiddelayedSetForwardBlockingSensorName(java.lang.String forwardSensor)voiddelayedSetForwardStoppingSensorName(java.lang.String forwardSensor)voiddelayedSetReverseBlockingSensorName(java.lang.String reverseSensor)voiddelayedSetReverseStoppingSensorName(java.lang.String reverseSensor)intgetActualLength()Gets the actual length of the Section without any scalingjava.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.java.lang.StringgetBeginBlockName()BlockgetBlockBySequenceNumber(int seqNumber)Get Block by its Sequence number in the Section.java.util.List<Block>getBlockList()Get a list of blocks in this sectionintgetBlockSequenceNumber(Block b)Get the sequence number of a Block.java.lang.StringgetEndBlockName()BlockgetEntryBlock()EntryPointgetEntryPointFromBlock(Block b, int dir)Get the EntryPoint for entry from the specified Block for travel in the specified direction.EntryPointgetEntryPointFromSection(Section s, int dir)Get the EntryPoint for entry from the specified Section for travel in specified direction.java.util.List<EntryPoint>getEntryPointList()BlockgetExitBlock()EntryPointgetExitPointToBlock(Block b, int dir)Get the EntryPoint for exit to the specified Block for travel in the specified direction.EntryPointgetExitPointToSection(Section s, int dir)Get the EntryPoint for exit to specified Section for travel in the specified direction.SensorgetForwardBlockingSensor()java.lang.StringgetForwardBlockingSensorName()java.util.List<EntryPoint>getForwardEntryPointList()SensorgetForwardStoppingSensor()java.lang.StringgetForwardStoppingSensorName()BlockgetLastBlock()floatgetLengthF(boolean meters, Scale scale)Get the scale length of Section.intgetLengthI(boolean meters, Scale scale)BlockgetNextBlock()intgetNumBlocks()Gets the number of Blocks in this SectionintgetOccupancy()Get the occupancy of a Section.SensorgetReverseBlockingSensor()java.lang.StringgetReverseBlockingSensorName()java.util.List<EntryPoint>getReverseEntryPointList()SensorgetReverseStoppingSensor()java.lang.StringgetReverseStoppingSensorName()Section.SectionTypegetSectionType()Get Section Type.intgetState()Get the state of the Section.java.util.List<NamedBeanUsageReport>getUsageReport(NamedBean bean)Get a list of references for the specified bean.booleanisForwardEntryPoint(EntryPoint ep)booleanisReverseEntryPoint(EntryPoint ep)intplaceDirectionSensors()Place direction sensors in SSL for all Signal Heads in this Section if the Sensors are not already present in the SSL.voidremoveAllBlocksFromSection()Remove all Blocks, Block Listeners, and Entry PointsvoidremoveEntryPoint(EntryPoint ep)voidsetAlternateColor(boolean set)Set/reset the display to use alternate color for unoccupied blocks in this section.voidsetAlternateColorFromActiveBlock(boolean set)Set/reset the display to use alternate color for unoccupied blocks in this Section.SensorsetForwardBlockingSensorName(java.lang.String forwardSensor)SensorsetForwardStoppingSensorName(java.lang.String forwardSensor)voidsetNameFromActiveBlock(java.lang.Object value)voidsetNameInBlocks(java.lang.Object value)Set the block values for blocks in this Section.voidsetNameInBlocks(java.lang.String name)Set the block values for blocks in this Section.SensorsetReverseBlockingSensorName(java.lang.String reverseSensor)SensorsetReverseStoppingSensorName(java.lang.String reverseSensor)voidsetSectionType(Section.SectionType type)Set Section Type.voidsetState(int state)Set the state of the Section.voidsuppressNameUpdate(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.Stringvalidate()Validate the Section.voidvetoableChange(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:
getOccupancyin 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:
getForwardBlockingSensorNamein interfaceSection
-
getForwardBlockingSensor
public Sensor getForwardBlockingSensor()
- Specified by:
getForwardBlockingSensorin interfaceSection
-
setForwardBlockingSensorName
public Sensor setForwardBlockingSensorName(java.lang.String forwardSensor)
- Specified by:
setForwardBlockingSensorNamein interfaceSection
-
delayedSetForwardBlockingSensorName
public void delayedSetForwardBlockingSensorName(java.lang.String forwardSensor)
- Specified by:
delayedSetForwardBlockingSensorNamein interfaceSection
-
getReverseBlockingSensorName
public java.lang.String getReverseBlockingSensorName()
- Specified by:
getReverseBlockingSensorNamein interfaceSection
-
setReverseBlockingSensorName
public Sensor setReverseBlockingSensorName(java.lang.String reverseSensor)
- Specified by:
setReverseBlockingSensorNamein interfaceSection
-
delayedSetReverseBlockingSensorName
public void delayedSetReverseBlockingSensorName(java.lang.String reverseSensor)
- Specified by:
delayedSetReverseBlockingSensorNamein interfaceSection
-
getReverseBlockingSensor
public Sensor getReverseBlockingSensor()
- Specified by:
getReverseBlockingSensorin interfaceSection
-
getLastBlock
public Block getLastBlock()
- Specified by:
getLastBlockin interfaceSection
-
getForwardStoppingSensorName
public java.lang.String getForwardStoppingSensorName()
- Specified by:
getForwardStoppingSensorNamein interfaceSection
-
getForwardStoppingSensor
@CheckForNull public Sensor getForwardStoppingSensor()
- Specified by:
getForwardStoppingSensorin interfaceSection
-
setForwardStoppingSensorName
public Sensor setForwardStoppingSensorName(java.lang.String forwardSensor)
- Specified by:
setForwardStoppingSensorNamein interfaceSection
-
delayedSetForwardStoppingSensorName
public void delayedSetForwardStoppingSensorName(java.lang.String forwardSensor)
- Specified by:
delayedSetForwardStoppingSensorNamein interfaceSection
-
getReverseStoppingSensorName
public java.lang.String getReverseStoppingSensorName()
- Specified by:
getReverseStoppingSensorNamein interfaceSection
-
setReverseStoppingSensorName
@CheckForNull public Sensor setReverseStoppingSensorName(java.lang.String reverseSensor)
- Specified by:
setReverseStoppingSensorNamein interfaceSection
-
delayedSetReverseStoppingSensorName
public void delayedSetReverseStoppingSensorName(java.lang.String reverseSensor)
- Specified by:
delayedSetReverseStoppingSensorNamein interfaceSection
-
getReverseStoppingSensor
@CheckForNull public Sensor getReverseStoppingSensor()
- Specified by:
getReverseStoppingSensorin 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:
delayedAddBlockin interfaceSection
-
getBlockList
@Nonnull public java.util.List<Block> getBlockList()
Get a list of blocks in this section- Specified by:
getBlockListin interfaceSection- Returns:
- a list of blocks
-
getNumBlocks
public int getNumBlocks()
Gets the number of Blocks in this Section- Specified by:
getNumBlocksin 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:
getLengthFin 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:
getLengthIin interfaceSection
-
getActualLength
public int getActualLength()
Gets the actual length of the Section without any scaling- Specified by:
getActualLengthin 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:
getBlockBySequenceNumberin 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:
getBlockSequenceNumberin 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:
removeAllBlocksFromSectionin interfaceSection
-
getEntryBlock
@CheckForNull public Block getEntryBlock()
- Specified by:
getEntryBlockin interfaceSection
-
getNextBlock
@CheckForNull public Block getNextBlock()
- Specified by:
getNextBlockin interfaceSection
-
getExitBlock
@CheckForNull public Block getExitBlock()
- Specified by:
getExitBlockin interfaceSection
-
containsBlock
public boolean containsBlock(Block b)
- Specified by:
containsBlockin interfaceSection
-
connectsToBlock
public boolean connectsToBlock(Block b)
- Specified by:
connectsToBlockin interfaceSection
-
getBeginBlockName
public java.lang.String getBeginBlockName()
- Specified by:
getBeginBlockNamein interfaceSection
-
getEndBlockName
public java.lang.String getEndBlockName()
- Specified by:
getEndBlockNamein interfaceSection
-
addToForwardList
public void addToForwardList(EntryPoint ep)
- Specified by:
addToForwardListin interfaceSection
-
addToReverseList
public void addToReverseList(EntryPoint ep)
- Specified by:
addToReverseListin interfaceSection
-
removeEntryPoint
public void removeEntryPoint(EntryPoint ep)
- Specified by:
removeEntryPointin interfaceSection
-
getForwardEntryPointList
@Nonnull public java.util.List<EntryPoint> getForwardEntryPointList()
- Specified by:
getForwardEntryPointListin interfaceSection
-
getReverseEntryPointList
@Nonnull public java.util.List<EntryPoint> getReverseEntryPointList()
- Specified by:
getReverseEntryPointListin interfaceSection
-
getEntryPointList
@Nonnull public java.util.List<EntryPoint> getEntryPointList()
- Specified by:
getEntryPointListin interfaceSection
-
isForwardEntryPoint
public boolean isForwardEntryPoint(EntryPoint ep)
- Specified by:
isForwardEntryPointin interfaceSection
-
isReverseEntryPoint
public boolean isReverseEntryPoint(EntryPoint ep)
- Specified by:
isReverseEntryPointin 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:
getEntryPointFromSectionin interfaceSection- Parameters:
s- the sectiondir- the direction of travel; one ofSection.FORWARDorSection.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:
getExitPointToSectionin interfaceSection- Parameters:
s- the sectiondir- the direction of travel; one ofSection.FORWARDorSection.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:
getEntryPointFromBlockin interfaceSection- Parameters:
b- the blockdir- the direction of travel; one ofSection.FORWARDorSection.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:
getExitPointToBlockin interfaceSection- Parameters:
b- the blockdir- the direction of travel; one ofSection.FORWARDorSection.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:
placeDirectionSensorsin 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:
setAlternateColorin 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:
setAlternateColorFromActiveBlockin 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:
setNameInBlocksin 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:
setNameInBlocksin interfaceSection- Parameters:
value- the name to set block values to
-
setNameFromActiveBlock
public void setNameFromActiveBlock(java.lang.Object value)
- Specified by:
setNameFromActiveBlockin interfaceSection
-
clearNameInUnoccupiedBlocks
public void clearNameInUnoccupiedBlocks()
Clear the block values for blocks in this Section.- Specified by:
clearNameInUnoccupiedBlocksin 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:
suppressNameUpdatein 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:
setSectionTypein interfaceSection- Parameters:
type- constant of section type.
-
getSectionType
public Section.SectionType getSectionType()
Get Section Type. Defaults to USERDEFINED.- Specified by:
getSectionTypein interfaceSection- Returns:
- constant of section type.
-
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
-
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.
-
-