AnyLogic
Expand
Font size
All Implemented Interfaces:
AbstractPositionalMarkup, AggregatableAnimationElement, HasLevel, RailMarkup, SVGElement, UsdElement, Serializable

public class RailwaySwitch
extends AbstractRailwayMarkup
implements AbstractPositionalMarkup
See Also:
Serialized Form

Nested Class Summary

Modifier and TypeClassDescription
static interface RailwaySwitch.IRailwaySwitchType 

Field Summary

Fields inherited from interface com.anylogic.engine.presentation.UsdElement

ID_NOT_SET

Constructor Summary

ConstructorDescription
RailwaySwitch() 
RailwaySwitch(Agent owner, ShapeDrawMode drawMode, boolean isPublic)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
RailwaySwitch(Agent owner, ShapeDrawMode drawMode, boolean isPublic, double radius, Color selectionColor, Paint color, RailwaySwitch.IRailwaySwitchType type, RailwayTrack... tracks) 
RailwaySwitch(Agent owner, ShapeDrawMode drawMode, boolean isPublic, double radius, Color selectionColor, Paint color, RailwayTrack track, RailwayTrack... alternativeTracks)
Deprecated.
deprecated in version 8.4, will be removed in the future releases

Method Summary

Modifier and TypeMethodDescription
voidconnectTracks(RailwayTrack source, RailwayTrack target)
The switch is set to the state (one of them, if several) which allows the travel from source to target track
booleancontains(double px, double py)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e.
RailwayTrackcurrentStateNextTrack(RailwayTrack source)
Returns the next track (for the current state), if the switch is approached from a given track.
List<RailwayTrack>getAlternativeTracks()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Alternative Tracks"
List<RailwayTrack>getAvailableTracks(RailwayTrack source)
Finds all the tracks that are available to go to if we approach the switch from source track
PaintgetColor()
Returns the color (or texture) of the switch.
SwitchDataSourcegetDataSource() 
RailwayTrackgetMainTrack()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Main Track"
doublegetRadius()
Returns the radius of this switch
RailwayTrackgetSelectedTrack()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Selected Track".
ColorgetSelectionColor()
Returns the color of the line animating the current switch position at model runtime.
intgetToggleCount()
Get the number of times the switch was toggled
RailwayTrackgetTrack(int index)
Returns the track with a given index connected to the switch.
List<RailwayTrack>getTracks()
Returns the list of all tracks connected to this switch
doublegetX()
Returns X coordinate of this element
doublegetY()
Returns Y coordinate of this element
doublegetZ()
Returns Z coordinate of this element
booleanisTrailingPoint(RailwayTrack from)
Tests if movement from a given track through the switch is a trailing point movement or face point.
RailwayTracknextTrack(RailwayTrack source)
Returns the next track, if the switch is approached from a given track.
booleanonClick(double clickx, double clicky)
Should be overridden to define the shape reaction on mouse click.
voidsetAllToAllType()
Sets the type of the switch to All to All.
voidsetColor(Paint color)
Sets the color (or texture) of the switch.
voidsetDoubleSlipType()
Sets the type of the switch to Double Slip.
voidsetNextFeasibleState(RailwayTrack source) 
voidsetRadius(double radius)
Sets the radius of this switch
voidsetSelectedTrack(RailwayTrack track)
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Selected Track" Use connectTracks(RailwayTrack, RailwayTrack) to set a switch state in which 2 specified tracks are connected (if such state exists)
voidsetSelectionColor(Color selectionColor)
Sets the color of the line animating the current switch position at model runtime.
voidsetSingleSlipType(RailwayTrack track)
Sets the type of the switch to Single Slip.
voidsetSwitch(RailwayTrack track, RailwayTrack... alternativeTracks)
Deprecated.
voidsetTracks(RailwayTrack... tracks)
Sets the tracks that are connected to the switch.
voidsetType(RailwaySwitch.IRailwaySwitchType type) 
booleanstateExists(RailwayTrack source, RailwayTrack target)
Checks if there is a state in which you can travel through switch from source track to target track
voidtoggle()
Toggles the selected tracks.
booleantrackStarts(RailwayTrack track)
Returns true if a given track start at the switch, and false if it ends there.

