Package com.anylogic.engine.markup
          - Field Summary
- Constructor Summary
- Method Summary
    - Methods inherited from class com.anylogic.engine.markup.AbstractRailwayMarkup
- Methods inherited from class com.anylogic.engine.markup.MarkupShape
- Methods inherited from class com.anylogic.engine.markup.AbstractMarkup
- Methods inherited from class java.lang.Object
- Methods inherited from interface com.anylogic.engine.markup.AggregatableAnimationElement
- Methods inherited from interface java.lang.Iterable
 
- Constructor Details
- Method Details
    - getPositionsOnTrack
- getDataSource
- block
- unblock
- isBlocked
- setBlocked
- reserveFor
- addToReservations
- removeFromReservations
- reservations
- isAvailableFor
- cancelReservation
- getStartSwitch
- getEndSwitch
- getTrains
- getOtherSwitch
- getSwitch
- getDrawingType
- setDrawingType
- setColor
- setColor
- getColor
- getTexture
- setWidth
- setWidth
- getWidth
- getWidth
- contains
- contains
- containsSq
- startDrawing
- lineTo
- arcTo
- addSegment
- getSegmentCount
- getSegment
- iterator
- length
- length
- getPositionAtOffset
- getNearestPoint
- getNearestPoint
- getNearestPoint
- getNearestPoint
- getNearestPointOnRay
- getNearestPointOnRay
- toPath3D
- isEmpty
- nCars
- getNCars
- getFirstCar
- getLastCar
- getCar
- getCars
- getFreeSpace
- getBoundingRectangle
- getCenter
 
- java.lang.Object
- com.anylogic.engine.markup.AbstractMarkup
- com.anylogic.engine.markup.MarkupShape
- com.anylogic.engine.markup.AbstractRailwayMarkup
- com.anylogic.engine.markup.RailwayTrack
- All Implemented Interfaces:
- AggregatableAnimationElement,- HasBoundingRectangle,- HasCenterPoint,- HasLevel,- RailMarkup,- SVGElement,- UsdElement,- Serializable,- Iterable<MarkupSegment>
public class RailwayTrack extends AbstractRailwayMarkup implements Iterable<MarkupSegment>, HasBoundingRectangle, HasCenterPoint
- See Also:
- Serialized Form
| Constructor | Description | 
|---|---|
| RailwayTrack() | |
| RailwayTrack | Deprecated.
 deprecated in version 8.4, will be removed in the future releases | 
| Modifier and Type | Method | Description | 
|---|---|---|
| void | addSegment | Adds segment to this markup element | 
| void | addToReservations | Reserve the track for certain trains | 
| void | arcTo | Adds arc segment with two circular arcs (available for markup elements
 created with no-argument constructor) | 
