Class OBlock
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.Block
-
- jmri.jmrit.logix.OBlock
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.lang.Comparable<NamedBean>
,java.util.EventListener
,PropertyChangeProvider
,NamedBean
,PhysicalLocationReporter
public class OBlock extends Block implements java.beans.PropertyChangeListener
OBlock extends jmri.Block to be used in Logix Conditionals and Warrants. It is the smallest piece of track that can have occupancy detection. A better name would be Detection Circuit. However, an OBlock can be defined without an occupancy sensor and used to calculate routes.Additional states are defined to indicate status of the track and trains to control panels. A jmri.Block has a PropertyChangeListener on the occupancy sensor and the OBlock will pass state changes of the occ.sensor on to its Warrant.
Entrances (exits when train moves in opposite direction) to OBlocks have Portals. A Portal object is a pair of OBlocks. Each OBlock has a list of its Portals.
When an OBlock (Detection Circuit) has a Portal whose entrance to the OBlock has a signal, then the OBlock and its chains of adjacent OBlocks up to the next OBlock having an entrance Portal with a signal, can be considered a "Block" in the sense of a prototypical railroad. Preferably all entrances to the "Block" should have entrance Portals with a signal.
A Portal has a list of paths (OPath objects) for each OBlock it separates. The paths are determined by the turnout settings of the turnouts contained in the block. Paths are contained within the Block boundaries. Names of OPath objects only need be unique within an OBlock.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OBlock.OBlockStatus
-
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.PhysicalLocationReporter
PhysicalLocationReporter.Direction
-
-
Field Summary
Fields Modifier and Type Field Description protected long
_entryTime
static int
ALLOCATED
static int
OUT_OF_SERVICE
static int
RUNNING
static int
TRACK_ERROR
-
Fields inherited from class jmri.Block
BLOCK_CURVATURE_CHANGE, BLOCK_LENGTH_CHANGE, BLOCK_PERMISSIVE_CHANGE, BLOCK_REPORTER_CHANGE, BLOCK_REPORTING_CURRENT, BLOCK_SPEED_CHANGE, GRADUAL, NONE, OCC_SENSOR_CHANGE, OCCUPIED, SEVERE, TIGHT, UNDETECTED, UNOCCUPIED
-
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addPath(OPath path)
Enforce unique path names within OBlock, but allow a duplicate name of an OPath from another OBlock to be checked if it is in one of the OBlock's Portals.void
addPortal(Portal portal)
Enforce unique portal names.java.lang.String
allocate(Warrant warrant)
Allocate (reserves) the block for the Warrant Note the block may be OCCUPIED by a non-warranted train, but the allocation is permitted.java.lang.String
allocatePath(java.lang.String pathName)
Note path name may be set if block is not allocated to a warrant.boolean
deAllocate(Warrant warrant)
Remove allocation state // maybe restore this?void
dispose()
Deactivate this object, so that it releases as many resources as possible and no longer effects others.boolean
equals(java.lang.Object obj)
Note: this has to make choices about identity values (always the same) and operation values (can change as the block works).java.lang.String
getAllocatedPathName()
java.lang.String
getAllocatingWarrantName()
java.lang.String
getBeanType()
For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.java.lang.String
getDescription()
Sensor
getErrorSensor()
static java.lang.String
getLocalStatusName(java.lang.String str)
java.awt.Color
getMarkerBackground()
java.awt.Font
getMarkerFont()
java.awt.Color
getMarkerForeground()
NamedBeanHandle<Sensor>
getNamedErrorSensor()
protected OPath
getPath()
OPath
getPathByName(java.lang.String name)
Portal
getPortalByName(java.lang.String name)
java.util.List<Portal>
getPortals()
static java.lang.String
getSystemStatusName(java.lang.String str)
java.util.List<NamedBeanUsageReport>
getUsageReport(NamedBean bean)
Get a list of references for the specified bean.Warrant
getWarrant()
void
goingActive()
(Override) Handles Block sensor going ACTIVE: this block is now occupied, figure out from who and copy their value.void
goingInactive()
(Override) Handles Block sensor going INACTIVE: this block is empty.void
goingInconsistent()
void
goingUnknown()
int
hashCode()
boolean
isAllocatedTo(Warrant warrant)
boolean
isDark()
boolean
isFree()
Test that block is not occupied and not allocatedboolean
isMetric()
boolean
isOccupied()
protected java.lang.String
isPathSet(java.lang.String path)
Another block sharing a turnout with this block queries whether turnout is in use.java.lang.String
occupiedBy()
void
propertyChange(java.beans.PropertyChangeEvent evt)
void
pseudoPropertyChange(java.lang.String propName, java.lang.Object old, java.lang.Object n)
boolean
removeOPath(OPath path)
protected void
removePortal(Portal portal)
Remove portal from OBlock and stub all paths using this portal to be dead end spurs.void
setError(boolean set)
boolean
setErrorSensor(java.lang.String pName)
void
setLength(float len)
Set length in millimeters.void
setMarkerBackground(java.awt.Color c)
void
setMarkerFont(java.awt.Font f)
void
setMarkerForeground(java.awt.Color c)
void
setMetricUnits(boolean type)
void
setNamedSensor(NamedBeanHandle<Sensor> namedSensor)
Set Block Occupancy Sensor.void
setOutOfService(boolean set)
protected java.lang.String
setPath(java.lang.String pathName, Warrant warrant)
Set Turnouts for the path.void
setPortals(java.util.ArrayList<Portal> portals)
boolean
setSensor(java.lang.String pName)
Set the sensor by name.void
setState(int v)
Update the OBlock status.void
setValue(java.lang.Object o)
Set the value retained by this Block.protected void
showAllocated(Warrant warrant, java.lang.String pathName)
boolean
statusIs(java.lang.String statusName)
-
Methods inherited from class jmri.Block
addBlockDenyList, addBlockDenyList, addPath, findFromPath, getBlockSpeed, getCurvature, getDeniedBlocks, getDirection, getDirection, getLengthCm, getLengthIn, getLengthMm, getLocoAddress, getNamedSensor, getPaths, getPermissiveWorking, getPhysicalLocation, getPhysicalLocation, getReporter, getSensor, getSpeedLimit, getState, getValue, hasPath, isBlockDenied, isBlockDenied, isReportingCurrent, removeBlockDenyList, removeBlockDenyList, removePath, setAllocated, setBlockSpeed, setBlockSpeedName, setCurvature, setDirection, setPermissiveWorking, setReporter, setReportingCurrent, toDebugString, vetoableChange
-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef
-
-
-
-
Field Detail
-
ALLOCATED
public static final int ALLOCATED
- See Also:
- Constant Field Values
-
RUNNING
public static final int RUNNING
- See Also:
- Constant Field Values
-
OUT_OF_SERVICE
public static final int OUT_OF_SERVICE
- See Also:
- Constant Field Values
-
TRACK_ERROR
public static final int TRACK_ERROR
- See Also:
- Constant Field Values
-
_entryTime
protected long _entryTime
-
-
Method Detail
-
getLocalStatusName
public static java.lang.String getLocalStatusName(java.lang.String str)
-
getSystemStatusName
public static java.lang.String getSystemStatusName(java.lang.String str)
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:Block
Note: this has to make choices about identity values (always the same) and operation values (can change as the block works). Might be missing some identity values.
-
hashCode
public int hashCode()
Description copied from class:AbstractNamedBean
-
setSensor
public boolean setSensor(java.lang.String pName)
Set the sensor by name. Fires propertyChange "OccupancySensorChange" when changed.Override to only set an existing sensor and to amend state with not UNDETECTED return true if an existing Sensor is set or sensor is to be removed from block.
-
setNamedSensor
public void setNamedSensor(NamedBeanHandle<Sensor> namedSensor)
Description copied from class:Block
Set Block Occupancy Sensor. If Sensor set, Adds PCL, sets Block Occupancy Status to Sensor. Block State PropertyChange Event will fire. Does NOT route initial Sensor Status via goingUnknown() / goingActive() etc.If Sensor null, removes PCL on previous Sensor, sets Block status to UNDETECTED.
- Overrides:
setNamedSensor
in classBlock
- Parameters:
namedSensor
- Handle for Sensor.
-
setErrorSensor
public boolean setErrorSensor(java.lang.String pName)
- Parameters:
pName
- name of error sensor- Returns:
- true if successful
-
getErrorSensor
public Sensor getErrorSensor()
-
getNamedErrorSensor
public NamedBeanHandle<Sensor> getNamedErrorSensor()
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
isPathSet
protected java.lang.String isPathSet(@Nonnull java.lang.String path)
Another block sharing a turnout with this block queries whether turnout is in use.- Parameters:
path
- that uses a common shared turnout- Returns:
- If warrant exists and path==pathname, return warrant display name, else null.
-
getWarrant
public Warrant getWarrant()
-
isAllocatedTo
public boolean isAllocatedTo(Warrant warrant)
-
getAllocatedPathName
public java.lang.String getAllocatedPathName()
-
setMetricUnits
public void setMetricUnits(boolean type)
-
isMetric
public boolean isMetric()
-
setMarkerForeground
public void setMarkerForeground(java.awt.Color c)
-
getMarkerForeground
public java.awt.Color getMarkerForeground()
-
setMarkerBackground
public void setMarkerBackground(java.awt.Color c)
-
getMarkerBackground
public java.awt.Color getMarkerBackground()
-
setMarkerFont
public void setMarkerFont(java.awt.Font f)
-
getMarkerFont
public java.awt.Font getMarkerFont()
-
setState
public void setState(int v)
Update the OBlock status. Override Block because change must come from an OBlock for Web Server to receive it
-
setValue
public void setValue(java.lang.Object o)
Set the value retained by this Block. Also used when the Block itself gathers a value from an adjacent Block. This can be overridden in a subclass if e.g. you want to keep track of Blocks elsewhere, but make sure you also eventually invoke the super.setValue() here. Fires propertyChange "value" when changed.
-
statusIs
public boolean statusIs(java.lang.String statusName)
-
isDark
public boolean isDark()
-
isOccupied
public boolean isOccupied()
-
occupiedBy
public java.lang.String occupiedBy()
-
isFree
public boolean isFree()
Test that block is not occupied and not allocated- Returns:
- true if not occupied and not allocated
-
allocate
@CheckForNull public java.lang.String allocate(Warrant warrant)
Allocate (reserves) the block for the Warrant Note the block may be OCCUPIED by a non-warranted train, but the allocation is permitted.- Parameters:
warrant
- the Warrant- Returns:
- message with if block is already allocated to another warrant or block is OUT_OF_SERVICE
-
showAllocated
protected void showAllocated(Warrant warrant, java.lang.String pathName)
-
allocatePath
@CheckForNull public java.lang.String allocatePath(java.lang.String pathName)
Note path name may be set if block is not allocated to a warrant. For use by CircuitBuilder Only. (test paths for editCircuitPaths)- Parameters:
pathName
- name of a path- Returns:
- error message, otherwise null
-
getAllocatingWarrantName
public java.lang.String getAllocatingWarrantName()
-
deAllocate
public boolean deAllocate(Warrant warrant)
Remove allocation state // maybe restore this? Remove listener regardless of ownership- Parameters:
warrant
- warrant that has reserved this block. null is allowed for Conditionals and CircuitBuilder to reset the block. Otherwise, null should not be used.- Returns:
- true if warrant deallocated.
-
setOutOfService
public void setOutOfService(boolean set)
-
setError
public void setError(boolean set)
-
addPortal
public void addPortal(Portal portal)
Enforce unique portal names. Portals are now managed beans since 2014. This enforces unique names.- Parameters:
portal
- the Portal to add
-
removePortal
protected void removePortal(@CheckForNull Portal portal)
Remove portal from OBlock and stub all paths using this portal to be dead end spurs.- Parameters:
portal
- the Portal to remove
-
getPortalByName
public Portal getPortalByName(java.lang.String name)
-
getPortals
@Nonnull public java.util.List<Portal> getPortals()
-
setPortals
public void setPortals(java.util.ArrayList<Portal> portals)
-
getPathByName
public OPath getPathByName(java.lang.String name)
-
setLength
public void setLength(float len)
Description copied from class:Block
Set length in millimeters. Paths will inherit this length, if their length is not specifically set. This length is the maximum length of any Path in the block. Path lengths exceeding this will be set to the default length.Fires propertyChange "BlockLengthChange" when changed, float values in mm.
-
addPath
public boolean addPath(OPath path)
Enforce unique path names within OBlock, but allow a duplicate name of an OPath from another OBlock to be checked if it is in one of the OBlock's Portals.- Parameters:
path
- the OPath to add- Returns:
- true if path was added to OBlock
-
removeOPath
public boolean removeOPath(OPath path)
-
setPath
protected java.lang.String setPath(java.lang.String pathName, Warrant warrant)
Set Turnouts for the path.Called by warrants to set turnouts for a train it is able to run. The warrant parameter verifies that the block is indeed allocated to the warrant. If the block is unwarranted then the block is allocated to the calling warrant. A logix conditional may also call this method with a null warrant parameter for manual logix control. If the block is under a different warrant the call will be rejected.
- Parameters:
pathName
- name of the pathwarrant
- warrant the block is allocated to- Returns:
- error message if the call fails. null if the call succeeds
-
pseudoPropertyChange
public void pseudoPropertyChange(java.lang.String propName, java.lang.Object old, java.lang.Object n)
-
goingInactive
public void goingInactive()
(Override) Handles Block sensor going INACTIVE: this block is empty. Called by handleSensorChange- Overrides:
goingInactive
in classBlock
-
goingActive
public void goingActive()
(Override) Handles Block sensor going ACTIVE: this block is now occupied, figure out from who and copy their value. Called by handleSensorChange- Overrides:
goingActive
in classBlock
-
goingUnknown
public void goingUnknown()
- Overrides:
goingUnknown
in classBlock
-
goingInconsistent
public void goingInconsistent()
- Overrides:
goingInconsistent
in classBlock
-
dispose
public void dispose()
Description copied from class:AbstractNamedBean
Deactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
- Specified by:
dispose
in interfaceNamedBean
- Overrides:
dispose
in classAbstractNamedBean
-
getDescription
public java.lang.String getDescription()
-
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
- Overrides:
getUsageReport
in classBlock
- Parameters:
bean
- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
getBeanType
@Nonnull 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
- Overrides:
getBeanType
in classBlock
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
-