use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class NodeTimetableByTracksWriter method writeNodeTimetable.
/**
* writes node timetable.
*
* @param node node
* @param str appendable
*/
public void writeNodeTimetable(Node node, Appendable str) throws IOException {
TimeConverter c = node.getDiagram().getTimeConverter();
str.append("Node: ");
str.append(node.getName()).append('\n');
List<NodeTrack> tracks = node.getTracks();
for (NodeTrack track : tracks) {
str.append("Track: " + track.getNumber()).append('\n');
for (TimeInterval interval : track.getTimeIntervalList()) {
try (Formatter f = new Formatter(str)) {
f.format("%1$-20s", interval.getTrain().getDefaultCompleteName());
str.append(c.convertIntToText(interval.getStart(), true));
str.append(" ").append(c.convertIntToText(interval.getEnd(), true)).append("\n");
f.flush();
}
}
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TrainTimetableWriter method writeTrainTimetable.
/**
* writes train timetable.
*
* @param train train
* @param str appendable
*/
public void writeTrainTimetable(Train train, Appendable str) throws IOException {
TimeConverter c = train.getDiagram().getTimeConverter();
str.append("Train: ");
str.append(train.getDefaultCompleteName()).append('\n');
for (TimeInterval time : train.getNodeIntervals()) {
Node node = time.getOwnerAsNode();
@SuppressWarnings("resource") Formatter f = new Formatter(str);
f.format("%1$-20s", node.getName());
if (time.isFirst() || !time.isStop()) {
str.append(" ").append(c.convertIntToText(time.getEnd(), true)).append("\n");
} else if (time.isLast()) {
str.append(c.convertIntToText(time.getStart(), true)).append("\n");
} else if (time.isStop()) {
str.append(c.convertIntToText(time.getStart(), true)).append(" ");
str.append(c.convertIntToText(time.getEnd(), true)).append("\n");
} else {
str.append('\n');
}
f.flush();
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class PreviousNextTrainValidator method checkTrainIntervals.
private void checkTrainIntervals(Event event, Train currentTrain) {
if (event.getType() == Type.SPECIAL && event.getData() instanceof SpecialTrainTimeIntervalList) {
SpecialTrainTimeIntervalList list = (SpecialTrainTimeIntervalList) event.getData();
if (list.getType() == SpecialTrainTimeIntervalList.Type.TRACK) {
int changed = list.getChanged();
if (currentTrain.getPreviousJoinedTrain() != null && changed == 0) {
TimeInterval source = currentTrain.getFirstInterval();
TimeInterval dest = currentTrain.getPreviousJoinedTrain().getLastInterval();
checkAndUpdateTrack(source, dest);
} else if (currentTrain.getNextJoinedTrain() != null && changed == currentTrain.getTimeIntervalList().size() - 1) {
TimeInterval source = currentTrain.getLastInterval();
TimeInterval dest = currentTrain.getNextJoinedTrain().getFirstInterval();
checkAndUpdateTrack(source, dest);
}
}
if (currentTrain.getNextJoinedTrain() != null) {
checkAndUpdateNextTrainStart(currentTrain);
checkAndUpdateTimeAfter(currentTrain);
}
if (currentTrain.getPreviousJoinedTrain() != null) {
checkAndUpdateTimeAfter(currentTrain.getPreviousJoinedTrain());
}
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class TrainDiagramBuilder method setFreightNet.
public void setFreightNet(LSFreightNet lsFreightNet) throws LSException {
FreightNet net = lsFreightNet.createFreightNet(diagram);
this.diagram.setFreightNet(net);
for (LSFreightConnection lsConnection : lsFreightNet.getConnections()) {
Train from = diagram.getTrains().getById(lsConnection.getTrainFrom());
Train to = diagram.getTrains().getById(lsConnection.getTrainTo());
TimeInterval iFrom = from.getIntervalById(lsConnection.getIntervalFrom());
TimeInterval iTo = to.getIntervalById(lsConnection.getIntervalTo());
FNConnection connection = diagram.getFreightNet().addConnection(iFrom, iTo);
connection.merge(lsConnection.getAttributes().createAttributes(diagram::getObjectById));
}
}
use of net.parostroj.timetable.model.TimeInterval in project grafikon by jub77.
the class FreightNetPane2 method updateInfo.
private void updateInfo() {
StringBuilder builder = new StringBuilder();
FNConnection conn = selector.getSelectedConnection();
TimeInterval from = conn != null ? conn.getFrom() : connection.first;
TimeInterval to = conn != null ? conn.getTo() : connection.second;
if (from != null) {
builder.append(from.getOwnerAsNode().getAbbr()).append(": ");
builder.append(getIntervalInfo(from, true));
}
if (to != null) {
builder.append(" -> ").append(getIntervalInfo(to, false));
}
infoTextField.setText(builder.toString());
}
Aggregations