Search in sources :

Example 91 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method reactToEdgeSelection.

private void reactToEdgeSelection(Edge selected, boolean outgoing) {
    if (selected == null) {
        return;
    }
    showGraph.highlightEdge(selected);
    /* for turns, highlight the outgoing street's ends */
    if (selected instanceof StreetEdge) {
        List<Vertex> vertices = new ArrayList<Vertex>();
        List<Edge> edges = new ArrayList<Edge>();
        Vertex tov = selected.getToVertex();
        for (Edge og : tov.getOutgoing()) {
            if (og instanceof StreetEdge) {
                edges.add(og);
                vertices.add(og.getToVertex());
                break;
            }
        }
        Vertex fromv = selected.getFromVertex();
        for (Edge ic : fromv.getIncoming()) {
            if (ic instanceof StreetEdge) {
                edges.add(ic);
                vertices.add(ic.getFromVertex());
                break;
            }
        }
        // showGraph.setHighlightedVertices(vertices);
        showGraph.setHighlightedEdges(edges);
    }
    /* add the connected vertices to the list of vertices */
    VertexList nearbyModel = (VertexList) nearbyVertices.getModel();
    List<Vertex> vertices = nearbyModel.selected;
    Vertex v;
    if (outgoing) {
        v = selected.getToVertex();
    } else {
        v = selected.getFromVertex();
    }
    if (!vertices.contains(v)) {
        vertices.add(v);
        nearbyModel = new VertexList(vertices);
        // this should just be an event, but for
        nearbyVertices.setModel(nearbyModel);
    // some reason, JList doesn't implement
    // the right event.
    }
    /* set up metadata tab */
    metadataModel.clear();
    getMetadata(selected);
    // fromv
    Vertex fromv = selected.getFromVertex();
    getMetadata(fromv);
    if (selected instanceof StreetEdge) {
    // TODO ElevationProfileSegment do not exist anymore
    // getMetadata(((StreetEdge) selected).getElevationProfileSegment());
    }
    metadataList.revalidate();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 92 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method initControlButtons.

private void initControlButtons() {
    /* buttons at bottom */
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(0, 3));
    leftPanel.add(buttonPanel, BorderLayout.PAGE_END);
    JButton zoomDefaultButton = new JButton("Zoom to default");
    zoomDefaultButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            showGraph.zoomToDefault();
        }
    });
    buttonPanel.add(zoomDefaultButton);
    final JFrame frame = this;
    JButton zoomToNodeButton = new JButton("Zoom to node");
    zoomToNodeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String nodeName = (String) JOptionPane.showInputDialog(frame, "Node id", JOptionPane.PLAIN_MESSAGE);
            Vertex v = getGraph().getVertex(nodeName);
            if (v == null) {
                System.out.println("no such node " + nodeName);
            } else {
                showGraph.zoomToVertex(v);
            }
        }
    });
    buttonPanel.add(zoomToNodeButton);
    JButton zoomToLocationButton = new JButton("Zoom to location");
    zoomToLocationButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String result = JOptionPane.showInputDialog("Enter the location (lat lon)");
            if (result == null || result.length() == 0)
                return;
            String[] tokens = result.split("[\\s,]+");
            double lat = Double.parseDouble(tokens[0]);
            double lon = Double.parseDouble(tokens[1]);
            Coordinate c = new Coordinate(lon, lat);
            showGraph.zoomToLocation(c);
        }
    });
    buttonPanel.add(zoomToLocationButton);
    JButton zoomOutButton = new JButton("Zoom out");
    zoomOutButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            showGraph.zoomOut();
        }
    });
    buttonPanel.add(zoomOutButton);
    JButton routeButton2 = new JButton("Route");
    routeButton2.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // String initialFrom = "";
            // Object selected = nearbyVertices.getSelectedValue();
            // if (selected != null) {
            // initialFrom = selected.toString();
            // }
            // RouteDialog dlg = new RouteDialog(frame, initialFrom); // modal
            String from = sourceVertex.getText();
            String to = sinkVertex.getText();
            route(from, to);
        }
    });
    buttonPanel.add(routeButton2);
    JButton findButton = new JButton("Find node");
    findButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String nodeName = (String) JOptionPane.showInputDialog(frame, "Node id", JOptionPane.PLAIN_MESSAGE);
            Vertex v = getGraph().getVertex(nodeName);
            if (v == null) {
                System.out.println("no such node " + nodeName);
            } else {
                showGraph.highlightVertex(v);
                ArrayList<Vertex> l = new ArrayList<Vertex>();
                l.add(v);
                verticesSelected(l);
            }
        }
    });
    buttonPanel.add(findButton);
    JButton findEdgeButton = new JButton("Find edge");
    findEdgeButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String edgeName = (String) JOptionPane.showInputDialog(frame, "Edge name like", JOptionPane.PLAIN_MESSAGE);
            for (Vertex gv : getGraph().getVertices()) {
                for (Edge edge : gv.getOutgoing()) {
                    if (edge.getName() != null && edge.getName().contains(edgeName)) {
                        showGraph.highlightVertex(gv);
                        ArrayList<Vertex> l = new ArrayList<Vertex>();
                        l.add(gv);
                        verticesSelected(l);
                    }
                }
            }
        }
    });
    buttonPanel.add(findEdgeButton);
    JButton checkButton = new JButton("Check graph");
    checkButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            checkGraph();
        }
    });
    buttonPanel.add(checkButton);
    JButton traceButton = new JButton("Trace");
    traceButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            trace();
        }
    });
    buttonPanel.add(traceButton);
    // annotation search button
    JButton annotationButton = new JButton("Find annotations");
    annotationButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            findAnnotation();
        }
    });
    buttonPanel.add(annotationButton);
    JButton findEdgeByIdButton = new JButton("Find edge ID");
    findEdgeByIdButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String edgeIdStr = (String) JOptionPane.showInputDialog(frame, "Edge ID", JOptionPane.PLAIN_MESSAGE);
            Integer edgeId = Integer.parseInt(edgeIdStr);
            Edge edge = getGraph().getEdgeById(edgeId);
            if (edge != null) {
                showGraph.highlightEdge(edge);
                showGraph.highlightVertex(edge.getFromVertex());
            } else {
                System.out.println("Found no edge with ID " + edgeIdStr);
            }
        }
    });
    buttonPanel.add(findEdgeByIdButton);
    JButton snapButton = new JButton("Snap location");
    snapButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            LOG.error("StreetIndex.getClosestPointOnStreet no longer exists.");
        }
    });
    buttonPanel.add(snapButton);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 93 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class GraphVisualizer method initVertexInfoSubpanel.

