routing/

postion.*

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().

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

Implements Position += length operator.

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

Implements Position -= length operator.

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

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
__weakref__

list of weak references to the object (if defined)

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

Dumps the position to JSON.

Returns:dict
initialize(simulation)[source]

Initialize position defined by parameters.

isNull()[source]
Returns:True if this Position is Null.
Return type:bool
isOut()[source]
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
isValid()[source]
Returns:True if this Position is valid.
Return type:bool
next(pos=0, direction=-1)[source]
Parameters:
  • pos – metre position
  • direction (int) –
Returns:

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:

Position

positionOnTI
Returns:float with distance of the Position from the end of the TrackItem connected to previousTI
previous(pos=None)[source]
Parameters:
  • pos – metre position
  • direction (int) –
Returns:

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:

Position

previousTI
Returns:TrackItem connected to this one from which to measure the distance of the Position
reversed()[source]
Returns:a position that is physically on the exact same place, but coming from the opposite direction
Return type:Position
trackItem
Returns:TrackItem on which this Position is
trackItemsToPosition(p)[source]
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

position

Returns the position this PositionGraphicsItem represents

updatePosition()[source]

Updates the position of this PositionGraphicsItem according to its Position.

route.*

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.

__eq__(other)[source]
Returns:True if two routes are equal if they have the same routeNum() routeNum or if both beginSignal and endSignal are equal
__gt__(other)[source]

Route is greater than other when its routeNum is greater

__init__(parameters)[source]

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
__lt__(other)[source]

Route is lower than other when its routeNum is lower

__ne__(other)[source]

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

activate(persistent=False)[source]

Called by the simulation when the route is activated.

appendDirection(tiId, direction)[source]

Appends a direction to a TrackItem on the Route.

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

Returns the SignalItem where this route starts.

createPositionsList()[source]

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

desactivate()[source]

Called by the simulation when the route is desactivated.

direction(tiId)[source]

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

directions

Returns the directions dictionary

endSignal

Returns the SignalItem where this route ends.

for_json()[source]

Dumps this route to JSON.

getRouteState()[source]
Returns:int - Returns the current route state:
  • 0 = Not activated
  • 1 = Activated, non persistent
  • 2 = Activated, persistent
initialState
Returns:int - the state of the route at the beginning of the simulation.
  • 0 = Not activated
  • 1 = Activated, non persistent
  • 2 = Activated, persistent
initialize(simulation)[source]

Initializes the route once all trackitems are loaded.

isActivable()[source]
Returns:True - if this route can be activated, i.e. that no other active route is conflicting with this route.
Parameters:
Returns:

True - if the route links si1 to si2.

persistent
Returns:True if this route is persistent
positions

Returns the positions list of this route.

routeNum

Returns this route number

setToInitialState()[source]

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

__init__(editor)[source]

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

flags(index)[source]

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.

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

Updates data when modified in the view