use of net.parostroj.timetable.model.TextItem in project grafikon by jub77.
the class LSTextItem method createTextItem.
public TextItem createTextItem(TrainDiagram diagram) throws LSException {
TextItem item = new TextItem(id, diagram);
item.getAttributes().add(attributes.createAttributes(diagram::getObjectById));
if (template != null) {
item.setTemplate(template.createTextTemplate());
}
item.setType(TextItem.Type.fromKey(type));
item.setName(name);
return item;
}
use of net.parostroj.timetable.model.TextItem in project grafikon by jub77.
the class FileLoadSaveImpl method save.
@Override
public void save(TrainDiagram diagram, ZipOutputStream zipOutput) throws LSException {
try {
// save metadata
zipOutput.putNextEntry(new ZipEntry(METADATA));
this.createMetadata(METADATA_KEY_MODEL_VERSION).store(zipOutput, null);
FileLoadSaveAttachments attachments = new FileLoadSaveAttachments(DATA_ATTACHMENTS);
// increase save version (increment by one)
diagram.setSaveVersion(diagram.getSaveVersion() + 1);
// update save timestamp
diagram.setSaveTimestamp(new Date());
// save train diagram
this.save(zipOutput, DATA_TRAIN_DIAGRAM, new LSTrainDiagram(diagram));
// save net
this.save(zipOutput, DATA_NET, new LSNet(diagram.getNet()));
int cnt = 0;
// save train type categories
for (TrainTypeCategory category : diagram.getTrainTypeCategories()) {
this.save(zipOutput, this.createEntryName(DATA_TRAIN_TYPE_CATEGORIES, "xml", cnt++), new LSTrainTypeCategory(category));
}
cnt = 0;
// save routes
for (Route route : diagram.getRoutes()) {
this.save(zipOutput, this.createEntryName(DATA_ROUTES, "xml", cnt++), new LSRoute(route));
}
cnt = 0;
// save train types
for (TrainType trainType : diagram.getTrainTypes()) {
this.save(zipOutput, this.createEntryName(DATA_TRAIN_TYPES, "xml", cnt++), new LSTrainType(trainType));
}
cnt = 0;
// save trains
for (Train train : diagram.getTrains()) {
this.save(zipOutput, this.createEntryName(DATA_TRAINS, "xml", cnt++), new LSTrain(train));
}
cnt = 0;
// save engine classes
for (EngineClass engineClass : diagram.getEngineClasses()) {
this.save(zipOutput, this.createEntryName(DATA_ENGINE_CLASSES, "xml", cnt++), new LSEngineClass(engineClass));
}
cnt = 0;
// save text items
for (TextItem item : diagram.getTextItems()) {
this.save(zipOutput, this.createEntryName(DATA_TEXT_ITEMS, "xml", cnt++), new LSTextItem(item));
}
cnt = 0;
// save output templates
for (OutputTemplate template : diagram.getOutputTemplates()) {
LSOutputTemplate lsOutputTemplate = Boolean.TRUE.equals(properties.get("inline.output.template.attachments")) ? new LSOutputTemplate(template) : new LSOutputTemplate(template, attachments);
this.save(zipOutput, this.createEntryName(DATA_OUTPUT_TEMPLATES, "xml", cnt++), lsOutputTemplate);
}
cnt = 0;
// save diagram change sets
for (String version : diagram.getChangesTracker().getVersions()) {
DiagramChangeSet set = diagram.getChangesTracker().getChangeSet(version);
if (!set.getChanges().isEmpty())
this.save(zipOutput, this.createEntryName(DATA_CHANGES, "xml", cnt++), new LSDiagramChangeSet(set));
}
cnt = 0;
// save trains cycles
for (TrainsCycle cycle : diagram.getCycles()) {
this.save(zipOutput, this.createEntryName(DATA_TRAINS_CYCLES, "xml", cnt++), new LSTrainsCycle(cycle));
}
cnt = 0;
// save outputs
for (Output output : diagram.getOutputs()) {
this.save(zipOutput, this.createEntryName(DATA_OUTPUTS, "xml", cnt++), new LSOutput(output));
}
// save images
cnt = 0;
FileLoadSaveImages saveImages = new FileLoadSaveImages(DATA_IMAGES);
for (TimetableImage image : diagram.getImages()) {
this.save(zipOutput, createEntryName(DATA_IMAGES, "xml", cnt++), new LSImage(image));
saveImages.saveTimetableImage(image, zipOutput);
}
// save attachments
attachments.save(zipOutput);
// save freight net
this.save(zipOutput, FREIGHT_NET, new LSFreightNet(diagram.getFreightNet()));
} catch (IOException ex) {
throw new LSException(ex);
}
}
use of net.parostroj.timetable.model.TextItem in project grafikon by jub77.
the class TrainDiagramBuilder method setTextItem.
public void setTextItem(LSTextItem lsTextItem) throws LSException {
TextItem item = lsTextItem.createTextItem(diagram);
diagram.getTextItems().add(item);
}
use of net.parostroj.timetable.model.TextItem 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;
}
Aggregations