Search in sources :

Example 26 with Train

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

the class LSTrainsCycleItem method createTrainsCycleItem.

public TrainsCycleItem createTrainsCycleItem(TrainsCycle cycle, TrainDiagram diagram) throws LSException {
    Train modelTrain = diagram.getTrains().getById(train);
    TrainsCycleItem item = new TrainsCycleItem(cycle, modelTrain, LocalizedString.fromString(comment), modelTrain.getIntervalById(from), modelTrain.getIntervalById(to));
    if (attributes != null) {
        item.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
    }
    return item;
}
Also used : TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) Train(net.parostroj.timetable.model.Train)

Example 27 with Train

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

the class LoadFilter4d19 method checkDiagram.

@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
    if (version.compareTo(new ModelVersion(4, 19, 0)) <= 0) {
        // not passing cargo in center (move to time interval from train)
        for (Train train : diagram.getTrains()) {
            if (train.getAttributeAsBool("no.transitive.region.start")) {
                for (TimeInterval interval : train.getNodeIntervals()) {
                    if (interval.isFirst())
                        continue;
                    if (interval.getOwnerAsNode().isCenterOfRegions()) {
                        interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, true);
                    }
                }
            }
        }
    }
    if (version.compareTo(new ModelVersion(4, 19, 2)) <= 0) {
        // convert some texts to localized strings
        this.convertToLocalizedStrings(diagram);
        // filter out output templates with default.template
        removeDefaultTemplatesExceptDrawAndXml(diagram);
    }
}
Also used : TimeInterval(net.parostroj.timetable.model.TimeInterval) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) Train(net.parostroj.timetable.model.Train)

Example 28 with Train

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

the class LoadFilter4d2 method checkDiagram.

@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
    if (version.compareTo(new ModelVersion(4, 2)) <= 0) {
        // fix weight info
        for (Train train : diagram.getTrains()) {
            Integer weight = TrainsHelper.getWeightFromInfoAttribute(train);
            if (weight != null) {
                train.setAttribute(Train.ATTR_WEIGHT, weight);
            }
            // remove weight.info attribute
            train.removeAttribute("weight.info");
        }
        // fix route info
        for (Train train : diagram.getTrains()) {
            String routeInfo = ObjectsUtil.checkAndTrim(train.getAttribute("route.info", String.class));
            if (routeInfo != null) {
                try {
                    train.setAttribute(Train.ATTR_ROUTE, this.convert(routeInfo));
                } catch (GrafikonException e) {
                    log.warn("Couldn't convert route info to template: {}", e.getMessage());
                }
                train.removeAttribute("route.info");
            }
        }
    }
}
Also used : GrafikonException(net.parostroj.timetable.model.GrafikonException) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) Train(net.parostroj.timetable.model.Train)

Example 29 with Train

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

the class TrainTimetablesExtractor method getTrainTimetables.

public TrainTimetables getTrainTimetables() {
    List<TrainTimetable> result = new LinkedList<>();
    List<Text> texts = null;
    // trains
    for (Train train : trains) {
        result.add(this.createTimetable(train));
    }
    // texts
    for (TextItem item : diagram.getTextItems()) {
        Text text = this.createText(item);
        if (text != null) {
            if (texts == null) {
                texts = new LinkedList<>();
            }
            texts.add(text);
        }
    }
    TrainTimetables timetables = new TrainTimetables(result);
    timetables.setTexts(texts);
    // routes
    timetables.setRoutes(RoutesExtractor.convert(routes, diagram));
    // route length unit
    LengthUnit unit = diagram.getAttribute(TrainDiagram.ATTR_ROUTE_LENGTH_UNIT, LengthUnit.class);
    if (unit != null) {
        timetables.setRouteLengthUnit(unit);
    }
    // route info (lower priority)
    timetables.setRouteNumbers(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_NUMBERS, String.class));
    timetables.setRouteStations(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_NODES, String.class));
    // validity
    timetables.setValidity(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_VALIDITY, String.class));
    // cycle
    if (cycle != null) {
        DriverCyclesExtractor ex = new DriverCyclesExtractor(diagram, null, false);
        timetables.setCycle(ex.createCycle(cycle));
    }
    return timetables;
}
Also used : TextItem(net.parostroj.timetable.model.TextItem) TranslatedString(net.parostroj.timetable.model.TranslatedString) Train(net.parostroj.timetable.model.Train) LinkedList(java.util.LinkedList) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

Example 30 with Train

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

the class StationTimetablesExtractor method getLength.

private LengthInfo getLength(TimeInterval interval) {
    LengthInfo lengthInfo = null;
    Train train = interval.getTrain();
    TrainType trainType = train.getType();
    if (!interval.isLast() && interval.isStop() && trainType != null && trainType.getAttributes().getBool(TrainType.ATTR_SHOW_WEIGHT_INFO)) {
        Pair<Node, Integer> length = getNextLength(interval.getOwnerAsNode(), train, NextType.LAST_STATION);
        // if length was calculated
        if (length != null && length.second != null) {
            // update length with station lengths
            lengthInfo = new LengthInfo();
            lengthInfo.setLength(length.second);
            LengthUnit lengthUnitObj = diagram.getAttribute(TrainDiagram.ATTR_LENGTH_UNIT, LengthUnit.class);
            lengthInfo.setLengthInAxles(LengthUnit.AXLE == lengthUnitObj);
            lengthInfo.setLengthUnit(lengthUnitObj);
            lengthInfo.setStationAbbr(length.first.getAbbr());
        }
    }
    return lengthInfo;
}
Also used : Node(net.parostroj.timetable.model.Node) TrainType(net.parostroj.timetable.model.TrainType) Train(net.parostroj.timetable.model.Train) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

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