Search in sources :

Example 6 with TrainsCycleItem

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

the class StationTimetablesExtractor method addCycles.

private void addCycles(TimeInterval interval, TrainsCycleType type, List<CycleWithTypeFromTo> cycles, BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> nextItemF, BiFunction<TrainsCycle, TrainsCycleItem, TrainsCycleItem> previousItemF) {
    Train train = interval.getTrain();
    for (TrainsCycleItem item : train.getCycles(type)) {
        if (item.getToInterval() == interval) {
            // end
            TrainsCycle cycle = item.getCycle();
            TrainsCycleItem itemNext = nextItemF.apply(cycle, item);
            CycleWithTypeFromTo cycleFromTo = new CycleWithTypeFromTo(false, false, cycle.getName(), cycle.getDescription(), itemNext != null ? itemNext.getTrain().getName() : null, itemNext != null ? converter.convertIntToXml(itemNext.getStartTime()) : null);
            cycleFromTo.setTypeKey(type.getKey());
            cycleFromTo.setTypeName(type.getName());
            this.updateAdjacent(cycleFromTo, item, itemNext);
            cycles.add(cycleFromTo);
        }
        if (item.getFromInterval() == interval) {
            // start
            TrainsCycle cycle = item.getCycle();
            TrainsCycleItem itemPrev = previousItemF.apply(cycle, item);
            CycleWithTypeFromTo cycleFromTo = new CycleWithTypeFromTo(itemPrev == null, true, cycle.getName(), cycle.getDescription(), itemPrev != null ? itemPrev.getTrain().getName() : null, itemPrev != null ? converter.convertIntToXml(itemPrev.getEndTime()) : null);
            cycleFromTo.setTypeKey(type.getKey());
            cycleFromTo.setTypeName(type.getName());
            this.updateAdjacent(cycleFromTo, item, itemPrev);
            cycles.add(cycleFromTo);
        }
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) Train(net.parostroj.timetable.model.Train)

Example 7 with TrainsCycleItem

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

the class PositionsExtractor method getItemStarts.

private List<Pair<TrainsCycleItem, TimeInterval>> getItemStarts(Collection<TrainsCycle> cycles, Integer start) {
    int startingTime = start == null ? 0 : start;
    List<Pair<TrainsCycleItem, TimeInterval>> itemStarts = new ArrayList<>();
    for (TrainsCycle cycle : sortTrainsCycleList(cycles)) {
        TrainsCycleItem sItem = null;
        boolean added = false;
        for (TrainsCycleItem item : cycle) {
            Interval nInterval = IntervalFactory.createInterval(item.getStartTime(), item.getEndTime()).normalize();
            if (nInterval.isOverThreshold(startingTime)) {
                // go through intervals ...
                int lStartTime = startingTime + (startingTime < item.getStartTime() ? TimeInterval.DAY : 0);
                for (TimeInterval interval : Iterables.filter(item.getIntervals(), ModelPredicates::nodeInterval)) {
                    if (interval.isStop() && !interval.isLast() && interval.getEnd() >= lStartTime) {
                        itemStarts.add(new Pair<>(item, interval));
                        added = true;
                        break;
                    }
                }
            }
            if (sItem == null && nInterval.getStart() > startingTime) {
                sItem = item;
            }
        }
        if (!added) {
            if (sItem == null) {
                sItem = cycle.getFirstItem();
            }
            if (sItem != null) {
                itemStarts.add(new Pair<>(sItem, sItem.getFromInterval()));
            }
        }
    }
    return itemStarts;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TimeInterval(net.parostroj.timetable.model.TimeInterval) ArrayList(java.util.ArrayList) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) Pair(net.parostroj.timetable.utils.Pair) Interval(net.parostroj.timetable.model.Interval) TimeInterval(net.parostroj.timetable.model.TimeInterval)

Example 8 with TrainsCycleItem

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

the class TCDelegate method checkConflicts.

private void checkConflicts(TrainsCycle cycle, StringBuilder result) {
    List<Conflict> conflicts = checker.checkConflicts(cycle);
    TimeConverter c = cycle.getDiagram().getTimeConverter();
    for (Conflict item : conflicts) {
        TrainsCycleItem fromItem = item.getFrom();
        TrainsCycleItem toItem = item.getTo();
        for (ConflictType conflictType : item.getType()) {
            switch(conflictType) {
                case NODE:
                    addNewLineIfNotEmpty(result);
                    result.append(String.format("%s %s", ResourceLoader.getString("ec.problem.nodes"), formatItems(fromItem, toItem, c)));
                    if (!cycle.isPartOfSequence() && fromItem == cycle.getLastItem() && toItem == cycle.getFirstItem()) {
                        addNewLineIfNotEmpty(result);
                        result.append(ResourceLoader.getString("ec.problem.startend"));
                    }
                    break;
                case TIME:
                    addNewLineIfNotEmpty(result);
                    result.append(String.format("%s %s", ResourceLoader.getString("ec.problem.time"), formatItems(fromItem, toItem, c)));
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : Conflict(net.parostroj.timetable.actions.TrainsCycleChecker.Conflict) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) TimeConverter(net.parostroj.timetable.model.TimeConverter) ConflictType(net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType)

Example 9 with TrainsCycleItem

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

the class LocalizationTypeFactory method getCirculationItemDesc.

private static String getCirculationItemDesc(Reference<LocalizedString> ref) {
    TrainsCycleItem circulationItem = (TrainsCycleItem) ((AttributeReference<?>) ref).getHolder();
    String circDesc = circulationItem.getCycle().getDisplayDescription();
    String trainDesc = circulationItem.getTrain().getDefaultName();
    return String.format("%s (%s: %s)", trainDesc, circulationItem.getCycle().getName(), circDesc);
}
Also used : TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) LocalizedString(net.parostroj.timetable.model.LocalizedString)

Example 10 with TrainsCycleItem

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

the class LSTrainsCycleItem method createTrainsCycleItem.

public TrainsCycleItem createTrainsCycleItem(TrainsCycle cycle, TrainDiagram diagram) throws LSException {
    Train modelTrain = diagram.getTrains().getById(train);
    TrainsCycleItem item = new TrainsCycleItem(cycle, modelTrain, LocalizedString.fromString(comment), modelTrain.getIntervalById(from), modelTrain.getIntervalById(to));
    if (attributes != null) {
        item.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
    }
    return item;
}
Also used : TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) Train(net.parostroj.timetable.model.Train)

Aggregations

TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)12 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)6 Train (net.parostroj.timetable.model.Train)5 LinkedList (java.util.LinkedList)4 ArrayList (java.util.ArrayList)2 ConflictType (net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType)2 TimeConverter (net.parostroj.timetable.model.TimeConverter)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 List (java.util.List)1 Map (java.util.Map)1 TrainsCycleChecker (net.parostroj.timetable.actions.TrainsCycleChecker)1 Conflict (net.parostroj.timetable.actions.TrainsCycleChecker.Conflict)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 FNConnection (net.parostroj.timetable.model.FNConnection)1 Interval (net.parostroj.timetable.model.Interval)1 LocalizedString (net.parostroj.timetable.model.LocalizedString)1 TimeIntervalList (net.parostroj.timetable.model.TimeIntervalList)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)1 TranslatedString (net.parostroj.timetable.model.TranslatedString)1