jmri
Class Block

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.Block
All Implemented Interfaces:
Serializable, NamedBean

public class Block
extends AbstractNamedBean

Represents a particular piece of track, more informally a "Block". As trains move around the layout, a set of Block objects interact to keep track of which train is where, going in which direction. As a result of this, the set of Block objects pass around "token" (value) Objects representing the trains. This could be e.g. a Throttle to control the train, or something else.

A Block (at least in this implementation) corresponds exactly to the track covered by a single sensor. That should be generalized in the future.

Objects of this class are Named Beans, so can be manipulated through tables, have listeners, etc.

There is no functional requirement for a type letter in the System Name, but by convention we use 'B' for 'Block'. The default implementation is not system-specific, so a system letter of 'I' is appropriate. This leads to system names like "IB201".

The direction of a Block is set from the direction of the incoming train. When a train is found to be coming in on a particular Path, that Path's getFromBlockDirection becomes the direction of the train in this Block.

Issues:

Do not assume that a Block object uniquely represents a piece of track. To allow independent development, it must be possible for multiple Block objects to take care of a particular section of track.

Possible state values:

Possible Curvature attributes (optional) User can set the curvature if desired. For use in automatic running of trains, to indicate where slow down is required.

The length of the block may also optionally be entered if desired. This attribute is for use in automatic running of trains. Length should be the actual length of model railroad track in the block. It is always stored here in millimeter units. A length of 0.0 indicates no entry of length by the user.

Author:
Bob Jacobsen Copyright (C) 2006, 2008, Dave Duchamp Copywright (C) 2009
See Also:
Serialized Form

Field Summary
static int GRADUAL
           
static int NONE
           
static int OCCUPIED
           
static int SEVERE
           
static int TIGHT
           
static int UNOCCUPIED
           
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT, UNKNOWN
 
Constructor Summary
Block(String systemName)
           
Block(String systemName, String userName)
           
 
Method Summary
 void addPath(Path p)
           
 int getCurvature()
           
 int getDirection()
           
 float getLengthCm()
           
 float getLengthIn()
           
 float getLengthMm()
           
 List<Path> getPaths()
          Get a copy of the list of Paths
 Sensor getSensor()
           
 int getState()
          Provide generic access to internal state.
 Object getValue()
           
 void removePath(Path p)
           
 void setCurvature(int c)
           
 void setDirection(int direction)
           
 void setLength(float l)
           
 void setSensor(Sensor sensor)
           
 void setState(int v)
          Provide a general method for updating the report.
 void setValue(Object value)
          Set the value retained by this Block.
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, dispose, firePropertyChange, getComment, getNumPropertyChangeListeners, getSystemName, getUserName, removePropertyChangeListener, setComment, setUserName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OCCUPIED

public static final int OCCUPIED
See Also:
Constant Field Values

UNOCCUPIED

public static final int UNOCCUPIED
See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

GRADUAL

public static final int GRADUAL
See Also:
Constant Field Values

TIGHT

public static final int TIGHT
See Also:
Constant Field Values

SEVERE

public static final int SEVERE
See Also:
Constant Field Values
Constructor Detail

Block

public Block(String systemName)

Block

public Block(String systemName,
             String userName)
Method Detail

setSensor

public void setSensor(Sensor sensor)

getSensor

public Sensor getSensor()

getState

public int getState()
Description copied from interface: NamedBean
Provide 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 provided to make Jython script access easier to read.


addPath

public void addPath(Path p)

removePath

public void removePath(Path p)

getPaths

public List<Path> getPaths()
Get a copy of the list of Paths


setState

public void setState(int v)
Provide a general method for updating the report.


setValue

public void setValue(Object value)
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.

Parameters:
value - The new Object resident in this block, or null if none.

getValue

public Object getValue()

setDirection

public void setDirection(int direction)

getDirection

public int getDirection()

setCurvature

public void setCurvature(int c)

getCurvature

public int getCurvature()

setLength

public void setLength(float l)

getLengthMm

public float getLengthMm()

getLengthCm

public float getLengthCm()

getLengthIn

public float getLengthIn()


Copyright © 1997 - 2009 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads