def findPreviousSignalPosition(self, pos=routing.Position()): """ Finds the position of the first signal behind the train head or the given position. @return The position of the first signal behind""" if pos == routing.Position(): cur = self._trainHead else: cur = pos while not cur.trackItem.tiType.startswith("E"): ti = cur.trackItem if ti.tiType.startswith("S"): if ti.isOnPosition(cur): return cur cur = cur.previous() return routing.Position()
def _setTrainHeadStr(self, value): """Setter function for the trainHeadStr property.""" if self.simulation.context == utils.Context.EDITOR_TRAINS: tiId, ptiId, posOnTI = eval(value.strip('()')) trackItem = self.simulation.trackItem(tiId) previousTI = self.simulation.trackItem(ptiId) self.trainHead = routing.Position(trackItem, previousTI, posOnTI)
def getNextSignalInfo(self, pos=routing.Position()): """Returns the position and distance of first signal ahead of the train head or ahead of the given position if specified""" retPos = routing.Position() retDist = -1 if pos == routing.Position(): pos = self._trainHead if not pos.trackItem.tiType.startswith("E"): cur = pos.next() while not cur.trackItem.tiType.startswith("E"): ti = cur.trackItem if ti.tiType.startswith("S"): if ti.isOnPosition(cur): retPos = cur break cur = cur.next() if retPos != routing.Position(): retDist = self._trainHead.distanceToPosition(retPos) return retPos, retDist
def graphicsMousePressEvent(self, event, itemId): """This function is called by the owned TrackGraphicsItem to handle its mousePressEvent. Reimplemented to send the positionSelected signal.""" super().graphicsMousePressEvent(event, itemId) #pos = event.buttonDownPos(Qt.LeftButton) if event.button() == Qt.LeftButton: #and self.graphicsItem.shape().contains(pos): if (self.simulation.context == utils.Context.EDITOR_TRAINS and self.tiId > 0): x = event.buttonDownPos(Qt.LeftButton).x() ratio = (x - self.line.x1()) / (self.line.x2() - self.line.x1()) self.positionSelected.emit( routing.Position(self, self.previousItem, self.realLength * ratio))
def __init__(self, simulation, parameters): """Constructor for the Train class""" super().__init__() self.simulation = simulation self._serviceCode = parameters["servicecode"] self._trainType = self.simulation.trainTypes[parameters["traintype"]] self._speed = 0 self._initialSpeed = float(parameters["speed"]) self._accel = 0 tiId = parameters["tiid"] previousTiId = parameters["previoustiid"] posOnTI = parameters["posonti"] self._trainHead = routing.Position( self.simulation.trackItem(tiId), self.simulation.trackItem(previousTiId), posOnTI) self._status = TrainStatus.INACTIVE self._lastSignal = None self._signalActions = [(0, 999)] self._applicableActionIndex = 0 self._stoppedTime = 0 if "stoppedtime" in parameters: self._stoppedTime = parameters["stoppedtime"] self.updateMinimumStopTime() self._initialDelayProba = utils.DurationProba( parameters["initialdelay"]) self.setInitialDelay() if self.currentService is not None: self._nextPlaceIndex = 0 if "nextplaceindex" in parameters: self._nextPlaceIndex = parameters["nextplaceindex"] else: self._nextPlaceIndex = None self._appearTime = QtCore.QTime.fromString(parameters["appeartime"]) self.simulation.timeElapsed.connect(self.advance) self.simulation.timeChanged.connect(self.activate) # FIXME Throw back all these actions to MainWindow self.assignAction = QtGui.QAction(self.tr("Reassign service..."), self) self.assignAction.triggered.connect(self.reassignService) self.resetServiceAction = QtGui.QAction(self.tr("Reset service"), self) self.resetServiceAction.triggered.connect(self.resetService) self.reverseAction = QtGui.QAction(self.tr("Reverse"), self) self.reverseAction.triggered.connect(self.reverse)
def findPreviousSignal(self, pos=routing.Position()): """ @return The first signal behind the train head""" return self.findPreviousSignalPosition(pos).trackItem
def getDistanceToNextSignal(self, pos=routing.Position()): """Returns the distance to the next Signal""" nsp, nsd = self.getNextSignalInfo(pos) return nsd
def findNextSignal(self, pos=routing.Position()): """ @return The first signal ahead the train head or ahead of the given position if specified""" nsp, nsd = self.getNextSignalInfo(pos) return nsp.trackItem