use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class BaseConnectionStrategy method getFreightToNodesImpl.
private void getFreightToNodesImpl(Node start, TimeInterval fromInterval, List<TrainConnection> path, List<FreightConnectionPath> result, Set<FNConnection> used, FreightConnectionFilter filter, FilterContext context) {
FilterResult filterResult;
Iterator<TimeInterval> intervals = fromInterval.getTrain().iterator();
Iterators.find(intervals, interval -> interval == fromInterval);
intervals = Iterators.filter(intervals, interval -> interval.isNodeOwner() && (interval.isFreightTo() || interval.isFreightConnection()));
while (intervals.hasNext()) {
TimeInterval i = intervals.next();
if (i.isFreight()) {
FreightConnectionPath newDst = FreightFactory.createFreightNodeConnection(start, i.getOwnerAsNode(), i.isRegionCenterTransfer(), createNewPath(path, fromInterval, i));
filterResult = filter.accepted(context, newDst, 0);
if (filterResult == FilterResult.STOP_EXCLUDE) {
break;
}
if (filterResult != FilterResult.IGNORE) {
result.add(newDst);
}
if (filterResult == FilterResult.STOP_INCLUDE) {
break;
}
}
for (FNConnection conn : freightNet.getTrainsFrom(i)) {
if (!used.contains(conn)) {
used.add(conn);
List<TrainConnection> newPath = createNewPath(path, fromInterval, conn.getFrom());
this.getFreightToNodesImpl(start, conn.getTo(), newPath, result, used, conn.getFreightDstFilter(filter, false), context);
}
}
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TrainTableModel method setValueAt.
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
int time = 0;
editBlock = true;
TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
switch(column) {
case START:
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
int oldTime = TimeUtil.normalizeTime(interval.getStart());
int newTime = TimeUtil.normalizeTime(time);
int newStartTime = TimeUtil.normalizeTime(train.getStartTime() + (newTime - oldTime));
train.move(newStartTime);
this.fireTableRowsUpdated(0, lastRow);
}
break;
case END:
// departure
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
if (rowIndex == 0) {
train.move(time);
this.fireTableDataChanged();
} else {
int start = TimeUtil.normalizeTime(interval.getStart());
time = TimeUtil.normalizeTime(time);
if (time < start) {
time += TimeInterval.DAY;
}
int newStop = time - start;
if (newStop >= 0) {
train.changeStopTime(interval, newStop);
this.fireTableRowsUpdated(rowIndex - 1, lastRow);
}
}
}
break;
case STOP:
// stop time
try {
time = converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
time = -1;
}
if (time >= 0) {
boolean originalIsFreight = interval.isFreight();
train.changeStopTime(interval, time);
int firstRow = rowIndex - 1;
if (interval.isFreight() != originalIsFreight) {
firstRow = 0;
}
this.fireTableRowsUpdated(firstRow, lastRow);
}
break;
case SPEED_LIMIT:
// velocity limit
Integer velocity = (Integer) aValue;
if (velocity == null || velocity > 0) {
train.changeSpeedAndAddedTime(interval, velocity, interval.getAddedTime());
this.fireTableRowsUpdated(rowIndex - 2 >= 0 ? rowIndex - 2 : 0, lastRow);
}
break;
case ADDED_TIME:
// added time
if (aValue != null) {
int addedTime;
try {
addedTime = ObjectsUtil.isEmpty((String) aValue) ? 0 : converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
addedTime = -1;
}
if (addedTime >= 0) {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), addedTime);
}
} else {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), 0);
}
this.fireTableRowsUpdated(rowIndex, lastRow);
break;
case PLATFORM:
// platform
Track track = (Track) aValue;
if (interval.isNodeOwner()) {
NodeTrack newTrack = (NodeTrack) track;
if (newTrack != null) {
train.changeNodeTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
} else if (interval.isLineOwner()) {
LineTrack newTrack = (LineTrack) track;
if (newTrack != null) {
train.changeLineTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
}
break;
case COMMENT:
// comment
String commentStr = ObjectsUtil.checkAndTrim((String) aValue);
LocalizedString lComment = null;
if (commentStr != null) {
lComment = LocalizedString.newBuilder(interval.getComment()).setDefaultString(commentStr).build();
}
interval.getAttributes().setRemove(TimeInterval.ATTR_COMMENT, lComment);
break;
case OCCUPIED_ENTRY:
// entry of the occupied track
interval.getAttributes().setBool(TimeInterval.ATTR_OCCUPIED, (Boolean) aValue);
break;
case SHUNT:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_SHUNT, (Boolean) aValue);
break;
case COMMENT_SHOWN:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_COMMENT_SHOWN, (Boolean) aValue);
break;
case SET_SPEED:
// train speed
Integer trainSpeed = (Integer) aValue;
if (trainSpeed != null && trainSpeed <= 0) {
trainSpeed = null;
}
interval.getAttributes().setRemove(TimeInterval.ATTR_SET_SPEED, trainSpeed);
break;
case IGNORE_LENGTH:
// ignore length of the station in computation
interval.getAttributes().setBool(TimeInterval.ATTR_IGNORE_LENGTH, (Boolean) aValue);
this.fireTableRowsUpdated(rowIndex, rowIndex);
break;
case MANAGED_FREIGHT:
interval.getAttributes().setBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
case REGION_CENTER_TRANSFER:
interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
default:
break;
}
editBlock = false;
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class LoadFilter4d19 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 19, 0)) <= 0) {
// not passing cargo in center (move to time interval from train)
for (Train train : diagram.getTrains()) {
if (train.getAttributeAsBool("no.transitive.region.start")) {
for (TimeInterval interval : train.getNodeIntervals()) {
if (interval.isFirst())
continue;
if (interval.getOwnerAsNode().isCenterOfRegions()) {
interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, true);
}
}
}
}
}
if (version.compareTo(new ModelVersion(4, 19, 2)) <= 0) {
// convert some texts to localized strings
this.convertToLocalizedStrings(diagram);
// filter out output templates with default.template
removeDefaultTemplatesExceptDrawAndXml(diagram);
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TrainTimetablesExtractor method extractRows.
private void extractRows(Train train, TrainTimetable timetable) {
timetable.setRows(new LinkedList<TrainTimetableRow>());
Iterator<TimeInterval> i = train.getTimeIntervalList().iterator();
TimeInterval lastLineI = null;
while (i.hasNext()) {
TimeInterval nodeI = i.next();
TimeInterval lineI = i.hasNext() ? i.next() : null;
if (nodeI.getOwnerAsNode().getType() == NodeType.SIGNAL) {
lastLineI = lineI;
continue;
}
TrainTimetableRow row = new TrainTimetableRow();
row.setRef(nodeI);
if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_CONTROL_STATION)) {
row.setControlStation(true);
}
if (Node.IP_NEW_SIGNALS.equals(nodeI.getOwnerAsNode().getAttribute(Node.ATTR_INTERLOCKING_PLANT, String.class))) {
row.setLightSignals(true);
}
row.setStation(nodeI.getOwnerAsNode().getName());
row.setStationAbbr(nodeI.getOwnerAsNode().getAbbr());
row.setStationType(nodeI.getOwnerAsNode().getType().getKey());
if (!nodeI.isFirst())
row.setArrival(diagram.getTimeConverter().convertIntToXml(nodeI.getStart()));
if (!nodeI.isLast())
row.setDeparture(diagram.getTimeConverter().convertIntToXml(nodeI.getEnd()));
if (lineI != null) {
row.setSpeed(lineI.getSpeed());
row.setLineTracks(lineI.getOwnerAsLine().getTracks().size());
row.setSetSpeed(lineI.getAttribute(TimeInterval.ATTR_SET_SPEED, Integer.class));
}
// comment
if (nodeI.getAttributes().getBool(TimeInterval.ATTR_COMMENT_SHOWN)) {
row.setComment(nodeI.getComment());
}
// check line end
if ((nodeI.isLast() || nodeI.isInnerStop()) && nodeI.getTrack().getAttributes().getBool(Track.ATTR_LINE_END)) {
row.setLineEnd(Boolean.TRUE);
}
// check occupied track
if (nodeI.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED)) {
row.setOccupied(Boolean.TRUE);
}
// check shunt
if (nodeI.getAttributes().getBool(TimeInterval.ATTR_SHUNT)) {
row.setShunt(Boolean.TRUE);
}
if (nodeI.getOwnerAsNode().getTracks().size() > 1)
row.setTrack(nodeI.getTrack().getNumber());
boolean onControlled = checkOnControlled(nodeI.getOwnerAsNode());
if (onControlled)
row.setOnControlled(true);
if (lastLineI != null && lastLineI.getToStraightTrack() != null)
row.setStraight(lastLineI.getToStraightTrack() == nodeI.getTrack());
if (nodeI.getOwnerAsNode().getAttributes().getBool(Node.ATTR_TRAPEZOID_SIGN)) {
Pair<Boolean, List<TranslatedString>> concurrentTrains = this.getConcurrentTrains(nodeI);
if (concurrentTrains != null) {
row.setConcurrentTrains(concurrentTrains.second);
row.setFirstConcurrent(concurrentTrains.first);
}
}
LineClass lineClass = lineI != null ? lineI.getLineClass() : null;
if (lineClass != null)
row.setLineClass(lineClass.getName());
// route position
Double routePosition = null;
Double routePositionOut = null;
if (lineI != null)
routePositionOut = this.getRoutePosition(lineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
if (lastLineI != null)
routePosition = this.getRoutePosition(lastLineI.getOwnerAsLine(), nodeI.getOwnerAsNode());
if (routePosition == null)
routePosition = routePositionOut;
if (routePosition != null && routePositionOut != null && routePosition.doubleValue() == routePositionOut.doubleValue())
routePositionOut = null;
row.setRoutePosition(routePosition);
row.setRoutePositionOut(routePositionOut);
// freight
if (nodeI.isFirst() && nodeI.isFreight()) {
List<? extends FreightConnection> freightDests = strategy.getFreightToNodes(nodeI);
if (!freightDests.isEmpty()) {
ArrayList<FreightDestinationInfo> fl = new ArrayList<>(freightDests.size());
for (FreightConnection dst : freightDests) {
fl.add(FreightDestinationInfo.convert(locale, dst));
}
row.setFreightDest(fl);
}
}
timetable.getRows().add(row);
lastLineI = lineI;
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class StationTimetablesExtractor method getStationTimetables.
public List<StationTimetable> getStationTimetables() {
List<StationTimetable> result = new LinkedList<>();
for (Node node : nodes) {
StationTimetable timetable = new StationTimetable(node.getName());
timetable.setType(node.getType());
// regions + company
Set<Region> regions = node.getRegions();
if (!regions.isEmpty()) {
timetable.setRegions(regions.stream().map(RegionInfo::convert).collect(Collectors.toList()));
}
Company company = node.getAttribute(Node.ATTR_COMPANY, Company.class);
if (company != null) {
timetable.setCompany(CompanyInfo.convert(company));
}
// process rows ...
for (TimeInterval interval : this.collectIntervals(node)) {
if (techTime || !interval.isTechnological()) {
timetable.getRows().add(this.createRow(interval));
}
}
result.add(timetable);
}
return result;
}
Aggregations