use of net.parostroj.timetable.model.NodeTrack 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.NodeTrack 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.NodeTrack in project grafikon by jub77.
the class TrainTableModel method setValueAt.
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
int time = 0;
editBlock = true;
TimeInterval interval = train.getTimeIntervalList().get(rowIndex);
TrainTableColumn column = TrainTableColumn.getColumn(columnIndex);
switch(column) {
case START:
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
int oldTime = TimeUtil.normalizeTime(interval.getStart());
int newTime = TimeUtil.normalizeTime(time);
int newStartTime = TimeUtil.normalizeTime(train.getStartTime() + (newTime - oldTime));
train.move(newStartTime);
this.fireTableRowsUpdated(0, lastRow);
}
break;
case END:
// departure
time = converter.convertTextToInt((String) aValue);
if (time != -1) {
if (rowIndex == 0) {
train.move(time);
this.fireTableDataChanged();
} else {
int start = TimeUtil.normalizeTime(interval.getStart());
time = TimeUtil.normalizeTime(time);
if (time < start) {
time += TimeInterval.DAY;
}
int newStop = time - start;
if (newStop >= 0) {
train.changeStopTime(interval, newStop);
this.fireTableRowsUpdated(rowIndex - 1, lastRow);
}
}
}
break;
case STOP:
// stop time
try {
time = converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
time = -1;
}
if (time >= 0) {
boolean originalIsFreight = interval.isFreight();
train.changeStopTime(interval, time);
int firstRow = rowIndex - 1;
if (interval.isFreight() != originalIsFreight) {
firstRow = 0;
}
this.fireTableRowsUpdated(firstRow, lastRow);
}
break;
case SPEED_LIMIT:
// velocity limit
Integer velocity = (Integer) aValue;
if (velocity == null || velocity > 0) {
train.changeSpeedAndAddedTime(interval, velocity, interval.getAddedTime());
this.fireTableRowsUpdated(rowIndex - 2 >= 0 ? rowIndex - 2 : 0, lastRow);
}
break;
case ADDED_TIME:
// added time
if (aValue != null) {
int addedTime;
try {
addedTime = ObjectsUtil.isEmpty((String) aValue) ? 0 : converter.convertMinutesTextToInt((String) aValue);
} catch (ParseException e) {
// wrong conversion doesn't change anything
addedTime = -1;
}
if (addedTime >= 0) {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), addedTime);
}
} else {
train.changeSpeedAndAddedTime(interval, interval.getSpeedLimit(), 0);
}
this.fireTableRowsUpdated(rowIndex, lastRow);
break;
case PLATFORM:
// platform
Track track = (Track) aValue;
if (interval.isNodeOwner()) {
NodeTrack newTrack = (NodeTrack) track;
if (newTrack != null) {
train.changeNodeTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
} else if (interval.isLineOwner()) {
LineTrack newTrack = (LineTrack) track;
if (newTrack != null) {
train.changeLineTrack(interval, newTrack);
this.fireTableRowsUpdated(rowIndex, rowIndex);
}
}
break;
case COMMENT:
// comment
String commentStr = ObjectsUtil.checkAndTrim((String) aValue);
LocalizedString lComment = null;
if (commentStr != null) {
lComment = LocalizedString.newBuilder(interval.getComment()).setDefaultString(commentStr).build();
}
interval.getAttributes().setRemove(TimeInterval.ATTR_COMMENT, lComment);
break;
case OCCUPIED_ENTRY:
// entry of the occupied track
interval.getAttributes().setBool(TimeInterval.ATTR_OCCUPIED, (Boolean) aValue);
break;
case SHUNT:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_SHUNT, (Boolean) aValue);
break;
case COMMENT_SHOWN:
// entry shunting on the far side
interval.getAttributes().setBool(TimeInterval.ATTR_COMMENT_SHOWN, (Boolean) aValue);
break;
case SET_SPEED:
// train speed
Integer trainSpeed = (Integer) aValue;
if (trainSpeed != null && trainSpeed <= 0) {
trainSpeed = null;
}
interval.getAttributes().setRemove(TimeInterval.ATTR_SET_SPEED, trainSpeed);
break;
case IGNORE_LENGTH:
// ignore length of the station in computation
interval.getAttributes().setBool(TimeInterval.ATTR_IGNORE_LENGTH, (Boolean) aValue);
this.fireTableRowsUpdated(rowIndex, rowIndex);
break;
case MANAGED_FREIGHT:
interval.getAttributes().setBool(TimeInterval.ATTR_NOT_MANAGED_FREIGHT, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
case REGION_CENTER_TRANSFER:
interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, !((Boolean) aValue));
this.fireTableRowsUpdated(0, lastRow);
break;
default:
break;
}
editBlock = false;
}
use of net.parostroj.timetable.model.NodeTrack 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