Add feature to calculate route between rtept

This commit is contained in:
vshcherb 2014-05-21 01:55:59 +02:00
parent 2d548eec46
commit 81daec3e70
8 changed files with 105 additions and 25 deletions

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="use_points_as_intermediates">Calculate route between points</string>
<string name="osmo_register_device">Registering device... </string> <string name="osmo_register_device">Registering device... </string>
<string name="osmo_io_error">OSMo connection problem : </string> <string name="osmo_io_error">OSMo connection problem : </string>
<string name="osmo_mode_on">Stop OSMo</string> <string name="osmo_mode_on">Stop OSMo</string>

View file

@ -123,6 +123,26 @@ public class GPXUtilities {
public boolean isCloudmadeRouteFile() { public boolean isCloudmadeRouteFile() {
return "cloudmade".equalsIgnoreCase(author); return "cloudmade".equalsIgnoreCase(author);
} }
public boolean hasRtePt() {
for(Route r : routes) {
if(r.points.size() > 0) {
return true;
}
}
return false;
}
public boolean hasTrkpt() {
for(Track t : tracks) {
for (TrkSegment ts : t.segments) {
if (ts.points.size() > 0) {
return true;
}
}
}
return false;
}
public void proccessPoints() { public void proccessPoints() {
List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>(); List<List<WptPt>> tpoints = new ArrayList<List<WptPt>>();

View file

@ -786,9 +786,10 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", true).makeProfile().cache(); public final OsmandPreference<Boolean> SPEAK_SPEED_CAMERA = new BooleanPreference("speak_cameras", true).makeProfile().cache();
public final OsmandPreference<Boolean> SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache(); public final OsmandPreference<Boolean> SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache();
public final OsmandPreference<Boolean> ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_ROUTE_CALC_OSMAND_PARTS = new BooleanPreference("gpx_routing_calculate_osmand_route", true).makeGlobal().cache();
public final OsmandPreference<Boolean> SPEAK_GPX_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_CALCULATE_RTEPT = new BooleanPreference("gpx_routing_calculate_rtept", true).makeGlobal().cache();
public final OsmandPreference<Boolean> CALC_GPX_ROUTE = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache(); public final OsmandPreference<Boolean> GPX_SPEAK_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();

View file

@ -473,9 +473,15 @@ public class MapActivityActions implements DialogProvider {
} else { } else {
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication() GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication()
.getSettings()); .getSettings());
params.setCalculateOsmAndRouteParts(settings.ROUTE_CALC_OSMAND_PARTS.get()); if (result.hasRtePt() && !result.hasTrkpt()) {
params.setAnnounceWaypoints(settings.SPEAK_GPX_WPT.get()); settings.GPX_CALCULATE_RTEPT.set(true);
params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get()); } else {
settings.GPX_CALCULATE_RTEPT.set(false);
}
params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
params.setAnnounceWaypoints(settings.GPX_SPEAK_WPT.get());
params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get());
params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
List<Location> ps = params.getPoints(); List<Location> ps = params.getPoints();
mapActivity.getRoutingHelper().setGpxParams(params); mapActivity.getRoutingHelper().setGpxParams(params);
settings.FOLLOW_THE_GPX_ROUTE.set(result.path); settings.FOLLOW_THE_GPX_ROUTE.set(result.path);

View file