private void initVertexInfoSubpanel() {
    JPanel vertexDataPanel = new JPanel();
    vertexDataPanel.setLayout(new BoxLayout(vertexDataPanel, BoxLayout.PAGE_AXIS));
    vertexDataPanel.setPreferredSize(new Dimension(300, 600));
    leftPanel.add(vertexDataPanel, BorderLayout.CENTER);
    // nearby vertices
    JLabel nvLabel = new JLabel("Vertices");
    vertexDataPanel.add(nvLabel);
    nearbyVertices = new JList<DisplayVertex>();
    nearbyVertices.setVisibleRowCount(4);
    JScrollPane nvScrollPane = new JScrollPane(nearbyVertices);
    vertexDataPanel.add(nvScrollPane);
    nearbyVertices.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            outgoingEdges.removeAll();
            incomingEdges.removeAll();
            DisplayVertex selected = (DisplayVertex) nearbyVertices.getSelectedValue();
            if (selected != null) {
                Vertex nowSelected = selected.vertex;
                showGraph.highlightVertex(nowSelected);
                outgoingEdges.setModel(new EdgeListModel(nowSelected.getOutgoing()));
                incomingEdges.setModel(new EdgeListModel(nowSelected.getIncoming()));
            }
        }
    });
    // listener useful for both incoming and outgoing edge list panes
    // when a different edge is selected, change up the pattern pane and list of nearby nodes
    ListSelectionListener edgeChanged = new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            @SuppressWarnings("unchecked") JList<Edge> edgeList = (JList<Edge>) e.getSource();
            Edge selected = (Edge) edgeList.getSelectedValue();
            boolean outgoing = (edgeList == outgoingEdges);
            reactToEdgeSelection(selected, outgoing);
        }
    };
    // outgoing edges
    JLabel ogeLabel = new JLabel("Outgoing edges");
    vertexDataPanel.add(ogeLabel);
    outgoingEdges = new JList<Edge>();
    outgoingEdges.setVisibleRowCount(4);
    JScrollPane ogeScrollPane = new JScrollPane(outgoingEdges);
    vertexDataPanel.add(ogeScrollPane);
    outgoingEdges.addListSelectionListener(edgeChanged);
    // incoming edges
    JLabel iceLabel = new JLabel("Incoming edges");
    vertexDataPanel.add(iceLabel);
    incomingEdges = new JList<Edge>();
    JScrollPane iceScrollPane = new JScrollPane(incomingEdges);
    vertexDataPanel.add(iceScrollPane);
    incomingEdges.addListSelectionListener(edgeChanged);
    // paths list
    JLabel pathsLabel = new JLabel("Paths");
    vertexDataPanel.add(pathsLabel);
    pathsList = new JList<PathPrinter>();
    popup = new JPopupMenu();
    JMenuItem compareMenuItem = new JMenuItem("compare");
    compareMenuItem.addActionListener(new OnPopupMenuClickListener());
    popup.add(compareMenuItem);
    // make paths list right-clickable
    pathsList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                @SuppressWarnings("unchecked") JList<PathPrinter> list = (JList<PathPrinter>) e.getSource();
                int row = list.locationToIndex(e.getPoint());
                list.setSelectedIndex(row);
                popup.show(list, e.getX(), e.getY());
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    pathsList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent ev) {
            PathPrinter pp = ((PathPrinter) pathsList.getSelectedValue());
            if (pp == null) {
                return;
            }
            GraphPath path = pp.gp;
            DefaultListModel<State> pathModel = new DefaultListModel<State>();
            for (State st : path.states) {
                pathModel.addElement(st);
            }
            pathStates.setModel(pathModel);
            showGraph.highlightGraphPath(path);
        }
    });
    JScrollPane pathsScrollPane = new JScrollPane(pathsList);
    vertexDataPanel.add(pathsScrollPane);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) ListSelectionEvent(javax.swing.event.ListSelectionEvent) GraphPath(org.opentripplanner.routing.spt.GraphPath) ListSelectionListener(javax.swing.event.ListSelectionListener) State(org.opentripplanner.routing.core.State) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 94 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class ShowGraph method drawHighlighted.

