Search in sources :

Example 1 with Line

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

the class LSTrain method createTrain.

public Train createTrain(TrainDiagram diagram) {
    Train train = diagram.getPartFactory().createTrain(id);
    train.setNumber(number);
    train.getAttributes().add(attributes.createAttributes());
    train.setDescription(desc);
    train.setTopSpeed(topSpeed);
    train.setType(diagram.getTrainTypes().getById(type));
    // build time interval list
    TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, start);
    for (Object routePart : getRoute()) {
        if (routePart instanceof LSTrainRoutePartNode) {
            LSTrainRoutePartNode nodePart = (LSTrainRoutePartNode) routePart;
            Node node = diagram.getNet().getNodeById(nodePart.getNodeId());
            NodeTrack nodeTrack = node.getTrackById(nodePart.getTrackId());
            builder.addNode(nodePart.getIntervalId(), node, nodeTrack, nodePart.getStop(), nodePart.getAttributes().createAttributes());
        } else {
            LSTrainRoutePartLine linePart = (LSTrainRoutePartLine) routePart;
            Line line = diagram.getNet().getLineById(linePart.getLineId());
            LineTrack lineTrack = line.getTrackById(linePart.getTrackId());
            builder.addLine(linePart.getIntervalId(), line, lineTrack, linePart.getSpeed(), 0, linePart.getAttributes().createAttributes());
        }
    }
    builder.finish();
    // set technological time
    train.setTimeBefore(this.timeBefore);
    train.setTimeAfter(this.timeAfter);
    return train;
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) Line(net.parostroj.timetable.model.Line) TrainIntervalsBuilder(net.parostroj.timetable.actions.TrainIntervalsBuilder) Node(net.parostroj.timetable.model.Node) Train(net.parostroj.timetable.model.Train) LineTrack(net.parostroj.timetable.model.LineTrack)

Example 2 with Line

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

the class LSLine method createLine.

public Line createLine(TrainDiagram diagram) throws LSException {
    Net net = diagram.getNet();
    Node fromNode = net.getNodeById(getFrom());
    Node toNode = net.getNodeById(getTo());
    if (speed != null && speed <= 0) {
        speed = null;
    }
    Line line = diagram.getPartFactory().createLine(id, length, fromNode, toNode, speed);
    line.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
    // tracks
    if (this.tracks != null)
        for (LSLineTrack lsLineTrack : this.tracks) {
            LineTrack lineTrack = lsLineTrack.createLineTrack(diagram::getObjectById);
            NodeTrack fromStraight = fromNode.getTrackById(lsLineTrack.getFromStraightTrack());
            NodeTrack toStraight = toNode.getTrackById(lsLineTrack.getToStraightTrack());
            lineTrack.setFromStraightTrack(fromStraight);
            lineTrack.setToStraightTrack(toStraight);
            line.addTrack(lineTrack);
        }
    return line;
}
Also used : Line(net.parostroj.timetable.model.Line) NodeTrack(net.parostroj.timetable.model.NodeTrack) Node(net.parostroj.timetable.model.Node) Net(net.parostroj.timetable.model.Net) LineTrack(net.parostroj.timetable.model.LineTrack)

Example 3 with Line

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

the class NetGraphComponent method createConnectionHandler.

@Override
protected mxConnectionHandler createConnectionHandler() {
    return new mxConnectionHandler(this) {

        @Override
        public boolean isValidTarget(Object cell) {
            if (cell != null) {
                Object object = ((mxCell) cell).getValue();
                if (object instanceof Node) {
                    Graph<Node, Line> net = getNet();
                    Node targetNode = (Node) object;
                    Node sourceNode = (Node) ((mxCell) source.getCell()).getValue();
                    return !net.containsEdge(sourceNode, targetNode);
                }
            }
            return super.isValidTarget(cell);
        }
    };
}
Also used : Line(net.parostroj.timetable.model.Line) com.mxgraph.model.mxCell(com.mxgraph.model.mxCell) Node(net.parostroj.timetable.model.Node) com.mxgraph.swing.handler.mxConnectionHandler(com.mxgraph.swing.handler.mxConnectionHandler)

Example 4 with Line

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

the class TrainDiagramBuilder method setNet.

