use of net.parostroj.timetable.model.Node in project grafikon by jub77.
the class RegionValidator method removeRegionFromNet.
private void removeRegionFromNet(Region region) {
// remove region from all nodes where it appears
for (Node node : diagram.getNet().getNodes()) {
if (node.getRegions().contains(region)) {
node.setRemoveAttribute(Node.ATTR_REGIONS, this.removeRegion(node.getRegions(), region));
node.setRemoveAttribute(Node.ATTR_CENTER_OF_REGIONS, this.removeRegion(node.getCenterRegions(), region));
}
}
}
use of net.parostroj.timetable.model.Node in project grafikon by jub77.
the class SelectNodesDialog method setNodes.
public void setNodes(Set<Node> nodes) {
List<Node> sortedNodes = (new ElementSort<Node>(new NodeComparator())).sort(nodes);
nodesComboBox.removeAllItems();
for (Node node : sortedNodes) {
nodesComboBox.addItem(node);
}
nodesComboBox.setSelectedIndex(0);
this.selectedNode = null;
this.pack();
}
use of net.parostroj.timetable.model.Node in project grafikon by jub77.
the class BaseConnectionStrategy method getFreightToNodesImpl.
private void getFreightToNodesImpl(Node start, TimeInterval fromInterval, List<TrainConnection> path, List<FreightConnectionPath> result, Set<FNConnection> used, FreightConnectionFilter filter, FilterContext context) {
FilterResult filterResult;
Iterator<TimeInterval> intervals = fromInterval.getTrain().iterator();
Iterators.find(intervals, interval -> interval == fromInterval);
intervals = Iterators.filter(intervals, interval -> interval.isNodeOwner() && (interval.isFreightTo() || interval.isFreightConnection()));
while (intervals.hasNext()) {
TimeInterval i = intervals.next();
if (i.isFreight()) {
FreightConnectionPath newDst = FreightFactory.createFreightNodeConnection(start, i.getOwnerAsNode(), i.isRegionCenterTransfer(), createNewPath(path, fromInterval, i));
filterResult = filter.accepted(context, newDst, 0);
if (filterResult == FilterResult.STOP_EXCLUDE) {
break;
}
if (filterResult != FilterResult.IGNORE) {
result.add(newDst);
}
if (filterResult == FilterResult.STOP_INCLUDE) {
break;
}
}
for (FNConnection conn : freightNet.getTrainsFrom(i)) {
if (!used.contains(conn)) {
used.add(conn);
List<TrainConnection> newPath = createNewPath(path, fromInterval, conn.getFrom());
this.getFreightToNodesImpl(start, conn.getTo(), newPath, result, used, conn.getFreightDstFilter(filter, false), context);
}
}
}
}
use of net.parostroj.timetable.model.Node in project grafikon by jub77.
the class NodeImport method importObjectImpl.
@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
// check class
if (!(o instanceof Node))
return null;
Node importedNode = (Node) o;
// check if the train already exist
Node checkedNode = this.getNode(importedNode);
if (checkedNode != null) {
String message = "station already exists";
this.addError(importedNode, message);
log.debug("{}: {}", message, checkedNode);
return null;
}
// create new node
Node node = getDiagram().getPartFactory().createNode(this.getId(importedNode), importedNode.getType(), importedNode.getName(), importedNode.getAbbr());
node.getAttributes().add(this.importAttributes(importedNode.getAttributes()));
node.setLocation(importedNode.getLocation());
// tracks
for (NodeTrack importedTrack : importedNode.getTracks()) {
NodeTrack track = new NodeTrack(this.getId(importedTrack), importedTrack.getNumber());
track.setPlatform(importedTrack.isPlatform());
track.getAttributes().add(this.importAttributes(importedTrack.getAttributes()));
node.addTrack(track);
}
// add to diagram
this.getDiagram().getNet().addNode(node);
this.addImportedObject(node);
log.trace("Successfully imported node: {}", node);
return node;
}
use of net.parostroj.timetable.model.Node 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;
}
Aggregations