use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class AbstractTemplateLoader method getTemplateList.
@Override
public TemplateList getTemplateList() throws LSException {
if (templateList == null) {
// load template list
try (InputStream is = getTemplateListStream()) {
JAXBContext context = JAXBContext.newInstance(TemplateList.class);
Unmarshaller u = context.createUnmarshaller();
templateList = (TemplateList) u.unmarshal(is);
log.debug("Loaded list of templates: {}", this);
} catch (JAXBException e) {
throw new LSException("Cannot deserialize list of templates: " + e.getMessage(), e);
} catch (IOException e) {
throw new LSException("Error reading list of templates: " + e.getMessage(), e);
}
}
return templateList;
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSSerializerImpl1 method save.
@Override
public void save(Writer writer, TrainDiagram diagram, LSTrainTypeList trainTypeList) throws LSException {
try {
LSTransformationData data = new LSTransformationData(trainTypeList);
LSTrainDiagram lsDiagram = new LSTrainDiagram(diagram, data);
marshaller.marshal(lsDiagram, writer);
} catch (JAXBException e) {
throw new LSException("Cannot save train diagram.", e);
}
}
use of net.parostroj.timetable.model.ls.LSException in project grafikon by jub77.
the class LSTrainsData method updateTrainsData.
public void updateTrainsData(TrainsData trainsData) throws LSException {
try {
trainsData.setTrainNameTemplate(TextTemplate.createTextTemplate(trainNameTemplate, TextTemplate.Language.MVEL));
trainsData.setTrainCompleteNameTemplate(TextTemplate.createTextTemplate(trainCompleteNameTemplate, TextTemplate.Language.MVEL));
trainsData.setTrainSortPattern(trainSortPattern.createSortPattern());
trainsData.setRunningTimeScript(Script.createScript("int time = (int) Math.floor((((double) length) * scale * timeScale * 3.6) / (speed * 1000));\n" + "int penalty = 0;\n" + "if (toSpeed < speed) {\n" + " int penalty1 = penaltySolver.getDecelerationPenalty(speed);\n" + " int penalty2 = penaltySolver.getDecelerationPenalty(toSpeed);\n" + " penalty = penalty1 - penalty2;\n" + "}\n" + "if (fromSpeed < speed) {\n" + " int penalty1 = penaltySolver.getAccelerationPenalty(fromSpeed);\n" + " int penalty2 = penaltySolver.getAccelerationPenalty(speed);\n" + " penalty = penalty + penalty2 - penalty1;\n" + "}\n" + "time = time + (int)Math.round(penalty * 0.18d * timeScale);\n" + "time = time + addedTime;\n" + "time = ((int)((time + 40) / 60)) * 60;\n" + "return time;\n", Script.Language.GROOVY));
} catch (GrafikonException e) {
throw new LSException(e);
}
}
use of net.parostroj.timetable.model.ls.LSException 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.ls.LSException in project grafikon by jub77.
the class LSRoute method createRoute.
public Route createRoute(Net net) throws LSException {
Route route = new Route(id, net.getDiagram());
route.setName(name);
route.setNetPart(netPart);
// create segments
boolean node = true;
for (String segment : getSegments()) {
RouteSegment<?> routeSegment = null;
if (node) {
routeSegment = net.getNodeById(segment);
} else {
routeSegment = net.getLineById(segment);
}
if (routeSegment == null) {
String message = String.format("Segment with id:%s not found. Cannot create route with id:%s.", segment, id);
log.warn(message);
throw new LSException(message);
}
route.getSegments().add(routeSegment);
node = !node;
}
return route;
}
Aggregations