Search in sources :

Example 1 with FreightConnection

use of net.parostroj.timetable.model.freight.FreightConnection in project grafikon by jub77.

the class StationTimetablesExtractor method addOtherData.

private void addOtherData(TimeInterval interval, StationTimetableRow row) {
    // technological time handle differently
    row.setTechnologicalTime(interval.isTechnological());
    if (row.isTechnologicalTime()) {
        return;
    }
    row.setLength(this.getLength(interval));
    BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> nextF = getNextFunction();
    BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> previousF = getPreviousFunction();
    this.addEnginesAndTrainUnits(interval, diagram.getEngineCycleType(), row.getEngine(), nextF, previousF);
    this.addEnginesAndTrainUnits(interval, diagram.getTrainUnitCycleType(), row.getTrainUnit(), nextF, previousF);
    for (TrainsCycleType type : diagram.getCycleTypes()) {
        if (!type.isDefaultType()) {
            this.addCycles(interval, type, row.getCycle(), nextF, previousF);
        }
    }
    if (interval.isFreight()) {
        List<? extends FreightConnection> freightDests = strategy.getFreightToNodes(interval);
        if (!freightDests.isEmpty()) {
            ArrayList<FreightDestinationInfo> fl = new ArrayList<>(freightDests.size());
            for (FreightConnection dst : freightDests) {
                fl.add(FreightDestinationInfo.convert(locale, dst));
            }
            row.setFreightTo(fl);
        }
    }
    if (interval.isFreightConnection()) {
        Map<Train, List<FreightConnectionPath>> passedCargoDst = strategy.getFreightPassedInNode(interval);
        if (!passedCargoDst.isEmpty()) {
            List<FreightToTrain> fttl = new ArrayList<>();
            for (Map.Entry<Train, List<FreightConnectionPath>> entry : passedCargoDst.entrySet()) {
                FreightToTrain ftt = new FreightToTrain();
                ftt.setTrain(entry.getKey().getName());
                List<? extends FreightConnection> mList = entry.getValue();
                List<FreightDestinationInfo> fl = new ArrayList<>(mList.size());
                for (FreightConnection dst : mList) {
                    fl.add(FreightDestinationInfo.convert(locale, dst));
                }
                ftt.setFreightTo(fl);
                fttl.add(ftt);
            }
            row.setFreightToTrain(fttl);
        }
    }
    List<FNConnection> trainsFrom = diagram.getFreightNet().getTrainsTo(interval);
    if (!trainsFrom.isEmpty()) {
        ArrayList<TranslatedString> nt = new ArrayList<>(trainsFrom.size());
        for (FNConnection conn : trainsFrom) {
            nt.add(conn.getFrom().getTrain().getName());
        }
        row.setFreightFromTrain(nt);
    }
    row.setComment(interval.getComment());
    row.setOccupied(interval.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED));
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TranslatedString(net.parostroj.timetable.model.TranslatedString) ArrayList(java.util.ArrayList) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) FreightConnection(net.parostroj.timetable.model.freight.FreightConnection) ArrayList(java.util.ArrayList) TimeIntervalList(net.parostroj.timetable.model.TimeIntervalList) LinkedList(java.util.LinkedList) List(java.util.List) Train(net.parostroj.timetable.model.Train) Map(java.util.Map) FNConnection(net.parostroj.timetable.model.FNConnection) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType)

Example 2 with FreightConnection

use of net.parostroj.timetable.model.freight.FreightConnection in project grafikon by jub77.

the class TrainTimetablesExtractor method extractRows.

