Search in sources :

Example 11 with ModelVersion

use of net.parostroj.timetable.model.ls.ModelVersion 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 12 with ModelVersion

use of net.parostroj.timetable.model.ls.ModelVersion 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 13 with ModelVersion

use of net.parostroj.timetable.model.ls.ModelVersion 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)

Aggregations

ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)13 LSException (net.parostroj.timetable.model.ls.LSException)6 Properties (java.util.Properties)4 ZipEntry (java.util.zip.ZipEntry)3 IOException (java.io.IOException)2 Node (net.parostroj.timetable.model.Node)2 Region (net.parostroj.timetable.model.Region)2 Train (net.parostroj.timetable.model.Train)2 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)2 TrainType (net.parostroj.timetable.model.TrainType)2 LSFile (net.parostroj.timetable.model.ls.LSFile)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1 ZipInputStream (java.util.zip.ZipInputStream)1 Attributes (net.parostroj.timetable.model.Attributes)1 FreightColor (net.parostroj.timetable.model.FreightColor)1 GrafikonException (net.parostroj.timetable.model.GrafikonException)1