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);
}
}
}
}
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;
}
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;
}
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;
}
Aggregations