Changeset 33414 in osm for applications/editors/josm/plugins/pt_assistant/src
- Timestamp:
- 2017-06-26T18:45:06+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 7 edited
-
actions/IncompleteMembersDownloadThread.java (modified) (2 diffs)
-
actions/SplitRoundaboutAction.java (modified) (6 diffs)
-
gui/PTAssistantLayer.java (modified) (1 diff)
-
gui/PTAssistantLayerManager.java (modified) (1 diff)
-
gui/PTAssistantPaintVisitor.java (modified) (1 diff)
-
utils/RouteUtils.java (modified) (11 diffs)
-
validation/PTAssistantValidatorTest.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java
r33055 r33414 41 41 for (Relation currentSelectedRelation : Main.getLayerManager().getEditDataSet() 42 42 .getSelectedRelations()) { 43 if (RouteUtils.is TwoDirectionRoute(currentSelectedRelation)) {43 if (RouteUtils.isVersionTwoPTRoute(currentSelectedRelation)) { 44 44 list.add(currentSelectedRelation); 45 45 } … … 51 51 Collection<Relation> allRelations = Main.getLayerManager().getEditDataSet().getRelations(); 52 52 for (Relation currentRelation : allRelations) { 53 if (RouteUtils.is TwoDirectionRoute(currentRelation)) {53 if (RouteUtils.isVersionTwoPTRoute(currentRelation)) { 54 54 list.add(currentRelation); 55 55 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SplitRoundaboutAction.java
r33413 r33414 113 113 public void updateRelations(Map<Relation, List<Integer>> savedPositions, 114 114 List<Node> splitNodes, Collection<Way> splitWays) { 115 Map<Relation, Integer> memberOffset = new HashMap<>();115 Map<Relation, Integer> memberOffset = new HashMap<>(); 116 116 savedPositions.forEach((r, positions) -> 117 positions.forEach(i -> {118 119 if(!memberOffset.containsKey(r))120 memberOffset.put(r, 0);121 int offset = memberOffset.get(r);122 123 Pair<Way, Way> entryExitWays= getEntryExitWays(r, i + offset);124 Way entryWay = entryExitWays.a;125 Way exitWay = entryExitWays.b;126 127 //get the entry and exit nodes, exit if not found128 Node entryNode = getNodeInCommon(splitNodes, entryWay);129 Node exitNode = getNodeInCommon(splitNodes, exitWay);130 131 if(entryNode == null || exitNode == null)132 return;133 134 //starting from the entry node, add split ways until the135 //exit node is reached136 List<Way> parents = entryNode.getParentWays();137 parents.removeIf(w -> !w.firstNode().equals(entryNode));138 parents.removeIf(w -> w.equals(entryWay));139 140 Way curr = parents.get(0);141 142 while(!curr.lastNode().equals(exitNode)) {143 r.addMember(i + offset++, new RelationMember(null, curr));144 parents = curr.lastNode().getParentWays();145 parents.remove(curr);146 parents.removeIf(w -> !splitWays.contains(w));147 curr = parents.get(0);148 }149 r.addMember(i + offset++, new RelationMember(null, curr));150 memberOffset.put(r, offset);151 }));117 positions.forEach(i -> { 118 119 if(!memberOffset.containsKey(r)) 120 memberOffset.put(r, 0); 121 int offset = memberOffset.get(r); 122 123 Pair<Way, Way> entryExitWays= getEntryExitWays(r, i + offset); 124 Way entryWay = entryExitWays.a; 125 Way exitWay = entryExitWays.b; 126 127 //get the entry and exit nodes, exit if not found 128 Node entryNode = getNodeInCommon(splitNodes, entryWay); 129 Node exitNode = getNodeInCommon(splitNodes, exitWay); 130 131 if(entryNode == null || exitNode == null) 132 return; 133 134 //starting from the entry node, add split ways until the 135 //exit node is reached 136 List<Way> parents = entryNode.getParentWays(); 137 parents.removeIf(w -> !w.firstNode().equals(entryNode)); 138 parents.removeIf(w -> w.equals(entryWay)); 139 140 Way curr = parents.get(0); 141 142 while(!curr.lastNode().equals(exitNode)) { 143 r.addMember(i + offset++, new RelationMember(null, curr)); 144 parents = curr.lastNode().getParentWays(); 145 parents.remove(curr); 146 parents.removeIf(w -> !splitWays.contains(w)); 147 curr = parents.get(0); 148 } 149 r.addMember(i + offset++, new RelationMember(null, curr)); 150 memberOffset.put(r, offset); 151 })); 152 152 } 153 153 … … 165 165 private Pair<Way, Way> getEntryExitWays(Relation r, Integer position) { 166 166 167 //the ways returned are the one exactly before and after the roundabout168 Pair<Way, Way> ret = new Pair<>(null, null);169 ret.a = r.getMember(position-1).getWay();170 ret.b = r.getMember(position).getWay();171 return ret;167 //the ways returned are the one exactly before and after the roundabout 168 Pair<Way, Way> ret = new Pair<>(null, null); 169 ret.a = r.getMember(position-1).getWay(); 170 ret.b = r.getMember(position).getWay(); 171 return ret; 172 172 } 173 173 … … 186 186 for(OsmPrimitive prim : parent.getReferrers()) { 187 187 if(prim.getType() == OsmPrimitiveType.RELATION && 188 RouteUtils.is TwoDirectionRoute((Relation) prim))188 RouteUtils.isPTRoute((Relation) prim)) 189 189 return false; 190 190 } … … 203 203 List <OsmPrimitive> referrers = roundabout.getReferrers(); 204 204 referrers.removeIf(r -> r.getType() != OsmPrimitiveType.RELATION 205 || !RouteUtils.is TwoDirectionRoute((Relation) r));205 || !RouteUtils.isPTRoute((Relation) r)); 206 206 207 207 for(OsmPrimitive currPrim : referrers) { … … 210 210 if(curr.getMember(j).getUniqueId() == roundabout.getUniqueId()) { 211 211 if(!savedPositions.containsKey(curr)) 212 savedPositions.put(curr, new ArrayList<>());213 List<Integer> positions = savedPositions.get(curr);214 positions.add(j - positions.size());212 savedPositions.put(curr, new ArrayList<>()); 213 List<Integer> positions = savedPositions.get(curr); 214 positions.add(j - positions.size()); 215 215 } 216 216 } 217 217 218 218 if(savedPositions.containsKey(curr)) 219 curr.removeMembersFor(roundabout);219 curr.removeMembersFor(roundabout); 220 220 } 221 221 … … 232 232 if(selected.getType() != OsmPrimitiveType.WAY) 233 233 return; 234 if(((Way)selected).isClosed() && selected.hasTag("junction", "roundabout")) { 234 if(((Way)selected).isClosed() 235 && (selected.hasTag("junction", "roundabout") 236 || selected.hasTag("oneway", "yes"))) { 235 237 setEnabled(true); 236 238 return; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayer.java
r33362 r33414 207 207 Relation relation = editor.getRelation(); 208 208 209 if (RouteUtils.is TwoDirectionRoute(relation)) {209 if (RouteUtils.isVersionTwoPTRoute(relation)) { 210 210 this.repaint(relation); 211 211 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantLayerManager.java
r33408 r33414 38 38 for (OsmPrimitive primitive : newSelection) { 39 39 if (primitive.getType().equals(OsmPrimitiveType.RELATION) 40 && RouteUtils.is TwoDirectionRoute((Relation) primitive)) {41 routes.add(primitive);40 && RouteUtils.isVersionTwoPTRoute((Relation) primitive)) { 41 routes.add(primitive); 42 42 } 43 43 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java
r33322 r33414 346 346 if (parent.getType().equals(OsmPrimitiveType.RELATION)) { 347 347 Relation relation = (Relation) parent; 348 if (RouteUtils.is TwoDirectionRoute(relation) && relation.get("ref") != null348 if (RouteUtils.isVersionTwoPTRoute(relation) && relation.get("ref") != null 349 349 && !relation.get("ref").equals("")) { 350 350 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r33406 r33414 19 19 public final class RouteUtils { 20 20 21 private final static String ptVersionTag = "public_transport:version"; 21 22 private RouteUtils() { 22 23 // private constructor for util classes … … 32 33 * with the pt_assistant plugin, false otherwise. 33 34 */ 34 public static boolean isTwoDirectionRoute(Relation r) { 35 public static boolean isVersionTwoPTRoute(Relation r) { 36 37 if(!isPTRoute(r)) { 38 return false; 39 } 40 41 if (!r.hasTag(ptVersionTag, "2")) { 42 return false; 43 } 44 45 return !r.hasTag("bus", "on_demand"); 46 } 47 48 public static boolean isVersionOnePTRoute(Relation r) { 49 50 if(!isPTRoute(r)) { 51 return false; 52 } 53 54 if(r.get(ptVersionTag) == null) { 55 return true; 56 } 57 58 return r.hasTag(ptVersionTag, "1"); 59 } 60 61 public static boolean isPTRoute(Relation r) { 35 62 36 63 if (r == null) { … … 38 65 } 39 66 40 if (!r.hasKey("route") || !r.hasTag("public_transport:version", "2")) {41 return false;42 }43 44 67 String [] acceptedRouteTags = new String[] { 45 "bus", "trolleybus", "share_taxi",68 "bus", "trolleybus", "share_taxi", 46 69 "tram", "light_rail", "subway", "train"}; 47 70 48 return r.hasTag("route", acceptedRouteTags) 49 && !r.hasTag("bus", "on_demand"); 71 return r.hasTag("route", acceptedRouteTags); 50 72 } 51 73 … … 66 88 return (rm.getType().equals(OsmPrimitiveType.WAY)) 67 89 && (rm.getWay().hasTag("public_transport", "platform") 68 || rm.getWay().hasTag("highway", "platform")90 || rm.getWay().hasTag("highway", "platform") 69 91 || rm.getWay().hasTag("railway", "platform")); 70 92 } … … 88 110 if (rm.getType().equals(OsmPrimitiveType.WAY)) { 89 111 return !(rm.getWay().hasTag("public_transport", "platform") 90 || rm.getWay().hasTag("highway", "platform")112 || rm.getWay().hasTag("highway", "platform") 91 113 || rm.getWay().hasTag("railway", "platform")); 92 114 } … … 115 137 116 138 if (OsmUtils.isTrue(way.get("oneway")) 117 || OsmUtils.isReversed(way.get("oneway"))139 || OsmUtils.isReversed(way.get("oneway")) 118 140 || way.hasTag("junction", "roundabout") 119 141 || way.hasTag("highway", "motorway")) { … … 121 143 if (!way.hasTag("busway", "lane") 122 144 && !way.hasTag("busway", "opposite_lane") 123 && !way.hasTag("busway:left", "lane")145 && !way.hasTag("busway:left", "lane") 124 146 && !way.hasTag("busway:right", "lane") 125 147 && !way.hasTag("oneway:bus", "no") … … 155 177 156 178 return w1FirstNode == w2FirstNode 157 || w1FirstNode == w2LastNode158 || w1LastNode == w2FirstNode179 || w1FirstNode == w2LastNode 180 || w1LastNode == w2FirstNode 159 181 || w1LastNode == w2LastNode; 160 182 } … … 195 217 public static boolean isWaySuitableForBuses(Way way) { 196 218 197 String [] acceptedHighwayTags = new String [] {198 "motorway", "trunk", "primary", "secondary", "tertiary",219 String [] acceptedHighwayTags = new String [] { 220 "motorway", "trunk", "primary", "secondary", "tertiary", 199 221 "unclassified" , "road", "residential", "service", 200 222 "motorway_link", "trunk_link", "primary_link", "secondary_link", 201 223 "tertiary_link", "living_street", "bus_guideway", "road"}; 202 224 203 if(way.hasTag("highway", acceptedHighwayTags)225 if(way.hasTag("highway", acceptedHighwayTags) 204 226 || way.hasTag("cycleway", "share_busway") 205 227 || way.hasTag("cycleway", "shared_lane")) { … … 207 229 } 208 230 209 if (way.hasTag("highway", "pedestrian") 210 && (way.hasTag("bus", "yes") 211 || way.hasTag("psv", "yes") 212 || way.hasTag("bus", "designated") 213 || way.hasTag("psv", "designated"))) { 214 return true; 215 } 216 217 return false; 231 return (way.hasTag("highway", "pedestrian") 232 && (way.hasTag("bus", "yes", "designated") 233 || way.hasTag("psv", "yes", "designated"))); 218 234 } 219 235 … … 225 241 public static boolean isWaySuitableForPublicTransport(Way way) { 226 242 227 String [] acceptedRailwayTags = new String [] {228 "tram", "subway", "light_rail", "rail"};243 String [] acceptedRailwayTags = new String [] { 244 "tram", "subway", "light_rail", "rail"}; 229 245 230 246 return isWaySuitableForBuses(way) 231 || way.hasTag("railway", acceptedRailwayTags);247 || way.hasTag("railway", acceptedRailwayTags); 232 248 } 233 249 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java
r33405 r33414 144 144 } 145 145 146 if (!RouteUtils.is TwoDirectionRoute(r)) {146 if (!RouteUtils.isVersionTwoPTRoute(r)) { 147 147 return; 148 148 }
Note:
See TracChangeset
for help on using the changeset viewer.
