Search in sources :

Example 1 with TimeConverter

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();
            }
        }
    }
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) TimeInterval(net.parostroj.timetable.model.TimeInterval) Formatter(java.util.Formatter) TimeConverter(net.parostroj.timetable.model.TimeConverter)

Example 2 with TimeConverter

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();
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) Formatter(java.util.Formatter) Node(net.parostroj.timetable.model.Node) TimeConverter(net.parostroj.timetable.model.TimeConverter)

Example 3 with TimeConverter

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();
}
Also used : TrainsCycleChecker(net.parostroj.timetable.actions.TrainsCycleChecker) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) TimeConverter(net.parostroj.timetable.model.TimeConverter) ConflictType(net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 4 with TimeConverter

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;
}
Also used : LocalizedString(net.parostroj.timetable.model.LocalizedString) LocalizedString(net.parostroj.timetable.model.LocalizedString) TimeConverter(net.parostroj.timetable.model.TimeConverter)

Example 5 with TimeConverter

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;
            }
        }
    }
}
Also used : Conflict(net.parostroj.timetable.actions.TrainsCycleChecker.Conflict) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) TimeConverter(net.parostroj.timetable.model.TimeConverter) ConflictType(net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType)

Aggregations

TimeConverter (net.parostroj.timetable.model.TimeConverter)5 Formatter (java.util.Formatter)2 ConflictType (net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)2 TrainsCycleChecker (net.parostroj.timetable.actions.TrainsCycleChecker)1 Conflict (net.parostroj.timetable.actions.TrainsCycleChecker.Conflict)1 LocalizedString (net.parostroj.timetable.model.LocalizedString)1 Node (net.parostroj.timetable.model.Node)1 NodeTrack (net.parostroj.timetable.model.NodeTrack)1 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)1