use of net.parostroj.timetable.model.TrainDiagram in project grafikon by jub77.
the class TrainCycleTypeRemoveValidator method validate.
@Override
public boolean validate(Event event) {
if (event.getSource() instanceof TrainDiagram && event.getType() == Type.REMOVED && event.getObject() instanceof TrainsCycleType) {
// remove all cycles ...
TrainsCycleType cycleType = (TrainsCycleType) event.getObject();
List<TrainsCycle> copy = ImmutableList.copyOf(cycleType.getCycles());
for (TrainsCycle cycle : copy) {
cycleType.getCycles().remove(cycle);
}
return true;
}
return false;
}
use of net.parostroj.timetable.model.TrainDiagram in project grafikon by jub77.
the class OutputWithDiagramStream method write.
@Override
public void write(OutputParams params) throws OutputException {
OutputParamsUtil.checkParamsAnd(params, PARAM_TRAIN_DIAGRAM);
OutputParamsUtil.checkParamsOr(params, PARAM_OUTPUT_FILE, PARAM_OUTPUT_STREAM);
TrainDiagram diagram = (TrainDiagram) params.getParam(PARAM_TRAIN_DIAGRAM).getValue();
if (params.paramExist(PARAM_OUTPUT_STREAM) && params.getParam(PARAM_OUTPUT_STREAM).getValue() != null) {
OutputStream stream = (OutputStream) params.getParam(PARAM_OUTPUT_STREAM).getValue();
testAndWrite(diagram, params, stream);
} else {
File oFile = (File) params.getParam(PARAM_OUTPUT_FILE).getValue();
try (OutputStream stream = new FileOutputStream(oFile)) {
testAndWrite(diagram, params, stream);
} catch (FileNotFoundException e) {
throw new OutputException("Cannot open output file.", e);
} catch (IOException e) {
throw new OutputException("Error writing output", e);
}
}
}
use of net.parostroj.timetable.model.TrainDiagram 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);
}
}
use of net.parostroj.timetable.model.TrainDiagram in project grafikon by jub77.
the class OutputTemplateSelectionModelAction method action.
@Override
protected void action() {
ExportImportSelection selection = new ExportImportSelection();
selection.setImportOverwrite(true);
selection.setImportMatch(ImportMatch.NAME);
if (context.hasAttribute("library")) {
Library library = (Library) context.getAttribute("library");
selection.addItems(ImportComponent.OUTPUT_TEMPLATES, library.getItems().get(LibraryItemType.OUTPUT_TEMPLATE).stream().map(item -> item.getObject()).collect(Collectors.toList()));
} else {
TrainDiagram diagram = (TrainDiagram) context.getAttribute("diagram");
selection.addItems(ImportComponent.OUTPUT_TEMPLATES, diagram.getOutputTemplates());
}
context.setAttribute("selection", selection);
}
use of net.parostroj.timetable.model.TrainDiagram in project grafikon by jub77.
the class DriverCycleDelegate method getTrainCycleErrors.
@Override
public String getTrainCycleErrors(TrainsCycle cycle) {
TrainDiagram diagram = model.getDiagram();
TimeConverter c = diagram.getTimeConverter();
StringBuilder result = new StringBuilder();
List<TrainsCycleChecker.Conflict> conflicts = checker.checkConflicts(cycle);
for (TrainsCycleChecker.Conflict item : conflicts) {
TrainsCycleItem fromItem = item.getFrom();
TrainsCycleItem toItem = item.getTo();
for (ConflictType conflictType : this.colapseTimeConflictTypes(item.getType())) {
switch(conflictType) {
case NODE:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes"), formatItems(fromItem, toItem, c)));
break;
case TRANSITION_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.move.nodes.time.problem"), formatItems(fromItem, toItem, c)));
break;
case TIME:
case SETUP_TIME:
addNewLineIfNotEmpty(result);
result.append(String.format("%s %s", ResourceLoader.getString("ec.problem.time"), formatItems(fromItem, toItem, c)));
break;
}
}
}
return result.toString();
}
Aggregations