Search in sources :

Example 1 with EngineClass

use of net.parostroj.timetable.model.EngineClass 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);
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TextItem(net.parostroj.timetable.model.TextItem) ZipEntry(java.util.zip.ZipEntry) Output(net.parostroj.timetable.model.Output) TrainTypeCategory(net.parostroj.timetable.model.TrainTypeCategory) TrainType(net.parostroj.timetable.model.TrainType) Route(net.parostroj.timetable.model.Route) TimetableImage(net.parostroj.timetable.model.TimetableImage) DiagramChangeSet(net.parostroj.timetable.model.changes.DiagramChangeSet) IOException(java.io.IOException) Date(java.util.Date) OutputTemplate(net.parostroj.timetable.model.OutputTemplate) EngineClass(net.parostroj.timetable.model.EngineClass) Train(net.parostroj.timetable.model.Train) LSException(net.parostroj.timetable.model.ls.LSException)

Example 2 with EngineClass

use of net.parostroj.timetable.model.EngineClass in project grafikon by jub77.

the class LibraryBuilder method importEngineClass.

public LibraryItem importEngineClass(EngineClass engineClass) {
    EngineClass engineClassCopy = copyFactory.copy(engineClass, engineClass.getId());
    for (WeightTableRow row : engineClassCopy.getWeightTable()) {
        for (LineClass origLineClass : ImmutableList.copyOf(row.getWeights().keySet())) {
            Integer weight = row.getWeight(origLineClass);
            row.removeWeightInfo(origLineClass);
            ObjectWithId currentLineClass = this.getObjectById(origLineClass.getId());
            if (currentLineClass == null) {
                if (config.isAddMissing()) {
                    LibraryItem lineClassItem = this.importLineClass(origLineClass);
                    currentLineClass = lineClassItem.getObject();
                } else {
                    throw new IllegalArgumentException("Line class missing from library: " + origLineClass);
                }
            } else if (!(currentLineClass instanceof LineClass)) {
                throw new IllegalArgumentException("Wrong type of line class: " + origLineClass);
            }
            row.setWeightInfo((LineClass) currentLineClass, weight);
        }
    }
    return addImpl(engineClassCopy, LibraryItemType.ENGINE_CLASS);
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) ObjectWithId(net.parostroj.timetable.model.ObjectWithId) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass)

Example 3 with EngineClass

use of net.parostroj.timetable.model.EngineClass in project grafikon by jub77.

the class EngineClassImport method importObjectImpl.

@Override
protected ObjectWithId importObjectImpl(ObjectWithId o) {
    // check class
    if (!(o instanceof EngineClass))
        return null;
    EngineClass importedEngineClass = (EngineClass) o;
    // check existence
    EngineClass checkedEngineClass = this.getEngineClass(importedEngineClass);
    if (checkedEngineClass != null) {
        if (overwrite) {
            this.getDiagram().getEngineClasses().remove(checkedEngineClass);
        } else {
            String message = "engine class already exists";
            this.addError(importedEngineClass, message);
            log.debug("{}: {}", message, checkedEngineClass);
            return null;
        }
    }
    // create new engine class
    EngineClass engineClass = new EngineClass(this.getId(importedEngineClass), importedEngineClass.getName());
    // process weight rows
    for (WeightTableRow impRow : importedEngineClass.getWeightTable()) {
        WeightTableRow row = engineClass.createWeightTableRow(impRow.getSpeed());
        for (Map.Entry<LineClass, Integer> impEntry : impRow.getWeights().entrySet()) {
            LineClass lineClass = this.getLineClass(impEntry.getKey());
            if (lineClass == null) {
                String message = "line class missing: " + impEntry.getKey().getName();
                this.addError(importedEngineClass, message);
                log.debug(message);
                return null;
            }
            row.setWeightInfo(lineClass, impEntry.getValue());
        }
        engineClass.addWeightTableRow(row);
    }
    // add to diagram
    this.getDiagram().getEngineClasses().add(engineClass);
    this.addImportedObject(engineClass);
    log.trace("Successfully imported engine class: {}", engineClass);
    return engineClass;
}
Also used : WeightTableRow(net.parostroj.timetable.model.WeightTableRow) LineClass(net.parostroj.timetable.model.LineClass) EngineClass(net.parostroj.timetable.model.EngineClass) Map(java.util.Map)

Example 4 with EngineClass

use of net.parostroj.timetable.model.EngineClass in project grafikon by jub77.

the class EngineClassPM method ok.

@Operation(path = "ok")
public void ok() {
    EngineClass engineClass = reference != null ? reference.get() : null;
    if (engineClass != null) {
        // write values back
        engineClass.setName(name.getText());
        engineClass.setGroupKey(ObjectsUtil.checkAndTrim(groupKey.getText()));
    }
}
Also used : EngineClass(net.parostroj.timetable.model.EngineClass) Operation(org.beanfabrics.support.Operation)

Example 5 with EngineClass

use of net.parostroj.timetable.model.EngineClass in project grafikon by jub77.

the class TrainDiagramBuilder method setEngineClass.

public void setEngineClass(LSEngineClass lsEngineClass) throws LSException {
    EngineClass ec = lsEngineClass.createEngineClass(diagram.getNet().getLineClasses()::getById);
    EngineClass foundEc = null;
    if ((foundEc = diagram.getEngineClasses().getById(ec.getId())) != null) {
        diagram.getEngineClasses().remove(foundEc);
    }
    diagram.getEngineClasses().add(ec);
}
Also used : EngineClass(net.parostroj.timetable.model.EngineClass)

Aggregations

EngineClass (net.parostroj.timetable.model.EngineClass)5 LineClass (net.parostroj.timetable.model.LineClass)2 WeightTableRow (net.parostroj.timetable.model.WeightTableRow)2 IOException (java.io.IOException)1 Date (java.util.Date)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 ObjectWithId (net.parostroj.timetable.model.ObjectWithId)1 Output (net.parostroj.timetable.model.Output)1 OutputTemplate (net.parostroj.timetable.model.OutputTemplate)1 Route (net.parostroj.timetable.model.Route)1 TextItem (net.parostroj.timetable.model.TextItem)1 TimetableImage (net.parostroj.timetable.model.TimetableImage)1 Train (net.parostroj.timetable.model.Train)1 TrainType (net.parostroj.timetable.model.TrainType)1 TrainTypeCategory (net.parostroj.timetable.model.TrainTypeCategory)1 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)1 DiagramChangeSet (net.parostroj.timetable.model.changes.DiagramChangeSet)1 LSException (net.parostroj.timetable.model.ls.LSException)1 Operation (org.beanfabrics.support.Operation)1