use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class LSTrainsCycleItem method createTrainsCycleItem.
public TrainsCycleItem createTrainsCycleItem(TrainsCycle cycle, TrainDiagram diagram) throws LSException {
Train modelTrain = diagram.getTrains().getById(train);
TrainsCycleItem item = new TrainsCycleItem(cycle, modelTrain, LocalizedString.fromString(comment), modelTrain.getIntervalById(from), modelTrain.getIntervalById(to));
if (attributes != null) {
item.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
}
return item;
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class LoadFilter4d19 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 19, 0)) <= 0) {
// not passing cargo in center (move to time interval from train)
for (Train train : diagram.getTrains()) {
if (train.getAttributeAsBool("no.transitive.region.start")) {
for (TimeInterval interval : train.getNodeIntervals()) {
if (interval.isFirst())
continue;
if (interval.getOwnerAsNode().isCenterOfRegions()) {
interval.setAttributeAsBool(TimeInterval.ATTR_NO_REGION_CENTER_TRANSFER, true);
}
}
}
}
}
if (version.compareTo(new ModelVersion(4, 19, 2)) <= 0) {
// convert some texts to localized strings
this.convertToLocalizedStrings(diagram);
// filter out output templates with default.template
removeDefaultTemplatesExceptDrawAndXml(diagram);
}
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class LoadFilter4d2 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 2)) <= 0) {
// fix weight info
for (Train train : diagram.getTrains()) {
Integer weight = TrainsHelper.getWeightFromInfoAttribute(train);
if (weight != null) {
train.setAttribute(Train.ATTR_WEIGHT, weight);
}
// remove weight.info attribute
train.removeAttribute("weight.info");
}
// fix route info
for (Train train : diagram.getTrains()) {
String routeInfo = ObjectsUtil.checkAndTrim(train.getAttribute("route.info", String.class));
if (routeInfo != null) {
try {
train.setAttribute(Train.ATTR_ROUTE, this.convert(routeInfo));
} catch (GrafikonException e) {
log.warn("Couldn't convert route info to template: {}", e.getMessage());
}
train.removeAttribute("route.info");
}
}
}
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class TrainTimetablesExtractor method getTrainTimetables.
public TrainTimetables getTrainTimetables() {
List<TrainTimetable> result = new LinkedList<>();
List<Text> texts = null;
// trains
for (Train train : trains) {
result.add(this.createTimetable(train));
}
// texts
for (TextItem item : diagram.getTextItems()) {
Text text = this.createText(item);
if (text != null) {
if (texts == null) {
texts = new LinkedList<>();
}
texts.add(text);
}
}
TrainTimetables timetables = new TrainTimetables(result);
timetables.setTexts(texts);
// routes
timetables.setRoutes(RoutesExtractor.convert(routes, diagram));
// route length unit
LengthUnit unit = diagram.getAttribute(TrainDiagram.ATTR_ROUTE_LENGTH_UNIT, LengthUnit.class);
if (unit != null) {
timetables.setRouteLengthUnit(unit);
}
// route info (lower priority)
timetables.setRouteNumbers(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_NUMBERS, String.class));
timetables.setRouteStations(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_NODES, String.class));
// validity
timetables.setValidity(diagram.getAttribute(TrainDiagram.ATTR_ROUTE_VALIDITY, String.class));
// cycle
if (cycle != null) {
DriverCyclesExtractor ex = new DriverCyclesExtractor(diagram, null, false);
timetables.setCycle(ex.createCycle(cycle));
}
return timetables;
}
use of net.parostroj.timetable.model.Train in project grafikon by jub77.
the class StationTimetablesExtractor method getLength.
private LengthInfo getLength(TimeInterval interval) {
LengthInfo lengthInfo = null;
Train train = interval.getTrain();
TrainType trainType = train.getType();
if (!interval.isLast() && interval.isStop() && trainType != null && trainType.getAttributes().getBool(TrainType.ATTR_SHOW_WEIGHT_INFO)) {
Pair<Node, Integer> length = getNextLength(interval.getOwnerAsNode(), train, NextType.LAST_STATION);
// if length was calculated
if (length != null && length.second != null) {
// update length with station lengths
lengthInfo = new LengthInfo();
lengthInfo.setLength(length.second);
LengthUnit lengthUnitObj = diagram.getAttribute(TrainDiagram.ATTR_LENGTH_UNIT, LengthUnit.class);
lengthInfo.setLengthInAxles(LengthUnit.AXLE == lengthUnitObj);
lengthInfo.setLengthUnit(lengthUnitObj);
lengthInfo.setStationAbbr(length.first.getAbbr());
}
}
return lengthInfo;
}
Aggregations