Search in sources :

Example 1 with Route

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

the class TrainTimetablesExtractor method computeRoutePosition.

private Double computeRoutePosition(Pair<Line, Node> pair) {
    Route foundRoute = null;
    for (Route route : diagram.getRoutes()) {
        if (route.isNetPart() && checkRoute(pair.first, route.getSegments())) {
            foundRoute = route;
            break;
        }
    }
    if (foundRoute != null) {
        // compute distance
        long length = 0;
        for (RouteSegment<?> seg : foundRoute.getSegments()) {
            if (seg.asNode() == pair.second) {
                break;
            } else if (seg.asLine() != null) {
                length += seg.asLine().getLength();
            }
        }
        double ratio = UnitUtil.getRouteLengthRatio(diagram);
        return UnitUtil.convertRouteLenght(length, diagram, ratio);
    } else
        return null;
}
Also used : Route(net.parostroj.timetable.model.Route)

Example 2 with Route

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

the class GTVButtonPanel method setTrainDiagram.

protected void setTrainDiagram(TrainDiagram td) {
    this.td = td;
    fill();
    if (td != null) {
        td.addListener(new Listener() {

            @Override
            public void changed(Event event) {
                if (event.getType() == Type.ADDED || event.getType() == Type.REMOVED && event.getObject() instanceof Route) {
                    fill();
                }
            }
        });
    }
}
Also used : ActionListener(java.awt.event.ActionListener) PopupMenuListener(javax.swing.event.PopupMenuListener) Event(net.parostroj.timetable.model.events.Event) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Route(net.parostroj.timetable.model.Route)

Example 3 with Route

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

the class GraphicalTimetableView method createMenuForRoutes.

private void createMenuForRoutes(Collection<Route> routesCollection) {
    // remove items
    routesMenu.removeAllItems();
    // remove rest
    routesMenu.removeAll();
    // sort routes
    List<Route> routes = new ArrayList<>(routesCollection);
    Collator collator = Collator.getInstance();
    Collections.sort(routes, (o1, o2) -> collator.compare(o1.toString(), o2.toString()));
    int i = 0;
    for (Route lRoute : routes) {
        if (i++ >= ROUTE_COUNT) {
            // add item for list of routes
            routesMenu.add(new javax.swing.JSeparator());
            routesMenu.add(routesMenuItem);
            break;
        }
        Wrapper<Route> routeWrapper = Wrapper.getWrapper(lRoute);
        routesMenu.addItem(routeWrapper.toString(), lRoute);
    }
    routesMenu.setSelectedItem(this.getRoute());
}
Also used : ArrayList(java.util.ArrayList) Route(net.parostroj.timetable.model.Route) Collator(java.text.Collator)

Example 4 with Route

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

use of net.parostroj.timetable.model.Route 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;
}
Also used : Route(net.parostroj.timetable.model.Route) LSException(net.parostroj.timetable.model.ls.LSException)

Aggregations

Route (net.parostroj.timetable.model.Route)9 LSException (net.parostroj.timetable.model.ls.LSException)3 Train (net.parostroj.timetable.model.Train)2 TrainsCycle (net.parostroj.timetable.model.TrainsCycle)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Collator (java.text.Collator)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 PopupMenuEvent (javax.swing.event.PopupMenuEvent)1 PopupMenuListener (javax.swing.event.PopupMenuListener)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 EngineClass (net.parostroj.timetable.model.EngineClass)1 Output (net.parostroj.timetable.model.Output)1