Ignore:
Timestamp:
2017-06-12T11:27:11+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant plugin] further development for #josm14904 now it supports mode of travel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/EdgeSelectionAction.java

    r33370 r33390  
    1818import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1919import org.openstreetmap.josm.data.osm.Way;
     20import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils;
    2021import org.openstreetmap.josm.tools.ImageProvider;
    2122import org.openstreetmap.josm.tools.Shortcut;
     
    4445
    4546    /*
    46      * given a way, it looks at both directions until it finds a
    47      * crossway (parents.size > 2) or until the end of the
    48      * edge (parens.size = 1)
     47     * given a way, it looks at both directions for good candidates to be added
     48     * to the edge
    4949     */
    50     private List<Way> getEdgeFromWay(Way initial)
     50    private List<Way> getEdgeFromWay(Way initial, String modeOfTravel)
    5151    {
    5252        List<Way> edge = new ArrayList<>();
     53        if(!isWaySuitableForMode(initial, modeOfTravel))
     54                return edge;
    5355
    5456        Way curr = initial;
    5557        while(true) {
    56                 List<Way> parents = curr.firstNode(true).getParentWays();
    57                 if(parents.size() != 2)
     58                List<Way> options = curr.firstNode(true).getParentWays();
     59                options.remove(curr);
     60                curr = chooseBestWay(options, modeOfTravel);
     61                if(curr == null || edge.contains(curr))
    5862                        break;
    59                 curr = parents.get(0) == curr ? parents.get(1) : parents.get(0);
    6063                edge.add(curr);
    6164        }
     
    6366        curr = initial;
    6467        while(true) {
    65                 List<Way> parents = curr.lastNode(true).getParentWays();
    66                 if(parents.size() != 2)
     68                List<Way> options = curr.lastNode(true).getParentWays();
     69                options.remove(curr);
     70                curr = chooseBestWay(options, modeOfTravel);
     71                if(curr == null || edge.contains(curr))
    6772                        break;
    68                 curr = parents.get(0) == curr ? parents.get(1) : parents.get(0);
    6973                edge.add(curr);
    7074        }
     
    7478    }
    7579
    76     @Override
     80    private Boolean isWaySuitableForMode(Way toCheck, String modeOfTravel)
     81    {
     82        if("bus".equals(modeOfTravel))
     83                return RouteUtils.isWaySuitableForBuses(toCheck);
     84
     85        return RouteUtils.isWaySuitableForPublicTransport(toCheck);
     86    }
     87
     88    /*
     89     *
     90     */
     91    private Way chooseBestWay(List<Way> ways, String modeOfTravel)
     92    {
     93        ways.removeIf(w -> !isWaySuitableForMode(w, modeOfTravel));
     94        if(ways.isEmpty())
     95                return null;
     96        if(ways.size() == 1)
     97                return ways.get(0);
     98
     99        Way theChoosenOne = null;
     100
     101        if("bus".equals(modeOfTravel))
     102        {
     103
     104        }
     105        if("tram".equals(modeOfTravel))
     106        {
     107
     108        }
     109
     110        return theChoosenOne;
     111    }
     112
     113    private String getModeOfTravel() {
     114        //find a way to get the currently opened relation editor and get the
     115        //from there the current type of route
     116                return "bus";
     117        }
     118
     119        @Override
    77120    public void mouseClicked(MouseEvent e) {
    78121
    79122                DataSet ds = Main.getLayerManager().getEditLayer().data;
    80123        Way initial = Main.map.mapView.getNearestWay(e.getPoint(), OsmPrimitive::isUsable);
    81         if(initial != null)
    82                 ds.setSelected(getEdgeFromWay(initial));
     124        if(initial != null){
     125                ds.setSelected(getEdgeFromWay(initial, getModeOfTravel()));
     126        }
    83127        else
    84128                ds.clearSelection();
     
    99143        else {
    100144                Main.map.mapView.setCursor(waySelectCursor);
    101                 highlighted.addAll(getEdgeFromWay(initial));
     145                highlighted.addAll(getEdgeFromWay(initial, getModeOfTravel()));
    102146        }
    103147
Note: See TracChangeset for help on using the changeset viewer.