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