Class TrackSegment
- java.lang.Object
-
- jmri.jmrit.display.layoutEditor.LayoutTrack
-
- jmri.jmrit.display.layoutEditor.TrackSegment
-
public class TrackSegment extends LayoutTrack
TrackSegment is a segment of track on a layout linking two nodes of the layout. A node may be a LayoutTurnout, a LevelXing or a PositionablePoint.PositionablePoints have 1 or 2 connection points. LayoutTurnouts have 3 or 4 (crossovers) connection points, designated A, B, C, and D. LevelXing's have 4 connection points, designated A, B, C, and D.
TrackSegments carry the connectivity information between the three types of nodes. Track Segments serve as the lines in a graph which shows layout connectivity. For the connectivity graph to be valid, all connections between nodes must be via TrackSegments.
TrackSegments carry Block information, as do LayoutTurnouts and LevelXings.
Arrows and bumpers are visual, presentation aspects handled in the View.
-
-
Field Summary
Fields Modifier and Type Field Description protected LayoutTrack
connect1
protected LayoutTrack
connect2
java.lang.String
tConnect1Name
java.lang.String
tConnect2Name
java.lang.String
tLayoutBlockName
protected HitPointType
type1
protected HitPointType
type2
-
Fields inherited from class jmri.jmrit.display.layoutEditor.LayoutTrack
models
-
-
Constructor Summary
Constructors Constructor Description TrackSegment(java.lang.String id, java.lang.String c1Name, HitPointType t1, java.lang.String c2Name, HitPointType t2, boolean main, LayoutEditor models)
TrackSegment(java.lang.String id, LayoutTrack c1, HitPointType t1, LayoutTrack c2, HitPointType t2, boolean main, LayoutEditor models)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRemove()
Check for active block boundaries.java.util.List<HitPointType>
checkForFreeConnections()
return a list of the available connections for this layout trackvoid
checkForNonContiguousBlocks(java.util.HashMap<java.lang.String,java.util.List<java.util.Set<java.lang.String>>> blockNamesToTrackNameSetsMap)
check this track and its neighbors for non-contiguous blocksboolean
checkForUnAssignedBlocks()
determine if all the appropriate blocks have been assigned to this trackvoid
collectContiguousTracksNamesInBlockNamed(java.lang.String blockName, java.util.Set<java.lang.String> TrackNameSet)
recursive routine to check for all contiguous tracks in this blockNamejava.lang.String
getBlockName()
LayoutTrack
getConnect1()
java.lang.String
getConnect1Name()
LayoutTrack
getConnect2()
java.lang.String
getConnect2Name()
LayoutTrack
getConnection(HitPointType connectionType)
get the LayoutTrack connected at the specified connection typeLayoutBlock
getLayoutBlock()
protected java.util.List<LayoutConnectivity>
getLayoutConnectivity()
get the layout connectivity for this trackjava.util.ArrayList<java.lang.String>
getPointReferences(HitPointType type, LayoutTrack conn)
HitPointType
getType1()
HitPointType
getType2()
java.lang.String
getTypeName()
Get the type of this item.boolean
isActive()
Get state.boolean
isMainline()
void
reCheckBlockBoundary()
temporary fill of abstract from abovevoid
remove()
Remove this object from display and persistance.boolean
replaceTrackConnection(LayoutTrack oldTrack, LayoutTrack newTrack, HitPointType newType)
Replace old track connection with new track connection.void
setAllLayoutBlocks(LayoutBlock layoutBlock)
Assign all the layout blocks in this trackvoid
setConnect1(LayoutTrack o, HitPointType type)
void
setConnect2(LayoutTrack o, HitPointType type)
void
setConnection(HitPointType connectionType, LayoutTrack o, HitPointType type)
set the LayoutTrack connected at the specified connection typevoid
setLayoutBlock(LayoutBlock newLayoutBlock)
Set up a LayoutBlock for this Track Segment.void
setLayoutBlockByName(java.lang.String name)
Set up a LayoutBlock for this Track Segment.void
setMainline(boolean main)
protected void
setNewConnect1(LayoutTrack connectTrack, HitPointType connectionType)
set a new connection 1protected void
setNewConnect2(LayoutTrack connectTrack, HitPointType connectionType)
set a new connection 2void
setObjects(LayoutEditor p)
Initialization method.java.lang.String
toString()
Get debugging string for the TrackSegment.void
updateBlockInfo()
-
Methods inherited from class jmri.jmrit.display.layoutEditor.LayoutTrack
getId, getName, getTurnoutStateString, isDisconnected, setIdent
-
-
-
-
Field Detail
-
connect1
protected LayoutTrack connect1
-
type1
protected HitPointType type1
-
connect2
protected LayoutTrack connect2
-
type2
protected HitPointType type2
-
tConnect1Name
public java.lang.String tConnect1Name
-
tConnect2Name
public java.lang.String tConnect2Name
-
tLayoutBlockName
public java.lang.String tLayoutBlockName
-
-
Constructor Detail
-
TrackSegment
public TrackSegment(@Nonnull java.lang.String id, @CheckForNull LayoutTrack c1, HitPointType t1, @CheckForNull LayoutTrack c2, HitPointType t2, boolean main, @Nonnull LayoutEditor models)
-
TrackSegment
public TrackSegment(@Nonnull java.lang.String id, @CheckForNull java.lang.String c1Name, HitPointType t1, @CheckForNull java.lang.String c2Name, HitPointType t2, boolean main, @Nonnull LayoutEditor models)
-
-
Method Detail
-
toString
public java.lang.String toString()
Get debugging string for the TrackSegment.- Overrides:
toString
in classjava.lang.Object
- Returns:
- text showing id and connections of this segment
-
getBlockName
@Nonnull public java.lang.String getBlockName()
-
getType1
public HitPointType getType1()
-
getType2
public HitPointType getType2()
-
getConnect1
public LayoutTrack getConnect1()
-
getConnect2
public LayoutTrack getConnect2()
-
setNewConnect1
protected void setNewConnect1(@CheckForNull LayoutTrack connectTrack, HitPointType connectionType)
set a new connection 1- Parameters:
connectTrack
- the track we want to connect toconnectionType
- where on that track we want to be connected
-
setNewConnect2
protected void setNewConnect2(@CheckForNull LayoutTrack connectTrack, HitPointType connectionType)
set a new connection 2- Parameters:
connectTrack
- the track we want to connect toconnectionType
- where on that track we want to be connected
-
replaceTrackConnection
public boolean replaceTrackConnection(@CheckForNull LayoutTrack oldTrack, @CheckForNull LayoutTrack newTrack, HitPointType newType)
Replace old track connection with new track connection.- Parameters:
oldTrack
- the old track connection.newTrack
- the new track connection.newType
- the hit point type.- Returns:
- true if successful.
-
isMainline
public boolean isMainline()
- Specified by:
isMainline
in classLayoutTrack
- Returns:
- true if track segment is a main line
-
setMainline
public void setMainline(boolean main)
-
getLayoutBlock
public LayoutBlock getLayoutBlock()
-
getConnect1Name
public java.lang.String getConnect1Name()
-
getConnect2Name
public java.lang.String getConnect2Name()
-
getConnection
public LayoutTrack getConnection(HitPointType connectionType) throws JmriException
get the LayoutTrack connected at the specified connection typeThis implementation returns null because
getConnect1()
andgetConnect2()
should be used instead.- Specified by:
getConnection
in classLayoutTrack
- Parameters:
connectionType
- where on us to get the connection- Returns:
- the LayoutTrack connected at the specified connection type
- Throws:
JmriException
- - if the connectionType is invalid
-
setConnection
public void setConnection(HitPointType connectionType, @CheckForNull LayoutTrack o, HitPointType type) throws JmriException
set the LayoutTrack connected at the specified connection typeThis implementation does nothing because
setNewConnect1(jmri.jmrit.display.layoutEditor.LayoutTrack, jmri.jmrit.display.layoutEditor.HitPointType)
andsetNewConnect2(jmri.jmrit.display.layoutEditor.LayoutTrack, jmri.jmrit.display.layoutEditor.HitPointType)
should be used instead.- Specified by:
setConnection
in classLayoutTrack
- Parameters:
connectionType
- where on us to set the connectiono
- the LayoutTrack that is to be connectedtype
- where on the LayoutTrack we are connected- Throws:
JmriException
- - if connectionType or type are invalid
-
setConnect1
public void setConnect1(@CheckForNull LayoutTrack o, HitPointType type)
-
setConnect2
public void setConnect2(@CheckForNull LayoutTrack o, HitPointType type)
-
setLayoutBlock
public void setLayoutBlock(@CheckForNull LayoutBlock newLayoutBlock)
Set up a LayoutBlock for this Track Segment.- Parameters:
newLayoutBlock
- the LayoutBlock to set
-
setLayoutBlockByName
public void setLayoutBlockByName(@CheckForNull java.lang.String name)
Set up a LayoutBlock for this Track Segment.- Parameters:
name
- the name of the new LayoutBlock
-
setObjects
public void setObjects(LayoutEditor p)
Initialization method. The above variables are initialized by PositionablePointXml, then the following method is called after the entire LayoutEditor is loaded to set the specific TrackSegment objects.- Specified by:
setObjects
in classLayoutTrack
- Parameters:
p
- the layout editor
-
updateBlockInfo
public void updateBlockInfo()
-
canRemove
public boolean canRemove()
Check for active block boundaries.If any connection point of a layout track object has attached objects, such as signal masts, signal heads or NX sensors, the layout track object cannot be deleted.
- Specified by:
canRemove
in classLayoutTrack
- Returns:
- true if the layout track object can be deleted.
-
getPointReferences
public java.util.ArrayList<java.lang.String> getPointReferences(HitPointType type, LayoutTrack conn)
-
remove
public void remove()
Remove this object from display and persistance.
-
isActive
public boolean isActive()
Get state. "active" means that the object is still displayed, and should be stored.- Returns:
- true if still displayed, else false.
-
reCheckBlockBoundary
public void reCheckBlockBoundary()
temporary fill of abstract from above- Specified by:
reCheckBlockBoundary
in classLayoutTrack
-
getLayoutConnectivity
protected java.util.List<LayoutConnectivity> getLayoutConnectivity()
get the layout connectivity for this track- Specified by:
getLayoutConnectivity
in classLayoutTrack
- Returns:
- the list of Layout Connectivity objects
-
checkForFreeConnections
public java.util.List<HitPointType> checkForFreeConnections()
return a list of the available connections for this layout track- Specified by:
checkForFreeConnections
in classLayoutTrack
- Returns:
- the list of available connections
-
checkForUnAssignedBlocks
public boolean checkForUnAssignedBlocks()
determine if all the appropriate blocks have been assigned to this track- Specified by:
checkForUnAssignedBlocks
in classLayoutTrack
- Returns:
- true if all appropriate blocks have been assigned
-
checkForNonContiguousBlocks
public void checkForNonContiguousBlocks(@Nonnull java.util.HashMap<java.lang.String,java.util.List<java.util.Set<java.lang.String>>> blockNamesToTrackNameSetsMap)
check this track and its neighbors for non-contiguous blocksFor each (non-null) blocks of this track do: #1) If it's got an entry in the blockNamesToTrackNameSetMap then #2) If this track is not in one of the TrackNameSets for this block #3) add a new set (with this block/track) to blockNamesToTrackNameSetMap and #4) check all the connections in this block (by calling the 2nd method below)
Basically, we're maintaining contiguous track sets for each block found (in blockNamesToTrackNameSetMap)
- Specified by:
checkForNonContiguousBlocks
in classLayoutTrack
- Parameters:
blockNamesToTrackNameSetsMap
- hashmap of key:block names to lists of track name sets for those blocks
-
collectContiguousTracksNamesInBlockNamed
public void collectContiguousTracksNamesInBlockNamed(@Nonnull java.lang.String blockName, @Nonnull java.util.Set<java.lang.String> TrackNameSet)
recursive routine to check for all contiguous tracks in this blockName- Specified by:
collectContiguousTracksNamesInBlockNamed
in classLayoutTrack
- Parameters:
blockName
- the block that we're checking forTrackNameSet
- the set of track names in this block
-
setAllLayoutBlocks
public void setAllLayoutBlocks(LayoutBlock layoutBlock)
Assign all the layout blocks in this track- Specified by:
setAllLayoutBlocks
in classLayoutTrack
- Parameters:
layoutBlock
- to this layout block (used by the Tools menu's "Assign block to selection" item)
-
getTypeName
public java.lang.String getTypeName()
Get the type of this item.- Specified by:
getTypeName
in classLayoutTrack
- Returns:
- the type
-
-