@ -128,13 +128,16 @@ public class FailSafeFuntions {
final GPXRouteParamsBuilder gpxRoute; final GPXRouteParamsBuilder gpxRoute;
if (result != null) { if (result != null) {
gpxRoute = new GPXRouteParamsBuilder(result, settings); gpxRoute = new GPXRouteParamsBuilder(result, settings);
if (settings.SPEAK_GPX_WPT.get()) { if (settings.GPX_SPEAK_WPT.get()) {
gpxRoute.setAnnounceWaypoints(true); gpxRoute.setAnnounceWaypoints(true);
} }
if (settings.ROUTE_CALC_OSMAND_PARTS.get()) { if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
gpxRoute.setCalculateOsmAndRouteParts(true); gpxRoute.setCalculateOsmAndRouteParts(true);
} }
if(settings.CALC_GPX_ROUTE.get()) { if (settings.GPX_CALCULATE_RTEPT.get()) {
gpxRoute.setUseIntermediatePointsRTE(true);
}
if(settings.GPX_ROUTE_CALC.get()) {
gpxRoute.setCalculateOsmAndRoute(true); gpxRoute.setCalculateOsmAndRoute(true);
} }
} else { } else {

View file

@ -119,7 +119,8 @@ public class RouteProvider {
private boolean reverse; private boolean reverse;
private boolean leftSide; private boolean leftSide;
private boolean passWholeRoute; private boolean passWholeRoute;
public boolean calculateOsmAndRouteParts; private boolean calculateOsmAndRouteParts;
private boolean useIntermediatePointsRTE;
public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings){ public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings){
leftSide = settings.DRIVING_REGION.get().leftHandDriving; leftSide = settings.DRIVING_REGION.get().leftHandDriving;
@ -142,6 +143,14 @@ public class RouteProvider {
this.calculateOsmAndRouteParts = calculateOsmAndRouteParts; this.calculateOsmAndRouteParts = calculateOsmAndRouteParts;
} }
public void setUseIntermediatePointsRTE(boolean useIntermediatePointsRTE) {
this.useIntermediatePointsRTE = useIntermediatePointsRTE;
}
public boolean isUseIntermediatePointsRTE() {
return useIntermediatePointsRTE;
}
public boolean isCalculateOsmAndRoute() { public boolean isCalculateOsmAndRoute() {
return calculateOsmAndRoute; return calculateOsmAndRoute;
} }
@ -196,6 +205,7 @@ public class RouteProvider {
boolean calculateOsmAndRoute; boolean calculateOsmAndRoute;
boolean passWholeRoute; boolean passWholeRoute;
boolean calculateOsmAndRouteParts; boolean calculateOsmAndRouteParts;
boolean useIntermediatePointsRTE;
public List<Location> getPoints() { public List<Location> getPoints() {
return points; return points;
@ -229,8 +239,9 @@ public class RouteProvider {
boolean reverse = builder.reverse; boolean reverse = builder.reverse;
passWholeRoute = builder.passWholeRoute; passWholeRoute = builder.passWholeRoute;
calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts; calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts;
useIntermediatePointsRTE = builder.useIntermediatePointsRTE;
boolean announceWaypoints = builder.announceWaypoints; boolean announceWaypoints = builder.announceWaypoints;
calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute; builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){ if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){
directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10); directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10);
if(reverse){ if(reverse){
@ -240,10 +251,12 @@ public class RouteProvider {
} }
} else { } else {
// first of all check tracks // first of all check tracks
for (Track tr : file.tracks) { if (!useIntermediatePointsRTE) {
for (TrkSegment tkSeg : tr.segments) { for (Track tr : file.tracks) {
for (WptPt pt : tkSeg.points) { for (TrkSegment tkSeg : tr.segments) {
points.add(createLocation(pt)); for (WptPt pt : tkSeg.points) {
points.add(createLocation(pt));
}
} }
} }
} }
@ -348,9 +361,13 @@ public class RouteProvider {
return res; return res;
} }
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) { private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
// get the closest point to start and to end // get the closest point to start and to end
GPXRouteParams gpxParams = routeParams.gpxRoute; GPXRouteParams gpxParams = routeParams.gpxRoute;
if(routeParams.gpxRoute.useIntermediatePointsRTE){
final List<Location> intermediates = gpxParams.points;
return calculateOsmAndRouteWithIntermediatePoints(routeParams, intermediates);
}
List<Location> gpxRoute ; List<Location> gpxRoute ;
int[] startI = new int[]{0}; int[] startI = new int[]{0};
int[] endI = new int[]{gpxParams.points.size()}; int[] endI = new int[]{gpxParams.points.size()};
@ -378,6 +395,28 @@ public class RouteProvider {
private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams,
final List<Location> intermediates) throws IOException {
RouteCalculationParams rp = new RouteCalculationParams();
rp.calculationProgress = routeParams.calculationProgress;
rp.ctx = routeParams.ctx;
rp.mode = routeParams.mode;
rp.start = routeParams.start;
rp.end = routeParams.end;
rp.leftSide = routeParams.leftSide;
rp.type = routeParams.type;
rp.fast = routeParams.fast;
rp.previousToRecalculate = routeParams.previousToRecalculate;
rp.intermediates = new ArrayList<LatLon>();
for(Location w : intermediates) {
rp.intermediates.add(new LatLon(w.getLatitude(), w.getLongitude()));
}
return findVectorMapsRoute(rp, false);
}
private List<RouteDirectionInfo> calcDirections(int[] startI, int[] endI, private List<RouteDirectionInfo> calcDirections(int[] startI, int[] endI,
final List<RouteDirectionInfo> inputDirections) { final List<RouteDirectionInfo> inputDirections) {
List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>(); List<RouteDirectionInfo> directions = new ArrayList<RouteDirectionInfo>();

View file

@ -757,7 +757,7 @@ public class RoutingHelper {
return; return;
} }
final boolean onlineSourceWithoutInternet = !res.isCalculated() && params.type.isOnline() && !settings.isInternetConnectionAvailable(); final boolean onlineSourceWithoutInternet = !res.isCalculated() && params.type.isOnline() && !settings.isInternetConnectionAvailable();
if (onlineSourceWithoutInternet && settings.ROUTE_CALC_OSMAND_PARTS.get()) { if (onlineSourceWithoutInternet && settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) { if (params.previousToRecalculate != null && params.previousToRecalculate.isCalculated()) {
res = provider.recalculatePartOfflineRoute(res, params); res = provider.recalculatePartOfflineRoute(res, params);
} }

View file

@ -188,20 +188,23 @@ public class MapRoutePreferencesControl extends MapControls {
} }
} else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) { } else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
rp.setCalculateOsmAndRouteParts(selected); rp.setCalculateOsmAndRouteParts(selected);
settings.ROUTE_CALC_OSMAND_PARTS.set(selected); settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
} else if (gpxParam.id == R.string.gpx_option_from_start_point) { } else if (gpxParam.id == R.string.gpx_option_from_start_point) {
rp.setPassWholeRoute(selected); rp.setPassWholeRoute(selected);
} else if (gpxParam.id == R.string.announce_gpx_waypoints) { } else if (gpxParam.id == R.string.announce_gpx_waypoints) {
settings.SPEAK_GPX_WPT.set(selected); settings.GPX_SPEAK_WPT.set(selected);
rp.setAnnounceWaypoints(selected); rp.setAnnounceWaypoints(selected);
} else if (gpxParam.id == R.string.use_points_as_intermediates) {
settings.GPX_CALCULATE_RTEPT.set(selected);
rp.setUseIntermediatePointsRTE(selected);
} else if (gpxParam.id == R.string.calculate_osmand_route_gpx) { } else if (gpxParam.id == R.string.calculate_osmand_route_gpx) {
settings.CALC_GPX_ROUTE.set(selected); settings.GPX_ROUTE_CALC.set(selected);
rp.setCalculateOsmAndRoute(selected); rp.setCalculateOsmAndRoute(selected);
updateParameters(); updateParameters();
} }
} }
if (gpxParam.id == R.string.calculate_osmand_route_without_internet) { if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
settings.ROUTE_CALC_OSMAND_PARTS.set(selected); settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
} }
if (gpxParam.id == R.string.fast_route_mode) { if (gpxParam.id == R.string.fast_route_mode) {
settings.FAST_ROUTE_MODE.set(selected); settings.FAST_ROUTE_MODE.set(selected);
@ -215,18 +218,25 @@ public class MapRoutePreferencesControl extends MapControls {
boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ; boolean osmandRouter = settings.ROUTER_SERVICE.get() == RouteService.OSMAND ;
if(!osmandRouter) { if(!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet, list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
getString(R.string.calculate_osmand_route_without_internet), settings.ROUTE_CALC_OSMAND_PARTS.get())); getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode, list.add(new OtherLocalRoutingParameter(R.string.fast_route_mode,
getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get())); getString(R.string.fast_route_mode), settings.FAST_ROUTE_MODE.get()));
return list; return list;
} }
if(rparams != null) { if(rparams != null) {
GPXFile fl = rparams.getFile();
if (fl.hasRtePt()) {
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
}
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
getString(R.string.gpx_option_reverse_route), rparams.isReverse())); getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point, if (!rparams.isUseIntermediatePointsRTE()) {
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute())); getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment, list.add(new OtherLocalRoutingParameter(R.string.gpx_option_calculate_first_last_segment,
getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts())); getString(R.string.gpx_option_calculate_first_last_segment), rparams.isCalculateOsmAndRouteParts()));
}
list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints, list.add(new OtherLocalRoutingParameter(R.string.announce_gpx_waypoints,
getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints())); getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
// Temporary disabled // Temporary disabled