trains/

train.*

class ts2.trains.train.Train(parameters)[source]

Bases: PyQt5.QtCore.QObject

A Train is a stock running on a track at a certain speed and to which is assigned a Service .

__init__(parameters)[source]
Parameters:paramaters (dict) –
actionTime
Returns:the time at which the current action has been achieved or 0.
Return type:QTime or 0
activate(time)[source]

Activate this Train if time is after this Train‘s appearTime().

advance(secs)[source]

Advances the train by a step corresponding to the elapsed secs, and executes all the associated actions.

appearTimeStr

Returns the time at which this train appears on the scene as a String.

applicableActionIndex

Returns the applicable action in the action list.

calculatedSpeed(targetDistance, targetSpeedAtPos)[source]

Returns the speed the train should be right now to be able to be at a speed of targetSpeedAtPos at a distance of targetDistance from the train head, not exceeding maxSpeed. This function does not take into account any sampling margin.

currentService

Returns the Service object assigned to this train

drawTrain(advanceLength=0)[source]

This function draws the train on the scene by setting the correct trainHead and trainTail to the different trackItems met.

:param advanceLength : The length that the train has advanced since the last call to this function.

executeActions(advanceLength)[source]

Execute actions that have to be done when the train head enters a trackItem or when the train tail leaves another. For each case this is done in two stages: - first execute actions related to the train itself and - then call TrackItem.trainHeadActions() or TrackItem.trainTailActions()).

findNextSignal(pos=<ts2.routing.position.Position object>)[source]

@return The first signal ahead the train head or ahead of the given position if specified

findPreviousSignal(pos=<ts2.routing.position.Position object>)[source]

@return The first signal behind the train head

findPreviousSignalPosition(pos=<ts2.routing.position.Position object>)[source]

Finds the position of the first signal behind the train head or the given position. @return The position of the first signal behind

for_json()[source]

Dumps this train to JSON.

getDistanceToNextSignal(pos=<ts2.routing.position.Position object>)[source]

Returns the distance to the next Signal

getDistanceToNextStop(maxDistance)[source]

Returns the distance to the next stop by looking forward of the _trainHead up to a maximum distance of maxDistance.

getDistanceToNextTrain(maxDistance, trackCircuit=False)[source]

Returns the distance to the next train by looking forward of the _trainHead up to a maximum distance of maxDistance. If trackCircuit is True, then the distance is given to the trackItem on which a train is present. Otherwise, the real distance to the train is returned.

getMaximumSpeed()[source]

Returns the maximum speed allowed for the train in its current position

getNextSignalInfo(pos=None)[source]
Parameters:pos (Position) –
Returns:
  • the position and distance of first signal ahead of the train head
  • or ahead of the given position if specified
Return type:(Position, int)
getNextSpeedLimitInfo(maxDistance)[source]
Parameters:maxDistance (int) – The maximum distance to look ahead
Returns:the next speed limit and the distance at which it starts, looking at each trackitem forward of the trainHead up to a maximum distance of maxDistance.
Return type:(int, ?)
initialDelay
Returns:the number of seconds of delay that this train had when it was activated.
Return type:int
initialDelayStr

Returns the initialDelay probability function as a string.

initialSpeed

Returns the initial speed of the train, i.e. the speed it has when it appears on the scene

initialize(simulation)[source]

Initialize the train once everything else is loaded. :param simulation: The simulation on which to initialize this Train :type simulation: simulation.Simulation

isActive()[source]
Returns:True if the train is in the area and its current service is not finished
Return type:bool
isOnScenery()[source]
Returns:True if the train is on the scenery
Return type:bool
isOut()[source]
Returns:True if the train exited the area
Return type:bool
jumpToNextPlace()[source]

Set the nextPlaceIndex to the next serviceLine. If there is no serviceLine after the current one, change the service of the train to nextService if any.

lastSignal

Returns the last signal that the driver has seen, which may be the one just in front.

minimumStopTime
Returns:the minimum stopping time for next station
Return type:int
nextPlaceIndex

Returns the index of the next place, that is the index of the ServiceLine of the current service pointing to the next place the train is scheduled to. :rtype : int

reassignService()[source]

Pops up a dialog for the user to choose the new service and reassign it to this train, if the service is not already assigned to another train

resetService()[source]

Resets the service, i.e. sets the pointer to the first station.

reverse()[source]

Reverses the train direction.

serviceCode
Returns:the service code of this train
Return type:str
setInitialDelay()[source]

Sets up the initial delay variable.

setSpeed(secs)[source]

