Search in sources :

Example 16 with TrainType

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

the class LSTrainType method createTrainType.

public TrainType createTrainType(PartFactory partFactory, Function<String, ObjectWithId> mapping, Function<String, TrainTypeCategory> categoryMapping) throws LSException {
    TrainType type = partFactory.createTrainType(id);
    if (abbr != null) {
        type.setAbbr(LocalizedString.fromString(abbr));
    }
    type.setColor(Conversions.convertTextToColor(color));
    if (desc != null) {
        type.setDesc(LocalizedString.fromString(desc));
    }
    type.setPlatform(platform);
    type.setTrainCompleteNameTemplate(trainCompleteNameTemplate != null ? trainCompleteNameTemplate.createTextTemplate() : null);
    type.setTrainNameTemplate(trainNameTemplate != null ? trainNameTemplate.createTextTemplate() : null);
    type.setCategory(categoryMapping.apply(categoryId));
    if (attributes != null) {
        type.getAttributes().add(attributes.createAttributes(mapping));
    }
    return type;
}
Also used : TrainType(net.parostroj.timetable.model.TrainType)

Example 17 with TrainType

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

the class LoadFilter4d21 method checkDiagram.

@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
    if (version.compareTo(new ModelVersion(4, 21, 0)) <= 0) {
        // convert route unit...
        Attributes attributes = diagram.getAttributes();
        if (attributes.containsKey(TrainDiagram.ATTR_ROUTE_LENGTH_UNIT)) {
            // try to convert to length unit
            String lUnitStr = attributes.get(TrainDiagram.ATTR_ROUTE_LENGTH_UNIT, String.class);
            LengthUnit lUnit = LengthUnit.getByKey(lUnitStr);
            attributes.setRemove(TrainDiagram.ATTR_ROUTE_LENGTH_UNIT, lUnit);
        }
    }
    if (version.compareTo(new ModelVersion(4, 21, 1)) <= 0) {
        // convert train name templates (common)
        diagram.getTrainsData().setTrainNameTemplate(convertForAbbreviation(diagram.getTrainsData().getTrainNameTemplate()));
        diagram.getTrainsData().setTrainCompleteNameTemplate(convertForAbbreviation(diagram.getTrainsData().getTrainCompleteNameTemplate()));
        // in train types
        for (TrainType type : diagram.getTrainTypes()) {
            type.setTrainNameTemplate(convertForAbbreviation(type.getTrainNameTemplate()));
            type.setTrainCompleteNameTemplate(convertForAbbreviation(type.getTrainCompleteNameTemplate()));
        }
    }
}
Also used : Attributes(net.parostroj.timetable.model.Attributes) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) TrainType(net.parostroj.timetable.model.TrainType) LengthUnit(net.parostroj.timetable.model.units.LengthUnit)

Example 18 with TrainType

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

TrainType (net.parostroj.timetable.model.TrainType)18 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)4 LSException (net.parostroj.timetable.model.ls.LSException)3 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 Node (net.parostroj.timetable.model.Node)2 Train (net.parostroj.timetable.model.Train)2 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)2 LengthUnit (net.parostroj.timetable.model.units.LengthUnit)2 Pair (net.parostroj.timetable.utils.Pair)2 Color (java.awt.Color)1 GridLayout (java.awt.GridLayout)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 JCheckBox (javax.swing.JCheckBox)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1 Attributes (net.parostroj.timetable.model.Attributes)1 CopyFactory (net.parostroj.timetable.model.CopyFactory)1