use of net.parostroj.timetable.model.TimeConverter 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.TimeConverter 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.TimeConverter in project grafikon by jub77.
the class DriverCycleDelegate method getTrainCycleErrors.
@Override
public String getTrainCycleErrors(TrainsCycle cycle) {
TrainDiagram diagram = model.getDiagram();
TimeConverter c = diagram.getTimeConverter();
StringBuilder result = new StringBuilder();
List<TrainsCycleChecker.Conflict> conflicts = checker.checkConflicts(cycle);
for (TrainsCycleChecker.Conflict item : conflicts) {
TrainsCycleItem fromItem = item.getFrom();
TrainsCycleItem toItem = item.getTo();
for (ConflictType conflictType : this.colapseTimeConflictTypes(item.getType())) {
switch(conflictType) {
case NODE:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes"), formatItems(fromItem, toItem, c)));
break;
case TRANSITION_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes.time.problem"), formatItems(fromItem, toItem, c)));
break;
case TIME:
case SETUP_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.problem.time"), formatItems(fromItem, toItem, c)));
break;
}
}
}
return result.toString();
}
use of net.parostroj.timetable.model.TimeConverter in project grafikon by jub77.
the class TrainsCycleItemWrapperDelegate method toStringItem.
public String toStringItem(TrainsCycleItem item) {
TimeConverter c = item.getTrain().getDiagram().getTimeConverter();
String str = String.format("%s (%s[%s],%s[%s])", item.getTrain().getDefaultName(), item.getFromInterval().getOwnerAsNode().getName(), this.getStartTime(c, item), item.getToInterval().getOwnerAsNode().getName(), c.convertIntToText(item.getEndTime()));
LocalizedString lComment = item.getComment();
String comment = ObjectsUtil.checkAndTrim(lComment == null ? null : lComment.getDefaultString());
if (showComment && comment != null) {
str = String.format("%s - %s", str, comment);
}
return str;
}
use of net.parostroj.timetable.model.TimeConverter 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;
}
}
}
}
Aggregations