use of net.parostroj.timetable.model.ls.ModelVersion in project grafikon by jub77.
the class LoadFilter4d18 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 18, 3)) <= 0) {
// adjust complete name templates
TextTemplate template = diagram.getTrainsData().getTrainCompleteNameTemplate();
diagram.getTrainsData().setTrainCompleteNameTemplate(this.adjustDescription(template));
for (TrainType type : diagram.getTrainTypes()) {
template = type.getTrainCompleteNameTemplate();
if (template != null) {
type.setTrainCompleteNameTemplate(this.adjustDescription(template));
}
}
}
if (version.compareTo(new ModelVersion(4, 18, 4)) <= 0) {
// multiple regions allowed per node (even centers)
for (Node node : diagram.getNet().getNodes()) {
Region region = (Region) node.removeAttribute("region");
if (region != null) {
Boolean regionCenter = (Boolean) node.removeAttribute("region.start");
node.setAttribute(Node.ATTR_REGIONS, Collections.singleton(region));
if (regionCenter != null && regionCenter) {
node.setAttribute(Node.ATTR_CENTER_OF_REGIONS, Collections.singleton(region));
}
}
}
}
}
use of net.parostroj.timetable.model.ls.ModelVersion in project grafikon by jub77.
the class LSLibraryImpl method load.
@Override
public Library load(ZipInputStream is) throws LSException {
try {
ZipEntry entry = null;
ModelVersion version = (ModelVersion) properties.get(VERSION_PROPERTY);
LibraryBuilder libraryBuilder = new LibraryBuilder();
while ((entry = is.getNextEntry()) != null) {
if (entry.getName().equals(METADATA)) {
// check major and minor version (do not allow load newer versions)
Properties props = new Properties();
props.load(is);
version = checkVersion(METADATA_KEY_LIBRARY_VERSION, props);
continue;
}
LSLibraryItem lsItem = lss.load(is, LSLibraryItem.class);
lsItem.createLibraryItem(libraryBuilder);
}
log.debug("Loaded version: {}", version != null ? version : "<missing>");
return libraryBuilder.build();
} catch (IOException e) {
throw new LSException(e);
}
}
use of net.parostroj.timetable.model.ls.ModelVersion in project grafikon by jub77.
the class LoadFilter4d22 method checkDiagram.
@Override
public void checkDiagram(TrainDiagram diagram, ModelVersion version) {
if (version.compareTo(new ModelVersion(4, 22, 0)) <= 0) {
for (Node node : diagram.getNet().getNodes()) {
node.getAttributes().setSkipListeners(true);
try {
Collection<Region> regions = node.getAttributeAsCollection(Node.ATTR_REGIONS, Region.class);
if (regions != null && !(regions instanceof Set)) {
node.setAttribute(Node.ATTR_REGIONS, new HashSet<>(regions));
}
Collection<Region> centerRegions = node.getAttributeAsCollection(Node.ATTR_CENTER_OF_REGIONS, Region.class);
if (centerRegions != null && !(centerRegions instanceof Set)) {
node.setAttribute(Node.ATTR_CENTER_OF_REGIONS, new HashSet<>(centerRegions));
}
Collection<FreightColor> freightColors = node.getAttributeAsCollection(Node.ATTR_FREIGHT_COLORS, FreightColor.class);
if (freightColors != null && !(freightColors instanceof Set)) {
node.setAttribute(Node.ATTR_FREIGHT_COLORS, new HashSet<>(freightColors));
}
} finally {
node.getAttributes().setSkipListeners(false);
}
}
}
}
use of net.parostroj.timetable.model.ls.ModelVersion in project grafikon by jub77.
the class AbstractLSImpl method checkVersion.
protected ModelVersion checkVersion(String versionKey, Properties props) throws LSException {
ModelVersion current = getSaveVersion();
ModelVersion loaded = ModelVersion.parseModelVersion(props.getProperty(versionKey));
if (current.compareTo(loaded) < 0) {
throw new LSException(String.format("Current version [%s] is older than the version of loaded file [%s].", current.toString(), loaded.toString()));
}
return loaded;
}
use of net.parostroj.timetable.model.ls.ModelVersion in project grafikon by jub77.
the class FileLoadSaveImpl method load.
@Override
public TrainDiagram load(ZipInputStream zipInput) throws LSException {
try {
ZipEntry entry = null;
TrainDiagramBuilder builder = null;
FileLoadSaveImages loadImages = new FileLoadSaveImages(DATA_IMAGES);
FileLoadSaveAttachments attachments = new FileLoadSaveAttachments(DATA_ATTACHMENTS);
ModelVersion version = (ModelVersion) properties.get(VERSION_PROPERTY);
while ((entry = zipInput.getNextEntry()) != null) {
if (entry.getName().equals(METADATA)) {
// check major and minor version (do not allow load newer versions)
Properties props = new Properties();
props.load(zipInput);
version = checkVersion(METADATA_KEY_MODEL_VERSION, props);
continue;
}
if (entry.getName().equals(DATA_TRAIN_DIAGRAM)) {
LSTrainDiagram lstd = lss.load(zipInput, LSTrainDiagram.class);
builder = new TrainDiagramBuilder(lstd, attachments);
}
// test diagram
if (builder == null) {
throw new LSException("Train diagram builder has to be first entry: " + entry.getName());
}
if (entry.getName().equals(DATA_PENALTY_TABLE)) {
builder.setPenaltyTable(lss.load(zipInput, LSPenaltyTable.class));
} else if (entry.getName().equals(DATA_NET)) {
builder.setNet(lss.load(zipInput, LSNet.class));
} else if (entry.getName().startsWith(DATA_ROUTES)) {
builder.setRoute(lss.load(zipInput, LSRoute.class));
} else if (entry.getName().startsWith(DATA_TRAIN_TYPE_CATEGORIES)) {
builder.setTrainTypeCategory(lss.load(zipInput, LSTrainTypeCategory.class));
} else if (entry.getName().startsWith(DATA_TRAIN_TYPES)) {
builder.setTrainType(lss.load(zipInput, LSTrainType.class));
} else if (entry.getName().startsWith(DATA_TEXT_ITEMS)) {
builder.setTextItem(lss.load(zipInput, LSTextItem.class));
} else if (entry.getName().startsWith(DATA_OUTPUT_TEMPLATES)) {
builder.setOutputTemplate(lss.load(zipInput, LSOutputTemplate.class));
} else if (entry.getName().startsWith(DATA_TRAINS)) {
builder.setTrain(lss.load(zipInput, LSTrain.class));
} else if (entry.getName().startsWith(DATA_ENGINE_CLASSES)) {
builder.setEngineClass(lss.load(zipInput, LSEngineClass.class));
} else if (entry.getName().startsWith(DATA_TRAINS_CYCLES)) {
builder.setTrainsCycle(lss.load(zipInput, LSTrainsCycle.class));
} else if (entry.getName().startsWith(DATA_CHANGES)) {
builder.setDiagramChangeSet(lss.load(zipInput, LSDiagramChangeSet.class));
} else if (entry.getName().startsWith(FREIGHT_NET)) {
builder.setFreightNet(lss.load(zipInput, LSFreightNet.class));
} else if (entry.getName().startsWith(DATA_IMAGES)) {
if (entry.getName().endsWith(".xml")) {
builder.addImage(lss.load(zipInput, LSImage.class));
} else {
builder.addImageFile(new File(entry.getName()).getName(), loadImages.loadTimetableImage(zipInput, entry));
}
} else if (entry.getName().startsWith(DATA_ATTACHMENTS)) {
attachments.load(zipInput, entry);
} else if (entry.getName().startsWith(DATA_OUTPUTS)) {
builder.setOutput(lss.load(zipInput, LSOutput.class));
}
}
TrainDiagram trainDiagram = builder.getTrainDiagram();
for (LoadFilter filter : loadFilters) {
filter.checkDiagram(trainDiagram, version);
}
log.debug("Loaded version: {}", version != null ? version : "<missing>");
return trainDiagram;
} catch (IOException e) {
throw new LSException(e);
}
}
Aggregations