Search in sources :

Example 1 with TranslatedString

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

the class TrainTimetablesExtractor method getConcurrentTrains.

private Pair<Boolean, List<TranslatedString>> getConcurrentTrains(TimeInterval interval) {
    TrainComparator comparator = diagram.getTrainsData().getTrainComparator();
    Node node = interval.getOwnerAsNode();
    TimeInterval toBeChecked = interval;
    Train train = interval.getTrain();
    if (interval.isFirst() && train.getTimeIntervalBefore() != null)
        toBeChecked = train.getTimeIntervalBefore();
    else if (interval.isLast() && train.getTimeIntervalAfter() != null)
        toBeChecked = train.getTimeIntervalAfter();
    Set<TimeInterval> over = node.getOverlappingTimeIntervals(toBeChecked);
    boolean first = true;
    // check if the train is first in the station (start be marked with trapezoid)
    if (!interval.isFirst())
        for (Iterator<TimeInterval> i = over.iterator(); i.hasNext(); ) {
            TimeInterval checked = i.next();
            if (interval.getStart() > checked.getStart() || (interval.getStart() == checked.getStart() && comparator.compare(interval.getTrain(), checked.getTrain()) >= 0)) {
                first = false;
                break;
            }
        }
    if (over.isEmpty()) {
        return null;
    } else {
        List<Train> tTrains = new ArrayList<>(over.size());
        for (TimeInterval ti : over) {
            if (!tTrains.contains(ti.getTrain()))
                tTrains.add(ti.getTrain());
        }
        ElementSort<Train> s = new ElementSort<>(new TrainComparator(node.getDiagram().getTrainsData().getTrainSortPattern()));
        tTrains = s.sort(tTrains);
        List<TranslatedString> result = new LinkedList<>();
        for (Train t : tTrains) {
            result.add(t.getName());
        }
        return new Pair<>(first, result);
    }
}
Also used : TranslatedString(net.parostroj.timetable.model.TranslatedString) TimeInterval(net.parostroj.timetable.model.TimeInterval) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) ElementSort(net.parostroj.timetable.actions.ElementSort) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) TrainComparator(net.parostroj.timetable.actions.TrainComparator) Train(net.parostroj.timetable.model.Train) Pair(net.parostroj.timetable.utils.Pair)

Example 2 with TranslatedString

use of net.parostroj.timetable.model.TranslatedString 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 3 with TranslatedString

use of net.parostroj.timetable.model.TranslatedString 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)3 LinkedList (java.util.LinkedList)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 List (java.util.List)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 Train (net.parostroj.timetable.model.Train)2 FreightConnection (net.parostroj.timetable.model.freight.FreightConnection)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 ElementSort (net.parostroj.timetable.actions.ElementSort)1 TrainComparator (net.parostroj.timetable.actions.TrainComparator)1 FNConnection (net.parostroj.timetable.model.FNConnection)1 LineClass (net.parostroj.timetable.model.LineClass)1 Node (net.parostroj.timetable.model.Node)1 TimeIntervalList (net.parostroj.timetable.model.TimeIntervalList)1 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)1 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)1 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)1 Pair (net.parostroj.timetable.utils.Pair)1