|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2008 Navit Team |
22 | * Copyright (C) 2005-2008 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
276 | struct route_path *oldpath, struct route_info *pos, |
295 | struct route_path *oldpath, struct route_info *pos, |
277 | struct route_info *dst, struct vehicleprofile *profile); |
296 | struct route_info *dst, struct vehicleprofile *profile); |
278 | static void route_process_street_graph(struct route_graph *this, |
297 | static void route_process_street_graph(struct route_graph *this, |
279 | struct item *item, struct vehicleprofile *profile); |
298 | struct item *item, struct vehicleprofile *profile); |
280 | //static void route_graph_destroy(struct route_graph *this); |
299 | //static void route_graph_destroy(struct route_graph *this); |
281 | static void route_path_update(struct route *this, int cancel, int async); |
300 | void route_path_update(struct route *this, int cancel, int async); |
282 | static int route_time_seg(struct vehicleprofile *profile, |
301 | static int route_time_seg(struct vehicleprofile *profile, |
283 | struct route_segment_data *over, struct route_traffic_distortion *dist); |
302 | struct route_segment_data *over, struct route_traffic_distortion *dist); |
284 | static void route_graph_flood(struct route_graph *this, struct route_info *dst, |
303 | static void route_graph_flood(struct route_graph *this, struct route_info *dst, |
285 | struct vehicleprofile *profile, struct callback *cb); |
304 | struct vehicleprofile *profile, struct callback *cb); |
286 | static void route_graph_reset(struct route_graph *this); |
305 | static void route_graph_reset(struct route_graph *this); |
… | |
… | |
778 | } |
797 | } |
779 | } |
798 | } |
780 | else |
799 | else |
781 | { |
800 | { |
782 | route_status.u.num = route_status_not_found; |
801 | route_status.u.num = route_status_not_found; |
783 | dbg(0, "try harder\n"); |
802 | // dbg(0, "try harder\n"); |
784 | // Try to rebuild the graph with smaller roads |
803 | // Try to rebuild the graph with smaller roads |
785 | if (this->try_harder == 0) |
804 | if (this->try_harder == 0) |
786 | { |
805 | { |
787 | this->try_harder = 1; |
806 | this->try_harder = 1; |
788 | route_graph_destroy(this->graph); |
807 | route_graph_destroy(this->graph); |
… | |
… | |
803 | * @attention For this to work the route graph has to be destroyed if the route's |
822 | * @attention For this to work the route graph has to be destroyed if the route's |
804 | * @attention destination is changed somewhere! |
823 | * @attention destination is changed somewhere! |
805 | * |
824 | * |
806 | * @param this The route to update |
825 | * @param this The route to update |
807 | */ |
826 | */ |
808 | static void route_path_update(struct route *this, int cancel, int async) |
827 | void route_path_update(struct route *this, int cancel, int async) |
809 | { |
828 | { |
810 | //dbg(1, "enter %d\n", cancel); |
829 | //dbg(1, "enter %d\n", cancel); |
811 | if (!this->pos || !this->destinations) |
830 | if (!this->pos || !this->destinations) |
812 | { |
831 | { |
813 | //dbg(1, "destroy\n"); |
832 | //dbg(1, "destroy\n"); |
… | |
… | |
2017 | * @param item The item to add |
2036 | * @param item The item to add |
2018 | */ |
2037 | */ |
2019 | static void route_process_traffic_distortion(struct route_graph *this, |
2038 | static void route_process_traffic_distortion(struct route_graph *this, |
2020 | struct item *item) |
2039 | struct item *item) |
2021 | { |
2040 | { |
|
|
2041 | //dbg(0,"EEnter\n"); |
|
|
2042 | |
2022 | struct route_graph_point *s_pnt, *e_pnt; |
2043 | struct route_graph_point *s_pnt, *e_pnt; |
2023 | struct coord c, l; |
2044 | struct coord c, l; |
2024 | struct attr delay_attr, maxspeed_attr; |
2045 | struct attr delay_attr, maxspeed_attr; |
2025 | struct route_graph_segment_data data; |
2046 | struct route_graph_segment_data data; |
2026 | |
2047 | |
… | |
… | |
2035 | s_pnt = route_graph_add_point(this, &l); |
2056 | s_pnt = route_graph_add_point(this, &l); |
2036 | while (item_coord_get(item, &c, 1)) |
2057 | while (item_coord_get(item, &c, 1)) |
2037 | { |
2058 | { |
2038 | l = c; |
2059 | l = c; |
2039 | } |
2060 | } |
|
|
2061 | |
2040 | e_pnt = route_graph_add_point(this, &l); |
2062 | e_pnt = route_graph_add_point(this, &l); |
2041 | s_pnt->flags |= RP_TRAFFIC_DISTORTION; |
2063 | s_pnt->flags |= RP_TRAFFIC_DISTORTION; |
2042 | e_pnt->flags |= RP_TRAFFIC_DISTORTION; |
2064 | e_pnt->flags |= RP_TRAFFIC_DISTORTION; |
|
|
2065 | |
2043 | if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) |
2066 | if (item_attr_get(item, attr_maxspeed, &maxspeed_attr)) |
2044 | { |
2067 | { |
2045 | data.flags |= AF_SPEED_LIMIT; |
2068 | data.flags |= AF_SPEED_LIMIT; |
2046 | data.maxspeed = maxspeed_attr.u.num; |
2069 | data.maxspeed = maxspeed_attr.u.num; |
2047 | } |
2070 | } |
|
|
2071 | |
2048 | if (item_attr_get(item, attr_delay, &delay_attr)) |
2072 | if (item_attr_get(item, attr_delay, &delay_attr)) |
|
|
2073 | { |
2049 | data.len = delay_attr.u.num; |
2074 | data.len = delay_attr.u.num; |
|
|
2075 | } |
|
|
2076 | //dbg(0,"add traffic distortion segment, speed=%d\n", data.maxspeed); |
2050 | route_graph_add_segment(this, s_pnt, e_pnt, &data); |
2077 | route_graph_add_segment(this, s_pnt, e_pnt, &data); |
2051 | } |
2078 | } |
2052 | } |
2079 | } |
2053 | |
2080 | |
2054 | /** |
2081 | /** |
… | |
… | |
2861 | route_graph_build_done(rg, 0); |
2888 | route_graph_build_done(rg, 0); |
2862 | return; |
2889 | return; |
2863 | } |
2890 | } |
2864 | } |
2891 | } |
2865 | if (item->type == type_traffic_distortion) |
2892 | if (item->type == type_traffic_distortion) |
|
|
2893 | { |
2866 | route_process_traffic_distortion(rg, item); |
2894 | route_process_traffic_distortion(rg, item); |
|
|
2895 | } |
2867 | else if (item->type == type_street_turn_restriction_no || item->type |
2896 | else if (item->type == type_street_turn_restriction_no || item->type |
2868 | == type_street_turn_restriction_only) |
2897 | == type_street_turn_restriction_only) |
2869 | route_process_turn_restriction(rg, item); |
2898 | route_process_turn_restriction(rg, item); |
2870 | else |
2899 | else |
2871 | route_process_street_graph(rg, item, profile); |
2900 | route_process_street_graph(rg, item, profile); |
… | |
… | |
2900 | |
2929 | |
2901 | ret->sel = route_calc_selection(c, count, try_harder); |
2930 | ret->sel = route_calc_selection(c, count, try_harder); |
2902 | ret->h = mapset_open(ms); |
2931 | ret->h = mapset_open(ms); |
2903 | ret->done_cb = done_cb; |
2932 | ret->done_cb = done_cb; |
2904 | ret->busy = 1; |
2933 | ret->busy = 1; |
|
|
2934 | |
2905 | if (route_graph_build_next_map(ret)) |
2935 | if (route_graph_build_next_map(ret)) |
2906 | { |
2936 | { |
|
|
2937 | |
|
|
2938 | // ------ xxxxxx ---- |
2907 | if (async) |
2939 | if (async) |
2908 | { |
2940 | { |
2909 | ret->idle_cb = callback_new_2( |
|
|
2910 | callback_cast(route_graph_build_idle), ret, profile); |
2941 | ret->idle_cb = callback_new_2(callback_cast(route_graph_build_idle), ret, profile); |
2911 | ret->idle_ev = event_add_idle(50, ret->idle_cb); |
2942 | ret->idle_ev = event_add_idle(50, ret->idle_cb); |
2912 | } |
2943 | } |
2913 | } |
2944 | } |
2914 | else |
2945 | else |
|
|
2946 | { |
2915 | route_graph_build_done(ret, 0); |
2947 | route_graph_build_done(ret, 0); |
|
|
2948 | } |
2916 | |
2949 | |
2917 | return ret; |
2950 | return ret; |
2918 | } |
2951 | } |
2919 | |
2952 | |
2920 | static void route_graph_update_done(struct route *this, struct callback *cb) |
2953 | static void route_graph_update_done(struct route *this, struct callback *cb) |
… | |
… | |
2953 | { |
2986 | { |
2954 | struct route_info *dst = tmp->data; |
2987 | struct route_info *dst = tmp->data; |
2955 | c[i++] = dst->c; |
2988 | c[i++] = dst->c; |
2956 | tmp = g_list_next(tmp); |
2989 | tmp = g_list_next(tmp); |
2957 | } |
2990 | } |
|
|
2991 | |
2958 | this->graph = route_graph_build(this->ms, c, i, this->route_graph_done_cb, |
2992 | this->graph = route_graph_build(this->ms, c, i, this->route_graph_done_cb, |
2959 | async, this->vehicleprofile, this->try_harder); |
2993 | async, this->vehicleprofile, this->try_harder); |
|
|
2994 | |
2960 | if (!async) |
2995 | if (!async) |
2961 | { |
2996 | { |
2962 | while (this->graph->busy) |
2997 | while (this->graph->busy) |
|
|
2998 | { |
2963 | route_graph_build_idle(this->graph, this->vehicleprofile); |
2999 | route_graph_build_idle(this->graph, this->vehicleprofile); |
|
|
3000 | } |
2964 | } |
3001 | } |
2965 | } |
3002 | } |
2966 | |
3003 | |
2967 | /** |
3004 | /** |
2968 | * @brief Gets street data for an item |
3005 | * @brief Gets street data for an item |
… | |
… | |
2979 | const int step = 128; |
3016 | const int step = 128; |
2980 | int c; |
3017 | int c; |
2981 | |
3018 | |
2982 | do |
3019 | do |
2983 | { |
3020 | { |
2984 | ret1 = g_realloc( |
3021 | ret1 = g_realloc(ret, sizeof(struct street_data) + (count + step) * sizeof(struct coord)); |
2985 | ret, |
|
|
2986 | sizeof(struct street_data) + (count + step) |
|
|
2987 | * sizeof(struct coord)); |
|
|
2988 | if (!ret1) |
3022 | if (!ret1) |
2989 | { |
3023 | { |
2990 | if (ret) |
3024 | if (ret) |
2991 | g_free(ret); |
3025 | g_free(ret); |
2992 | return NULL; |
3026 | return NULL; |
… | |
… | |
2995 | c = item_coord_get(item, &ret->c[count], step); |
3029 | c = item_coord_get(item, &ret->c[count], step); |
2996 | count += c; |
3030 | count += c; |
2997 | } |
3031 | } |
2998 | while (c && c == step); |
3032 | while (c && c == step); |
2999 | |
3033 | |
3000 | ret1 = g_realloc(ret, |
|
|
3001 | sizeof(struct street_data) + count * sizeof(struct coord)); |
3034 | ret1 = g_realloc(ret, sizeof(struct street_data) + count * sizeof(struct coord)); |
3002 | if (ret1) |
3035 | if (ret1) |
3003 | ret = ret1; |
3036 | ret = ret1; |
3004 | ret->item = *item; |
3037 | ret->item = *item; |
3005 | ret->count = count; |
3038 | ret->count = count; |
3006 | if (item_attr_get(item, attr_flags, &flags_attr)) |
3039 | if (item_attr_get(item, attr_flags, &flags_attr)) |