Class LayoutTurntable
- java.lang.Object
-
- jmri.jmrit.display.layoutEditor.LayoutTrack
-
- jmri.jmrit.display.layoutEditor.LayoutTurntable
-
public class LayoutTurntable extends LayoutTrack
A LayoutTurntable is a representation used by LayoutEditor to display a turntable.A LayoutTurntable has a variable number of connection points, called RayTracks, each radiating from the center of the turntable. Each of these points should be connected to a TrackSegment.
Each radiating segment (RayTrack) gets its Block information from its connected track segment.
Each radiating segment (RayTrack) has a unique connection index. The connection index is set when the RayTrack is created, and cannot be changed. This connection index is used to maintain the identity of the radiating segment to its connected Track Segment as ray tracks are added and deleted by the user.
The radius of the turntable circle is variable by the user.
Each radiating segment (RayTrack) connecting point is a fixed distance from the center of the turntable. The user may vary the angle of the radiating segment. Angles are measured from the vertical (12 o'clock) position in a clockwise manner. For example, 30 degrees is 1 o'clock, 60 degrees is 2 o'clock, 90 degrees is 3 o'clock, etc.
Each radiating segment is drawn from its connection point to the turntable circle in the direction of the turntable center.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLayoutTurntable.RayTrack
-
Field Summary
Fields Modifier and Type Field Description java.util.List<LayoutTurntable.RayTrack>rayTrackListjava.lang.StringtLayoutBlockName-
Fields inherited from class jmri.jmrit.display.layoutEditor.LayoutTrack
models
-
-
Constructor Summary
Constructors Constructor Description LayoutTurntable(java.lang.String id, LayoutEditor models)Constructor method
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LayoutTurntable.RayTrackaddRay(double angle)Add a ray at the specified angle.voidaddRayTrack(double angle, int index, java.lang.String name)booleancanRemove()Check for active block boundaries.java.util.List<HitPointType>checkForFreeConnections()return a list of the available connections for this layout trackvoidcheckForNonContiguousBlocks(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 blocksbooleancheckForUnAssignedBlocks()determine if all the appropriate blocks have been assigned to this trackvoidcollectContiguousTracksNamesInBlockNamed(java.lang.String blockName, java.util.Set<java.lang.String> TrackNameSet)recursive routine to check for all contiguous tracks in this blockNamevoiddeleteRay(LayoutTurntable.RayTrack rayTrack)Delete this ray track.java.lang.StringgetBlockName()LayoutTrackgetConnection(HitPointType connectionType)get the LayoutTrack connected at the specified connection typeLayoutBlockgetLayoutBlock()protected java.util.List<LayoutConnectivity>getLayoutConnectivity()get the layout connectivity for this trackintgetNumberRays()Get the number of rays on turntable.intgetPosition()Get the turntable position.doublegetRadius()Get the radius for this turntable.doublegetRayAngle(int i)Get the angle for the ray at this position in the rayTrackList.TrackSegmentgetRayConnectIndexed(int index)Get the connection for the ray with this index.TrackSegmentgetRayConnectOrdered(int i)Get the connection for the ray at the index in the rayTrackList.intgetRayIndex(int i)Get the index for the ray at this position in the rayTrackList.java.util.List<LayoutTurntable.RayTrack>getRayTrackList()TurnoutgetRayTurnout(int i)Get the turnout for the ray at this index.java.lang.StringgetRayTurnoutName(int i)Get the name of the turnout for the ray at this index.intgetRayTurnoutState(int i)Get the state of the turnout for the ray at this index.java.lang.StringgetTypeName()Get the type of this item.booleanisActive()Get if turntable is active.booleanisMainline()booleanisMainlineIndexed(int index)Test if ray with this index is a mainline track or not.booleanisMainlineOrdered(int i)Test if ray at this index is a mainline track or not.booleanisRayDisabled(int i)Get if the ray at this index is disabled.booleanisRayDisabledWhenOccupied(int i)Get the disabled when occupied state of the ray at this index.booleanisTurnoutControlled()Is this turntable turnout controlled?protected voidreCheckBlockBoundary()abstract method... subclasses should implement _IF_ they need to recheck their block boundariesvoidremove()Remove this object from display and persistance.voidsetAllLayoutBlocks(LayoutBlock layoutBlock)Assign all the layout blocks in this trackvoidsetConnection(HitPointType connectionType, LayoutTrack o, HitPointType type)set the LayoutTrack connected at the specified connection typevoidsetLayoutBlock(LayoutBlock newLayoutBlock)Set up a LayoutBlock for this LayoutTurntable.voidsetLayoutBlockByName(java.lang.String name)Set up a LayoutBlock for this LayoutTurntable.voidsetObjects(LayoutEditor p)Initialization method The name of each track segment connected to a ray track is initialized by by LayoutTurntableXml, then the following method is called after the entire LayoutEditor is loaded to set the specific TrackSegment objects.voidsetPosition(int index)Set turntable position to the ray with this index.voidsetRadius(double r)Set the radius for this turntable.voidsetRayConnect(TrackSegment ts, int index)Set the connection for the ray at the index in the rayTrackList.voidsetRayDisabled(int i, boolean boo)Set the disabled state of the ray at this index.voidsetRayDisabledWhenOccupied(int i, boolean boo)Set the disabled when occupied state of the ray at this index.voidsetRayTurnout(int index, java.lang.String turnoutName, int state)Set the turnout and state for the ray with this index.voidsetTurnoutControlled(boolean boo)Set if this turntable is turnout controlled.java.lang.StringtoString()Get a string that represents this object.-
Methods inherited from class jmri.jmrit.display.layoutEditor.LayoutTrack
getId, getName, getTurnoutStateString, isDisconnected, setIdent
-
-
-
-
Field Detail
-
rayTrackList
public final java.util.List<LayoutTurntable.RayTrack> rayTrackList
-
tLayoutBlockName
public java.lang.String tLayoutBlockName
-
-
Constructor Detail
-
LayoutTurntable
public LayoutTurntable(@Nonnull java.lang.String id, @Nonnull LayoutEditor models)
Constructor method- Parameters:
id- the name for the turntablemodels- what layout editor panel to put it in
-
-
Method Detail
-
toString
@Nonnull public java.lang.String toString()
Get a string that represents this object. This should only be used for debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
- the string
-
getRadius
public double getRadius()
Get the radius for this turntable.- Returns:
- the radius for this turntable
-
setRadius
public void setRadius(double r)
Set the radius for this turntable.- Parameters:
r- the radius for this turntable
-
getBlockName
@Nonnull public java.lang.String getBlockName()
- Returns:
- the layout block name
-
getLayoutBlock
@CheckForNull public LayoutBlock getLayoutBlock()
- Returns:
- the layout block
-
setLayoutBlock
public void setLayoutBlock(@CheckForNull LayoutBlock newLayoutBlock)
Set up a LayoutBlock for this LayoutTurntable.- Parameters:
newLayoutBlock- the LayoutBlock to set
-
setLayoutBlockByName
public void setLayoutBlockByName(@CheckForNull java.lang.String name)
Set up a LayoutBlock for this LayoutTurntable.- Parameters:
name- the name of the new LayoutBlock
-
addRay
public LayoutTurntable.RayTrack addRay(double angle)
Add a ray at the specified angle.- Parameters:
angle- the angle- Returns:
- the RayTrack
-
addRayTrack
public void addRayTrack(double angle, int index, java.lang.String name)
-
getRayConnectIndexed
@CheckForNull public TrackSegment getRayConnectIndexed(int index)
Get the connection for the ray with this index.- Parameters:
index- the index- Returns:
- the connection for the ray with this value of getConnectionIndex
-
getRayConnectOrdered
@CheckForNull public TrackSegment getRayConnectOrdered(int i)
Get the connection for the ray at the index in the rayTrackList.- Parameters:
i- the index in the rayTrackList- Returns:
- the connection for the ray at that index in the rayTrackList or null
-
setRayConnect
public void setRayConnect(@CheckForNull TrackSegment ts, int index)
Set the connection for the ray at the index in the rayTrackList.- Parameters:
ts- the connectionindex- the index in the rayTrackList
-
getRayTrackList
@Nonnull public java.util.List<LayoutTurntable.RayTrack> getRayTrackList()
-
getNumberRays
public int getNumberRays()
Get the number of rays on turntable.- Returns:
- the number of rays
-
getRayIndex
public int getRayIndex(int i)
Get the index for the ray at this position in the rayTrackList.- Parameters:
i- the position in the rayTrackList- Returns:
- the index
-
getRayAngle
public double getRayAngle(int i)
Get the angle for the ray at this position in the rayTrackList.- Parameters:
i- the position in the rayTrackList- Returns:
- the angle
-
setRayTurnout
public void setRayTurnout(int index, @CheckForNull java.lang.String turnoutName, int state)
Set the turnout and state for the ray with this index.- Parameters:
index- the indexturnoutName- the turnout namestate- the state
-
getRayTurnoutName
@CheckForNull public java.lang.String getRayTurnoutName(int i)
Get the name of the turnout for the ray at this index.- Parameters:
i- the index- Returns:
- name of the turnout for the ray at this index
-
getRayTurnout
@CheckForNull public Turnout getRayTurnout(int i)
Get the turnout for the ray at this index.- Parameters:
i- the index- Returns:
- the turnout for the ray at this index
-
getRayTurnoutState
public int getRayTurnoutState(int i)
Get the state of the turnout for the ray at this index.- Parameters:
i- the index- Returns:
- state of the turnout for the ray at this index
-
isRayDisabled
public boolean isRayDisabled(int i)
Get if the ray at this index is disabled.- Parameters:
i- the index- Returns:
- true if disabled
-
setRayDisabled
public void setRayDisabled(int i, boolean boo)
Set the disabled state of the ray at this index.- Parameters:
i- the indexboo- the state
-
isRayDisabledWhenOccupied
public boolean isRayDisabledWhenOccupied(int i)
Get the disabled when occupied state of the ray at this index.- Parameters:
i- the index- Returns:
- the state
-
setRayDisabledWhenOccupied
public void setRayDisabledWhenOccupied(int i, boolean boo)
Set the disabled when occupied state of the ray at this index.- Parameters:
i- the indexboo- the state
-
getConnection
public LayoutTrack getConnection(HitPointType connectionType) throws JmriException
get the LayoutTrack connected at the specified connection type- Specified by:
getConnectionin 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 type- Specified by:
setConnectionin 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
-
isMainlineIndexed
public boolean isMainlineIndexed(int index)
Test if ray with this index is a mainline track or not.Defaults to false (not mainline) if connecting track segment is missing.
- Parameters:
index- the index- Returns:
- true if connecting track segment is mainline
-
isMainlineOrdered
public boolean isMainlineOrdered(int i)
Test if ray at this index is a mainline track or not.Defaults to false (not mainline) if connecting track segment is missing
- Parameters:
i- the index- Returns:
- true if connecting track segment is mainline
-
isMainline
public boolean isMainline()
- Specified by:
isMainlinein classLayoutTrack
-
setObjects
public void setObjects(@Nonnull LayoutEditor p)
Initialization method The name of each track segment connected to a ray track is initialized by by LayoutTurntableXml, then the following method is called after the entire LayoutEditor is loaded to set the specific TrackSegment objects.- Specified by:
setObjectsin classLayoutTrack- Parameters:
p- the layout editor
-
isTurnoutControlled
public boolean isTurnoutControlled()
Is this turntable turnout controlled?- Returns:
- true if so
-
setTurnoutControlled
public void setTurnoutControlled(boolean boo)
Set if this turntable is turnout controlled.- Parameters:
boo- set true if so
-
setPosition
public void setPosition(int index)
Set turntable position to the ray with this index.- Parameters:
index- the index
-
getPosition
public int getPosition()
Get the turntable position.- Returns:
- the turntable position
-
deleteRay
public void deleteRay(@Nonnull LayoutTurntable.RayTrack rayTrack)
Delete this ray track.- Parameters:
rayTrack- the ray track
-
remove
public void remove()
Remove this object from display and persistance.
-
isActive
public boolean isActive()
Get if turntable is active. "active" means that the object is still displayed, and should be stored.- Returns:
- true if active, else false.
-
reCheckBlockBoundary
protected void reCheckBlockBoundary()
abstract method... subclasses should implement _IF_ they need to recheck their block boundaries- Specified by:
reCheckBlockBoundaryin classLayoutTrack
-
getLayoutConnectivity
@CheckForNull protected java.util.List<LayoutConnectivity> getLayoutConnectivity()
get the layout connectivity for this track- Specified by:
getLayoutConnectivityin classLayoutTrack- Returns:
- the list of Layout Connectivity objects
-
checkForFreeConnections
@Nonnull public java.util.List<HitPointType> checkForFreeConnections()
return a list of the available connections for this layout track- Specified by:
checkForFreeConnectionsin 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:
checkForUnAssignedBlocksin 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:
checkForNonContiguousBlocksin 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:
collectContiguousTracksNamesInBlockNamedin 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:
setAllLayoutBlocksin classLayoutTrack- Parameters:
layoutBlock- to this layout block (used by the Tools menu's "Assign block to selection" item)
-
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:
canRemovein classLayoutTrack- Returns:
- true if the layout track object can be deleted.
-
getTypeName
public java.lang.String getTypeName()
Get the type of this item.- Specified by:
getTypeNamein classLayoutTrack- Returns:
- the type
-
-