Search in sources :

Example 11 with Train

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

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

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

the class TrainRegionCollector method getItemsForPoint.

@Override
public List<TimeInterval> getItemsForPoint(int x, int y, int radius) {
    Rectangle2D cursor = new Rectangle2D.Double(x - radius, y - radius, radius * 2, radius * 2);
    LinkedList<TimeInterval> list = new LinkedList<>();
    for (Train train : regions.keySet()) {
        for (Pair<Shape, TimeInterval> pair : regions.get(train)) {
            if (pair.first.intersects(cursor) && !list.contains(pair.second)) {
                TimeInterval interval = pair.second;
                if (interval.isNodeOwner()) {
                    list.addFirst(interval);
                } else {
                    list.add(interval);
                }
            }
        }
    }
    return list;
}
Also used : Shape(java.awt.Shape) TimeInterval(net.parostroj.timetable.model.TimeInterval) Rectangle2D(java.awt.geom.Rectangle2D) Train(net.parostroj.timetable.model.Train)

Example 14 with Train

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

the class TrainRegionCollector method getRectangleForItems.

@Override
public Rectangle getRectangleForItems(List<TimeInterval> items) {
    Iterable<Train> trains = Iterables.transform(items, SelectorUtils.createToTrainFunction());
    Iterable<Train> uniqueTrains = Iterables.filter(trains, SelectorUtils.createUniqueTrainFilter());
    Rectangle result = null;
    for (Train train : uniqueTrains) {
        Collection<Pair<Shape, TimeInterval>> shapes = regions.get(train);
        if (shapes != null) {
            for (Pair<Shape, TimeInterval> pair : shapes) {
                Shape shape = pair.first;
                Rectangle bounds = shape.getBounds();
                if (result == null) {
                    result = bounds;
                } else {
                    result = result.union(bounds);
                }
            }
        }
    }
    return result;
}
Also used : Shape(java.awt.Shape) TimeInterval(net.parostroj.timetable.model.TimeInterval) Rectangle(java.awt.Rectangle) Train(net.parostroj.timetable.model.Train) Pair(net.parostroj.timetable.utils.Pair)

Example 15 with Train

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

the class ImportModelAction method backgroundAction.

@Override
protected void backgroundAction() {
    setWaitMessage(ResourceLoader.getString("wait.message.import"));
    setWaitDialogVisible(true);
    long time = System.currentTimeMillis();
    try {
        ExportImportSelection selection = context.getAttribute("selection", ExportImportSelection.class);
        TrainDiagram diagram = context.getAttribute("diagramImport", TrainDiagram.class);
        TrainImportConfig trainImportConfig = context.getAttribute("trainImport", TrainImportConfig.class);
        Map<ImportComponent, Collection<ObjectWithId>> map = selection.getObjectMap();
        imports = new TrainDiagramPartImport(diagram, selection.getImportMatch(), selection.isImportOverwrite());
        List<ObjectWithId> list = map.values().stream().sequential().flatMap(item -> item.stream().sequential()).collect(Collectors.toList());
        if (list.isEmpty()) {
            return;
        }
        if (trainImportConfig != null && trainImportConfig.isRemoveExisting()) {
            // remove existing trains in group
            Consumer<ObjectWithId> deleteProcess = item -> diagram.getTrains().remove(item);
            Iterable<Train> filteredTrains = Iterables.filter(diagram.getTrains(), ModelPredicates.inGroup(trainImportConfig.getToGroup()));
            processItems(filteredTrains, deleteProcess);
        }
        // import new objects
        Consumer<ObjectWithId> importProcess = item -> {
            ImportComponent i = ImportComponent.getByComponentClass(item.getClass());
            if (i != null) {
                ObjectWithId imported = imports.importPart(item);
                processImportedObject(imported, trainImportConfig);
            } else {
                log.warn("No import for class {}", item.getClass().getName());
            }
        };
        processItems(list, importProcess);
    } finally {
        log.debug("Import finished in {}ms", System.currentTimeMillis() - time);
        setWaitDialogVisible(false);
    }
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) Collection(java.util.Collection) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) LoggerFactory(org.slf4j.LoggerFactory) ImportError(net.parostroj.timetable.model.imports.Import.ImportError) ModelPredicates(net.parostroj.timetable.filters.ModelPredicates) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) Node(net.parostroj.timetable.model.Node) Consumer(java.util.function.Consumer) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) List(java.util.List) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport) Map(java.util.Map) LinkedList(java.util.LinkedList) TrainType(net.parostroj.timetable.model.TrainType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Group(net.parostroj.timetable.model.Group) Train(net.parostroj.timetable.model.Train) ImportComponent(net.parostroj.timetable.model.imports.ImportComponent) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) Collection(java.util.Collection) Train(net.parostroj.timetable.model.Train) TrainDiagramPartImport(net.parostroj.timetable.model.imports.TrainDiagramPartImport)

Aggregations

Train (net.parostroj.timetable.model.Train)31 TimeInterval (net.parostroj.timetable.model.TimeInterval)8 LinkedList (java.util.LinkedList)5 Node (net.parostroj.timetable.model.Node)5 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)5 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)5 List (java.util.List)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Component (java.awt.Component)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 JOptionPane (javax.swing.JOptionPane)2 TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)2 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 Group (net.parostroj.timetable.model.Group)2 Route (net.parostroj.timetable.model.Route)2