Search in sources :

Example 21 with Train

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

the class PreviousNextTrainValidator method validate.

@Override
public boolean validate(Event event) {
    checkRemovedTrain(event);
    if (event.getSource() instanceof Train) {
        Train currentTrain = (Train) event.getSource();
        checkTrainAttributes(event, currentTrain);
        checkTrainIntervals(event, currentTrain);
        return true;
    }
    return false;
}
Also used : Train(net.parostroj.timetable.model.Train)

Example 22 with Train

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

the class BaseConnectionStrategy method getFreightPassedInNode.

protected Map<Train, List<FreightConnectionPath>> getFreightPassedInNode(TimeInterval fromInterval, FreightConnectionFilter filter) {
    if (!fromInterval.isNodeOwner()) {
        throw new IllegalArgumentException("Only node intervals allowed.");
    }
    Map<Train, List<FreightConnectionPath>> result = new LinkedHashMap<>();
    List<FNConnection> connections = freightNet.getTrainsFrom(fromInterval);
    for (FNConnection conn : connections) {
        List<FreightConnectionPath> nodes = this.getFreightToNodesImpl(conn.getTo(), conn.getFreightDstFilter(filter, true));
        result.put(conn.getTo().getTrain(), nodes);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Train(net.parostroj.timetable.model.Train) FNConnection(net.parostroj.timetable.model.FNConnection) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with Train

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

the class XmlTrainTimetablesOutput method writeTo.

@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
    try {
        // extract tts
        List<Train> trains = SelectionHelper.selectTrains(params, diagram);
        List<Route> routes = SelectionHelper.getRoutes(params, diagram, trains);
        TrainsCycle cycle = SelectionHelper.getDriverCycle(params);
        TrainTimetablesExtractor te = new TrainTimetablesExtractor(diagram, trains, routes, cycle, this.getLocale());
        TrainTimetables tt = te.getTrainTimetables();
        JAXBContext context = JAXBContext.newInstance(TrainTimetables.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        Writer writer = new OutputStreamWriter(stream, this.getCharset());
        m.marshal(tt, writer);
    } catch (Exception e) {
        throw new OutputException(e);
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) TrainTimetablesExtractor(net.parostroj.timetable.output2.impl.TrainTimetablesExtractor) TrainTimetables(net.parostroj.timetable.output2.impl.TrainTimetables) Train(net.parostroj.timetable.model.Train) Route(net.parostroj.timetable.model.Route) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 24 with Train

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

the class CopyTrainPM method writeResult.

private void writeResult() {
    // create copy of the train
    Train train = this.trainRef.get();
    if (train != null) {
        TrainDiagram diagram = train.getDiagram();
        int lTime = this.time.getTime();
        if (lTime == -1) {
            // select midnight if the time is not correct
            lTime = 0;
        }
        TrainBuilder builder = new TrainBuilder();
        String name = this.number.getText();
        Train newTrain = reversed.getBoolean() ? builder.createReverseTrain(IdGenerator.getInstance().getId(), name, lTime, train) : builder.createTrain(IdGenerator.getInstance().getId(), name, lTime, train);
        // add train to diagram
        diagram.getTrains().add(newTrain);
    }
}
Also used : TrainBuilder(net.parostroj.timetable.actions.TrainBuilder) Train(net.parostroj.timetable.model.Train) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 25 with Train

use of net.parostroj.timetable.model.Train 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

Train (net.parostroj.timetable.model.Train)31 TimeInterval (net.parostroj.timetable.model.TimeInterval)8 LinkedList (java.util.LinkedList)5 Node (net.parostroj.timetable.model.Node)5 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)5 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)5 List (java.util.List)4 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FNConnection (net.parostroj.timetable.model.FNConnection)3 TranslatedString (net.parostroj.timetable.model.TranslatedString)3 Component (java.awt.Component)2 Rectangle (java.awt.Rectangle)2 Shape (java.awt.Shape)2 JOptionPane (javax.swing.JOptionPane)2 TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)2 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 Group (net.parostroj.timetable.model.Group)2 Route (net.parostroj.timetable.model.Route)2