class ts2.routing.position.Position(trackItem=None, previousTI=None, positionOnTI=0.0, parameters=None)[source]

Bases: object

A Position object is a point on a TrackItem.

A Position is defined as being positionOnTI() meters away from the end of the TrackItem that is connected to TrackItem previousTI(). Note that a Position has a direction, so that for any point on a TrackItem, there are two Positions that can be defined:

  • one starting from one end of the TrackItem
  • the other starting from the other end.

You can get the other Position by calling reversed().

Parameters:length (float) – meters to add to this position
Returns:the position that is length meters ahead of this position.
Return type:Position
Parameters:p (Position) –
Returns:True if p is the same Position as this one.
Return type:bool

Implements Position += length operator.

Returns:new position
Return type:Position
__init__(trackItem=None, previousTI=None, positionOnTI=0.0, parameters=None)[source]
  • trackItem
  • previousTI
  • positionOnTI
  • parameters

Implements Position -= length operator.

Returns:new position
Return type:Position
Parameters:p (Position) –
Returns:True if p is not the same Position as this one..
Return type:bool
Returns:a string representation of the position, which is (trackItem.tiId, previousTI.tiId, positionOnTI)
Return type:str

Returns the position that is length meters behind this Position.

Parameters:length (float) – length in meters to add to this position
Returns:The new position
Return type:Position

list of weak references to the object (if defined)

Parameters:p (Position) –
Returns:The distance between the current position and p. if p is ahead of current position, otherwise zero
Return type:float

Dumps the position to JSON.


Initialize position defined by parameters.

Returns:True if this Position is Null.
Return type:bool
Returns:True if this position is out of the scenery, going outwards i.e. on an EndItem with a previous item that is not None.
Return type:bool
Returns:True if this Position is valid.
Return type:bool
next(pos=0, direction=-1)[source]
  • pos – metre position
  • direction (int) –

A Position on the next TrackItem (i.e. the TrackItem connected to this one which is not previousTI) at pos meters from the connection of the next TrackItem to this one. By default, pos is 0.

Return type:


Returns:float with distance of the Position from the end of the TrackItem connected to previousTI
  • pos – metre position
  • direction (int) –

a Position on the previous TrackItem (i.e. previousTI), running backwards, at pos meters from the end behind (i.e. the end not connected to this TrackItem). By default, pos is equal to the length of the previous Item, so that the position is on the connection point with this TrackItem.

Return type:


Returns:TrackItem connected to this one from which to measure the distance of the Position
Returns:a position that is physically on the exact same place, but coming from the opposite direction
Return type:Position
Returns:TrackItem on which this Position is
Parameters:p (Position) –
Returns:a list of all the trackItems between this position and position p including the trackItem of this position and the trackItem of position p.
Return type:a list of TrackItem‘s
class ts2.routing.position.PositionGraphicsItem(simulation, position=None, parent=None)[source]

Bases: PyQt5.QtWidgets.QGraphicsPolygonItem

This class is a graphics representation of a position to be put on a scene.

__init__(simulation, position=None, parent=None)[source]

Constructor for the PositionGraphicsItem class


Returns the position this PositionGraphicsItem represents


Updates the position of this PositionGraphicsItem according to its Position.


class ts2.routing.route.Route(parameters)[source]

Bases: PyQt5.QtCore.QObject

A Path between two signals

A route is a path between two signals. If a route is activated, the path is selected, and the signals at the beginning and the end of the route are changed and the conflicting possible other routes are inhibited. Routes are static and defined in the game file. The player can only activate or deactivate them.

Returns:True if two routes are equal if they have the same routeNum() routeNum or if both beginSignal and endSignal are equal

Route is greater than other when its routeNum is greater


After construction, the directions dictionary must be filled and then the _positions list must be populated by calling createPositionsList()

Parameters:parameters – json dict with data to create the route

Route is lower than other when its routeNum is lower


Two routes are not equal if they have different routeNum and if at least one of beginSignal or endSignal is different


Called by the simulation when the route is activated.

appendDirection(tiId, direction)[source]

Appends a direction to a TrackItem on the Route.

  • tiId – The trackItem number to which we add direction
  • direction – The direction to append. For points, 0 means normal and other values means reverse

Returns the SignalItem where this route starts.


Populates the _positions list. If the route is invalid, it leaves the _positions list empty. Also completes the _directions map, with obvious directions.


Called by the simulation when the route is desactivated.


Returns the direction of this route at the trackItem with id tiId


Returns the directions dictionary


Returns the SignalItem where this route ends.


Dumps this route to JSON.

Returns:int - Returns the current route state:
  • 0 = Not activated
  • 1 = Activated, non persistent
  • 2 = Activated, persistent
Returns:int - the state of the route at the beginning of the simulation.
  • 0 = Not activated
  • 1 = Activated, non persistent
  • 2 = Activated, persistent

Initializes the route once all trackitems are loaded.

Returns:True - if this route can be activated, i.e. that no other active route is conflicting with this route.

True - if the route links si1 to si2.

Returns:True if this route is persistent

Returns the positions list of this route.


Returns this route number


Setup routes according to their initial state.

class ts2.routing.route.RoutesModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

The RoutesModel is a table model for routes that is used in the editor


Constructor for the RoutesModel class

columnCount(parent=None, *args, **kwargs)[source]

Returns the number of columns of the model

data(index, role=0)[source]

Returns the data at the given index


Returns the flags of the model

headerData(section, orientation, role=0)[source]

Returns the header labels

rowCount(parent=None, *args, **kwargs)[source]

Returns the number of rows of the model, corresponding to the number of routes.

setData(index, value, role=None)[source]

Updates data when modified in the view