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