-
Notifications
You must be signed in to change notification settings - Fork 14
Add basic controls for the routing helper reimplementation #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
floscher
wants to merge
17
commits into
master
Choose a base branch
from
routing_helper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
023ec80
Start creating the routing helper rewrite, at the moment just a bit o…
floscher 08c2706
Automatically open routing helper when selecting a route relation, ma…
floscher 928c168
Add really basic transport mode detection to routing help, currently …
floscher 0aa7bb6
I completed the BusTransportMode, so it works for all kinds of buses.
PolyglotOpenstreetmap 2395f15
I created a BicycleTransportMode
PolyglotOpenstreetmap 3d3cc48
I created a PedestrianTransportMode and a HorseTransportMode. I also …
PolyglotOpenstreetmap bc77476
Make the suitable ways in transport modes a static field
PolyglotOpenstreetmap ff36ed1
Rename routing helper to route explorer
floscher f23c46e
I factored out the code duplication. It made the code less readable t…
PolyglotOpenstreetmap 92fc292
created a test for the BusTransportMode, canTurn still needs to be added
PolyglotOpenstreetmap 8e57521
fixed the tests and the implementation of canTraverseWay
PolyglotOpenstreetmap 1d15ad9
made the BusTransportModeTest somewhat more extensive for testCanTrav…
PolyglotOpenstreetmap d3ec984
I tried to add tests for canTurn, but I'm stuck on line 46 of Abstrac…
PolyglotOpenstreetmap cab5fd5
All the tests are passing. Prohibiting turn restrictions "no_" are te…
PolyglotOpenstreetmap 58f97e5
I added tests for the mandatory types, but the result with only asser…
PolyglotOpenstreetmap 5055bc5
Oops, fix copy/paste error
PolyglotOpenstreetmap 56b6c9b
Turn restrictions seem to be a can of worms...
PolyglotOpenstreetmap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...g/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BicycleTransportMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import com.drew.lang.annotations.NotNull; | ||
| import org.openstreetmap.josm.data.osm.IRelation; | ||
| import org.openstreetmap.josm.data.osm.IWay; | ||
| import org.openstreetmap.josm.data.osm.Node; | ||
| import org.openstreetmap.josm.data.osm.OsmPrimitiveType; | ||
| import org.openstreetmap.josm.data.osm.Relation; | ||
| import org.openstreetmap.josm.data.osm.Way; | ||
| import org.openstreetmap.josm.plugins.pt_assistant.utils.PTIcons; | ||
| import org.openstreetmap.josm.tools.I18n; | ||
| import org.openstreetmap.josm.tools.ImageProvider; | ||
|
|
||
| public class BicycleTransportMode implements ITransportMode { | ||
| @Override | ||
| public boolean canTraverseWay(@NotNull final IWay<?> way, @NotNull final WayTraversalDirection direction) { | ||
| final String onewayValue = way.get("oneway"); | ||
| List<String> majorHighways = Arrays.asList( | ||
| "tertiary", "secondary", "primary", "trunk"); | ||
| majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); | ||
| // This list is ordered from most suitable to least suitable | ||
| List<String> suitableHighwaysForBicycle = Arrays.asList( | ||
| "cycleway", "cyclestreet", "path", "residential", "unclassified", "service", "track", "living_street"); | ||
| suitableHighwaysForBicycle.addAll(majorHighways); // TODO do this only once when plugin starts | ||
| return !way.hasTag("bicycle", "no") && | ||
| (way.hasTag("highway", suitableHighwaysForBicycle) || | ||
| way.hasTag("bicycle", "yes")) | ||
| && ( | ||
| onewayValue == null || "no".equals(way.get("oneway:bicycle")) || | ||
| ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || | ||
| ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canBeUsedForRelation(@NotNull final IRelation<?> relation) { | ||
| return relation.hasTag("type", "route") && relation.hasTag("route", "bicycle"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canTurn(@NotNull final Way from, @NotNull final Node via, @NotNull final Way to) { | ||
| final Set<Relation> restrictionRelations = from.getReferrers().stream() | ||
| .map(it -> it.getType() == OsmPrimitiveType.RELATION ? (Relation) it : null) | ||
| .filter(Objects::nonNull) | ||
| .filter(it -> "restriction".equals(it.get("type")) || "restriction:bicycle".equals(it.get("type"))) | ||
| .filter(it -> it.findRelationMembers("from").contains(from)) | ||
| .filter(it -> it.findRelationMembers("via").contains(via)) | ||
| .filter(it -> it.findRelationMembers("to").contains(to)) | ||
| .collect(Collectors.toSet()); | ||
| for (Relation restrictionRelation : restrictionRelations) { | ||
| final String restriction = restrictionRelation.get("restriction"); | ||
| final String except = restrictionRelation.get("except"); | ||
| if (restriction.startsWith("no_") && !except.contains("bicycle")) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return from.containsNode(via) && to.containsNode(via); | ||
| } | ||
|
|
||
| @Override | ||
| public ImageProvider getIcon() { | ||
| return PTIcons.BICYCLE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return I18n.marktr("bicycle"); | ||
| } | ||
| } |
78 changes: 78 additions & 0 deletions
78
...a/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BusTransportMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.swing.Icon; | ||
|
|
||
| import com.drew.lang.annotations.NotNull; | ||
| import org.openstreetmap.josm.data.osm.IRelation; | ||
| import org.openstreetmap.josm.data.osm.IWay; | ||
| import org.openstreetmap.josm.data.osm.Node; | ||
| import org.openstreetmap.josm.data.osm.OsmPrimitiveType; | ||
| import org.openstreetmap.josm.data.osm.Relation; | ||
| import org.openstreetmap.josm.data.osm.Way; | ||
| import org.openstreetmap.josm.plugins.pt_assistant.utils.PTIcons; | ||
| import org.openstreetmap.josm.tools.I18n; | ||
| import org.openstreetmap.josm.tools.ImageProvider; | ||
|
|
||
| public class BusTransportMode implements ITransportMode { | ||
| @Override | ||
| public boolean canTraverseWay(@NotNull final IWay<?> way, @NotNull final WayTraversalDirection direction) { | ||
| final String onewayValue = way.get("oneway"); | ||
| List<String> majorHighways = Arrays.asList( | ||
| "motorway", "trunk", "primary", "secondary", "tertiary"); | ||
| majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); | ||
| List<String> suitableHighwaysForBus = Arrays.asList( | ||
| "unclassified", "residential", "service", "living_street", "cyclestreet"); | ||
| suitableHighwaysForBus.addAll(majorHighways); // TODO do this only once when plugin starts | ||
| return (way.hasTag("highway", suitableHighwaysForBus) || | ||
| way.hasTag("psv", "yes") || way.hasTag ("bus", "yes")) | ||
| && ( | ||
| onewayValue == null || "no".equals(way.get("oneway:bus")) || | ||
| ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || | ||
| ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canBeUsedForRelation(@NotNull final IRelation<?> relation) { | ||
| return relation.hasTag("type", "route") && relation.hasTag("route", | ||
| "bus", "coach", "minibus"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canTurn(@NotNull final Way from, @NotNull final Node via, @NotNull final Way to) { | ||
| final Set<Relation> restrictionRelations = from.getReferrers().stream() | ||
| .map(it -> it.getType() == OsmPrimitiveType.RELATION ? (Relation) it : null) | ||
| .filter(Objects::nonNull) | ||
| .filter(it -> "restriction".equals(it.get("type")) || "restriction:bus".equals(it.get("type"))) | ||
| .filter(it -> it.findRelationMembers("from").contains(from)) | ||
| .filter(it -> it.findRelationMembers("via").contains(via)) | ||
| .filter(it -> it.findRelationMembers("to").contains(to)) | ||
| .collect(Collectors.toSet()); | ||
| for (Relation restrictionRelation : restrictionRelations) { | ||
| final String restriction = restrictionRelation.get("restriction"); | ||
| final String except = restrictionRelation.get("except"); | ||
| if (restriction.startsWith("no_") && !except.contains("psv")) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return from.containsNode(via) && to.containsNode(via); | ||
| } | ||
|
|
||
| @Override | ||
| public ImageProvider getIcon() { | ||
| return PTIcons.BUS; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return I18n.marktr("bus"); | ||
| } | ||
| } |
75 changes: 75 additions & 0 deletions
75
...org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/HorseTransportMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import com.drew.lang.annotations.NotNull; | ||
| import org.openstreetmap.josm.data.osm.IRelation; | ||
| import org.openstreetmap.josm.data.osm.IWay; | ||
| import org.openstreetmap.josm.data.osm.Node; | ||
| import org.openstreetmap.josm.data.osm.OsmPrimitiveType; | ||
| import org.openstreetmap.josm.data.osm.Relation; | ||
| import org.openstreetmap.josm.data.osm.Way; | ||
| import org.openstreetmap.josm.plugins.pt_assistant.utils.PTIcons; | ||
| import org.openstreetmap.josm.tools.I18n; | ||
| import org.openstreetmap.josm.tools.ImageProvider; | ||
|
|
||
| public class HorseTransportMode implements ITransportMode { | ||
| @Override | ||
| public boolean canTraverseWay(@NotNull final IWay<?> way, @NotNull final WayTraversalDirection direction) { | ||
| final String onewayValue = way.get("oneway"); | ||
| List<String> majorHighways = Arrays.asList( | ||
| "tertiary", "secondary", "primary", "trunk"); | ||
| majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); | ||
| // This list is ordered from most suitable to least suitable | ||
| List<String> suitableHighwaysForHorseRiders = Arrays.asList( | ||
| "bridleway", "pedestrian", "footway", "path", "track", "living_street", "residential", "unclassified", "cyclestreet", "service", "cycleway"); | ||
| suitableHighwaysForHorseRiders.addAll(majorHighways); // TODO do this only once when plugin starts | ||
| return !way.hasTag("horse", "no") && | ||
| (way.hasTag("highway", suitableHighwaysForHorseRiders) || | ||
| way.hasTag("horse", "yes")) | ||
| && ( | ||
| onewayValue == null || | ||
| ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || | ||
| ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canBeUsedForRelation(@NotNull final IRelation<?> relation) { | ||
| return relation.hasTag("type", "route") && relation.hasTag("route", "horse"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canTurn(@NotNull final Way from, @NotNull final Node via, @NotNull final Way to) { | ||
| final Set<Relation> restrictionRelations = from.getReferrers().stream() | ||
| .map(it -> it.getType() == OsmPrimitiveType.RELATION ? (Relation) it : null) | ||
| .filter(Objects::nonNull) | ||
| .filter(it -> "restriction".equals(it.get("type"))) | ||
| .filter(it -> it.findRelationMembers("from").contains(from)) | ||
| .filter(it -> it.findRelationMembers("via").contains(via)) | ||
| .filter(it -> it.findRelationMembers("to").contains(to)) | ||
| .collect(Collectors.toSet()); | ||
| for (Relation restrictionRelation : restrictionRelations) { | ||
| final String restriction = restrictionRelation.get("restriction"); | ||
| if (restriction.startsWith("no_")) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return from.containsNode(via) && to.containsNode(via); | ||
| } | ||
|
|
||
| @Override | ||
| public ImageProvider getIcon() { | ||
| return PTIcons.HORSE; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return I18n.marktr("equestrian"); | ||
| } | ||
| } | ||
55 changes: 55 additions & 0 deletions
55
...ava/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/ITransportMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; | ||
|
|
||
| import com.drew.lang.annotations.NotNull; | ||
| import org.openstreetmap.josm.data.osm.IRelation; | ||
| import org.openstreetmap.josm.data.osm.IWay; | ||
| import org.openstreetmap.josm.data.osm.Node; | ||
| import org.openstreetmap.josm.data.osm.Way; | ||
| import org.openstreetmap.josm.tools.I18n; | ||
| import org.openstreetmap.josm.tools.ImageProvider; | ||
|
|
||
| public interface ITransportMode { | ||
| /** | ||
| * Just a convenience method for {@link #canTraverseWay(IWay, WayTraversalDirection)} that assumes {@link WayTraversalDirection#FORWARD} | ||
| * @param way the way for which we check, if it can be traversed by the transport mode | ||
| * @return {@code true} if the transport mode can travel along the way in the forward direction. Otherwise {@code false}. | ||
| */ | ||
| default boolean canTraverseWay(final Way way) { | ||
| return canTraverseWay(way, WayTraversalDirection.FORWARD); | ||
| } | ||
|
|
||
| /** | ||
| * @param way the way that is checked, if the transport mode can traverse | ||
| * @param direction the travel direction for which we check | ||
| * @return {@code true} iff the transport mode can travel along the given way in the given direction. Otherwise {@code false}. | ||
| */ | ||
| boolean canTraverseWay(@NotNull IWay<?> way, @NotNull WayTraversalDirection direction); | ||
|
|
||
| /** | ||
| * Checks if this transport mode should be used for the given relation | ||
| * @param relation the relation that is checked, if it is suitable for the transport mode | ||
| * @return {@code true} if the transport mode is suitable for the relation. Otherwise {@code false}. | ||
| */ | ||
| boolean canBeUsedForRelation(@NotNull final IRelation<?> relation); | ||
|
|
||
| /** | ||
| * @param from the way from which the vehicle is coming | ||
| * @param via the node that the vehicle travels through, must be part of {@code from} and {@code to} ways, | ||
| * or this method will return false | ||
| * @param to the way onto which the vehicle makes the turn | ||
| * @return {@code true} iff the transport mode can make a turn from the given {@code from} way, | ||
| * via the given {@code via} node to the given {@code to} way. Otherwise {@code false}. | ||
| * This method assumes that both ways can be traversed by the transport mode, it does not check that. | ||
| */ | ||
| boolean canTurn(@NotNull final Way from, @NotNull final Node via, @NotNull final Way to); | ||
|
|
||
| /** | ||
| * @return an icon representing the transport mode | ||
| */ | ||
| ImageProvider getIcon(); | ||
|
|
||
| /** | ||
| * @return a unique name for the transport mode. This string should be translatable, so please use {@link I18n#marktr} on the string that's returned! | ||
| */ | ||
| String getName(); | ||
| } |
78 changes: 78 additions & 0 deletions
78
...penstreetmap/josm/plugins/pt_assistant/actions/routinghelper/PedestrianTransportMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.swing.Icon; | ||
|
|
||
| import com.drew.lang.annotations.NotNull; | ||
| import org.openstreetmap.josm.data.osm.IRelation; | ||
| import org.openstreetmap.josm.data.osm.IWay; | ||
| import org.openstreetmap.josm.data.osm.Node; | ||
| import org.openstreetmap.josm.data.osm.OsmPrimitiveType; | ||
| import org.openstreetmap.josm.data.osm.Relation; | ||
| import org.openstreetmap.josm.data.osm.Way; | ||
| import org.openstreetmap.josm.plugins.pt_assistant.utils.PTIcons; | ||
| import org.openstreetmap.josm.tools.I18n; | ||
| import org.openstreetmap.josm.tools.ImageProvider; | ||
|
|
||
| public class PedestrianTransportMode implements ITransportMode { | ||
| @Override | ||
| public boolean canTraverseWay(@NotNull final IWay<?> way, @NotNull final WayTraversalDirection direction) { | ||
| final String onewayValue = way.get("oneway"); | ||
| List<String> majorHighways = Arrays.asList( | ||
| "tertiary", "secondary", "primary", "trunk"); | ||
| majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); | ||
| // This list is ordered from most suitable to least suitable | ||
| List<String> suitableHighwaysForPedestrians = Arrays.asList( | ||
| "pedestrian", "footway", "path", "track", "living_street", "residential", "unclassified", "cyclestreet", "service", "cycleway", "bridleway"); | ||
| suitableHighwaysForPedestrians.addAll(majorHighways); // TODO do this only once when plugin starts | ||
| return !way.hasTag("foot", "no") && | ||
| (way.hasTag("highway", suitableHighwaysForPedestrians) || | ||
| way.hasTag("foot", "yes")) | ||
| && ( | ||
| onewayValue == null || "no".equals(way.get("foot:backward")) || "no".equals(way.get("oneway:foot")) || | ||
| ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || | ||
| ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canBeUsedForRelation(@NotNull final IRelation<?> relation) { | ||
| return relation.hasTag("type", "route") && relation.hasTag("route", | ||
| "foot", "walking", "hiking"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canTurn(@NotNull final Way from, @NotNull final Node via, @NotNull final Way to) { | ||
| final Set<Relation> restrictionRelations = from.getReferrers().stream() | ||
| .map(it -> it.getType() == OsmPrimitiveType.RELATION ? (Relation) it : null) | ||
| .filter(Objects::nonNull) | ||
| .filter(it -> "restriction".equals(it.get("type"))) | ||
| .filter(it -> it.findRelationMembers("from").contains(from)) | ||
| .filter(it -> it.findRelationMembers("via").contains(via)) | ||
| .filter(it -> it.findRelationMembers("to").contains(to)) | ||
| .collect(Collectors.toSet()); | ||
| for (Relation restrictionRelation : restrictionRelations) { | ||
| final String restriction = restrictionRelation.get("restriction"); | ||
| if (restriction.startsWith("no_")) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return from.containsNode(via) && to.containsNode(via); | ||
| } | ||
|
|
||
| @Override | ||
| public ImageProvider getIcon() { | ||
| return PTIcons.PEDESTRIAN; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return I18n.marktr("pedestrian"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.