public void setNet(LSNet lsNet) throws LSException {
    Net net = lsNet.createNet(this.diagram);
    this.diagram.setNet(net);
    // add regions
    if (lsNet.getRegions() != null) {
        Collection<DelayedAttributes<Region>> regions = new ArrayList<>();
        for (LSRegion lsRegion : lsNet.getRegions()) {
            DelayedAttributes<Region> daRegion = lsRegion.createRegion(diagram);
            net.getRegions().add(daRegion.getObject());
            regions.add(daRegion);
        }
        for (DelayedAttributes<Region> daRegion : regions) {
            daRegion.addAttributes();
        }
    }
    // add line classes
    if (lsNet.getLineClasses() != null) {
        for (LSLineClass lsLineClass : lsNet.getLineClasses()) {
            net.getLineClasses().add(lsLineClass.createLineClass());
        }
    }
    // create nodes ...
    if (lsNet.getNodes() != null) {
        for (LSNode lsNode : lsNet.getNodes()) {
            Node node = lsNode.createNode(diagram.getPartFactory(), diagram::getObjectById);
            net.addNode(node);
        }
    }
    // create lines ...
    if (lsNet.getLines() != null) {
        for (LSLine lsLine : lsNet.getLines()) {
            Line line = lsLine.createLine(diagram);
            Node from = net.getNodeById(lsLine.getFrom());
            Node to = net.getNodeById(lsLine.getTo());
            net.addLine(from, to, line);
        }
    }
}
Also used : Node(net.parostroj.timetable.model.Node) ArrayList(java.util.ArrayList) Line(net.parostroj.timetable.model.Line) Region(net.parostroj.timetable.model.Region) Net(net.parostroj.timetable.model.Net) FreightNet(net.parostroj.timetable.model.FreightNet)

Example 5 with Line

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

the class LSTrain method createTrain.

public DelayedAttributes<Train> createTrain(TrainDiagram diagram) throws LSException {
    Train train = diagram.getPartFactory().createTrain(id);
    train.setNumber(number);
    train.setDescription(desc);
    train.setTopSpeed(topSpeed);
    train.setType(diagram.getTrainTypes().getById(type));
    // build time interval list
    TrainIntervalsBuilder builder = new TrainIntervalsBuilder(train, start);
    if (this.route != null) {
        for (Object routePart : this.route) {
            if (routePart instanceof LSTrainRoutePartNode) {
                LSTrainRoutePartNode nodePart = (LSTrainRoutePartNode) routePart;
                Node node = diagram.getNet().getNodeById(nodePart.getNodeId());
                NodeTrack nodeTrack = node.getTrackById(nodePart.getTrackId());
                builder.addNode(nodePart.getIntervalId(), node, nodeTrack, nodePart.getStop(), nodePart.getAttributes().createAttributes(diagram::getObjectById));
            } else {
                LSTrainRoutePartLine linePart = (LSTrainRoutePartLine) routePart;
                Line line = diagram.getNet().getLineById(linePart.getLineId());
                LineTrack lineTrack = line.getTrackById(linePart.getTrackId());
                builder.addLine(linePart.getIntervalId(), line, lineTrack, linePart.getSpeed(), linePart.getAddedTime() != null ? linePart.getAddedTime() : 0, linePart.getAttributes().createAttributes(diagram::getObjectById));
            }
        }
    }
    builder.finish();
    // set technological time
    train.setTimeBefore(this.timeBefore);
    train.setTimeAfter(this.timeAfter);
    return new DelayedAttributes<>(train, attributes, diagram::getObjectById);
}
Also used : NodeTrack(net.parostroj.timetable.model.NodeTrack) Line(net.parostroj.timetable.model.Line) TrainIntervalsBuilder(net.parostroj.timetable.actions.TrainIntervalsBuilder) Node(net.parostroj.timetable.model.Node) Train(net.parostroj.timetable.model.Train) LineTrack(net.parostroj.timetable.model.LineTrack)

Aggregations

Line (net.parostroj.timetable.model.Line)5 Node (net.parostroj.timetable.model.Node)5 LineTrack (net.parostroj.timetable.model.LineTrack)3 NodeTrack (net.parostroj.timetable.model.NodeTrack)3 TrainIntervalsBuilder (net.parostroj.timetable.actions.TrainIntervalsBuilder)2 Net (net.parostroj.timetable.model.Net)2 Train (net.parostroj.timetable.model.Train)2 com.mxgraph.model.mxCell (com.mxgraph.model.mxCell)1 com.mxgraph.swing.handler.mxConnectionHandler (com.mxgraph.swing.handler.mxConnectionHandler)1 ArrayList (java.util.ArrayList)1 FreightNet (net.parostroj.timetable.model.FreightNet)1 Region (net.parostroj.timetable.model.Region)1