Methods inherited from class com.anylogic.engine.markup.AbstractRailwayMarkup

getDrawMode, getLevel, getOutsideLevelZ, getRailYard

Methods inherited from class com.anylogic.engine.markup.MarkupShape

error, getFullName, getPresentable, getSpace, initialize, isClickHandled, isPublic, remove, setDrawMode, setOwner

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods inherited from interface com.anylogic.engine.markup.AbstractPositionalMarkup

getRotation, getSpace, isVisible

Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement

postInitialize

Methods inherited from interface com.anylogic.engine.presentation.SVGElement

executeUserAction, findSVGElement, getSVGId, removeSVGFromOwner, resetSVGState, updateSVGProperties

Methods inherited from interface com.anylogic.engine.presentation.UsdElement

getOrGenerateUSDId

Constructor Details

RailwaySwitch

public RailwaySwitch()

RailwaySwitch

@Deprecated
public RailwaySwitch(Agent owner,
 ShapeDrawMode drawMode,
 boolean isPublic)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Parameters:
owner -
drawMode -
isPublic -

RailwaySwitch

@AnyLogicInternalCodegenAPI
public RailwaySwitch(Agent owner,
 ShapeDrawMode drawMode,
 boolean isPublic,
 double radius,
 Color selectionColor,
 Paint color,
 RailwaySwitch.IRailwaySwitchType type,
 RailwayTrack... tracks)
Parameters:
owner -
drawMode -
isPublic -
radius -
selectionColor -
color -
type -
tracks -

RailwaySwitch

@AnyLogicInternalAPI
@Deprecated
public RailwaySwitch(Agent owner,
 ShapeDrawMode drawMode,
 boolean isPublic,
 double radius,
 Color selectionColor,
 Paint color,
 RailwayTrack track,
 RailwayTrack... alternativeTracks)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Parameters:
owner -
drawMode -
isPublic -
radius -
selectionColor -
color -
track -
alternativeTracks -

Method Details

getDataSource

@AnyLogicInternalAPI
public SwitchDataSource getDataSource()

setTracks

public void setTracks(RailwayTrack... tracks)
Sets the tracks that are connected to the switch. Can be used only when creating the switch by code.
Parameters:
tracks - tracks that are connected to the switch

setType

@AnyLogicInternalAPI
public void setType(RailwaySwitch.IRailwaySwitchType type)

setSingleSlipType

public void setSingleSlipType(RailwayTrack track)
Sets the type of the switch to Single Slip. Can be used only when creating the switch by code.
Parameters:
track - the track that allows switching the lane. That is there will be two available tracks to go to when approaching the switch from this track.

setDoubleSlipType

public void setDoubleSlipType()
Sets the type of the switch to Double Slip. Can be used only when creating the switch by code.

setAllToAllType

public void setAllToAllType()
Sets the type of the switch to All to All. Can be used only when creating the switch by code.

setSwitch

@Deprecated
public void setSwitch(RailwayTrack track,
 RailwayTrack... alternativeTracks)
Deprecated.

getX

public double getX()
Returns X coordinate of this element
Specified by:
getX in interface AbstractPositionalMarkup
Returns:
X coordinate of this element

getY

public double getY()
Returns Y coordinate of this element
Specified by:
getY in interface AbstractPositionalMarkup
Returns:
Y coordinate of this element

getZ

public double getZ()
Returns Z coordinate of this element
Specified by:
getZ in interface AbstractPositionalMarkup
Returns:
Z coordinate of this element

getRadius

public double getRadius()
Returns the radius of this switch
Returns:
the radius of this switch

setRadius

public void setRadius(double radius)
Sets the radius of this switch
Parameters:
radius - of this switch

getSelectionColor

public Color getSelectionColor()
Returns the color of the line animating the current switch position at model runtime.
Returns:
the color of the line animating the current switch position at model runtime.

setSelectionColor

public void setSelectionColor(Color selectionColor)
Sets the color of the line animating the current switch position at model runtime.
Parameters:
selectionColor - new selection color

getColor

public Paint getColor()
Returns the color (or texture) of the switch.
Returns:
the color (or texture) of the switch.