| void | block() | Block the track. | 
| void | cancelReservation() | Cancel existing reservations for the track. | 
| boolean | contains | Test if the shape contains the point with the given coordinates (relative
 to this shape's container, i.e. | 
| boolean | contains | Test if the shape contains the point with the given coordinates (relative
 to this shape's container, i.e. | 
| boolean | containsSq | Test if the shape contains the point with the given coordinates (relative
 to this shape's container, i.e. | 
| BoundingRectangle | getBoundingRectangle() | |
| Agent | getCar | 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 | 
| Position | getCenter | |
| Color | getColor() | Returns the color of the shape, or  nullif shape has no
 color or has textured (in this case#getFillTexture()should be
 used instead) | 
| TrackDataSource | getDataSource() | |
| PathDrawingType | getDrawingType() | Returns the drawing type of this path | 
| RailwaySwitch | getEndSwitch() | Get the switch at the end of the track | 
| Agent | getFirstCar() | Returns the car closest to the beginning of the track, or null if 
 the track is empty | 
| double | getFreeSpace | Tests the availability of space on the track. | 
| Agent | getLastCar() | Returns the car closest to the end of the track, or null if 
 the track is empty | 
| int | getNCars() | Deprecated.
 use  nCars() | 
| double | getNearestPoint | Calculates (using the  outputobject) the point in this space
 markup element nearest to the given (x, y, z) point. | 
| double | getNearestPoint | Calculates (using the  outputobject) the point in this space
 markup element nearest to the given (x, y, z) point. | 
| double | getNearestPoint | Calculates (using the  outputobject) the point in this space
 markup element nearest to the given (x, y) point. | 
| double | getNearestPoint | Calculates (using the  outputobject) the point in this space
 markup element nearest to the given (x, y) point. | 
| double | getNearestPointOnRay | Calculates the intersection point between this element and the given ray. | 
| double | getNearestPointOnRay | Calculates the intersection point between this element and the given ray. | 
| RailwaySwitch | getOtherSwitch | If the given switch is 'start switch' of this track, returns track's 'end switch',
 otherwise returns 'source switch'. | 
| Position | getPositionAtOffset | Returns the point located on the markup element with the given  offsetdistance calculated from start point. | 
| List<PositionOnTrack> | getPositionsOnTrack() | Returns a list of all PositionOnTrack elements on this track | 
| MarkupSegment | getSegment | Returns the segment by its index | 
| int | getSegmentCount() | Returns the number of segments | 
| RailwaySwitch | getStartSwitch() | Get the switch at the start of the track | 
| RailwaySwitch | getSwitch | Returns the switch at the beginning or at the end of the track. | 
| Texture | getTexture() | 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 | 
| double | getWidth() | Returns the width of the track. | 
| double | getWidth | Returns the width of the track. | 
| boolean | isAvailableFor | Check if the specified train can move through the track | 
| boolean | isBlocked() | Check if the track is blocked | 
| boolean | isEmpty() | Tests if the track is empty, i.e. | 
| Iterator<MarkupSegment> | iterator() | Creates and returns read-only iterator over segments | 
| final double | length() | Returns the length of the markup element, calculated in 3D space. | 
| final double | length | Returns the length of the markup element, calculated in 3D space. | 
| void | lineTo | Adds line segment (available for markup elements created with no-argument
 constructor) | 
| int | nCars() | Returns the number of cars on the track (including partially) | 
| void | removeFromReservations | Cancel existing reservations for specified trains | 
| List<Agent> | reservations() | Return all the trains that this track has been reserved for | 
| void | reserveFor | Reserve the track for certain trains | 
| void | setBlocked | Set track's block status | 
| void | setColor | Sets the color of the shape. | 
| void | setColor | Sets the color (or  Texture) of the shape. | 
| void | setDrawingType | Sets the drawing type of this path | 
| void | setWidth | Deprecated.
 this method is deprecated and may be removed in the next release. | 
| void | setWidth | Sets the width of the track, 0 means thinnest possible | 
| void | startDrawing | Starts drawing (available for markup elements created with no-argument
 constructor) | 
| Path3D | toPath3D() | Converts this markup element to  Path3Dinterface | 
| void | unblock() | Unblock the track and allow trains to move through it | 
error, getFullName, getPresentable, getSpace, initialize, isClickHandled, isOnly3D, isPublic, onClick, remove, setDrawMode, setOwnerdiscardOwner, executeUserAction, findSVGElement, getGroupOrOwner, getInspect, getInspectionWindowString, getName, getOrGenerateUSDId, getSVGComponent, getSVGId, initializeInternal, isVisible, onAggregatorInitialized, onAggregatorVisibilityChanged, removeSVGFromOwner, resetSVGState, setInspect, setVisible, updateDynamicProperties, updateDynamicPropertiesStructural, updateSVGPropertiespublic 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-
public List<PositionOnTrack> getPositionsOnTrack()
Returns a list of all PositionOnTrack elements on this track
- Returns:
- a list of all PositionOnTrack elements on this track
@AnyLogicInternalAPI public TrackDataSource getDataSource()
public void block()
Block the track. Trains that are on the track are allowed to leave the track but cannot enter it after that
public void unblock()
Unblock the track and allow trains to move through it
public boolean isBlocked()
Check if the track is blocked
- Returns:
- true if it is blocked, false - otherwise
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
public void reserveFor(Agent... trains) 
Reserve the track for certain trains
- Parameters:
- trains- Only these trains are allowed to move through the track
public void addToReservations(Agent... trains) 
Reserve the track for certain trains
- Parameters:
- trains- are added to the trains allowed to move through the track
public void removeFromReservations(Agent... trains) 
Cancel existing reservations for specified trains
- Parameters:
- trains- are added to the trains allowed to move through the track
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
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
public void cancelReservation()
Cancel existing reservations for the track. All trains will be able to move through the track, provided it is unblocked
public RailwaySwitch getStartSwitch()
Get the switch at the start of the track
- Returns:
- the switch at the start of the track
public RailwaySwitch getEndSwitch()
Get the switch at the end of the track
- Returns:
- the switch at the end of the track
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
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
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
public PathDrawingType getDrawingType()
Returns the drawing type of this path
- Returns:
- the drawing type of this path
public void setDrawingType(PathDrawingType drawingType) 
Sets the drawing type of this path
- Parameters:
- drawingType- the drawing type of this path
public void setColor(Color color) 
Sets the color of the shape.
- Parameters:
- color- the new color, null = do not draw the shape
public void setColor(Paint color) 
Sets the color (or 
Texture) of the shape.- Parameters:
- color- the new color, null = do not draw the shape
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
public Texture getTexture()
Returns the texture of the shape, if the shape has texture
- Returns:
- the texture of the shape
@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
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
public double getWidth()
Returns the width of the track.
- Returns:
- the width of the track, measured in pixels
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
public boolean contains(double px, double py) 
Description copied from class: 
MarkupShapeTest 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:
- containsin class- MarkupShape
- Parameters:
- px- the x coordinate relative to this shape's container
- py- the y coordinate relative to this shape's container
- Returns:
- trueif the shape contains the point with the given coordinates
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:
- trueif the shape contains the point with the given coordinates
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:
- trueif the shape contains the point with the given coordinates
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
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
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
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
public int getSegmentCount()
Returns the number of segments
- Returns:
- the number of segments
public MarkupSegment getSegment(int index) 
Returns the segment by its index
- Parameters:
- index- the segment index, [0 ..- getSegmentCount()- 1]
- Returns:
- the segment
public Iterator<MarkupSegment> iterator()
Creates and returns read-only iterator over segments
- Specified by:
- iteratorin interface- Iterable<MarkupSegment>
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
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
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
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.zis left unchanged.
- Returns:
- the square of distance to the nearest point in the horizontal (XY) projection
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.zis left unchanged.
- Returns:
- the square of distance to the nearest point in the horizontal (XY) projection
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
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
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 -1if there is no intersections with the given ray
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 -1if there is no intersections with the given ray
public Path3D toPath3D()
Converts this markup element to 
Path3D interfacepublic 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
public int nCars()
Returns the number of cars on the track (including partially)
- Returns:
- the number of cars on the track
- Since:
- 7.2
@Deprecated public int getNCars()
Deprecated.
use 
nCars()Returns the number of cars on the track (including partially)
- Returns:
- the number of cars on the track
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
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
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
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
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
@AnyLogicInternalAPI public BoundingRectangle getBoundingRectangle()
- Specified by:
- getBoundingRectanglein interface- HasBoundingRectangle
@AnyLogicInternalAPI public Position getCenter(Position out) 
- Specified by:
- getCenterin interface- HasCenterPoint