From 1370e3050da29ccabaa4a549a0b95355566cc601 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 6 Feb 2014 00:17:07 +0100 Subject: [PATCH] Update warnings & settings with new routing --- .../binary/BinaryMapRouteReaderAdapter.java | 28 ++++------ .../osmand/router/RoutePlannerFrontEnd.java | 2 + .../osmand/router/RoutingConfiguration.java | 14 ++--- .../src/net/osmand/router/RoutingContext.java | 28 +++++++--- OsmAnd/res/values/strings.xml | 7 +++ OsmAnd/res/xml/navigation_settings.xml | 2 - .../src/net/osmand/plus/OsmandSettings.java | 6 +-- .../SettingsNavigationActivity.java | 1 - .../SettingsDevelopmentActivity.java | 2 + .../osmand/plus/routing/RouteProvider.java | 51 +++++++++++++------ 10 files changed, 82 insertions(+), 59 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 68ececcdb7..697eaa75e2 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -188,11 +188,6 @@ public class BinaryMapRouteReaderAdapter { public static class RouteRegion extends BinaryIndexPart { public int regionsRead; - public int borderBoxPointer = 0; - public int baseBorderBoxPointer = 0; - public int borderBoxLength = 0; - public int baseBorderBoxLength = 0; - List subregions = new ArrayList(); List basesubregions = new ArrayList(); List routeEncodingRules = new ArrayList(); @@ -258,6 +253,15 @@ public class BinaryMapRouteReaderAdapter { } return l; } + + public boolean contains(int x31, int y31) { + for(RouteSubregion s : subregions) { + if(s.left <= x31 && s.right >= x31 && s.top <= y31 && s.bottom >= y31) { + return true; + } + } + return false; + } } // Used in C++ @@ -360,20 +364,6 @@ public class BinaryMapRouteReaderAdapter { codedIS.popLimit(oldLimit); break; } - case OsmandOdb.OsmAndRoutingIndex.BASEBORDERBOX_FIELD_NUMBER: - case OsmandOdb.OsmAndRoutingIndex.BORDERBOX_FIELD_NUMBER: { - int length = readInt(); - int filePointer = codedIS.getTotalBytesRead(); - if(tag == OsmandOdb.OsmAndRoutingIndex.BORDERBOX_FIELD_NUMBER) { - region.borderBoxLength = length; - region.borderBoxPointer = filePointer; - } else { - region.baseBorderBoxLength = length; - region.baseBorderBoxPointer = filePointer; - } - codedIS.skipRawBytes(length); - break; - } case OsmandOdb.OsmAndRoutingIndex.BLOCKS_FIELD_NUMBER : { // Finish reading file! codedIS.skipRawBytes(codedIS.getBytesUntilLimit()); diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index 55ced1ed03..bee6246df2 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -195,6 +195,8 @@ public class RoutePlannerFrontEnd { private List runNativeRouting(final RoutingContext ctx) throws IOException { refreshProgressDistance(ctx); RouteRegion[] regions = ctx.reverseMap.keySet().toArray(new BinaryMapRouteReaderAdapter.RouteRegion[ctx.reverseMap.size()]); + ctx.checkOldRoutingFiles(ctx.startX, ctx.startY); + ctx.checkOldRoutingFiles(ctx.targetX, ctx.targetY); RouteSegmentResult[] res = ctx.nativeLib.runNativeRouting(ctx.startX, ctx.startY, ctx.targetX, ctx.targetY, ctx.config, regions, ctx.calculationProgress, ctx.precalculatedRouteDirection, ctx.calculationMode == RouteCalculationMode.BASE); ArrayList result = new ArrayList(Arrays.asList(res)); diff --git a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java index 83d39d9eb5..6498017233 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingConfiguration.java @@ -53,24 +53,20 @@ public class RoutingConfiguration { private Map attributes = new LinkedHashMap(); public RoutingConfiguration build(String router, int memoryLimitMB) { - return build(router, null, memoryLimitMB, new String[0]); + return build(router, null, memoryLimitMB, null); } - public RoutingConfiguration build(String router, int memoryLimitMB, String[] specialization) { - return build(router, null, memoryLimitMB, specialization); + public RoutingConfiguration build(String router, int memoryLimitMB, Map params) { + return build(router, null, memoryLimitMB, params); } - public RoutingConfiguration build(String router, Double direction, int memoryLimitMB, String[] specialization) { + public RoutingConfiguration build(String router, Double direction, int memoryLimitMB, Map params) { if (!routers.containsKey(router)) { router = defaultRouter; } RoutingConfiguration i = new RoutingConfiguration(); if (routers.containsKey(router)) { i.router = routers.get(router); - if (specialization != null) { - Map params = new LinkedHashMap(); - for (String s : specialization) { - params.put(s, "true"); - } + if (params != null) { i.router = i.router.build(params); } i.routerName = router; diff --git a/OsmAnd-java/src/net/osmand/router/RoutingContext.java b/OsmAnd-java/src/net/osmand/router/RoutingContext.java index 02b6d24f20..3dd77876e0 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutingContext.java +++ b/OsmAnd-java/src/net/osmand/router/RoutingContext.java @@ -102,16 +102,9 @@ public class RoutingContext { // callback of processing segments RouteSegmentVisitor visitor = null; - // old planner public FinalRouteSegment finalRouteSegment; - - - - - - public RoutingContext(RoutingContext cp) { this.config = cp.config; this.map.putAll(cp.map); @@ -370,6 +363,24 @@ public class RoutingContext { int tileY = y31 >> zoomToLoad; return loadTileHeaders(zoomToLoad, tileX, tileY); } + + public void checkOldRoutingFiles(BinaryMapIndexReader key) { + if(calculationMode == RouteCalculationMode.BASE && key.getDateCreated() < 1390431600000l) { // new SimpleDateFormat("dd-MM-yyyy").parse("23-01-2014").getTime() + throw new RuntimeException("Update map '"+key.getRegionNames()+ "' !"); + } + } + + public void checkOldRoutingFiles(int x31, int y31) { + for (Entry> r : map.entrySet()) { + BinaryMapIndexReader reader = r.getKey(); + for(RouteRegion reg : reader.getRoutingIndexes()) { + if(reg.contains(x31, y31)) { + checkOldRoutingFiles(reader); + break; + } + } + } + } public List loadTileHeaders(final int zoomToLoadM31, int tileX, int tileY) { SearchRequest request = BinaryMapIndexReader.buildSearchRouteRequest(tileX << zoomToLoadM31, @@ -382,6 +393,9 @@ public class RoutingContext { long now = System.nanoTime(); // int rg = r.getValue().get(0).routeReg.regionsRead; List subregs = r.getKey().searchRouteIndexTree(request, r.getValue()); + if(subregs.size() > 0) { + checkOldRoutingFiles(r.getKey()); + } for (RouteSubregion sr : subregs) { int ind = searchSubregionTile(sr); RoutingSubregionTile found; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 270e4fd5aa..81e07ddf40 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,13 @@ 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 --> + Changes in 1.7: + * Completely updated routing (fast and precise) + * Active simulation in tunnels + + Fast route calculation failed (%s), fallback to slow calculation. + Disable 2-phase routing for car navigation + Disable complex routing Seamark Choose use profiles visible in application Application Profiles diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index 710f2e1172..ac2857b301 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -15,6 +15,4 @@ - diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 24abb6dab6..043ba39f5a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -723,11 +723,7 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile(); // temporarily for new version - public final CommonPreference PRECISE_ROUTING_MODE = new BooleanPreference("precise_routing_mode", false).makeProfile(); - public final CommonPreference OPTIMAL_ROUTE_MODE = new BooleanPreference("optimal_route_mode", true).makeProfile(); - { - OPTIMAL_ROUTE_MODE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false); - } + public final CommonPreference DISABLE_COMPLEX_ROUTING = new BooleanPreference("disable_complex_routing", false).makeGlobal(); public final OsmandPreference SHOW_TRAFFIC_WARNINGS = new BooleanPreference("show_traffic_warnings", true).makeProfile().cache(); public final OsmandPreference SHOW_CAMERAS = new BooleanPreference("show_cameras", true).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 816a5e1495..f2ff828bf5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -64,7 +64,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { settings = getMyApplication().getSettings(); registerBooleanPreference(settings.FAST_ROUTE_MODE, screen); - registerBooleanPreference(settings.PRECISE_ROUTING_MODE, screen); registerBooleanPreference(settings.SNAP_TO_ROAD, screen); registerBooleanPreference(settings.USE_COMPASS_IN_NAVIGATION, screen); diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index c43bf89975..db3df680a3 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -37,6 +37,8 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { R.string.trace_rendering, R.string.trace_rendering_descr); cat.addPreference(dbg); + cat.addPreference(createCheckBoxPreference(settings.DISABLE_COMPLEX_ROUTING, R.string.disable_complex_routing, R.string.disable_complex_routing_descr)); + cat.addPreference(createCheckBoxPreference(settings.USE_MAGNETIC_FIELD_SENSOR_COMPASS, R.string.use_magnetic_sensor, R.string.use_magnetic_sensor_descr)); Preference pref = new Preference(this); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index d8ee112184..259686b41e 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -13,6 +13,7 @@ import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -390,26 +391,24 @@ public class RouteProvider { } else { return applicationModeNotSupported(params); } - // order matters - List specs = new ArrayList(); + Map paramsR = new LinkedHashMap(); if (!settings.FAST_ROUTE_MODE.getModeValue(params.mode)) { - specs.add(GeneralRouter.USE_SHORTEST_WAY); + paramsR.put(GeneralRouter.USE_SHORTEST_WAY, "true"); } if(settings.AVOID_FERRIES.getModeValue(params.mode)){ - specs.add(GeneralRouter.AVOID_FERRIES); + paramsR.put(GeneralRouter.AVOID_FERRIES, "true"); } if(settings.AVOID_TOLL_ROADS.getModeValue(params.mode)){ - specs.add(GeneralRouter.AVOID_TOLL); + paramsR.put(GeneralRouter.AVOID_TOLL, "true"); } if(settings.AVOID_MOTORWAY.getModeValue(params.mode)){ - specs.add(GeneralRouter.AVOID_MOTORWAY); + paramsR.put(GeneralRouter.AVOID_MOTORWAY, "true"); } else if(settings.PREFER_MOTORWAYS.getModeValue(params.mode)){ - specs.add(GeneralRouter.PREFER_MOTORWAYS); + paramsR.put(GeneralRouter.PREFER_MOTORWAYS, "true"); } if(settings.AVOID_UNPAVED_ROADS.getModeValue(params.mode)){ - specs.add(GeneralRouter.AVOID_UNPAVED); + paramsR.put(GeneralRouter.AVOID_UNPAVED, "true"); } - String[] specialization = specs.toArray(new String[specs.size()]); float mb = (1 << 20); Runtime rt = Runtime.getRuntime(); // make visible @@ -418,13 +417,21 @@ public class RouteProvider { RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ? params.start.getBearing() / 180d * Math.PI : null, - memoryLimit, specialization); - RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, - params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) ? - RouteCalculationMode.COMPLEX : RouteCalculationMode.NORMAL); + memoryLimit, paramsR); + boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get(); + RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, + RouteCalculationMode.NORMAL); + RoutingContext complexCtx = null; + if(complex) { + complexCtx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, + RouteCalculationMode.COMPLEX); + complexCtx.calculationProgress = params.calculationProgress; + } + ctx.leftSideNavigation = params.leftSide; ctx.calculationProgress = params.calculationProgress; if(params.previousToRecalculate != null) { - ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute(); + // not used any more + // ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute(); } LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude()); LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude()); @@ -433,8 +440,20 @@ public class RouteProvider { inters = new ArrayList(params.intermediates); } try { - ctx.leftSideNavigation = params.leftSide; - List result = router.searchRoute(ctx, st, en, inters); + List result ; + if(complexCtx != null) { + try { + result = router.searchRoute(complexCtx, st, en, inters); + // discard ctx and replace with calculated + ctx = complexCtx; + } catch(RuntimeException e) { + params.ctx.showToastMessage(R.string.complex_route_calculation_failed, e.getMessage()); + result = router.searchRoute(ctx, st, en, inters); + } + } else { + result = router.searchRoute(ctx, st, en, inters); + } + if(result == null || result.isEmpty()) { if(ctx.calculationProgress.segmentNotFound == 0) { return new RouteCalculationResult(params.ctx.getString(R.string.starting_point_too_far));