Sets the speed of the train.

Param:secs: Number of seconds (in the game) between two clock

ticks.

showTrainActionsMenu(widget, pos)[source]

Pops-up the train actions menu on the given QWidget

shunting
Returns:True if the train is shunting False otherwise
signalActions

Returns the list of actions asked by the last seen signal. List of (target, speed) tuples.

speed

Returns the current speed of the Train.

splitTrain(splitIndex)[source]

Splits this train at the given index. :param splitIndex: The index at which to split the train. 1 is between the first and second element, 2 between the second and third, etc. counting from the train head.

splitTrainPopUp()[source]

Pops up a dialog for the user to choose where to split the train and then split it.

status
Returns:the status of the train
Return type:TrainStatus
stoppedTime
Returns:the number of seconds that this train is stopped at then current station.
Return type:int
targetSpeed(secs, targetDistance=-1, targetSpeedAtPos=0)[source]

Defines the current target speed of the train depending on the parameters.

Parameters:
  • targetDistance – the distance at which the train should be at targetSpeedAtPos
  • targetSpeedAtPos – the target speed when the train will be at targetDistance
Returns:

the current target speed for the train, including sampling margin.

Return type:

float

trainHead
Returns:the Position of the head of this train.
Return type:Position
trainHeadStr
Returns:the Position of the head of this train.
Return type:str
trainId

Returns the train Id which is index of this train inside the train list of the simulation.

trainType
Returns:The TrainType of this Train
Return type:TrainType
trainTypeCode

Returns the code of the train type

updateMinimumStopTime()[source]

Updates the minimum stopping time for next station.

updateSignalActions()[source]

Updates the applicable signal actions list based on the position of the train and the visible signal.

updateStatus(secs)[source]

Updates the status of the train

class ts2.trains.train.TrainInfoModel(simulation)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for displaying a single service information in a view

__init__(simulation)[source]

Constructor for the TrainInfoModel 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(column, orientation, role=0)[source]

Returns the headers for this model

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

Returns the number of rows in the model

setTrainByTrainId(trainId)[source]

Sets the train instance associated with this model from its trainId

train

Returns the train instance associated with this model

update()[source]

Emits the dataChanged signal for the lines that may change.

updateSpeed()[source]

Emits the dataChanged signal for the speed only.

class ts2.trains.train.TrainListModel(simulation)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for displaying trains as a list during the game.

__init__(simulation)[source]

Constructor for the TrainListModel class

columnCount(parent=<PyQt5.QtCore.QModelIndex object>, *args)[source]

Returns the number of columns of the model @TODO ?? wtf

data(index, role=0)[source]

Returns the data at the given index

flags(index)[source]

Returns the flags of the model

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

Returns the column headers to display

rowCount(parent=<PyQt5.QtCore.QModelIndex object>, *args)[source]

Returns the number of rows of the model, corresponding to the number of trains of the simulation

update(trainId)[source]

Emits the dataChanged signal for the train defined by trainId.

class ts2.trains.train.TrainStatus[source]

Bases: PyQt5.QtCore.QObject

Holds the enum describing the status of a Train

END_OF_SERVICE = 50

Ended its service and no new service assigned

INACTIVE = 0

Not yet entered on the scene

OUT = 40

Exited the area

RUNNING = 10

Running with a positive speed

STOPPED = 20

Scheduled stop, e.g. at a station

WAITING = 30

Unscheduled stop, e.g. at a red signal

classmethod text(status)[source]
Returns:Text corresponding to each status to display in the application
Return type:str
class ts2.trains.train.TrainsModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for displaying trains as a list in the editor

__init__(editor)[source]

Constructor for the TrainsModel class

