Search in sources :

Example 6 with TrainsCycle

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

the class TCListView method deleteButtonActionPerformed.

private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {
    // get selected cycles ...
    int[] selectedIndices = cyclesList.getSelectedIndices();
    List<TrainsCycle> toBeDeleted = new ArrayList<>(selectedIndices.length);
    for (int selectedIndex : selectedIndices) {
        TrainsCycle cycle = cycles.getIndex(selectedIndex).getElement();
        toBeDeleted.add(cycle);
    }
    for (TrainsCycle cycle : toBeDeleted) {
        if (cycle != null) {
            // remove from diagram
            cycle.getType().getCycles().remove(cycle);
            // fire event
            delegate.fireEvent(TCDelegate.Action.DELETED_CYCLE, cycle);
        }
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) ArrayList(java.util.ArrayList)

Example 7 with TrainsCycle

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

the class StationTimetablesExtractor method addEnginesAndTrainUnits.

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

Example 8 with TrainsCycle

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

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

use of net.parostroj.timetable.model.TrainsCycle 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)

Aggregations

TrainsCycle (net.parostroj.timetable.model.TrainsCycle)18 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)6 Train (net.parostroj.timetable.model.Train)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)3 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)3 Route (net.parostroj.timetable.model.Route)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1