Search in sources :

Example 11 with TrainsCycle

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

the class CirculationSequenceDialog method fillFree.

private void fillFree() {
    elementSelectionPanel.clear();
    TrainsCycleType type = circulation.getType();
    // left - not selected part
    for (TrainsCycle cc : type.getCycles()) {
        if (cc != circulation && !cc.isPartOfSequence()) {
            elementSelectionPanel.getNotSelected().addWrapper(Wrapper.getWrapper(cc));
        }
    }
    // right - selected
    List<Wrapper<TrainsCycle>> selCirc = new ArrayList<Wrapper<TrainsCycle>>();
    circulation.applyToSequence(tc -> selCirc.add(Wrapper.getWrapper(tc)));
    elementSelectionPanel.getSelected().setListOfWrappers(selCirc);
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) Wrapper(net.parostroj.timetable.gui.wrappers.Wrapper) ArrayList(java.util.ArrayList) TrainsCycleType(net.parostroj.timetable.model.TrainsCycleType)

Example 12 with TrainsCycle

use of net.parostroj.timetable.model.TrainsCycle 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 13 with TrainsCycle

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

the class TrainsCycleValidator method validate.

@Override
public boolean validate(Event event) {
    boolean validated = false;
    if (event.getSource() instanceof TrainsCycle) {
        validated = handleTrainsCycleEvent(event);
    }
    if (event.getSource() instanceof TrainDiagram && event.getObject() instanceof TrainsCycle && event.getType() == Event.Type.REMOVED) {
        TrainsCycle deleted = (TrainsCycle) event.getObject();
        // handle sequence of circulations
        if (deleted.isPartOfSequence()) {
            deleted.removeFromSequence();
        }
        validated = true;
    }
    return validated;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) TrainDiagram(net.parostroj.timetable.model.TrainDiagram)

Example 14 with TrainsCycle

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

the class XmlTrainTimetablesOutput method writeTo.

@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
    try {
        // extract tts
        List<Train> trains = SelectionHelper.selectTrains(params, diagram);
        List<Route> routes = SelectionHelper.getRoutes(params, diagram, trains);
        TrainsCycle cycle = SelectionHelper.getDriverCycle(params);
        TrainTimetablesExtractor te = new TrainTimetablesExtractor(diagram, trains, routes, cycle, this.getLocale());
        TrainTimetables tt = te.getTrainTimetables();
        JAXBContext context = JAXBContext.newInstance(TrainTimetables.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        Writer writer = new OutputStreamWriter(stream, this.getCharset());
        m.marshal(tt, writer);
    } catch (Exception e) {
        throw new OutputException(e);
    }
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) OutputStreamWriter(java.io.OutputStreamWriter) TrainTimetablesExtractor(net.parostroj.timetable.output2.impl.TrainTimetablesExtractor) TrainTimetables(net.parostroj.timetable.output2.impl.TrainTimetables) Train(net.parostroj.timetable.model.Train) Route(net.parostroj.timetable.model.Route) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 15 with TrainsCycle

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

the class TrainsCycleWrapperDelegate method toString.

@Override
public String toString(TrainsCycle element) {
    TrainsCycle cycle = element;
    String str = cycle.getName();
    if (showType) {
        str = String.format("%s (%s)", cycle.getName(), cycle.getType().getName().translate());
    }
    return str;
}
Also used : TrainsCycle(net.parostroj.timetable.model.TrainsCycle)

Aggregations

TrainsCycle (net.parostroj.timetable.model.TrainsCycle)18 TrainsCycleItem (net.parostroj.timetable.model.TrainsCycleItem)6 Train (net.parostroj.timetable.model.Train)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)3 TrainDiagram (net.parostroj.timetable.model.TrainDiagram)3 TrainsCycleType (net.parostroj.timetable.model.TrainsCycleType)3 Route (net.parostroj.timetable.model.Route)2 TimeInterval (net.parostroj.timetable.model.TimeInterval)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 ModelPredicates (net.parostroj.timetable.filters.ModelPredicates)1 Wrapper (net.parostroj.timetable.gui.wrappers.Wrapper)1