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