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));
}
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);
}
}
}
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;
}
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;
}
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);
}
}
Aggregations