Search in sources :

Example 1 with FreightConnectionStrategy

use of net.parostroj.timetable.model.freight.FreightConnectionStrategy in project grafikon by jub77.

the class TrainTableModel method getValueAt.

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
    TrainDiagram diagram = train.getDiagram();
    Object retValue = null;
    TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
    switch(column) {
        // node name
        case NODE:
            if (interval.isNodeOwner()) {
                retValue = interval.getOwnerAsNode().getName();
            } else {
                retValue = "";
            }
            break;
        // arrival
        case START:
            if (!interval.isFirst()) {
                retValue = converter.convertIntToText(interval.getStart(), true);
            }
            break;
        // departure
        case END:
            if (!interval.isLast()) {
                retValue = converter.convertIntToText(interval.getEnd(), true);
            }
            break;
        // stop time
        case STOP:
            if (interval.isNodeOwner() && rowIndex != 0 && rowIndex != lastRow && interval.getOwnerAsNode().getType() != NodeType.SIGNAL) {
                retValue = converter.convertIntToMinutesText(interval.getLength());
            }
            break;
        // speed
        case SPEED_LIMIT:
            if (interval.isLineOwner()) {
                retValue = interval.getSpeedLimit();
            }
            break;
        // used speed
        case SPEED:
            retValue = interval.getSpeed();
            break;
        // added time
        case ADDED_TIME:
            if (interval.isLineOwner() && interval.getAddedTime() != 0) {
                retValue = converter.convertIntToMinutesText(interval.getAddedTime());
            }
            break;
        // platform
        case PLATFORM:
            if (interval.isNodeOwner()) {
                if (interval.getOwnerAsNode().getTracks().size() > 1) {
                    retValue = interval.getTrack();
                }
            } else if (interval.isLineOwner()) {
                // only for more than one track per line
                if (interval.getOwnerAsLine().getTracks().size() > 1) {
                    return interval.getTrack();
                }
            }
            break;
        // problems
        case CONFLICTS:
            StringBuilder builder = new StringBuilder();
            for (TimeInterval overlap : interval.getOverlappingIntervals()) {
                if (builder.length() != 0) {
                    builder.append(", ");
                }
                builder.append(overlap.getTrain().getDefaultName());
            }
            retValue = builder.toString();
            break;
        // comment
        case COMMENT:
            LocalizedString lComment = interval.getComment();
            retValue = lComment == null ? null : lComment.getDefaultString();
            break;
        case OCCUPIED_ENTRY:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_OCCUPIED);
            break;
        case SHUNT:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_SHUNT);
            break;
        case COMMENT_SHOWN:
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_COMMENT_SHOWN);
            break;
        case REAL_STOP:
            if (interval.isNodeOwner() && rowIndex != 0 && rowIndex != lastRow && interval.getOwnerAsNode().getType() != NodeType.SIGNAL) {
                int stop = interval.getLength() / 60;
                // celculate with time scale ...
                Double timeScale = diagram.getAttributes().get(TrainDiagram.ATTR_TIME_SCALE, Double.class);
                retValue = stop / timeScale;
            }
            break;
        case WEIGHT:
            // weight info
            if (interval.isLineOwner()) {
                retValue = TrainsHelper.getWeight(interval);
            }
            break;
        case LENGTH:
            // length info
            retValue = TrainsHelper.getLength(interval);
            break;
        case SET_SPEED:
            // train speed
            retValue = interval.getAttribute(TimeInterval.ATTR_SET_SPEED, Object.class);
            break;
        case IGNORE_LENGTH:
            // ignore station length
            retValue = interval.getAttributes().getBool(TimeInterval.ATTR_IGNORE_LENGTH);
            break;
        case MANAGED_FREIGHT:
            // managed freight
            retValue = false;
            if (train.isManagedFreight() && interval.isNodeOwner()) {
                retValue = (interval.getLength() > 0 || rowIndex == 0 || rowIndex == lastRow) && !interval.getAttributeAsBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT);
            }
            break;
        case REGION_CENTER_TRANSFER:
            // transfer in region center
            retValue = false;
            if (interval.isNodeOwner() && train.isManagedFreight()) {
                if (interval.getOwnerAsNode().isCenterOfRegions() && !interval.getAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER) && rowIndex != 0) {
                    retValue = true;
                }
            }
            break;
        case FREIGHT_TO_STATIONS:
            FreightConnectionStrategy strategy = train.getDiagram().getFreightNet().getConnectionStrategy();
            if (rowIndex % 2 == 0 && (interval.isFreight() || interval.isFreightConnection())) {
                StringBuilder result = new StringBuilder();
                Map<Train, List<FreightConnectionPath>> passedCargoDst = strategy.getFreightPassedInNode(interval);
                for (Map.Entry<Train, List<FreightConnectionPath>> entry : passedCargoDst.entrySet()) {
                    List<FreightConnectionPath> mList = entry.getValue();
                    result.append('(').append(freightUtil.freightListToString(mList, Locale.getDefault()));
                    result.append(" > ").append(entry.getKey().getDefaultName()).append(')');
                }
                if (interval.isFreightFrom()) {
                    List<FreightConnectionPath> cargoDst = strategy.getFreightToNodes(interval);
                    List<FreightConnectionPath> mList = cargoDst;
                    if (!cargoDst.isEmpty() && result.length() > 0) {
                        result.append(' ');
                    }
                    result.append(freightUtil.freightListToString(mList, Locale.getDefault()));
                }
                retValue = result.toString();
            }
            break;
        // default (should not be reached)
        default:
            // nothing
            assert false : "Unexpected column";
            break;
    }
    return retValue;
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) FreightConnectionStrategy(net.parostroj.timetable.model.freight.FreightConnectionStrategy) LocalizedString(net.parostroj.timetable.model.LocalizedString) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) FreightConnectionPath(net.parostroj.timetable.model.freight.FreightConnectionPath) List(java.util.List) Train(net.parostroj.timetable.model.Train) Map(java.util.Map)