columnCount(parent=None, *args)[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(column, orientation, role=0)[source]

Returns the column headers to display

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

Returns the number of rows of the model, corresponding to the number of trains of the editor

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

Updates data when modified in the view

simulation

Returns the simulation this model is attached to.

ts2.trains.train.translate(str, str, str disambiguation=None, int n=-1) → str

service.*

class ts2.trains.service.Service(parameters)[source]

Bases: object

A Service is mainly a predefined schedule that trains are supposed to follow with a few additional informations. The schedule is composed of several “lines” of type ServiceLine

__init__(parameters)[source]

Constructor for the Service class

__weakref__

list of weak references to the object (if defined)

autoReverse

Returns true if the train is to be reversed when the service ends

description

Returns the service code

entryPlaceName

Returns the place of entry of the train as a string

exitPlaceName

Returns the place where the train is due to exit as a string.

for_json()[source]

Data for JSON dump.

getEntryPlaceData()[source]

Returns the placeCode and trackCode of the entry point of the train

initialize(simulation)[source]

Initialize the service once the simulation is loaded.

lines

Returns the lines of this service

nextServiceCode

Returns the service code that should be assigned to the train that just ended this service

plannedTrainType

Returns the planned train type code (string) for this service, which is not necessarily the actual train type of the train to which this service is assigned.

serviceCode

Returns the service code

class ts2.trains.service.ServiceInfoModel(simulation)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for displaying a single service information in a view

__init__(simulation)[source]

Constructor for the ServiceInfoModel 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(column, 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 serviceLines of this service.

setServiceCode(serviceCode)[source]

Sets the service linked with this model from its serviceCode.

class ts2.trains.service.ServiceLine(parameters)[source]

Bases: object

A serviceLine is a line of the definition of the service. It consists of a place (usually a station) with a track number and scheduled times to arrive at and depart from this station.

__eq__(other)[source]

Equal operator

__init__(parameters)[source]

Constructor for the ServiceLine class

__weakref__

list of weak references to the object (if defined)

for_json()[source]

Dumps this service line to JSON.

initialize(service)[source]

Initialize the serviceLine for the given service.

mustStop

Returns true if this service is supposed to stop at the place of this ServiceLine

place

Returns the place of this ServiceLine

placeCode

Returns the place code of this ServiceLine

scheduledArrivalTime

Returns the scheduled arrival time of this service at the place of this ServiceLine, as a QTime

scheduledArrivalTimeStr

Returns the scheduled arrival time of this service at the place of this ServiceLine as a string

scheduledDepartureTime

Returns the scheduled departure time of this service at the place of this ServiceLine, as a QTime

scheduledDepartureTimeStr

Returns the scheduled departure time of this service at the place of this ServiceLine, as a string

service

Returns the service this ServiceLine belongs to

trackCode

Returns the trackCode of this ServiceLine

class ts2.trains.service.ServiceLinesModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for ServiceLine class used in the editor

__init__(editor)[source]

Constructor for the ServicesModel 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 serviceLines of this service

service

Returns the service this model is attached to

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

Updates data when modified in the view

setServiceCode(serviceCode)[source]

Sets the service linked with this model from its serviceCode.

simulation

Returns the editor of this model.

class ts2.trains.service.ServiceListModel(simulation)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for displaying services during the game. This model makes a copy of the services of the simulation at the time it is created.

__init__(simulation)[source]

Constructor for the ServiceInfoModel 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 services in the simulation.

updateModel()[source]

Updates the internal copy of the services with the simulation services.

class ts2.trains.service.ServicesModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for Service class used in the editor

__init__(editor)[source]

Constructor for the ServicesModel 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 services of the editor

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

Updates data when modified in the view

simulation

Returns the simulation this model belongs to.

traintype.*

class ts2.trains.traintype.TrainType(parameters)[source]

Bases: object

The TrainType class holds information relating to rolling stock types.

__init__(parameters)[source]

Constructor for the TrainType class

__weakref__

list of weak references to the object (if defined)

code
Returns:the unique code of this rolling stock type
Return type:str
description
Returns:the description of this rolling stock type
Return type:str
elements
Returns:The list of TrainType elements

that constitute this train type.

elementsStr
Returns:A string representation of the list of other

TrainType that constitute this rolling stock. Returns “[]” if this TrainType cannot be divided. :rtype: str

emergBraking
Returns:the emergency braking of this rolling stock type, in m/s2. Emergency braking is the maximum rate at which a train can reduce its speed in case of a danger ahead.
Return type:float
for_json()[source]

Dumps this trainType to JSON

initialize(simulation)[source]

Initializes the simulation variable once it is loaded.

length
Returns:the length of this rolling stock type in meters
Return type:int
maxSpeed
Returns:the maximum speed that this rolling stock type is capable, in

m/s :rtype: float

stdAccel
Returns:the standard acceleration of this rolling stock type, in m/s2
Return type:float
stdBraking
Returns:The standard braking of this rolling stock type, in m/s2. The standard braking is the normal rate at which speed will be reduced when approaching a speed limit, a station, a signal, etc.
Return type:float
class ts2.trains.traintype.TrainTypesModel(editor)[source]

Bases: PyQt5.QtCore.QAbstractTableModel

Model for TrainType class used in the editor

__init__(editor)[source]

Constructor for the TrainTypesModel 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 rolling stock types.

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

Updates data when modified in the view