Search in sources :

Example 26 with Node

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));
        }
    }
}
Also used : Node(net.parostroj.timetable.model.Node)

Example 27 with Node

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();
}
Also used : NodeComparator(net.parostroj.timetable.actions.NodeComparator) Node(net.parostroj.timetable.model.Node) ElementSort(net.parostroj.timetable.actions.ElementSort)

Example 28 with Node

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);
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) Collection(java.util.Collection) Set(java.util.Set) Node(net.parostroj.timetable.model.Node) Iterators(com.google.common.collect.Iterators) FNConnection(net.parostroj.timetable.model.FNConnection) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) FilterContext(net.parostroj.timetable.model.FreightConnectionFilter.FilterContext) TimeInterval(net.parostroj.timetable.model.TimeInterval) FreightNet(net.parostroj.timetable.model.FreightNet) Map(java.util.Map) FreightConnectionFilter(net.parostroj.timetable.model.FreightConnectionFilter) LinkedList(java.util.LinkedList) Collections(java.util.Collections) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) Train(net.parostroj.timetable.model.Train) TimeInterval(net.parostroj.timetable.model.TimeInterval) FilterResult(net.parostroj.timetable.model.FreightConnectionFilter.FilterResult) FNConnection(net.parostroj.timetable.model.FNConnection)

Example 29 with Node

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;
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) Node(net.parostroj.timetable.model.Node)

Example 30 with 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;
}
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)

Aggregations

Node (net.parostroj.timetable.model.Node)39 List (java.util.List)10 ArrayList (java.util.ArrayList)9 TimeInterval (net.parostroj.timetable.model.TimeInterval)9 BorderLayout (java.awt.BorderLayout)8 Collection (java.util.Collection)8 Region (net.parostroj.timetable.model.Region)8 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)8 FlowLayout (java.awt.FlowLayout)7 Comparator (java.util.Comparator)7 Set (java.util.Set)7 BorderFactory (javax.swing.BorderFactory)7 JButton (javax.swing.JButton)7 JPanel (javax.swing.JPanel)7 JScrollPane (javax.swing.JScrollPane)7 RxActionHandler (net.parostroj.timetable.gui.actions.execution.RxActionHandler)7 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)7 GuiIcon (net.parostroj.timetable.gui.utils.GuiIcon)7 ResourceLoader (net.parostroj.timetable.gui.utils.ResourceLoader)7 ItemEvent (java.awt.event.ItemEvent)6