Switch

The Switch object represents a two-way railroad switch that connects three tracks: 0, 1, and 2. Depending on its state, the switch will direct the trains coming from track 0 (face point movement) to either track 1 or track 2. The trains coming from track 1 or 2 (trailing point movement) will always proceed to track 0 regardless of the state of the switch and will always force the switch to the corresponding state.

Switch is automatically created when you connect railway tracks. There should be exactly three tracks with end points in one point, and the switch will detect which of them are tracks 1 and 2 (alternative tracks) based on the angles between the track segments.

You can toggle the switch state by clicking within the circle, or via its API.

States of a switch and their animation

You do not need to use functions of switches too often: the Rail Library object TrainMoveTo is capable of setting up the switch states automatically when the train moves along a defined route. 

The switch is animated by the circle. You can customize Switch line color, Switch circle color (idle), Switch circle color (busy) in the RailSettings block. In addition, the state of the switch is shown with a thin line drawn over the circle.

Properties

General

Name – The name of the switch. The name is used to identify and access the switch from code and flowchart blocks properties.

Ignore – If selected, the switch is excluded from the model.

Visible on upper level – If selected, the switch is also visible on the upper level where this agent lives.

Lock – If selected, the switch is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you want to prevent editing this shape while drawing other shapes over it.

Visible – Here you specify whether the shape is visible on animation at model runtime, or not. Using the control, choose yes or no.

Advanced

Show in - This shape cannot be displayed in 3D.

Functions

RailwayTrack getSelectedTrack() - Returns the currently selected track (track 1 or 2).

void setSelectedTrack(RailwayTrack track) - Selects one of the two alternative tracks (1 or 2). If there is a car over the switch at that time, signals error.
        Parameter: track - the track to select

RailwayTrack getMainTrack() -  Returns the main track.

void toggle() - Toggles the selected tracks.

RailwayTrack nextTrack(RailwayTrack from) - Based on the state of the switch, returns the next track, given the switch is approached from a given track. 
        Parameter: from - the track from which the switch is being approached

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. Returns true if trailing point, false if facing point. 
        Parameter: from - the track by which the switch is being approached

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

List<RailwayTrack> getAlternativeTracks() - Returns the list of tracks connected to the switch. 

RailwayTrack getTrack( int index ) - Returns the track with a given index connected to the switch. 
        Parameter: index - the index of the track: 0, 1, or 2

RailwayNetwork getRailYard() - Returns the railway network this switch belongs to, or null if this switch is not a part of a railway network.

double getRadius() - Returns the radius of the switch.

void setRadius(double radius) - Sets the radius of the switch.
        Parameter: radius - the radius of the switch

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

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

void setSelectionColor(Color color) - Sets the color of the line animating the current switch position at model runtime.
        Parameter: color - the color the current switch position is highlighted with

boolean isVisible() - Returns true if the switch is visible; returns false otherwise.

void setVisible(boolean v) - Sets the visibility of the switch.
       Parameter: v - visibility. If v is true - the switch is set to be visible, if it is false - not visible.

double getX() - Returns the X-coordinate of the switch.

double getY() - Returns the Y-coordinate of the switch.

double getZ() - Returns the Z-coordinate of the switch.


Related topics

 Railway track

 Railway network

 Rail Library

 API Reference: RailwaySwitch Class