Example 2 with FreightConnectionStrategy

use of net.parostroj.timetable.model.freight.FreightConnectionStrategy in project grafikon by jub77.

the class FreightCheckPanel method checkFreight.

private void checkFreight(TextBuffer buffer) {
    FreightConnectionStrategy strategy = FreightConnectionStrategy.createCached(diagram.getFreightNet().getConnectionStrategy());
    // check
    FreightChecker checker = new FreightChecker(strategy);
    // check all centers
    buffer.appendText(ResourceLoader.getString("freight.check.centers") + ":\n", boldUnderlineStyle);
    diagram.getNet().getNodes().stream().filter(n -> n.isCenterOfRegions()).forEach(n -> {
        Set<Node> noConnToNodes = checker.getNoConnectionsToNodes(n, notFreightTypes);
        Set<Node> noConnToCenter = checker.getNoConnectionToCenter(n, notFreightTypes);
        buffer.appendText("-", noConnToCenter.isEmpty() && noConnToNodes.isEmpty() ? okStyle : errorStyle);
        buffer.appendText(String.format("  %s\n", nodeWithRegionToString(n)), null);
        for (Node ncNode : noConnToNodes) {
            buffer.appendText(String.format("   %s → %s\n", n.getName(), ncNode.getName()), null);
        }
        for (Node ncNode : noConnToCenter) {
            buffer.appendText(String.format("   %s → %s\n", ncNode.getName(), n.getName()), null);
        }
    });
    buffer.appendText(ResourceLoader.getString("freight.check.center.connections") + ":\n", boldUnderlineStyle);
    Map<Node, List<ConnectionState<NodeConnectionEdges>>> centerConnMap = checker.analyseCenterConnections(diagram.getNet()).stream().collect(Collectors.groupingBy(c -> c.getFrom()));
    centerConnMap.entrySet().stream().sorted(Comparator.comparing(e -> e.getKey().getName(), comparator)).forEach(c -> {
        boolean exists = c.getValue().stream().allMatch(ConnectionState::exists);
        buffer.appendText("-", exists ? okStyle : errorStyle);
        buffer.appendText(String.format("  %s\n", nodeWithRegionToString(c.getKey())), null);
        c.getValue().stream().filter(cx -> !cx.exists()).forEach(cx -> {
            buffer.appendText(String.format("   %s → %s\n", cx.getFrom().getName(), nodeWithRegionToString(cx.getTo())), null);
        });
    });
    buffer.appendText(ResourceLoader.getString("freight.check.node.connections") + ":\n", boldUnderlineStyle);
    checker.analyseNodeConnections(diagram.getNet(), notFreightTypes).stream().filter(c -> !c.exists()).sorted(compareConnections()).forEach(c -> {
        buffer.appendText("-", errorStyle);
        buffer.appendText(String.format("  %s → %s\n", c.getFrom().getName(), c.getTo().getName()), null);
    });
}
Also used : OutputFreightUtil(net.parostroj.timetable.output2.util.OutputFreightUtil) StyleConstants(javax.swing.text.StyleConstants) LoggerFactory(org.slf4j.LoggerFactory) StyledDocument(javax.swing.text.StyledDocument) Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) ResourceLoader(net.parostroj.timetable.gui.utils.ResourceLoader) Locale(java.util.Locale) Map(java.util.Map) FreightConnectionStrategy(net.parostroj.timetable.model.freight.FreightConnectionStrategy) ImageIcon(javax.swing.ImageIcon) JTextPane(javax.swing.JTextPane) BorderLayout(java.awt.BorderLayout) AttributeSet(javax.swing.text.AttributeSet) OutputUtil(net.parostroj.timetable.output2.util.OutputUtil) FlowLayout(java.awt.FlowLayout) NodeType(net.parostroj.timetable.model.NodeType) JButton(javax.swing.JButton) Logger(org.slf4j.Logger) ConnectionState(net.parostroj.timetable.model.freight.FreightChecker.ConnectionState) GuiComponentUtils(net.parostroj.timetable.gui.utils.GuiComponentUtils) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) BadLocationException(javax.swing.text.BadLocationException) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) FreightChecker(net.parostroj.timetable.model.freight.FreightChecker) JScrollPane(javax.swing.JScrollPane) List(java.util.List) FontMetrics(java.awt.FontMetrics) Style(javax.swing.text.Style) GuiIcon(net.parostroj.timetable.gui.utils.GuiIcon) NodeConnectionEdges(net.parostroj.timetable.model.freight.NodeConnectionEdges) RxActionHandler(net.parostroj.timetable.gui.actions.execution.RxActionHandler) Pair(net.parostroj.timetable.utils.Pair) Comparator(java.util.Comparator) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) JPanel(javax.swing.JPanel) Node(net.parostroj.timetable.model.Node) FreightConnectionStrategy(net.parostroj.timetable.model.freight.FreightConnectionStrategy) FreightChecker(net.parostroj.timetable.model.freight.FreightChecker) NodeConnectionEdges(net.parostroj.timetable.model.freight.NodeConnectionEdges) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionState(net.parostroj.timetable.model.freight.FreightChecker.ConnectionState)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)2 FreightConnectionStrategy (net.parostroj.timetable.model.freight.FreightConnectionStrategy)2 BorderLayout (java.awt.BorderLayout)1 FlowLayout (java.awt.FlowLayout)1 FontMetrics (java.awt.FontMetrics)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.joining (java.util.stream.Collectors.joining)1 BorderFactory (javax.swing.BorderFactory)1 ImageIcon (javax.swing.ImageIcon)1 JButton (javax.swing.JButton)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextPane (javax.swing.JTextPane)1 AttributeSet (javax.swing.text.AttributeSet)1