|
|
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-2009 Navit Team |
22 | * Copyright (C) 2005-2009 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 |
… | |
… | |
64 | #include "util.h" |
83 | #include "util.h" |
65 | #include "messages.h" |
84 | #include "messages.h" |
66 | #include "vehicleprofile.h" |
85 | #include "vehicleprofile.h" |
67 | #include "sunriset.h" |
86 | #include "sunriset.h" |
68 | #include "bookmarks.h" |
87 | #include "bookmarks.h" |
|
|
88 | #include "map.h" |
69 | #ifdef HAVE_API_WIN32_BASE |
89 | #ifdef HAVE_API_WIN32_BASE |
70 | #include <windows.h> |
90 | #include <windows.h> |
71 | #include "util.h" |
91 | #include "util.h" |
72 | #endif |
92 | #endif |
73 | #ifdef HAVE_API_WIN32_CE |
93 | #ifdef HAVE_API_WIN32_CE |
… | |
… | |
77 | /** |
97 | /** |
78 | * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object |
98 | * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object |
79 | * @{ |
99 | * @{ |
80 | */ |
100 | */ |
81 | |
101 | |
82 | |
|
|
83 | struct gui *main_loop_gui; |
102 | struct gui *main_loop_gui; |
84 | |
103 | |
85 | struct attr_iter { |
104 | struct attr_iter |
|
|
105 | { |
86 | union { |
106 | union |
|
|
107 | { |
87 | GList *list; |
108 | GList *list; |
88 | struct mapset_handle *mapset_handle; |
109 | struct mapset_handle *mapset_handle; |
89 | } u; |
110 | } u; |
90 | }; |
111 | }; |
91 | |
112 | |
92 | static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv); |
113 | static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv); |
93 | static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt); |
114 | static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt); |
94 | static int navit_add_vehicle(struct navit *this_, struct vehicle *v); |
|
|
95 | static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init); |
115 | static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init); |
96 | static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir); |
116 | static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir); |
97 | static void navit_set_cursors(struct navit *this_); |
|
|
98 | static void navit_cmd_zoom_to_route(struct navit *this); |
117 | static void navit_cmd_zoom_to_route(struct navit *this); |
99 | static void navit_cmd_set_center_cursor(struct navit *this_); |
118 | static void navit_cmd_set_center_cursor(struct navit *this_); |
100 | static void navit_cmd_announcer_toggle(struct navit *this_); |
119 | static void navit_cmd_announcer_toggle(struct navit *this_); |
101 | static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv); |
120 | static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv); |
102 | |
121 | |
103 | int allow_gui_internal = 0; |
122 | int allow_gui_internal = 0; |
104 | int routing_mode = 0; |
123 | int routing_mode = 0; |
105 | int MYSTERY_SPEED = 2; |
124 | int MYSTERY_SPEED = 2; |
106 | int offline_search_filter_duplicates = 0; |
125 | int offline_search_filter_duplicates = 0; |
107 | int offline_search_break_searching = 0; |
126 | int offline_search_break_searching = 0; |
|
|
127 | char *navit_maps_dir; |
|
|
128 | int cancel_drawing_global = 0; |
|
|
129 | int global_speak_streetnames = 1; |
|
|
130 | int allow_large_mapfiles = 1; // allow the use of large (>2GB) mapfiles // -> value unused for now |
|
|
131 | int cache_size_file = 1024 * 1024 * 10; // default value was: 20971520 (~20 MB) |
|
|
132 | int draw_polylines_fast = 0; // default: 0 |
|
|
133 | int limit_order_corrected = 4; // remain at this order level for drawing streets etc. |
|
|
134 | int global_search_street_size_factor = 1; // make search radius for streets bigger |
108 | |
135 | |
109 | struct navit *global_navit; |
|
|
110 | |
|
|
111 | void |
|
|
112 | navit_add_mapset(struct navit *this_, struct mapset *ms) |
136 | void navit_add_mapset(struct navit *this_, struct mapset *ms) |
113 | { |
137 | { |
114 | //dbg(0,"EEnter\n"); |
138 | ////DBG dbg(0,"EEnter\n"); |
115 | this_->mapsets = g_list_append(this_->mapsets, ms); |
139 | this_->mapsets = g_list_append(this_->mapsets, ms); |
116 | } |
140 | } |
117 | |
141 | |
118 | struct mapset * |
142 | struct mapset * |
119 | navit_get_mapset(struct navit *this_) |
143 | navit_get_mapset(struct navit *this_) |
120 | { |
144 | { |
121 | //dbg(0,"EEnter\n"); |
145 | ////DBG dbg(0,"EEnter\n"); |
122 | if(this_->mapsets){ |
146 | if (this_->mapsets) |
|
|
147 | { |
123 | return this_->mapsets->data; |
148 | return this_->mapsets->data; |
124 | } else { |
149 | } |
|
|
150 | else |
|
|
151 | { |
125 | dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n"); |
152 | //DBG dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n"); |
126 | } |
153 | } |
127 | return NULL; |
154 | return NULL; |
128 | } |
155 | } |
129 | |
156 | |
130 | struct tracking * |
157 | struct tracking * |
131 | navit_get_tracking(struct navit *this_) |
158 | navit_get_tracking(struct navit *this_) |
132 | { |
159 | { |
133 | //dbg(0,"EEnter\n"); |
160 | ////DBG dbg(0,"EEnter\n"); |
134 | return this_->tracking; |
161 | return this_->tracking; |
135 | } |
162 | } |
136 | |
163 | |
137 | /** |
164 | /** |
138 | * @brief Get the user data directory. |
165 | * @brief Get the user data directory. |
… | |
… | |
143 | * returns the directory used to store user data files (center.txt, |
170 | * returns the directory used to store user data files (center.txt, |
144 | * destination.txt, bookmark.txt, ...) |
171 | * destination.txt, bookmark.txt, ...) |
145 | * |
172 | * |
146 | */ |
173 | */ |
147 | char* |
174 | char* |
148 | navit_get_user_data_directory(int create) { |
175 | navit_get_user_data_directory(int create) |
|
|
176 | { |
149 | //dbg(0,"EEnter\n"); |
177 | ////DBG dbg(0,"EEnter\n"); |
150 | char *dir; |
178 | char *dir; |
151 | dir = getenv("NAVIT_USER_DATADIR"); |
179 | dir = getenv("NAVIT_USER_DATADIR"); |
152 | if (create && !file_exists(dir)) { |
180 | if (create && !file_exists(dir)) |
|
|
181 | { |
153 | dbg(0,"creating dir %s\n", dir); |
182 | //DBG dbg(0, "creating dir %s\n", dir); |
154 | if (file_mkdir(dir,0)) { |
183 | if (file_mkdir(dir, 0)) |
|
|
184 | { |
155 | dbg(0,"failed creating dir %s\n", dir); |
185 | //DBG dbg(0, "failed creating dir %s\n", dir); |
156 | return NULL; |
186 | return NULL; |
157 | } |
187 | } |
158 | } |
188 | } |
159 | return dir; |
189 | return dir; |
160 | } /* end: navit_get_user_data_directory(gboolean create) */ |
190 | } /* end: navit_get_user_data_directory(gboolean create) */ |
161 | |
191 | |
162 | |
|
|
163 | void |
|
|
164 | navit_draw_async(struct navit *this_, int async) |
192 | void navit_draw_async(struct navit *this_, int async) |
165 | { |
193 | { |
166 | //dbg(0,"EEnter this_->blocked=%d\n",this_->blocked); |
194 | //DBG dbg(0,"EEnter this_->blocked=%d\n",this_->blocked); |
167 | if (this_->blocked) |
195 | if (this_->blocked) |
168 | { |
196 | { |
169 | this_->blocked |= 2; |
197 | this_->blocked |= 2; |
170 | //dbg(0,"set this_->blocked=%d\n",this_->blocked); |
198 | ////DBG dbg(0,"set this_->blocked=%d\n",this_->blocked); |
171 | return; |
199 | return; |
172 | } |
200 | } |
173 | transform_setup_source_rect(this_->trans); |
201 | transform_setup_source_rect(this_->trans); |
174 | graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1); |
202 | graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags | 1); |
175 | } |
203 | } |
176 | |
204 | |
177 | void |
|
|
178 | navit_draw(struct navit *this_) |
205 | void navit_draw(struct navit *this_) |
179 | { |
206 | { |
180 | //dbg(0,"EEnter this_->ready=%d\n",this_->ready); |
207 | ////DBG dbg(0,"EEnter this_->ready=%d\n",this_->ready); |
181 | if (this_->ready == 3) |
208 | if (this_->ready == 3) |
182 | { |
209 | { |
183 | //dbg(0,"navit_draw_async_001\n"); |
210 | ////DBG dbg(0,"navit_draw_async_001\n"); |
184 | navit_draw_async(this_, 0); |
211 | navit_draw_async(this_, 0); |
185 | } |
212 | } |
186 | } |
213 | } |
187 | |
214 | |
188 | int |
|
|
189 | navit_get_ready(struct navit *this_) |
215 | int navit_get_ready(struct navit *this_) |
190 | { |
216 | { |
191 | //dbg(0,"EEnter\n"); |
217 | ////DBG dbg(0,"EEnter\n"); |
192 | return this_->ready; |
218 | return this_->ready; |
193 | } |
219 | } |
194 | |
220 | |
195 | |
|
|
196 | |
|
|
197 | void |
|
|
198 | navit_draw_displaylist(struct navit *this_) |
221 | void navit_draw_displaylist(struct navit *this_) |
199 | { |
222 | { |
200 | //dbg(0,"EEnter\n"); |
223 | ////DBG dbg(0,"EEnter\n"); |
201 | if (this_->ready == 3) |
224 | if (this_->ready == 3) |
202 | { |
225 | { |
203 | // dbg(0,"call graphics_displaylist_draw 2") |
226 | // //DBG dbg(0,"call graphics_displaylist_draw 2") |
204 | graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1); |
227 | graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags | 1); |
205 | } |
228 | } |
206 | } |
229 | } |
207 | |
230 | |
208 | static void |
|
|
209 | navit_map_progress(struct navit *this_) |
231 | static void navit_map_progress(struct navit *this_) |
210 | { |
232 | { |
211 | //dbg(0,"EEnter\n"); |
233 | ////DBG dbg(0,"EEnter\n"); |
212 | struct map *map; |
234 | struct map *map; |
213 | struct mapset *ms; |
235 | struct mapset *ms; |
214 | struct mapset_handle *msh; |
236 | struct mapset_handle *msh; |
215 | struct attr attr; |
237 | struct attr attr; |
216 | struct point p; |
238 | struct point p; |
217 | if (this_->ready != 3) |
239 | if (this_->ready != 3) |
218 | return; |
240 | return; |
219 | p.x=10; |
241 | p.x = 10; |
220 | p.y=32; |
242 | p.y = 32; |
221 | |
243 | |
222 | ms=this_->mapsets->data; |
244 | ms = this_->mapsets->data; |
223 | msh=mapset_open(ms); |
245 | msh = mapset_open(ms); |
224 | while (msh && (map=mapset_next(msh, 0))) { |
246 | while (msh && (map = mapset_next(msh, 0))) |
|
|
247 | { |
225 | if (map_get_attr(map, attr_progress, &attr, NULL)) { |
248 | if (map_get_attr(map, attr_progress, &attr, NULL)) |
|
|
249 | { |
226 | char *str=g_strdup_printf("%s ",attr.u.str); |
250 | char *str = g_strdup_printf("%s ", attr.u.str); |
227 | graphics_draw_mode(this_->gra, draw_mode_begin); |
251 | graphics_draw_mode(this_->gra, draw_mode_begin); |
228 | graphics_draw_text_std(this_->gra, 16, str, &p); |
252 | graphics_draw_text_std(this_->gra, 16, str, &p); |
229 | g_free(str); |
253 | g_free(str); |
230 | p.y+=32; |
254 | p.y += 32; |
231 | graphics_draw_mode(this_->gra, draw_mode_end); |
255 | graphics_draw_mode(this_->gra, draw_mode_end); |
232 | } |
256 | } |
233 | } |
257 | } |
234 | mapset_close(msh); |
258 | mapset_close(msh); |
235 | } |
259 | } |
236 | |
260 | |
237 | static void |
|
|
238 | navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr) |
261 | static void navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr) |
239 | { |
262 | { |
240 | //dbg(0,"EEnter\n"); |
263 | ////DBG dbg(0,"EEnter\n"); |
241 | int updated; |
264 | int updated; |
242 | |
265 | |
243 | if ((this_->route)&&(this_->route->route_status_was_updated == 1)) |
266 | if ((this_->route) && (this_->route->route_status_was_updated == 1)) |
244 | { |
267 | { |
245 | this_->route->route_status_was_updated=0; |
268 | this_->route->route_status_was_updated = 0; |
246 | // send route_status to java |
269 | // send route_status to java |
247 | #ifdef HAVE_API_ANDROID |
270 | #ifdef HAVE_API_ANDROID |
248 | android_return_generic_int(1, this_->route->route_status); |
271 | android_return_generic_int(1, this_->route->route_status); |
249 | #endif |
272 | #endif |
250 | } |
273 | } |
251 | |
274 | |
252 | if (attr->type != attr_route_status) |
275 | if (attr->type != attr_route_status) |
253 | { |
276 | { |
254 | //dbg(0,"ret 1\n"); |
277 | ////DBG dbg(0,"ret 1\n"); |
255 | return; |
278 | return; |
256 | } |
279 | } |
257 | updated=attr->u.num; |
280 | updated = attr->u.num; |
258 | //dbg(0,"updated=%d\n", updated); |
281 | ////DBG dbg(0,"updated=%d\n", updated); |
259 | if (this_->ready != 3) |
282 | if (this_->ready != 3) |
260 | { |
283 | { |
261 | //dbg(0,"ret 2\n"); |
284 | ////DBG dbg(0,"ret 2\n"); |
262 | return; |
285 | return; |
263 | } |
286 | } |
264 | if (updated != route_status_path_done_new) |
287 | if (updated != route_status_path_done_new) |
265 | { |
288 | { |
266 | //dbg(0,"ret 3\n"); |
289 | ////DBG dbg(0,"ret 3\n"); |
267 | return; |
290 | return; |
268 | } |
291 | } |
269 | if (this_->vehicle) |
292 | if (this_->vehicle) |
270 | { |
293 | { |
271 | if (this_->vehicle->follow_curr == 1) |
294 | if (this_->vehicle->follow_curr == 1) |
272 | { |
295 | { |
273 | //dbg(0,"ret 4\n"); |
296 | ////DBG dbg(0,"ret 4\n"); |
274 | //dbg(0,"disabled -> we want redraw!!\n"); |
297 | ////DBG dbg(0,"disabled -> we want redraw!!\n"); |
275 | // return; |
298 | // return; |
276 | } |
299 | } |
277 | if (this_->vehicle->follow_curr <= this_->vehicle->follow) |
300 | if (this_->vehicle->follow_curr <= this_->vehicle->follow) |
278 | { |
301 | { |
279 | this_->vehicle->follow_curr=this_->vehicle->follow; |
302 | this_->vehicle->follow_curr = this_->vehicle->follow; |
280 | } |
|
|
281 | } |
303 | } |
|
|
304 | } |
282 | //dbg(0,"draw s*\n"); |
305 | ////DBG dbg(0,"draw s*\n"); |
283 | navit_draw(this_); |
306 | navit_draw(this_); |
284 | //dbg(0,"draw e*\n"); |
307 | ////DBG dbg(0,"draw e*\n"); |
285 | } |
308 | } |
286 | |
309 | |
287 | void |
|
|
288 | navit_handle_resize(struct navit *this_, int w, int h) |
310 | void navit_handle_resize(struct navit *this_, int w, int h) |
289 | { |
311 | { |
290 | //dbg(0,"EEnter\n"); |
312 | //DBG dbg(0,"EEnter\n"); |
291 | struct map_selection sel; |
313 | struct map_selection sel; |
292 | int callback=(this_->ready == 1); |
314 | int callback = (this_->ready == 1); |
293 | //dbg(0,"pre this_->ready=%d\n",this_->ready); |
315 | ////DBG dbg(0,"pre this_->ready=%d\n",this_->ready); |
294 | this_->ready |= 2; |
316 | this_->ready |= 2; |
295 | //dbg(0,"set this_->ready=%d\n",this_->ready); |
317 | ////DBG dbg(0,"set this_->ready=%d\n",this_->ready); |
296 | memset(&sel, 0, sizeof(sel)); |
318 | memset(&sel, 0, sizeof(sel)); |
297 | this_->w=w; |
319 | this_->w = w; |
298 | this_->h=h; |
320 | this_->h = h; |
299 | sel.u.p_rect.rl.x=w; |
321 | sel.u.p_rect.rl.x = w; |
300 | sel.u.p_rect.rl.y=h; |
322 | sel.u.p_rect.rl.y = h; |
301 | transform_set_screen_selection(this_->trans, &sel); |
323 | transform_set_screen_selection(this_->trans, &sel); |
302 | graphics_init(this_->gra); |
324 | graphics_init(this_->gra); |
303 | graphics_set_rect(this_->gra, &sel.u.p_rect); |
325 | graphics_set_rect(this_->gra, &sel.u.p_rect); |
304 | if (callback) |
326 | if (callback) |
|
|
327 | { |
|
|
328 | //DBG dbg(0,"callback do\n"); |
305 | callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_); |
329 | callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_); |
|
|
330 | } |
306 | if (this_->ready == 3) |
331 | if (this_->ready == 3) |
307 | { |
332 | { |
308 | //dbg(0,"navit_draw_async_002\n"); |
333 | //DBG dbg(0,"navit_draw_async_002\n"); |
309 | navit_draw_async(this_, 1); |
334 | navit_draw_async(this_, 1); |
310 | } |
335 | } |
311 | } |
336 | } |
312 | |
337 | |
313 | static void |
|
|
314 | navit_resize(void *data, int w, int h) |
338 | void navit_resize(void *data, int w, int h) |
315 | { |
339 | { |
316 | //dbg(0,"EEnter\n"); |
340 | //DBG dbg(0,"EEnter %p\n", data); |
317 | struct navit *this=data; |
341 | struct navit *this = data; |
318 | if (!this->ignore_graphics_events) |
342 | if (!this->ignore_graphics_events) |
|
|
343 | { |
|
|
344 | //DBG dbg(0,"11\n"); |
319 | navit_handle_resize(this, w, h); |
345 | navit_handle_resize(this, w, h); |
|
|
346 | } |
320 | } |
347 | } |
321 | |
348 | |
322 | int |
|
|
323 | navit_get_width(struct navit *this_) |
349 | int navit_get_width(struct navit *this_) |
324 | { |
350 | { |
325 | //dbg(0,"EEnter\n"); |
351 | ////DBG dbg(0,"EEnter\n"); |
326 | return this_->w; |
352 | return this_->w; |
327 | } |
353 | } |
328 | |
354 | |
329 | |
|
|
330 | int |
|
|
331 | navit_get_height(struct navit *this_) |
355 | int navit_get_height(struct navit *this_) |
332 | { |
356 | { |
333 | //dbg(0,"EEnter\n"); |
357 | ////DBG dbg(0,"EEnter\n"); |
334 | return this_->h; |
358 | return this_->h; |
335 | } |
359 | } |
336 | |
360 | |
337 | static void |
|
|
338 | navit_popup(void *data) |
361 | static void navit_popup(void *data) |
339 | { |
362 | { |
340 | //dbg(0,"EEnter\n"); |
363 | ////DBG dbg(0,"EEnter\n"); |
341 | struct navit *this_=data; |
364 | struct navit *this_ = data; |
342 | popup(this_, 1, &this_->pressed); |
365 | popup(this_, 1, &this_->pressed); |
343 | this_->button_timeout=NULL; |
366 | this_->button_timeout = NULL; |
344 | this_->popped=1; |
367 | this_->popped = 1; |
345 | } |
368 | } |
346 | |
369 | |
347 | |
|
|
348 | int |
|
|
349 | navit_ignore_button(struct navit *this_) |
370 | int navit_ignore_button(struct navit *this_) |
350 | { |
371 | { |
351 | //dbg(0,"EEnter\n"); |
372 | ////DBG dbg(0,"EEnter\n"); |
352 | if (this_->ignore_button) |
373 | if (this_->ignore_button) |
353 | return 1; |
374 | return 1; |
354 | this_->ignore_button=1; |
375 | this_->ignore_button = 1; |
355 | return 0; |
376 | return 0; |
356 | } |
377 | } |
357 | |
378 | |
358 | void |
|
|
359 | navit_ignore_graphics_events(struct navit *this_, int ignore) |
379 | void navit_ignore_graphics_events(struct navit *this_, int ignore) |
360 | { |
380 | { |
361 | //dbg(0,"EEnter\n"); |
381 | ////DBG dbg(0,"EEnter\n"); |
362 | this_->ignore_graphics_events=ignore; |
382 | this_->ignore_graphics_events = ignore; |
363 | } |
383 | } |
364 | |
384 | |
365 | static void |
|
|
366 | update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot) |
385 | static void update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot) |
367 | { |
386 | { |
368 | //dbg(0,"EEnter\n"); |
387 | ////DBG dbg(0,"EEnter\n"); |
369 | struct coord co,cn; |
388 | struct coord co, cn; |
370 | struct coord c,*cp; |
389 | struct coord c, *cp; |
371 | int yaw; |
390 | int yaw; |
372 | double angleo,anglen; |
391 | double angleo, anglen; |
373 | |
392 | |
374 | if (!transform_reverse(tr, old, &co)) |
393 | if (!transform_reverse(tr, old, &co)) |
375 | return; |
394 | return; |
376 | if (rot) { |
395 | if (rot) |
|
|
396 | { |
377 | angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI; |
397 | angleo = atan2(old->y - rot->y, old->x - rot->x) * 180 / M_PI; |
378 | anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI; |
398 | anglen = atan2(new->y - rot->y, new->x - rot->x) * 180 / M_PI; |
379 | yaw=transform_get_yaw(tr)+angleo-anglen; |
399 | yaw = transform_get_yaw(tr) + angleo - anglen; |
380 | transform_set_yaw(tr, yaw % 360); |
400 | transform_set_yaw(tr, yaw % 360); |
381 | } |
401 | } |
382 | if (!transform_reverse(tr, new, &cn)) |
402 | if (!transform_reverse(tr, new, &cn)) |
383 | return; |
403 | return; |
384 | cp=transform_get_center(tr); |
404 | cp = transform_get_center(tr); |
385 | c.x=cp->x+co.x-cn.x; |
405 | c.x = cp->x + co.x - cn.x; |
386 | c.y=cp->y+co.y-cn.y; |
406 | c.y = cp->y + co.y - cn.y; |
387 | dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y); |
407 | // dbg(1, "from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y); |
388 | transform_set_center(tr, &c); |
408 | transform_set_center(tr, &c); |
389 | } |
409 | } |
390 | |
410 | |
391 | void |
|
|
392 | navit_set_timeout(struct navit *this_) |
411 | void navit_set_timeout(struct navit *this_) |
393 | { |
412 | { |
394 | //dbg(0,"EEnter\n"); |
413 | ////DBG dbg(0,"EEnter\n"); |
395 | struct attr follow; |
414 | struct attr follow; |
396 | follow.type=attr_follow; |
415 | follow.type = attr_follow; |
397 | follow.u.num=this_->center_timeout; |
416 | follow.u.num = this_->center_timeout; |
398 | navit_set_attr(this_, &follow); |
417 | navit_set_attr(this_, &follow); |
399 | } |
418 | } |
400 | |
419 | |
401 | int |
|
|
402 | navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback) |
420 | int navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback) |
403 | { |
421 | { |
404 | //dbg(0,"EEnter\n"); |
422 | ////DBG dbg(0,"EEnter\n"); |
405 | int border=16; |
423 | int border = 16; |
406 | |
424 | |
407 | dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button); |
425 | // dbg(1, "enter %d %d (ignore %d)\n", pressed, button, this_->ignore_button); |
408 | callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p); |
426 | callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p); |
409 | if (this_->ignore_button) { |
427 | if (this_->ignore_button) |
|
|
428 | { |
410 | this_->ignore_button=0; |
429 | this_->ignore_button = 0; |
411 | return 0; |
430 | return 0; |
412 | } |
431 | } |
413 | if (pressed) { |
432 | if (pressed) |
|
|
433 | { |
414 | this_->pressed=*p; |
434 | this_->pressed = *p; |
415 | this_->last=*p; |
435 | this_->last = *p; |
416 | this_->zoomed=0; |
436 | this_->zoomed = 0; |
417 | if (button == 1) { |
437 | if (button == 1) |
|
|
438 | { |
418 | this_->button_pressed=1; |
439 | this_->button_pressed = 1; |
419 | this_->moved=0; |
440 | this_->moved = 0; |
420 | this_->popped=0; |
441 | this_->popped = 0; |
421 | if (popup_callback) |
442 | if (popup_callback) |
422 | this_->button_timeout=event_add_timeout(500, 0, popup_callback); |
443 | this_->button_timeout = event_add_timeout(500, 0, popup_callback); |
423 | } |
444 | } |
424 | if (button == 2) |
445 | if (button == 2) |
425 | navit_set_center_screen(this_, p, 1); |
446 | navit_set_center_screen(this_, p, 1); |
426 | if (button == 3) |
447 | if (button == 3) |
427 | popup(this_, button, p); |
448 | popup(this_, button, p); |
428 | if (button == 4 && this_->use_mousewheel) { |
449 | if (button == 4 && this_->use_mousewheel) |
|
|
450 | { |
429 | this_->zoomed = 1; |
451 | this_->zoomed = 1; |
430 | navit_zoom_in(this_, 2, p); |
452 | navit_zoom_in(this_, 2, p); |
431 | } |
453 | } |
432 | if (button == 5 && this_->use_mousewheel) { |
454 | if (button == 5 && this_->use_mousewheel) |
|
|
455 | { |
433 | this_->zoomed = 1; |
456 | this_->zoomed = 1; |
434 | navit_zoom_out(this_, 2, p); |
457 | navit_zoom_out(this_, 2, p); |
435 | } |
458 | } |
436 | } else { |
459 | } |
|
|
460 | else |
|
|
461 | { |
437 | |
462 | |
438 | this_->button_pressed=0; |
463 | this_->button_pressed = 0; |
439 | if (this_->button_timeout) { |
464 | if (this_->button_timeout) |
|
|
465 | { |
440 | event_remove_timeout(this_->button_timeout); |
466 | event_remove_timeout(this_->button_timeout); |
441 | this_->button_timeout=NULL; |
467 | this_->button_timeout = NULL; |
442 | if (! this_->moved && ! transform_within_border(this_->trans, p, border)) { |
468 | if (!this_->moved && !transform_within_border(this_->trans, p, border)) |
|
|
469 | { |
443 | navit_set_center_screen(this_, p, !this_->zoomed); |
470 | navit_set_center_screen(this_, p, !this_->zoomed); |
444 | } |
471 | } |
445 | } |
472 | } |
446 | if (this_->motion_timeout) { |
473 | if (this_->motion_timeout) |
|
|
474 | { |
447 | event_remove_timeout(this_->motion_timeout); |
475 | event_remove_timeout(this_->motion_timeout); |
448 | this_->motion_timeout=NULL; |
476 | this_->motion_timeout = NULL; |
449 | } |
477 | } |
450 | if (this_->moved) { |
478 | if (this_->moved) |
|
|
479 | { |
451 | struct point pr; |
480 | struct point pr; |
452 | pr.x=this_->w/2; |
481 | pr.x = this_->w / 2; |
453 | pr.y=this_->h; |
482 | pr.y = this_->h; |
454 | #if 0 |
483 | #if 0 |
455 | update_transformation(this_->trans, &this_->pressed, p, &pr); |
484 | update_transformation(this_->trans, &this_->pressed, p, &pr); |
456 | #else |
485 | #else |
457 | update_transformation(this_->trans, &this_->pressed, p, NULL); |
486 | update_transformation(this_->trans, &this_->pressed, p, NULL); |
458 | #endif |
487 | #endif |
459 | graphics_draw_drag(this_->gra, NULL); |
488 | graphics_draw_drag(this_->gra, NULL); |
460 | transform_copy(this_->trans, this_->trans_cursor); |
489 | transform_copy(this_->trans, this_->trans_cursor); |
461 | graphics_overlay_disable(this_->gra, 0); |
490 | graphics_overlay_disable(this_->gra, 0); |
462 | if (!this_->zoomed) |
491 | if (!this_->zoomed) |
463 | navit_set_timeout(this_); |
492 | navit_set_timeout(this_); |
464 | navit_draw(this_); |
493 | navit_draw(this_); |
|
|
494 | } |
465 | } else |
495 | else |
466 | return 1; |
496 | return 1; |
467 | } |
497 | } |
468 | return 0; |
498 | return 0; |
469 | } |
499 | } |
470 | |
500 | |
471 | static void |
|
|
472 | navit_button(void *data, int pressed, int button, struct point *p) |
501 | static void navit_button(void *data, int pressed, int button, struct point *p) |
473 | { |
502 | { |
474 | //dbg(0,"EEnter\n"); |
503 | ////DBG dbg(0,"EEnter\n"); |
475 | struct navit *this=data; |
504 | struct navit *this = data; |
476 | dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events); |
505 | // dbg(1, "enter %d %d ignore %d\n", pressed, button, this->ignore_graphics_events); |
477 | if (!this->ignore_graphics_events) { |
506 | if (!this->ignore_graphics_events) |
|
|
507 | { |
478 | if (! this->popup_callback) |
508 | if (!this->popup_callback) |
479 | this->popup_callback=callback_new_1(callback_cast(navit_popup), this); |
509 | this->popup_callback = callback_new_1(callback_cast(navit_popup), this); |
480 | navit_handle_button(this, pressed, button, p, this->popup_callback); |
510 | navit_handle_button(this, pressed, button, p, this->popup_callback); |
481 | } |
511 | } |
482 | } |
512 | } |
483 | |
513 | |
484 | |
|
|
485 | static void |
|
|
486 | navit_motion_timeout(struct navit *this_) |
514 | static void navit_motion_timeout(struct navit *this_) |
487 | { |
515 | { |
488 | //dbg(0,"EEnter\n"); |
516 | ////DBG dbg(0,"EEnter\n"); |
489 | int dx, dy; |
517 | int dx, dy; |
490 | |
518 | |
491 | if (this_->drag_bitmap) { |
519 | if (this_->drag_bitmap) |
|
|
520 | { |
492 | struct point point; |
521 | struct point point; |
493 | point.x=(this_->current.x-this_->pressed.x); |
522 | point.x = (this_->current.x - this_->pressed.x); |
494 | point.y=(this_->current.y-this_->pressed.y); |
523 | point.y = (this_->current.y - this_->pressed.y); |
495 | if (graphics_draw_drag(this_->gra, &point)) { |
524 | if (graphics_draw_drag(this_->gra, &point)) |
|
|
525 | { |
496 | graphics_overlay_disable(this_->gra, 1); |
526 | graphics_overlay_disable(this_->gra, 1); |
497 | graphics_draw_mode(this_->gra, draw_mode_end); |
527 | graphics_draw_mode(this_->gra, draw_mode_end); |
498 | this_->moved=1; |
528 | this_->moved = 1; |
499 | this_->motion_timeout=NULL; |
529 | this_->motion_timeout = NULL; |
500 | return; |
530 | return; |
501 | } |
531 | } |
502 | } |
532 | } |
503 | dx=(this_->current.x-this_->last.x); |
533 | dx = (this_->current.x - this_->last.x); |
504 | dy=(this_->current.y-this_->last.y); |
534 | dy = (this_->current.y - this_->last.y); |
505 | if (dx || dy) { |
535 | if (dx || dy) |
|
|
536 | { |
506 | struct transformation *tr; |
537 | struct transformation *tr; |
507 | struct point pr; |
538 | struct point pr; |
508 | this_->last=this_->current; |
539 | this_->last = this_->current; |
509 | graphics_overlay_disable(this_->gra, 1); |
540 | graphics_overlay_disable(this_->gra, 1); |
510 | tr=transform_dup(this_->trans); |
541 | tr = transform_dup(this_->trans); |
511 | pr.x=this_->w/2; |
542 | pr.x = this_->w / 2; |
512 | pr.y=this_->h; |
543 | pr.y = this_->h; |
513 | #if 0 |
544 | #if 0 |
514 | update_transformation(tr, &this_->pressed, &this_->current, &pr); |
545 | update_transformation(tr, &this_->pressed, &this_->current, &pr); |
515 | #else |
546 | #else |
516 | update_transformation(tr, &this_->pressed, &this_->current, NULL); |
547 | update_transformation(tr, &this_->pressed, &this_->current, NULL); |
517 | #endif |
548 | #endif |
518 | #if 0 |
549 | #if 0 |
519 | graphics_displaylist_move(this_->displaylist, dx, dy); |
550 | graphics_displaylist_move(this_->displaylist, dx, dy); |
520 | #endif |
551 | #endif |
521 | graphics_draw_cancel(this_->gra, this_->displaylist); |
552 | graphics_draw_cancel(this_->gra, this_->displaylist); |
522 | // dbg(0,"call graphics_displaylist_draw 1") |
553 | // //DBG dbg(0,"call graphics_displaylist_draw 1") |
523 | graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags); |
554 | graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags); |
524 | transform_destroy(tr); |
555 | transform_destroy(tr); |
525 | this_->moved=1; |
556 | this_->moved = 1; |
526 | } |
557 | } |
527 | this_->motion_timeout=NULL; |
558 | this_->motion_timeout = NULL; |
528 | return; |
559 | return; |
529 | } |
560 | } |
530 | |
561 | |
531 | void |
|
|
532 | navit_handle_motion(struct navit *this_, struct point *p) |
562 | void navit_handle_motion(struct navit *this_, struct point *p) |
533 | { |
563 | { |
534 | //dbg(0,"EEnter\n"); |
564 | ////DBG dbg(0,"EEnter\n"); |
535 | int dx, dy; |
565 | int dx, dy; |
536 | |
566 | |
537 | if (this_->button_pressed && !this_->popped) { |
567 | if (this_->button_pressed && !this_->popped) |
|
|
568 | { |
538 | dx=(p->x-this_->pressed.x); |
569 | dx = (p->x - this_->pressed.x); |
539 | dy=(p->y-this_->pressed.y); |
570 | dy = (p->y - this_->pressed.y); |
540 | if (dx < -8 || dx > 8 || dy < -8 || dy > 8) { |
571 | if (dx < -8 || dx > 8 || dy < -8 || dy > 8) |
|
|
572 | { |
541 | this_->moved=1; |
573 | this_->moved = 1; |
542 | if (this_->button_timeout) { |
574 | if (this_->button_timeout) |
|
|
575 | { |
543 | event_remove_timeout(this_->button_timeout); |
576 | event_remove_timeout(this_->button_timeout); |
544 | this_->button_timeout=NULL; |
577 | this_->button_timeout = NULL; |
545 | } |
578 | } |
546 | this_->current=*p; |
579 | this_->current = *p; |
547 | if (! this_->motion_timeout_callback) |
580 | if (!this_->motion_timeout_callback) |
548 | this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_); |
581 | this_->motion_timeout_callback = callback_new_1(callback_cast(navit_motion_timeout), this_); |
549 | if (! this_->motion_timeout) |
582 | if (!this_->motion_timeout) |
550 | this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback); |
583 | this_->motion_timeout = event_add_timeout(100, 0, this_->motion_timeout_callback); |
551 | } |
|
|
552 | } |
584 | } |
|
|
585 | } |
553 | } |
586 | } |
554 | |
587 | |
555 | static void |
|
|
556 | navit_motion(void *data, struct point *p) |
588 | static void navit_motion(void *data, struct point *p) |
557 | { |
589 | { |
558 | //dbg(0,"EEnter\n"); |
590 | ////DBG dbg(0,"EEnter\n"); |
559 | struct navit *this=data; |
591 | struct navit *this = data; |
560 | if (!this->ignore_graphics_events) |
592 | if (!this->ignore_graphics_events) |
561 | navit_handle_motion(this, p); |
593 | navit_handle_motion(this, p); |
562 | } |
594 | } |
563 | |
595 | |
564 | static void |
|
|
565 | navit_predraw(struct navit *this_) |
596 | static void navit_predraw(struct navit *this_) |
566 | { |
597 | { |
567 | //dbg(0,"EEnter\n"); |
598 | ////DBG dbg(0,"EEnter\n"); |
568 | GList *l; |
599 | GList *l; |
569 | struct navit_vehicle *nv; |
600 | struct navit_vehicle *nv; |
570 | transform_copy(this_->trans, this_->trans_cursor); |
601 | transform_copy(this_->trans, this_->trans_cursor); |
571 | l=this_->vehicles; |
602 | l = this_->vehicles; |
572 | while (l) |
603 | while (l) |
573 | { |
604 | { |
574 | nv=l->data; |
605 | nv = l->data; |
575 | //dbg(0,"* here *\n"); |
606 | ////DBG dbg(0,"* here *\n"); |
576 | //dbg(0,"vehicle_draw_004\n"); |
607 | ////DBG dbg(0,"vehicle_draw_004\n"); |
577 | navit_vehicle_draw(this_, nv, NULL); |
608 | navit_vehicle_draw(this_, nv, NULL); |
578 | l=g_list_next(l); |
609 | l = g_list_next(l); |
579 | } |
610 | } |
580 | } |
611 | } |
581 | |
612 | |
582 | static void |
|
|
583 | navit_scale(struct navit *this_, long scale, struct point *p, int draw) |
613 | static void navit_scale(struct navit *this_, long scale, struct point *p, int draw) |
584 | { |
614 | { |
585 | //dbg(0,"EEnter\n"); |
615 | //DBG dbg(0,"EEnter\n"); |
586 | struct coord c1, c2, *center; |
616 | struct coord c1, c2, *center; |
587 | |
617 | |
588 | if (scale < this_->zoom_min) |
618 | if (scale < this_->zoom_min) |
589 | { |
619 | { |
590 | scale=this_->zoom_min; |
620 | scale = this_->zoom_min; |
591 | } |
621 | } |
592 | |
622 | |
593 | if (scale > this_->zoom_max) |
623 | if (scale > this_->zoom_max) |
594 | { |
624 | { |
595 | scale=this_->zoom_max; |
625 | scale = this_->zoom_max; |
596 | } |
626 | } |
597 | |
627 | |
598 | // return scale value to android |
628 | // return scale value to android |
599 | #ifdef HAVE_API_ANDROID |
629 | #ifdef HAVE_API_ANDROID |
600 | android_return_generic_int(3, (int)scale); |
630 | android_return_generic_int(3, (int)scale); |
… | |
… | |
613 | center = transform_center(this_->trans); |
643 | center = transform_center(this_->trans); |
614 | center->x += c1.x - c2.x; |
644 | center->x += c1.x - c2.x; |
615 | center->y += c1.y - c2.y; |
645 | center->y += c1.y - c2.y; |
616 | } |
646 | } |
617 | |
647 | |
|
|
648 | //DBG dbg(0,"aa331\n"); |
|
|
649 | |
618 | if (draw) |
650 | if (draw) |
619 | { |
651 | { |
620 | navit_draw(this_); |
652 | navit_draw(this_); |
621 | } |
653 | } |
|
|
654 | |
|
|
655 | //DBG dbg(0,"leave\n"); |
622 | } |
656 | } |
623 | |
657 | |
624 | /** |
658 | /** |
625 | * @brief Automatically adjusts zoom level |
659 | * @brief Automatically adjusts zoom level |
626 | * |
660 | * |
… | |
… | |
630 | * @param this_ The navit struct |
664 | * @param this_ The navit struct |
631 | * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle |
665 | * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle |
632 | * @param speed The vehicles speed in meters per second |
666 | * @param speed The vehicles speed in meters per second |
633 | * @param dir The direction into which the vehicle moves |
667 | * @param dir The direction into which the vehicle moves |
634 | */ |
668 | */ |
635 | static void |
|
|
636 | navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw) |
669 | static void navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw) |
637 | { |
670 | { |
638 | struct point pc; |
671 | struct point pc; |
639 | int distance,w,h; |
672 | int distance, w, h; |
640 | double new_scale; |
673 | double new_scale; |
641 | long scale; |
674 | long scale; |
642 | |
675 | |
643 | if (! this_->autozoom_active) { |
676 | if (!this_->autozoom_active) |
|
|
677 | { |
644 | return; |
678 | return; |
645 | } |
679 | } |
646 | |
680 | |
647 | distance = speed * this_->autozoom_secs; |
681 | distance = speed * this_->autozoom_secs; |
648 | |
682 | |
… | |
… | |
652 | |
686 | |
653 | /* We make sure that the point we want to see is within a certain range |
687 | /* We make sure that the point we want to see is within a certain range |
654 | * around the vehicle. The radius of this circle is the size of the |
688 | * around the vehicle. The radius of this circle is the size of the |
655 | * screen. This doesn't necessarily mean the point is visible because of |
689 | * screen. This doesn't necessarily mean the point is visible because of |
656 | * perspective etc. Quite rough, but should be enough. */ |
690 | * perspective etc. Quite rough, but should be enough. */ |
657 | |
691 | |
658 | if (w > h) { |
692 | if (w > h) |
|
|
693 | { |
659 | new_scale = (double)distance / h * 16; |
694 | new_scale = (double) distance / h * 16; |
660 | } else { |
695 | } |
|
|
696 | else |
|
|
697 | { |
661 | new_scale = (double)distance / w * 16; |
698 | new_scale = (double) distance / w * 16; |
662 | } |
699 | } |
663 | |
700 | |
664 | if (abs(new_scale - scale) < 2) { |
701 | if (abs(new_scale - scale) < 2) |
|
|
702 | { |
665 | return; // Smoothing |
703 | return; // Smoothing |
666 | } |
704 | } |
667 | |
705 | |
668 | if (new_scale >= this_->autozoom_min) { |
706 | if (new_scale >= this_->autozoom_min) |
|
|
707 | { |
669 | navit_scale(this_, (long)new_scale, &pc, 0); |
708 | navit_scale(this_, (long) new_scale, &pc, 0); |
670 | } else { |
709 | } |
|
|
710 | else |
|
|
711 | { |
671 | if (scale != this_->autozoom_min) { |
712 | if (scale != this_->autozoom_min) |
|
|
713 | { |
672 | navit_scale(this_, this_->autozoom_min, &pc, 0); |
714 | navit_scale(this_, this_->autozoom_min, &pc, 0); |
673 | } |
715 | } |
674 | } |
716 | } |
675 | } |
717 | } |
676 | |
718 | |
… | |
… | |
680 | * @param navit The navit instance |
722 | * @param navit The navit instance |
681 | * @param factor The zoom factor, usually 2 |
723 | * @param factor The zoom factor, usually 2 |
682 | * @param p The invariant point (if set to NULL, default to center) |
724 | * @param p The invariant point (if set to NULL, default to center) |
683 | * @returns nothing |
725 | * @returns nothing |
684 | */ |
726 | */ |
685 | void |
|
|
686 | navit_zoom_in(struct navit *this_, int factor, struct point *p) |
727 | void navit_zoom_in(struct navit *this_, int factor, struct point *p) |
687 | { |
728 | { |
688 | //dbg(0,"EEnter\n"); |
729 | ////DBG dbg(0,"EEnter\n"); |
689 | long scale=transform_get_scale(this_->trans)/factor; |
730 | long scale = transform_get_scale(this_->trans) / factor; |
690 | if (scale < 1) |
731 | if (scale < 1) |
691 | scale=1; |
732 | scale = 1; |
692 | //dbg(0,"zoom in -> scale=%d",scale); |
733 | ////DBG dbg(0,"zoom in -> scale=%d",scale); |
693 | navit_scale(this_, scale, p, 1); |
734 | navit_scale(this_, scale, p, 1); |
694 | } |
735 | } |
695 | |
736 | |
696 | /** |
737 | /** |
697 | * Change the current zoom level |
738 | * Change the current zoom level |
… | |
… | |
699 | * @param navit The navit instance |
740 | * @param navit The navit instance |
700 | * @param factor The zoom factor, usually 2 |
741 | * @param factor The zoom factor, usually 2 |
701 | * @param p The invariant point (if set to NULL, default to center) |
742 | * @param p The invariant point (if set to NULL, default to center) |
702 | * @returns nothing |
743 | * @returns nothing |
703 | */ |
744 | */ |
704 | void |
|
|
705 | navit_zoom_out(struct navit *this_, int factor, struct point *p) |
745 | void navit_zoom_out(struct navit *this_, int factor, struct point *p) |
706 | { |
746 | { |
707 | //dbg(0,"EEnter\n"); |
747 | ////DBG dbg(0,"EEnter\n"); |
708 | long scale=transform_get_scale(this_->trans)*factor; |
748 | long scale = transform_get_scale(this_->trans) * factor; |
709 | //dbg(0,"zoom out -> scale=%d",scale); |
749 | ////DBG dbg(0,"zoom out -> scale=%d",scale); |
710 | navit_scale(this_, scale, p, 1); |
750 | navit_scale(this_, scale, p, 1); |
711 | } |
751 | } |
712 | |
752 | |
713 | int |
|
|
714 | navit_get_cur_pnt(struct navit *this_, struct point *p) |
753 | int navit_get_cur_pnt(struct navit *this_, struct point *p) |
715 | { |
754 | { |
716 | //dbg(0,"EEnter\n"); |
755 | ////DBG dbg(0,"EEnter\n"); |
717 | return navit_get_cursor_pnt(this_, p, 0, NULL); |
756 | return navit_get_cursor_pnt(this_, p, 0, NULL); |
718 | } |
757 | } |
719 | |
758 | |
720 | void |
|
|
721 | navit_zoom_in_cursor(struct navit *this_, int factor) |
759 | void navit_zoom_in_cursor(struct navit *this_, int factor) |
722 | { |
760 | { |
723 | //dbg(0,"EEnter\n"); |
761 | ////DBG dbg(0,"EEnter\n"); |
724 | struct point p; |
762 | struct point p; |
725 | if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) { |
763 | if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) |
|
|
764 | { |
726 | navit_zoom_in(this_, factor, &p); |
765 | navit_zoom_in(this_, factor, &p); |
727 | this_->vehicle->follow_curr=this_->vehicle->follow; |
766 | this_->vehicle->follow_curr = this_->vehicle->follow; |
|
|
767 | } |
728 | } else |
768 | else |
729 | navit_zoom_in(this_, factor, NULL); |
769 | navit_zoom_in(this_, factor, NULL); |
730 | } |
770 | } |
731 | |
771 | |
732 | void |
|
|
733 | navit_zoom_to_scale(struct navit *this_, int new_scale) |
772 | void navit_zoom_to_scale(struct navit *this_, int new_scale) |
734 | { |
773 | { |
735 | //dbg(0,"EEnter\n"); |
774 | //DBG dbg(0,"EEnter\n"); |
736 | long scale=transform_get_scale(this_->trans); |
775 | long scale = transform_get_scale(this_->trans); |
737 | long new_scale_long=new_scale; |
776 | long new_scale_long = new_scale; |
738 | //dbg(0,"zoom to scale -> old scale=%d",scale); |
777 | //DBG dbg(0,"zoom to scale -> old scale=%d",scale); |
739 | //dbg(0,"zoom to scale -> want scale=%d",new_scale_long); |
778 | //DBG dbg(0,"zoom to scale -> want scale=%d",new_scale_long); |
740 | |
779 | |
741 | // only do something if scale changed! |
780 | // only do something if scale changed! |
742 | if (scale != new_scale_long) |
781 | if (scale != new_scale_long) |
743 | { |
782 | { |
744 | navit_scale(this_, new_scale_long, NULL, 1); |
783 | navit_scale(this_, new_scale_long, NULL, 1); |
745 | } |
784 | } |
746 | } |
785 | } |
747 | |
786 | |
748 | void |
|
|
749 | navit_zoom_out_cursor(struct navit *this_, int factor) |
787 | void navit_zoom_out_cursor(struct navit *this_, int factor) |
750 | { |
788 | { |
751 | //dbg(0,"EEnter\n"); |
789 | ////DBG dbg(0,"EEnter\n"); |
752 | struct point p; |
790 | struct point p; |
753 | if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) { |
791 | if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) |
|
|
792 | { |
754 | navit_zoom_out(this_, 2, &p); |
793 | navit_zoom_out(this_, 2, &p); |
755 | this_->vehicle->follow_curr=this_->vehicle->follow; |
794 | this_->vehicle->follow_curr = this_->vehicle->follow; |
|
|
795 | } |
756 | } else |
796 | else |
757 | navit_zoom_out(this_, 2, NULL); |
797 | navit_zoom_out(this_, 2, NULL); |
758 | } |
798 | } |
759 | |
799 | |
760 | static int |
|
|
761 | navit_cmd_zoom_in(struct navit *this_) |
800 | static int navit_cmd_zoom_in(struct navit *this_) |
762 | { |
801 | { |
763 | //dbg(0,"EEnter\n"); |
802 | ////DBG dbg(0,"EEnter\n"); |
764 | navit_zoom_in_cursor(this_, 2); |
803 | navit_zoom_in_cursor(this_, 2); |
765 | return 0; |
804 | return 0; |
766 | } |
805 | } |
767 | |
806 | |
768 | static int |
|
|
769 | navit_cmd_zoom_out(struct navit *this_) |
807 | static int navit_cmd_zoom_out(struct navit *this_) |
770 | { |
808 | { |
771 | //dbg(0,"EEnter\n"); |
809 | ////DBG dbg(0,"EEnter\n"); |
772 | navit_zoom_out_cursor(this_, 2); |
810 | navit_zoom_out_cursor(this_, 2); |
773 | return 0; |
811 | return 0; |
774 | } |
812 | } |
775 | |
813 | |
776 | |
|
|
777 | static void |
|
|
778 | navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
814 | static void navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
779 | { |
815 | { |
780 | //dbg(0,"EEnter\n"); |
816 | ////DBG dbg(0,"EEnter\n"); |
781 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) |
817 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) |
|
|
818 | { |
782 | navit_say(this, in[0]->u.str); |
819 | navit_say(this, in[0]->u.str); |
|
|
820 | } |
783 | } |
821 | } |
784 | |
822 | |
785 | static GHashTable *cmd_int_var_hash = NULL; |
823 | static GHashTable *cmd_int_var_hash = NULL; |
786 | static GHashTable *cmd_attr_var_hash = NULL; |
824 | static GHashTable *cmd_attr_var_hash = NULL; |
787 | |
825 | |
… | |
… | |
793 | * @param in input attributes in[0] is the key string, in[1] is the integer value to store |
831 | * @param in input attributes in[0] is the key string, in[1] is the integer value to store |
794 | * @param out output attributes, unused |
832 | * @param out output attributes, unused |
795 | * @param valid unused |
833 | * @param valid unused |
796 | * @returns nothing |
834 | * @returns nothing |
797 | */ |
835 | */ |
798 | static void |
|
|
799 | navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
836 | static void navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
800 | { |
837 | { |
801 | //dbg(0,"EEnter\n"); |
838 | ////DBG dbg(0,"EEnter\n"); |
802 | char*key; |
839 | char*key; |
803 | struct attr*val; |
840 | struct attr*val; |
804 | if(!cmd_int_var_hash) { |
841 | if (!cmd_int_var_hash) |
|
|
842 | { |
805 | cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal); |
843 | cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal); |
806 | } |
844 | } |
807 | |
845 | |
808 | if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && |
846 | if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) |
809 | (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) { |
847 | { |
810 | val = g_new(struct attr,1); |
848 | val = g_new(struct attr,1); |
811 | attr_dup_content(in[1],val); |
849 | attr_dup_content(in[1], val); |
812 | key = g_strdup(in[0]->u.str); |
850 | key = g_strdup(in[0]->u.str); |
813 | g_hash_table_insert(cmd_int_var_hash, key, val); |
851 | g_hash_table_insert(cmd_int_var_hash, key, val); |
814 | } |
852 | } |
815 | } |
853 | } |
816 | |
|
|
817 | |
854 | |
818 | /** |
855 | /** |
819 | * Store key value pair for the command system (for attr typed values, can be used as opaque handles) |
856 | * Store key value pair for the command system (for attr typed values, can be used as opaque handles) |
820 | * |
857 | * |
821 | * @param navit The navit instance |
858 | * @param navit The navit instance |
… | |
… | |
824 | * @param out output attributes, unused |
861 | * @param out output attributes, unused |
825 | * @param valid unused |
862 | * @param valid unused |
826 | * @returns nothing |
863 | * @returns nothing |
827 | */ |
864 | */ |
828 | //TODO free stored attributes on navit_destroy |
865 | //TODO free stored attributes on navit_destroy |
829 | static void |
|
|
830 | navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
866 | static void navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
831 | { |
867 | { |
832 | //dbg(0,"EEnter\n"); |
868 | ////DBG dbg(0,"EEnter\n"); |
833 | char*key; |
869 | char*key; |
834 | struct attr*val; |
870 | struct attr*val; |
835 | if(!cmd_attr_var_hash) { |
871 | if (!cmd_attr_var_hash) |
|
|
872 | { |
836 | cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal); |
873 | cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal); |
837 | } |
874 | } |
838 | |
875 | |
839 | if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && |
876 | if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1])) |
840 | (in && in[1] )) { |
877 | { |
841 | val = attr_dup(in[1]); |
878 | val = attr_dup(in[1]); |
842 | //val = in[1]; |
879 | //val = in[1]; |
843 | key = g_strdup(in[0]->u.str); |
880 | key = g_strdup(in[0]->u.str); |
844 | g_hash_table_insert(cmd_attr_var_hash, key, val); |
881 | g_hash_table_insert(cmd_attr_var_hash, key, val); |
845 | } |
882 | } |
846 | } |
883 | } |
847 | |
|
|
848 | |
|
|
849 | |
884 | |
850 | /** |
885 | /** |
851 | * command to toggle the active state of a named layer of the current layout |
886 | * command to toggle the active state of a named layer of the current layout |
852 | * |
887 | * |
853 | * @param navit The navit instance |
888 | * @param navit The navit instance |
… | |
… | |
855 | * @param in input attribute in[0] is the name of the layer |
890 | * @param in input attribute in[0] is the name of the layer |
856 | * @param out output unused |
891 | * @param out output unused |
857 | * @param valid unused |
892 | * @param valid unused |
858 | * @returns nothing |
893 | * @returns nothing |
859 | */ |
894 | */ |
860 | static void |
|
|
861 | navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
895 | static void navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
862 | { |
896 | { |
863 | //dbg(0,"EEnter\n"); |
897 | ////DBG dbg(0,"EEnter\n"); |
864 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) { |
898 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) |
|
|
899 | { |
865 | if(this->layout_current && this->layout_current->layers) { |
900 | if (this->layout_current && this->layout_current->layers) |
|
|
901 | { |
866 | GList* layers = this->layout_current->layers; |
902 | GList* layers = this->layout_current->layers; |
867 | while (layers) { |
903 | while (layers) |
|
|
904 | { |
868 | struct layer*l=layers->data; |
905 | struct layer*l = layers->data; |
869 | if(l && !strcmp(l->name,in[0]->u.str) ) { |
906 | if (l && !strcmp(l->name, in[0]->u.str)) |
|
|
907 | { |
870 | l->active ^= 1; |
908 | l->active ^= 1; |
871 | navit_draw(this); |
909 | navit_draw(this); |
872 | return; |
910 | return; |
873 | } |
911 | } |
874 | layers=g_list_next(layers); |
912 | layers = g_list_next(layers); |
875 | } |
|
|
876 | } |
913 | } |
877 | } |
914 | } |
|
|
915 | } |
878 | } |
916 | } |
879 | |
917 | |
880 | /** |
918 | /** |
881 | * adds an item with the current coordinate of the vehicle to a named map |
919 | * adds an item with the current coordinate of the vehicle to a named map |
882 | * |
920 | * |
… | |
… | |
885 | * @param in input attribute in[0] is the name of the map |
923 | * @param in input attribute in[0] is the name of the map |
886 | * @param out output attribute, 0 on error or the id of the created item on success |
924 | * @param out output attribute, 0 on error or the id of the created item on success |
887 | * @param valid unused |
925 | * @param valid unused |
888 | * @returns nothing |
926 | * @returns nothing |
889 | */ |
927 | */ |
890 | static void |
|
|
891 | navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
928 | static void navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
892 | { |
929 | { |
893 | //dbg(0,"EEnter\n"); |
930 | ////DBG dbg(0,"EEnter\n"); |
894 | struct attr **list = g_new0(struct attr *,2); |
931 | struct attr **list = g_new0(struct attr *,2); |
895 | struct attr*val = g_new0(struct attr,1); |
932 | struct attr*val = g_new0(struct attr,1); |
896 | struct mapset* ms; |
933 | struct mapset* ms; |
897 | struct map_selection sel; |
934 | struct map_selection sel; |
898 | const int selection_range = 10; |
935 | const int selection_range = 10; |
… | |
… | |
900 | struct item *it; |
937 | struct item *it; |
901 | struct map* curr_map = NULL; |
938 | struct map* curr_map = NULL; |
902 | struct coord curr_coord; |
939 | struct coord curr_coord; |
903 | struct map_rect *mr; |
940 | struct map_rect *mr; |
904 | |
941 | |
905 | val->type = attr_type_item_begin; |
942 | val->type = attr_type_item_begin; |
906 | val->u.item = NULL; //return invalid item on error |
943 | val->u.item = NULL; //return invalid item on error |
907 | list[0] = val; |
944 | list[0] = val; |
908 | list[1] = NULL; |
945 | list[1] = NULL; |
909 | *out = list; |
946 | *out = list; |
910 | if ( |
|
|
911 | in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name |
947 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name |
912 | in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type |
948 | in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type |
913 | ) { |
949 | ) |
|
|
950 | { |
914 | |
951 | |
915 | if(!(ms=navit_get_mapset(this))) { |
952 | if (!(ms = navit_get_mapset(this))) |
|
|
953 | { |
916 | return; |
954 | return; |
917 | } |
955 | } |
918 | |
956 | |
919 | if((item_type = item_from_name(in[1]->u.str))==type_none) { |
957 | if ((item_type = item_from_name(in[1]->u.str)) == type_none) |
|
|
958 | { |
920 | return; |
959 | return; |
921 | } |
960 | } |
922 | |
961 | |
923 | curr_map = mapset_get_map_by_name(ms, in[0]->u.str); |
962 | curr_map = mapset_get_map_by_name(ms, in[0]->u.str); |
924 | |
963 | |
925 | //no map with the given name found |
964 | //no map with the given name found |
926 | if( ! curr_map) { |
965 | if (!curr_map) |
|
|
966 | { |
927 | return; |
967 | return; |
928 | } |
968 | } |
929 | |
969 | |
930 | if(this->vehicle && this->vehicle->vehicle ) { |
970 | if (this->vehicle && this->vehicle->vehicle) |
|
|
971 | { |
931 | struct attr pos_attr; |
972 | struct attr pos_attr; |
932 | if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) { |
973 | if (vehicle_get_attr(this->vehicle->vehicle, attr_position_coord_geo, &pos_attr, NULL)) |
|
|
974 | { |
933 | transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord); |
975 | transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord); |
|
|
976 | } |
934 | } else { |
977 | else |
|
|
978 | { |
935 | return; |
979 | return; |
936 | } |
980 | } |
|
|
981 | } |
937 | } else { |
982 | else |
|
|
983 | { |
938 | return; |
984 | return; |
939 | } |
985 | } |
940 | |
986 | |
941 | sel.next=NULL; |
987 | sel.next = NULL; |
942 | sel.order=18; |
988 | sel.order = 18; |
943 | sel.range.min=type_none; |
989 | sel.range.min = type_none; |
944 | sel.range.max=type_tec_common; |
990 | sel.range.max = type_tec_common; |
945 | sel.u.c_rect.lu.x=curr_coord.x-selection_range; |
991 | sel.u.c_rect.lu.x = curr_coord.x - selection_range; |
946 | sel.u.c_rect.lu.y=curr_coord.y+selection_range; |
992 | sel.u.c_rect.lu.y = curr_coord.y + selection_range; |
947 | sel.u.c_rect.rl.x=curr_coord.x+selection_range; |
993 | sel.u.c_rect.rl.x = curr_coord.x + selection_range; |
948 | sel.u.c_rect.rl.y=curr_coord.y-selection_range; |
994 | sel.u.c_rect.rl.y = curr_coord.y - selection_range; |
949 | |
995 | |
950 | mr = map_rect_new(curr_map, &sel); |
996 | mr = map_rect_new(curr_map, &sel); |
951 | if(mr) { |
997 | if (mr) |
|
|
998 | { |
952 | it = map_rect_create_item( mr, item_type); |
999 | it = map_rect_create_item(mr, item_type); |
953 | item_coord_set(it,&curr_coord, 1, change_mode_modify); |
1000 | item_coord_set(it, &curr_coord, 1, change_mode_modify); |
954 | val->u.item = it; |
1001 | val->u.item = it; |
955 | } |
1002 | } |
956 | map_rect_destroy(mr); |
1003 | map_rect_destroy(mr); |
957 | } |
1004 | } |
958 | } |
1005 | } |
959 | |
1006 | |
960 | /** |
1007 | /** |
961 | * sets an attribute (name value pair) of a map item specified by map name and item id |
1008 | * sets an attribute (name value pair) of a map item specified by map name and item id |
962 | * |
1009 | * |
… | |
… | |
965 | * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value |
1012 | * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value |
966 | * @param out output attribute, 0 on error, 1 on success |
1013 | * @param out output attribute, 0 on error, 1 on success |
967 | * @param valid unused |
1014 | * @param valid unused |
968 | * @returns nothing |
1015 | * @returns nothing |
969 | */ |
1016 | */ |
970 | static void |
|
|
971 | navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1017 | static void navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
972 | { |
1018 | { |
973 | //dbg(0,"EEnter\n"); |
1019 | ////DBG dbg(0,"EEnter\n"); |
974 | if ( |
|
|
975 | in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str &&//map name |
1020 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name |
976 | in[1] && ATTR_IS_ITEM(in[1]->type) && //item |
1021 | in[1] && ATTR_IS_ITEM(in[1]->type) && //item |
977 | in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str |
1022 | in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str |
978 | in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str |
1023 | in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str |
979 | ) { |
1024 | ) |
|
|
1025 | { |
980 | struct attr attr_to_set; |
1026 | struct attr attr_to_set; |
981 | struct map* curr_map = NULL; |
1027 | struct map* curr_map = NULL; |
982 | struct mapset *ms; |
1028 | struct mapset *ms; |
983 | struct map_selection sel; |
1029 | struct map_selection sel; |
984 | const int selection_range = 500; |
1030 | const int selection_range = 500; |
985 | struct coord curr_coord; |
1031 | struct coord curr_coord; |
986 | struct item *it; |
1032 | struct item *it; |
987 | |
1033 | |
988 | if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) { |
1034 | if (ATTR_IS_STRING(attr_from_name(in[2]->u.str))) |
|
|
1035 | { |
989 | attr_to_set.u.str = in[3]->u.str; |
1036 | attr_to_set.u.str = in[3]->u.str; |
990 | attr_to_set.type = attr_from_name(in[2]->u.str); |
1037 | attr_to_set.type = attr_from_name(in[2]->u.str); |
991 | } |
1038 | } |
992 | else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) { |
1039 | else if (ATTR_IS_INT(attr_from_name(in[2]->u.str))) |
|
|
1040 | { |
993 | attr_to_set.u.num = atoi(in[3]->u.str); |
1041 | attr_to_set.u.num = atoi(in[3]->u.str); |
994 | attr_to_set.type = attr_from_name(in[2]->u.str); |
1042 | attr_to_set.type = attr_from_name(in[2]->u.str); |
995 | } |
1043 | } |
996 | else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) { |
1044 | else if (ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) |
|
|
1045 | { |
997 | double* val = g_new0(double,1); |
1046 | double* val = g_new0(double,1); |
998 | *val = atof(in[3]->u.str); |
1047 | *val = atof(in[3]->u.str); |
999 | attr_to_set.u.numd = val; |
1048 | attr_to_set.u.numd = val; |
1000 | attr_to_set.type = attr_from_name(in[2]->u.str); |
1049 | attr_to_set.type = attr_from_name(in[2]->u.str); |
1001 | } |
1050 | } |
1002 | |
1051 | |
1003 | ms = navit_get_mapset(this); |
1052 | ms = navit_get_mapset(this); |
1004 | |
1053 | |
1005 | curr_map = mapset_get_map_by_name(ms, in[0]->u.str); |
1054 | curr_map = mapset_get_map_by_name(ms, in[0]->u.str); |
1006 | |
1055 | |
1007 | if( ! curr_map) { |
1056 | if (!curr_map) |
|
|
1057 | { |
1008 | return; |
1058 | return; |
1009 | } |
1059 | } |
1010 | sel.next=NULL; |
1060 | sel.next = NULL; |
1011 | sel.order=18; |
1061 | sel.order = 18; |
1012 | sel.range.min=type_none; |
1062 | sel.range.min = type_none; |
1013 | sel.range.max=type_tec_common; |
1063 | sel.range.max = type_tec_common; |
1014 | sel.u.c_rect.lu.x=curr_coord.x-selection_range; |
1064 | sel.u.c_rect.lu.x = curr_coord.x - selection_range; |
1015 | sel.u.c_rect.lu.y=curr_coord.y+selection_range; |
1065 | sel.u.c_rect.lu.y = curr_coord.y + selection_range; |
1016 | sel.u.c_rect.rl.x=curr_coord.x+selection_range; |
1066 | sel.u.c_rect.rl.x = curr_coord.x + selection_range; |
1017 | sel.u.c_rect.rl.y=curr_coord.y-selection_range; |
1067 | sel.u.c_rect.rl.y = curr_coord.y - selection_range; |
1018 | |
1068 | |
1019 | it = in[1]->u.item; |
1069 | it = in[1]->u.item; |
1020 | if(it) { |
1070 | if (it) |
|
|
1071 | { |
1021 | item_attr_set(it, &attr_to_set, change_mode_modify); |
1072 | item_attr_set(it, &attr_to_set, change_mode_modify); |
1022 | } |
1073 | } |
1023 | } |
1074 | } |
1024 | } |
1075 | } |
1025 | |
1076 | |
… | |
… | |
1031 | * @param in input attribute in[0] is the key string |
1082 | * @param in input attribute in[0] is the key string |
1032 | * @param out output attribute, the attr for the given key string if exists or NULL |
1083 | * @param out output attribute, the attr for the given key string if exists or NULL |
1033 | * @param valid unused |
1084 | * @param valid unused |
1034 | * @returns nothing |
1085 | * @returns nothing |
1035 | */ |
1086 | */ |
1036 | static void |
|
|
1037 | navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1087 | static void navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1038 | { |
1088 | { |
1039 | //dbg(0,"EEnter\n"); |
1089 | ////DBG dbg(0,"EEnter\n"); |
1040 | struct attr **list = g_new0(struct attr *,2); |
1090 | struct attr **list = g_new0(struct attr *,2); |
1041 | if(!cmd_int_var_hash) { |
1091 | if (!cmd_int_var_hash) |
|
|
1092 | { |
1042 | struct attr*val = g_new0(struct attr,1); |
1093 | struct attr*val = g_new0(struct attr,1); |
1043 | val->type = attr_type_item_begin; |
1094 | val->type = attr_type_item_begin; |
1044 | val->u.item = NULL; |
1095 | val->u.item = NULL; |
1045 | list[0] = val; |
1096 | list[0] = val; |
1046 | } |
1097 | } |
1047 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) { |
1098 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) |
|
|
1099 | { |
1048 | struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str); |
1100 | struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str); |
1049 | if(ret) { |
1101 | if (ret) |
|
|
1102 | { |
1050 | list[0] = attr_dup(ret); |
1103 | list[0] = attr_dup(ret); |
1051 | } |
1104 | } |
1052 | else { |
1105 | else |
|
|
1106 | { |
1053 | struct attr*val = g_new0(struct attr,1); |
1107 | struct attr*val = g_new0(struct attr,1); |
1054 | val->type = attr_type_int_begin; |
1108 | val->type = attr_type_int_begin; |
1055 | val->u.item = NULL; |
1109 | val->u.item = NULL; |
1056 | list[0] = val; |
1110 | list[0] = val; |
|
|
1111 | } |
1057 | } |
1112 | } |
1058 | } |
|
|
1059 | list[1] = NULL; |
1113 | list[1] = NULL; |
1060 | *out = list; |
1114 | *out = list; |
1061 | } |
1115 | } |
1062 | |
|
|
1063 | |
1116 | |
1064 | /** |
1117 | /** |
1065 | * Get value given a key string for the command system |
1118 | * Get value given a key string for the command system |
1066 | * |
1119 | * |
1067 | * @param navit The navit instance |
1120 | * @param navit The navit instance |
… | |
… | |
1069 | * @param in input attribute in[0] is the key string |
1122 | * @param in input attribute in[0] is the key string |
1070 | * @param out output attribute, the value for the given key string if exists or 0 |
1123 | * @param out output attribute, the value for the given key string if exists or 0 |
1071 | * @param valid unused |
1124 | * @param valid unused |
1072 | * @returns nothing |
1125 | * @returns nothing |
1073 | */ |
1126 | */ |
1074 | static void |
|
|
1075 | navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1127 | static void navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1076 | { |
1128 | { |
1077 | //dbg(0,"EEnter\n"); |
1129 | ////DBG dbg(0,"EEnter\n"); |
1078 | struct attr **list = g_new0(struct attr *,2); |
1130 | struct attr **list = g_new0(struct attr *,2); |
1079 | if(!cmd_int_var_hash) { |
1131 | if (!cmd_int_var_hash) |
|
|
1132 | { |
1080 | struct attr*val = g_new0(struct attr,1); |
1133 | struct attr*val = g_new0(struct attr,1); |
1081 | val->type = attr_type_int_begin; |
1134 | val->type = attr_type_int_begin; |
1082 | val->u.num = 0; |
1135 | val->u.num = 0; |
1083 | list[0] = val; |
1136 | list[0] = val; |
1084 | } |
1137 | } |
1085 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) { |
1138 | if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) |
|
|
1139 | { |
1086 | struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str); |
1140 | struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str); |
1087 | if(ret) { |
1141 | if (ret) |
|
|
1142 | { |
1088 | list[0] = ret; |
1143 | list[0] = ret; |
1089 | } |
1144 | } |
1090 | else { |
1145 | else |
|
|
1146 | { |
1091 | struct attr*val = g_new0(struct attr,1); |
1147 | struct attr*val = g_new0(struct attr,1); |
1092 | val->type = attr_type_int_begin; |
1148 | val->type = attr_type_int_begin; |
1093 | val->u.num = 0; |
1149 | val->u.num = 0; |
1094 | list[0] = val; |
1150 | list[0] = val; |
|
|
1151 | } |
1095 | } |
1152 | } |
1096 | } |
|
|
1097 | list[1] = NULL; |
1153 | list[1] = NULL; |
1098 | *out = list; |
1154 | *out = list; |
1099 | } |
1155 | } |
1100 | |
1156 | |
1101 | GList *cmd_int_var_stack = NULL; |
1157 | GList *cmd_int_var_stack = NULL; |
… | |
… | |
1108 | * @param in input attribute in[0] is the integer attibute to push |
1164 | * @param in input attribute in[0] is the integer attibute to push |
1109 | * @param out output attributes, unused |
1165 | * @param out output attributes, unused |
1110 | * @param valid unused |
1166 | * @param valid unused |
1111 | * @returns nothing |
1167 | * @returns nothing |
1112 | */ |
1168 | */ |
1113 | static void |
|
|
1114 | navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1169 | static void navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1115 | { |
1170 | { |
1116 | //dbg(0,"EEnter\n"); |
1171 | ////DBG dbg(0,"EEnter\n"); |
1117 | if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) { |
1172 | if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) |
|
|
1173 | { |
1118 | struct attr*val = g_new(struct attr,1); |
1174 | struct attr*val = g_new(struct attr,1); |
1119 | attr_dup_content(in[0],val); |
1175 | attr_dup_content(in[0], val); |
1120 | cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val); |
1176 | cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val); |
1121 | } |
1177 | } |
1122 | } |
1178 | } |
1123 | |
1179 | |
1124 | /** |
1180 | /** |
… | |
… | |
1129 | * @param in input attributes unused |
1185 | * @param in input attributes unused |
1130 | * @param out output attribute, the value popped if stack isn't empty or 0 |
1186 | * @param out output attribute, the value popped if stack isn't empty or 0 |
1131 | * @param valid unused |
1187 | * @param valid unused |
1132 | * @returns nothing |
1188 | * @returns nothing |
1133 | */ |
1189 | */ |
1134 | static void |
|
|
1135 | navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1190 | static void navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1136 | { |
1191 | { |
1137 | //dbg(0,"EEnter\n"); |
1192 | ////DBG dbg(0,"EEnter\n"); |
1138 | struct attr **list = g_new0(struct attr *,2); |
1193 | struct attr **list = g_new0(struct attr *,2); |
1139 | if(!cmd_int_var_stack) { |
1194 | if (!cmd_int_var_stack) |
|
|
1195 | { |
1140 | struct attr*val = g_new0(struct attr,1); |
1196 | struct attr*val = g_new0(struct attr,1); |
1141 | val->type = attr_type_int_begin; |
1197 | val->type = attr_type_int_begin; |
1142 | val->u.num = 0; |
1198 | val->u.num = 0; |
1143 | list[0] = val; |
1199 | list[0] = val; |
1144 | } |
1200 | } |
1145 | else { |
1201 | else |
|
|
1202 | { |
1146 | list[0] = cmd_int_var_stack->data; |
1203 | list[0] = cmd_int_var_stack->data; |
1147 | cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack); |
1204 | cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack); |
1148 | } |
1205 | } |
1149 | list[1] = NULL; |
1206 | list[1] = NULL; |
1150 | *out = list; |
1207 | *out = list; |
1151 | } |
1208 | } |
1152 | |
1209 | |
… | |
… | |
1158 | * @param in input attributes unused |
1215 | * @param in input attributes unused |
1159 | * @param out output attribute, the size of stack |
1216 | * @param out output attribute, the size of stack |
1160 | * @param valid unused |
1217 | * @param valid unused |
1161 | * @returns nothing |
1218 | * @returns nothing |
1162 | */ |
1219 | */ |
1163 | static void |
|
|
1164 | navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1220 | static void navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1165 | { |
1221 | { |
1166 | //dbg(0,"EEnter\n"); |
1222 | ////DBG dbg(0,"EEnter\n"); |
1167 | struct attr **list; |
1223 | struct attr **list; |
1168 | struct attr *attr = g_new0(struct attr ,1); |
1224 | struct attr *attr = g_new0(struct attr ,1); |
1169 | attr->type = attr_type_int_begin; |
1225 | attr->type = attr_type_int_begin; |
1170 | if(!cmd_int_var_stack) { |
1226 | if (!cmd_int_var_stack) |
|
|
1227 | { |
1171 | attr->u.num = 0; |
1228 | attr->u.num = 0; |
1172 | } |
1229 | } |
1173 | else { |
1230 | else |
|
|
1231 | { |
1174 | attr->u.num = g_list_length(cmd_int_var_stack); |
1232 | attr->u.num = g_list_length(cmd_int_var_stack); |
1175 | } |
|
|
1176 | list = g_new0(struct attr *,2); |
1233 | }list = g_new0(struct attr *,2); |
1177 | list[0] = attr; |
1234 | list[0] = attr; |
1178 | list[1] = NULL; |
1235 | list[1] = NULL; |
1179 | *out = list; |
1236 | *out = list; |
1180 | cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack); |
1237 | cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack); |
1181 | } |
1238 | } |
1182 | |
1239 | |
1183 | static void |
|
|
1184 | navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1240 | static void navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1185 | { |
1241 | { |
1186 | //dbg(0,"EEnter\n"); |
1242 | ////DBG dbg(0,"EEnter\n"); |
1187 | struct pcoord pc; |
1243 | struct pcoord pc; |
1188 | char *description=NULL; |
1244 | char *description = NULL; |
1189 | if (!in) |
1245 | if (!in) |
1190 | return; |
1246 | return; |
1191 | if (!in[0]) |
1247 | if (!in[0]) |
1192 | return; |
1248 | return; |
1193 | pc.pro = transform_get_projection(this->trans); |
1249 | pc.pro = transform_get_projection(this->trans); |
1194 | if (ATTR_IS_COORD(in[0]->type)) { |
1250 | if (ATTR_IS_COORD(in[0]->type)) |
|
|
1251 | { |
1195 | pc.x=in[0]->u.coord->x; |
1252 | pc.x = in[0]->u.coord->x; |
1196 | pc.y=in[0]->u.coord->y; |
1253 | pc.y = in[0]->u.coord->y; |
1197 | in++; |
1254 | in++; |
|
|
1255 | } |
1198 | } else if (ATTR_IS_PCOORD(in[0]->type)) { |
1256 | else if (ATTR_IS_PCOORD(in[0]->type)) |
|
|
1257 | { |
1199 | pc=*in[0]->u.pcoord; |
1258 | pc = *in[0]->u.pcoord; |
1200 | in++; |
1259 | in++; |
|
|
1260 | } |
1201 | } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) { |
1261 | else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) |
|
|
1262 | { |
1202 | pc.pro=in[0]->u.num; |
1263 | pc.pro = in[0]->u.num; |
1203 | pc.x=in[1]->u.num; |
1264 | pc.x = in[1]->u.num; |
1204 | pc.y=in[2]->u.num; |
1265 | pc.y = in[2]->u.num; |
1205 | in+=3; |
1266 | in += 3; |
|
|
1267 | } |
1206 | } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) { |
1268 | else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) |
|
|
1269 | { |
1207 | pc.x=in[0]->u.num; |
1270 | pc.x = in[0]->u.num; |
1208 | pc.y=in[1]->u.num; |
1271 | pc.y = in[1]->u.num; |
1209 | in+=2; |
1272 | in += 2; |
|
|
1273 | } |
1210 | } else |
1274 | else |
|
|
1275 | { |
1211 | return; |
1276 | return; |
|
|
1277 | } |
1212 | if (in[0] && ATTR_IS_STRING(in[0]->type)) |
1278 | if (in[0] && ATTR_IS_STRING(in[0]->type)) |
|
|
1279 | { |
1213 | description=in[0]->u.str; |
1280 | description = in[0]->u.str; |
|
|
1281 | } |
1214 | navit_set_destination(this, &pc, description, 1); |
1282 | navit_set_destination(this, &pc, description, 1); |
1215 | } |
1283 | } |
1216 | |
1284 | |
1217 | static void |
|
|
1218 | navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1285 | static void navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1219 | { |
1286 | { |
1220 | //dbg(0,"EEnter\n"); |
1287 | ////DBG dbg(0,"EEnter\n"); |
1221 | struct attr attr; |
1288 | struct attr attr; |
1222 | attr.type=attr_type_string_begin; |
1289 | attr.type = attr_type_string_begin; |
1223 | attr.u.str="Fix me"; |
1290 | attr.u.str = "Fix me"; |
1224 | if (out) { |
1291 | if (out) |
|
|
1292 | { |
1225 | *out=attr_generic_add_attr(*out, &attr); |
1293 | *out = attr_generic_add_attr(*out, &attr); |
1226 | } |
1294 | } |
1227 | } |
1295 | } |
1228 | |
1296 | |
1229 | /** |
1297 | /** |
1230 | * Join several string attributes into one |
1298 | * Join several string attributes into one |
… | |
… | |
1234 | * @param in input attributes in[0] - separator, in[1..] - attributes to join |
1302 | * @param in input attributes in[0] - separator, in[1..] - attributes to join |
1235 | * @param out output attribute joined attribute as string |
1303 | * @param out output attribute joined attribute as string |
1236 | * @param valid unused |
1304 | * @param valid unused |
1237 | * @returns nothing |
1305 | * @returns nothing |
1238 | */ |
1306 | */ |
1239 | static void |
|
|
1240 | navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1307 | static void navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1241 | { |
1308 | { |
1242 | //dbg(0,"EEnter\n"); |
1309 | ////DBG dbg(0,"EEnter\n"); |
1243 | struct attr attr; |
1310 | struct attr attr; |
1244 | gchar *ret, *sep; |
1311 | gchar *ret, *sep; |
1245 | int i; |
1312 | int i; |
1246 | attr.type=attr_type_string_begin; |
1313 | attr.type = attr_type_string_begin; |
1247 | attr.u.str=NULL; |
1314 | attr.u.str = NULL; |
1248 | if(in[0] && in[1]) { |
1315 | if (in[0] && in[1]) |
|
|
1316 | { |
1249 | sep=attr_to_text(in[0],NULL,1); |
1317 | sep = attr_to_text(in[0], NULL, 1); |
1250 | ret=attr_to_text(in[1],NULL,1); |
1318 | ret = attr_to_text(in[1], NULL, 1); |
1251 | for(i=2;in[i];i++) { |
1319 | for (i = 2; in[i]; i++) |
|
|
1320 | { |
1252 | gchar *in_i=attr_to_text(in[i],NULL,1); |
1321 | gchar *in_i = attr_to_text(in[i], NULL, 1); |
1253 | gchar *r=g_strjoin(sep,ret,in_i,NULL); |
1322 | gchar *r = g_strjoin(sep, ret, in_i, NULL); |
1254 | g_free(in_i); |
1323 | g_free(in_i); |
1255 | g_free(ret); |
1324 | g_free(ret); |
1256 | ret=r; |
1325 | ret = r; |
1257 | } |
1326 | } |
1258 | g_free(sep); |
1327 | g_free(sep); |
1259 | attr.u.str=ret; |
1328 | attr.u.str = ret; |
1260 | if(out) { |
1329 | if (out) |
|
|
1330 | { |
1261 | *out=attr_generic_add_attr(*out, &attr); |
1331 | *out = attr_generic_add_attr(*out, &attr); |
1262 | } |
1332 | } |
1263 | g_free(ret); |
1333 | g_free(ret); |
1264 | } |
1334 | } |
1265 | } |
1335 | } |
1266 | |
1336 | |
… | |
… | |
1272 | * @param in input attributes in[0] - name of executable, in[1..] - parameters |
1342 | * @param in input attributes in[0] - name of executable, in[1..] - parameters |
1273 | * @param out output attribute unused |
1343 | * @param out output attribute unused |
1274 | * @param valid unused |
1344 | * @param valid unused |
1275 | * @returns nothing |
1345 | * @returns nothing |
1276 | */ |
1346 | */ |
1277 | static void |
|
|
1278 | navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1347 | static void navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid) |
1279 | { |
1348 | { |
1280 | //dbg(0,"EEnter\n"); |
1349 | ////DBG dbg(0,"EEnter\n"); |
1281 | int i,j, nparms, nvalid; |
1350 | int i, j, nparms, nvalid; |
1282 | const char ** argv=NULL; |
1351 | const char ** argv = NULL; |
1283 | struct spawn_process_info *pi; |
1352 | struct spawn_process_info *pi; |
1284 | |
1353 | |
1285 | nparms=0; |
1354 | nparms = 0; |
1286 | nvalid=0; |
1355 | nvalid = 0; |
1287 | if(in) { |
1356 | if (in) |
|
|
1357 | { |
1288 | while(in[nparms]) { |
1358 | while (in[nparms]) |
|
|
1359 | { |
1289 | if (in[nparms]->type!=attr_none) |
1360 | if (in[nparms]->type != attr_none) |
1290 | nvalid++; |
1361 | nvalid++; |
1291 | nparms++; |
1362 | nparms++; |
1292 | } |
1363 | } |
1293 | } |
1364 | } |
1294 | |
1365 | |
1295 | if(nvalid>0) { |
1366 | if (nvalid > 0) |
|
|
1367 | { |
1296 | argv=g_new(char*,nvalid+1); |
1368 | argv=g_new(char*,nvalid+1); |
1297 | for(i=0,j=0;in[i];i++) { |
1369 | for (i = 0, j = 0; in[i]; i++) |
|
|
1370 | { |
1298 | if(in[i]->type!=attr_none ) { |
1371 | if (in[i]->type != attr_none) |
|
|
1372 | { |
1299 | argv[j++]=attr_to_text(in[i],NULL,1); |
1373 | argv[j++] = attr_to_text(in[i], NULL, 1); |
|
|
1374 | } |
1300 | } else { |
1375 | else |
|
|
1376 | { |
1301 | dbg(0,"Parameter #%i is attr_none - skipping\n",i); |
1377 | //DBG dbg(0, "Parameter #%i is attr_none - skipping\n", i); |
1302 | } |
|
|
1303 | } |
1378 | } |
|
|
1379 | } |
1304 | argv[j]=NULL; |
1380 | argv[j] = NULL; |
1305 | pi=spawn_process(argv); |
1381 | pi = spawn_process(argv); |
1306 | |
1382 | |
1307 | // spawn_process() testing suite - uncomment following code to test. |
1383 | // spawn_process() testing suite - uncomment following code to test. |
1308 | //sleep(3); |
1384 | //sleep(3); |
1309 | // example of non-blocking wait |
1385 | // example of non-blocking wait |
1310 | //int st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st); |
1386 | //int st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st); |
1311 | // example of blocking wait |
1387 | // example of blocking wait |
1312 | //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st); |
1388 | //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st); |
1313 | // example of wait after process is finished and status is |
1389 | // example of wait after process is finished and status is |
1314 | // already tested |
1390 | // already tested |
1315 | //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st); |
1391 | //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st); |
1316 | // example of wait after process is finished and status is |
1392 | // example of wait after process is finished and status is |
1317 | // already tested - unblocked |
1393 | // already tested - unblocked |
1318 | //st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st); |
1394 | //st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st); |
1319 | |
1395 | |
1320 | // End testing suite |
1396 | // End testing suite |
1321 | spawn_process_info_free(pi); |
1397 | spawn_process_info_free(pi); |
1322 | for(i=0;argv[i];i++) |
1398 | for (i = 0; argv[i]; i++) |
1323 | g_free(argv[i]); |
1399 | g_free(argv[i]); |
1324 | g_free(argv); |
1400 | g_free(argv); |
1325 | } |
1401 | } |
1326 | } |
1402 | } |
1327 | |
1403 | |
1328 | |
|
|
1329 | static struct command_table commands[] = { |
1404 | static struct command_table commands[] = |
|
|
1405 | { |
1330 | {"zoom_in",command_cast(navit_cmd_zoom_in)}, |
1406 | { "zoom_in", command_cast(navit_cmd_zoom_in) }, |
1331 | {"zoom_out",command_cast(navit_cmd_zoom_out)}, |
1407 | { "zoom_out", command_cast(navit_cmd_zoom_out) }, |
1332 | {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)}, |
1408 | { "zoom_to_route", command_cast(navit_cmd_zoom_to_route) }, |
1333 | {"say",command_cast(navit_cmd_say)}, |
1409 | { "say", command_cast(navit_cmd_say) }, |
1334 | {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)}, |
1410 | { "set_center_cursor", command_cast(navit_cmd_set_center_cursor) }, |
1335 | {"set_destination",command_cast(navit_cmd_set_destination)}, |
1411 | { "set_destination", command_cast(navit_cmd_set_destination) }, |
1336 | {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)}, |
1412 | { "announcer_toggle", command_cast(navit_cmd_announcer_toggle) }, |
1337 | {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)}, |
1413 | { "fmt_coordinates", command_cast(navit_cmd_fmt_coordinates) }, |
1338 | {"set_int_var",command_cast(navit_cmd_set_int_var)}, |
1414 | { "set_int_var", command_cast(navit_cmd_set_int_var) }, |
1339 | {"get_int_var",command_cast(navit_cmd_get_int_var)}, |
1415 | { "get_int_var", command_cast(navit_cmd_get_int_var) }, |
1340 | {"push_int",command_cast(navit_cmd_push_int)}, |
1416 | { "push_int", command_cast(navit_cmd_push_int) }, |
1341 | {"pop_int",command_cast(navit_cmd_pop_int)}, |
1417 | { "pop_int", command_cast(navit_cmd_pop_int) }, |
1342 | {"int_stack_size",command_cast(navit_cmd_int_stack_size)}, |
1418 | { "int_stack_size", command_cast(navit_cmd_int_stack_size) }, |
1343 | {"toggle_layer",command_cast(navit_cmd_toggle_layer)}, |
1419 | { "toggle_layer", command_cast(navit_cmd_toggle_layer) }, |
1344 | {"strjoin",command_cast(navit_cmd_strjoin)}, |
1420 | { "strjoin", command_cast(navit_cmd_strjoin) }, |
1345 | {"spawn",command_cast(navit_cmd_spawn)}, |
1421 | { "spawn", command_cast(navit_cmd_spawn) }, |
1346 | {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)}, |
1422 | { "map_add_curr_pos", command_cast(navit_cmd_map_add_curr_pos) }, |
1347 | {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)}, |
1423 | { "map_item_set_attr", command_cast(navit_cmd_map_item_set_attr) }, |
1348 | {"set_attr_var",command_cast(navit_cmd_set_attr_var)}, |
1424 | { "set_attr_var", command_cast(navit_cmd_set_attr_var) }, |
1349 | {"get_attr_var",command_cast(navit_cmd_get_attr_var)}, |
1425 | { "get_attr_var", command_cast(navit_cmd_get_attr_var) }, }; |
1350 | }; |
1426 | |
1351 | |
|
|
1352 | void |
|
|
1353 | navit_command_add_table(struct navit*this_, struct command_table *commands, int count) |
1427 | void navit_command_add_table(struct navit*this_, struct command_table *commands, int count) |
1354 | { |
1428 | { |
1355 | //dbg(0,"EEnter\n"); |
1429 | ////DBG dbg(0,"EEnter\n"); |
1356 | command_add_table(this_->attr_cbl, commands, count, this_); |
1430 | command_add_table(this_->attr_cbl, commands, count, this_); |
1357 | } |
1431 | } |
1358 | |
1432 | |
1359 | struct navit * |
1433 | struct navit * |
1360 | navit_new(struct attr *parent, struct attr **attrs) |
1434 | navit_new(struct attr *parent, struct attr **attrs) |
1361 | { |
1435 | { |
1362 | //dbg(0,"EEnter\n"); |
1436 | ////DBG dbg(0,"EEnter\n"); |
1363 | struct navit *this_=g_new0(struct navit, 1); |
1437 | struct navit *this_=g_new0(struct navit, 1); |
1364 | struct pcoord center; |
1438 | struct pcoord center; |
1365 | struct coord co; |
1439 | struct coord co; |
1366 | struct coord_geo g; |
1440 | struct coord_geo g; |
1367 | enum projection pro=projection_mg; |
1441 | enum projection pro = projection_mg; |
1368 | int zoom = 256; |
1442 | int zoom = 256; |
1369 | g.lat=53.13; |
1443 | g.lat = 53.13; |
1370 | g.lng=11.70; |
1444 | g.lng = 11.70; |
1371 | |
1445 | |
1372 | this_->self.type=attr_navit; |
1446 | this_->self.type = attr_navit; |
1373 | this_->self.u.navit=this_; |
1447 | this_->self.u.navit = this_; |
1374 | this_->attr_cbl=callback_list_new(); |
1448 | this_->attr_cbl = callback_list_new(); |
1375 | |
1449 | |
1376 | this_->orientation=-1; |
1450 | this_->orientation = -1; |
1377 | this_->tracking_flag=1; |
1451 | this_->tracking_flag = 1; |
1378 | this_->recentdest_count=10; |
1452 | this_->recentdest_count = 10; |
1379 | this_->osd_configuration=-1; |
1453 | this_->osd_configuration = -1; |
1380 | |
1454 | |
1381 | // changed default to 1 |
1455 | // changed default to 1 |
1382 | this_->center_timeout = 1; |
1456 | this_->center_timeout = 1; |
1383 | this_->use_mousewheel = 1; |
1457 | this_->use_mousewheel = 1; |
1384 | this_->autozoom_secs = 10; |
1458 | this_->autozoom_secs = 10; |
… | |
… | |
1391 | this_->border = 16; |
1465 | this_->border = 16; |
1392 | |
1466 | |
1393 | this_->trans = transform_new(); |
1467 | this_->trans = transform_new(); |
1394 | this_->trans_cursor = transform_new(); |
1468 | this_->trans_cursor = transform_new(); |
1395 | transform_from_geo(pro, &g, &co); |
1469 | transform_from_geo(pro, &g, &co); |
1396 | center.x=co.x; |
1470 | center.x = co.x; |
1397 | center.y=co.y; |
1471 | center.y = co.y; |
1398 | center.pro = pro; |
1472 | center.pro = pro; |
1399 | |
1473 | |
1400 | dbg(0,"setting center from xmlfile [hardcoded]\n"); |
1474 | //DBG dbg(0, "setting center from xmlfile [hardcoded]\n"); |
1401 | transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0); |
1475 | transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0); |
1402 | |
1476 | |
1403 | // initialze trans_cursor here |
1477 | // initialze trans_cursor here |
1404 | transform_copy(this_->trans, this_->trans_cursor); |
1478 | transform_copy(this_->trans, this_->trans_cursor); |
1405 | // initialze trans_cursor here |
1479 | // initialze trans_cursor here |
1406 | |
1480 | |
1407 | this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans); |
1481 | this_->bookmarks = bookmarks_new(&this_->self, NULL, this_->trans); |
1408 | |
1482 | |
1409 | this_->prevTs=0; |
1483 | this_->prevTs = 0; |
1410 | |
1484 | |
1411 | for (;*attrs; attrs++) { |
1485 | for (; *attrs; attrs++) |
|
|
1486 | { |
1412 | navit_set_attr_do(this_, *attrs, 1); |
1487 | navit_set_attr_do(this_, *attrs, 1); |
1413 | } |
1488 | } |
1414 | this_->displaylist=graphics_displaylist_new(); |
1489 | this_->displaylist = graphics_displaylist_new(); |
1415 | command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_); |
1490 | command_add_table(this_->attr_cbl, commands, sizeof(commands) / sizeof(struct command_table), this_); |
1416 | |
1491 | |
1417 | this_->messages = messagelist_new(attrs); |
1492 | // this_->messages = messagelist_new(attrs); |
1418 | |
1493 | |
1419 | //dbg(0,"111111\n"); |
1494 | ////DBG dbg(0,"111111\n"); |
1420 | |
1495 | |
1421 | return this_; |
1496 | return this_; |
1422 | } |
1497 | } |
1423 | |
1498 | |
1424 | static int |
|
|
1425 | navit_set_gui(struct navit *this_, struct gui *gui) |
1499 | static int navit_set_gui(struct navit *this_, struct gui *gui) |
1426 | { |
1500 | { |
1427 | //dbg(0,"EEnter\n"); |
1501 | ////DBG dbg(0,"EEnter\n"); |
1428 | if (this_->gui) |
1502 | if (this_->gui) |
1429 | return 0; |
1503 | return 0; |
1430 | this_->gui=gui; |
1504 | this_->gui = gui; |
1431 | if (gui_has_main_loop(this_->gui)) { |
1505 | if (gui_has_main_loop(this_->gui)) |
|
|
1506 | { |
1432 | if (! main_loop_gui) { |
1507 | if (!main_loop_gui) |
|
|
1508 | { |
1433 | main_loop_gui=this_->gui; |
1509 | main_loop_gui = this_->gui; |
|
|
1510 | } |
1434 | } else { |
1511 | else |
|
|
1512 | { |
1435 | dbg(0,"gui with main loop already active, ignoring this instance"); |
1513 | //DBG dbg(0, "gui with main loop already active, ignoring this instance"); |
1436 | return 0; |
1514 | return 0; |
1437 | } |
1515 | } |
1438 | } |
1516 | } |
1439 | return 1; |
1517 | return 1; |
1440 | } |
1518 | } |
1441 | |
1519 | |
1442 | void |
|
|
1443 | navit_add_message(struct navit *this_, char *message) |
1520 | void navit_add_message(struct navit *this_, char *message) |
1444 | { |
1521 | { |
1445 | //dbg(0,"EEnter\n"); |
1522 | ////DBG dbg(0,"EEnter\n"); |
1446 | message_new(this_->messages, message); |
1523 | // message_new(this_->messages, message); |
1447 | } |
1524 | } |
1448 | |
1525 | |
1449 | struct message |
|
|
1450 | *navit_get_messages(struct navit *this_) |
1526 | struct message *navit_get_messages(struct navit *this_) |
1451 | { |
1527 | { |
1452 | //dbg(0,"EEnter\n"); |
1528 | ////DBG dbg(0,"EEnter\n"); |
1453 | return message_get(this_->messages); |
1529 | // return message_get(this_->messages); |
1454 | } |
1530 | } |
1455 | |
1531 | |
1456 | static int |
|
|
1457 | navit_set_graphics(struct navit *this_, struct graphics *gra) |
1532 | static int navit_set_graphics(struct navit *this_, struct graphics *gra) |
1458 | { |
1533 | { |
1459 | //dbg(0,"EEnter\n"); |
1534 | ////DBG dbg(0,"EEnter\n"); |
1460 | if (this_->gra) |
1535 | if (this_->gra) |
1461 | return 0; |
1536 | return 0; |
1462 | this_->gra=gra; |
1537 | this_->gra = gra; |
1463 | this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_); |
1538 | this_->resize_callback = callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_); |
1464 | graphics_add_callback(gra, this_->resize_callback); |
1539 | graphics_add_callback(gra, this_->resize_callback); |
1465 | this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_); |
1540 | this_->button_callback = callback_new_attr_1(callback_cast(navit_button), attr_button, this_); |
1466 | graphics_add_callback(gra, this_->button_callback); |
1541 | graphics_add_callback(gra, this_->button_callback); |
1467 | this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_); |
1542 | this_->motion_callback = callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_); |
1468 | graphics_add_callback(gra, this_->motion_callback); |
1543 | graphics_add_callback(gra, this_->motion_callback); |
1469 | this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_); |
1544 | this_->predraw_callback = callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_); |
1470 | graphics_add_callback(gra, this_->predraw_callback); |
1545 | graphics_add_callback(gra, this_->predraw_callback); |
1471 | //dbg(0,"111111111\n"); |
1546 | ////DBG dbg(0,"111111111\n"); |
1472 | return 1; |
1547 | return 1; |
1473 | } |
1548 | } |
1474 | |
1549 | |
1475 | struct graphics * |
1550 | struct graphics * |
1476 | navit_get_graphics(struct navit *this_) |
1551 | navit_get_graphics(struct navit *this_) |
1477 | { |
1552 | { |
1478 | //dbg(0,"EEnter\n"); |
1553 | ////DBG dbg(0,"EEnter\n"); |
1479 | return this_->gra; |
1554 | return this_->gra; |
1480 | } |
1555 | } |
1481 | |
1556 | |
1482 | struct vehicleprofile * |
1557 | struct vehicleprofile * |
1483 | navit_get_vehicleprofile(struct navit *this_) |
1558 | navit_get_vehicleprofile(struct navit *this_) |
1484 | { |
1559 | { |
1485 | //dbg(0,"EEnter\n"); |
1560 | ////DBG dbg(0,"EEnter\n"); |
1486 | return this_->vehicleprofile; |
1561 | return this_->vehicleprofile; |
1487 | } |
1562 | } |
1488 | |
1563 | |
1489 | GList * |
1564 | GList * |
1490 | navit_get_vehicleprofiles(struct navit *this_) |
1565 | navit_get_vehicleprofiles(struct navit *this_) |
1491 | { |
1566 | { |
1492 | //dbg(0,"EEnter\n"); |
1567 | ////DBG dbg(0,"EEnter\n"); |
1493 | return this_->vehicleprofiles; |
1568 | return this_->vehicleprofiles; |
1494 | } |
1569 | } |
1495 | |
1570 | |
1496 | static void |
|
|
1497 | navit_projection_set(struct navit *this_, enum projection pro, int draw) |
1571 | static void navit_projection_set(struct navit *this_, enum projection pro, int draw) |
1498 | { |
1572 | { |
1499 | //dbg(0,"EEnter\n"); |
1573 | ////DBG dbg(0,"EEnter\n"); |
1500 | struct coord_geo g; |
1574 | struct coord_geo g; |
1501 | struct coord *c; |
1575 | struct coord *c; |
1502 | |
1576 | |
1503 | c=transform_center(this_->trans); |
1577 | c = transform_center(this_->trans); |
1504 | transform_to_geo(transform_get_projection(this_->trans), c, &g); |
1578 | transform_to_geo(transform_get_projection(this_->trans), c, &g); |
1505 | transform_set_projection(this_->trans, pro); |
1579 | transform_set_projection(this_->trans, pro); |
1506 | transform_from_geo(pro, &g, c); |
1580 | transform_from_geo(pro, &g, c); |
1507 | if (draw) |
1581 | if (draw) |
1508 | navit_draw(this_); |
1582 | navit_draw(this_); |
… | |
… | |
1514 | * @param navit The navit instance |
1588 | * @param navit The navit instance |
1515 | * @param c The coordinate to start routing to |
1589 | * @param c The coordinate to start routing to |
1516 | * @param description A label which allows the user to later identify this destination in the former destinations selection |
1590 | * @param description A label which allows the user to later identify this destination in the former destinations selection |
1517 | * @returns nothing |
1591 | * @returns nothing |
1518 | */ |
1592 | */ |
1519 | void |
|
|
1520 | navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async) |
1593 | void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async) |
1521 | { |
1594 | { |
1522 | //dbg(0,"EEnter\n"); |
1595 | ////DBG dbg(0,"EEnter\n"); |
1523 | char *destination_file; |
1596 | char *destination_file; |
1524 | if (c) { |
1597 | if (c) |
|
|
1598 | { |
1525 | this_->destination=*c; |
1599 | this_->destination = *c; |
1526 | this_->destination_valid=1; |
1600 | this_->destination_valid = 1; |
1527 | |
|
|
1528 | dbg(1, "navit->navit_set_destination %i\n", c->x); |
1601 | //dbg(0, "navit->navit_set_destination %i\n", c->x); |
1529 | dbg(1, "navit->navit_set_destination %i\n", c->y); |
1602 | //dbg(0, "navit->navit_set_destination %i\n", c->y); |
1530 | |
1603 | } |
1531 | } else |
1604 | else |
|
|
1605 | { |
1532 | this_->destination_valid=0; |
1606 | this_->destination_valid = 0; |
|
|
1607 | } |
1533 | destination_file = bookmarks_get_destination_file(TRUE); |
1608 | //destination_file = bookmarks_get_destination_file(TRUE); |
1534 | bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count); |
1609 | //bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count); |
1535 | g_free(destination_file); |
1610 | //g_free(destination_file); |
1536 | callback_list_call_attr_0(this_->attr_cbl, attr_destination); |
1611 | callback_list_call_attr_0(this_->attr_cbl, attr_destination); |
1537 | if (this_->route) { |
1612 | if (this_->route) |
|
|
1613 | { |
|
|
1614 | //dbg(0, "navit->navit_set_destination 2: %i %i\n", c->x, c->y); |
|
|
1615 | |
1538 | route_set_destination(this_->route, c, async); |
1616 | route_set_destination(this_->route, c, async); |
1539 | |
|
|
1540 | if (this_->ready == 3) |
1617 | if (this_->ready == 3) |
|
|
1618 | { |
1541 | navit_draw(this_); |
1619 | navit_draw(this_); |
|
|
1620 | } |
|
|
1621 | } |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | /** |
|
|
1625 | * add a waypoint to an active route |
|
|
1626 | * |
|
|
1627 | * @param navit The navit instance |
|
|
1628 | * @param c The coordinate of the waypoint |
|
|
1629 | * @param description A dummy string |
|
|
1630 | * @returns nothing |
|
|
1631 | */ |
|
|
1632 | void navit_add_waypoint_to_route(struct navit *this_, struct pcoord *c, const char *description, int async) |
|
|
1633 | { |
|
|
1634 | if (this_->destination_valid == 1) |
|
|
1635 | { |
|
|
1636 | //int count = 0; |
|
|
1637 | //count = g_list_length(this_->route->destinations); |
|
|
1638 | //DBG dbg(0, "count=%d\n", count); |
|
|
1639 | |
|
|
1640 | //dbg(0, "navit->navit_add_waypoint_to_route 1: %i %i\n", c->x, c->y); |
|
|
1641 | |
|
|
1642 | route_add_destination(this_->route, c, async); |
|
|
1643 | |
|
|
1644 | this_->destination = *c; |
|
|
1645 | this_->destination_valid = 1; |
|
|
1646 | } |
|
|
1647 | else |
|
|
1648 | { |
|
|
1649 | //dbg(0, "navit->navit_add_waypoint_to_route 2: %i %i\n", c->x, c->y); |
|
|
1650 | navit_set_destination(this_, c, description, async); |
1542 | } |
1651 | } |
1543 | } |
1652 | } |
1544 | |
1653 | |
1545 | /** |
1654 | /** |
1546 | * Start the route computing to a given set of coordinates including waypoints |
1655 | * Start the route computing to a given set of coordinates including waypoints |
… | |
… | |
1548 | * @param navit The navit instance |
1657 | * @param navit The navit instance |
1549 | * @param c The coordinate to start routing to |
1658 | * @param c The coordinate to start routing to |
1550 | * @param description A label which allows the user to later identify this destination in the former destinations selection |
1659 | * @param description A label which allows the user to later identify this destination in the former destinations selection |
1551 | * @returns nothing |
1660 | * @returns nothing |
1552 | */ |
1661 | */ |
1553 | void |
|
|
1554 | navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async) |
1662 | void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async) |
1555 | { |
1663 | { |
1556 | //dbg(0,"EEnter\n"); |
1664 | ////DBG dbg(0,"EEnter\n"); |
1557 | char *destination_file; |
1665 | char *destination_file; |
1558 | if (c && count) { |
1666 | if (c && count) |
|
|
1667 | { |
1559 | this_->destination=c[count-1]; |
1668 | this_->destination = c[count - 1]; |
1560 | this_->destination_valid=1; |
1669 | this_->destination_valid = 1; |
|
|
1670 | //dbg(0, "navit->navit_set_destinations 1: %i %i\n", c[count-1].x, c[count-1].y); |
|
|
1671 | } |
1561 | } else |
1672 | else |
|
|
1673 | { |
1562 | this_->destination_valid=0; |
1674 | this_->destination_valid = 0; |
|
|
1675 | } |
1563 | destination_file = bookmarks_get_destination_file(TRUE); |
1676 | //destination_file = bookmarks_get_destination_file(TRUE); |
1564 | bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count); |
1677 | //bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count); |
1565 | g_free(destination_file); |
1678 | //g_free(destination_file); |
1566 | callback_list_call_attr_0(this_->attr_cbl, attr_destination); |
1679 | callback_list_call_attr_0(this_->attr_cbl, attr_destination); |
1567 | if (this_->route) { |
1680 | if (this_->route) |
|
|
1681 | { |
1568 | route_set_destinations(this_->route, c, count, async); |
1682 | route_set_destinations(this_->route, c, count, async); |
1569 | |
|
|
1570 | if (this_->ready == 3) |
1683 | if (this_->ready == 3) |
|
|
1684 | { |
1571 | navit_draw(this_); |
1685 | navit_draw(this_); |
|
|
1686 | } |
1572 | } |
1687 | } |
1573 | } |
1688 | } |
1574 | |
1689 | |
1575 | /** |
1690 | /** |
1576 | * @brief Checks if a route is calculated |
1691 | * @brief Checks if a route is calculated |
… | |
… | |
1578 | * This function checks if a route is calculated. |
1693 | * This function checks if a route is calculated. |
1579 | * |
1694 | * |
1580 | * @param this_ The navit struct whose route should be checked. |
1695 | * @param this_ The navit struct whose route should be checked. |
1581 | * @return True if the route is set, false otherwise. |
1696 | * @return True if the route is set, false otherwise. |
1582 | */ |
1697 | */ |
1583 | int |
|
|
1584 | navit_check_route(struct navit *this_) |
1698 | int navit_check_route(struct navit *this_) |
1585 | { |
1699 | { |
1586 | //dbg(0,"EEnter\n"); |
1700 | ////DBG dbg(0,"EEnter\n"); |
1587 | if (this_->route) { |
1701 | if (this_->route) |
|
|
1702 | { |
1588 | return route_get_path_set(this_->route); |
1703 | return route_get_path_set(this_->route); |
1589 | } |
1704 | } |
1590 | |
1705 | |
1591 | return 0; |
1706 | return 0; |
1592 | } |
1707 | } |
1593 | |
1708 | |
1594 | static int |
|
|
1595 | navit_former_destinations_active(struct navit *this_) |
1709 | static int navit_former_destinations_active(struct navit *this_) |
1596 | { |
1710 | { |
1597 | //dbg(0,"EEnter\n"); |
1711 | ////DBG dbg(0,"EEnter\n"); |
|
|
1712 | |
|
|
1713 | return 0; |
|
|
1714 | // disable this function!! |
|
|
1715 | |
|
|
1716 | |
1598 | char *destination_file = bookmarks_get_destination_file(FALSE); |
1717 | char *destination_file = bookmarks_get_destination_file(FALSE); |
1599 | FILE *f; |
1718 | FILE *f; |
1600 | int active=0; |
1719 | int active = 0; |
1601 | char buffer[3]; |
1720 | char buffer[3]; |
1602 | f=fopen(destination_file,"r"); |
1721 | f = fopen(destination_file, "r"); |
1603 | if (f) { |
1722 | if (f) |
|
|
1723 | { |
1604 | if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n')) |
1724 | if (!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0] != '\n' || buffer[1] != '\n')) |
|
|
1725 | { |
1605 | active=1; |
1726 | active = 1; |
|
|
1727 | } |
1606 | fclose(f); |
1728 | fclose(f); |
1607 | } |
1729 | } |
1608 | g_free(destination_file); |
1730 | g_free(destination_file); |
|
|
1731 | |
1609 | return active; |
1732 | return active; |
1610 | } |
1733 | } |
1611 | |
1734 | |
1612 | static void |
|
|
1613 | navit_add_former_destinations_from_file(struct navit *this_) |
1735 | static void navit_add_former_destinations_from_file(struct navit *this_) |
1614 | { |
1736 | { |
1615 | //dbg(0,"EEnter\n"); |
1737 | ////DBG dbg(0,"EEnter\n"); |
1616 | char *destination_file = bookmarks_get_destination_file(FALSE); |
1738 | char *destination_file = bookmarks_get_destination_file(FALSE); |
1617 | struct attr *attrs[4]; |
1739 | struct attr *attrs[4]; |
1618 | struct map_rect *mr; |
1740 | struct map_rect *mr; |
1619 | struct item *item; |
1741 | struct item *item; |
1620 | int i,valid=0,count=0; |
1742 | int i, valid = 0, count = 0; |
1621 | struct coord c[16]; |
1743 | struct coord c[16]; |
1622 | struct pcoord pc[16]; |
1744 | struct pcoord pc[16]; |
1623 | struct attr parent; |
1745 | struct attr parent; |
1624 | struct attr type; |
1746 | struct attr type; |
1625 | struct attr data; |
1747 | struct attr data; |
1626 | struct attr flags; |
1748 | struct attr flags; |
1627 | |
1749 | |
1628 | parent.type=attr_navit; |
1750 | parent.type = attr_navit; |
1629 | parent.u.navit=this_; |
1751 | parent.u.navit = this_; |
1630 | |
1752 | |
1631 | type.type=attr_type; |
1753 | type.type = attr_type; |
1632 | type.u.str="textfile"; |
1754 | type.u.str = "textfile"; |
1633 | |
1755 | |
1634 | data.type=attr_data; |
1756 | data.type = attr_data; |
1635 | data.u.str=destination_file; |
1757 | data.u.str = destination_file; |
1636 | |
1758 | |
1637 | flags.type=attr_flags; |
1759 | flags.type = attr_flags; |
1638 | flags.u.num=1; |
1760 | flags.u.num = 1; |
1639 | |
1761 | |
1640 | attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL; |
1762 | attrs[0] = &type; |
|
|
1763 | attrs[1] = &data; |
|
|
1764 | attrs[2] = &flags; |
|
|
1765 | attrs[3] = NULL; |
1641 | |
1766 | |
1642 | this_->former_destination=map_new(&parent, attrs); |
1767 | this_->former_destination = map_new(&parent, attrs); |
1643 | g_free(destination_file); |
1768 | g_free(destination_file); |
1644 | if (!this_->route || !navit_former_destinations_active(this_)) |
1769 | if (!this_->route || !navit_former_destinations_active(this_)) |
1645 | return; |
1770 | return; |
1646 | mr=map_rect_new(this_->former_destination, NULL); |
1771 | mr = map_rect_new(this_->former_destination, NULL); |
1647 | while ((item=map_rect_get_item(mr))) { |
1772 | while ((item = map_rect_get_item(mr))) |
|
|
1773 | { |
1648 | if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16))) |
1774 | if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count = item_coord_get(item, c, 16))) |
1649 | valid=1; |
1775 | valid = 1; |
1650 | } |
1776 | } |
1651 | map_rect_destroy(mr); |
1777 | map_rect_destroy(mr); |
1652 | if (valid && count > 0) { |
1778 | if (valid && count > 0) |
|
|
1779 | { |
1653 | for (i = 0 ; i < count ; i++) { |
1780 | for (i = 0; i < count; i++) |
|
|
1781 | { |
1654 | pc[i].pro=map_projection(this_->former_destination); |
1782 | pc[i].pro = map_projection(this_->former_destination); |
1655 | pc[i].x=c[i].x; |
1783 | pc[i].x = c[i].x; |
1656 | pc[i].y=c[i].y; |
1784 | pc[i].y = c[i].y; |
1657 | } |
1785 | } |
1658 | if (count == 1) |
1786 | if (count == 1) |
|
|
1787 | { |
1659 | route_set_destination(this_->route, &pc[0], 1); |
1788 | route_set_destination(this_->route, &pc[0], 1); |
|
|
1789 | } |
1660 | else |
1790 | else |
|
|
1791 | { |
1661 | route_set_destinations(this_->route, pc, count, 1); |
1792 | route_set_destinations(this_->route, pc, count, 1); |
|
|
1793 | } |
1662 | this_->destination=pc[count-1]; |
1794 | this_->destination = pc[count - 1]; |
1663 | this_->destination_valid=1; |
1795 | this_->destination_valid = 1; |
1664 | } |
1796 | } |
1665 | } |
1797 | } |
1666 | |
1798 | |
1667 | |
|
|
1668 | void |
|
|
1669 | navit_textfile_debug_log(struct navit *this_, const char *fmt, ...) |
1799 | void navit_textfile_debug_log(struct navit *this_, const char *fmt, ...) |
1670 | { |
1800 | { |
1671 | //dbg(0,"EEnter\n"); |
1801 | ////DBG dbg(0,"EEnter\n"); |
1672 | va_list ap; |
1802 | va_list ap; |
1673 | char *str1,*str2; |
1803 | char *str1, *str2; |
1674 | va_start(ap, fmt); |
1804 | va_start(ap, fmt); |
1675 | if (this_->textfile_debug_log && this_->vehicle) { |
1805 | if (this_->textfile_debug_log && this_->vehicle) |
|
|
1806 | { |
1676 | str1=g_strdup_vprintf(fmt, ap); |
1807 | str1 = g_strdup_vprintf(fmt, ap); |
1677 | str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1); |
1808 | str2 = g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1); |
1678 | log_write(this_->textfile_debug_log, str2, strlen(str2), 0); |
1809 | log_write(this_->textfile_debug_log, str2, strlen(str2), 0); |
1679 | g_free(str2); |
1810 | g_free(str2); |
1680 | g_free(str1); |
1811 | g_free(str1); |
1681 | } |
1812 | } |
1682 | va_end(ap); |
1813 | va_end(ap); |
1683 | } |
1814 | } |
1684 | |
1815 | |
1685 | void |
|
|
1686 | navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...) |
1816 | void navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...) |
1687 | { |
1817 | { |
1688 | //dbg(0,"EEnter\n"); |
1818 | ////DBG dbg(0,"EEnter\n"); |
1689 | va_list ap; |
1819 | va_list ap; |
1690 | char *str1,*str2; |
1820 | char *str1, *str2; |
1691 | va_start(ap, fmt); |
1821 | va_start(ap, fmt); |
1692 | if (this_->textfile_debug_log && this_->vehicle) { |
1822 | if (this_->textfile_debug_log && this_->vehicle) |
|
|
1823 | { |
1693 | str1=g_strdup_vprintf(fmt, ap); |
1824 | str1 = g_strdup_vprintf(fmt, ap); |
1694 | str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1); |
1825 | str2 = g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1); |
1695 | log_write(this_->textfile_debug_log, str2, strlen(str2), 0); |
1826 | log_write(this_->textfile_debug_log, str2, strlen(str2), 0); |
1696 | g_free(str2); |
1827 | g_free(str2); |
1697 | g_free(str1); |
1828 | g_free(str1); |
1698 | } |
1829 | } |
1699 | va_end(ap); |
1830 | va_end(ap); |
1700 | } |
1831 | } |
1701 | |
1832 | |
1702 | void |
|
|
1703 | navit_say(struct navit *this_, char *text) |
1833 | void navit_say(struct navit *this_, char *text) |
1704 | { |
1834 | { |
1705 | //dbg(0,"EEnter\n"); |
1835 | ////DBG dbg(0,"EEnter\n"); |
1706 | if(this_->speech) { |
1836 | if (this_->speech) |
|
|
1837 | { |
1707 | speech_say(this_->speech, text); |
1838 | speech_say(this_->speech, text); |
1708 | } |
1839 | } |
1709 | } |
1840 | } |
1710 | |
1841 | |
1711 | /** |
1842 | /** |
1712 | * @brief Toggles the navigation announcer for navit |
1843 | * @brief Toggles the navigation announcer for navit |
1713 | * @param this_ The navit object |
1844 | * @param this_ The navit object |
1714 | */ |
1845 | */ |
1715 | static void |
|
|
1716 | navit_cmd_announcer_toggle(struct navit *this_) |
1846 | static void navit_cmd_announcer_toggle(struct navit *this_) |
1717 | { |
1847 | { |
1718 | struct attr attr, speechattr; |
1848 | struct attr attr, speechattr; |
1719 | |
1849 | |
1720 | // search for the speech attribute |
1850 | // search for the speech attribute |
1721 | if(!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1851 | if (!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1722 | return; |
1852 | return; |
1723 | // find out if the corresponding attribute attr_active has been set |
1853 | // find out if the corresponding attribute attr_active has been set |
1724 | if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) { |
1854 | if (speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) |
|
|
1855 | { |
1725 | // flip it then... |
1856 | // flip it then... |
1726 | attr.u.num = !attr.u.num; |
1857 | attr.u.num = !attr.u.num; |
1727 | } else { |
1858 | } |
|
|
1859 | else |
|
|
1860 | { |
1728 | // otherwise disable it because voice is enabled by default |
1861 | // otherwise disable it because voice is enabled by default |
1729 | attr.type = attr_active; |
1862 | attr.type = attr_active; |
1730 | attr.u.num = 0; |
1863 | attr.u.num = 0; |
1731 | } |
1864 | } |
1732 | |
1865 | |
1733 | // apply the new state |
1866 | // apply the new state |
1734 | if(!speech_set_attr(speechattr.u.speech, &attr)) |
1867 | if (!speech_set_attr(speechattr.u.speech, &attr)) |
1735 | return; |
1868 | return; |
1736 | |
1869 | |
1737 | // announce that the speech attribute has changed |
1870 | // announce that the speech attribute has changed |
1738 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1871 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1739 | } |
1872 | } |
1740 | |
1873 | |
1741 | |
|
|
1742 | |
|
|
1743 | |
|
|
1744 | void |
|
|
1745 | navit_cmd_announcer_on(struct navit *this_) |
1874 | void navit_cmd_announcer_on(struct navit *this_) |
1746 | { |
1875 | { |
1747 | struct attr attr, speechattr; |
1876 | struct attr attr, speechattr; |
1748 | |
1877 | |
1749 | // search for the speech attribute |
1878 | // search for the speech attribute |
1750 | if(!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1879 | if (!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1751 | return; |
1880 | return; |
1752 | |
1881 | |
1753 | attr.type = attr_active; |
1882 | attr.type = attr_active; |
1754 | attr.u.num = 1; |
1883 | attr.u.num = 1; |
1755 | |
1884 | |
1756 | // apply the new state |
1885 | // apply the new state |
1757 | if(!speech_set_attr(speechattr.u.speech, &attr)) |
1886 | if (!speech_set_attr(speechattr.u.speech, &attr)) |
1758 | return; |
1887 | return; |
1759 | |
1888 | |
1760 | // announce that the speech attribute has changed |
1889 | // announce that the speech attribute has changed |
1761 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1890 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1762 | } |
1891 | } |
1763 | |
1892 | |
1764 | |
|
|
1765 | void |
|
|
1766 | navit_cmd_announcer_off(struct navit *this_) |
1893 | void navit_cmd_announcer_off(struct navit *this_) |
1767 | { |
1894 | { |
1768 | struct attr attr, speechattr; |
1895 | struct attr attr, speechattr; |
1769 | |
1896 | |
1770 | // search for the speech attribute |
1897 | // search for the speech attribute |
1771 | if(!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1898 | if (!navit_get_attr(this_, attr_speech, &speechattr, NULL)) |
1772 | return; |
1899 | return; |
1773 | |
1900 | |
1774 | attr.type = attr_active; |
1901 | attr.type = attr_active; |
1775 | attr.u.num = 0; |
1902 | attr.u.num = 0; |
1776 | |
1903 | |
1777 | // apply the new state |
1904 | // apply the new state |
1778 | if(!speech_set_attr(speechattr.u.speech, &attr)) |
1905 | if (!speech_set_attr(speechattr.u.speech, &attr)) |
1779 | return; |
1906 | return; |
1780 | |
1907 | |
1781 | // announce that the speech attribute has changed |
1908 | // announce that the speech attribute has changed |
1782 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1909 | callback_list_call_attr_0(this_->attr_cbl, attr_speech); |
1783 | } |
1910 | } |
1784 | |
1911 | |
1785 | |
|
|
1786 | |
|
|
1787 | void |
|
|
1788 | navit_speak(struct navit *this_) |
1912 | void navit_speak(struct navit *this_) |
1789 | { |
1913 | { |
1790 | //dbg(0,"EEnter\n"); |
1914 | ////DBG dbg(0,"EEnter\n"); |
1791 | struct navigation *nav=this_->navigation; |
1915 | struct navigation *nav = this_->navigation; |
1792 | struct map *map=NULL; |
1916 | struct map *map = NULL; |
1793 | struct map_rect *mr=NULL; |
1917 | struct map_rect *mr = NULL; |
1794 | struct item *item; |
1918 | struct item *item; |
1795 | struct attr attr; |
1919 | struct attr attr; |
1796 | |
1920 | |
1797 | if (!speech_get_attr(this_->speech, attr_active, &attr, NULL)) |
1921 | if (!speech_get_attr(this_->speech, attr_active, &attr, NULL)) |
1798 | attr.u.num = 1; |
1922 | attr.u.num = 1; |
1799 | dbg(1, "this_.speech->active %i\n", attr.u.num); |
1923 | // dbg(1, "this_.speech->active %i\n", attr.u.num); |
1800 | if(!attr.u.num) |
1924 | if (!attr.u.num) |
1801 | return; |
1925 | return; |
1802 | |
1926 | |
1803 | if (nav) |
1927 | if (nav) |
1804 | map=navigation_get_map(nav); |
1928 | map = navigation_get_map(nav); |
1805 | if (map) |
1929 | if (map) |
1806 | mr=map_rect_new(map, NULL); |
1930 | mr = map_rect_new(map, NULL); |
1807 | if (mr) { |
1931 | if (mr) |
|
|
1932 | { |
1808 | while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none)); |
1933 | while ((item = map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none)) |
|
|
1934 | ; |
1809 | if (item && item_attr_get(item, attr_navigation_speech, &attr)) { |
1935 | if (item && item_attr_get(item, attr_navigation_speech, &attr)) |
|
|
1936 | { |
1810 | speech_say(this_->speech, attr.u.str); |
1937 | speech_say(this_->speech, attr.u.str); |
1811 | navit_add_message(this_, attr.u.str); |
1938 | //navit_add_message(this_, attr.u.str); |
1812 | navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str); |
1939 | navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str); |
1813 | } |
1940 | } |
1814 | map_rect_destroy(mr); |
1941 | map_rect_destroy(mr); |
1815 | } |
1942 | } |
1816 | } |
1943 | } |
1817 | |
1944 | |
1818 | static void |
|
|
1819 | navit_window_roadbook_update(struct navit *this_) |
1945 | static void navit_window_roadbook_update(struct navit *this_) |
1820 | { |
1946 | { |
1821 | //dbg(0,"EEnter\n"); |
1947 | ////DBG dbg(0,"EEnter\n"); |
1822 | struct navigation *nav=this_->navigation; |
1948 | struct navigation *nav = this_->navigation; |
1823 | struct map *map=NULL; |
1949 | struct map *map = NULL; |
1824 | struct map_rect *mr=NULL; |
1950 | struct map_rect *mr = NULL; |
1825 | struct item *item; |
1951 | struct item *item; |
1826 | struct attr attr; |
1952 | struct attr attr; |
1827 | struct param_list param[5]; |
1953 | struct param_list param[5]; |
1828 | int secs; |
1954 | int secs; |
1829 | |
1955 | |
1830 | dbg(1,"enter\n"); |
1956 | // dbg(1, "enter\n"); |
1831 | datawindow_mode(this_->roadbook_window, 1); |
1957 | datawindow_mode(this_->roadbook_window, 1); |
1832 | if (nav) |
1958 | if (nav) |
1833 | map=navigation_get_map(nav); |
1959 | map = navigation_get_map(nav); |
1834 | if (map) |
1960 | if (map) |
1835 | mr=map_rect_new(map, NULL); |
1961 | mr = map_rect_new(map, NULL); |
1836 | //dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr); |
1962 | ////DBG dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr); |
1837 | if (mr) { |
1963 | if (mr) |
|
|
1964 | { |
1838 | //dbg(0,"while loop\n"); |
1965 | ////DBG dbg(0,"while loop\n"); |
1839 | while ((item=map_rect_get_item(mr))) { |
1966 | while ((item = map_rect_get_item(mr))) |
|
|
1967 | { |
1840 | //dbg(0,"item=%p\n", item); |
1968 | ////DBG dbg(0,"item=%p\n", item); |
1841 | attr.u.str=NULL; |
1969 | attr.u.str = NULL; |
1842 | if (item->type != type_nav_position) { |
1970 | if (item->type != type_nav_position) |
|
|
1971 | { |
1843 | item_attr_get(item, attr_navigation_long, &attr); |
1972 | item_attr_get(item, attr_navigation_long, &attr); |
1844 | if (attr.u.str == NULL) { |
1973 | if (attr.u.str == NULL) |
|
|
1974 | { |
1845 | continue; |
1975 | continue; |
1846 | } |
1976 | } |
1847 | dbg(2, "Command='%s'\n", attr.u.str); |
1977 | dbg(2, "Command='%s'\n", attr.u.str); |
1848 | param[0].value=g_strdup(attr.u.str); |
1978 | param[0].value = g_strdup(attr.u.str); |
|
|
1979 | } |
1849 | } else |
1980 | else |
1850 | param[0].value=_("Position"); |
1981 | param[0].value = _("Position"); |
1851 | param[0].name=_("Command"); |
1982 | param[0].name = _("Command"); |
1852 | |
1983 | |
1853 | item_attr_get(item, attr_length, &attr); |
1984 | item_attr_get(item, attr_length, &attr); |
1854 | dbg(2, "Length=%d\n", attr.u.num); |
1985 | dbg(2, "Length=%d\n", attr.u.num); |
1855 | param[1].name=_("Length"); |
1986 | param[1].name = _("Length"); |
1856 | |
1987 | |
1857 | if ( attr.u.num >= 2000 ) |
1988 | if (attr.u.num >= 2000) |
1858 | { |
1989 | { |
1859 | param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") ); |
1990 | param[1].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km")); |
1860 | } |
1991 | } |
1861 | else |
1992 | else |
1862 | { |
1993 | { |
1863 | param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m")); |
1994 | param[1].value = g_strdup_printf("%7d %s", attr.u.num, _("m")); |
1864 | } |
1995 | } |
1865 | |
1996 | |
1866 | item_attr_get(item, attr_time, &attr); |
1997 | item_attr_get(item, attr_time, &attr); |
1867 | dbg(2, "Time=%d\n", attr.u.num); |
1998 | dbg(2, "Time=%d\n", attr.u.num); |
1868 | secs=attr.u.num/10; |
1999 | secs = attr.u.num / 10; |
1869 | param[2].name=_("Time"); |
2000 | param[2].name = _("Time"); |
1870 | if ( secs >= 3600 ) |
2001 | if (secs >= 3600) |
1871 | { |
2002 | { |
1872 | param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60); |
2003 | param[2].value = g_strdup_printf("%d:%02d:%02d", secs / 60, (secs / 60) % 60, secs % 60); |
1873 | } |
2004 | } |
1874 | else |
2005 | else |
1875 | { |
2006 | { |
1876 | param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60); |
2007 | param[2].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60); |
1877 | } |
2008 | } |
1878 | |
2009 | |
1879 | item_attr_get(item, attr_destination_length, &attr); |
2010 | item_attr_get(item, attr_destination_length, &attr); |
1880 | dbg(2, "Destlength=%d\n", attr.u.num); |
2011 | dbg(2, "Destlength=%d\n", attr.u.num); |
1881 | param[3].name=_("Destination Length"); |
2012 | param[3].name = _("Destination Length"); |
1882 | if ( attr.u.num >= 2000 ) |
2013 | if (attr.u.num >= 2000) |
1883 | { |
2014 | { |
1884 | param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") ); |
2015 | param[3].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km")); |
1885 | } |
2016 | } |
1886 | else |
2017 | else |
1887 | { |
2018 | { |
1888 | param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m")); |
2019 | param[3].value = g_strdup_printf("%d %s", attr.u.num, _("m")); |
1889 | } |
2020 | } |
1890 | |
2021 | |
1891 | item_attr_get(item, attr_destination_time, &attr); |
2022 | item_attr_get(item, attr_destination_time, &attr); |
1892 | dbg(2, "Desttime=%d\n", attr.u.num); |
2023 | dbg(2, "Desttime=%d\n", attr.u.num); |
1893 | secs=attr.u.num/10; |
2024 | secs = attr.u.num / 10; |
1894 | param[4].name=_("Destination Time"); |
2025 | param[4].name = _("Destination Time"); |
1895 | if ( secs >= 3600 ) |
2026 | if (secs >= 3600) |
1896 | { |
2027 | { |
1897 | param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60); |
2028 | param[4].value = g_strdup_printf("%d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60); |
1898 | } |
2029 | } |
1899 | else |
2030 | else |
1900 | { |
2031 | { |
1901 | param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60); |
2032 | param[4].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60); |
1902 | } |
2033 | } |
1903 | datawindow_add(this_->roadbook_window, param, 5); |
2034 | datawindow_add(this_->roadbook_window, param, 5); |
1904 | } |
2035 | } |
1905 | map_rect_destroy(mr); |
2036 | map_rect_destroy(mr); |
1906 | } |
2037 | } |
1907 | datawindow_mode(this_->roadbook_window, 0); |
2038 | datawindow_mode(this_->roadbook_window, 0); |
1908 | } |
2039 | } |
1909 | |
2040 | |
1910 | void |
|
|
1911 | navit_window_roadbook_destroy(struct navit *this_) |
2041 | void navit_window_roadbook_destroy(struct navit *this_) |
1912 | { |
2042 | { |
1913 | //dbg(0, "enter\n"); |
2043 | ////DBG dbg(0, "enter\n"); |
1914 | navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback); |
2044 | navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback); |
1915 | this_->roadbook_window=NULL; |
2045 | this_->roadbook_window = NULL; |
1916 | this_->roadbook_callback=NULL; |
2046 | this_->roadbook_callback = NULL; |
1917 | } |
2047 | } |
1918 | void |
|
|
1919 | navit_window_roadbook_new(struct navit *this_) |
2048 | void navit_window_roadbook_new(struct navit *this_) |
1920 | { |
2049 | { |
1921 | if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) { |
2050 | if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) |
|
|
2051 | { |
1922 | return; |
2052 | return; |
1923 | } |
2053 | } |
1924 | |
2054 | |
1925 | this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_); |
2055 | this_->roadbook_callback = callback_new_1(callback_cast(navit_window_roadbook_update), this_); |
1926 | navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback); |
2056 | navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback); |
1927 | this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_)); |
2057 | this_->roadbook_window = gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_)); |
1928 | navit_window_roadbook_update(this_); |
2058 | navit_window_roadbook_update(this_); |
1929 | } |
2059 | } |
1930 | |
2060 | |
1931 | void |
|
|
1932 | navit_remove_all_maps(struct navit *this_) |
2061 | void navit_remove_all_maps(struct navit *this_) |
1933 | { |
2062 | { |
1934 | struct mapset *ms; |
2063 | struct mapset *ms; |
1935 | struct map *map3; |
2064 | struct map *map3; |
1936 | |
2065 | |
|
|
2066 | // first: stop navigation! |
|
|
2067 | //if (global_navit->destination_valid != 0) |
|
|
2068 | //{ |
|
|
2069 | navit_set_destination(global_navit, NULL, NULL, 0); |
|
|
2070 | //} |
|
|
2071 | |
|
|
2072 | |
|
|
2073 | if (this_->route) |
|
|
2074 | { |
|
|
2075 | struct attr callback; |
|
|
2076 | // this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_); |
|
|
2077 | callback.type=attr_callback; |
|
|
2078 | callback.u.callback=this_->route_cb; |
|
|
2079 | route_remove_attr(this_->route, &callback); |
|
|
2080 | |
|
|
2081 | this_->route->ms = NULL; |
|
|
2082 | // route_set_mapset(this_->route, ms); |
|
|
2083 | // route_set_projection(this_->route, transform_get_projection(this_->trans)); |
|
|
2084 | |
|
|
2085 | //*********route_destroy(this_->route); |
|
|
2086 | |
|
|
2087 | //route_path_destroy(this_->route->path2,1); |
|
|
2088 | //this_->route->path2 = NULL; |
|
|
2089 | //route_graph_destroy(this_->route->graph); |
|
|
2090 | //this_->route->graph=NULL; |
|
|
2091 | } |
|
|
2092 | |
|
|
2093 | /* |
|
|
2094 | map_rect_destroy(displaylist->mr); |
|
|
2095 | if (!route_selection) |
|
|
2096 | map_selection_destroy(displaylist->sel); |
|
|
2097 | mapset_close(displaylist->msh); |
|
|
2098 | displaylist->mr=NULL; |
|
|
2099 | displaylist->sel=NULL; |
|
|
2100 | displaylist->m=NULL; |
|
|
2101 | displaylist->msh=NULL; |
|
|
2102 | profile(1,"callback\n"); |
|
|
2103 | callback_call_1(displaylist->cb, cancel); |
|
|
2104 | */ |
|
|
2105 | |
|
|
2106 | struct displaylist *dl = navit_get_displaylist(this_); |
|
|
2107 | dl->m = NULL; |
|
|
2108 | dl->msh = NULL; |
|
|
2109 | |
1937 | if (this_->mapsets) |
2110 | if (this_->mapsets) |
1938 | { |
2111 | { |
1939 | struct mapset_handle *msh; |
2112 | struct mapset_handle *msh; |
1940 | ms=this_->mapsets->data; |
2113 | ms = this_->mapsets->data; |
1941 | msh=mapset_open(ms); |
2114 | msh = mapset_open(ms); |
|
|
2115 | ////DBG dbg(0,"removing map bb0\n"); |
1942 | while (msh && (map3=mapset_next(msh, 0))) |
2116 | while (msh && (map3 = mapset_next(msh, 0))) |
1943 | { |
2117 | { |
|
|
2118 | ////DBG dbg(0,"removing map bb1\n"); |
1944 | struct attr map_name_attr; |
2119 | struct attr map_name_attr; |
1945 | if (map_get_attr(map3,attr_name, &map_name_attr,NULL)) |
2120 | if (map_get_attr(map3, attr_name, &map_name_attr, NULL)) |
1946 | { |
2121 | { |
1947 | //dbg(0,"map name=%s",map_name_attr.u.str); |
2122 | //DBG dbg(0, "map name=%s", map_name_attr.u.str); |
1948 | if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0) |
2123 | if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0) |
1949 | { |
2124 | { |
1950 | //dbg(0,"removing map\n"); |
2125 | //DBG dbg(0, "removing map a0\n"); |
|
|
2126 | struct attr active; |
|
|
2127 | active.type = attr_active; |
|
|
2128 | active.u.num = 0; |
|
|
2129 | //map_set_attr(map3, &active); |
|
|
2130 | |
|
|
2131 | //DBG dbg(0, "removing map a1\n"); |
1951 | struct attr map_attr; |
2132 | struct attr map_attr; |
1952 | map_attr.u.map=map3; |
2133 | map_attr.u.map = map3; |
1953 | map_attr.type=attr_map; |
2134 | map_attr.type = attr_map; |
1954 | mapset_remove_attr(ms, &map_attr); |
2135 | mapset_remove_attr(ms, &map_attr); |
|
|
2136 | |
|
|
2137 | //DBG dbg(0, "removing map a2\n"); |
|
|
2138 | map3->refcount = 1; |
1955 | map_destroy(map3); |
2139 | map_destroy(map3); |
|
|
2140 | //DBG dbg(0, "removing map a3\n"); |
|
|
2141 | map3 = NULL; |
1956 | } |
2142 | } |
1957 | } |
2143 | } |
1958 | } |
2144 | } |
1959 | mapset_close(msh); |
2145 | mapset_close(msh); |
|
|
2146 | //DBG dbg(0, "removing map bb4\n"); |
1960 | } |
2147 | } |
1961 | } |
|
|
1962 | |
2148 | |
1963 | void |
2149 | dl->ms = this_->mapsets->data; |
|
|
2150 | |
|
|
2151 | // int async = 0; |
|
|
2152 | // transform_setup_source_rect(this_->trans); |
|
|
2153 | // graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1); |
|
|
2154 | //this_->displaylist->ms=this_->mapsets->data; |
|
|
2155 | |
|
|
2156 | } |
|
|
2157 | |
1964 | navit_add_all_maps(struct navit *this_) |
2158 | void navit_add_all_maps(struct navit *this_) |
1965 | { |
2159 | { |
1966 | struct mapset *ms; |
|
|
1967 | struct map *map3; |
2160 | struct map *map3; |
1968 | |
2161 | |
1969 | if (this_->mapsets) |
2162 | if (this_->mapsets) |
1970 | { |
2163 | { |
|
|
2164 | //DBG dbg(0, "xADDx all maps - start\n"); |
|
|
2165 | |
|
|
2166 | struct mapset *ms; |
1971 | ms=this_->mapsets->data; |
2167 | ms = this_->mapsets->data; |
1972 | |
2168 | |
1973 | struct attr type; |
2169 | struct attr type; |
1974 | struct attr parent; |
2170 | struct attr parent; |
1975 | struct attr data; |
2171 | struct attr data; |
1976 | struct attr flags; |
2172 | struct attr flags; |
1977 | struct map *map2; |
2173 | struct map *map2; |
1978 | struct attr map2_attr; |
2174 | struct attr map2_attr; |
1979 | struct attr *attrs[4]; |
2175 | struct attr *attrs[4]; |
1980 | char *map_file; |
2176 | char *map_file; |
1981 | |
2177 | |
1982 | parent.type=attr_navit; |
2178 | parent.type = attr_navit; |
1983 | parent.u.navit=this_; |
2179 | parent.u.navit = this_; |
1984 | type.type=attr_type; |
2180 | type.type = attr_type; |
1985 | type.u.str="binfile"; |
2181 | type.u.str = "binfile"; |
1986 | data.type=attr_data; |
2182 | data.type = attr_data; |
1987 | map_file=g_strdup("/sdcard/zanavi/maps/borders.bin"); |
2183 | map_file = g_strdup_printf("%sborders.bin", navit_maps_dir); |
1988 | data.u.str=map_file; |
2184 | data.u.str = map_file; |
1989 | |
2185 | |
1990 | //dbg(0,"map name=%s",map_file); |
2186 | ////DBG dbg(0,"map name=%s",map_file); |
1991 | |
2187 | |
1992 | flags.type=attr_flags; |
2188 | flags.type = attr_flags; |
1993 | flags.u.num=0; |
2189 | flags.u.num = 0; |
1994 | attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL; |
2190 | attrs[0] = &type; |
|
|
2191 | attrs[1] = &data; |
|
|
2192 | attrs[2] = &flags; |
|
|
2193 | attrs[3] = NULL; |
1995 | map2=map_new(&parent, attrs); |
2194 | map2 = map_new(&parent, attrs); |
1996 | if (map2) |
2195 | if (map2) |
1997 | { |
2196 | { |
1998 | map2_attr.u.data=map2; |
2197 | map2_attr.u.data = map2; |
1999 | map2_attr.type=attr_map; |
2198 | map2_attr.type = attr_map; |
2000 | mapset_add_attr_name(ms, &map2_attr); |
2199 | // mapset_add_attr_name(ms, &map2_attr); |
|
|
2200 | mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/borders.bin"); |
|
|
2201 | struct attr active; |
|
|
2202 | active.type = attr_active; |
|
|
2203 | active.u.num = 0; |
|
|
2204 | //map_set_attr(map2, &active); |
2001 | } |
2205 | } |
2002 | g_free(map_file); |
2206 | g_free(map_file); |
2003 | |
2207 | |
2004 | parent.type=attr_navit; |
2208 | parent.type = attr_navit; |
2005 | parent.u.navit=this_; |
2209 | parent.u.navit = this_; |
2006 | type.type=attr_type; |
2210 | type.type = attr_type; |
2007 | type.u.str="binfile"; |
2211 | type.u.str = "binfile"; |
2008 | data.type=attr_data; |
2212 | data.type = attr_data; |
2009 | map_file=g_strdup("/sdcard/zanavi/maps/coastline.bin"); |
2213 | map_file = g_strdup_printf("%scoastline.bin", navit_maps_dir); |
2010 | data.u.str=map_file; |
2214 | data.u.str = map_file; |
2011 | |
2215 | |
2012 | //dbg(0,"map name=%s",map_file); |
2216 | ////DBG dbg(0,"map name=%s",map_file); |
2013 | |
2217 | |
2014 | flags.type=attr_flags; |
2218 | flags.type = attr_flags; |
2015 | flags.u.num=0; |
2219 | flags.u.num = 0; |
2016 | attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL; |
2220 | attrs[0] = &type; |
|
|
2221 | attrs[1] = &data; |
|
|
2222 | attrs[2] = &flags; |
|
|
2223 | attrs[3] = NULL; |
2017 | map2=map_new(&parent, attrs); |
2224 | map2 = map_new(&parent, attrs); |
2018 | if (map2) |
2225 | if (map2) |
2019 | { |
2226 | { |
2020 | map2_attr.u.data=map2; |
2227 | map2_attr.u.data = map2; |
2021 | map2_attr.type=attr_map; |
2228 | map2_attr.type = attr_map; |
2022 | mapset_add_attr_name(ms, &map2_attr); |
2229 | // mapset_add_attr_name(ms, &map2_attr); |
|
|
2230 | mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/coastline.bin"); |
|
|
2231 | struct attr active; |
|
|
2232 | active.type = attr_active; |
|
|
2233 | active.u.num = 0; |
|
|
2234 | //map_set_attr(map2, &active); |
2023 | } |
2235 | } |
2024 | g_free(map_file); |
2236 | g_free(map_file); |
2025 | |
2237 | |
2026 | int i=1; |
2238 | int i = 1; |
2027 | for(i = 1; i < 10;i++) |
2239 | for (i = 1; i < 10; i++) |
2028 | { |
2240 | { |
2029 | struct map *map22; |
2241 | struct map *map22; |
2030 | struct attr map22_attr; |
2242 | struct attr map22_attr; |
2031 | parent.type=attr_navit; |
2243 | parent.type = attr_navit; |
2032 | parent.u.navit=this_; |
2244 | parent.u.navit = this_; |
2033 | type.type=attr_type; |
2245 | type.type = attr_type; |
2034 | type.u.str="binfile"; |
2246 | type.u.str = "binfile"; |
2035 | data.type=attr_data; |
2247 | data.type = attr_data; |
2036 | map_file=g_strdup_printf("/sdcard/zanavi/maps/navitmap_00%d.bin",i); |
2248 | map_file = g_strdup_printf("%snavitmap_00%d.bin", navit_maps_dir, i); |
2037 | data.u.str=map_file; |
2249 | data.u.str = map_file; |
2038 | //dbg(0,"map name=%s",map_file); |
|
|
2039 | flags.type=attr_flags; |
2250 | flags.type = attr_flags; |
2040 | flags.u.num=0; |
2251 | flags.u.num = 0; |
2041 | attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL; |
2252 | attrs[0] = &type; |
|
|
2253 | attrs[1] = &data; |
|
|
2254 | attrs[2] = &flags; |
|
|
2255 | attrs[3] = NULL; |
2042 | map22=map_new(&parent, attrs); |
2256 | map22 = map_new(&parent, attrs); |
2043 | if (map22) |
2257 | if (map22) |
2044 | { |
2258 | { |
|
|
2259 | //DBG dbg(0, "*add* map name=%s\n", map_file); |
2045 | map22_attr.u.data=map22; |
2260 | map22_attr.u.data = map22; |
2046 | map22_attr.type=attr_map; |
2261 | map22_attr.type = attr_map; |
2047 | mapset_add_attr_name(ms, &map22_attr); |
2262 | // mapset_add_attr_name(ms, &map22_attr); |
|
|
2263 | char *map_name_str; |
|
|
2264 | map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_00%d.bin", i); |
|
|
2265 | mapset_add_attr_name_str(ms, &map22_attr, map_name_str); |
|
|
2266 | struct attr active; |
|
|
2267 | active.type = attr_active; |
|
|
2268 | active.u.num = 0; |
|
|
2269 | //map_set_attr(map22, &active); |
|
|
2270 | g_free(map_name_str); |
2048 | } |
2271 | } |
2049 | g_free(map_file); |
2272 | g_free(map_file); |
2050 | } |
2273 | } |
2051 | |
2274 | |
2052 | i=10; |
2275 | i = 10; |
2053 | for(i = 10; i < 21;i++) |
2276 | for (i = 10; i < 21; i++) |
2054 | { |
2277 | { |
2055 | parent.type=attr_navit; |
2278 | parent.type = attr_navit; |
2056 | parent.u.navit=this_; |
2279 | parent.u.navit = this_; |
2057 | type.type=attr_type; |
2280 | type.type = attr_type; |
2058 | type.u.str="binfile"; |
2281 | type.u.str = "binfile"; |
2059 | data.type=attr_data; |
2282 | data.type = attr_data; |
2060 | map_file=g_strdup_printf("/sdcard/zanavi/maps/navitmap_0%d.bin",i); |
2283 | map_file = g_strdup_printf("%snavitmap_0%d.bin", navit_maps_dir, i); |
2061 | data.u.str=map_file; |
2284 | data.u.str = map_file; |
2062 | //dbg(0,"map name=%s",map_file); |
2285 | ////DBG dbg(0,"map name=%s",map_file); |
2063 | flags.type=attr_flags; |
2286 | flags.type = attr_flags; |
2064 | flags.u.num=0; |
2287 | flags.u.num = 0; |
2065 | attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL; |
2288 | attrs[0] = &type; |
|
|
2289 | attrs[1] = &data; |
|
|
2290 | attrs[2] = &flags; |
|
|
2291 | attrs[3] = NULL; |
2066 | map2=map_new(&parent, attrs); |
2292 | map2 = map_new(&parent, attrs); |
2067 | if (map2) |
2293 | if (map2) |
2068 | { |
2294 | { |
2069 | map2_attr.u.data=map2; |
2295 | map2_attr.u.data = map2; |
2070 | map2_attr.type=attr_map; |
2296 | map2_attr.type = attr_map; |
2071 | mapset_add_attr_name(ms, &map2_attr); |
2297 | // mapset_add_attr_name(ms, &map2_attr); |
|
|
2298 | char *map_name_str; |
|
|
2299 | map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_0%d.bin", i); |
|
|
2300 | mapset_add_attr_name_str(ms, &map2_attr, map_name_str); |
|
|
2301 | struct attr active; |
|
|
2302 | active.type = attr_active; |
|
|
2303 | active.u.num = 0; |
|
|
2304 | //map_set_attr(map2, &active); |
|
|
2305 | g_free(map_name_str); |
2072 | } |
2306 | } |
2073 | g_free(map_file); |
2307 | g_free(map_file); |
2074 | } |
2308 | } |
2075 | } |
2309 | } |
2076 | } |
|
|
2077 | |
2310 | |
2078 | void |
2311 | /* |
2079 | navit_reload_maps(struct navit *this_) |
2312 | if (this_->mapsets) |
2080 | { |
2313 | { |
2081 | navit_remove_all_maps(this_); |
2314 | struct mapset_handle *msh; |
2082 | navit_add_all_maps(this_); |
2315 | struct map *map; |
2083 | } |
|
|
2084 | |
|
|
2085 | void |
|
|
2086 | navit_init(struct navit *this_) |
|
|
2087 | { |
|
|
2088 | //dbg(0,"EEnter\n"); |
|
|
2089 | struct mapset *ms; |
2316 | struct mapset *ms; |
2090 | struct map *map; |
|
|
2091 | int callback; |
|
|
2092 | char *center_file; |
|
|
2093 | |
2317 | |
2094 | dbg(0,"enter gui %p graphics %p\n",this_->gui,this_->gra); |
2318 | //DBG dbg(0,"xx ms callbacks xx\n"); |
2095 | |
2319 | |
2096 | if (!this_->gui && !(this_->flags & 2)) { |
|
|
2097 | dbg(0,"no gui\n"); |
|
|
2098 | navit_destroy(this_); |
|
|
2099 | return; |
|
|
2100 | } |
|
|
2101 | if (!this_->gra && !(this_->flags & 1)) { |
|
|
2102 | dbg(0,"no graphics\n"); |
|
|
2103 | navit_destroy(this_); |
|
|
2104 | return; |
|
|
2105 | } |
|
|
2106 | dbg(0,"Connecting gui to graphics\n"); |
|
|
2107 | if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) { |
|
|
2108 | struct attr attr_type_gui, attr_type_graphics; |
|
|
2109 | gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL); |
|
|
2110 | graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL); |
|
|
2111 | dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str); |
|
|
2112 | // dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n"); |
|
|
2113 | // dbg(0," for explanations and solutions\n"); |
|
|
2114 | |
|
|
2115 | navit_destroy(this_); |
|
|
2116 | return; |
|
|
2117 | } |
|
|
2118 | if (this_->speech && this_->navigation) { |
|
|
2119 | struct attr speech; |
|
|
2120 | speech.type=attr_speech; |
|
|
2121 | speech.u.speech=this_->speech; |
|
|
2122 | navigation_set_attr(this_->navigation, &speech); |
|
|
2123 | } |
|
|
2124 | dbg(0,"Initializing graphics\n"); |
|
|
2125 | dbg(0,"Setting Vehicle\n"); |
|
|
2126 | navit_set_vehicle(this_, this_->vehicle); |
|
|
2127 | dbg(0,"Adding dynamic maps to mapset %p\n",this_->mapsets); |
|
|
2128 | if (this_->mapsets) { |
|
|
2129 | struct mapset_handle *msh; |
|
|
2130 | ms=this_->mapsets->data; |
2320 | ms=this_->mapsets->data; |
2131 | this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
2321 | this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
2132 | msh=mapset_open(ms); |
2322 | msh=mapset_open(ms); |
2133 | while (msh && (map=mapset_next(msh, 0))) { |
2323 | while (msh && (map=mapset_next(msh, 0))) |
|
|
2324 | { |
2134 | //pass new callback instance for each map in the mapset to make map callback list destruction work correctly |
2325 | //pass new callback instance for each map in the mapset to make map callback list destruction work correctly |
2135 | struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
2326 | struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
2136 | map_add_callback(map, pcb); |
2327 | map_add_callback(map, pcb); |
2137 | } |
2328 | } |
2138 | mapset_close(msh); |
2329 | mapset_close(msh); |
2139 | |
2330 | } |
|
|
2331 | */ |
|
|
2332 | |
|
|
2333 | struct attr parent; |
|
|
2334 | parent.type = attr_navit; |
|
|
2335 | parent.u.navit = global_navit; |
|
|
2336 | |
|
|
2337 | struct attr *attrs_r[2]; |
|
|
2338 | attrs_r[0] = NULL; |
|
|
2339 | attrs_r[1] = NULL; |
|
|
2340 | |
|
|
2341 | //***this_->route = route_new(&parent, attrs_r); |
|
|
2342 | |
|
|
2343 | |
|
|
2344 | //int async = 0; |
|
|
2345 | //transform_setup_source_rect(this_->trans); |
|
|
2346 | //graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1); |
|
|
2347 | |
|
|
2348 | struct displaylist *dl = navit_get_displaylist(this_); |
|
|
2349 | dl->ms = this_->mapsets->data; |
|
|
2350 | dl->m = NULL; |
|
|
2351 | dl->msh = NULL; |
|
|
2352 | |
2140 | if (this_->route) { |
2353 | if (this_->route) |
2141 | if ((map=route_get_map(this_->route))) { |
2354 | { |
2142 | struct attr map_a,map_name; |
2355 | struct mapset *ms; |
2143 | map_a.type=attr_map; |
2356 | ms = this_->mapsets->data; |
2144 | map_a.u.map=map; |
|
|
2145 | map_name.type=attr_name; |
|
|
2146 | map_name.u.str="_ms_route"; |
|
|
2147 | map_set_attr(map_a.u.map, &map_name); |
|
|
2148 | mapset_add_attr(ms, &map_a); |
|
|
2149 | } |
|
|
2150 | if ((map=route_get_graph_map(this_->route))) { |
|
|
2151 | struct attr map_a,active,map_name; |
|
|
2152 | map_a.type=attr_map; |
|
|
2153 | map_a.u.map=map; |
|
|
2154 | active.type=attr_active; |
|
|
2155 | active.u.num=0; |
|
|
2156 | map_name.type=attr_name; |
|
|
2157 | map_name.u.str="_ms_route_graph"; |
|
|
2158 | map_set_attr(map_a.u.map, &map_name); |
|
|
2159 | mapset_add_attr(ms, &map_a); |
|
|
2160 | map_set_attr(map, &active); |
|
|
2161 | } |
|
|
2162 | route_set_mapset(this_->route, ms); |
2357 | route_set_mapset(this_->route, ms); |
2163 | route_set_projection(this_->route, transform_get_projection(this_->trans)); |
2358 | |
2164 | } |
|
|
2165 | if (this_->tracking) { |
|
|
2166 | tracking_set_mapset(this_->tracking, ms); |
|
|
2167 | if (this_->route) |
|
|
2168 | tracking_set_route(this_->tracking, this_->route); |
|
|
2169 | } |
|
|
2170 | if (this_->navigation) { |
|
|
2171 | if ((map=navigation_get_map(this_->navigation))) { |
|
|
2172 | struct attr map_a,active,map_name; |
|
|
2173 | map_a.type=attr_map; |
|
|
2174 | map_a.u.map=map; |
|
|
2175 | active.type=attr_active; |
|
|
2176 | active.u.num=0; |
|
|
2177 | map_name.type=attr_name; |
|
|
2178 | map_name.u.str="_ms_navigation"; |
|
|
2179 | map_set_attr(map_a.u.map, &map_name); |
|
|
2180 | mapset_add_attr(ms, &map_a); |
|
|
2181 | map_set_attr(map, &active); |
|
|
2182 | } |
|
|
2183 | } |
|
|
2184 | if (this_->tracking) { |
|
|
2185 | if ((map=tracking_get_map(this_->tracking))) { |
|
|
2186 | struct attr map_a,active,map_name; |
|
|
2187 | map_a.type=attr_map; |
|
|
2188 | map_a.u.map=map; |
|
|
2189 | active.type=attr_active; |
|
|
2190 | active.u.num=0; |
|
|
2191 | map_name.type=attr_name; |
|
|
2192 | map_name.u.str="_ms_tracking"; |
|
|
2193 | map_set_attr(map_a.u.map, &map_name); |
|
|
2194 | mapset_add_attr(ms, &map_a); |
|
|
2195 | map_set_attr(map, &active); |
|
|
2196 | } |
|
|
2197 | } |
|
|
2198 | // *DISABLED* navit_add_former_destinations_from_file(this_); |
|
|
2199 | } |
|
|
2200 | if (this_->route) { |
|
|
2201 | struct attr callback; |
2359 | struct attr callback; |
2202 | this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_); |
2360 | this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_); |
2203 | callback.type=attr_callback; |
2361 | callback.type=attr_callback; |
2204 | callback.u.callback=this_->route_cb; |
2362 | callback.u.callback=this_->route_cb; |
2205 | route_add_attr(this_->route, &callback); |
2363 | route_add_attr(this_->route, &callback); |
|
|
2364 | // ***** route_set_projection(this_->route, transform_get_projection(this_->trans)); |
|
|
2365 | } |
|
|
2366 | |
|
|
2367 | if (this_->tracking) |
|
|
2368 | { |
|
|
2369 | struct mapset *ms; |
|
|
2370 | ms = this_->mapsets->data; |
|
|
2371 | |
|
|
2372 | tracking_set_mapset(this_->tracking, ms); |
|
|
2373 | if (this_->route) |
|
|
2374 | { |
|
|
2375 | tracking_set_route(this_->tracking, this_->route); |
2206 | } |
2376 | } |
|
|
2377 | } |
|
|
2378 | |
|
|
2379 | |
|
|
2380 | } |
|
|
2381 | |
|
|
2382 | void navit_reload_maps(struct navit *this_) |
|
|
2383 | { |
|
|
2384 | navit_remove_all_maps(this_); |
|
|
2385 | navit_add_all_maps(this_); |
|
|
2386 | } |
|
|
2387 | |
|
|
2388 | void navit_init(struct navit *this_) |
|
|
2389 | { |
|
|
2390 | ////DBG dbg(0,"EEnter\n"); |
|
|
2391 | struct mapset *ms; |
|
|
2392 | struct map *map; |
|
|
2393 | int callback; |
|
|
2394 | char *center_file; |
|
|
2395 | |
|
|
2396 | // default value |
|
|
2397 | navit_maps_dir = "/sdcard/zanavi/maps/"; |
|
|
2398 | |
|
|
2399 | global_img_waypoint = NULL; |
|
|
2400 | |
|
|
2401 | //DBG dbg(0, "enter gui %p graphics %p\n", this_->gui, this_->gra); |
|
|
2402 | |
|
|
2403 | if (!this_->gui && !(this_->flags & 2)) |
|
|
2404 | { |
|
|
2405 | dbg(0, "no gui\n"); |
|
|
2406 | navit_destroy(this_); |
|
|
2407 | return; |
|
|
2408 | } |
|
|
2409 | |
|
|
2410 | if (!this_->gra && !(this_->flags & 1)) |
|
|
2411 | { |
|
|
2412 | dbg(0, "no graphics\n"); |
|
|
2413 | navit_destroy(this_); |
|
|
2414 | return; |
|
|
2415 | } |
|
|
2416 | |
|
|
2417 | //DBG dbg(0, "Connecting gui to graphics\n"); |
|
|
2418 | |
|
|
2419 | if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) |
|
|
2420 | { |
|
|
2421 | struct attr attr_type_gui, attr_type_graphics; |
|
|
2422 | gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL); |
|
|
2423 | graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL); |
|
|
2424 | //DBG dbg(0, "failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str); |
|
|
2425 | // //DBG dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n"); |
|
|
2426 | // //DBG dbg(0," for explanations and solutions\n"); |
|
|
2427 | |
|
|
2428 | dbg(0,"failed to connect to graphics\n"); |
|
|
2429 | navit_destroy(this_); |
|
|
2430 | return; |
|
|
2431 | } |
|
|
2432 | |
|
|
2433 | if (this_->speech && this_->navigation) |
|
|
2434 | { |
|
|
2435 | struct attr speech; |
|
|
2436 | speech.type = attr_speech; |
|
|
2437 | speech.u.speech = this_->speech; |
|
|
2438 | navigation_set_attr(this_->navigation, &speech); |
|
|
2439 | } |
|
|
2440 | |
|
|
2441 | //DBG dbg(0, "Initializing graphics\n"); |
|
|
2442 | //DBG dbg(0, "Setting Vehicle\n"); |
|
|
2443 | navit_set_vehicle(this_, this_->vehicle); |
|
|
2444 | //DBG dbg(0, "Adding dynamic maps to mapset %p\n", this_->mapsets); |
|
|
2445 | |
|
|
2446 | if (this_->mapsets) |
|
|
2447 | { |
|
|
2448 | struct mapset_handle *msh; |
|
|
2449 | ms = this_->mapsets->data; |
|
|
2450 | // **D** // this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
|
|
2451 | msh = mapset_open(ms); |
|
|
2452 | while (msh && (map = mapset_next(msh, 0))) |
|
|
2453 | { |
|
|
2454 | //pass new callback instance for each map in the mapset to make map callback list destruction work correctly |
|
|
2455 | // **D** // struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_); |
|
|
2456 | // **D** // map_add_callback(map, pcb); |
|
|
2457 | } |
|
|
2458 | mapset_close(msh); |
|
|
2459 | |
|
|
2460 | if (this_->route) |
|
|
2461 | { |
|
|
2462 | if ((map = route_get_map(this_->route))) |
|
|
2463 | { |
|
|
2464 | struct attr map_a, map_name; |
|
|
2465 | map_a.type = attr_map; |
|
|
2466 | map_a.u.map = map; |
|
|
2467 | map_name.type = attr_name; |
|
|
2468 | map_name.u.str = "_ms_route"; |
|
|
2469 | map_set_attr(map_a.u.map, &map_name); |
|
|
2470 | mapset_add_attr(ms, &map_a); |
|
|
2471 | } |
|
|
2472 | |
|
|
2473 | if ((map = route_get_graph_map(this_->route))) |
|
|
2474 | { |
|
|
2475 | struct attr map_a, active, map_name; |
|
|
2476 | map_a.type = attr_map; |
|
|
2477 | map_a.u.map = map; |
|
|
2478 | active.type = attr_active; |
|
|
2479 | active.u.num = 0; |
|
|
2480 | map_name.type = attr_name; |
|
|
2481 | map_name.u.str = "_ms_route_graph"; |
|
|
2482 | map_set_attr(map_a.u.map, &map_name); |
|
|
2483 | mapset_add_attr(ms, &map_a); |
|
|
2484 | map_set_attr(map, &active); |
|
|
2485 | } |
|
|
2486 | route_set_mapset(this_->route, ms); |
|
|
2487 | route_set_projection(this_->route, transform_get_projection(this_->trans)); |
|
|
2488 | } |
|
|
2489 | |
|
|
2490 | if (this_->tracking) |
|
|
2491 | { |
|
|
2492 | tracking_set_mapset(this_->tracking, ms); |
|
|
2493 | if (this_->route) |
|
|
2494 | { |
|
|
2495 | tracking_set_route(this_->tracking, this_->route); |
|
|
2496 | } |
|
|
2497 | } |
|
|
2498 | |
|
|
2499 | if (this_->navigation) |
|
|
2500 | { |
|
|
2501 | if ((map = navigation_get_map(this_->navigation))) |
|
|
2502 | { |
|
|
2503 | struct attr map_a, active, map_name; |
|
|
2504 | map_a.type = attr_map; |
|
|
2505 | map_a.u.map = map; |
|
|
2506 | active.type = attr_active; |
|
|
2507 | active.u.num = 0; |
|
|
2508 | map_name.type = attr_name; |
|
|
2509 | map_name.u.str = "_ms_navigation"; |
|
|
2510 | map_set_attr(map_a.u.map, &map_name); |
|
|
2511 | mapset_add_attr(ms, &map_a); |
|
|
2512 | map_set_attr(map, &active); |
|
|
2513 | } |
|
|
2514 | } |
|
|
2515 | |
|
|
2516 | if (this_->tracking) |
|
|
2517 | { |
|
|
2518 | if ((map = tracking_get_map(this_->tracking))) |
|
|
2519 | { |
|
|
2520 | struct attr map_a, active, map_name; |
|
|
2521 | map_a.type = attr_map; |
|
|
2522 | map_a.u.map = map; |
|
|
2523 | active.type = attr_active; |
|
|
2524 | active.u.num = 0; |
|
|
2525 | map_name.type = attr_name; |
|
|
2526 | map_name.u.str = "_ms_tracking"; |
|
|
2527 | map_set_attr(map_a.u.map, &map_name); |
|
|
2528 | mapset_add_attr(ms, &map_a); |
|
|
2529 | map_set_attr(map, &active); |
|
|
2530 | } |
|
|
2531 | } |
|
|
2532 | // *DISABLED* navit_add_former_destinations_from_file(this_); |
|
|
2533 | } |
|
|
2534 | |
|
|
2535 | if (this_->route) |
|
|
2536 | { |
|
|
2537 | struct attr callback; |
|
|
2538 | this_->route_cb = callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_); |
|
|
2539 | callback.type = attr_callback; |
|
|
2540 | callback.u.callback = this_->route_cb; |
|
|
2541 | route_add_attr(this_->route, &callback); |
|
|
2542 | } |
|
|
2543 | |
2207 | if (this_->navigation) { |
2544 | if (this_->navigation) |
|
|
2545 | { |
2208 | if (this_->speech) { |
2546 | if (this_->speech) |
|
|
2547 | { |
2209 | this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_); |
2548 | this_->nav_speech_cb = callback_new_1(callback_cast(navit_speak), this_); |
2210 | navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb); |
2549 | navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb); |
2211 | } |
2550 | } |
|
|
2551 | |
2212 | if (this_->route) |
2552 | if (this_->route) |
|
|
2553 | { |
2213 | navigation_set_route(this_->navigation, this_->route); |
2554 | navigation_set_route(this_->navigation, this_->route); |
2214 | } |
2555 | } |
|
|
2556 | } |
|
|
2557 | |
2215 | dbg(0,"Setting Center\n"); |
2558 | dbg(0, "Setting Center\n"); |
2216 | center_file = bookmarks_get_center_file(FALSE); |
2559 | center_file = bookmarks_get_center_file(FALSE); |
|
|
2560 | //dbg(0, "g0\n"); |
2217 | bookmarks_set_center_from_file(this_->bookmarks, center_file); |
2561 | bookmarks_set_center_from_file(this_->bookmarks, center_file); |
2218 | g_free(center_file); |
2562 | g_free(center_file); |
2219 | #if 0 |
2563 | #if 0 |
2220 | if (this_->menubar) { |
2564 | if (this_->menubar) |
|
|
2565 | { |
2221 | men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL); |
2566 | men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL); |
2222 | if (men) { |
2567 | if (men) |
|
|
2568 | { |
2223 | navit_add_menu_windows_items(this_, men); |
2569 | navit_add_menu_windows_items(this_, men); |
2224 | } |
2570 | } |
2225 | } |
2571 | } |
2226 | #endif |
2572 | #endif |
2227 | global_navit=this_; |
2573 | global_navit = this_; |
2228 | #if 0 |
2574 | #if 0 |
2229 | navit_window_roadbook_new(this_); |
2575 | navit_window_roadbook_new(this_); |
2230 | navit_window_items_new(this_); |
2576 | navit_window_items_new(this_); |
2231 | #endif |
2577 | #endif |
2232 | |
2578 | |
|
|
2579 | //dbg(0, "g1\n"); |
2233 | messagelist_init(this_->messages); |
2580 | //messagelist_init(this_->messages); |
2234 | |
2581 | |
|
|
2582 | //dbg(0, "g2\n"); |
2235 | navit_set_cursors(this_); |
2583 | navit_set_cursors(this_); |
2236 | |
2584 | |
2237 | callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_); |
2585 | callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_); |
2238 | callback=(this_->ready == 2); |
2586 | callback = (this_->ready == 2); |
2239 | dbg(0,"pre this_->ready=%d\n",this_->ready); |
2587 | //DBG dbg(0, "pre this_->ready=%d\n", this_->ready); |
2240 | this_->ready|=1; |
2588 | this_->ready |= 1; |
2241 | dbg(0,"set this_->ready=%d\n",this_->ready); |
2589 | //DBG dbg(0, "set this_->ready=%d\n", this_->ready); |
2242 | //dbg(0,"ready=%d\n",this_->ready); |
2590 | ////DBG dbg(0,"ready=%d\n",this_->ready); |
2243 | if (this_->ready == 3) |
2591 | if (this_->ready == 3) |
2244 | { |
2592 | { |
2245 | //dbg(0,"navit_draw_async_003\n"); |
2593 | ////DBG dbg(0,"navit_draw_async_003\n"); |
2246 | navit_draw_async(this_, 1); |
2594 | navit_draw_async(this_, 1); |
2247 | } |
2595 | } |
|
|
2596 | |
2248 | if (callback) |
2597 | if (callback) |
|
|
2598 | { |
2249 | callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_); |
2599 | callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_); |
|
|
2600 | } |
2250 | #if 0 |
2601 | #if 0 |
2251 | routech_test(this_); |
2602 | routech_test(this_); |
2252 | #endif |
2603 | #endif |
2253 | //dbg(0,"1111111111\n"); |
2604 | //dbg(0, "1111111111\n"); |
2254 | } |
2605 | } |
2255 | |
2606 | |
2256 | void |
|
|
2257 | navit_zoom_to_rect(struct navit *this_, struct coord_rect *r) |
2607 | void navit_zoom_to_rect(struct navit *this_, struct coord_rect *r) |
2258 | { |
2608 | { |
2259 | //dbg(0,"EEnter\n"); |
2609 | ////DBG dbg(0,"EEnter\n"); |
2260 | struct coord c; |
2610 | struct coord c; |
2261 | int scale=16; |
2611 | int scale = 16; |
2262 | |
2612 | |
2263 | c.x=(r->rl.x+r->lu.x)/2; |
2613 | c.x = (r->rl.x + r->lu.x) / 2; |
2264 | c.y=(r->rl.y+r->lu.y)/2; |
2614 | c.y = (r->rl.y + r->lu.y) / 2; |
2265 | transform_set_center(this_->trans, &c); |
2615 | transform_set_center(this_->trans, &c); |
2266 | dbg(1,"%x,%x-%x,%x\n", r->rl.x,r->rl.y,r->lu.x,r->lu.y); |
2616 | // dbg(1, "%x,%x-%x,%x\n", r->rl.x, r->rl.y, r->lu.x, r->lu.y); |
2267 | while (scale < 1<<20) { |
2617 | while (scale < 1 << 20) |
|
|
2618 | { |
2268 | struct point p1,p2; |
2619 | struct point p1, p2; |
2269 | transform_set_scale(this_->trans, scale); |
2620 | transform_set_scale(this_->trans, scale); |
2270 | transform_setup_source_rect(this_->trans); |
2621 | transform_setup_source_rect(this_->trans); |
2271 | transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL); |
2622 | transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL); |
2272 | transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL); |
2623 | transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL); |
2273 | dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y); |
2624 | // dbg(1, "%d,%d-%d,%d\n", p1.x, p1.y, p2.x, p2.y); |
2274 | if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w || |
2625 | if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w || p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h) |
2275 | p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h) |
|
|
2276 | scale*=2; |
2626 | scale *= 2; |
2277 | else |
2627 | else |
2278 | break; |
2628 | break; |
2279 | |
2629 | |
2280 | } |
2630 | } |
2281 | if (this_->ready == 3) |
2631 | if (this_->ready == 3) |
2282 | { |
2632 | { |
2283 | //dbg(0,"navit_draw_async_004\n"); |
2633 | ////DBG dbg(0,"navit_draw_async_004\n"); |
2284 | navit_draw_async(this_,0); |
2634 | navit_draw_async(this_, 0); |
2285 | } |
2635 | } |
2286 | } |
2636 | } |
2287 | |
2637 | |
2288 | void |
|
|
2289 | navit_zoom_to_route(struct navit *this_, int orientation) |
2638 | void navit_zoom_to_route(struct navit *this_, int orientation) |
2290 | { |
2639 | { |
2291 | //dbg(0,"EEnter\n"); |
2640 | ////DBG dbg(0,"EEnter\n"); |
2292 | struct map *map; |
2641 | struct map *map; |
2293 | struct map_rect *mr=NULL; |
2642 | struct map_rect *mr = NULL; |
2294 | struct item *item; |
2643 | struct item *item; |
2295 | struct coord c; |
2644 | struct coord c; |
2296 | struct coord_rect r; |
2645 | struct coord_rect r; |
2297 | int count=0; |
2646 | int count = 0; |
2298 | if (! this_->route) |
2647 | if (!this_->route) |
2299 | return; |
2648 | return; |
2300 | dbg(1,"enter\n"); |
2649 | // dbg(1, "enter\n"); |
2301 | map=route_get_map(this_->route); |
2650 | map = route_get_map(this_->route); |
2302 | dbg(1,"map=%p\n",map); |
2651 | // dbg(1, "map=%p\n", map); |
2303 | if (map) |
2652 | if (map) |
2304 | mr=map_rect_new(map, NULL); |
2653 | mr = map_rect_new(map, NULL); |
2305 | dbg(1,"mr=%p\n",mr); |
2654 | // dbg(1, "mr=%p\n", mr); |
2306 | if (mr) { |
2655 | if (mr) |
|
|
2656 | { |
2307 | while ((item=map_rect_get_item(mr))) { |
2657 | while ((item = map_rect_get_item(mr))) |
|
|
2658 | { |
2308 | dbg(1,"item=%s\n", item_to_name(item->type)); |
2659 | // dbg(1, "item=%s\n", item_to_name(item->type)); |
2309 | while (item_coord_get(item, &c, 1)) { |
2660 | while (item_coord_get(item, &c, 1)) |
|
|
2661 | { |
2310 | dbg(1,"coord\n"); |
2662 | // dbg(1, "coord\n"); |
2311 | if (!count) |
2663 | if (!count) |
2312 | r.lu=r.rl=c; |
2664 | r.lu = r.rl = c; |
2313 | else |
2665 | else |
2314 | coord_rect_extend(&r, &c); |
2666 | coord_rect_extend(&r, &c); |
2315 | count++; |
2667 | count++; |
2316 | } |
2668 | } |
2317 | } |
2669 | } |
2318 | map_rect_destroy(mr); |
2670 | map_rect_destroy(mr); |
2319 | } |
2671 | } |
2320 | if (! count) |
2672 | if (!count) |
2321 | return; |
2673 | return; |
2322 | if (orientation != -1) |
2674 | if (orientation != -1) |
2323 | transform_set_yaw(this_->trans, orientation); |
2675 | transform_set_yaw(this_->trans, orientation); |
2324 | navit_zoom_to_rect(this_, &r); |
2676 | navit_zoom_to_rect(this_, &r); |
2325 | } |
2677 | } |
2326 | |
2678 | |
2327 | static void |
|
|
2328 | navit_cmd_zoom_to_route(struct navit *this) |
2679 | static void navit_cmd_zoom_to_route(struct navit *this) |
2329 | { |
2680 | { |
2330 | //dbg(0,"EEnter\n"); |
2681 | ////DBG dbg(0,"EEnter\n"); |
2331 | navit_zoom_to_route(this, 0); |
2682 | navit_zoom_to_route(this, 0); |
2332 | } |
2683 | } |
2333 | |
|
|
2334 | |
2684 | |
2335 | /** |
2685 | /** |
2336 | * show point on map |
2686 | * show point on map |
2337 | * |
2687 | * |
2338 | * @param navit The navit instance |
2688 | * @param navit The navit instance |
2339 | * @param center The point where to center the map, including its projection |
2689 | * @param center The point where to center the map, including its projection |
2340 | * @returns nothing |
2690 | * @returns nothing |
2341 | */ |
2691 | */ |
2342 | void |
|
|
2343 | navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout) |
2692 | void navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout) |
2344 | { |
2693 | { |
2345 | //dbg(0,"EEnter\n"); |
2694 | ////DBG dbg(0,"EEnter\n"); |
2346 | struct coord *c=transform_center(this_->trans); |
2695 | struct coord *c = transform_center(this_->trans); |
2347 | struct coord c1,c2; |
2696 | struct coord c1, c2; |
2348 | enum projection pro = transform_get_projection(this_->trans); |
2697 | enum projection pro = transform_get_projection(this_->trans); |
2349 | if (pro != center->pro) { |
2698 | if (pro != center->pro) |
|
|
2699 | { |
2350 | c1.x = center->x; |
2700 | c1.x = center->x; |
2351 | c1.y = center->y; |
2701 | c1.y = center->y; |
2352 | transform_from_to(&c1, center->pro, &c2, pro); |
2702 | transform_from_to(&c1, center->pro, &c2, pro); |
2353 | } else { |
2703 | } |
|
|
2704 | else |
|
|
2705 | { |
2354 | c2.x = center->x; |
2706 | c2.x = center->x; |
2355 | c2.y = center->y; |
2707 | c2.y = center->y; |
2356 | } |
2708 | } |
2357 | *c=c2; |
2709 | *c = c2; |
2358 | if (set_timeout) |
2710 | if (set_timeout) |
|
|
2711 | { |
2359 | navit_set_timeout(this_); |
2712 | navit_set_timeout(this_); |
|
|
2713 | } |
2360 | if (this_->ready == 3) |
2714 | if (this_->ready == 3) |
|
|
2715 | { |
2361 | navit_draw(this_); |
2716 | navit_draw(this_); |
|
|
2717 | } |
2362 | } |
2718 | } |
2363 | |
2719 | |
2364 | static void |
|
|
2365 | navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout) |
2720 | static void navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout) |
2366 | { |
2721 | { |
2367 | //dbg(0,"EEnter\n"); |
2722 | ////DBG dbg(0,"EEnter\n"); |
2368 | int width, height; |
2723 | int width, height; |
2369 | struct point po; |
2724 | struct point po; |
2370 | transform_set_center(this_->trans, c); |
2725 | transform_set_center(this_->trans, c); |
2371 | transform_get_size(this_->trans, &width, &height); |
2726 | transform_get_size(this_->trans, &width, &height); |
2372 | po.x=width/2; |
2727 | po.x = width / 2; |
2373 | po.y=height/2; |
2728 | po.y = height / 2; |
2374 | update_transformation(this_->trans, &po, p, NULL); |
2729 | update_transformation(this_->trans, &po, p, NULL); |
2375 | if (set_timeout) |
2730 | if (set_timeout) |
|
|
2731 | { |
2376 | navit_set_timeout(this_); |
2732 | navit_set_timeout(this_); |
|
|
2733 | } |
2377 | } |
2734 | } |
2378 | |
2735 | |
2379 | /** |
2736 | /** |
2380 | * Links all vehicles to a cursor depending on the current profile. |
2737 | * Links all vehicles to a cursor depending on the current profile. |
2381 | * |
2738 | * |
2382 | * @param this_ A navit instance |
2739 | * @param this_ A navit instance |
2383 | * @author Ralph Sennhauser (10/2009) |
2740 | * @author Ralph Sennhauser (10/2009) |
2384 | */ |
2741 | */ |
2385 | static void |
|
|
2386 | navit_set_cursors(struct navit *this_) |
2742 | void navit_set_cursors(struct navit *this_) |
2387 | { |
2743 | { |
2388 | //dbg(0,"EEnter\n"); |
|
|
2389 | struct attr name; |
2744 | struct attr name; |
2390 | struct navit_vehicle *nv; |
2745 | struct navit_vehicle *nv; |
2391 | struct cursor *c; |
2746 | struct cursor *c; |
2392 | GList *v; |
2747 | GList *v; |
2393 | |
2748 | |
|
|
2749 | //dbg(0, "Enter\n"); |
|
|
2750 | |
2394 | v=g_list_first(this_->vehicles); // GList of navit_vehicles |
2751 | v = g_list_first(this_->vehicles); // GList of navit_vehicles |
2395 | while (v) { |
2752 | while (v) |
|
|
2753 | { |
|
|
2754 | dbg(0, "* found vehicle *\n"); |
2396 | nv=v->data; |
2755 | nv = v->data; |
2397 | if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) { |
2756 | if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) |
|
|
2757 | { |
2398 | if (!strcmp(name.u.str,"none")) |
2758 | if (!strcmp(name.u.str, "none")) |
|
|
2759 | { |
2399 | c=NULL; |
2760 | c = NULL; |
|
|
2761 | } |
2400 | else |
2762 | else |
|
|
2763 | { |
2401 | c=layout_get_cursor(this_->layout_current, name.u.str); |
2764 | c = layout_get_cursor(this_->layout_current, name.u.str); |
|
|
2765 | } |
|
|
2766 | } |
2402 | } else |
2767 | else |
|
|
2768 | { |
2403 | c=layout_get_cursor(this_->layout_current, "default"); |
2769 | c = layout_get_cursor(this_->layout_current, "default"); |
|
|
2770 | } |
2404 | vehicle_set_cursor(nv->vehicle, c, 0); |
2771 | vehicle_set_cursor(nv->vehicle, c, 0); |
2405 | v=g_list_next(v); |
2772 | v = g_list_next(v); |
2406 | } |
2773 | } |
2407 | return; |
2774 | return; |
2408 | } |
2775 | } |
2409 | |
2776 | |
2410 | static int |
2777 | void navit_remove_cursors(struct navit *this_) |
2411 | navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir) |
|
|
2412 | { |
2778 | { |
|
|
2779 | struct attr name; |
|
|
2780 | struct navit_vehicle *nv; |
|
|
2781 | struct cursor *c; |
|
|
2782 | GList *v; |
|
|
2783 | |
2413 | //dbg(0,"EEnter\n"); |
2784 | //dbg(0, "Enter\n"); |
|
|
2785 | name.type = attr_cursor; |
|
|
2786 | |
|
|
2787 | v = g_list_first(this_->vehicles); // GList of navit_vehicles |
|
|
2788 | while (v) |
|
|
2789 | { |
|
|
2790 | dbg(0, "* found vehicle *\n"); |
|
|
2791 | nv = v->data; |
|
|
2792 | vehicle_remove_attr(nv->vehicle, &name); |
|
|
2793 | v = g_list_next(v); |
|
|
2794 | } |
|
|
2795 | return; |
|
|
2796 | } |
|
|
2797 | |
|
|
2798 | static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir) |
|
|
2799 | { |
|
|
2800 | ////DBG dbg(0,"EEnter\n"); |
2414 | int width, height; |
2801 | int width, height; |
2415 | struct navit_vehicle *nv=this_->vehicle; |
2802 | struct navit_vehicle *nv = this_->vehicle; |
2416 | |
2803 | |
2417 | float offset=this_->radius; // Cursor offset from the center of the screen (percent). |
2804 | float offset = this_->radius; // Cursor offset from the center of the screen (percent). |
2418 | #if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */ |
2805 | #if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */ |
2419 | float min_offset = 0.; // Percent offset at min_offset_speed. |
2806 | float min_offset = 0.; // Percent offset at min_offset_speed. |
2420 | float max_offset = 30.; // Percent offset at max_offset_speed. |
2807 | float max_offset = 30.; // Percent offset at max_offset_speed. |
2421 | int min_offset_speed = 2; // Speed in km/h |
2808 | int min_offset_speed = 2; // Speed in km/h |
2422 | int max_offset_speed = 50; // Speed ini km/h |
2809 | int max_offset_speed = 50; // Speed ini km/h |
2423 | // Calculate cursor offset from the center of the screen, upon speed. |
2810 | // Calculate cursor offset from the center of the screen, upon speed. |
2424 | if (nv->speed <= min_offset_speed) { |
2811 | if (nv->speed <= min_offset_speed) |
2425 | offset = min_offset; |
2812 | { |
|
|
2813 | offset = min_offset; |
|
|
2814 | } |
2426 | } else if (nv->speed > max_offset_speed) { |
2815 | else if (nv->speed > max_offset_speed) |
2427 | offset = max_offset; |
2816 | { |
2428 | } else { |
2817 | offset = max_offset; |
|
|
2818 | } |
|
|
2819 | else |
|
|
2820 | { |
2429 | offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed); |
2821 | offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed); |
2430 | } |
2822 | } |
2431 | #endif |
2823 | #endif |
2432 | |
2824 | |
2433 | transform_get_size(this_->trans, &width, &height); |
2825 | transform_get_size(this_->trans, &width, &height); |
2434 | if (this_->orientation == -1 || keep_orientation) { |
2826 | if (this_->orientation == -1 || keep_orientation) |
|
|
2827 | { |
2435 | p->x=50*width/100; |
2828 | p->x = 50 * width / 100; |
2436 | p->y=(50 + offset)*height/100; |
2829 | p->y = (50 + offset) * height / 100; |
2437 | if (dir) |
2830 | if (dir) |
2438 | *dir=keep_orientation?this_->orientation:nv->dir; |
2831 | *dir = keep_orientation ? this_->orientation : nv->dir; |
2439 | } else { |
2832 | } |
|
|
2833 | else |
|
|
2834 | { |
2440 | int mdir; |
2835 | int mdir; |
2441 | if (this_->tracking && this_->tracking_flag) { |
2836 | if (this_->tracking && this_->tracking_flag) |
|
|
2837 | { |
2442 | mdir = tracking_get_angle(this_->tracking) - this_->orientation; |
2838 | mdir = tracking_get_angle(this_->tracking) - this_->orientation; |
|
|
2839 | } |
2443 | } else { |
2840 | else |
|
|
2841 | { |
2444 | mdir=nv->dir-this_->orientation; |
2842 | mdir = nv->dir - this_->orientation; |
2445 | } |
2843 | } |
2446 | |
2844 | |
2447 | p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100; |
2845 | p->x = (50 - offset * sin(M_PI * mdir / 180.)) * width / 100; |
2448 | p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100; |
2846 | p->y = (50 + offset * cos(M_PI * mdir / 180.)) * height / 100; |
2449 | if (dir) |
2847 | if (dir) |
2450 | *dir=this_->orientation; |
2848 | *dir = this_->orientation; |
2451 | } |
2849 | } |
2452 | return 1; |
2850 | return 1; |
2453 | } |
2851 | } |
2454 | |
2852 | |
2455 | void |
|
|
2456 | navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation) |
2853 | void navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation) |
2457 | { |
2854 | { |
2458 | //dbg(0,"EEnter\n"); |
2855 | ////DBG dbg(0,"EEnter\n"); |
2459 | int dir; |
2856 | int dir; |
2460 | struct point pn; |
2857 | struct point pn; |
2461 | struct navit_vehicle *nv=this_->vehicle; |
2858 | struct navit_vehicle *nv = this_->vehicle; |
2462 | navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir); |
2859 | navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir); |
2463 | transform_set_yaw(this_->trans, dir); |
2860 | transform_set_yaw(this_->trans, dir); |
2464 | navit_set_center_coord_screen(this_, &nv->coord, &pn, 0); |
2861 | navit_set_center_coord_screen(this_, &nv->coord, &pn, 0); |
2465 | if (autozoom) |
2862 | if (autozoom) |
2466 | navit_autozoom(this_, &nv->coord, nv->speed, 0); |
2863 | navit_autozoom(this_, &nv->coord, nv->speed, 0); |
2467 | } |
2864 | } |
2468 | |
2865 | |
2469 | static void |
|
|
2470 | navit_set_center_cursor_draw(struct navit *this_) |
2866 | static void navit_set_center_cursor_draw(struct navit *this_) |
2471 | { |
2867 | { |
2472 | //dbg(0,"EEnter\n"); |
2868 | ////DBG dbg(0,"EEnter\n"); |
2473 | navit_set_center_cursor(this_,1,0); |
2869 | navit_set_center_cursor(this_, 1, 0); |
2474 | if (this_->ready == 3) |
2870 | if (this_->ready == 3) |
2475 | { |
2871 | { |
2476 | //dbg(0,"navit_draw_async_005\n"); |
2872 | ////DBG dbg(0,"navit_draw_async_005\n"); |
2477 | navit_draw_async(this_, 1); |
2873 | navit_draw_async(this_, 1); |
2478 | } |
2874 | } |
2479 | } |
2875 | } |
2480 | |
2876 | |
2481 | static void |
|
|
2482 | navit_cmd_set_center_cursor(struct navit *this_) |
2877 | static void navit_cmd_set_center_cursor(struct navit *this_) |
2483 | { |
2878 | { |
2484 | //dbg(0,"EEnter\n"); |
2879 | ////DBG dbg(0,"EEnter\n"); |
2485 | navit_set_center_cursor_draw(this_); |
2880 | navit_set_center_cursor_draw(this_); |
2486 | } |
2881 | } |
2487 | |
2882 | |
2488 | void |
|
|
2489 | navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout) |
2883 | void navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout) |
2490 | { |
2884 | { |
2491 | //dbg(0,"EEnter\n"); |
2885 | ////DBG dbg(0,"EEnter\n"); |
2492 | struct coord c; |
2886 | struct coord c; |
2493 | struct pcoord pc; |
2887 | struct pcoord pc; |
2494 | transform_reverse(this_->trans, p, &c); |
2888 | transform_reverse(this_->trans, p, &c); |
2495 | pc.x = c.x; |
2889 | pc.x = c.x; |
2496 | pc.y = c.y; |
2890 | pc.y = c.y; |
2497 | pc.pro = transform_get_projection(this_->trans); |
2891 | pc.pro = transform_get_projection(this_->trans); |
2498 | navit_set_center(this_, &pc, set_timeout); |
2892 | navit_set_center(this_, &pc, set_timeout); |
2499 | } |
2893 | } |
2500 | |
2894 | |
2501 | #if 0 |
2895 | #if 0 |
2502 | switch((*attrs)->type) { |
2896 | switch((*attrs)->type) |
|
|
2897 | { |
2503 | case attr_zoom: |
2898 | case attr_zoom: |
2504 | zoom=(*attrs)->u.num; |
2899 | zoom=(*attrs)->u.num; |
2505 | break; |
2900 | break; |
2506 | case attr_center: |
2901 | case attr_center: |
2507 | g=*((*attrs)->u.coord_geo); |
2902 | g=*((*attrs)->u.coord_geo); |
2508 | break; |
2903 | break; |
2509 | #endif |
2904 | #endif |
2510 | |
2905 | |
2511 | static int |
|
|
2512 | navit_set_attr_do(struct navit *this_, struct attr *attr, int init) |
2906 | static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init) |
2513 | { |
2907 | { |
2514 | //dbg(0,"EEnter\n"); |
2908 | ////DBG dbg(0,"EEnter\n"); |
2515 | int dir=0, orient_old=0, attr_updated=0; |
2909 | int dir = 0, orient_old = 0, attr_updated = 0; |
2516 | struct coord co; |
2910 | struct coord co; |
2517 | long zoom; |
2911 | long zoom; |
2518 | GList *l; |
2912 | GList *l; |
2519 | struct navit_vehicle *nv; |
2913 | struct navit_vehicle *nv; |
2520 | struct layout *lay; |
2914 | struct layout *lay; |
2521 | struct attr active; |
2915 | struct attr active; |
2522 | active.type=attr_active; |
2916 | active.type = attr_active; |
2523 | active.u.num=0; |
2917 | active.u.num = 0; |
2524 | |
2918 | |
2525 | switch (attr->type) { |
2919 | switch (attr->type) |
|
|
2920 | { |
2526 | case attr_autozoom: |
2921 | case attr_autozoom: |
2527 | attr_updated=(this_->autozoom_secs != attr->u.num); |
2922 | attr_updated = (this_->autozoom_secs != attr->u.num); |
2528 | this_->autozoom_secs = attr->u.num; |
2923 | this_->autozoom_secs = attr->u.num; |
2529 | break; |
2924 | break; |
2530 | case attr_autozoom_active: |
2925 | case attr_autozoom_active: |
2531 | attr_updated=(this_->autozoom_active != attr->u.num); |
2926 | attr_updated = (this_->autozoom_active != attr->u.num); |
2532 | this_->autozoom_active = attr->u.num; |
2927 | this_->autozoom_active = attr->u.num; |
2533 | break; |
2928 | break; |
2534 | case attr_center: |
2929 | case attr_center: |
2535 | transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co); |
2930 | transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co); |
2536 | dbg(1,"0x%x,0x%x\n",co.x,co.y); |
2931 | // dbg(1, "0x%x,0x%x\n", co.x, co.y); |
2537 | transform_set_center(this_->trans, &co); |
2932 | transform_set_center(this_->trans, &co); |
2538 | break; |
2933 | break; |
2539 | case attr_drag_bitmap: |
2934 | case attr_drag_bitmap: |
2540 | attr_updated=(this_->drag_bitmap != !!attr->u.num); |
2935 | attr_updated = (this_->drag_bitmap != !!attr->u.num); |
2541 | this_->drag_bitmap=!!attr->u.num; |
2936 | this_->drag_bitmap = !!attr->u.num; |
2542 | break; |
2937 | break; |
2543 | case attr_flags: |
2938 | case attr_flags: |
2544 | attr_updated=(this_->flags != attr->u.num); |
2939 | attr_updated = (this_->flags != attr->u.num); |
2545 | this_->flags=attr->u.num; |
2940 | this_->flags = attr->u.num; |
2546 | break; |
2941 | break; |
2547 | case attr_flags_graphics: |
2942 | case attr_flags_graphics: |
2548 | attr_updated=(this_->graphics_flags != attr->u.num); |
2943 | attr_updated = (this_->graphics_flags != attr->u.num); |
2549 | this_->graphics_flags=attr->u.num; |
2944 | this_->graphics_flags = attr->u.num; |
2550 | break; |
2945 | break; |
2551 | case attr_follow: |
2946 | case attr_follow: |
2552 | if (!this_->vehicle) |
2947 | if (!this_->vehicle) |
2553 | return 0; |
2948 | return 0; |
2554 | attr_updated=(this_->vehicle->follow_curr != attr->u.num); |
2949 | attr_updated = (this_->vehicle->follow_curr != attr->u.num); |
2555 | this_->vehicle->follow_curr = attr->u.num; |
2950 | this_->vehicle->follow_curr = attr->u.num; |
2556 | break; |
2951 | break; |
2557 | case attr_layout: |
2952 | case attr_layout: |
2558 | if(this_->layout_current!=attr->u.layout) { |
2953 | if (this_->layout_current != attr->u.layout) |
|
|
2954 | { |
2559 | this_->layout_current=attr->u.layout; |
2955 | this_->layout_current = attr->u.layout; |
2560 | graphics_font_destroy_all(this_->gra); |
2956 | graphics_font_destroy_all(this_->gra); |
2561 | navit_set_cursors(this_); |
2957 | navit_set_cursors(this_); |
2562 | if (this_->ready == 3) |
|
|
2563 | navit_draw(this_); |
|
|
2564 | attr_updated=1; |
|
|
2565 | } |
|
|
2566 | break; |
|
|
2567 | case attr_layout_name: |
|
|
2568 | l=this_->layouts; |
|
|
2569 | while (l) { |
|
|
2570 | lay=l->data; |
|
|
2571 | if (!strcmp(lay->name,attr->u.str)) { |
|
|
2572 | struct attr attr; |
|
|
2573 | attr.type=attr_layout; |
|
|
2574 | attr.u.layout=lay; |
|
|
2575 | return navit_set_attr_do(this_, &attr, init); |
|
|
2576 | } |
|
|
2577 | l=g_list_next(l); |
|
|
2578 | } |
|
|
2579 | return 0; |
|
|
2580 | case attr_map_border: |
|
|
2581 | if (this_->border != attr->u.num) { |
|
|
2582 | this_->border=attr->u.num; |
|
|
2583 | attr_updated=1; |
|
|
2584 | } |
|
|
2585 | break; |
|
|
2586 | case attr_orientation: |
|
|
2587 | orient_old=this_->orientation; |
|
|
2588 | this_->orientation=attr->u.num; |
|
|
2589 | if (!init) { |
|
|
2590 | if (this_->orientation != -1) { |
|
|
2591 | dir = this_->orientation; |
|
|
2592 | } else { |
|
|
2593 | if (this_->vehicle) { |
|
|
2594 | dir = this_->vehicle->dir; |
|
|
2595 | } |
|
|
2596 | } |
|
|
2597 | transform_set_yaw(this_->trans, dir); |
|
|
2598 | if (orient_old != this_->orientation) { |
|
|
2599 | #if 0 |
|
|
2600 | if (this_->ready == 3) |
2958 | if (this_->ready == 3) |
2601 | navit_draw(this_); |
2959 | navit_draw(this_); |
|
|
2960 | attr_updated = 1; |
|
|
2961 | } |
|
|
2962 | break; |
|
|
2963 | case attr_layout_name: |
|
|
2964 | l = this_->layouts; |
|
|
2965 | while (l) |
|
|
2966 | { |
|
|
2967 | lay = l->data; |
|
|
2968 | if (!strcmp(lay->name, attr->u.str)) |
|
|
2969 | { |
|
|
2970 | struct attr attr; |
|
|
2971 | attr.type = attr_layout; |
|
|
2972 | attr.u.layout = lay; |
|
|
2973 | return navit_set_attr_do(this_, &attr, init); |
|
|
2974 | } |
|
|
2975 | l = g_list_next(l); |
|
|
2976 | } |
|
|
2977 | return 0; |
|
|
2978 | case attr_map_border: |
|
|
2979 | if (this_->border != attr->u.num) |
|
|
2980 | { |
|
|
2981 | this_->border = attr->u.num; |
|
|
2982 | attr_updated = 1; |
|
|
2983 | } |
|
|
2984 | break; |
|
|
2985 | case attr_orientation: |
|
|
2986 | orient_old = this_->orientation; |
|
|
2987 | this_->orientation = attr->u.num; |
|
|
2988 | if (!init) |
|
|
2989 | { |
|
|
2990 | if (this_->orientation != -1) |
|
|
2991 | { |
|
|
2992 | dir = this_->orientation; |
|
|
2993 | } |
|
|
2994 | else |
|
|
2995 | { |
|
|
2996 | if (this_->vehicle) |
|
|
2997 | { |
|
|
2998 | dir = this_->vehicle->dir; |
|
|
2999 | } |
|
|
3000 | } |
|
|
3001 | transform_set_yaw(this_->trans, dir); |
|
|
3002 | if (orient_old != this_->orientation) |
|
|
3003 | { |
|
|
3004 | #if 0 |
|
|
3005 | if (this_->ready == 3) |
|
|
3006 | navit_draw(this_); |
2602 | #endif |
3007 | #endif |
2603 | attr_updated=1; |
|
|
2604 | } |
|
|
2605 | } |
|
|
2606 | break; |
|
|
2607 | case attr_osd_configuration: |
|
|
2608 | dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration); |
|
|
2609 | attr_updated=(this_->osd_configuration != attr->u.num); |
|
|
2610 | this_->osd_configuration=attr->u.num; |
|
|
2611 | break; |
|
|
2612 | case attr_pitch: |
|
|
2613 | attr_updated=(this_->pitch != attr->u.num); |
|
|
2614 | this_->pitch=attr->u.num; |
|
|
2615 | transform_set_pitch(this_->trans, this_->pitch); |
|
|
2616 | if (!init && attr_updated && this_->ready == 3) |
|
|
2617 | navit_draw(this_); |
|
|
2618 | break; |
|
|
2619 | case attr_projection: |
|
|
2620 | if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) { |
|
|
2621 | navit_projection_set(this_, attr->u.projection, !init); |
|
|
2622 | attr_updated=1; |
|
|
2623 | } |
|
|
2624 | break; |
|
|
2625 | case attr_radius: |
|
|
2626 | attr_updated=(this_->radius != attr->u.num); |
|
|
2627 | this_->radius=attr->u.num; |
|
|
2628 | break; |
|
|
2629 | case attr_recent_dest: |
|
|
2630 | attr_updated=(this_->recentdest_count != attr->u.num); |
|
|
2631 | this_->recentdest_count=attr->u.num; |
|
|
2632 | break; |
|
|
2633 | case attr_speech: |
|
|
2634 | if(this_->speech && this_->speech != attr->u.speech) { |
|
|
2635 | attr_updated=1; |
|
|
2636 | this_->speech = attr->u.speech; |
|
|
2637 | } |
|
|
2638 | break; |
|
|
2639 | case attr_timeout: |
|
|
2640 | attr_updated=(this_->center_timeout != attr->u.num); |
|
|
2641 | this_->center_timeout = attr->u.num; |
|
|
2642 | break; |
|
|
2643 | case attr_tracking: |
|
|
2644 | attr_updated=(this_->tracking_flag != !!attr->u.num); |
|
|
2645 | this_->tracking_flag=!!attr->u.num; |
|
|
2646 | break; |
|
|
2647 | case attr_transformation: |
|
|
2648 | this_->trans=attr->u.transformation; |
|
|
2649 | break; |
|
|
2650 | case attr_use_mousewheel: |
|
|
2651 | attr_updated=(this_->use_mousewheel != !!attr->u.num); |
|
|
2652 | this_->use_mousewheel=!!attr->u.num; |
|
|
2653 | break; |
|
|
2654 | case attr_vehicle: |
|
|
2655 | l=this_->vehicles; |
|
|
2656 | while(l) { |
|
|
2657 | nv=l->data; |
|
|
2658 | if (nv->vehicle == attr->u.vehicle) { |
|
|
2659 | if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) { |
|
|
2660 | if (this_->vehicle) |
|
|
2661 | vehicle_set_attr(this_->vehicle->vehicle, &active); |
|
|
2662 | active.u.num=1; |
|
|
2663 | vehicle_set_attr(nv->vehicle, &active); |
|
|
2664 | attr_updated=1; |
3008 | attr_updated = 1; |
2665 | } |
3009 | } |
|
|
3010 | } |
|
|
3011 | break; |
|
|
3012 | case attr_osd_configuration: |
|
|
3013 | //DBG dbg(0, "setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration); |
|
|
3014 | attr_updated = (this_->osd_configuration != attr->u.num); |
|
|
3015 | this_->osd_configuration = attr->u.num; |
|
|
3016 | break; |
|
|
3017 | case attr_pitch: |
|
|
3018 | attr_updated = (this_->pitch != attr->u.num); |
|
|
3019 | this_->pitch = attr->u.num; |
|
|
3020 | transform_set_pitch(this_->trans, this_->pitch); |
|
|
3021 | if (!init && attr_updated && this_->ready == 3) |
|
|
3022 | navit_draw(this_); |
|
|
3023 | break; |
|
|
3024 | case attr_projection: |
|
|
3025 | if (this_->trans && transform_get_projection(this_->trans) != attr->u.projection) |
|
|
3026 | { |
|
|
3027 | navit_projection_set(this_, attr->u.projection, !init); |
|
|
3028 | attr_updated = 1; |
|
|
3029 | } |
|
|
3030 | break; |
|
|
3031 | case attr_radius: |
|
|
3032 | attr_updated = (this_->radius != attr->u.num); |
|
|
3033 | this_->radius = attr->u.num; |
|
|
3034 | break; |
|
|
3035 | case attr_recent_dest: |
|
|
3036 | attr_updated = (this_->recentdest_count != attr->u.num); |
|
|
3037 | this_->recentdest_count = attr->u.num; |
|
|
3038 | break; |
|
|
3039 | case attr_speech: |
|
|
3040 | if (this_->speech && this_->speech != attr->u.speech) |
|
|
3041 | { |
|
|
3042 | attr_updated = 1; |
|
|
3043 | this_->speech = attr->u.speech; |
|
|
3044 | } |
|
|
3045 | break; |
|
|
3046 | case attr_timeout: |
|
|
3047 | attr_updated = (this_->center_timeout != attr->u.num); |
|
|
3048 | this_->center_timeout = attr->u.num; |
|
|
3049 | break; |
|
|
3050 | case attr_tracking: |
|
|
3051 | attr_updated = (this_->tracking_flag != !!attr->u.num); |
|
|
3052 | this_->tracking_flag = !!attr->u.num; |
|
|
3053 | break; |
|
|
3054 | case attr_transformation: |
|
|
3055 | this_->trans = attr->u.transformation; |
|
|
3056 | break; |
|
|
3057 | case attr_use_mousewheel: |
|
|
3058 | attr_updated = (this_->use_mousewheel != !!attr->u.num); |
|
|
3059 | this_->use_mousewheel = !!attr->u.num; |
|
|
3060 | break; |
|
|
3061 | case attr_vehicle: |
|
|
3062 | l = this_->vehicles; |
|
|
3063 | while (l) |
|
|
3064 | { |
|
|
3065 | nv = l->data; |
|
|
3066 | if (nv->vehicle == attr->u.vehicle) |
|
|
3067 | { |
|
|
3068 | if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) |
|
|
3069 | { |
|
|
3070 | if (this_->vehicle) |
|
|
3071 | vehicle_set_attr(this_->vehicle->vehicle, &active); |
|
|
3072 | active.u.num = 1; |
|
|
3073 | vehicle_set_attr(nv->vehicle, &active); |
|
|
3074 | attr_updated = 1; |
|
|
3075 | } |
2666 | navit_set_vehicle(this_, nv); |
3076 | navit_set_vehicle(this_, nv); |
2667 | } |
3077 | } |
2668 | l=g_list_next(l); |
3078 | l = g_list_next(l); |
2669 | } |
3079 | } |
2670 | break; |
3080 | break; |
2671 | case attr_zoom: |
3081 | case attr_zoom: |
2672 | zoom=transform_get_scale(this_->trans); |
3082 | zoom = transform_get_scale(this_->trans); |
2673 | attr_updated=(zoom != attr->u.num); |
3083 | attr_updated = (zoom != attr->u.num); |
2674 | transform_set_scale(this_->trans, attr->u.num); |
3084 | transform_set_scale(this_->trans, attr->u.num); |
2675 | if (attr_updated && !init) |
3085 | if (attr_updated && !init) |
2676 | navit_draw(this_); |
3086 | navit_draw(this_); |
2677 | break; |
3087 | break; |
2678 | case attr_zoom_min: |
3088 | case attr_zoom_min: |
2679 | attr_updated=(attr->u.num != this_->zoom_min); |
3089 | attr_updated = (attr->u.num != this_->zoom_min); |
2680 | this_->zoom_min=attr->u.num; |
3090 | this_->zoom_min = attr->u.num; |
2681 | break; |
3091 | break; |
2682 | case attr_zoom_max: |
3092 | case attr_zoom_max: |
2683 | attr_updated=(attr->u.num != this_->zoom_max); |
3093 | attr_updated = (attr->u.num != this_->zoom_max); |
2684 | this_->zoom_max=attr->u.num; |
3094 | this_->zoom_max = attr->u.num; |
2685 | break; |
3095 | break; |
2686 | case attr_message: |
3096 | case attr_message: |
2687 | navit_add_message(this_, attr->u.str); |
3097 | //navit_add_message(this_, attr->u.str); |
2688 | break; |
3098 | break; |
2689 | case attr_follow_cursor: |
3099 | case attr_follow_cursor: |
2690 | attr_updated=(this_->follow_cursor != !!attr->u.num); |
3100 | attr_updated = (this_->follow_cursor != !!attr->u.num); |
2691 | this_->follow_cursor=!!attr->u.num; |
3101 | this_->follow_cursor = !!attr->u.num; |
2692 | break; |
3102 | break; |
2693 | case attr_imperial: |
3103 | case attr_imperial: |
2694 | attr_updated=(this_->imperial != attr->u.num); |
3104 | attr_updated = (this_->imperial != attr->u.num); |
2695 | this_->imperial=attr->u.num; |
3105 | this_->imperial = attr->u.num; |
2696 | break; |
3106 | break; |
2697 | default: |
3107 | default: |
2698 | return 0; |
3108 | return 0; |
2699 | } |
3109 | } |
2700 | if (attr_updated && !init) { |
3110 | if (attr_updated && !init) |
|
|
3111 | { |
2701 | callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); |
3112 | callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); |
2702 | if (attr->type == attr_osd_configuration) |
3113 | if (attr->type == attr_osd_configuration) |
2703 | graphics_draw_mode(this_->gra, draw_mode_end); |
3114 | graphics_draw_mode(this_->gra, draw_mode_end); |
2704 | } |
3115 | } |
2705 | return 1; |
3116 | return 1; |
2706 | } |
3117 | } |
2707 | |
3118 | |
2708 | int |
|
|
2709 | navit_set_attr(struct navit *this_, struct attr *attr) |
3119 | int navit_set_attr(struct navit *this_, struct attr *attr) |
2710 | { |
3120 | { |
2711 | //dbg(0,"EEnter\n"); |
3121 | ////DBG dbg(0,"EEnter\n"); |
2712 | return navit_set_attr_do(this_, attr, 0); |
3122 | return navit_set_attr_do(this_, attr, 0); |
2713 | } |
3123 | } |
2714 | |
3124 | |
2715 | int |
|
|
2716 | navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
3125 | int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) |
2717 | { |
3126 | { |
2718 | //dbg(0,"EEnter\n"); |
3127 | ////DBG dbg(0,"EEnter\n"); |
2719 | struct message *msg; |
3128 | struct message *msg; |
2720 | int len,offset; |
3129 | int len, offset; |
2721 | int ret=1; |
3130 | int ret = 1; |
2722 | |
3131 | |
2723 | switch (type) { |
3132 | switch (type) |
|
|
3133 | { |
2724 | case attr_message: |
3134 | case attr_message: |
2725 | msg = navit_get_messages(this_); |
|
|
2726 | |
|
|
2727 | if (!msg) { |
|
|
2728 | return 0; |
3135 | return 0; |
|
|
3136 | /* |
|
|
3137 | msg = navit_get_messages(this_); |
|
|
3138 | |
|
|
3139 | if (!msg) |
|
|
3140 | { |
|
|
3141 | return 0; |
2729 | } |
3142 | } |
2730 | |
3143 | |
2731 | len = 0; |
3144 | len = 0; |
2732 | while (msg) { |
3145 | while (msg) |
|
|
3146 | { |
2733 | len += strlen(msg->text) + 1; |
3147 | len += strlen(msg->text) + 1; |
2734 | msg = msg->next; |
3148 | msg = msg->next; |
2735 | } |
3149 | } |
2736 | attr->u.str = g_malloc(len + 1); |
3150 | attr->u.str = g_malloc(len + 1); |
2737 | |
3151 | |
2738 | msg = navit_get_messages(this_); |
3152 | msg = navit_get_messages(this_); |
2739 | offset = 0; |
3153 | offset = 0; |
2740 | while (msg) { |
3154 | while (msg) |
|
|
3155 | { |
2741 | g_stpcpy((attr->u.str + offset), msg->text); |
3156 | g_stpcpy((attr->u.str + offset), msg->text); |
2742 | offset += strlen(msg->text); |
3157 | offset += strlen(msg->text); |
2743 | attr->u.str[offset] = '\n'; |
3158 | attr->u.str[offset] = '\n'; |
2744 | offset++; |
3159 | offset++; |
2745 | |
3160 | |
2746 | msg = msg->next; |
3161 | msg = msg->next; |
2747 | } |
3162 | } |
2748 | |
3163 | |
2749 | attr->u.str[len] = '\0'; |
3164 | attr->u.str[len] = '\0'; |
|
|
3165 | */ |
2750 | break; |
3166 | break; |
2751 | case attr_imperial: |
3167 | case attr_imperial: |
2752 | attr->u.num=this_->imperial; |
3168 | attr->u.num = this_->imperial; |
2753 | break; |
3169 | break; |
2754 | case attr_bookmark_map: |
3170 | case attr_bookmark_map: |
2755 | attr->u.map=bookmarks_get_map(this_->bookmarks); |
3171 | attr->u.map = bookmarks_get_map(this_->bookmarks); |
2756 | break; |
3172 | break; |
2757 | case attr_bookmarks: |
3173 | case attr_bookmarks: |
2758 | attr->u.bookmarks=this_->bookmarks; |
3174 | attr->u.bookmarks = this_->bookmarks; |
2759 | break; |
3175 | break; |
2760 | case attr_callback_list: |
3176 | case attr_callback_list: |
2761 | attr->u.callback_list=this_->attr_cbl; |
3177 | attr->u.callback_list = this_->attr_cbl; |
2762 | break; |
3178 | break; |
2763 | case attr_destination: |
3179 | case attr_destination: |
2764 | if (! this_->destination_valid) |
3180 | if (!this_->destination_valid) |
|
|
3181 | return 0; |
|
|
3182 | attr->u.pcoord = &this_->destination; |
|
|
3183 | break; |
|
|
3184 | case attr_displaylist: |
|
|
3185 | attr->u.displaylist = this_->displaylist; |
|
|
3186 | return (attr->u.displaylist != NULL); |
|
|
3187 | case attr_follow: |
|
|
3188 | if (!this_->vehicle) |
|
|
3189 | return 0; |
|
|
3190 | attr->u.num = this_->vehicle->follow_curr; |
|
|
3191 | break; |
|
|
3192 | case attr_former_destination_map: |
|
|
3193 | attr->u.map = this_->former_destination; |
|
|
3194 | break; |
|
|
3195 | case attr_graphics: |
|
|
3196 | attr->u.graphics = this_->gra; |
|
|
3197 | ret = (attr->u.graphics != NULL); |
|
|
3198 | break; |
|
|
3199 | case attr_gui: |
|
|
3200 | attr->u.gui = this_->gui; |
|
|
3201 | ret = (attr->u.gui != NULL); |
|
|
3202 | break; |
|
|
3203 | case attr_layout: |
|
|
3204 | if (iter) |
|
|
3205 | { |
|
|
3206 | if (iter->u.list) |
|
|
3207 | { |
|
|
3208 | iter->u.list = g_list_next(iter->u.list); |
|
|
3209 | } |
|
|
3210 | else |
|
|
3211 | { |
|
|
3212 | iter->u.list = this_->layouts; |
|
|
3213 | } |
|
|
3214 | if (!iter->u.list) |
|
|
3215 | { |
|
|
3216 | return 0; |
|
|
3217 | } |
|
|
3218 | attr->u.layout = (struct layout *) iter->u.list->data; |
|
|
3219 | } |
|
|
3220 | else |
|
|
3221 | { |
|
|
3222 | attr->u.layout = this_->layout_current; |
|
|
3223 | } |
|
|
3224 | break; |
|
|
3225 | case attr_map: |
|
|
3226 | if (iter && this_->mapsets) |
|
|
3227 | { |
|
|
3228 | if (!iter->u.mapset_handle) |
|
|
3229 | { |
|
|
3230 | iter->u.mapset_handle = mapset_open((struct mapset *) this_->mapsets->data); |
|
|
3231 | } |
|
|
3232 | attr->u.map = mapset_next(iter->u.mapset_handle, 0); |
|
|
3233 | if (!attr->u.map) |
|
|
3234 | { |
|
|
3235 | mapset_close(iter->u.mapset_handle); |
|
|
3236 | return 0; |
|
|
3237 | } |
|
|
3238 | } |
|
|
3239 | else |
|
|
3240 | { |
|
|
3241 | return 0; |
|
|
3242 | } |
|
|
3243 | break; |
|
|
3244 | case attr_mapset: |
|
|
3245 | attr->u.mapset = this_->mapsets->data; |
|
|
3246 | ret = (attr->u.mapset != NULL); |
|
|
3247 | break; |
|
|
3248 | case attr_navigation: |
|
|
3249 | attr->u.navigation = this_->navigation; |
|
|
3250 | break; |
|
|
3251 | case attr_orientation: |
|
|
3252 | attr->u.num = this_->orientation; |
|
|
3253 | break; |
|
|
3254 | case attr_osd_configuration: |
|
|
3255 | attr->u.num = this_->osd_configuration; |
|
|
3256 | break; |
|
|
3257 | case attr_pitch: |
|
|
3258 | attr->u.num = transform_get_pitch(this_->trans); |
|
|
3259 | break; |
|
|
3260 | case attr_projection: |
|
|
3261 | if (this_->trans) |
|
|
3262 | { |
|
|
3263 | attr->u.num = transform_get_projection(this_->trans); |
|
|
3264 | } |
|
|
3265 | else |
|
|
3266 | { |
|
|
3267 | return 0; |
|
|
3268 | } |
|
|
3269 | break; |
|
|
3270 | case attr_route: |
|
|
3271 | attr->u.route = this_->route; |
|
|
3272 | break; |
|
|
3273 | case attr_speech: |
|
|
3274 | attr->u.speech = this_->speech; |
|
|
3275 | break; |
|
|
3276 | case attr_tracking: |
|
|
3277 | attr->u.num = this_->tracking_flag; |
|
|
3278 | break; |
|
|
3279 | case attr_trackingo: |
|
|
3280 | attr->u.tracking = this_->tracking; |
|
|
3281 | break; |
|
|
3282 | case attr_transformation: |
|
|
3283 | attr->u.transformation = this_->trans; |
|
|
3284 | break; |
|
|
3285 | case attr_vehicle: |
|
|
3286 | if (iter) |
|
|
3287 | { |
|
|
3288 | if (iter->u.list) |
|
|
3289 | { |
|
|
3290 | iter->u.list = g_list_next(iter->u.list); |
|
|
3291 | } |
|
|
3292 | else |
|
|
3293 | { |
|
|
3294 | iter->u.list = this_->vehicles; |
|
|
3295 | } |
|
|
3296 | if (!iter->u.list) |
|
|
3297 | return 0; |
|
|
3298 | attr->u.vehicle = ((struct navit_vehicle*) iter->u.list->data)->vehicle; |
|
|
3299 | } |
|
|
3300 | else |
|
|
3301 | { |
|
|
3302 | if (this_->vehicle) |
|
|
3303 | { |
|
|
3304 | attr->u.vehicle = this_->vehicle->vehicle; |
|
|
3305 | } |
|
|
3306 | else |
|
|
3307 | { |
|
|
3308 | return 0; |
|
|
3309 | } |
|
|
3310 | } |
|
|
3311 | break; |
|
|
3312 | case attr_vehicleprofile: |
|
|
3313 | attr->u.vehicleprofile = this_->vehicleprofile; |
|
|
3314 | break; |
|
|
3315 | case attr_zoom: |
|
|
3316 | attr->u.num = transform_get_scale(this_->trans); |
|
|
3317 | break; |
|
|
3318 | case attr_autozoom_active: |
|
|
3319 | attr->u.num = this_->autozoom_active; |
|
|
3320 | break; |
|
|
3321 | case attr_follow_cursor: |
|
|
3322 | attr->u.num = this_->follow_cursor; |
|
|
3323 | break; |
|
|
3324 | default: |
2765 | return 0; |
3325 | return 0; |
2766 | attr->u.pcoord=&this_->destination; |
|
|
2767 | break; |
|
|
2768 | case attr_displaylist: |
|
|
2769 | attr->u.displaylist=this_->displaylist; |
|
|
2770 | return (attr->u.displaylist != NULL); |
|
|
2771 | case attr_follow: |
|
|
2772 | if (!this_->vehicle) |
|
|
2773 | return 0; |
|
|
2774 | attr->u.num=this_->vehicle->follow_curr; |
|
|
2775 | break; |
|
|
2776 | case attr_former_destination_map: |
|
|
2777 | attr->u.map=this_->former_destination; |
|
|
2778 | break; |
|
|
2779 | case attr_graphics: |
|
|
2780 | attr->u.graphics=this_->gra; |
|
|
2781 | ret=(attr->u.graphics != NULL); |
|
|
2782 | break; |
|
|
2783 | case attr_gui: |
|
|
2784 | attr->u.gui=this_->gui; |
|
|
2785 | ret=(attr->u.gui != NULL); |
|
|
2786 | break; |
|
|
2787 | case attr_layout: |
|
|
2788 | if (iter) |
|
|
2789 | { |
|
|
2790 | if (iter->u.list) |
|
|
2791 | { |
|
|
2792 | iter->u.list=g_list_next(iter->u.list); |
|
|
2793 | } |
|
|
2794 | else |
|
|
2795 | { |
|
|
2796 | iter->u.list=this_->layouts; |
|
|
2797 | } |
|
|
2798 | if (!iter->u.list) |
|
|
2799 | { |
|
|
2800 | return 0; |
|
|
2801 | } |
|
|
2802 | attr->u.layout=(struct layout *)iter->u.list->data; |
|
|
2803 | } |
3326 | } |
2804 | else |
|
|
2805 | { |
|
|
2806 | attr->u.layout=this_->layout_current; |
|
|
2807 | } |
|
|
2808 | break; |
|
|
2809 | case attr_map: |
|
|
2810 | if (iter && this_->mapsets) { |
|
|
2811 | if (!iter->u.mapset_handle) { |
|
|
2812 | iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data); |
|
|
2813 | } |
|
|
2814 | attr->u.map=mapset_next(iter->u.mapset_handle, 0); |
|
|
2815 | if(!attr->u.map) { |
|
|
2816 | mapset_close(iter->u.mapset_handle); |
|
|
2817 | return 0; |
|
|
2818 | } |
|
|
2819 | } else { |
|
|
2820 | return 0; |
|
|
2821 | } |
|
|
2822 | break; |
|
|
2823 | case attr_mapset: |
|
|
2824 | attr->u.mapset=this_->mapsets->data; |
|
|
2825 | ret=(attr->u.mapset != NULL); |
|
|
2826 | break; |
|
|
2827 | case attr_navigation: |
|
|
2828 | attr->u.navigation=this_->navigation; |
|
|
2829 | break; |
|
|
2830 | case attr_orientation: |
|
|
2831 | attr->u.num=this_->orientation; |
|
|
2832 | break; |
|
|
2833 | case attr_osd_configuration: |
|
|
2834 | attr->u.num=this_->osd_configuration; |
|
|
2835 | break; |
|
|
2836 | case attr_pitch: |
|
|
2837 | attr->u.num=transform_get_pitch(this_->trans); |
|
|
2838 | break; |
|
|
2839 | case attr_projection: |
|
|
2840 | if(this_->trans) { |
|
|
2841 | attr->u.num=transform_get_projection(this_->trans); |
|
|
2842 | } else { |
|
|
2843 | return 0; |
|
|
2844 | } |
|
|
2845 | break; |
|
|
2846 | case attr_route: |
|
|
2847 | attr->u.route=this_->route; |
|
|
2848 | break; |
|
|
2849 | case attr_speech: |
|
|
2850 | attr->u.speech=this_->speech; |
|
|
2851 | break; |
|
|
2852 | case attr_tracking: |
|
|
2853 | attr->u.num=this_->tracking_flag; |
|
|
2854 | break; |
|
|
2855 | case attr_trackingo: |
|
|
2856 | attr->u.tracking=this_->tracking; |
|
|
2857 | break; |
|
|
2858 | case attr_transformation: |
|
|
2859 | attr->u.transformation=this_->trans; |
|
|
2860 | break; |
|
|
2861 | case attr_vehicle: |
|
|
2862 | if(iter) { |
|
|
2863 | if(iter->u.list) { |
|
|
2864 | iter->u.list=g_list_next(iter->u.list); |
|
|
2865 | } else { |
|
|
2866 | iter->u.list=this_->vehicles; |
|
|
2867 | } |
|
|
2868 | if(!iter->u.list) |
|
|
2869 | return 0; |
|
|
2870 | attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle; |
|
|
2871 | } else { |
|
|
2872 | if(this_->vehicle) { |
|
|
2873 | attr->u.vehicle=this_->vehicle->vehicle; |
|
|
2874 | } else { |
|
|
2875 | return 0; |
|
|
2876 | } |
|
|
2877 | } |
|
|
2878 | break; |
|
|
2879 | case attr_vehicleprofile: |
|
|
2880 | attr->u.vehicleprofile=this_->vehicleprofile; |
|
|
2881 | break; |
|
|
2882 | case attr_zoom: |
|
|
2883 | attr->u.num=transform_get_scale(this_->trans); |
|
|
2884 | break; |
|
|
2885 | case attr_autozoom_active: |
|
|
2886 | attr->u.num=this_->autozoom_active; |
|
|
2887 | break; |
|
|
2888 | case attr_follow_cursor: |
|
|
2889 | attr->u.num=this_->follow_cursor; |
|
|
2890 | break; |
|
|
2891 | default: |
|
|
2892 | return 0; |
|
|
2893 | } |
|
|
2894 | attr->type=type; |
3327 | attr->type = type; |
2895 | return ret; |
3328 | return ret; |
2896 | } |
3329 | } |
2897 | |
3330 | |
2898 | static int |
|
|
2899 | navit_add_log(struct navit *this_, struct log *log) |
3331 | static int navit_add_log(struct navit *this_, struct log *log) |
2900 | { |
3332 | { |
2901 | struct attr type_attr; |
3333 | struct attr type_attr; |
2902 | if (!log_get_attr(log, attr_type, &type_attr, NULL)) |
3334 | if (!log_get_attr(log, attr_type, &type_attr, NULL)) |
2903 | return 0; |
3335 | return 0; |
2904 | if (!strcmp(type_attr.u.str, "textfile_debug")) { |
3336 | if (!strcmp(type_attr.u.str, "textfile_debug")) |
|
|
3337 | { |
2905 | char *header = "type=track_tracked\n"; |
3338 | char *header = "type=track_tracked\n"; |
2906 | if (this_->textfile_debug_log) |
3339 | if (this_->textfile_debug_log) |
2907 | return 0; |
3340 | return 0; |
2908 | log_set_header(log, header, strlen(header)); |
3341 | log_set_header(log, header, strlen(header)); |
2909 | this_->textfile_debug_log=log; |
3342 | this_->textfile_debug_log = log; |
2910 | return 1; |
3343 | return 1; |
2911 | } |
3344 | } |
2912 | return 0; |
3345 | return 0; |
2913 | } |
3346 | } |
2914 | |
3347 | |
2915 | static int |
|
|
2916 | navit_add_layout(struct navit *this_, struct layout *layout) |
3348 | static int navit_add_layout(struct navit *this_, struct layout *layout) |
2917 | { |
3349 | { |
2918 | //dbg(0,"EEnter\n"); |
3350 | ////DBG dbg(0,"EEnter\n"); |
2919 | struct attr active; |
3351 | struct attr active; |
2920 | this_->layouts = g_list_append(this_->layouts, layout); |
3352 | this_->layouts = g_list_append(this_->layouts, layout); |
2921 | layout_get_attr(layout, attr_active, &active, NULL); |
3353 | layout_get_attr(layout, attr_active, &active, NULL); |
2922 | if(active.u.num || !this_->layout_current) { |
3354 | if (active.u.num || !this_->layout_current) |
|
|
3355 | { |
2923 | this_->layout_current=layout; |
3356 | this_->layout_current = layout; |
2924 | return 1; |
3357 | return 1; |
2925 | } |
3358 | } |
2926 | return 0; |
3359 | return 0; |
2927 | } |
3360 | } |
2928 | |
3361 | |
2929 | int |
|
|
2930 | navit_add_attr(struct navit *this_, struct attr *attr) |
3362 | int navit_add_attr(struct navit *this_, struct attr *attr) |
2931 | { |
3363 | { |
2932 | //dbg(0,"EEnter\n"); |
3364 | ////DBG dbg(0,"EEnter\n"); |
2933 | |
3365 | |
2934 | int ret=1; |
3366 | int ret = 1; |
2935 | switch (attr->type) { |
3367 | switch (attr->type) |
|
|
3368 | { |
2936 | case attr_callback: |
3369 | case attr_callback: |
2937 | navit_add_callback(this_, attr->u.callback); |
3370 | navit_add_callback(this_, attr->u.callback); |
2938 | break; |
3371 | break; |
2939 | case attr_log: |
3372 | case attr_log: |
2940 | ret=navit_add_log(this_, attr->u.log); |
3373 | ret = navit_add_log(this_, attr->u.log); |
2941 | break; |
3374 | break; |
2942 | case attr_gui: |
3375 | case attr_gui: |
2943 | ret=navit_set_gui(this_, attr->u.gui); |
3376 | ret = navit_set_gui(this_, attr->u.gui); |
2944 | break; |
3377 | break; |
2945 | case attr_graphics: |
3378 | case attr_graphics: |
2946 | ret=navit_set_graphics(this_, attr->u.graphics); |
3379 | ret = navit_set_graphics(this_, attr->u.graphics); |
2947 | break; |
3380 | break; |
2948 | case attr_layout: |
3381 | case attr_layout: |
2949 | ret=navit_add_layout(this_, attr->u.layout); |
3382 | ret = navit_add_layout(this_, attr->u.layout); |
2950 | break; |
3383 | break; |
2951 | case attr_route: |
3384 | case attr_route: |
2952 | this_->route=attr->u.route; |
3385 | this_->route = attr->u.route; |
2953 | break; |
3386 | break; |
2954 | case attr_mapset: |
3387 | case attr_mapset: |
2955 | this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset); |
3388 | this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset); |
2956 | break; |
3389 | break; |
2957 | case attr_navigation: |
3390 | case attr_navigation: |
2958 | this_->navigation=attr->u.navigation; |
3391 | this_->navigation = attr->u.navigation; |
2959 | break; |
3392 | break; |
2960 | case attr_recent_dest: |
3393 | case attr_recent_dest: |
2961 | this_->recentdest_count = attr->u.num; |
3394 | this_->recentdest_count = attr->u.num; |
2962 | break; |
3395 | break; |
2963 | case attr_speech: |
3396 | case attr_speech: |
2964 | this_->speech=attr->u.speech; |
3397 | this_->speech = attr->u.speech; |
2965 | break; |
3398 | break; |
2966 | case attr_tracking: |
3399 | case attr_tracking: |
2967 | this_->tracking=attr->u.tracking; |
3400 | this_->tracking = attr->u.tracking; |
2968 | break; |
3401 | break; |
2969 | case attr_vehicle: |
3402 | case attr_vehicle: |
2970 | ret=navit_add_vehicle(this_, attr->u.vehicle); |
3403 | ret = navit_add_vehicle(this_, attr->u.vehicle); |
2971 | break; |
3404 | break; |
2972 | case attr_vehicleprofile: |
3405 | case attr_vehicleprofile: |
2973 | this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile); |
3406 | this_->vehicleprofiles = g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile); |
2974 | break; |
3407 | break; |
2975 | case attr_autozoom_min: |
3408 | case attr_autozoom_min: |
2976 | this_->autozoom_min = attr->u.num; |
3409 | this_->autozoom_min = attr->u.num; |
2977 | break; |
3410 | break; |
2978 | default: |
3411 | default: |
2979 | return 0; |
3412 | return 0; |
2980 | } |
3413 | } |
2981 | callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); |
3414 | callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); |
2982 | return ret; |
3415 | return ret; |
2983 | } |
3416 | } |
2984 | |
3417 | |
2985 | int |
|
|
2986 | navit_remove_attr(struct navit *this_, struct attr *attr) |
3418 | int navit_remove_attr(struct navit *this_, struct attr *attr) |
2987 | { |
3419 | { |
2988 | int ret=1; |
3420 | int ret = 1; |
2989 | switch (attr->type) { |
3421 | switch (attr->type) |
|
|
3422 | { |
2990 | case attr_callback: |
3423 | case attr_callback: |
2991 | navit_remove_callback(this_, attr->u.callback); |
3424 | navit_remove_callback(this_, attr->u.callback); |
2992 | break; |
3425 | break; |
2993 | default: |
3426 | default: |
2994 | return 0; |
3427 | return 0; |
2995 | } |
3428 | } |
2996 | return ret; |
3429 | return ret; |
2997 | } |
3430 | } |
2998 | |
3431 | |
2999 | struct attr_iter * |
3432 | struct attr_iter * |
3000 | navit_attr_iter_new(void) |
3433 | navit_attr_iter_new(void) |
3001 | { |
3434 | { |
3002 | return g_new0(struct attr_iter, 1); |
3435 | return g_new0(struct attr_iter, 1); |
3003 | } |
3436 | } |
3004 | |
3437 | |
3005 | void |
|
|
3006 | navit_attr_iter_destroy(struct attr_iter *iter) |
3438 | void navit_attr_iter_destroy(struct attr_iter *iter) |
3007 | { |
3439 | { |
3008 | g_free(iter); |
3440 | g_free(iter); |
3009 | } |
3441 | } |
3010 | |
3442 | |
3011 | void |
|
|
3012 | navit_add_callback(struct navit *this_, struct callback *cb) |
3443 | void navit_add_callback(struct navit *this_, struct callback *cb) |
3013 | { |
3444 | { |
3014 | //dbg(0,"EEnter\n"); |
3445 | ////DBG dbg(0,"EEnter\n"); |
3015 | |
3446 | |
3016 | callback_list_add(this_->attr_cbl, cb); |
3447 | callback_list_add(this_->attr_cbl, cb); |
3017 | } |
3448 | } |
3018 | |
3449 | |
3019 | void |
|
|
3020 | navit_remove_callback(struct navit *this_, struct callback *cb) |
3450 | void navit_remove_callback(struct navit *this_, struct callback *cb) |
3021 | { |
3451 | { |
3022 | //dbg(0,"EEnter\n"); |
3452 | ////DBG dbg(0,"EEnter\n"); |
3023 | |
3453 | |
3024 | callback_list_remove(this_->attr_cbl, cb); |
3454 | callback_list_remove(this_->attr_cbl, cb); |
3025 | } |
3455 | } |
3026 | |
3456 | |
3027 | /** |
3457 | /** |
… | |
… | |
3029 | * |
3459 | * |
3030 | * @param navit The navit instance |
3460 | * @param navit The navit instance |
3031 | * @returns nothing |
3461 | * @returns nothing |
3032 | */ |
3462 | */ |
3033 | |
3463 | |
3034 | static void |
|
|
3035 | navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt) |
3464 | static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt) |
3036 | { |
3465 | { |
3037 | //dbg(0,"EEnter\n"); |
3466 | ////DBG dbg(0,"EEnter\n"); |
3038 | |
3467 | |
3039 | struct point cursor_pnt; |
3468 | struct point cursor_pnt; |
3040 | enum projection pro; |
3469 | enum projection pro; |
3041 | |
3470 | |
3042 | if (this_->blocked) |
3471 | if (this_->blocked) |
3043 | return; |
3472 | return; |
3044 | if (pnt) |
3473 | if (pnt) |
3045 | { |
3474 | { |
3046 | cursor_pnt=*pnt; |
3475 | cursor_pnt = *pnt; |
3047 | } |
3476 | } |
3048 | else |
3477 | else |
3049 | { |
3478 | { |
3050 | pro=transform_get_projection(this_->trans_cursor); |
3479 | pro = transform_get_projection(this_->trans_cursor); |
3051 | if (!pro) |
3480 | if (!pro) |
3052 | return; |
3481 | return; |
3053 | transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL); |
3482 | transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL); |
3054 | } |
3483 | } |
3055 | //dbg(0,"xx=%d\n",cursor_pnt.x); |
3484 | ////DBG dbg(0,"xx=%d\n",cursor_pnt.x); |
3056 | //dbg(0,"yy=%d\n",cursor_pnt.y); |
3485 | ////DBG dbg(0,"yy=%d\n",cursor_pnt.y); |
3057 | |
3486 | |
3058 | global_vehicle_pos_onscreen.x=cursor_pnt.x; |
3487 | global_vehicle_pos_onscreen.x = cursor_pnt.x; |
3059 | global_vehicle_pos_onscreen.y=cursor_pnt.y; |
3488 | global_vehicle_pos_onscreen.y = cursor_pnt.y; |
3060 | |
3489 | |
3061 | |
|
|
3062 | //dbg(0,"xx=%d\n",pnt->x); |
3490 | ////DBG dbg(0,"xx=%d\n",pnt->x); |
3063 | //dbg(0,"yy=%d\n",pnt->y); |
3491 | ////DBG dbg(0,"yy=%d\n",pnt->y); |
3064 | //dbg(0,"vehicle_draw_001\n"); |
3492 | ////DBG dbg(0,"vehicle_draw_001\n"); |
3065 | vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed); |
3493 | vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0 : 1, nv->dir - transform_get_yaw(this_->trans_cursor), nv->speed); |
3066 | #if 0 |
3494 | #if 0 |
3067 | if (pnt) |
3495 | if (pnt) |
3068 | pnt2=*pnt; |
3496 | pnt2=*pnt; |
3069 | else { |
3497 | else |
|
|
3498 | { |
3070 | pro=transform_get_projection(this_->trans); |
3499 | pro=transform_get_projection(this_->trans); |
3071 | transform(this_->trans, pro, &nv->coord, &pnt2, 1); |
3500 | transform(this_->trans, pro, &nv->coord, &pnt2, 1); |
3072 | } |
3501 | } |
3073 | #if 1 |
3502 | #if 1 |
3074 | cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL); |
3503 | cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL); |
… | |
… | |
3076 | cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1); |
3505 | cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1); |
3077 | #endif |
3506 | #endif |
3078 | #endif |
3507 | #endif |
3079 | } |
3508 | } |
3080 | |
3509 | |
3081 | static void |
|
|
3082 | navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv) |
3510 | static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv) |
3083 | { |
3511 | { |
3084 | // dbg(0,"EEnter\n"); |
3512 | //DBG dbg(0,"EEnter\n"); |
3085 | |
3513 | |
3086 | struct attr attr_valid, attr_dir, attr_speed, attr_pos; |
3514 | struct attr attr_valid, attr_dir, attr_speed, attr_pos; |
3087 | struct pcoord cursor_pc; |
3515 | struct pcoord cursor_pc; |
3088 | struct point cursor_pnt, *pnt=&cursor_pnt; |
3516 | struct point cursor_pnt, *pnt = &cursor_pnt; |
3089 | struct tracking *tracking=NULL; |
3517 | struct tracking *tracking = NULL; |
3090 | struct pcoord pc[16]; |
3518 | struct pcoord pc[16]; |
3091 | enum projection pro=transform_get_projection(this_->trans_cursor); |
3519 | enum projection pro = transform_get_projection(this_->trans_cursor); |
3092 | int count; |
3520 | int count; |
3093 | int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *); |
3521 | int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *); |
3094 | void *attr_object; |
3522 | void *attr_object; |
3095 | char *destination_file; |
3523 | char *destination_file; |
3096 | |
3524 | |
3097 | // dbg(0,"navit_vehicle_update_001 %d\n",pro); |
3525 | // //DBG dbg(0,"navit_vehicle_update_001 %d\n",pro); |
3098 | //profile(0,NULL); |
3526 | //profile(0,NULL); |
3099 | if (this_->ready != 3) { |
3527 | if (this_->ready != 3) |
|
|
3528 | { |
3100 | //profile(0,"return 1\n"); |
3529 | //profile(0,"return 1\n"); |
3101 | return; |
3530 | return; |
3102 | } |
3531 | } |
3103 | navit_layout_switch(this_); |
3532 | navit_layout_switch(this_); |
3104 | if (this_->vehicle == nv && this_->tracking_flag) |
3533 | if (this_->vehicle == nv && this_->tracking_flag) |
3105 | tracking=this_->tracking; |
3534 | tracking = this_->tracking; |
3106 | if (tracking) { |
3535 | if (tracking) |
|
|
3536 | { |
3107 | tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro); |
3537 | tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro); |
3108 | attr_object=tracking; |
3538 | attr_object = tracking; |
3109 | get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr; |
3539 | get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) tracking_get_attr; |
3110 | } else { |
3540 | } |
|
|
3541 | else |
|
|
3542 | { |
3111 | attr_object=nv->vehicle; |
3543 | attr_object = nv->vehicle; |
3112 | get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr; |
3544 | get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) vehicle_get_attr; |
3113 | } |
3545 | } |
3114 | if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL)) |
3546 | if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL)) |
3115 | if (!attr_valid.u.num != attr_position_valid_invalid) |
3547 | if (!attr_valid.u.num != attr_position_valid_invalid) |
3116 | return; |
3548 | return; |
3117 | if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) || |
3549 | if (!get_attr(attr_object, attr_position_direction, &attr_dir, NULL) || !get_attr(attr_object, attr_position_speed, &attr_speed, NULL) || !get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) |
3118 | ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) || |
3550 | { |
3119 | ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) { |
|
|
3120 | // profile(0,"return 2\n"); |
3551 | // profile(0,"return 2\n"); |
3121 | return; |
3552 | return; |
3122 | } |
3553 | } |
3123 | nv->dir=*attr_dir.u.numd; |
3554 | nv->dir = *attr_dir.u.numd; |
3124 | nv->speed=*attr_speed.u.numd; |
3555 | nv->speed = *attr_speed.u.numd; |
3125 | transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord); |
3556 | transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord); |
3126 | if (nv != this_->vehicle) |
3557 | if (nv != this_->vehicle) |
3127 | { |
3558 | { |
3128 | //dbg(0,"---> 2 x=%d\n", nv->coord.x); |
3559 | ////DBG dbg(0,"---> 2 x=%d\n", nv->coord.x); |
3129 | //dbg(0,"---> 2 y=%d\n", nv->coord.y); |
3560 | ////DBG dbg(0,"---> 2 y=%d\n", nv->coord.y); |
3130 | // dbg(0,"vehicle_draw_002\n"); |
3561 | // //DBG dbg(0,"vehicle_draw_002\n"); |
3131 | navit_vehicle_draw(this_, nv, NULL); |
3562 | navit_vehicle_draw(this_, nv, NULL); |
3132 | // profile(0,"return 3\n"); |
3563 | // profile(0,"return 3\n"); |
3133 | return; |
3564 | return; |
3134 | } |
3565 | } |
3135 | cursor_pc.x = nv->coord.x; |
3566 | cursor_pc.x = nv->coord.x; |
3136 | cursor_pc.y = nv->coord.y; |
3567 | cursor_pc.y = nv->coord.y; |
3137 | cursor_pc.pro = pro; |
3568 | cursor_pc.pro = pro; |
3138 | if (this_->route) { |
3569 | if (this_->route) |
|
|
3570 | { |
3139 | if (tracking) |
3571 | if (tracking) |
3140 | route_set_position_from_tracking(this_->route, tracking, pro); |
3572 | route_set_position_from_tracking(this_->route, tracking, pro); |
3141 | else |
3573 | else |
3142 | route_set_position(this_->route, &cursor_pc); |
3574 | route_set_position(this_->route, &cursor_pc); |
3143 | } |
3575 | } |
3144 | callback_list_call_attr_0(this_->attr_cbl, attr_position); |
3576 | callback_list_call_attr_0(this_->attr_cbl, attr_position); |
3145 | navit_textfile_debug_log(this_, "type=trackpoint_tracked"); |
3577 | // navit_textfile_debug_log(this_, "type=trackpoint_tracked"); |
3146 | if (this_->gui && nv->speed > MYSTERY_SPEED) |
3578 | if (this_->gui && nv->speed > MYSTERY_SPEED) |
3147 | navit_disable_suspend(); |
3579 | navit_disable_suspend(); |
3148 | transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL); |
3580 | transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL); |
3149 | if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow && |
3581 | if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow && (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border))) |
3150 | (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border))) |
|
|
3151 | { |
3582 | { |
3152 | navit_set_center_cursor_draw(this_); |
3583 | navit_set_center_cursor_draw(this_); |
3153 | //dbg(0,"---> xxCENTER\n"); |
3584 | ////DBG dbg(0,"---> xxCENTER\n"); |
3154 | //dbg(0,"---> 3 x=%d\n", nv->coord.x); |
3585 | ////DBG dbg(0,"---> 3 x=%d\n", nv->coord.x); |
3155 | //dbg(0,"---> 3 y=%d\n", nv->coord.y); |
3586 | ////DBG dbg(0,"---> 3 y=%d\n", nv->coord.y); |
3156 | |
3587 | |
3157 | //dbg(0,"---> 4 x=%d\n", cursor_pnt.x); |
3588 | ////DBG dbg(0,"---> 4 x=%d\n", cursor_pnt.x); |
3158 | //dbg(0,"---> 4 y=%d\n", cursor_pnt.y); |
3589 | ////DBG dbg(0,"---> 4 y=%d\n", cursor_pnt.y); |
3159 | |
3590 | |
3160 | //global_vehicle_pos_onscreen.x=cursor_pnt.x; |
3591 | //global_vehicle_pos_onscreen.x=cursor_pnt.x; |
3161 | //global_vehicle_pos_onscreen.y=cursor_pnt.y; |
3592 | //global_vehicle_pos_onscreen.y=cursor_pnt.y; |
3162 | |
3593 | |
3163 | } |
3594 | } |
3164 | else |
3595 | else |
3165 | { |
3596 | { |
3166 | //dbg(0,"vehicle_draw_003\n"); |
3597 | ////DBG dbg(0,"vehicle_draw_003\n"); |
3167 | navit_vehicle_draw(this_, nv, pnt); |
3598 | navit_vehicle_draw(this_, nv, pnt); |
3168 | //global_vehicle_pos_onscreen.x=pnt->x; |
3599 | //global_vehicle_pos_onscreen.x=pnt->x; |
3169 | //global_vehicle_pos_onscreen.y=pnt->y; |
3600 | //global_vehicle_pos_onscreen.y=pnt->y; |
3170 | //dbg(0,"---> x=%d\n", pnt->x); |
3601 | ////DBG dbg(0,"---> x=%d\n", pnt->x); |
3171 | //dbg(0,"---> y=%d\n", pnt->y); |
3602 | ////DBG dbg(0,"---> y=%d\n", pnt->y); |
3172 | } |
3603 | } |
3173 | |
3604 | |
3174 | if (nv->follow_curr > 1) |
3605 | if (nv->follow_curr > 1) |
3175 | nv->follow_curr--; |
3606 | nv->follow_curr--; |
3176 | else |
3607 | else |
3177 | nv->follow_curr=nv->follow; |
3608 | nv->follow_curr = nv->follow; |
3178 | callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle); |
3609 | callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle); |
3179 | |
3610 | |
3180 | /* Finally, if we reached our destination, stop navigation. */ |
3611 | /* Finally, if we reached our destination, stop navigation. */ |
3181 | if (this_->route) { |
3612 | if (this_->route) |
|
|
3613 | { |
3182 | switch(route_destination_reached(this_->route)) { |
3614 | switch (route_destination_reached(this_->route)) |
|
|
3615 | { |
3183 | case 1: |
3616 | case 1: |
3184 | route_remove_waypoint(this_->route); |
3617 | route_remove_waypoint(this_->route); |
3185 | count=route_get_destinations(this_->route, pc, 16); |
3618 | count = route_get_destinations(this_->route, pc, 16); |
|
|
3619 | |
3186 | destination_file = bookmarks_get_destination_file(TRUE); |
3620 | // destination_file = bookmarks_get_destination_file(TRUE); |
3187 | bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count); |
3621 | // bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count); |
|
|
3622 | |
3188 | #ifdef HAVE_API_ANDROID |
3623 | #ifdef HAVE_API_ANDROID |
3189 | // waypoint reached |
3624 | // waypoint reached |
3190 | android_return_generic_int(5, 1); |
3625 | android_return_generic_int(5, 1); |
|
|
3626 | android_send_generic_text(1,"+*#O:Waypoint reached\n"); |
|
|
3627 | // say it |
|
|
3628 | navit_say(this_, _("Waypoint reached")); |
3191 | #endif |
3629 | #endif |
3192 | break; |
3630 | break; |
3193 | case 2: |
3631 | case 2: |
3194 | navit_set_destination(this_, NULL, NULL, 0); |
3632 | navit_set_destination(this_, NULL, NULL, 0); |
3195 | // ** inform java that we reached our destination ** |
3633 | // ** inform java that we reached our destination ** |
3196 | #ifdef HAVE_API_ANDROID |
3634 | #ifdef HAVE_API_ANDROID |
3197 | android_return_generic_int(4, 1); |
3635 | android_return_generic_int(4, 1); |
|
|
3636 | android_send_generic_text(1,"+*#O:You have reached your destination\n"); |
|
|
3637 | // say it |
|
|
3638 | navit_say(this_, _("You have reached your destination")); |
3198 | #endif |
3639 | #endif |
3199 | break; |
3640 | break; |
3200 | } |
3641 | } |
3201 | } |
3642 | } |
3202 | //profile(0,"return 5\n"); |
3643 | //profile(0,"return 5\n"); |
3203 | // dbg(0,"navit_vehicle_update_999\n"); |
3644 | // //DBG dbg(0,"navit_vehicle_update_999\n"); |
3204 | } |
3645 | } |
3205 | |
3646 | |
3206 | /** |
3647 | /** |
3207 | * Set the position of the vehicle |
3648 | * Set the position of the vehicle |
3208 | * |
3649 | * |
3209 | * @param navit The navit instance |
3650 | * @param navit The navit instance |
3210 | * @param c The coordinate to set as position |
3651 | * @param c The coordinate to set as position |
3211 | * @returns nothing |
3652 | * @returns nothing |
3212 | */ |
3653 | */ |
3213 | |
3654 | |
3214 | void |
|
|
3215 | navit_set_position(struct navit *this_, struct pcoord *c) |
3655 | void navit_set_position(struct navit *this_, struct pcoord *c) |
3216 | { |
3656 | { |
3217 | //dbg(0,"EEnter\n"); |
3657 | //DBG dbg(0,"EEnter\n"); |
3218 | |
3658 | |
3219 | if (this_->route) { |
3659 | if (this_->route) |
|
|
3660 | { |
3220 | route_set_position(this_->route, c); |
3661 | route_set_position(this_->route, c); |
3221 | callback_list_call_attr_0(this_->attr_cbl, attr_position); |
3662 | callback_list_call_attr_0(this_->attr_cbl, attr_position); |
3222 | } |
3663 | } |
3223 | if (this_->ready == 3) |
3664 | if (this_->ready == 3) |
3224 | navit_draw(this_); |
3665 | navit_draw(this_); |
3225 | } |
3666 | } |
3226 | |
3667 | |
3227 | static int |
|
|
3228 | navit_set_vehicleprofile(struct navit *this_, char *name) |
3668 | static int navit_set_vehicleprofile(struct navit *this_, char *name) |
3229 | { |
3669 | { |
3230 | //dbg(0,"EEnter\n"); |
3670 | ////DBG dbg(0,"EEnter\n"); |
3231 | |
3671 | |
3232 | struct attr attr; |
3672 | struct attr attr; |
3233 | GList *l; |
3673 | GList *l; |
3234 | l=this_->vehicleprofiles; |
3674 | l = this_->vehicleprofiles; |
3235 | while (l) { |
3675 | while (l) |
|
|
3676 | { |
3236 | if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) { |
3677 | if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) |
|
|
3678 | { |
3237 | if (!strcmp(attr.u.str, name)) { |
3679 | if (!strcmp(attr.u.str, name)) |
|
|
3680 | { |
3238 | this_->vehicleprofile=l->data; |
3681 | this_->vehicleprofile = l->data; |
3239 | if (this_->route) |
3682 | if (this_->route) |
3240 | route_set_profile(this_->route, this_->vehicleprofile); |
3683 | route_set_profile(this_->route, this_->vehicleprofile); |
3241 | return 1; |
3684 | return 1; |
3242 | } |
3685 | } |
3243 | } |
3686 | } |
3244 | l=g_list_next(l); |
3687 | l = g_list_next(l); |
3245 | } |
3688 | } |
3246 | return 0; |
3689 | return 0; |
3247 | } |
3690 | } |
3248 | |
3691 | |
3249 | static void |
|
|
3250 | navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv) |
3692 | static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv) |
3251 | { |
3693 | { |
3252 | //dbg(0,"EEnter\n"); |
3694 | ////DBG dbg(0,"EEnter\n"); |
3253 | |
3695 | |
3254 | struct attr attr; |
3696 | struct attr attr; |
3255 | this_->vehicle=nv; |
3697 | this_->vehicle = nv; |
3256 | if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) { |
3698 | if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) |
|
|
3699 | { |
3257 | if (navit_set_vehicleprofile(this_, attr.u.str)) |
3700 | if (navit_set_vehicleprofile(this_, attr.u.str)) |
|
|
3701 | { |
3258 | return; |
3702 | return; |
3259 | } |
3703 | } |
|
|
3704 | } |
3260 | if (!navit_set_vehicleprofile(this_,"car")) { |
3705 | if (!navit_set_vehicleprofile(this_, "car")) |
|
|
3706 | { |
3261 | /* We do not have a fallback "car" profile |
3707 | /* We do not have a fallback "car" profile |
3262 | * so lets set any profile */ |
3708 | * so lets set any profile */ |
3263 | GList *l; |
3709 | GList *l; |
3264 | l=this_->vehicleprofiles; |
3710 | l = this_->vehicleprofiles; |
3265 | if (l) { |
3711 | if (l) |
|
|
3712 | { |
3266 | this_->vehicleprofile=l->data; |
3713 | this_->vehicleprofile = l->data; |
3267 | if (this_->route) |
3714 | if (this_->route) |
|
|
3715 | { |
3268 | route_set_profile(this_->route, this_->vehicleprofile); |
3716 | route_set_profile(this_->route, this_->vehicleprofile); |
|
|
3717 | } |
3269 | } |
3718 | } |
3270 | } |
3719 | } |
3271 | } |
3720 | } |
3272 | |
3721 | |
3273 | /** |
3722 | /** |
… | |
… | |
3275 | * |
3724 | * |
3276 | * @param navit The navit instance |
3725 | * @param navit The navit instance |
3277 | * @param v The vehicle instance |
3726 | * @param v The vehicle instance |
3278 | * @returns 1 for success |
3727 | * @returns 1 for success |
3279 | */ |
3728 | */ |
3280 | static int |
|
|
3281 | navit_add_vehicle(struct navit *this_, struct vehicle *v) |
3729 | int navit_add_vehicle(struct navit *this_, struct vehicle *v) |
3282 | { |
3730 | { |
3283 | //dbg(0,"EEnter\n"); |
3731 | ////DBG dbg(0,"EEnter\n"); |
3284 | |
3732 | |
3285 | struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1); |
3733 | struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1); |
3286 | struct attr follow, active, animate; |
3734 | struct attr follow, active, animate; |
3287 | nv->vehicle=v; |
3735 | nv->vehicle = v; |
3288 | nv->follow=0; |
3736 | nv->follow = 0; |
3289 | nv->last.x = 0; |
3737 | nv->last.x = 0; |
3290 | nv->last.y = 0; |
3738 | nv->last.y = 0; |
3291 | nv->animate_cursor=0; |
3739 | nv->animate_cursor = 0; |
3292 | if ((vehicle_get_attr(v, attr_follow, &follow, NULL))) |
3740 | if ((vehicle_get_attr(v, attr_follow, &follow, NULL))) |
3293 | nv->follow=follow.u.num; |
3741 | nv->follow = follow.u.num; |
3294 | nv->follow_curr=nv->follow; |
3742 | nv->follow_curr = nv->follow; |
3295 | this_->vehicles=g_list_append(this_->vehicles, nv); |
3743 | this_->vehicles = g_list_append(this_->vehicles, nv); |
3296 | if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num) |
3744 | if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num) |
3297 | navit_set_vehicle(this_, nv); |
3745 | navit_set_vehicle(this_, nv); |
3298 | if ((vehicle_get_attr(v, attr_animate, &animate, NULL))) |
3746 | if ((vehicle_get_attr(v, attr_animate, &animate, NULL))) |
3299 | nv->animate_cursor=animate.u.num; |
3747 | nv->animate_cursor = animate.u.num; |
3300 | nv->callback.type=attr_callback; |
3748 | nv->callback.type = attr_callback; |
3301 | nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv); |
3749 | nv->callback.u.callback = callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv); |
3302 | vehicle_add_attr(nv->vehicle, &nv->callback); |
3750 | vehicle_add_attr(nv->vehicle, &nv->callback); |
3303 | vehicle_set_attr(nv->vehicle, &this_->self); |
3751 | vehicle_set_attr(nv->vehicle, &this_->self); |
3304 | return 1; |
3752 | return 1; |
3305 | } |
3753 | } |
3306 | |
3754 | |
3307 | |
|
|
3308 | |
|
|
3309 | |
|
|
3310 | struct gui * |
3755 | struct gui * |
3311 | navit_get_gui(struct navit *this_) |
3756 | navit_get_gui(struct navit *this_) |
3312 | { |
3757 | { |
3313 | return this_->gui; |
3758 | return this_->gui; |
3314 | } |
3759 | } |
… | |
… | |
3335 | navit_get_displaylist(struct navit *this_) |
3780 | navit_get_displaylist(struct navit *this_) |
3336 | { |
3781 | { |
3337 | return this_->displaylist; |
3782 | return this_->displaylist; |
3338 | } |
3783 | } |
3339 | |
3784 | |
3340 | void |
|
|
3341 | navit_layout_switch(struct navit *n) |
3785 | void navit_layout_switch(struct navit *n) |
3342 | { |
3786 | { |
3343 | //dbg(0,"EEnter\n"); |
3787 | ////DBG dbg(0,"EEnter\n"); |
3344 | |
3788 | |
3345 | int currTs=0; |
3789 | int currTs = 0; |
3346 | struct attr iso8601_attr,geo_attr,valid_attr,layout_attr; |
3790 | struct attr iso8601_attr, geo_attr, valid_attr, layout_attr; |
3347 | double trise,tset,trise_actual; |
3791 | double trise, tset, trise_actual; |
3348 | struct layout *l; |
3792 | struct layout *l; |
3349 | int year, month, day; |
3793 | int year, month, day; |
3350 | |
3794 | |
3351 | if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) { |
3795 | if (navit_get_attr(n, attr_layout, &layout_attr, NULL) != 1) |
|
|
3796 | { |
3352 | return; //No layout - nothing to switch |
3797 | return; //No layout - nothing to switch |
3353 | } |
3798 | } |
3354 | if (!n->vehicle) |
3799 | if (!n->vehicle) |
3355 | return; |
|
|
3356 | l=layout_attr.u.layout; |
|
|
3357 | |
|
|
3358 | if (l->dayname || l->nightname) { |
|
|
3359 | //Ok, we know that we have profile to switch |
|
|
3360 | |
|
|
3361 | //Check that we aren't calculating too fast |
|
|
3362 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) { |
|
|
3363 | currTs=iso8601_to_secs(iso8601_attr.u.str); |
|
|
3364 | dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60); |
|
|
3365 | } |
|
|
3366 | if (currTs-(n->prevTs)<60) { |
|
|
3367 | //We've have to wait a little |
|
|
3368 | return; |
|
|
3369 | } |
|
|
3370 | if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3) |
|
|
3371 | return; |
3800 | return; |
|
|
3801 | l = layout_attr.u.layout; |
|
|
3802 | |
|
|
3803 | if (l->dayname || l->nightname) |
|
|
3804 | { |
|
|
3805 | //Ok, we know that we have profile to switch |
|
|
3806 | |
|
|
3807 | //Check that we aren't calculating too fast |
|
|
3808 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601, &iso8601_attr, NULL) == 1) |
|
|
3809 | { |
|
|
3810 | currTs = iso8601_to_secs(iso8601_attr.u.str); |
|
|
3811 | // dbg(1, "currTs: %u:%u\n", currTs % 86400 / 3600, ((currTs % 86400) % 3600) / 60); |
|
|
3812 | } |
|
|
3813 | if (currTs - (n->prevTs) < 60) |
|
|
3814 | { |
|
|
3815 | //We've have to wait a little |
|
|
3816 | return; |
|
|
3817 | } |
|
|
3818 | if (sscanf(iso8601_attr.u.str, "%d-%02d-%02dT", &year, &month, &day) != 3) |
|
|
3819 | return; |
3372 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) { |
3820 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr, NULL) && valid_attr.u.num == attr_position_valid_invalid) |
|
|
3821 | { |
3373 | return; //No valid fix yet |
3822 | return; //No valid fix yet |
3374 | } |
3823 | } |
3375 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) { |
3824 | if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo, &geo_attr, NULL) != 1) |
|
|
3825 | { |
3376 | //No position - no sun |
3826 | //No position - no sun |
3377 | return; |
3827 | return; |
3378 | } |
3828 | } |
3379 | |
3829 | |
3380 | //We calculate sunrise anyway, cause it is needed both for day and for night |
3830 | //We calculate sunrise anyway, cause it is needed both for day and for night |
3381 | if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) { |
3831 | if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0) |
|
|
3832 | { |
3382 | //near the pole sun never rises/sets, so we should never switch profiles |
3833 | //near the pole sun never rises/sets, so we should never switch profiles |
3383 | dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise)); |
3834 | // dbg(1, "trise: %u:%u, sun never visible, never switch profile\n", HOURS(trise), MINUTES(trise)); |
3384 | n->prevTs=currTs; |
3835 | n->prevTs = currTs; |
3385 | return; |
3836 | return; |
3386 | } |
3837 | } |
3387 | |
3838 | |
3388 | trise_actual=trise; |
3839 | trise_actual = trise; |
3389 | dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise)); |
3840 | // dbg(1, "trise: %u:%u\n", HOURS(trise), MINUTES(trise)); |
3390 | if (l->dayname) { |
3841 | if (l->dayname) |
3391 | |
3842 | { |
3392 | if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) || |
3843 | |
3393 | (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) { |
3844 | if ((HOURS(trise) * 60 + MINUTES(trise) == (currTs % 86400) / 60) || (n->prevTs == 0 && ((HOURS(trise) * 60 + MINUTES(trise) < (currTs % 86400) / 60)))) |
|
|
3845 | { |
3394 | //The sun is rising now! |
3846 | //The sun is rising now! |
3395 | if (strcmp(l->name,l->dayname)) { |
3847 | if (strcmp(l->name, l->dayname)) |
|
|
3848 | { |
3396 | navit_set_layout_by_name(n,l->dayname); |
3849 | navit_set_layout_by_name(n, l->dayname); |
|
|
3850 | } |
3397 | } |
3851 | } |
3398 | } |
|
|
3399 | } |
3852 | } |
3400 | if (l->nightname) { |
3853 | if (l->nightname) |
|
|
3854 | { |
3401 | if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) { |
3855 | if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0) |
|
|
3856 | { |
3402 | //near the pole sun never rises/sets, so we should never switch profiles |
3857 | //near the pole sun never rises/sets, so we should never switch profiles |
3403 | dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset)); |
3858 | // dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset), MINUTES(tset)); |
|
|
3859 | n->prevTs = currTs; |
|
|
3860 | return; |
|
|
3861 | } |
|
|
3862 | // dbg(1, "tset: %u:%u\n", HOURS(tset), MINUTES(tset)); |
|
|
3863 | if (HOURS(tset) * 60 + MINUTES(tset) == ((currTs % 86400) / 60) || (n->prevTs == 0 && (((HOURS(tset) * 60 + MINUTES(tset) < (currTs % 86400) / 60)) || ((HOURS(trise_actual) * 60 + MINUTES(trise_actual) > (currTs % 86400) / 60))))) |
|
|
3864 | { |
|
|
3865 | //Time to sleep |
|
|
3866 | if (strcmp(l->name, l->nightname)) |
|
|
3867 | { |
|
|
3868 | navit_set_layout_by_name(n, l->nightname); |
|
|
3869 | } |
|
|
3870 | } |
|
|
3871 | } |
|
|
3872 | |
3404 | n->prevTs=currTs; |
3873 | n->prevTs = currTs; |
3405 | return; |
|
|
3406 | } |
|
|
3407 | dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset)); |
|
|
3408 | if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60) |
|
|
3409 | || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) || |
|
|
3410 | ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) { |
|
|
3411 | //Time to sleep |
|
|
3412 | if (strcmp(l->name,l->nightname)) { |
|
|
3413 | navit_set_layout_by_name(n,l->nightname); |
|
|
3414 | } |
3874 | } |
3415 | } |
|
|
3416 | } |
|
|
3417 | |
|
|
3418 | n->prevTs=currTs; |
|
|
3419 | } |
|
|
3420 | } |
3875 | } |
3421 | |
3876 | |
3422 | int |
|
|
3423 | navit_set_vehicle_by_name(struct navit *n,const char *name) |
3877 | int navit_set_vehicle_by_name(struct navit *n, const char *name) |
3424 | { |
3878 | { |
3425 | //dbg(0,"EEnter\n"); |
3879 | ////DBG dbg(0,"EEnter\n"); |
3426 | |
3880 | |
3427 | struct vehicle *v; |
3881 | struct vehicle *v; |
3428 | struct attr_iter *iter; |
3882 | struct attr_iter *iter; |
3429 | struct attr vehicle_attr, name_attr; |
3883 | struct attr vehicle_attr, name_attr; |
3430 | |
3884 | |
3431 | iter=navit_attr_iter_new(); |
3885 | iter = navit_attr_iter_new(); |
3432 | |
3886 | |
3433 | while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) { |
3887 | while (navit_get_attr(n, attr_vehicle, &vehicle_attr, iter)) |
|
|
3888 | { |
3434 | v=vehicle_attr.u.vehicle; |
3889 | v = vehicle_attr.u.vehicle; |
3435 | vehicle_get_attr(v,attr_name,&name_attr,NULL); |
3890 | vehicle_get_attr(v, attr_name, &name_attr, NULL); |
3436 | if (name_attr.type==attr_name) { |
3891 | if (name_attr.type == attr_name) |
|
|
3892 | { |
3437 | if (!strcmp(name,name_attr.u.str)) { |
3893 | if (!strcmp(name, name_attr.u.str)) |
|
|
3894 | { |
3438 | navit_set_attr(n,&vehicle_attr); |
3895 | navit_set_attr(n, &vehicle_attr); |
3439 | navit_attr_iter_destroy(iter); |
3896 | navit_attr_iter_destroy(iter); |
3440 | return 1; |
3897 | return 1; |
3441 | } |
3898 | } |
3442 | } |
3899 | } |
3443 | } |
3900 | } |
3444 | navit_attr_iter_destroy(iter); |
3901 | navit_attr_iter_destroy(iter); |
3445 | return 0; |
|
|
3446 | } |
|
|
3447 | |
|
|
3448 | int |
|
|
3449 | navit_set_layout_by_name(struct navit *n,const char *name) |
|
|
3450 | { |
|
|
3451 | //dbg(0,"EEnter\n"); |
|
|
3452 | |
|
|
3453 | struct layout *l; |
|
|
3454 | struct attr_iter iter; |
|
|
3455 | struct attr layout_attr; |
|
|
3456 | |
|
|
3457 | iter.u.list=0x00; |
|
|
3458 | |
|
|
3459 | if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) { |
|
|
3460 | return 0; //No layouts - nothing to do |
|
|
3461 | } |
|
|
3462 | if (iter.u.list==NULL) { |
|
|
3463 | return 0; |
3902 | return 0; |
3464 | } |
3903 | } |
3465 | |
3904 | |
|
|
3905 | int navit_set_layout_by_name(struct navit *n, const char *name) |
|
|
3906 | { |
|
|
3907 | ////DBG dbg(0,"EEnter\n"); |
|
|
3908 | |
|
|
3909 | struct layout *l; |
|
|
3910 | struct attr_iter iter; |
|
|
3911 | struct attr layout_attr; |
|
|
3912 | |
|
|
3913 | iter.u.list = 0x00; |
|
|
3914 | |
|
|
3915 | if (navit_get_attr(n, attr_layout, &layout_attr, &iter) != 1) |
|
|
3916 | { |
|
|
3917 | return 0; //No layouts - nothing to do |
|
|
3918 | } |
|
|
3919 | if (iter.u.list == NULL) |
|
|
3920 | { |
|
|
3921 | return 0; |
|
|
3922 | } |
|
|
3923 | |
3466 | iter.u.list=g_list_first(iter.u.list); |
3924 | iter.u.list = g_list_first(iter.u.list); |
3467 | |
3925 | |
3468 | while(iter.u.list) { |
3926 | while (iter.u.list) |
|
|
3927 | { |
3469 | l=(struct layout*)iter.u.list->data; |
3928 | l = (struct layout*) iter.u.list->data; |
3470 | if (!strcmp(name,l->name)) { |
3929 | if (!strcmp(name, l->name)) |
|
|
3930 | { |
3471 | layout_attr.u.layout=l; |
3931 | layout_attr.u.layout = l; |
3472 | layout_attr.type=attr_layout; |
3932 | layout_attr.type = attr_layout; |
3473 | navit_set_attr(n,&layout_attr); |
3933 | navit_set_attr(n, &layout_attr); |
3474 | iter.u.list=g_list_first(iter.u.list); |
3934 | iter.u.list = g_list_first(iter.u.list); |
3475 | return 1; |
3935 | return 1; |
3476 | } |
3936 | } |
3477 | iter.u.list=g_list_next(iter.u.list); |
3937 | iter.u.list = g_list_next(iter.u.list); |
3478 | } |
3938 | } |
3479 | |
3939 | |
3480 | iter.u.list=g_list_first(iter.u.list); |
3940 | iter.u.list = g_list_first(iter.u.list); |
3481 | return 0; |
3941 | return 0; |
3482 | } |
3942 | } |
3483 | |
3943 | |
3484 | void |
|
|
3485 | navit_disable_suspend() { |
3944 | void navit_disable_suspend() |
|
|
3945 | { |
3486 | //dbg(0,"EEnter\n"); |
3946 | ////DBG dbg(0,"EEnter\n"); |
3487 | |
3947 | |
3488 | gui_disable_suspend(global_navit->gui); |
3948 | gui_disable_suspend(global_navit->gui); |
3489 | callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend); |
3949 | callback_list_call_attr_0(global_navit->attr_cbl, attr_unsuspend); |
3490 | } |
3950 | } |
3491 | |
3951 | |
3492 | int |
|
|
3493 | navit_block(struct navit *this_, int block) |
3952 | int navit_block(struct navit *this_, int block) |
3494 | { |
3953 | { |
3495 | //dbg(0,"EEnter\n"); |
3954 | ////DBG dbg(0,"EEnter\n"); |
3496 | |
3955 | |
3497 | if (block > 0) { |
3956 | if (block > 0) |
|
|
3957 | { |
3498 | this_->blocked |= 1; |
3958 | this_->blocked |= 1; |
3499 | if (graphics_draw_cancel(this_->gra, this_->displaylist)) |
3959 | if (graphics_draw_cancel(this_->gra, this_->displaylist)) |
3500 | this_->blocked |= 2; |
3960 | this_->blocked |= 2; |
3501 | return 0; |
3961 | return 0; |
3502 | } |
3962 | } |
3503 | if ((this_->blocked & 2) || block < 0) { |
3963 | if ((this_->blocked & 2) || block < 0) |
|
|
3964 | { |
3504 | this_->blocked=0; |
3965 | this_->blocked = 0; |
3505 | navit_draw(this_); |
3966 | navit_draw(this_); |
3506 | return 1; |
3967 | return 1; |
3507 | } |
3968 | } |
3508 | this_->blocked=0; |
3969 | this_->blocked = 0; |
3509 | return 0; |
3970 | return 0; |
3510 | } |
3971 | } |
3511 | |
3972 | |
3512 | void |
|
|
3513 | navit_destroy(struct navit *this_) |
3973 | void navit_destroy(struct navit *this_) |
3514 | { |
3974 | { |
3515 | //dbg(0,"EEnter\n"); |
3975 | dbg(0,"EEnter\n"); |
3516 | |
3976 | |
3517 | struct mapset*ms; |
3977 | struct mapset*ms; |
3518 | callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_); |
3978 | callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_); |
3519 | |
3979 | |
3520 | // dbg(0,"enter"); |
3980 | // //DBG dbg(0,"enter"); |
3521 | |
3981 | |
3522 | /* TODO: destroy objects contained in this_ */ |
3982 | /* TODO: destroy objects contained in this_ */ |
3523 | if (this_->vehicle) |
3983 | if (this_->vehicle) |
3524 | vehicle_destroy(this_->vehicle->vehicle); |
3984 | vehicle_destroy(this_->vehicle->vehicle); |
3525 | if (this_->bookmarks) |
3985 | if (this_->bookmarks) |
3526 | { |
3986 | { |
3527 | dbg(0,"save position to file"); |
3987 | dbg(0, "save position to file\n"); |
3528 | char *center_file = bookmarks_get_center_file(TRUE); |
3988 | char *center_file = bookmarks_get_center_file(TRUE); |
3529 | bookmarks_write_center_to_file(this_->bookmarks, center_file); |
3989 | bookmarks_write_center_to_file(this_->bookmarks, center_file); |
3530 | g_free(center_file); |
3990 | g_free(center_file); |
3531 | bookmarks_destroy(this_->bookmarks); |
3991 | bookmarks_destroy(this_->bookmarks); |
|
|
3992 | dbg(0, "save position to file -> ready\n"); |
3532 | } |
3993 | } |
|
|
3994 | dbg(0,"ex 001\n"); |
3533 | callback_destroy(this_->nav_speech_cb); |
3995 | callback_destroy(this_->nav_speech_cb); |
|
|
3996 | dbg(0,"ex 002\n"); |
3534 | callback_destroy(this_->roadbook_callback); |
3997 | callback_destroy(this_->roadbook_callback); |
|
|
3998 | dbg(0,"ex 003\n"); |
3535 | callback_destroy(this_->popup_callback); |
3999 | callback_destroy(this_->popup_callback); |
|
|
4000 | dbg(0,"ex 004\n"); |
3536 | callback_destroy(this_->motion_timeout_callback); |
4001 | callback_destroy(this_->motion_timeout_callback); |
|
|
4002 | dbg(0,"ex 005\n"); |
3537 | callback_destroy(this_->progress_cb); |
4003 | callback_destroy(this_->progress_cb); |
|
|
4004 | dbg(0,"ex 006\n"); |
3538 | if(this_->gra) |
4005 | if (this_->gra) |
3539 | graphics_remove_callback(this_->gra, this_->resize_callback); |
4006 | graphics_remove_callback(this_->gra, this_->resize_callback); |
3540 | callback_destroy(this_->resize_callback); |
4007 | callback_destroy(this_->resize_callback); |
|
|
4008 | dbg(0,"ex 007\n"); |
3541 | if(this_->gra) |
4009 | if (this_->gra) |
3542 | graphics_remove_callback(this_->gra, this_->button_callback); |
4010 | graphics_remove_callback(this_->gra, this_->button_callback); |
3543 | callback_destroy(this_->button_callback); |
4011 | callback_destroy(this_->button_callback); |
|
|
4012 | dbg(0,"ex 008\n"); |
3544 | if(this_->gra) |
4013 | if (this_->gra) |
3545 | graphics_remove_callback(this_->gra, this_->motion_callback); |
4014 | graphics_remove_callback(this_->gra, this_->motion_callback); |
3546 | callback_destroy(this_->motion_callback); |
4015 | callback_destroy(this_->motion_callback); |
|
|
4016 | dbg(0,"ex 009\n"); |
3547 | if(this_->gra) |
4017 | if (this_->gra) |
3548 | graphics_remove_callback(this_->gra, this_->predraw_callback); |
4018 | graphics_remove_callback(this_->gra, this_->predraw_callback); |
3549 | callback_destroy(this_->predraw_callback); |
4019 | callback_destroy(this_->predraw_callback); |
|
|
4020 | dbg(0,"ex 010\n"); |
3550 | route_destroy(this_->route); |
4021 | route_destroy(this_->route); |
|
|
4022 | dbg(0,"ex 011\n"); |
3551 | ms = navit_get_mapset(this_); |
4023 | ms = navit_get_mapset(this_); |
|
|
4024 | dbg(0,"ex 012\n"); |
3552 | if(ms) |
4025 | if (ms) |
3553 | mapset_destroy(ms); |
4026 | mapset_destroy(ms); |
|
|
4027 | dbg(0,"ex 013\n"); |
3554 | graphics_free(this_->gra); |
4028 | graphics_free(this_->gra); |
|
|
4029 | dbg(0,"ex 014\n"); |
3555 | g_free(this_); |
4030 | g_free(this_); |
|
|
4031 | dbg(0,"ex 015\n"); |
3556 | } |
4032 | } |
3557 | |
4033 | |
3558 | /** @} */ |
4034 | /** @} */ |