use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class StationTimetablesExtractor method createRow.
private StationTimetableRow createRow(TimeInterval interval) {
TimeInterval from = interval.getTrain().getInterval(interval, -1);
TimeInterval to = interval.getTrain().getInterval(interval, 1);
String fromNodeName = TransformUtil.getFromAbbr(interval);
String toNodeName = TransformUtil.getToAbbr(interval);
String endNodeName = (interval.isLast() || interval.isTechnological()) ? null : interval.getTrain().getEndNode().getAbbr();
String fromTime = (from == null && !interval.isTechnological()) ? null : converter.convertIntToXml(interval.getStart());
String toTime = (to == null && !interval.isTechnological()) ? null : converter.convertIntToXml(interval.getEnd());
StationTimetableRow row = new StationTimetableRow(interval.getTrain().getName(), fromNodeName, fromTime, toNodeName, toTime, endNodeName, interval.getTrack().getNumber());
row.setStop(interval.getLength());
this.addOtherData(interval, row);
row.setRef(interval);
return row;
}
use of net.parostroj.timetable.model.TimeInterval 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.TimeInterval 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.TimeInterval 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;
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class FreightDestinationPanel method addFreightTrainsFromNode.
private void addFreightTrainsFromNode(DataModel model, Node node, FreightAnalyser analyser) {
Locale locale = Locale.getDefault();
List<TimeInterval> intervalsFrom = analyser.getFreightIntervalsFrom(node);
List<Tuple<String>> trains = intervalsFrom.stream().map(i -> new Tuple<>(util.intervalToString(diagram, i, locale), util.freightListToString(analyser.getConnectionStrategy().getFreightToNodes(i), locale).stream().collect(Collectors.joining(", ")))).collect(Collectors.toList());
model.addLinesWithEmpty(trains);
}
Aggregations