Changeset 33390 in osm for applications
- Timestamp:
- 2017-06-12T11:27:11+02:00 (8 years ago)
- 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 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 20 21 import org.openstreetmap.josm.tools.ImageProvider; 21 22 import org.openstreetmap.josm.tools.Shortcut; … … 44 45 45 46 /* 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 49 49 */ 50 private List<Way> getEdgeFromWay(Way initial) 50 private List<Way> getEdgeFromWay(Way initial, String modeOfTravel) 51 51 { 52 52 List<Way> edge = new ArrayList<>(); 53 if(!isWaySuitableForMode(initial, modeOfTravel)) 54 return edge; 53 55 54 56 Way curr = initial; 55 57 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)) 58 62 break; 59 curr = parents.get(0) == curr ? parents.get(1) : parents.get(0);60 63 edge.add(curr); 61 64 } … … 63 66 curr = initial; 64 67 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)) 67 72 break; 68 curr = parents.get(0) == curr ? parents.get(1) : parents.get(0);69 73 edge.add(curr); 70 74 } … … 74 78 } 75 79 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 77 120 public void mouseClicked(MouseEvent e) { 78 121 79 122 DataSet ds = Main.getLayerManager().getEditLayer().data; 80 123 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 } 83 127 else 84 128 ds.clearSelection(); … … 99 143 else { 100 144 Main.map.mapView.setCursor(waySelectCursor); 101 highlighted.addAll(getEdgeFromWay(initial)); 145 highlighted.addAll(getEdgeFromWay(initial, getModeOfTravel())); 102 146 } 103 147
Note:
See TracChangeset
for help on using the changeset viewer.