Ticket #3447: ignore_oneways.patch

File ignore_oneways.patch, 4.3 KB (added by franpd, 14 years ago)
  • src/com/innovant/josm/jrt/core/RoutingGraph.java

     
    3535import org.jgrapht.Graph;
    3636import org.jgrapht.alg.BellmanFordShortestPath;
    3737import org.jgrapht.alg.DijkstraShortestPath;
    38 import org.jgrapht.graph.AsUndirectedGraph;
    3938import org.jgrapht.graph.DirectedWeightedMultigraph;
     39import org.openstreetmap.josm.Main;
    4040import org.openstreetmap.josm.data.osm.DataSet;
    4141import org.openstreetmap.josm.data.osm.Node;
    4242import org.openstreetmap.josm.data.osm.Way;
     
    4242import org.openstreetmap.josm.data.osm.Way;
    4343
    4444import com.innovant.josm.jrt.osm.OsmEdge;
     45import com.innovant.josm.plugin.routing.RoutingLayer;
     46import com.innovant.josm.plugin.routing.RoutingModel;
    4547
    4648/**
    4749 * Class utility to work with graph routers.
     
    197199                                               
    198200                                   
    199201                                    //this is where we link the vertices
     202                                                if (!routingProfile.isOnewayUsed())
     203                                                        //"Ignore oneways" is selected
     204                                                        addEdgeBidirectional(way, from, to);
     205                                               
     206                                                else //"Ignore oneways" is not selected
    200207                                                if (oneway_val == null || oneway_val == "false" || oneway_val == "no" || oneway_val == "0") {
    201208                                                //Case 1 (bi-way): oneway=false OR oneway=unset OR oneway=0 OR oneway=no
    202209                                                  addEdgeBidirectional(way, from, to);
     
    325332        Graph<Node,OsmEdge> g;
    326333        double totalWeight = 0;
    327334
    328         if (graph == null)
     335        RoutingLayer layer = (RoutingLayer)Main.map.mapView.getActiveLayer();
     336        RoutingModel routingModel = layer.getRoutingModel();
     337       
     338        if (graph == null || routingModel.getWaysChanged())
    329339            this.createGraph();
    330340        logger.debug("apply algorithm between nodes ");
    331341
     
    334344        }
    335345        logger.debug("-----------------------------------");
    336346
    337         // Assign the graph or an undirected view of the graph to g,
    338         // depending on whether oneway tags are used or not
    339         if (routingProfile.isOnewayUsed())
     347        // Assign the graph to g
    340348            g = graph;
    341         else
    342             g = new AsUndirectedGraph<Node, OsmEdge>((DirectedWeightedMultigraph<Node,OsmEdge>)graph);
    343         //TODO: Problemas no tiene encuenta el tema de oneway.
     349           
    344350        switch (algorithm) {
    345351        case ROUTING_ALG_DIJKSTRA:
    346352            logger.debug("Using Dijkstra algorithm");
  • src/com/innovant/josm/plugin/routing/gui/RoutingMenu.java

     
    131131                    else
    132132                        routingModel.routingGraph.getRoutingProfile().setOnewayUse(true);
    133133                    routingModel.setNodesChanged();
     134                    routingModel.setWaysChanged();
    134135                    Main.map.repaint();
    135136                }
    136137            }
  • src/com/innovant/josm/plugin/routing/RoutingModel.java

     
    6868     */
    6969    private boolean changeNodes=false;
    7070    /**
     71     * Flag to advise about changes in ways.
     72     */
     73    private boolean changeWays=false;
     74    /**
    7175     * Default Constructor.
    7276     */
    7377    public RoutingModel(DataSet data) {
     
    137141        {
    138142            path=this.routingGraph.applyAlgorithm(nodes, Algorithm.ROUTING_ALG_DIJKSTRA);
    139143            this.changeNodes=false;
     144            this.changeWays=false;
    140145        }
    141146        return path;
    142147    }
     
    147152    public void setNodesChanged() {
    148153        this.changeNodes = true;
    149154    }
     155   
     156    /**
     157     * Marks that some node or the node order has changed so the path should be computed again
     158     */
     159    public void setWaysChanged() {
     160        this.changeWays = true;
     161    }
     162   
     163    /**
     164     * Marks that some node or the node order has changed so the path should be computed again
     165     */
     166    public boolean getWaysChanged() {
     167        return this.changeWays;
     168    }
    150169
    151170    /**
    152171     * Resets all data.