setColor

public void setColor(Paint color)
Sets the color (or texture) of the switch.
Parameters:
color - the color (or texture) of the switch.

getToggleCount

public int getToggleCount()
Get the number of times the switch was toggled
Returns:
the number of times the switch was toggled

getMainTrack

@Deprecated
public RailwayTrack getMainTrack()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Main Track"

getAlternativeTracks

@Deprecated
public List<RailwayTrack> getAlternativeTracks()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Alternative Tracks"

getTracks

public List<RailwayTrack> getTracks()
Returns the list of all tracks connected to this switch
Returns:

getTrack

public RailwayTrack getTrack(int index)
Returns the track with a given index connected to the switch.
Parameters:
index - index of the track
Returns:
the track with a given index connected to the switch.

getSelectedTrack

@Deprecated
public RailwayTrack getSelectedTrack()
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Selected Track". Use currentStateNextTrack(RailwayTrack) to find the next track in the current switch position
Returns the currently selected track.
Returns:
the currently selected track.

setSelectedTrack

@Deprecated
public void setSelectedTrack(RailwayTrack track)
Deprecated.
Switches with more than 3 connected tracks do not have a notion of "Selected Track" Use connectTracks(RailwayTrack, RailwayTrack) to set a switch state in which 2 specified tracks are connected (if such state exists)
Selects one of the two alternative track. If a car is over the switch, signals error.
Parameters:
track - the track to select

getAvailableTracks

public List<RailwayTrack> getAvailableTracks(RailwayTrack source)
Finds all the tracks that are available to go to if we approach the switch from source track
Parameters:
source - the track
Returns:
an ArrayList of available tracks

stateExists

public boolean stateExists(RailwayTrack source,
 RailwayTrack target)
Checks if there is a state in which you can travel through switch from source track to target track
Parameters:
source - source track
target - target track
Returns:
true if there is such a state

connectTracks

public void connectTracks(RailwayTrack source,
 RailwayTrack target)
The switch is set to the state (one of them, if several) which allows the travel from source to target track
Parameters:
source - source track
target - target track

toggle

public void toggle()
Toggles the selected tracks.

nextTrack

public RailwayTrack nextTrack(RailwayTrack source)
Returns the next track, if the switch is approached from a given track. If the current switch state does not allow movement from the source track then the method returns the next track in the next feasible (for the source track) state (without changing the state)
Parameters:
source - the track from which the switch is being approached
Returns:
the next track

currentStateNextTrack

public RailwayTrack currentStateNextTrack(RailwayTrack source)
Returns the next track (for the current state), if the switch is approached from a given track.
Parameters:
source - the track from which the switch is being approached
Returns:
the next track for the current state, null if the source track does not belong to the current state.

setNextFeasibleState

@AnyLogicInternalAPI
public void setNextFeasibleState(RailwayTrack source)

isTrailingPoint

public boolean isTrailingPoint(RailwayTrack from)
Tests if movement from a given track through the switch is a trailing point movement or face point. Will signal error if the track is not connected to the switch. Only applicable to 1-2 switches (1-1 case is trivial).
Parameters:
from - the track by which the switch is being approached
Returns:
true if trailing point, false if facing point

trackStarts

public boolean trackStarts(RailwayTrack track)
Returns true if a given track start at the switch, and false if it ends there.
Parameters:
track - the track
Returns:
true if the track starts here, false if it ends

contains

public boolean contains(double px,
 double py)
Description copied from class: MarkupShape
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e. in the same system with the coordinates of this shape, x and y)
Specified by:
contains in class MarkupShape
Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
Returns:
true if the shape contains the point with the given coordinates

onClick

@AnyLogicInternalCodegenAPI
public boolean onClick(double clickx,
 double clicky)
Description copied from class: MarkupShape
Should be overridden to define the shape reaction on mouse click. The click coordinates are definitely within the shape bounds if this method is called. By default, does nothing and returns false.
Overrides:
onClick in class MarkupShape
Parameters:
clickx - the x coordinate of the click relative to the shape
clicky - the y coordinate of the click relative to the shape
Returns:
always return false here.