Search in sources :

Example 1 with TrainDiagram

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;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType)

Example 2 with TrainDiagram

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);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) File(java.io.File) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 3 with TrainDiagram

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);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) Properties(java.util.Properties) TrainDiagram(net.parostroj.timetable.model.TrainDiagram) ModelVersion(net.parostroj.timetable.model.ls.ModelVersion) File(java.io.File) LSFile(net.parostroj.timetable.model.ls.LSFile) LSException(net.parostroj.timetable.model.ls.LSException)

Example 4 with TrainDiagram

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);
}
Also used : ExportImportSelection(net.parostroj.timetable.gui.components.ExportImportSelection) Library(net.parostroj.timetable.model.library.Library) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 5 with TrainDiagram

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();
}
Also used : TrainsCycleChecker(net.parostroj.timetable.actions.TrainsCycleChecker) TrainsCycleItem(net.parostroj.timetable.model.TrainsCycleItem) TimeConverter(net.parostroj.timetable.model.TimeConverter) ConflictType(net.parostroj.timetable.actions.TrainsCycleChecker.ConflictType) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Aggregations

TrainDiagram (net.parostroj.timetable.model.TrainDiagram)23 LSException (net.parostroj.timetable.model.ls.LSException)5 IOException (java.io.IOException)4 Train (net.parostroj.timetable.model.Train)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)3 Component (java.awt.Component)2 List (java.util.List)2 Map (java.util.Map)2 Properties (java.util.Properties)2 ZipEntry (java.util.zip.ZipEntry)2 JOptionPane (javax.swing.JOptionPane)2 AfterLoadCheck (net.parostroj.timetable.actions.AfterLoadCheck)2 ExportImportSelection (net.parostroj.timetable.gui.components.ExportImportSelection)2 GuiComponentUtils (net.parostroj.timetable.gui.utils.GuiComponentUtils)2 LocalizedString (net.parostroj.timetable.model.LocalizedString)2 Library (net.parostroj.timetable.model.library.Library)2 ModelVersion (net.parostroj.timetable.model.ls.ModelVersion)2 Predicate (com.google.common.base.Predicate)1