Search in sources :

Example 1 with LineTrack

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

the class LSTrain method createTrain.

public Train createTrain(TrainDiagram diagram) {
    Train train = diagram.getPartFactory().createTrain(id);
    train.setNumber(number);
    train.getAttributes().add(attributes.createAttributes());
    train.setDescription(desc);
    train.setTopSpeed(topSpeed);
    train.setType(diagram.getTrainTypes().getById(type));
    // build time interval list
    TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, start);
    for (Object routePart : getRoute()) {
        if (routePart instanceof LSTrainRoutePartNode) {
            LSTrainRoutePartNode nodePart = (LSTrainRoutePartNode) routePart;
            Node node = diagram.getNet().getNodeById(nodePart.getNodeId());
            NodeTrack nodeTrack = node.getTrackById(nodePart.getTrackId());
            builder.addNode(nodePart.getIntervalId(), node, nodeTrack, nodePart.getStop(), nodePart.getAttributes().createAttributes());
        } else {
            LSTrainRoutePartLine linePart = (LSTrainRoutePartLine) routePart;
            Line line = diagram.getNet().getLineById(linePart.getLineId());
            LineTrack lineTrack = line.getTrackById(linePart.getTrackId());
            builder.addLine(linePart.getIntervalId(), line, lineTrack, linePart.getSpeed(), 0, linePart.getAttributes().createAttributes());
        }
    }
    builder.finish();
    // set technological time
    train.setTimeBefore(this.timeBefore);
    train.setTimeAfter(this.timeAfter);
    return train;
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) Line(net.parostroj.timetable.model.Line) TrainIntervalsBuilder(net.parostroj.timetable.actions.TrainIntervalsBuilder) Node(net.parostroj.timetable.model.Node) Train(net.parostroj.timetable.model.Train) LineTrack(net.parostroj.timetable.model.LineTrack)

Example 2 with LineTrack

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

the class LSLine method createLine.

public Line createLine(TrainDiagram diagram) throws LSException {
    Net net = diagram.getNet();
    Node fromNode = net.getNodeById(getFrom());
    Node toNode = net.getNodeById(getTo());
    if (speed != null && speed <= 0) {
        speed = null;
    }
    Line line = diagram.getPartFactory().createLine(id, length, fromNode, toNode, speed);
    line.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
    // tracks
    if (this.tracks != null)
        for (LSLineTrack lsLineTrack : this.tracks) {
            LineTrack lineTrack = lsLineTrack.createLineTrack(diagram::getObjectById);
            NodeTrack fromStraight = fromNode.getTrackById(lsLineTrack.getFromStraightTrack());
            NodeTrack toStraight = toNode.getTrackById(lsLineTrack.getToStraightTrack());
            lineTrack.setFromStraightTrack(fromStraight);
            lineTrack.setToStraightTrack(toStraight);
            line.addTrack(lineTrack);
        }
    return line;
}
Also used : Line(net.parostroj.timetable.model.Line) NodeTrack(net.parostroj.timetable.model.NodeTrack) Node(net.parostroj.timetable.model.Node) Net(net.parostroj.timetable.model.Net) LineTrack(net.parostroj.timetable.model.LineTrack)

Example 3 with LineTrack

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

the class LSLineTrack method createLineTrack.

public LineTrack createLineTrack(Function<String, ObjectWithId> mapping) throws LSException {
    LineTrack lineTrack = new LineTrack(this.getId());
    this.addValuesTrack(mapping, lineTrack);
    return lineTrack;
}
Also used : LineTrack(net.parostroj.timetable.model.LineTrack)

Example 4 with LineTrack

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

the class LSLineTrack method createLineTrack.

public LineTrack createLineTrack() {
    LineTrack lineTrack = new LineTrack(this.getId());
    this.addValuesTrack(lineTrack);
    return lineTrack;
}
Also used : LineTrack(net.parostroj.timetable.model.LineTrack)

Example 5 with LineTrack

use of net.parostroj.timetable.model.LineTrack 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;
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) TimeInterval(net.parostroj.timetable.model.TimeInterval) LocalizedString(net.parostroj.timetable.model.LocalizedString) ParseException(java.text.ParseException) LocalizedString(net.parostroj.timetable.model.LocalizedString) LineTrack(net.parostroj.timetable.model.LineTrack) NodeTrack(net.parostroj.timetable.model.NodeTrack) Track(net.parostroj.timetable.model.Track) LineTrack(net.parostroj.timetable.model.LineTrack)

Aggregations

LineTrack (net.parostroj.timetable.model.LineTrack)6 NodeTrack (net.parostroj.timetable.model.NodeTrack)4 Line (net.parostroj.timetable.model.Line)3 Node (net.parostroj.timetable.model.Node)3 TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)2 Train (net.parostroj.timetable.model.Train)2 ParseException (java.text.ParseException)1 LocalizedString (net.parostroj.timetable.model.LocalizedString)1 Net (net.parostroj.timetable.model.Net)1 TimeInterval (net.parostroj.timetable.model.TimeInterval)1 Track (net.parostroj.timetable.model.Track)1