Search in sources :

Example 1 with FreightColor

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

the class LoadFilter4d22 method checkDiagram.

@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
    if (version.compareTo(new ModelVersion(4, 22, 0)) <= 0) {
        for (Node node : diagram.getNet().getNodes()) {
            node.getAttributes().setSkipListeners(true);
            try {
                Collection<Region> regions = node.getAttributeAsCollection(Node.ATTR_REGIONS, Region.class);
                if (regions != null && !(regions instanceof Set)) {
                    node.setAttribute(Node.ATTR_REGIONS, new HashSet<>(regions));
                }
                Collection<Region> centerRegions = node.getAttributeAsCollection(Node.ATTR_CENTER_OF_REGIONS, Region.class);
                if (centerRegions != null && !(centerRegions instanceof Set)) {
                    node.setAttribute(Node.ATTR_CENTER_OF_REGIONS, new HashSet<>(centerRegions));
                }
                Collection<FreightColor> freightColors = node.getAttributeAsCollection(Node.ATTR_FREIGHT_COLORS, FreightColor.class);
                if (freightColors != null && !(freightColors instanceof Set)) {
                    node.setAttribute(Node.ATTR_FREIGHT_COLORS, new HashSet<>(freightColors));
                }
            } finally {
                node.getAttributes().setSkipListeners(false);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Node(net.parostroj.timetable.model.Node) Region(net.parostroj.timetable.model.Region) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) FreightColor(net.parostroj.timetable.model.FreightColor)

Example 2 with FreightColor

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

the class RegionPM method ok.

@Operation(path = "ok")
public boolean ok() {
    Region region = regionRef.get();
    if (region != null) {
        // write back
        region.setAttribute(Region.ATTR_LOCALE, locale.getValue());
        region.setName(ObjectsUtil.checkAndTrim(name.getText()));
        region.setSuperRegion(this.superRegion.getValue());
        region.setFreightColorRegion(colorRegion.getBoolean());
        // color mapping
        Map<FreightColor, Region> map = new EnumMap<>(FreightColor.class);
        for (ColorMappingPM cMapping : colorMap) {
            FreightColor mColor = cMapping.color.getValue();
            Region mRegion = cMapping.region.getValue();
            if (mColor != null && mRegion != null) {
                map.put(mColor, mRegion);
            }
        }
        region.setFreightColorMap(map);
    }
    return true;
}
Also used : Region(net.parostroj.timetable.model.Region) FreightColor(net.parostroj.timetable.model.FreightColor) EnumMap(java.util.EnumMap) Operation(org.beanfabrics.support.Operation)

Example 3 with FreightColor

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

the class FreightAnalyser method getFreightColors.

/**
 * Extracts information about colors.
 *
 * @param fromNode from node
 * @param toNode to node (if exists, can be null)
 * @param toRegions target regions (can be empty if the target is node only
 * @return set of colors for the connection
 */
public static Set<FreightColor> getFreightColors(Node fromNode, Node toNode, Set<Region> toRegions) {
    Set<FreightColor> colors = Collections.emptySet();
    Region fromFC = fromNode.getRegionHierarchy().getFreightColorRegion();
    if (toNode != null && !toNode.getFreightColors().isEmpty()) {
        // node colors ...
        Region toFC = toNode.getRegionHierarchy().getFreightColorRegion();
        if (fromFC == toFC) {
            // in the same region - use node freight color ...
            colors = toNode.getFreightColors();
        }
    }
    if (!toRegions.isEmpty()) {
        Region toFC = RegionHierarchy.from(toRegions).getFreightColorRegion();
        if (fromFC == toFC) {
            // the same freight color region - get all freight colors from regions
            Stream<FreightColor> regionColors = toRegions.stream().flatMap(r -> r.getAllNodes().stream()).flatMap(n -> n.getFreightColors().stream());
            colors = Stream.concat(regionColors, colors.stream()).collect(toSet());
        } else {
            // different freight color regions - get colors from color map
            if (fromFC != null && toFC != null) {
                Stream<FreightColor> regionMapColors = fromFC.getFreightColorMap().entrySet().stream().filter(e -> e.getValue() == toFC).map(Map.Entry::getKey);
                colors = Stream.concat(regionMapColors, colors.stream()).collect(toSet());
            }
        }
    }
    return colors;
}
Also used : RegionHierarchy(net.parostroj.timetable.model.RegionHierarchy) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Region(net.parostroj.timetable.model.Region) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Set(java.util.Set) Function(java.util.function.Function) Node(net.parostroj.timetable.model.Node) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Stream(java.util.stream.Stream) TimeInterval(net.parostroj.timetable.model.TimeInterval) Collectors.toMap(java.util.stream.Collectors.toMap) Collectors.mapping(java.util.stream.Collectors.mapping) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) Pair(net.parostroj.timetable.utils.Pair) ObjectsUtil.intersects(net.parostroj.timetable.utils.ObjectsUtil.intersects) Collections(java.util.Collections) TrainsCycle(net.parostroj.timetable.model.TrainsCycle) Collectors.toSet(java.util.stream.Collectors.toSet) TimeUtil(net.parostroj.timetable.utils.TimeUtil) FreightColor(net.parostroj.timetable.model.FreightColor) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType) Region(net.parostroj.timetable.model.Region) FreightColor(net.parostroj.timetable.model.FreightColor)

Example 4 with FreightColor

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

the class FreightDestinationInfo method convert.

public static FreightDestinationInfo convert(Locale locale, FreightConnection dst) {
    FreightDestinationInfo info = new FreightDestinationInfo();
    if (dst.getTo().isNode()) {
        Node to = dst.getTo().getNode();
        info.setName(to.getName());
        info.setAbbr(to.getAbbr());
        List<FreightColor> sortedColors = OutputFreightUtil.sortFreightColors(dst.getTo().getFreightColors());
        info.setColors(sortedColors == null || sortedColors.isEmpty() ? null : sortedColors);
        if (!dst.getTo().isVisible()) {
            info.setHidden(true);
        }
    }
    if (dst.getTo().isRegions()) {
        Set<Region> regions = dst.getTo().getRegions();
        info.setRegions(new OutputFreightUtil().regionsToString(regions, locale));
    }
    return info;
}
Also used : Node(net.parostroj.timetable.model.Node) Region(net.parostroj.timetable.model.Region) OutputFreightUtil(net.parostroj.timetable.output2.util.OutputFreightUtil) FreightColor(net.parostroj.timetable.model.FreightColor)

Aggregations

FreightColor (net.parostroj.timetable.model.FreightColor)4 Region (net.parostroj.timetable.model.Region)4 Node (net.parostroj.timetable.model.Node)3 Set (java.util.Set)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumMap (java.util.EnumMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)1 Collectors.mapping (java.util.stream.Collectors.mapping)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 RegionHierarchy (net.parostroj.timetable.model.RegionHierarchy)1