AnyLogic
Expand
Font size
All Implemented Interfaces:
AggregatableAnimationElement, HasLevel, RailMarkup, SVGElement, Serializable, Iterable<MarkupSegment>

public class RailwayTrack
extends AbstractRailwayMarkup
implements Iterable<MarkupSegment>
See Also:
Serialized Form

Constructor Summary

ConstructorDescription
RailwayTrack() 
RailwayTrack(Agent owner, ShapeDrawMode drawMode, boolean isPublic, PathDrawingType drawingType, Paint color, double width, MarkupSegment... segments)
Deprecated.
deprecated in version 8.4, will be removed in the future releases

Method Summary

Modifier and TypeMethodDescription
voidaddSegment(MarkupSegment segment)
Adds segment to this markup element
voidarcTo(double x, double y, double z, double startAngle, double endAngle, double ratioStartToEnd)
Adds arc segment with two circular arcs (available for markup elements created with no-argument constructor)
voidblock()
Block the track.
voidcancelReservation()
Cancel existing reservations for the 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.
booleancontains(double px, double py, double distance)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e.
booleancontainsSq(double px, double py, double squareDistance)
Test if the shape contains the point with the given coordinates (relative to this shape's container, i.e.
BoundingRectanglegetBoundingRectangle() 
AgentgetCar(int index)
Returns a car on the track at a given position counted from the beginning of the track.
List<Agent>getCars()
Returns the list of rail cars that are (maybe, partially) located of this track
ColorgetColor()
Returns the color of the shape, or null if shape has no color or has textured (in this case #getFillTexture() should be used instead)
TrackDataSourcegetDataSource() 
PathDrawingTypegetDrawingType()
Returns the drawing type of this path
RailwaySwitchgetEndSwitch()
Get the switch at the end of the track
AgentgetFirstCar()
Returns the car closest to the beginning of the track, or null if the track is empty
doublegetFreeSpace(boolean fromstart)
Tests the availability of space on the track.
AgentgetLastCar()
Returns the car closest to the end of the track, or null if the track is empty
intgetNCars()
Deprecated.
doublegetNearestPoint(double x, double y, double z, LengthUnits units, Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y, z) point.
doublegetNearestPoint(double x, double y, double z, Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y, z) point.
doublegetNearestPoint(double x, double y, LengthUnits units, Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y) point.
doublegetNearestPoint(double x, double y, Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y) point.
doublegetNearestPointOnRay(double x1, double y1, double x2, double y2, LengthUnits units, Point out)
Calculates the intersection point between this element and the given ray.
doublegetNearestPointOnRay(double x1, double y1, double x2, double y2, Point out)
Calculates the intersection point between this element and the given ray.
RailwaySwitchgetOtherSwitch(RailwaySwitch sw)
If the given switch is 'start switch' of this track, returns track's 'end switch', otherwise returns 'source switch'.
PositiongetPositionAtOffset(double offset, Position position)
Returns the point located on the markup element with the given offset distance calculated from start point.
List<PositionOnTrack>getPositionsOnTrack()
Returns a list of all PositionOnTrack elements on this track
MarkupSegmentgetSegment(int index)
Returns the segment by its index
intgetSegmentCount()
Returns the number of segments
RailwaySwitchgetStartSwitch()
Get the switch at the start of the track
RailwaySwitchgetSwitch(boolean atend)
Returns the switch at the beginning or at the end of the track.
TexturegetTexture()
Returns the texture of the shape, if the shape has texture
List<Agent>getTrains()
Get the list of trains that are currently (including partially) on the track
doublegetWidth()
Returns the width of the track.
doublegetWidth(LengthUnits units)
Returns the width of the track.
booleanisAvailableFor(Agent train)
Check if the specified train can move through the track
booleanisBlocked()
Check if the track is blocked
booleanisEmpty()
Tests if the track is empty, i.e.
Iterator<MarkupSegment>iterator()
Creates and returns read-only iterator over segments
final doublelength()
Returns the length of the markup element, calculated in 3D space.
final doublelength(LengthUnits units)
Returns the length of the markup element, calculated in 3D space.
voidlineTo(double x, double y, double z)
Adds line segment (available for markup elements created with no-argument constructor)
intnCars()
Returns the number of cars on the track (including partially)
List<Agent>reservations()
Return all the trains that this track has been reserved for
voidreserveFor(Agent... trains)
Reserve the track for certain trains
voidsetBlocked(boolean blocked)
Set track's block status
voidsetColor(Color color)
Sets the color of the shape.
voidsetColor(Paint color)
Sets the color (or Texture) of the shape.
voidsetDrawingType(PathDrawingType drawingType)
Sets the drawing type of this path
voidsetWidth(double width)
Deprecated.
this method is deprecated and may be removed in the next release.
voidsetWidth(double width, LengthUnits units)
Sets the width of the track, 0 means thinnest possible
voidstartDrawing(double x, double y, double z)
Starts drawing (available for markup elements created with no-argument constructor)
Path3DtoPath3D()
Converts this markup element to Path3D interface
voidunblock()
Unblock the track and allow trains to move through it

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, onClick, 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.AggregatableAnimationElement

postInitialize

Methods inherited from interface java.lang.Iterable

forEach, spliterator

Constructor Details

RailwayTrack

public RailwayTrack()

RailwayTrack

@Deprecated
public RailwayTrack(Agent owner,
 ShapeDrawMode drawMode,
 boolean isPublic,
 PathDrawingType drawingType,
 Paint color,
 double width,
 MarkupSegment... segments)
Deprecated.
deprecated in version 8.4, will be removed in the future releases
Parameters:
owner -
drawMode -
isPublic -
drawingType -
color -
width -
segments -

Method Details

getPositionsOnTrack

public List<PositionOnTrack> getPositionsOnTrack()
Returns a list of all PositionOnTrack elements on this track
Returns:
a list of all PositionOnTrack elements on this track

getDataSource

@AnyLogicInternalAPI
public TrackDataSource getDataSource()

block

public void block()
Block the track. Trains that are on the track are allowed to leave the track but cannot enter it after that

unblock

public void unblock()
Unblock the track and allow trains to move through it

isBlocked

public boolean isBlocked()
Check if the track is blocked
Returns:
true if it is blocked, false - otherwise

setBlocked

public void setBlocked(boolean blocked)
Set track's block status
Parameters:
blocked - if true (false) - block (unblock) the track. Does nothing for already blocked (unblocked) track

reserveFor

public void reserveFor(Agent... trains)
Reserve the track for certain trains
Parameters:
trains - Only these trains are allowed to move through the track

reservations

public List<Agent> reservations()
Return all the trains that this track has been reserved for
Returns:
all the trains that this track has been reserved for

isAvailableFor

public boolean isAvailableFor(Agent train)
Check if the specified train can move through the track
Parameters:
train - the train. If the argument is null the method returns the opposite result of isBlocked
Returns:
true if the train can move through the track, false - otherwise

cancelReservation

public void cancelReservation()
Cancel existing reservations for the track. All trains will be able to move through the track, provided it is unblocked

getStartSwitch

public RailwaySwitch getStartSwitch()
Get the switch at the start of the track
Returns:
the switch at the start of the track

getEndSwitch

public RailwaySwitch getEndSwitch()
Get the switch at the end of the track
Returns:
the switch at the end of the track

getTrains

public List<Agent> getTrains()
Get the list of trains that are currently (including partially) on the track
Returns:
list of trains that are currently on the track

getOtherSwitch

public RailwaySwitch getOtherSwitch(RailwaySwitch sw)
If the given switch is 'start switch' of this track, returns track's 'end switch', otherwise returns 'source switch'. Note that this function doesn't check that the given is either 'start switch' or 'end switch': this is the responsibility of user calling this function. The ordinal use case is calling this method for some path connected to some switch.
Parameters:
sw - the switch (one of the track endings)
Returns:
the switch of the other end of this track

getSwitch

public RailwaySwitch getSwitch(boolean atend)
Returns the switch at the beginning or at the end of the track.
Parameters:
atend - if true - the switch at the end is returned, otherwise at the beginning
Returns:
the switch at the beginning or at the end of the track, or null

getDrawingType

public PathDrawingType getDrawingType()
Returns the drawing type of this path
Returns:
the drawing type of this path

setDrawingType

public void setDrawingType(PathDrawingType drawingType)
Sets the drawing type of this path
Parameters:
drawingType - the drawing type of this path

setColor

public void setColor(Color color)
Sets the color of the shape.
Parameters:
color - the new color, null = do not draw the shape

setColor

public void setColor(Paint color)
Sets the color (or Texture) of the shape.
Parameters:
color - the new color, null = do not draw the shape

getColor

public Color getColor()
Returns the color of the shape, or null if shape has no color or has textured (in this case #getFillTexture() should be used instead)
Returns:
the color of the shape

getTexture

public Texture getTexture()
Returns the texture of the shape, if the shape has texture
Returns:
the texture of the shape

setWidth

@Deprecated
public void setWidth(double width)
Deprecated.
this method is deprecated and may be removed in the next release. Please use method with units argument instead.
Sets the width of the track, 0 means thinnest possible
Parameters:
width - the new width of the track, measured in pixels

setWidth

public void setWidth(double width,
 LengthUnits units)
Sets the width of the track, 0 means thinnest possible
Parameters:
width - width the new width of the track, measured in the given units
units - length units

getWidth

public double getWidth()
Returns the width of the track.
Returns:
the width of the track, measured in pixels

getWidth

public double getWidth(LengthUnits units)
Returns the width of the track.
Parameters:
units - length units
Returns:
the width of the track, measured in the given units

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

contains

public boolean contains(double px,
 double py,
 double distance)
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), using the given tolerance
Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
squareDistance - the square of distance tolerance to determine whether the given point lies on the markup element line or not
Returns:
true if the shape contains the point with the given coordinates

containsSq

public boolean containsSq(double px,
 double py,
 double squareDistance)
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), using the given tolerance
Parameters:
px - the x coordinate relative to this shape's container
py - the y coordinate relative to this shape's container
squareDistance - the square of distance tolerance to determine whether the given point lies on the markup element line or not
Returns:
true if the shape contains the point with the given coordinates

startDrawing

public void startDrawing(double x,
 double y,
 double z)
Starts drawing (available for markup elements created with no-argument constructor)
Parameters:
x - the x coordinate of the first point
y - the y coordinate of the first point
z - the z coordinate of the first point

lineTo

public void lineTo(double x,
 double y,
 double z)
Adds line segment (available for markup elements created with no-argument constructor)
Parameters:
x - the x coordinate of the segment end point
y - the y coordinate of the segment end point
z - the z coordinate of the segment end point

arcTo

public void arcTo(double x,
 double y,
 double z,
 double startAngle,
 double endAngle,
 double ratioStartToEnd)
Adds arc segment with two circular arcs (available for markup elements created with no-argument constructor)
Parameters:
x - the x coordinate of the segment end point
y - the y coordinate of the segment end point
z - the z coordinate of the segment end point
startAngle - orientation of segment line start
endAngle - orientation of segment line end
ratioStartToEnd - ratio between two circular arcs

addSegment

public void addSegment(MarkupSegment segment)
Adds segment to this markup element
Parameters:
segment - the segment, should be initialized if was created using no-argument constructor

getSegmentCount

public int getSegmentCount()
Returns the number of segments
Returns:
the number of segments

getSegment

public MarkupSegment getSegment(int index)
Returns the segment by its index
Parameters:
index - the segment index, [0 .. getSegmentCount() - 1]
Returns:
the segment

iterator

public Iterator<MarkupSegment> iterator()
Creates and returns read-only iterator over segments
Specified by:
iterator in interface Iterable<MarkupSegment>

length

public final double length()
Returns the length of the markup element, calculated in 3D space.
Returns:
the length of the markup element (measured in pixels), a positive number

length

public final double length(LengthUnits units)
Returns the length of the markup element, calculated in 3D space.
Parameters:
units - the length units
Returns:
the length of the markup element, a positive number
Since:
7.1

getPositionAtOffset

public Position getPositionAtOffset(double offset,
 Position position)
Returns the point located on the markup element with the given offset distance calculated from start point.
Parameters:
offset - offset, non-negative value, should be less or equal to the full length.
out - output object to write to, may be null
Returns:
the Position object with coordinates of the point with the given offset and orientation along markup element line at this point

getNearestPoint

public double getNearestPoint(double x,
 double y,
 Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y) point. Returns the square of distance to the point (in the XY-projection). All the calculations are performed in the horizontal projection (z-coordinates aren't used, as if all of the z coordinates were zero).
Parameters:
x - x coordinate of the point
y - y coordinate of the point
output - the output point to write result to. Note that output.z is left unchanged.
Returns:
the square of distance to the nearest point in the horizontal (XY) projection

getNearestPoint

public double getNearestPoint(double x,
 double y,
 LengthUnits units,
 Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y) point. Returns the square of distance to the point (in the XY-projection). All the calculations are performed in the horizontal projection (z-coordinates aren't used, as if all of the z coordinates were zero).
Parameters:
x - x coordinate of the point
y - y coordinate of the point
units - the length units
output - the output point to write result to. Note that output.z is left unchanged.
Returns:
the square of distance to the nearest point in the horizontal (XY) projection

getNearestPoint

public double getNearestPoint(double x,
 double y,
 double z,
 Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y, z) point. Returns the square of distance to the point.
Parameters:
x - x coordinate of the point
y - y coordinate of the point
z - z coordinate of the point
output - the output point to write result to.
Returns:
the square of distance to the nearest point

getNearestPoint

public double getNearestPoint(double x,
 double y,
 double z,
 LengthUnits units,
 Point out)
Calculates (using the output object) the point in this space markup element nearest to the given (x, y, z) point. Returns the square of distance to the point.
Parameters:
x - x coordinate of the point
y - y coordinate of the point
z - z coordinate of the point
units - the length units
output - the output point to write result to.
Returns:
the square of distance to the nearest point

getNearestPointOnRay

public double getNearestPointOnRay(double x1,
 double y1,
 double x2,
 double y2,
 Point out)
Calculates the intersection point between this element and the given ray. If there are several intersections, returns the one nearest to the ray start
Parameters:
x1 - the x coordinate of ray start
y1 - the y coordinate of ray start
x2 - the x coordinate of some ray point
y2 - the y coordinate of some ray point
out - the output: intersection point, should be not null
Returns:
the offset of the nearest point or -1 if there is no intersections with the given ray

getNearestPointOnRay

public double getNearestPointOnRay(double x1,
 double y1,
 double x2,
 double y2,
 LengthUnits units,
 Point out)
Calculates the intersection point between this element and the given ray. If there are several intersections, returns the one nearest to the ray start
Parameters:
x1 - the x coordinate of ray start
y1 - the y coordinate of ray start
x2 - the x coordinate of some ray point
y2 - the y coordinate of some ray point
units - the length units
out - the output: intersection point, should be not null
Returns:
the offset of the nearest point or -1 if there is no intersections with the given ray

toPath3D

public Path3D toPath3D()
Converts this markup element to Path3D interface

isEmpty

public boolean isEmpty()
Tests if the track is empty, i.e. there are no cars that are (even partially) on the track.
Returns:
true if the track is empty, false otherwise

nCars

public int nCars()
Returns the number of cars on the track (including partially)
Returns:
the number of cars on the track
Since:
7.2

getNCars

@Deprecated
public int getNCars()
Deprecated.
Returns the number of cars on the track (including partially)
Returns:
the number of cars on the track

getFirstCar

public Agent getFirstCar()
Returns the car closest to the beginning of the track, or null if the track is empty
Returns:
the first car on the track or null

getLastCar

public Agent getLastCar()
Returns the car closest to the end of the track, or null if the track is empty
Returns:
the last car on the track or null

getCar

public Agent getCar(int index)
Returns a car on the track at a given position counted from the beginning of the track. All cars count: moving, standing, coupled, and cars that are only partially on this track.
Parameters:
index - the index of the car
Returns:
the car at a given position, or null

getCars

public List<Agent> getCars()
Returns the list of rail cars that are (maybe, partially) located of this track
Returns:
the list of cars on this track

getFreeSpace

public double getFreeSpace(boolean fromstart)
Tests the availability of space on the track. If there are no cars on the track, returns infinity. If there are cars, returns the distance from the track start or end point (depending on the parameter fromstart) to the nearest car. If there is a car partially entered or exited the track at a given side, returns a negative value.
Parameters:
fromstart - if true, space is checked from the start point of the track, otherwise from end point
Returns:
the free space from a given side of the track in meters, or infinity

getBoundingRectangle

@AnyLogicInternalAPI
public BoundingRectangle getBoundingRectangle()