Search in sources :

Example 1 with TrainIntervalsBuilder

use of net.parostroj.timetable.actions.TrainIntervalsBuilder 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 TrainIntervalsBuilder

use of net.parostroj.timetable.actions.TrainIntervalsBuilder in project grafikon by jub77.

the class TrainImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId importedObject) {
    // check class
    if (!(importedObject instanceof Train)) {
        // skip other objects
        return null;
    }
    Train importedTrain = (Train) importedObject;
    // check if the train already exist
    Train checkedTrain = this.getTrain(importedTrain);
    if (checkedTrain != null) {
        String message = "train already exists";
        this.addError(importedTrain, message);
        log.debug("{}: {}", message, checkedTrain);
        return null;
    }
    // create a new train
    TrainType trainType = this.getTrainType(importedTrain.getType());
    if (trainType == null) {
        String message = "train type missing: " + importedTrain.getType();
        this.addError(importedTrain, message);
        log.debug(message);
        return null;
    }
    Train train = getDiagram().getPartFactory().createTrain(this.getId(importedTrain));
    train.setNumber(importedTrain.getNumber());
    train.getAttributes().add(this.importAttributes(importedTrain.getAttributes()));
    train.setDescription(importedTrain.getDescription());
    train.setType(trainType);
    train.setTopSpeed(importedTrain.getTopSpeed());
    TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, importedTrain.getStartTime());
    // create route (new)
    List<Triplet<RouteSegment<?>, Track, TimeInterval>> route = createNewRoute(importedTrain);
    if (route == null) {
        String message = "error creating route for train";
        this.addError(importedTrain, message);
        log.debug("{}: {}", message, importedTrain);
        return null;
    }
    for (Triplet<RouteSegment<?>, Track, TimeInterval> seg : route) {
        if (seg.first instanceof Node) {
            // node
            Node node = (Node) seg.first;
            builder.addNode(this.getId(seg.third), node, (NodeTrack) seg.second, seg.third.getLength(), seg.third.getAttributes());
        } else {
            // line
            Line line = (Line) seg.first;
            builder.addLine(this.getId(seg.third), line, (LineTrack) seg.second, seg.third.getSpeedLimit(), seg.third.getAddedTime(), seg.third.getAttributes());
        }
    }
    builder.finish();
    train.setTimeBefore(importedTrain.getTimeBefore());
    train.setTimeAfter(importedTrain.getTimeAfter());
    this.getDiagram().getTrains().add(train);
    this.addImportedObject(train);
    log.trace("Successfully imported train: {}", train);
    return train;
}
Also used : TrainIntervalsBuilder(net.parostroj.timetable.actions.TrainIntervalsBuilder) Triplet(net.parostroj.timetable.utils.Triplet)

Example 3 with TrainIntervalsBuilder

use of net.parostroj.timetable.actions.TrainIntervalsBuilder in project grafikon by jub77.

the class LSTrain method createTrain.

public DelayedAttributes<Train> createTrain(TrainDiagram diagram) throws LSException {
    Train train = diagram.getPartFactory().createTrain(id);
    train.setNumber(number);
    train.setDescription(desc);
    train.setTopSpeed(topSpeed);
    train.setType(diagram.getTrainTypes().getById(type));
    // build time interval list
    TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, start);
    if (this.route != null) {
        for (Object routePart : this.route) {
            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(diagram::getObjectById));
            } 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(), linePart.getAddedTime() != null ? linePart.getAddedTime() : 0, linePart.getAttributes().createAttributes(diagram::getObjectById));
            }
        }
    }
    builder.finish();
    // set technological time
    train.setTimeBefore(this.timeBefore);
    train.setTimeAfter(this.timeAfter);
    return new DelayedAttributes<>(train, attributes, diagram::getObjectById);
}
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)

Aggregations

TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)3 Line (net.parostroj.timetable.model.Line)2 LineTrack (net.parostroj.timetable.model.LineTrack)2 Node (net.parostroj.timetable.model.Node)2 NodeTrack (net.parostroj.timetable.model.NodeTrack)2 Train (net.parostroj.timetable.model.Train)2 Triplet (net.parostroj.timetable.utils.Triplet)1