Search in sources :

Example 1 with Net

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

the class RegionValidator method validate.

@Override
public boolean validate(Event event) {
    if (event.getSource() instanceof Net && event.getType() == Type.REMOVED && event.getObject() instanceof Region) {
        this.cancelSuperRegion((Region) event.getObject());
        this.removeRegionFromNet((Region) event.getObject());
        return true;
    }
    if (event.getType() == Type.OBJECT_ATTRIBUTE && event.getObject() instanceof Region) {
        checkObjectAttributeOfRegion(event);
    }
    // in case region is used - cannot be used as super-region
    if (event.getSource() instanceof Node && event.getType() == Type.ATTRIBUTE && event.getAttributeChange().checkName(Node.ATTR_REGIONS)) {
        for (Region region : ((Node) event.getSource()).getRegions()) {
            if (region.hasSubRegions())
                this.cancelSuperRegion(region);
        }
        checkCommonSuperRegion((Node) event.getSource());
    }
    return false;
}
Also used : Node(net.parostroj.timetable.model.Node) Region(net.parostroj.timetable.model.Region) Net(net.parostroj.timetable.model.Net)

Example 2 with Net

use of net.parostroj.timetable.model.Net 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 Net

use of net.parostroj.timetable.model.Net 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)

Aggregations

Net (net.parostroj.timetable.model.Net)3 Node (net.parostroj.timetable.model.Node)3 Line (net.parostroj.timetable.model.Line)2 Region (net.parostroj.timetable.model.Region)2 ArrayList (java.util.ArrayList)1 FreightNet (net.parostroj.timetable.model.FreightNet)1 LineTrack (net.parostroj.timetable.model.LineTrack)1 NodeTrack (net.parostroj.timetable.model.NodeTrack)1