private void extractRows(Train train, TrainTimetable timetable) {
    timetable.setRows(new LinkedList<TrainTimetableRow>());
    Iterator<TimeInterval> i = train.getTimeIntervalList().iterator();
    TimeInterval lastLineI = null;
    while (i.hasNext()) {
        TimeInterval nodeI = i.next();
        TimeInterval lineI = i.hasNext() ? i.next() : null;
        if (nodeI.getOwnerAsNode().getType() == NodeType.SIGNAL) {
            lastLineI = lineI;
            continue;
        }
        TrainTimetableRow row = new TrainTimetableRow();
        row.setRef(nodeI);
        if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_CONTROL_STATION)) {
            row.setControlStation(true);
        }
        if (Node.IP_NEW_SIGNALS.equals(nodeI.getOwnerAsNode().getAttribute(Node.ATTR_INTERLOCKING_PLANT, String.class))) {
            row.setLightSignals(true);
        }
        row.setStation(nodeI.getOwnerAsNode().getName());
        row.setStationAbbr(nodeI.getOwnerAsNode().getAbbr());
        row.setStationType(nodeI.getOwnerAsNode().getType().getKey());
        if (!nodeI.isFirst())
            row.setArrival(diagram.getTimeConverter().convertIntToXml(nodeI.getStart()));
        if (!nodeI.isLast())
            row.setDeparture(diagram.getTimeConverter().convertIntToXml(nodeI.getEnd()));
        if (lineI != null) {
            row.setSpeed(lineI.getSpeed());
            row.setLineTracks(lineI.getOwnerAsLine().getTracks().size());
            row.setSetSpeed(lineI.getAttribute(TimeInterval.ATTR_SET_SPEED, Integer.class));
        }
        // comment
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_COMMENT_SHOWN)) {
            row.setComment(nodeI.getComment());
        }
        // check line end
        if ((nodeI.isLast() || nodeI.isInnerStop()) && nodeI.getTrack().getAttributes().getBool(Track.ATTR_LINE_END)) {
            row.setLineEnd(Boolean.TRUE);
        }
        // check occupied track
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED)) {
            row.setOccupied(Boolean.TRUE);
        }
        // check shunt
        if (nodeI.getAttributes().getBool(TimeInterval.ATTR_SHUNT)) {
            row.setShunt(Boolean.TRUE);
        }
        if (nodeI.getOwnerAsNode().getTracks().size() > 1)
            row.setTrack(nodeI.getTrack().getNumber());
        boolean onControlled = checkOnControlled(nodeI.getOwnerAsNode());
        if (onControlled)
            row.setOnControlled(true);
        if (lastLineI != null && lastLineI.getToStraightTrack() != null)
            row.setStraight(lastLineI.getToStraightTrack() == nodeI.getTrack());
        if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_TRAPEZOID_SIGN)) {
            Pair<Boolean, List<TranslatedString>> concurrentTrains = this.getConcurrentTrains(nodeI);
            if (concurrentTrains != null) {
                row.setConcurrentTrains(concurrentTrains.second);
                row.setFirstConcurrent(concurrentTrains.first);
            }
        }
        LineClass lineClass = lineI != null ? lineI.getLineClass() : null;
        if (lineClass != null)
            row.setLineClass(lineClass.getName());
        // route position
        Double routePosition = null;
        Double routePositionOut = null;
        if (lineI != null)
            routePositionOut = this.getRoutePosition(lineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
        if (lastLineI != null)
            routePosition = this.getRoutePosition(lastLineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
        if (routePosition == null)
            routePosition = routePositionOut;
        if (routePosition != null && routePositionOut != null && routePosition.doubleValue() == routePositionOut.doubleValue())
            routePositionOut = null;
        row.setRoutePosition(routePosition);
        row.setRoutePositionOut(routePositionOut);
        // freight
        if (nodeI.isFirst() && nodeI.isFreight()) {
            List<? extends FreightConnection> freightDests = strategy.getFreightToNodes(nodeI);
            if (!freightDests.isEmpty()) {
                ArrayList<FreightDestinationInfo> fl = new ArrayList<>(freightDests.size());
                for (FreightConnection dst : freightDests) {
                    fl.add(FreightDestinationInfo.convert(locale, dst));
                }
                row.setFreightDest(fl);
            }
        }
        timetable.getRows().add(row);
        lastLineI = lineI;
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) ArrayList(java.util.ArrayList) TranslatedString(net.parostroj.timetable.model.TranslatedString) FreightConnection(net.parostroj.timetable.model.freight.FreightConnection) LineClass(net.parostroj.timetable.model.LineClass) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TranslatedString (net.parostroj.timetable.model.TranslatedString)2 FreightConnection (net.parostroj.timetable.model.freight.FreightConnection)2 Map (java.util.Map)1 FNConnection (net.parostroj.timetable.model.FNConnection)1 LineClass (net.parostroj.timetable.model.LineClass)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 TimeIntervalList (net.parostroj.timetable.model.TimeIntervalList)1 Train (net.parostroj.timetable.model.Train)1 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)1 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)1 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)1