use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class PreviousNextTrainValidator method validate.
@Override
public boolean validate(Event event) {
checkRemovedTrain(event);
if (event.getSource() instanceof Train) {
Train currentTrain = (Train) event.getSource();
checkTrainAttributes(event, currentTrain);
checkTrainIntervals(event, currentTrain);
return true;
}
return false;
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class BaseConnectionStrategy method getFreightPassedInNode.
protected Map<Train, List<FreightConnectionPath>> getFreightPassedInNode(TimeInterval fromInterval, FreightConnectionFilter filter) {
if (!fromInterval.isNodeOwner()) {
throw new IllegalArgumentException("Only node intervals allowed.");
}
Map<Train, List<FreightConnectionPath>> result = new LinkedHashMap<>();
List<FNConnection> connections = freightNet.getTrainsFrom(fromInterval);
for (FNConnection conn : connections) {
List<FreightConnectionPath> nodes = this.getFreightToNodesImpl(conn.getTo(), conn.getFreightDstFilter(filter, true));
result.put(conn.getTo().getTrain(), nodes);
}
return result;
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class XmlTrainTimetablesOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// extract tts
List<Train> trains = SelectionHelper.selectTrains(params, diagram);
List<Route> routes = SelectionHelper.getRoutes(params, diagram, trains);
TrainsCycle cycle = SelectionHelper.getDriverCycle(params);
TrainTimetablesExtractor te = new TrainTimetablesExtractor(diagram, trains, routes, cycle, this.getLocale());
TrainTimetables tt = te.getTrainTimetables();
JAXBContext context = JAXBContext.newInstance(TrainTimetables.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(tt, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class CopyTrainPM method writeResult.
private void writeResult() {
// create copy of the train
Train train = this.trainRef.get();
if (train != null) {
TrainDiagram diagram = train.getDiagram();
int lTime = this.time.getTime();
if (lTime == -1) {
// select midnight if the time is not correct
lTime = 0;
}
TrainBuilder builder = new TrainBuilder();
String name = this.number.getText();
Train newTrain = reversed.getBoolean() ? builder.createReverseTrain(IdGenerator.getInstance().getId(), name, lTime, train) : builder.createTrain(IdGenerator.getInstance().getId(), name, lTime, train);
// add train to diagram
diagram.getTrains().add(newTrain);
}
}
use of net.parostroj.timetable.model.Train 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