private void drawHighlighted() {
    /* Draw highlighted edges in another color */
    noFill();
    // yellow transparent edge highlight
    stroke(200, 200, 000, 16);
    strokeWeight(8);
    if (drawHighlighted && highlightedEdges != null) {
        try {
            for (Edge e : highlightedEdges) {
                drawEdge(e);
            }
        } catch (ConcurrentModificationException cme) {
        // The edge list was cleared or added to while it was being drawn, no harm done.
        }
    }
    /* Draw highlighted graph path in another color */
    if (highlightedGraphPath != null) {
        drawGraphPath(highlightedGraphPath);
    }
    /* Draw (single) highlighted edge in highlight color */
    if (highlightedEdge != null && highlightedEdge.getGeometry() != null) {
        stroke(10, 200, 10, 128);
        strokeWeight(12);
        drawEdge(highlightedEdge);
    }
    /* Draw highlighted vertices */
    // orange fill
    fill(255, 127, 0);
    noStroke();
    if (highlightedVertices != null) {
        for (Vertex v : highlightedVertices) {
            drawVertex(v, 8);
        }
    }
    /* Draw (single) highlighed coordinate in a different color */
    if (highlightedCoordinate != null) {
        fill(255, 255, 30);
        drawCoordinate(highlightedCoordinate, 7);
    }
    noFill();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 95 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class ShowGraph method mouseClicked.

@SuppressWarnings("unchecked")
public void mouseClicked() {
    Envelope screenEnv = new Envelope(new Coordinate(mouseX, mouseY));
    screenEnv.expandBy(4, 4);
    Envelope env = new Envelope(toModelX(screenEnv.getMinX()), toModelX(screenEnv.getMaxX()), toModelY(screenEnv.getMinY()), toModelY(screenEnv.getMaxY()));
    List<Vertex> nearby = (List<Vertex>) vertexIndex.query(env);
    selector.verticesSelected(nearby);
    drawLevel = DRAW_ALL;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11