/[zanavi_public1]/navit/navit/navit.c
ZANavi

Contents of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations) (download)
Sun Jun 17 08:12:47 2012 UTC (11 years, 9 months ago) by zoff99
File MIME type: text/plain
File size: 124416 byte(s)
lots of new stuff and fixes
1 zoff99 2 /**
2 zoff99 27 * 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    
20     /**
21 zoff99 2 * Navit, a modular navigation system.
22     * Copyright (C) 2005-2009 Navit Team
23     *
24     * This program is free software; you can redistribute it and/or
25     * modify it under the terms of the GNU General Public License
26     * version 2 as published by the Free Software Foundation.
27     *
28     * This program is distributed in the hope that it will be useful,
29     * but WITHOUT ANY WARRANTY; without even the implied warranty of
30     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31     * GNU General Public License for more details.
32     *
33     * You should have received a copy of the GNU General Public License
34     * along with this program; if not, write to the
35     * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36     * Boston, MA 02110-1301, USA.
37     */
38    
39     #define _USE_MATH_DEFINES 1
40     #include "config.h"
41     #ifdef HAVE_UNISTD_H
42     #include <unistd.h>
43     #endif
44     #include <stdio.h>
45     #include <stdlib.h>
46     #include <signal.h>
47     #include <string.h>
48     #include <fcntl.h>
49     #include <glib.h>
50     #include <math.h>
51     #include <time.h>
52     #include "debug.h"
53     #include "navit.h"
54     #include "callback.h"
55     #include "gui.h"
56     #include "item.h"
57     #include "projection.h"
58     #include "map.h"
59     #include "mapset.h"
60     #include "main.h"
61     #include "coord.h"
62     #include "point.h"
63     #include "transform.h"
64     #include "param.h"
65     #include "menu.h"
66     #include "graphics.h"
67     #include "popup.h"
68     #include "data_window.h"
69     #include "route.h"
70     #include "navigation.h"
71     #include "speech.h"
72     #include "track.h"
73     #include "vehicle.h"
74     #include "layout.h"
75     #include "log.h"
76     #include "attr.h"
77     #include "event.h"
78     #include "file.h"
79     #include "profile.h"
80     #include "command.h"
81     #include "navit_nls.h"
82     #include "map.h"
83     #include "util.h"
84     #include "messages.h"
85     #include "vehicleprofile.h"
86     #include "sunriset.h"
87     #include "bookmarks.h"
88 zoff99 27 #include "map.h"
89 zoff99 2 #ifdef HAVE_API_WIN32_BASE
90     #include <windows.h>
91     #include "util.h"
92     #endif
93     #ifdef HAVE_API_WIN32_CE
94     #include "libc.h"
95     #endif
96    
97     /**
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
99     * @{
100     */
101    
102     struct gui *main_loop_gui;
103    
104 zoff99 27 struct attr_iter
105     {
106     union
107     {
108 zoff99 2 GList *list;
109     struct mapset_handle *mapset_handle;
110     } u;
111     };
112    
113     static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
114     static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
115     static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
116     static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
117     static void navit_cmd_zoom_to_route(struct navit *this);
118     static void navit_cmd_set_center_cursor(struct navit *this_);
119     static void navit_cmd_announcer_toggle(struct navit *this_);
120     static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
121    
122     int allow_gui_internal = 0;
123     int routing_mode = 0;
124     int MYSTERY_SPEED = 2;
125 zoff99 14 int offline_search_filter_duplicates = 0;
126     int offline_search_break_searching = 0;
127 zoff99 27 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 zoff99 28 int shift_order = 0; // shift order level (for displaying objects) by this values (should only be bigger than zero!!)
135 zoff99 27 int global_search_street_size_factor = 1; // make search radius for streets bigger
136 zoff99 28 int disable_map_drawing = 0; // dont draw the map and dont read data from file (hopefully saving resources)
137     int enable_water_from_relations = 1; // do you want to draw water where the "tags" come from osm-"relations"
138     int hold_drawing = 0; // 0 -> draw normal , 1 -> dont do any drawing
139 zoff99 2
140 zoff99 28 long long draw_lines_count_2 = 0;
141     long long draw_lines_count_3 = 0;
142     long long draw_lines_count_4 = 0;
143    
144     int mapdraw_time[11 + 5]; // time to draw map on screen (in 1/1000 of a second) [add 5, just in case we inc it 2 times at same time because of threads]
145     int cur_mapdraw_time_index = 0;
146    
147 zoff99 27 void navit_add_mapset(struct navit *this_, struct mapset *ms)
148 zoff99 2 {
149 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
150     dbg(0,"+#+:enter\n");
151     #endif
152 zoff99 27 ////DBG dbg(0,"EEnter\n");
153 zoff99 2 this_->mapsets = g_list_append(this_->mapsets, ms);
154 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
155     dbg(0,"+#+:leave\n");
156     #endif
157 zoff99 2 }
158    
159     struct mapset *
160     navit_get_mapset(struct navit *this_)
161     {
162 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
163     dbg(0,"+#+:enter\n");
164     #endif
165 zoff99 27 ////DBG dbg(0,"EEnter\n");
166     if (this_->mapsets)
167     {
168 zoff99 2 return this_->mapsets->data;
169     }
170 zoff99 27 else
171     {
172     //DBG dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
173     }
174 zoff99 2 return NULL;
175     }
176    
177     struct tracking *
178     navit_get_tracking(struct navit *this_)
179     {
180 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
181     dbg(0,"+#+:enter\n");
182     #endif
183 zoff99 27 ////DBG dbg(0,"EEnter\n");
184 zoff99 2 return this_->tracking;
185     }
186    
187     /**
188     * @brief Get the user data directory.
189     * @param[in] create - create the directory if it does not exist
190     *
191     * @return char * to the data directory string.
192     *
193     * returns the directory used to store user data files (center.txt,
194     * destination.txt, bookmark.txt, ...)
195     *
196     */
197     char*
198 zoff99 27 navit_get_user_data_directory(int create)
199     {
200 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
201     dbg(0,"+#+:enter\n");
202     #endif
203 zoff99 27 ////DBG dbg(0,"EEnter\n");
204 zoff99 2 char *dir;
205     dir = getenv("NAVIT_USER_DATADIR");
206 zoff99 27 if (create && !file_exists(dir))
207     {
208     //DBG dbg(0, "creating dir %s\n", dir);
209     if (file_mkdir(dir, 0))
210     {
211     //DBG dbg(0, "failed creating dir %s\n", dir);
212 zoff99 2 return NULL;
213     }
214     }
215     return dir;
216     } /* end: navit_get_user_data_directory(gboolean create) */
217    
218 zoff99 27 void navit_draw_async(struct navit *this_, int async)
219 zoff99 2 {
220 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
221     dbg(0,"+#+:enter\n");
222     #endif
223     //dbg(0,"EEnter this_->blocked=%d\n",this_->blocked);
224 zoff99 2 if (this_->blocked)
225     {
226     this_->blocked |= 2;
227 zoff99 28 //dbg(0,"set this_->blocked=%d\n",this_->blocked);
228 zoff99 2 return;
229     }
230     transform_setup_source_rect(this_->trans);
231 zoff99 28 //dbg(0,"call graphics_draw\n");
232 zoff99 27 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags | 1);
233 zoff99 2 }
234    
235 zoff99 27 void navit_draw(struct navit *this_)
236 zoff99 2 {
237 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
238     dbg(0,"+#+:enter\n");
239     #endif
240    
241     //dbg(0,"EEnter this_->ready=%d\n",this_->ready);
242 zoff99 2 if (this_->ready == 3)
243     {
244 zoff99 28 //dbg(0,"navit_draw_async_001\n");
245 zoff99 2 navit_draw_async(this_, 0);
246     }
247     }
248    
249 zoff99 27 int navit_get_ready(struct navit *this_)
250 zoff99 2 {
251 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
252     dbg(0,"+#+:enter\n");
253     #endif
254 zoff99 27 ////DBG dbg(0,"EEnter\n");
255 zoff99 2 return this_->ready;
256     }
257    
258 zoff99 27 void navit_draw_displaylist(struct navit *this_)
259 zoff99 2 {
260 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
261     dbg(0,"+#+:enter\n");
262     #endif
263 zoff99 27 ////DBG dbg(0,"EEnter\n");
264 zoff99 2 if (this_->ready == 3)
265     {
266 zoff99 27 // //DBG dbg(0,"call graphics_displaylist_draw 2")
267     graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags | 1);
268 zoff99 2 }
269     }
270    
271 zoff99 27 static void navit_map_progress(struct navit *this_)
272 zoff99 2 {
273 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
274     dbg(0,"+#+:enter\n");
275     #endif
276 zoff99 27 ////DBG dbg(0,"EEnter\n");
277 zoff99 2 struct map *map;
278     struct mapset *ms;
279     struct mapset_handle *msh;
280     struct attr attr;
281     struct point p;
282     if (this_->ready != 3)
283     return;
284 zoff99 27 p.x = 10;
285     p.y = 32;
286 zoff99 2
287 zoff99 27 ms = this_->mapsets->data;
288     msh = mapset_open(ms);
289     while (msh && (map = mapset_next(msh, 0)))
290     {
291     if (map_get_attr(map, attr_progress, &attr, NULL))
292     {
293     char *str = g_strdup_printf("%s ", attr.u.str);
294 zoff99 2 graphics_draw_mode(this_->gra, draw_mode_begin);
295     graphics_draw_text_std(this_->gra, 16, str, &p);
296     g_free(str);
297 zoff99 27 p.y += 32;
298 zoff99 2 graphics_draw_mode(this_->gra, draw_mode_end);
299     }
300     }
301     mapset_close(msh);
302     }
303    
304 zoff99 27 static void navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
305 zoff99 2 {
306 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
307     dbg(0,"+#+:enter\n");
308     #endif
309    
310 zoff99 27 ////DBG dbg(0,"EEnter\n");
311 zoff99 2 int updated;
312    
313 zoff99 27 if ((this_->route) && (this_->route->route_status_was_updated == 1))
314 zoff99 2 {
315 zoff99 27 this_->route->route_status_was_updated = 0;
316 zoff99 2 // send route_status to java
317     #ifdef HAVE_API_ANDROID
318     android_return_generic_int(1, this_->route->route_status);
319     #endif
320     }
321    
322     if (attr->type != attr_route_status)
323     {
324 zoff99 27 ////DBG dbg(0,"ret 1\n");
325 zoff99 2 return;
326     }
327 zoff99 27 updated = attr->u.num;
328     ////DBG dbg(0,"updated=%d\n", updated);
329 zoff99 2 if (this_->ready != 3)
330     {
331 zoff99 27 ////DBG dbg(0,"ret 2\n");
332 zoff99 2 return;
333     }
334     if (updated != route_status_path_done_new)
335     {
336 zoff99 27 ////DBG dbg(0,"ret 3\n");
337 zoff99 2 return;
338     }
339     if (this_->vehicle)
340     {
341     if (this_->vehicle->follow_curr == 1)
342     {
343 zoff99 27 ////DBG dbg(0,"ret 4\n");
344     ////DBG dbg(0,"disabled -> we want redraw!!\n");
345 zoff99 2 // return;
346     }
347     if (this_->vehicle->follow_curr <= this_->vehicle->follow)
348     {
349 zoff99 27 this_->vehicle->follow_curr = this_->vehicle->follow;
350 zoff99 2 }
351     }
352 zoff99 27 ////DBG dbg(0,"draw s*\n");
353 zoff99 2 navit_draw(this_);
354 zoff99 27 ////DBG dbg(0,"draw e*\n");
355 zoff99 2 }
356    
357 zoff99 27 void navit_handle_resize(struct navit *this_, int w, int h)
358 zoff99 2 {
359 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
360     dbg(0,"+#+:enter\n");
361     #endif
362    
363     dbg(0,"EEnter\n");
364 zoff99 2 struct map_selection sel;
365 zoff99 27 int callback = (this_->ready == 1);
366 zoff99 28 dbg(0,"pre this_->ready=%d\n",this_->ready);
367     this_->ready = this_->ready | 2;
368     dbg(0,"set this_->ready=%d\n",this_->ready);
369 zoff99 2 memset(&sel, 0, sizeof(sel));
370 zoff99 27 this_->w = w;
371     this_->h = h;
372     sel.u.p_rect.rl.x = w;
373     sel.u.p_rect.rl.y = h;
374 zoff99 2 transform_set_screen_selection(this_->trans, &sel);
375     graphics_init(this_->gra);
376     graphics_set_rect(this_->gra, &sel.u.p_rect);
377 zoff99 27 if (callback)
378     {
379     //DBG dbg(0,"callback do\n");
380 zoff99 2 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
381 zoff99 27 }
382 zoff99 2 if (this_->ready == 3)
383     {
384 zoff99 28 dbg(0,"navit_draw_async_002\n");
385     // navit_draw_async(this_, 1);
386     navit_draw_async(this_, 0);
387 zoff99 2 }
388     }
389    
390 zoff99 27 void navit_resize(void *data, int w, int h)
391 zoff99 2 {
392 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
393     dbg(0,"+#+:enter\n");
394     #endif
395    
396 zoff99 27 //DBG dbg(0,"EEnter %p\n", data);
397     struct navit *this = data;
398 zoff99 2 if (!this->ignore_graphics_events)
399 zoff99 27 {
400     //DBG dbg(0,"11\n");
401 zoff99 2 navit_handle_resize(this, w, h);
402 zoff99 27 }
403 zoff99 2 }
404    
405 zoff99 27 int navit_get_width(struct navit *this_)
406 zoff99 2 {
407 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
408     dbg(0,"+#+:enter\n");
409     #endif
410 zoff99 27 ////DBG dbg(0,"EEnter\n");
411 zoff99 2 return this_->w;
412     }
413    
414 zoff99 27 int navit_get_height(struct navit *this_)
415 zoff99 2 {
416 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
417     dbg(0,"+#+:enter\n");
418     #endif
419 zoff99 27 ////DBG dbg(0,"EEnter\n");
420 zoff99 2 return this_->h;
421     }
422    
423 zoff99 27 static void navit_popup(void *data)
424 zoff99 2 {
425 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
426     dbg(0,"+#+:enter\n");
427     #endif
428 zoff99 27 ////DBG dbg(0,"EEnter\n");
429     struct navit *this_ = data;
430 zoff99 2 popup(this_, 1, &this_->pressed);
431 zoff99 27 this_->button_timeout = NULL;
432     this_->popped = 1;
433 zoff99 2 }
434    
435 zoff99 27 int navit_ignore_button(struct navit *this_)
436 zoff99 2 {
437 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
438     dbg(0,"+#+:enter\n");
439     #endif
440 zoff99 27 ////DBG dbg(0,"EEnter\n");
441 zoff99 2 if (this_->ignore_button)
442     return 1;
443 zoff99 27 this_->ignore_button = 1;
444 zoff99 2 return 0;
445     }
446    
447 zoff99 27 void navit_ignore_graphics_events(struct navit *this_, int ignore)
448 zoff99 2 {
449 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
450     dbg(0,"+#+:enter\n");
451     #endif
452 zoff99 27 ////DBG dbg(0,"EEnter\n");
453     this_->ignore_graphics_events = ignore;
454 zoff99 2 }
455    
456 zoff99 28 void update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
457 zoff99 2 {
458 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
459     dbg(0,"+#+:enter\n");
460     #endif
461 zoff99 27 ////DBG dbg(0,"EEnter\n");
462     struct coord co, cn;
463     struct coord c, *cp;
464 zoff99 2 int yaw;
465 zoff99 27 double angleo, anglen;
466 zoff99 2
467     if (!transform_reverse(tr, old, &co))
468     return;
469 zoff99 27 if (rot)
470     {
471     angleo = atan2(old->y - rot->y, old->x - rot->x) * 180 / M_PI;
472     anglen = atan2(new->y - rot->y, new->x - rot->x) * 180 / M_PI;
473     yaw = transform_get_yaw(tr) + angleo - anglen;
474 zoff99 2 transform_set_yaw(tr, yaw % 360);
475     }
476     if (!transform_reverse(tr, new, &cn))
477     return;
478 zoff99 27 cp = transform_get_center(tr);
479     c.x = cp->x + co.x - cn.x;
480     c.y = cp->y + co.y - cn.y;
481     // dbg(1, "from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
482 zoff99 2 transform_set_center(tr, &c);
483     }
484    
485 zoff99 27 void navit_set_timeout(struct navit *this_)
486 zoff99 2 {
487 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
488     dbg(0,"+#+:enter\n");
489     #endif
490    
491     // --------- DISABLE -----------
492     // --------- DISABLE -----------
493     // --------- DISABLE -----------
494     // --------- DISABLE -----------
495     return;
496     // --------- DISABLE -----------
497     // --------- DISABLE -----------
498     // --------- DISABLE -----------
499     // --------- DISABLE -----------
500    
501    
502 zoff99 27 ////DBG dbg(0,"EEnter\n");
503 zoff99 2 struct attr follow;
504 zoff99 27 follow.type = attr_follow;
505     follow.u.num = this_->center_timeout;
506 zoff99 2 navit_set_attr(this_, &follow);
507     }
508    
509 zoff99 27 int navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
510 zoff99 2 {
511 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
512     dbg(0,"+#+:enter\n");
513     #endif
514 zoff99 27 ////DBG dbg(0,"EEnter\n");
515     int border = 16;
516 zoff99 2
517 zoff99 27 // dbg(1, "enter %d %d (ignore %d)\n", pressed, button, this_->ignore_button);
518 zoff99 2 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
519 zoff99 27 if (this_->ignore_button)
520     {
521     this_->ignore_button = 0;
522 zoff99 2 return 0;
523     }
524 zoff99 27 if (pressed)
525     {
526     this_->pressed = *p;
527     this_->last = *p;
528     this_->zoomed = 0;
529     if (button == 1)
530     {
531     this_->button_pressed = 1;
532     this_->moved = 0;
533     this_->popped = 0;
534 zoff99 28 // ---- DISBALED --------
535     /*
536 zoff99 2 if (popup_callback)
537 zoff99 27 this_->button_timeout = event_add_timeout(500, 0, popup_callback);
538 zoff99 28 */
539 zoff99 2 }
540     if (button == 2)
541     navit_set_center_screen(this_, p, 1);
542     if (button == 3)
543     popup(this_, button, p);
544 zoff99 27 if (button == 4 && this_->use_mousewheel)
545     {
546 zoff99 2 this_->zoomed = 1;
547     navit_zoom_in(this_, 2, p);
548     }
549 zoff99 27 if (button == 5 && this_->use_mousewheel)
550     {
551 zoff99 2 this_->zoomed = 1;
552     navit_zoom_out(this_, 2, p);
553     }
554 zoff99 27 }
555     else
556     {
557 zoff99 2
558 zoff99 27 this_->button_pressed = 0;
559     if (this_->button_timeout)
560     {
561 zoff99 2 event_remove_timeout(this_->button_timeout);
562 zoff99 27 this_->button_timeout = NULL;
563     if (!this_->moved && !transform_within_border(this_->trans, p, border))
564     {
565 zoff99 2 navit_set_center_screen(this_, p, !this_->zoomed);
566     }
567     }
568 zoff99 27 if (this_->motion_timeout)
569     {
570 zoff99 2 event_remove_timeout(this_->motion_timeout);
571 zoff99 27 this_->motion_timeout = NULL;
572 zoff99 2 }
573 zoff99 27 if (this_->moved)
574     {
575 zoff99 2 struct point pr;
576 zoff99 27 pr.x = this_->w / 2;
577     pr.y = this_->h;
578 zoff99 2 #if 0
579     update_transformation(this_->trans, &this_->pressed, p, &pr);
580     #else
581     update_transformation(this_->trans, &this_->pressed, p, NULL);
582     #endif
583     graphics_draw_drag(this_->gra, NULL);
584     transform_copy(this_->trans, this_->trans_cursor);
585     graphics_overlay_disable(this_->gra, 0);
586 zoff99 27 if (!this_->zoomed)
587 zoff99 2 navit_set_timeout(this_);
588     navit_draw(this_);
589 zoff99 27 }
590     else
591 zoff99 2 return 1;
592     }
593     return 0;
594     }
595    
596 zoff99 27 static void navit_button(void *data, int pressed, int button, struct point *p)
597 zoff99 2 {
598 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
599     dbg(0,"+#+:enter\n");
600     #endif
601 zoff99 27 ////DBG dbg(0,"EEnter\n");
602     struct navit *this = data;
603     // dbg(1, "enter %d %d ignore %d\n", pressed, button, this->ignore_graphics_events);
604     if (!this->ignore_graphics_events)
605     {
606     if (!this->popup_callback)
607 zoff99 28 {
608 zoff99 27 this->popup_callback = callback_new_1(callback_cast(navit_popup), this);
609 zoff99 28 }
610 zoff99 2 navit_handle_button(this, pressed, button, p, this->popup_callback);
611     }
612     }
613    
614 zoff99 27 static void navit_motion_timeout(struct navit *this_)
615 zoff99 2 {
616 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
617     dbg(0,"+#+:enter\n");
618     #endif
619 zoff99 27 ////DBG dbg(0,"EEnter\n");
620 zoff99 2 int dx, dy;
621    
622 zoff99 27 if (this_->drag_bitmap)
623     {
624 zoff99 2 struct point point;
625 zoff99 27 point.x = (this_->current.x - this_->pressed.x);
626     point.y = (this_->current.y - this_->pressed.y);
627     if (graphics_draw_drag(this_->gra, &point))
628     {
629 zoff99 2 graphics_overlay_disable(this_->gra, 1);
630     graphics_draw_mode(this_->gra, draw_mode_end);
631 zoff99 27 this_->moved = 1;
632     this_->motion_timeout = NULL;
633 zoff99 2 return;
634     }
635 zoff99 27 }
636     dx = (this_->current.x - this_->last.x);
637     dy = (this_->current.y - this_->last.y);
638     if (dx || dy)
639     {
640 zoff99 2 struct transformation *tr;
641     struct point pr;
642 zoff99 27 this_->last = this_->current;
643 zoff99 2 graphics_overlay_disable(this_->gra, 1);
644 zoff99 27 tr = transform_dup(this_->trans);
645     pr.x = this_->w / 2;
646     pr.y = this_->h;
647 zoff99 2 #if 0
648     update_transformation(tr, &this_->pressed, &this_->current, &pr);
649     #else
650     update_transformation(tr, &this_->pressed, &this_->current, NULL);
651     #endif
652     #if 0
653     graphics_displaylist_move(this_->displaylist, dx, dy);
654     #endif
655     graphics_draw_cancel(this_->gra, this_->displaylist);
656 zoff99 27 // //DBG dbg(0,"call graphics_displaylist_draw 1")
657 zoff99 2 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
658     transform_destroy(tr);
659 zoff99 27 this_->moved = 1;
660 zoff99 2 }
661 zoff99 27 this_->motion_timeout = NULL;
662 zoff99 2 return;
663     }
664    
665 zoff99 27 void navit_handle_motion(struct navit *this_, struct point *p)
666 zoff99 2 {
667 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
668     dbg(0,"+#+:enter\n");
669     #endif
670 zoff99 27 ////DBG dbg(0,"EEnter\n");
671 zoff99 2 int dx, dy;
672    
673 zoff99 27 if (this_->button_pressed && !this_->popped)
674     {
675     dx = (p->x - this_->pressed.x);
676     dy = (p->y - this_->pressed.y);
677     if (dx < -8 || dx > 8 || dy < -8 || dy > 8)
678     {
679     this_->moved = 1;
680     if (this_->button_timeout)
681     {
682 zoff99 2 event_remove_timeout(this_->button_timeout);
683 zoff99 27 this_->button_timeout = NULL;
684 zoff99 2 }
685 zoff99 27 this_->current = *p;
686 zoff99 28
687     // -------- DISABLE -------
688     // -------- DISABLE -------
689     // -------- DISABLE -------
690     /*
691 zoff99 27 if (!this_->motion_timeout_callback)
692     this_->motion_timeout_callback = callback_new_1(callback_cast(navit_motion_timeout), this_);
693     if (!this_->motion_timeout)
694     this_->motion_timeout = event_add_timeout(100, 0, this_->motion_timeout_callback);
695 zoff99 28 */
696     // -------- DISABLE -------
697     // -------- DISABLE -------
698     // -------- DISABLE -------
699 zoff99 2 }
700     }
701     }
702    
703 zoff99 28 void navit_motion(void *data, struct point *p)
704 zoff99 2 {
705 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
706     dbg(0,"+#+:enter\n");
707     #endif
708 zoff99 27 ////DBG dbg(0,"EEnter\n");
709     struct navit *this = data;
710     if (!this->ignore_graphics_events)
711 zoff99 28 {
712 zoff99 2 navit_handle_motion(this, p);
713 zoff99 28 }
714 zoff99 2 }
715    
716 zoff99 27 static void navit_predraw(struct navit *this_)
717 zoff99 2 {
718 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
719     dbg(0,"+#+:enter\n");
720     #endif
721 zoff99 27 ////DBG dbg(0,"EEnter\n");
722 zoff99 2 GList *l;
723     struct navit_vehicle *nv;
724     transform_copy(this_->trans, this_->trans_cursor);
725 zoff99 27 l = this_->vehicles;
726 zoff99 2 while (l)
727     {
728 zoff99 27 nv = l->data;
729     ////DBG dbg(0,"* here *\n");
730     ////DBG dbg(0,"vehicle_draw_004\n");
731 zoff99 2 navit_vehicle_draw(this_, nv, NULL);
732 zoff99 27 l = g_list_next(l);
733 zoff99 2 }
734     }
735    
736 zoff99 27 static void navit_scale(struct navit *this_, long scale, struct point *p, int draw)
737 zoff99 2 {
738 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
739     dbg(0,"+#+:enter\n");
740     #endif
741 zoff99 27 //DBG dbg(0,"EEnter\n");
742 zoff99 2 struct coord c1, c2, *center;
743    
744     if (scale < this_->zoom_min)
745     {
746 zoff99 27 scale = this_->zoom_min;
747 zoff99 2 }
748    
749     if (scale > this_->zoom_max)
750     {
751 zoff99 27 scale = this_->zoom_max;
752 zoff99 2 }
753    
754     // return scale value to android
755     #ifdef HAVE_API_ANDROID
756     android_return_generic_int(3, (int)scale);
757     #endif
758    
759     if (p)
760     {
761     transform_reverse(this_->trans, p, &c1);
762     }
763    
764     transform_set_scale(this_->trans, scale);
765    
766     if (p)
767     {
768     transform_reverse(this_->trans, p, &c2);
769     center = transform_center(this_->trans);
770     center->x += c1.x - c2.x;
771     center->y += c1.y - c2.y;
772     }
773    
774 zoff99 27 //DBG dbg(0,"aa331\n");
775    
776 zoff99 2 if (draw)
777     {
778     navit_draw(this_);
779     }
780 zoff99 27
781     //DBG dbg(0,"leave\n");
782 zoff99 2 }
783    
784     /**
785     * @brief Automatically adjusts zoom level
786     *
787     * This function automatically adjusts the current
788     * zoom level according to the current speed.
789     *
790     * @param this_ The navit struct
791     * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
792     * @param speed The vehicles speed in meters per second
793     * @param dir The direction into which the vehicle moves
794     */
795 zoff99 27 static void navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
796 zoff99 2 {
797 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
798     dbg(0,"+#+:enter\n");
799     #endif
800 zoff99 2 struct point pc;
801 zoff99 27 int distance, w, h;
802 zoff99 2 double new_scale;
803     long scale;
804    
805 zoff99 27 if (!this_->autozoom_active)
806     {
807 zoff99 2 return;
808     }
809    
810     distance = speed * this_->autozoom_secs;
811    
812     transform_get_size(this_->trans, &w, &h);
813     transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
814     scale = transform_get_scale(this_->trans);
815    
816     /* We make sure that the point we want to see is within a certain range
817     * around the vehicle. The radius of this circle is the size of the
818     * screen. This doesn't necessarily mean the point is visible because of
819     * perspective etc. Quite rough, but should be enough. */
820 zoff99 27
821     if (w > h)
822     {
823     new_scale = (double) distance / h * 16;
824 zoff99 2 }
825 zoff99 27 else
826     {
827     new_scale = (double) distance / w * 16;
828     }
829 zoff99 2
830 zoff99 27 if (abs(new_scale - scale) < 2)
831     {
832 zoff99 2 return; // Smoothing
833     }
834 zoff99 27
835     if (new_scale >= this_->autozoom_min)
836     {
837     navit_scale(this_, (long) new_scale, &pc, 0);
838     }
839     else
840     {
841     if (scale != this_->autozoom_min)
842     {
843 zoff99 2 navit_scale(this_, this_->autozoom_min, &pc, 0);
844     }
845     }
846     }
847    
848     /**
849     * Change the current zoom level, zooming closer to the ground
850     *
851     * @param navit The navit instance
852     * @param factor The zoom factor, usually 2
853     * @param p The invariant point (if set to NULL, default to center)
854     * @returns nothing
855     */
856 zoff99 27 void navit_zoom_in(struct navit *this_, int factor, struct point *p)
857 zoff99 2 {
858 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
859     dbg(0,"+#+:enter\n");
860     #endif
861 zoff99 27 ////DBG dbg(0,"EEnter\n");
862     long scale = transform_get_scale(this_->trans) / factor;
863 zoff99 2 if (scale < 1)
864 zoff99 27 scale = 1;
865     ////DBG dbg(0,"zoom in -> scale=%d",scale);
866 zoff99 2 navit_scale(this_, scale, p, 1);
867     }
868    
869     /**
870     * Change the current zoom level
871     *
872     * @param navit The navit instance
873     * @param factor The zoom factor, usually 2
874     * @param p The invariant point (if set to NULL, default to center)
875     * @returns nothing
876     */
877 zoff99 27 void navit_zoom_out(struct navit *this_, int factor, struct point *p)
878 zoff99 2 {
879 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
880     dbg(0,"+#+:enter\n");
881     #endif
882 zoff99 27 ////DBG dbg(0,"EEnter\n");
883     long scale = transform_get_scale(this_->trans) * factor;
884     ////DBG dbg(0,"zoom out -> scale=%d",scale);
885 zoff99 2 navit_scale(this_, scale, p, 1);
886     }
887    
888 zoff99 27 int navit_get_cur_pnt(struct navit *this_, struct point *p)
889 zoff99 2 {
890 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
891     dbg(0,"+#+:enter\n");
892     #endif
893 zoff99 27 ////DBG dbg(0,"EEnter\n");
894 zoff99 2 return navit_get_cursor_pnt(this_, p, 0, NULL);
895     }
896    
897 zoff99 27 void navit_zoom_in_cursor(struct navit *this_, int factor)
898 zoff99 2 {
899 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
900     dbg(0,"+#+:enter\n");
901     #endif
902 zoff99 27 ////DBG dbg(0,"EEnter\n");
903 zoff99 2 struct point p;
904 zoff99 27 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL))
905     {
906 zoff99 2 navit_zoom_in(this_, factor, &p);
907 zoff99 27 this_->vehicle->follow_curr = this_->vehicle->follow;
908     }
909     else
910 zoff99 2 navit_zoom_in(this_, factor, NULL);
911     }
912    
913 zoff99 27 void navit_zoom_to_scale(struct navit *this_, int new_scale)
914 zoff99 2 {
915 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
916     dbg(0,"+#+:enter\n");
917     #endif
918 zoff99 27 //DBG dbg(0,"EEnter\n");
919     long scale = transform_get_scale(this_->trans);
920     long new_scale_long = new_scale;
921     //DBG dbg(0,"zoom to scale -> old scale=%d",scale);
922     //DBG dbg(0,"zoom to scale -> want scale=%d",new_scale_long);
923 zoff99 2
924     // only do something if scale changed!
925     if (scale != new_scale_long)
926     {
927     navit_scale(this_, new_scale_long, NULL, 1);
928     }
929 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
930     dbg(0,"+#+:leave\n");
931     #endif
932 zoff99 2 }
933    
934 zoff99 28 void navit_zoom_to_scale_with_center_point(struct navit *this_, int new_scale, struct point *p)
935     {
936     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
937     dbg(0,"+#+:enter\n");
938     #endif
939     //DBG dbg(0,"EEnter\n");
940     long scale = transform_get_scale(this_->trans);
941     long new_scale_long = new_scale;
942     dbg(0, "zoom to scale -> old scale=%d", scale);
943     dbg(0, "zoom to scale -> want scale=%d", new_scale_long);
944    
945     // only do something if scale changed!
946     if (scale != new_scale_long)
947     {
948     navit_scale(this_, new_scale_long, p, 1);
949     }
950     }
951    
952 zoff99 27 void navit_zoom_out_cursor(struct navit *this_, int factor)
953 zoff99 2 {
954 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
955     dbg(0,"+#+:enter\n");
956     #endif
957 zoff99 27 ////DBG dbg(0,"EEnter\n");
958 zoff99 2 struct point p;
959 zoff99 27 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL))
960     {
961 zoff99 2 navit_zoom_out(this_, 2, &p);
962 zoff99 27 this_->vehicle->follow_curr = this_->vehicle->follow;
963     }
964     else
965 zoff99 2 navit_zoom_out(this_, 2, NULL);
966     }
967    
968 zoff99 27 static int navit_cmd_zoom_in(struct navit *this_)
969 zoff99 2 {
970 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
971     dbg(0,"+#+:enter\n");
972     #endif
973 zoff99 27 ////DBG dbg(0,"EEnter\n");
974 zoff99 2 navit_zoom_in_cursor(this_, 2);
975     return 0;
976     }
977    
978 zoff99 27 static int navit_cmd_zoom_out(struct navit *this_)
979 zoff99 2 {
980 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
981     dbg(0,"+#+:enter\n");
982     #endif
983 zoff99 27 ////DBG dbg(0,"EEnter\n");
984 zoff99 2 navit_zoom_out_cursor(this_, 2);
985     return 0;
986     }
987    
988 zoff99 27 static void navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
989 zoff99 2 {
990 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
991     dbg(0,"+#+:enter\n");
992     #endif
993 zoff99 27 ////DBG dbg(0,"EEnter\n");
994     if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
995     {
996 zoff99 2 navit_say(this, in[0]->u.str);
997 zoff99 27 }
998 zoff99 2 }
999    
1000     static GHashTable *cmd_int_var_hash = NULL;
1001     static GHashTable *cmd_attr_var_hash = NULL;
1002    
1003     /**
1004     * Store key value pair for the command system (for int typed values)
1005     *
1006     * @param navit The navit instance
1007     * @param function unused (needed to match command function signiture)
1008     * @param in input attributes in[0] is the key string, in[1] is the integer value to store
1009     * @param out output attributes, unused
1010     * @param valid unused
1011     * @returns nothing
1012     */
1013 zoff99 27 static void navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1014 zoff99 2 {
1015 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1016     dbg(0,"+#+:enter\n");
1017     #endif
1018 zoff99 27 ////DBG dbg(0,"EEnter\n");
1019 zoff99 2 char*key;
1020     struct attr*val;
1021 zoff99 27 if (!cmd_int_var_hash)
1022     {
1023 zoff99 2 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1024     }
1025    
1026 zoff99 27 if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1] && ATTR_IS_NUMERIC(in[1]->type)))
1027     {
1028 zoff99 2 val = g_new(struct attr,1);
1029 zoff99 27 attr_dup_content(in[1], val);
1030 zoff99 2 key = g_strdup(in[0]->u.str);
1031     g_hash_table_insert(cmd_int_var_hash, key, val);
1032 zoff99 27 }
1033 zoff99 2 }
1034    
1035     /**
1036     * Store key value pair for the command system (for attr typed values, can be used as opaque handles)
1037     *
1038     * @param navit The navit instance
1039     * @param function unused (needed to match command function signiture)
1040     * @param in input attributes in[0] is the key string, in[1] is the attr* value to store
1041     * @param out output attributes, unused
1042     * @param valid unused
1043     * @returns nothing
1044     */
1045     //TODO free stored attributes on navit_destroy
1046 zoff99 27 static void navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1047 zoff99 2 {
1048 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1049     dbg(0,"+#+:enter\n");
1050     #endif
1051 zoff99 27 ////DBG dbg(0,"EEnter\n");
1052 zoff99 2 char*key;
1053     struct attr*val;
1054 zoff99 27 if (!cmd_attr_var_hash)
1055     {
1056 zoff99 2 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1057     }
1058    
1059 zoff99 27 if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1]))
1060     {
1061 zoff99 2 val = attr_dup(in[1]);
1062     //val = in[1];
1063     key = g_strdup(in[0]->u.str);
1064     g_hash_table_insert(cmd_attr_var_hash, key, val);
1065 zoff99 27 }
1066 zoff99 2 }
1067    
1068     /**
1069     * command to toggle the active state of a named layer of the current layout
1070     *
1071     * @param navit The navit instance
1072     * @param function unused (needed to match command function signiture)
1073     * @param in input attribute in[0] is the name of the layer
1074     * @param out output unused
1075     * @param valid unused
1076     * @returns nothing
1077     */
1078 zoff99 27 static void navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1079 zoff99 2 {
1080 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1081     dbg(0,"+#+:enter\n");
1082     #endif
1083 zoff99 27 ////DBG dbg(0,"EEnter\n");
1084     if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1085     {
1086     if (this->layout_current && this->layout_current->layers)
1087     {
1088 zoff99 2 GList* layers = this->layout_current->layers;
1089 zoff99 27 while (layers)
1090     {
1091     struct layer*l = layers->data;
1092     if (l && !strcmp(l->name, in[0]->u.str))
1093     {
1094 zoff99 2 l->active ^= 1;
1095     navit_draw(this);
1096     return;
1097     }
1098 zoff99 27 layers = g_list_next(layers);
1099 zoff99 2 }
1100     }
1101 zoff99 27 }
1102 zoff99 2 }
1103    
1104     /**
1105 zoff99 28 * command to set the active state of a named layer of the current layout
1106     *
1107     * @param navit The navit instance
1108     * @param name name of the layer
1109     * @param active 0 -> inactive, 1 -> active
1110     * @param draw 0 -> dont redraw, 1 -> redraw
1111     * @returns nothing
1112     */
1113     void navit_layer_set_active(struct navit *this, char *name, int active, int draw)
1114     {
1115     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1116     dbg(0,"+#+:enter\n");
1117     #endif
1118     //dbg(0,"EEnter\n");
1119     if (name)
1120     {
1121     if (this->layout_current && this->layout_current->layers)
1122     {
1123     GList* layers = this->layout_current->layers;
1124     while (layers)
1125     {
1126     struct layer *l = layers->data;
1127     if (l && !strcmp(l->name, name))
1128     {
1129     l->active = active;
1130     if (draw == 1)
1131     {
1132     navit_draw(this);
1133     }
1134     return;
1135     }
1136     layers = g_list_next(layers);
1137     }
1138     }
1139     }
1140     }
1141    
1142     /**
1143 zoff99 2 * adds an item with the current coordinate of the vehicle to a named map
1144     *
1145     * @param navit The navit instance
1146     * @param function unused (needed to match command function signiture)
1147     * @param in input attribute in[0] is the name of the map
1148     * @param out output attribute, 0 on error or the id of the created item on success
1149     * @param valid unused
1150     * @returns nothing
1151     */
1152 zoff99 27 static void navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1153 zoff99 2 {
1154 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1155     dbg(0,"+#+:enter\n");
1156     #endif
1157 zoff99 27 ////DBG dbg(0,"EEnter\n");
1158 zoff99 2 struct attr **list = g_new0(struct attr *,2);
1159     struct attr*val = g_new0(struct attr,1);
1160     struct mapset* ms;
1161     struct map_selection sel;
1162     const int selection_range = 10;
1163     enum item_type item_type;
1164     struct item *it;
1165     struct map* curr_map = NULL;
1166     struct coord curr_coord;
1167     struct map_rect *mr;
1168    
1169 zoff99 27 val->type = attr_type_item_begin;
1170     val->u.item = NULL; //return invalid item on error
1171     list[0] = val;
1172     list[1] = NULL;
1173 zoff99 2 *out = list;
1174 zoff99 27 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
1175     in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
1176     )
1177     {
1178 zoff99 2
1179 zoff99 27 if (!(ms = navit_get_mapset(this)))
1180     {
1181 zoff99 2 return;
1182     }
1183    
1184 zoff99 27 if ((item_type = item_from_name(in[1]->u.str)) == type_none)
1185     {
1186 zoff99 2 return;
1187     }
1188    
1189     curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
1190    
1191     //no map with the given name found
1192 zoff99 27 if (!curr_map)
1193     {
1194 zoff99 2 return;
1195     }
1196 zoff99 27
1197     if (this->vehicle && this->vehicle->vehicle)
1198     {
1199 zoff99 2 struct attr pos_attr;
1200 zoff99 27 if (vehicle_get_attr(this->vehicle->vehicle, attr_position_coord_geo, &pos_attr, NULL))
1201     {
1202 zoff99 2 transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
1203 zoff99 27 }
1204     else
1205     {
1206 zoff99 2 return;
1207     }
1208 zoff99 27 }
1209     else
1210     {
1211 zoff99 2 return;
1212     }
1213    
1214 zoff99 27 sel.next = NULL;
1215     sel.order = 18;
1216     sel.range.min = type_none;
1217     sel.range.max = type_tec_common;
1218     sel.u.c_rect.lu.x = curr_coord.x - selection_range;
1219     sel.u.c_rect.lu.y = curr_coord.y + selection_range;
1220     sel.u.c_rect.rl.x = curr_coord.x + selection_range;
1221     sel.u.c_rect.rl.y = curr_coord.y - selection_range;
1222    
1223 zoff99 2 mr = map_rect_new(curr_map, &sel);
1224 zoff99 27 if (mr)
1225     {
1226     it = map_rect_create_item(mr, item_type);
1227     item_coord_set(it, &curr_coord, 1, change_mode_modify);
1228     val->u.item = it;
1229 zoff99 2 }
1230     map_rect_destroy(mr);
1231 zoff99 27 }
1232 zoff99 2 }
1233    
1234     /**
1235     * sets an attribute (name value pair) of a map item specified by map name and item id
1236     *
1237     * @param navit The navit instance
1238     * @param function unused (needed to match command function signiture)
1239     * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
1240     * @param out output attribute, 0 on error, 1 on success
1241     * @param valid unused
1242     * @returns nothing
1243     */
1244 zoff99 27 static void navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1245 zoff99 2 {
1246 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1247     dbg(0,"+#+:enter\n");
1248     #endif
1249 zoff99 27 ////DBG dbg(0,"EEnter\n");
1250     if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
1251     in[1] && ATTR_IS_ITEM(in[1]->type) && //item
1252     in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
1253     in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
1254     )
1255     {
1256 zoff99 2 struct attr attr_to_set;
1257     struct map* curr_map = NULL;
1258     struct mapset *ms;
1259     struct map_selection sel;
1260     const int selection_range = 500;
1261     struct coord curr_coord;
1262     struct item *it;
1263 zoff99 27
1264     if (ATTR_IS_STRING(attr_from_name(in[2]->u.str)))
1265     {
1266 zoff99 2 attr_to_set.u.str = in[3]->u.str;
1267     attr_to_set.type = attr_from_name(in[2]->u.str);
1268     }
1269 zoff99 27 else if (ATTR_IS_INT(attr_from_name(in[2]->u.str)))
1270     {
1271 zoff99 2 attr_to_set.u.num = atoi(in[3]->u.str);
1272     attr_to_set.type = attr_from_name(in[2]->u.str);
1273     }
1274 zoff99 27 else if (ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str)))
1275     {
1276 zoff99 2 double* val = g_new0(double,1);
1277     *val = atof(in[3]->u.str);
1278     attr_to_set.u.numd = val;
1279     attr_to_set.type = attr_from_name(in[2]->u.str);
1280     }
1281    
1282     ms = navit_get_mapset(this);
1283    
1284     curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
1285    
1286 zoff99 27 if (!curr_map)
1287     {
1288 zoff99 2 return;
1289     }
1290 zoff99 27 sel.next = NULL;
1291     sel.order = 18;
1292     sel.range.min = type_none;
1293     sel.range.max = type_tec_common;
1294     sel.u.c_rect.lu.x = curr_coord.x - selection_range;
1295     sel.u.c_rect.lu.y = curr_coord.y + selection_range;
1296     sel.u.c_rect.rl.x = curr_coord.x + selection_range;
1297     sel.u.c_rect.rl.y = curr_coord.y - selection_range;
1298    
1299 zoff99 2 it = in[1]->u.item;
1300 zoff99 27 if (it)
1301     {
1302 zoff99 2 item_attr_set(it, &attr_to_set, change_mode_modify);
1303     }
1304     }
1305     }
1306    
1307     /**
1308     * Get attr variable given a key string for the command system (for opaque usage)
1309     *
1310     * @param navit The navit instance
1311     * @param function unused (needed to match command function signiture)
1312     * @param in input attribute in[0] is the key string
1313     * @param out output attribute, the attr for the given key string if exists or NULL
1314     * @param valid unused
1315     * @returns nothing
1316     */
1317 zoff99 27 static void navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1318 zoff99 2 {
1319 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1320     dbg(0,"+#+:enter\n");
1321     #endif
1322 zoff99 27 ////DBG dbg(0,"EEnter\n");
1323 zoff99 2 struct attr **list = g_new0(struct attr *,2);
1324 zoff99 27 if (!cmd_int_var_hash)
1325     {
1326 zoff99 2 struct attr*val = g_new0(struct attr,1);
1327 zoff99 27 val->type = attr_type_item_begin;
1328 zoff99 2 val->u.item = NULL;
1329 zoff99 27 list[0] = val;
1330 zoff99 2 }
1331 zoff99 27 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1332     {
1333 zoff99 2 struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
1334 zoff99 27 if (ret)
1335     {
1336 zoff99 2 list[0] = attr_dup(ret);
1337     }
1338 zoff99 27 else
1339     {
1340 zoff99 2 struct attr*val = g_new0(struct attr,1);
1341 zoff99 27 val->type = attr_type_int_begin;
1342 zoff99 2 val->u.item = NULL;
1343 zoff99 27 list[0] = val;
1344 zoff99 2 }
1345 zoff99 27 }
1346 zoff99 2 list[1] = NULL;
1347     *out = list;
1348     }
1349    
1350     /**
1351     * Get value given a key string for the command system
1352     *
1353     * @param navit The navit instance
1354     * @param function unused (needed to match command function signiture)
1355     * @param in input attribute in[0] is the key string
1356     * @param out output attribute, the value for the given key string if exists or 0
1357     * @param valid unused
1358     * @returns nothing
1359     */
1360 zoff99 27 static void navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1361 zoff99 2 {
1362 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1363     dbg(0,"+#+:enter\n");
1364     #endif
1365 zoff99 27 ////DBG dbg(0,"EEnter\n");
1366 zoff99 2 struct attr **list = g_new0(struct attr *,2);
1367 zoff99 27 if (!cmd_int_var_hash)
1368     {
1369 zoff99 2 struct attr*val = g_new0(struct attr,1);
1370 zoff99 27 val->type = attr_type_int_begin;
1371     val->u.num = 0;
1372     list[0] = val;
1373 zoff99 2 }
1374 zoff99 27 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1375     {
1376 zoff99 2 struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
1377 zoff99 27 if (ret)
1378     {
1379 zoff99 2 list[0] = ret;
1380     }
1381 zoff99 27 else
1382     {
1383 zoff99 2 struct attr*val = g_new0(struct attr,1);
1384 zoff99 27 val->type = attr_type_int_begin;
1385     val->u.num = 0;
1386     list[0] = val;
1387 zoff99 2 }
1388 zoff99 27 }
1389 zoff99 2 list[1] = NULL;
1390     *out = list;
1391     }
1392    
1393     GList *cmd_int_var_stack = NULL;
1394    
1395     /**
1396     * Push an integer to the stack for the command system
1397     *
1398     * @param navit The navit instance
1399     * @param function unused (needed to match command function signiture)
1400     * @param in input attribute in[0] is the integer attibute to push
1401     * @param out output attributes, unused
1402     * @param valid unused
1403     * @returns nothing
1404     */
1405 zoff99 27 static void navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1406 zoff99 2 {
1407 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1408     dbg(0,"+#+:enter\n");
1409     #endif
1410 zoff99 27 ////DBG dbg(0,"EEnter\n");
1411     if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type))
1412     {
1413 zoff99 2 struct attr*val = g_new(struct attr,1);
1414 zoff99 27 attr_dup_content(in[0], val);
1415 zoff99 2 cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
1416     }
1417     }
1418    
1419     /**
1420     * Pop an integer from the command system's integer stack
1421     *
1422     * @param navit The navit instance
1423     * @param function unused (needed to match command function signiture)
1424     * @param in input attributes unused
1425     * @param out output attribute, the value popped if stack isn't empty or 0
1426     * @param valid unused
1427     * @returns nothing
1428     */
1429 zoff99 27 static void navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1430 zoff99 2 {
1431 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1432     dbg(0,"+#+:enter\n");
1433     #endif
1434 zoff99 27 ////DBG dbg(0,"EEnter\n");
1435 zoff99 2 struct attr **list = g_new0(struct attr *,2);
1436 zoff99 27 if (!cmd_int_var_stack)
1437     {
1438 zoff99 2 struct attr*val = g_new0(struct attr,1);
1439     val->type = attr_type_int_begin;
1440 zoff99 27 val->u.num = 0;
1441     list[0] = val;
1442 zoff99 2 }
1443 zoff99 27 else
1444     {
1445 zoff99 2 list[0] = cmd_int_var_stack->data;
1446 zoff99 27 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack);
1447 zoff99 2 }
1448     list[1] = NULL;
1449     *out = list;
1450     }
1451    
1452     /**
1453     * Get current size of command system's integer stack
1454     *
1455     * @param navit The navit instance
1456     * @param function unused (needed to match command function signiture)
1457     * @param in input attributes unused
1458     * @param out output attribute, the size of stack
1459     * @param valid unused
1460     * @returns nothing
1461     */
1462 zoff99 27 static void navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1463 zoff99 2 {
1464 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1465     dbg(0,"+#+:enter\n");
1466     #endif
1467 zoff99 27 ////DBG dbg(0,"EEnter\n");
1468 zoff99 2 struct attr **list;
1469 zoff99 27 struct attr *attr = g_new0(struct attr ,1);
1470     attr->type = attr_type_int_begin;
1471     if (!cmd_int_var_stack)
1472     {
1473     attr->u.num = 0;
1474 zoff99 2 }
1475 zoff99 27 else
1476     {
1477     attr->u.num = g_list_length(cmd_int_var_stack);
1478     }list = g_new0(struct attr *,2);
1479 zoff99 2 list[0] = attr;
1480     list[1] = NULL;
1481     *out = list;
1482 zoff99 27 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack);
1483 zoff99 2 }
1484    
1485 zoff99 27 static void navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1486 zoff99 2 {
1487 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1488     dbg(0,"+#+:enter\n");
1489     #endif
1490 zoff99 27 ////DBG dbg(0,"EEnter\n");
1491 zoff99 2 struct pcoord pc;
1492 zoff99 27 char *description = NULL;
1493 zoff99 2 if (!in)
1494     return;
1495     if (!in[0])
1496     return;
1497     pc.pro = transform_get_projection(this->trans);
1498 zoff99 27 if (ATTR_IS_COORD(in[0]->type))
1499     {
1500     pc.x = in[0]->u.coord->x;
1501     pc.y = in[0]->u.coord->y;
1502 zoff99 2 in++;
1503 zoff99 27 }
1504     else if (ATTR_IS_PCOORD(in[0]->type))
1505     {
1506     pc = *in[0]->u.pcoord;
1507 zoff99 2 in++;
1508 zoff99 27 }
1509     else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type))
1510     {
1511     pc.pro = in[0]->u.num;
1512     pc.x = in[1]->u.num;
1513     pc.y = in[2]->u.num;
1514     in += 3;
1515     }
1516     else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type))
1517     {
1518     pc.x = in[0]->u.num;
1519     pc.y = in[1]->u.num;
1520     in += 2;
1521     }
1522     else
1523     {
1524 zoff99 2 return;
1525 zoff99 27 }
1526 zoff99 2 if (in[0] && ATTR_IS_STRING(in[0]->type))
1527 zoff99 27 {
1528     description = in[0]->u.str;
1529     }
1530 zoff99 2 navit_set_destination(this, &pc, description, 1);
1531     }
1532    
1533 zoff99 27 static void navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1534 zoff99 2 {
1535 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1536     dbg(0,"+#+:enter\n");
1537     #endif
1538 zoff99 27 ////DBG dbg(0,"EEnter\n");
1539 zoff99 2 struct attr attr;
1540 zoff99 27 attr.type = attr_type_string_begin;
1541     attr.u.str = "Fix me";
1542     if (out)
1543     {
1544     *out = attr_generic_add_attr(*out, &attr);
1545 zoff99 2 }
1546     }
1547    
1548     /**
1549     * Join several string attributes into one
1550     *
1551     * @param navit The navit instance
1552     * @param function unused (needed to match command function signiture)
1553     * @param in input attributes in[0] - separator, in[1..] - attributes to join
1554     * @param out output attribute joined attribute as string
1555     * @param valid unused
1556     * @returns nothing
1557     */
1558 zoff99 27 static void navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1559 zoff99 2 {
1560 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1561     dbg(0,"+#+:enter\n");
1562     #endif
1563 zoff99 27 ////DBG dbg(0,"EEnter\n");
1564 zoff99 2 struct attr attr;
1565     gchar *ret, *sep;
1566     int i;
1567 zoff99 27 attr.type = attr_type_string_begin;
1568     attr.u.str = NULL;
1569     if (in[0] && in[1])
1570     {
1571     sep = attr_to_text(in[0], NULL, 1);
1572     ret = attr_to_text(in[1], NULL, 1);
1573     for (i = 2; in[i]; i++)
1574     {
1575     gchar *in_i = attr_to_text(in[i], NULL, 1);
1576     gchar *r = g_strjoin(sep, ret, in_i, NULL);
1577 zoff99 2 g_free(in_i);
1578     g_free(ret);
1579 zoff99 27 ret = r;
1580 zoff99 2 }
1581     g_free(sep);
1582 zoff99 27 attr.u.str = ret;
1583     if (out)
1584     {
1585     *out = attr_generic_add_attr(*out, &attr);
1586 zoff99 2 }
1587     g_free(ret);
1588     }
1589     }
1590    
1591     /**
1592     * Call external program
1593     *
1594     * @param navit The navit instance
1595     * @param function unused (needed to match command function signiture)
1596     * @param in input attributes in[0] - name of executable, in[1..] - parameters
1597     * @param out output attribute unused
1598     * @param valid unused
1599     * @returns nothing
1600     */
1601 zoff99 27 static void navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1602 zoff99 2 {
1603 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1604     dbg(0,"+#+:enter\n");
1605     #endif
1606 zoff99 27 ////DBG dbg(0,"EEnter\n");
1607     int i, j, nparms, nvalid;
1608     const char ** argv = NULL;
1609 zoff99 2 struct spawn_process_info *pi;
1610    
1611 zoff99 27 nparms = 0;
1612     nvalid = 0;
1613     if (in)
1614     {
1615     while (in[nparms])
1616     {
1617     if (in[nparms]->type != attr_none)
1618 zoff99 2 nvalid++;
1619     nparms++;
1620     }
1621     }
1622 zoff99 27
1623     if (nvalid > 0)
1624     {
1625 zoff99 2 argv=g_new(char*,nvalid+1);
1626 zoff99 27 for (i = 0, j = 0; in[i]; i++)
1627     {
1628     if (in[i]->type != attr_none)
1629     {
1630     argv[j++] = attr_to_text(in[i], NULL, 1);
1631 zoff99 2 }
1632 zoff99 27 else
1633     {
1634     //DBG dbg(0, "Parameter #%i is attr_none - skipping\n", i);
1635     }
1636 zoff99 2 }
1637 zoff99 27 argv[j] = NULL;
1638     pi = spawn_process(argv);
1639    
1640 zoff99 2 // spawn_process() testing suite - uncomment following code to test.
1641     //sleep(3);
1642     // example of non-blocking wait
1643 zoff99 27 //int st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st);
1644 zoff99 2 // example of blocking wait
1645 zoff99 27 //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st);
1646 zoff99 2 // example of wait after process is finished and status is
1647     // already tested
1648 zoff99 27 //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st);
1649 zoff99 2 // example of wait after process is finished and status is
1650     // already tested - unblocked
1651 zoff99 27 //st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st);
1652    
1653 zoff99 2 // End testing suite
1654     spawn_process_info_free(pi);
1655 zoff99 27 for (i = 0; argv[i]; i++)
1656 zoff99 2 g_free(argv[i]);
1657     g_free(argv);
1658     }
1659     }
1660    
1661 zoff99 27 static struct command_table commands[] =
1662     {
1663     { "zoom_in", command_cast(navit_cmd_zoom_in) },
1664     { "zoom_out", command_cast(navit_cmd_zoom_out) },
1665     { "zoom_to_route", command_cast(navit_cmd_zoom_to_route) },
1666     { "say", command_cast(navit_cmd_say) },
1667     { "set_center_cursor", command_cast(navit_cmd_set_center_cursor) },
1668     { "set_destination", command_cast(navit_cmd_set_destination) },
1669     { "announcer_toggle", command_cast(navit_cmd_announcer_toggle) },
1670     { "fmt_coordinates", command_cast(navit_cmd_fmt_coordinates) },
1671     { "set_int_var", command_cast(navit_cmd_set_int_var) },
1672     { "get_int_var", command_cast(navit_cmd_get_int_var) },
1673     { "push_int", command_cast(navit_cmd_push_int) },
1674     { "pop_int", command_cast(navit_cmd_pop_int) },
1675     { "int_stack_size", command_cast(navit_cmd_int_stack_size) },
1676     { "toggle_layer", command_cast(navit_cmd_toggle_layer) },
1677     { "strjoin", command_cast(navit_cmd_strjoin) },
1678     { "spawn", command_cast(navit_cmd_spawn) },
1679     { "map_add_curr_pos", command_cast(navit_cmd_map_add_curr_pos) },
1680     { "map_item_set_attr", command_cast(navit_cmd_map_item_set_attr) },
1681     { "set_attr_var", command_cast(navit_cmd_set_attr_var) },
1682     { "get_attr_var", command_cast(navit_cmd_get_attr_var) }, };
1683 zoff99 2
1684 zoff99 27 void navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
1685 zoff99 2 {
1686 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1687     dbg(0,"+#+:enter\n");
1688     #endif
1689 zoff99 27 ////DBG dbg(0,"EEnter\n");
1690     command_add_table(this_->attr_cbl, commands, count, this_);
1691 zoff99 2 }
1692    
1693     struct navit *
1694     navit_new(struct attr *parent, struct attr **attrs)
1695     {
1696 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1697     dbg(0,"+#+:enter\n");
1698     #endif
1699 zoff99 27 ////DBG dbg(0,"EEnter\n");
1700 zoff99 2 struct navit *this_=g_new0(struct navit, 1);
1701     struct pcoord center;
1702     struct coord co;
1703     struct coord_geo g;
1704 zoff99 27 enum projection pro = projection_mg;
1705 zoff99 2 int zoom = 256;
1706 zoff99 27 g.lat = 53.13;
1707     g.lng = 11.70;
1708 zoff99 2
1709 zoff99 27 this_->self.type = attr_navit;
1710     this_->self.u.navit = this_;
1711     this_->attr_cbl = callback_list_new();
1712 zoff99 2
1713 zoff99 27 this_->orientation = -1;
1714     this_->tracking_flag = 1;
1715     this_->recentdest_count = 10;
1716     this_->osd_configuration = -1;
1717 zoff99 2
1718     // changed default to 1
1719     this_->center_timeout = 1;
1720     this_->use_mousewheel = 1;
1721     this_->autozoom_secs = 10;
1722     this_->autozoom_min = 7;
1723     this_->autozoom_active = 0;
1724     this_->zoom_min = 1;
1725     this_->zoom_max = 1048576; //-> order=-2 // 2097152 -> order=-3;
1726     this_->follow_cursor = 1;
1727     this_->radius = 30;
1728     this_->border = 16;
1729    
1730     this_->trans = transform_new();
1731     this_->trans_cursor = transform_new();
1732     transform_from_geo(pro, &g, &co);
1733 zoff99 27 center.x = co.x;
1734     center.y = co.y;
1735 zoff99 2 center.pro = pro;
1736    
1737 zoff99 27 //DBG dbg(0, "setting center from xmlfile [hardcoded]\n");
1738 zoff99 2 transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
1739    
1740     // initialze trans_cursor here
1741     transform_copy(this_->trans, this_->trans_cursor);
1742     // initialze trans_cursor here
1743    
1744 zoff99 27 this_->bookmarks = bookmarks_new(&this_->self, NULL, this_->trans);
1745 zoff99 2
1746 zoff99 27 this_->prevTs = 0;
1747 zoff99 2
1748 zoff99 27 for (; *attrs; attrs++)
1749     {
1750 zoff99 2 navit_set_attr_do(this_, *attrs, 1);
1751     }
1752 zoff99 27 this_->displaylist = graphics_displaylist_new();
1753     command_add_table(this_->attr_cbl, commands, sizeof(commands) / sizeof(struct command_table), this_);
1754 zoff99 2
1755 zoff99 27 // this_->messages = messagelist_new(attrs);
1756 zoff99 2
1757 zoff99 27 ////DBG dbg(0,"111111\n");
1758    
1759 zoff99 2 return this_;
1760     }
1761    
1762 zoff99 27 static int navit_set_gui(struct navit *this_, struct gui *gui)
1763 zoff99 2 {
1764 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1765     dbg(0,"+#+:enter\n");
1766     #endif
1767 zoff99 27 ////DBG dbg(0,"EEnter\n");
1768 zoff99 2 if (this_->gui)
1769     return 0;
1770 zoff99 27 this_->gui = gui;
1771     if (gui_has_main_loop(this_->gui))
1772     {
1773     if (!main_loop_gui)
1774     {
1775     main_loop_gui = this_->gui;
1776     }
1777     else
1778     {
1779     //DBG dbg(0, "gui with main loop already active, ignoring this instance");
1780 zoff99 2 return 0;
1781     }
1782     }
1783     return 1;
1784     }
1785    
1786 zoff99 27 void navit_add_message(struct navit *this_, char *message)
1787 zoff99 2 {
1788 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1789     dbg(0,"+#+:enter\n");
1790     #endif
1791 zoff99 27 ////DBG dbg(0,"EEnter\n");
1792     // message_new(this_->messages, message);
1793 zoff99 2 }
1794    
1795 zoff99 27 struct message *navit_get_messages(struct navit *this_)
1796 zoff99 2 {
1797 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1798     dbg(0,"+#+:enter\n");
1799     #endif
1800 zoff99 27 ////DBG dbg(0,"EEnter\n");
1801     // return message_get(this_->messages);
1802 zoff99 2 }
1803    
1804 zoff99 27 static int navit_set_graphics(struct navit *this_, struct graphics *gra)
1805 zoff99 2 {
1806 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1807     dbg(0,"+#+:enter\n");
1808     #endif
1809 zoff99 27 ////DBG dbg(0,"EEnter\n");
1810 zoff99 2 if (this_->gra)
1811     return 0;
1812 zoff99 27 this_->gra = gra;
1813 zoff99 28
1814     /*
1815 zoff99 27 this_->resize_callback = callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
1816 zoff99 2 graphics_add_callback(gra, this_->resize_callback);
1817 zoff99 27 this_->button_callback = callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
1818 zoff99 2 graphics_add_callback(gra, this_->button_callback);
1819 zoff99 27 this_->motion_callback = callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
1820 zoff99 2 graphics_add_callback(gra, this_->motion_callback);
1821 zoff99 28 */
1822    
1823     // this draw the vehicle // very stupid
1824 zoff99 27 this_->predraw_callback = callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
1825 zoff99 2 graphics_add_callback(gra, this_->predraw_callback);
1826 zoff99 28
1827 zoff99 27 ////DBG dbg(0,"111111111\n");
1828 zoff99 2 return 1;
1829     }
1830    
1831     struct graphics *
1832     navit_get_graphics(struct navit *this_)
1833     {
1834 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1835     dbg(0,"+#+:enter\n");
1836     #endif
1837 zoff99 27 ////DBG dbg(0,"EEnter\n");
1838 zoff99 2 return this_->gra;
1839     }
1840    
1841     struct vehicleprofile *
1842     navit_get_vehicleprofile(struct navit *this_)
1843     {
1844 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1845     dbg(0,"+#+:enter\n");
1846     #endif
1847 zoff99 27 ////DBG dbg(0,"EEnter\n");
1848 zoff99 2 return this_->vehicleprofile;
1849     }
1850    
1851     GList *
1852     navit_get_vehicleprofiles(struct navit *this_)
1853     {
1854 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1855     dbg(0,"+#+:enter\n");
1856     #endif
1857 zoff99 27 ////DBG dbg(0,"EEnter\n");
1858 zoff99 2 return this_->vehicleprofiles;
1859     }
1860    
1861 zoff99 27 static void navit_projection_set(struct navit *this_, enum projection pro, int draw)
1862 zoff99 2 {
1863 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1864     dbg(0,"+#+:enter\n");
1865     #endif
1866 zoff99 27 ////DBG dbg(0,"EEnter\n");
1867 zoff99 2 struct coord_geo g;
1868     struct coord *c;
1869    
1870 zoff99 27 c = transform_center(this_->trans);
1871 zoff99 2 transform_to_geo(transform_get_projection(this_->trans), c, &g);
1872     transform_set_projection(this_->trans, pro);
1873     transform_from_geo(pro, &g, c);
1874     if (draw)
1875 zoff99 28 {
1876 zoff99 2 navit_draw(this_);
1877 zoff99 28 }
1878 zoff99 2 }
1879    
1880     /**
1881     * Start the route computing to a given set of coordinates
1882     *
1883     * @param navit The navit instance
1884     * @param c The coordinate to start routing to
1885     * @param description A label which allows the user to later identify this destination in the former destinations selection
1886     * @returns nothing
1887     */
1888 zoff99 27 void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
1889 zoff99 2 {
1890 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1891     dbg(0,"+#+:enter\n");
1892     #endif
1893 zoff99 27 ////DBG dbg(0,"EEnter\n");
1894 zoff99 2 char *destination_file;
1895 zoff99 27 if (c)
1896     {
1897     this_->destination = *c;
1898     this_->destination_valid = 1;
1899     //dbg(0, "navit->navit_set_destination %i\n", c->x);
1900     //dbg(0, "navit->navit_set_destination %i\n", c->y);
1901     }
1902     else
1903     {
1904     this_->destination_valid = 0;
1905     }
1906     //destination_file = bookmarks_get_destination_file(TRUE);
1907     //bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
1908     //g_free(destination_file);
1909     callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1910     if (this_->route)
1911     {
1912     //dbg(0, "navit->navit_set_destination 2: %i %i\n", c->x, c->y);
1913 zoff99 2
1914     route_set_destination(this_->route, c, async);
1915     if (this_->ready == 3)
1916 zoff99 27 {
1917 zoff99 2 navit_draw(this_);
1918 zoff99 27 }
1919 zoff99 2 }
1920     }
1921    
1922     /**
1923 zoff99 27 * add a waypoint to an active route
1924     *
1925     * @param navit The navit instance
1926     * @param c The coordinate of the waypoint
1927     * @param description A dummy string
1928     * @returns nothing
1929     */
1930     void navit_add_waypoint_to_route(struct navit *this_, struct pcoord *c, const char *description, int async)
1931     {
1932 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1933     dbg(0,"+#+:enter\n");
1934     #endif
1935 zoff99 27 if (this_->destination_valid == 1)
1936     {
1937     //int count = 0;
1938     //count = g_list_length(this_->route->destinations);
1939     //DBG dbg(0, "count=%d\n", count);
1940    
1941     //dbg(0, "navit->navit_add_waypoint_to_route 1: %i %i\n", c->x, c->y);
1942    
1943     route_add_destination(this_->route, c, async);
1944    
1945     this_->destination = *c;
1946     this_->destination_valid = 1;
1947     }
1948     else
1949     {
1950     //dbg(0, "navit->navit_add_waypoint_to_route 2: %i %i\n", c->x, c->y);
1951     navit_set_destination(this_, c, description, async);
1952     }
1953     }
1954    
1955     /**
1956 zoff99 2 * Start the route computing to a given set of coordinates including waypoints
1957     *
1958     * @param navit The navit instance
1959     * @param c The coordinate to start routing to
1960     * @param description A label which allows the user to later identify this destination in the former destinations selection
1961     * @returns nothing
1962     */
1963 zoff99 27 void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
1964 zoff99 2 {
1965 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
1966     dbg(0,"+#+:enter\n");
1967     #endif
1968 zoff99 27 ////DBG dbg(0,"EEnter\n");
1969 zoff99 2 char *destination_file;
1970 zoff99 27 if (c && count)
1971     {
1972     this_->destination = c[count - 1];
1973     this_->destination_valid = 1;
1974     //dbg(0, "navit->navit_set_destinations 1: %i %i\n", c[count-1].x, c[count-1].y);
1975     }
1976     else
1977     {
1978     this_->destination_valid = 0;
1979     }
1980     //destination_file = bookmarks_get_destination_file(TRUE);
1981     //bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
1982     //g_free(destination_file);
1983 zoff99 2 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1984 zoff99 27 if (this_->route)
1985     {
1986 zoff99 2 route_set_destinations(this_->route, c, count, async);
1987     if (this_->ready == 3)
1988 zoff99 27 {
1989 zoff99 2 navit_draw(this_);
1990 zoff99 27 }
1991 zoff99 2 }
1992     }
1993    
1994     /**
1995     * @brief Checks if a route is calculated
1996     *
1997     * This function checks if a route is calculated.
1998     *
1999     * @param this_ The navit struct whose route should be checked.
2000     * @return True if the route is set, false otherwise.
2001     */
2002 zoff99 27 int navit_check_route(struct navit *this_)
2003 zoff99 2 {
2004 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2005     dbg(0,"+#+:enter\n");
2006     #endif
2007 zoff99 27 ////DBG dbg(0,"EEnter\n");
2008     if (this_->route)
2009     {
2010 zoff99 2 return route_get_path_set(this_->route);
2011     }
2012    
2013     return 0;
2014     }
2015    
2016 zoff99 27 static int navit_former_destinations_active(struct navit *this_)
2017 zoff99 2 {
2018 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2019     dbg(0,"+#+:enter\n");
2020     #endif
2021 zoff99 27 ////DBG dbg(0,"EEnter\n");
2022    
2023     return 0;
2024     // disable this function!!
2025    
2026    
2027 zoff99 2 char *destination_file = bookmarks_get_destination_file(FALSE);
2028     FILE *f;
2029 zoff99 27 int active = 0;
2030 zoff99 2 char buffer[3];
2031 zoff99 27 f = fopen(destination_file, "r");
2032     if (f)
2033     {
2034     if (!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0] != '\n' || buffer[1] != '\n'))
2035     {
2036     active = 1;
2037     }
2038 zoff99 2 fclose(f);
2039     }
2040     g_free(destination_file);
2041 zoff99 27
2042 zoff99 2 return active;
2043     }
2044    
2045 zoff99 27 static void navit_add_former_destinations_from_file(struct navit *this_)
2046 zoff99 2 {
2047 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2048     dbg(0,"+#+:enter\n");
2049     #endif
2050 zoff99 27 ////DBG dbg(0,"EEnter\n");
2051 zoff99 2 char *destination_file = bookmarks_get_destination_file(FALSE);
2052     struct attr *attrs[4];
2053     struct map_rect *mr;
2054     struct item *item;
2055 zoff99 27 int i, valid = 0, count = 0;
2056 zoff99 2 struct coord c[16];
2057     struct pcoord pc[16];
2058     struct attr parent;
2059     struct attr type;
2060     struct attr data;
2061     struct attr flags;
2062    
2063 zoff99 27 parent.type = attr_navit;
2064     parent.u.navit = this_;
2065 zoff99 2
2066 zoff99 27 type.type = attr_type;
2067     type.u.str = "textfile";
2068 zoff99 2
2069 zoff99 27 data.type = attr_data;
2070     data.u.str = destination_file;
2071 zoff99 2
2072 zoff99 27 flags.type = attr_flags;
2073     flags.u.num = 1;
2074 zoff99 2
2075 zoff99 27 attrs[0] = &type;
2076     attrs[1] = &data;
2077     attrs[2] = &flags;
2078     attrs[3] = NULL;
2079 zoff99 2
2080 zoff99 27 this_->former_destination = map_new(&parent, attrs);
2081 zoff99 2 g_free(destination_file);
2082     if (!this_->route || !navit_former_destinations_active(this_))
2083 zoff99 27 return;
2084     mr = map_rect_new(this_->former_destination, NULL);
2085     while ((item = map_rect_get_item(mr)))
2086     {
2087     if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count = item_coord_get(item, c, 16)))
2088     valid = 1;
2089 zoff99 2 }
2090     map_rect_destroy(mr);
2091 zoff99 27 if (valid && count > 0)
2092     {
2093     for (i = 0; i < count; i++)
2094     {
2095     pc[i].pro = map_projection(this_->former_destination);
2096     pc[i].x = c[i].x;
2097     pc[i].y = c[i].y;
2098 zoff99 2 }
2099     if (count == 1)
2100 zoff99 27 {
2101 zoff99 2 route_set_destination(this_->route, &pc[0], 1);
2102 zoff99 27 }
2103 zoff99 2 else
2104 zoff99 27 {
2105 zoff99 2 route_set_destinations(this_->route, pc, count, 1);
2106 zoff99 27 }
2107     this_->destination = pc[count - 1];
2108     this_->destination_valid = 1;
2109 zoff99 2 }
2110     }
2111    
2112 zoff99 27 void navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
2113 zoff99 2 {
2114 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2115     dbg(0,"+#+:enter\n");
2116     #endif
2117 zoff99 27 ////DBG dbg(0,"EEnter\n");
2118 zoff99 2 va_list ap;
2119 zoff99 27 char *str1, *str2;
2120 zoff99 2 va_start(ap, fmt);
2121 zoff99 27 if (this_->textfile_debug_log && this_->vehicle)
2122     {
2123     str1 = g_strdup_vprintf(fmt, ap);
2124     str2 = g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
2125 zoff99 2 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
2126     g_free(str2);
2127     g_free(str1);
2128     }
2129 zoff99 27 va_end(ap);
2130 zoff99 2 }
2131    
2132 zoff99 27 void navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
2133 zoff99 2 {
2134 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2135     dbg(0,"+#+:enter\n");
2136     #endif
2137 zoff99 27 ////DBG dbg(0,"EEnter\n");
2138 zoff99 2 va_list ap;
2139 zoff99 27 char *str1, *str2;
2140 zoff99 2 va_start(ap, fmt);
2141 zoff99 27 if (this_->textfile_debug_log && this_->vehicle)
2142     {
2143     str1 = g_strdup_vprintf(fmt, ap);
2144     str2 = g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
2145 zoff99 2 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
2146     g_free(str2);
2147     g_free(str1);
2148     }
2149 zoff99 27 va_end(ap);
2150 zoff99 2 }
2151    
2152 zoff99 27 void navit_say(struct navit *this_, char *text)
2153 zoff99 2 {
2154 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2155     dbg(0,"+#+:enter\n");
2156     #endif
2157 zoff99 27 ////DBG dbg(0,"EEnter\n");
2158     if (this_->speech)
2159     {
2160 zoff99 2 speech_say(this_->speech, text);
2161     }
2162     }
2163    
2164     /**
2165     * @brief Toggles the navigation announcer for navit
2166     * @param this_ The navit object
2167     */
2168 zoff99 27 static void navit_cmd_announcer_toggle(struct navit *this_)
2169 zoff99 2 {
2170 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2171     dbg(0,"+#+:enter\n");
2172     #endif
2173 zoff99 27 struct attr attr, speechattr;
2174 zoff99 2
2175 zoff99 27 // search for the speech attribute
2176     if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2177     return;
2178     // find out if the corresponding attribute attr_active has been set
2179     if (speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL))
2180     {
2181     // flip it then...
2182     attr.u.num = !attr.u.num;
2183     }
2184     else
2185     {
2186     // otherwise disable it because voice is enabled by default
2187     attr.type = attr_active;
2188     attr.u.num = 0;
2189     }
2190 zoff99 2
2191 zoff99 27 // apply the new state
2192     if (!speech_set_attr(speechattr.u.speech, &attr))
2193     return;
2194 zoff99 2
2195 zoff99 27 // announce that the speech attribute has changed
2196     callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2197 zoff99 2 }
2198    
2199 zoff99 27 void navit_cmd_announcer_on(struct navit *this_)
2200 zoff99 2 {
2201 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2202     dbg(0,"+#+:enter\n");
2203     #endif
2204 zoff99 27 struct attr attr, speechattr;
2205 zoff99 2
2206 zoff99 27 // search for the speech attribute
2207     if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2208     return;
2209 zoff99 2
2210     attr.type = attr_active;
2211     attr.u.num = 1;
2212    
2213 zoff99 27 // apply the new state
2214     if (!speech_set_attr(speechattr.u.speech, &attr))
2215     return;
2216 zoff99 2
2217 zoff99 27 // announce that the speech attribute has changed
2218     callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2219 zoff99 2 }
2220    
2221 zoff99 27 void navit_cmd_announcer_off(struct navit *this_)
2222 zoff99 2 {
2223 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2224     dbg(0,"+#+:enter\n");
2225     #endif
2226 zoff99 27 struct attr attr, speechattr;
2227 zoff99 2
2228 zoff99 27 // search for the speech attribute
2229     if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2230     return;
2231 zoff99 2
2232     attr.type = attr_active;
2233     attr.u.num = 0;
2234    
2235 zoff99 27 // apply the new state
2236     if (!speech_set_attr(speechattr.u.speech, &attr))
2237     return;
2238 zoff99 2
2239 zoff99 27 // announce that the speech attribute has changed
2240     callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2241 zoff99 2 }
2242    
2243 zoff99 27 void navit_speak(struct navit *this_)
2244 zoff99 2 {
2245 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2246     dbg(0,"+#+:enter\n");
2247     #endif
2248 zoff99 27 ////DBG dbg(0,"EEnter\n");
2249     struct navigation *nav = this_->navigation;
2250     struct map *map = NULL;
2251     struct map_rect *mr = NULL;
2252 zoff99 2 struct item *item;
2253     struct attr attr;
2254    
2255 zoff99 27 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
2256     attr.u.num = 1;
2257     // dbg(1, "this_.speech->active %i\n", attr.u.num);
2258     if (!attr.u.num)
2259     return;
2260 zoff99 2
2261     if (nav)
2262 zoff99 27 map = navigation_get_map(nav);
2263 zoff99 2 if (map)
2264 zoff99 27 mr = map_rect_new(map, NULL);
2265     if (mr)
2266     {
2267     while ((item = map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none))
2268     ;
2269     if (item && item_attr_get(item, attr_navigation_speech, &attr))
2270     {
2271 zoff99 2 speech_say(this_->speech, attr.u.str);
2272 zoff99 27 //navit_add_message(this_, attr.u.str);
2273 zoff99 2 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
2274     }
2275     map_rect_destroy(mr);
2276     }
2277     }
2278    
2279 zoff99 27 static void navit_window_roadbook_update(struct navit *this_)
2280 zoff99 2 {
2281 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2282     dbg(0,"+#+:enter\n");
2283     #endif
2284 zoff99 27 ////DBG dbg(0,"EEnter\n");
2285     struct navigation *nav = this_->navigation;
2286     struct map *map = NULL;
2287     struct map_rect *mr = NULL;
2288 zoff99 2 struct item *item;
2289     struct attr attr;
2290     struct param_list param[5];
2291     int secs;
2292    
2293 zoff99 27 // dbg(1, "enter\n");
2294 zoff99 2 datawindow_mode(this_->roadbook_window, 1);
2295     if (nav)
2296 zoff99 27 map = navigation_get_map(nav);
2297 zoff99 2 if (map)
2298 zoff99 27 mr = map_rect_new(map, NULL);
2299     ////DBG dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
2300     if (mr)
2301     {
2302     ////DBG dbg(0,"while loop\n");
2303     while ((item = map_rect_get_item(mr)))
2304     {
2305     ////DBG dbg(0,"item=%p\n", item);
2306     attr.u.str = NULL;
2307     if (item->type != type_nav_position)
2308     {
2309 zoff99 2 item_attr_get(item, attr_navigation_long, &attr);
2310 zoff99 27 if (attr.u.str == NULL)
2311     {
2312 zoff99 2 continue;
2313     }
2314     dbg(2, "Command='%s'\n", attr.u.str);
2315 zoff99 27 param[0].value = g_strdup(attr.u.str);
2316     }
2317     else
2318     param[0].value = _("Position");
2319     param[0].name = _("Command");
2320 zoff99 2
2321     item_attr_get(item, attr_length, &attr);
2322     dbg(2, "Length=%d\n", attr.u.num);
2323 zoff99 27 param[1].name = _("Length");
2324 zoff99 2
2325 zoff99 27 if (attr.u.num >= 2000)
2326 zoff99 2 {
2327 zoff99 27 param[1].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km"));
2328 zoff99 2 }
2329     else
2330     {
2331 zoff99 27 param[1].value = g_strdup_printf("%7d %s", attr.u.num, _("m"));
2332 zoff99 2 }
2333    
2334     item_attr_get(item, attr_time, &attr);
2335     dbg(2, "Time=%d\n", attr.u.num);
2336 zoff99 27 secs = attr.u.num / 10;
2337     param[2].name = _("Time");
2338     if (secs >= 3600)
2339 zoff99 2 {
2340 zoff99 27 param[2].value = g_strdup_printf("%d:%02d:%02d", secs / 60, (secs / 60) % 60, secs % 60);
2341 zoff99 2 }
2342     else
2343     {
2344 zoff99 27 param[2].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60);
2345 zoff99 2 }
2346    
2347     item_attr_get(item, attr_destination_length, &attr);
2348     dbg(2, "Destlength=%d\n", attr.u.num);
2349 zoff99 27 param[3].name = _("Destination Length");
2350     if (attr.u.num >= 2000)
2351 zoff99 2 {
2352 zoff99 27 param[3].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km"));
2353 zoff99 2 }
2354     else
2355     {
2356 zoff99 27 param[3].value = g_strdup_printf("%d %s", attr.u.num, _("m"));
2357 zoff99 2 }
2358    
2359     item_attr_get(item, attr_destination_time, &attr);
2360     dbg(2, "Desttime=%d\n", attr.u.num);
2361 zoff99 27 secs = attr.u.num / 10;
2362     param[4].name = _("Destination Time");
2363     if (secs >= 3600)
2364 zoff99 2 {
2365 zoff99 27 param[4].value = g_strdup_printf("%d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60);
2366 zoff99 2 }
2367     else
2368     {
2369 zoff99 27 param[4].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60);
2370 zoff99 2 }
2371     datawindow_add(this_->roadbook_window, param, 5);
2372     }
2373     map_rect_destroy(mr);
2374     }
2375     datawindow_mode(this_->roadbook_window, 0);
2376     }
2377    
2378 zoff99 27 void navit_window_roadbook_destroy(struct navit *this_)
2379 zoff99 2 {
2380 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2381     dbg(0,"+#+:enter\n");
2382     #endif
2383 zoff99 27 ////DBG dbg(0, "enter\n");
2384 zoff99 2 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
2385 zoff99 27 this_->roadbook_window = NULL;
2386     this_->roadbook_callback = NULL;
2387 zoff99 2 }
2388 zoff99 28
2389 zoff99 27 void navit_window_roadbook_new(struct navit *this_)
2390 zoff99 2 {
2391 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2392     dbg(0,"+#+:enter\n");
2393     #endif
2394 zoff99 27 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window)
2395     {
2396 zoff99 2 return;
2397     }
2398    
2399 zoff99 27 this_->roadbook_callback = callback_new_1(callback_cast(navit_window_roadbook_update), this_);
2400 zoff99 2 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
2401 zoff99 27 this_->roadbook_window = gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
2402 zoff99 2 navit_window_roadbook_update(this_);
2403     }
2404    
2405 zoff99 27 void navit_remove_all_maps(struct navit *this_)
2406 zoff99 2 {
2407 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2408     dbg(0,"+#+:enter\n");
2409     #endif
2410 zoff99 2 struct mapset *ms;
2411     struct map *map3;
2412    
2413 zoff99 28 // hold map drawing
2414     // this_->ready = 1;
2415    
2416 zoff99 27 // first: stop navigation!
2417     //if (global_navit->destination_valid != 0)
2418     //{
2419     navit_set_destination(global_navit, NULL, NULL, 0);
2420     //}
2421    
2422    
2423 zoff99 28 if (this_->route)
2424     {
2425     struct attr callback;
2426     // this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
2427     callback.type = attr_callback;
2428     callback.u.callback = this_->route_cb;
2429     route_remove_attr(this_->route, &callback);
2430 zoff99 27
2431 zoff99 28 this_->route->ms = NULL;
2432     // route_set_mapset(this_->route, ms);
2433     // route_set_projection(this_->route, transform_get_projection(this_->trans));
2434 zoff99 27
2435 zoff99 28 //*********route_destroy(this_->route);
2436 zoff99 27
2437 zoff99 28 //route_path_destroy(this_->route->path2,1);
2438     //this_->route->path2 = NULL;
2439     //route_graph_destroy(this_->route->graph);
2440     //this_->route->graph=NULL;
2441     }
2442 zoff99 27
2443     /*
2444     map_rect_destroy(displaylist->mr);
2445     if (!route_selection)
2446     map_selection_destroy(displaylist->sel);
2447     mapset_close(displaylist->msh);
2448     displaylist->mr=NULL;
2449     displaylist->sel=NULL;
2450     displaylist->m=NULL;
2451     displaylist->msh=NULL;
2452     profile(1,"callback\n");
2453     callback_call_1(displaylist->cb, cancel);
2454     */
2455    
2456     struct displaylist *dl = navit_get_displaylist(this_);
2457     dl->m = NULL;
2458     dl->msh = NULL;
2459    
2460 zoff99 2 if (this_->mapsets)
2461     {
2462     struct mapset_handle *msh;
2463 zoff99 27 ms = this_->mapsets->data;
2464     msh = mapset_open(ms);
2465     ////DBG dbg(0,"removing map bb0\n");
2466     while (msh && (map3 = mapset_next(msh, 0)))
2467 zoff99 2 {
2468 zoff99 27 ////DBG dbg(0,"removing map bb1\n");
2469 zoff99 2 struct attr map_name_attr;
2470 zoff99 27 if (map_get_attr(map3, attr_name, &map_name_attr, NULL))
2471 zoff99 2 {
2472 zoff99 27 //DBG dbg(0, "map name=%s", map_name_attr.u.str);
2473 zoff99 2 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
2474     {
2475 zoff99 28 dbg(0, "removing map name=%s", map_name_attr.u.str);
2476 zoff99 27 //DBG dbg(0, "removing map a0\n");
2477     struct attr active;
2478     active.type = attr_active;
2479     active.u.num = 0;
2480     //map_set_attr(map3, &active);
2481    
2482     //DBG dbg(0, "removing map a1\n");
2483 zoff99 2 struct attr map_attr;
2484 zoff99 27 map_attr.u.map = map3;
2485     map_attr.type = attr_map;
2486 zoff99 2 mapset_remove_attr(ms, &map_attr);
2487 zoff99 27
2488     //DBG dbg(0, "removing map a2\n");
2489     map3->refcount = 1;
2490 zoff99 2 map_destroy(map3);
2491 zoff99 27 //DBG dbg(0, "removing map a3\n");
2492     map3 = NULL;
2493 zoff99 2 }
2494 zoff99 28 else if (strncmp("-special-:", map_name_attr.u.str, 10) == 0)
2495     {
2496     dbg(0, "removing (special) map name=%s", map_name_attr.u.str);
2497     struct attr active;
2498     active.type = attr_active;
2499     active.u.num = 0;
2500    
2501     struct attr map_attr;
2502     map_attr.u.map = map3;
2503     map_attr.type = attr_map;
2504     mapset_remove_attr(ms, &map_attr);
2505    
2506     map3->refcount = 1;
2507     map_destroy(map3);
2508     map3 = NULL;
2509     }
2510 zoff99 2 }
2511     }
2512     mapset_close(msh);
2513 zoff99 27 //DBG dbg(0, "removing map bb4\n");
2514 zoff99 2 }
2515 zoff99 27
2516     dl->ms = this_->mapsets->data;
2517    
2518     // int async = 0;
2519     // transform_setup_source_rect(this_->trans);
2520     // graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
2521     //this_->displaylist->ms=this_->mapsets->data;
2522    
2523 zoff99 2 }
2524    
2525 zoff99 28 void navit_map_active_flag(struct navit *this_, int activate, const char *mapname)
2526     {
2527     // activate = 0 -> deactivate
2528     // activate = 1 -> activate
2529    
2530     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2531     dbg(0,"+#+:enter\n");
2532     #endif
2533     struct mapset *ms;
2534     struct map *map3;
2535    
2536     if (this_->mapsets)
2537     {
2538     struct mapset_handle *msh;
2539     ms = this_->mapsets->data;
2540     msh = mapset_open(ms);
2541     while (msh && (map3 = mapset_next(msh, 0)))
2542     {
2543     struct attr map_name_attr;
2544     if (map_get_attr(map3, attr_name, &map_name_attr, NULL))
2545     {
2546     dbg(0, "map name=%s\n", map_name_attr.u.str);
2547     if (strcmp(mapname, map_name_attr.u.str) == 0)
2548     {
2549     dbg(0, "setting active flag on map:%s\n", map_name_attr.u.str);
2550    
2551     struct attr active;
2552     active.type = attr_active;
2553     active.u.num = activate;
2554     map_set_attr(map3, &active);
2555     }
2556     }
2557     }
2558     mapset_close(msh);
2559     }
2560    
2561     }
2562    
2563 zoff99 27 void navit_add_all_maps(struct navit *this_)
2564 zoff99 2 {
2565 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2566     dbg(0,"+#+:enter\n");
2567     #endif
2568 zoff99 2 struct map *map3;
2569    
2570     if (this_->mapsets)
2571     {
2572 zoff99 27 //DBG dbg(0, "xADDx all maps - start\n");
2573 zoff99 2
2574 zoff99 27 struct mapset *ms;
2575     ms = this_->mapsets->data;
2576    
2577 zoff99 2 struct attr type;
2578     struct attr parent;
2579     struct attr data;
2580     struct attr flags;
2581     struct map *map2;
2582     struct attr map2_attr;
2583     struct attr *attrs[4];
2584     char *map_file;
2585    
2586 zoff99 27 parent.type = attr_navit;
2587     parent.u.navit = this_;
2588     type.type = attr_type;
2589     type.u.str = "binfile";
2590     data.type = attr_data;
2591     map_file = g_strdup_printf("%sborders.bin", navit_maps_dir);
2592     data.u.str = map_file;
2593 zoff99 2
2594 zoff99 27 ////DBG dbg(0,"map name=%s",map_file);
2595 zoff99 2
2596 zoff99 27 flags.type = attr_flags;
2597     flags.u.num = 0;
2598     attrs[0] = &type;
2599     attrs[1] = &data;
2600     attrs[2] = &flags;
2601     attrs[3] = NULL;
2602     map2 = map_new(&parent, attrs);
2603 zoff99 2 if (map2)
2604     {
2605 zoff99 27 map2_attr.u.data = map2;
2606     map2_attr.type = attr_map;
2607     // mapset_add_attr_name(ms, &map2_attr);
2608     mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/borders.bin");
2609     struct attr active;
2610     active.type = attr_active;
2611     active.u.num = 0;
2612     //map_set_attr(map2, &active);
2613 zoff99 2 }
2614     g_free(map_file);
2615    
2616 zoff99 27 parent.type = attr_navit;
2617     parent.u.navit = this_;
2618     type.type = attr_type;
2619     type.u.str = "binfile";
2620     data.type = attr_data;
2621     map_file = g_strdup_printf("%scoastline.bin", navit_maps_dir);
2622     data.u.str = map_file;
2623 zoff99 2
2624 zoff99 27 ////DBG dbg(0,"map name=%s",map_file);
2625 zoff99 2
2626 zoff99 27 flags.type = attr_flags;
2627     flags.u.num = 0;
2628     attrs[0] = &type;
2629     attrs[1] = &data;
2630     attrs[2] = &flags;
2631     attrs[3] = NULL;
2632     map2 = map_new(&parent, attrs);
2633 zoff99 2 if (map2)
2634     {
2635 zoff99 27 map2_attr.u.data = map2;
2636     map2_attr.type = attr_map;
2637     // mapset_add_attr_name(ms, &map2_attr);
2638     mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/coastline.bin");
2639     struct attr active;
2640     active.type = attr_active;
2641     active.u.num = 0;
2642     //map_set_attr(map2, &active);
2643 zoff99 2 }
2644     g_free(map_file);
2645    
2646 zoff99 28
2647    
2648    
2649    
2650    
2651     // gpx tracks map --------------------
2652     parent.type = attr_navit;
2653     parent.u.navit = this_;
2654     type.type = attr_type;
2655     type.u.str = "textfile";
2656     data.type = attr_data;
2657     map_file = g_strdup_printf("%sgpxtracks.txt", navit_maps_dir);
2658     data.u.str = map_file;
2659    
2660     flags.type = attr_flags;
2661     flags.u.num = 0;
2662     attrs[0] = &type;
2663     attrs[1] = &data;
2664     attrs[2] = &flags;
2665     attrs[3] = NULL;
2666     map2 = map_new(&parent, attrs);
2667     if (map2)
2668     {
2669     map2_attr.u.data = map2;
2670     map2_attr.type = attr_map;
2671     mapset_add_attr_name_str(ms, &map2_attr, "-special-:gpxtracks.txt");
2672     struct attr active;
2673     active.type = attr_active;
2674     active.u.num = 0;
2675     //map_set_attr(map2, &active);
2676     }
2677     g_free(map_file);
2678     // gpx tracks map --------------------
2679    
2680    
2681     // traffic map --------------------
2682     parent.type = attr_navit;
2683     parent.u.navit = this_;
2684     type.type = attr_type;
2685     type.u.str = "textfile";
2686     data.type = attr_data;
2687     map_file = g_strdup_printf("%straffic.txt", navit_maps_dir);
2688     data.u.str = map_file;
2689    
2690     flags.type = attr_flags;
2691     flags.u.num = 0;
2692     attrs[0] = &type;
2693     attrs[1] = &data;
2694     attrs[2] = &flags;
2695     attrs[3] = NULL;
2696     map2 = map_new(&parent, attrs);
2697     if (map2)
2698     {
2699     map2_attr.u.data = map2;
2700     map2_attr.type = attr_map;
2701     mapset_add_attr_name_str(ms, &map2_attr, "-special-:traffic.txt");
2702     struct attr active;
2703     active.type = attr_active;
2704     active.u.num = 0;
2705     //map_set_attr(map2, &active);
2706     }
2707     g_free(map_file);
2708     // traffic map --------------------
2709    
2710    
2711    
2712    
2713    
2714    
2715    
2716 zoff99 27 int i = 1;
2717     for (i = 1; i < 10; i++)
2718 zoff99 2 {
2719     struct map *map22;
2720     struct attr map22_attr;
2721 zoff99 27 parent.type = attr_navit;
2722     parent.u.navit = this_;
2723     type.type = attr_type;
2724     type.u.str = "binfile";
2725     data.type = attr_data;
2726     map_file = g_strdup_printf("%snavitmap_00%d.bin", navit_maps_dir, i);
2727     data.u.str = map_file;
2728     flags.type = attr_flags;
2729     flags.u.num = 0;
2730     attrs[0] = &type;
2731     attrs[1] = &data;
2732     attrs[2] = &flags;
2733     attrs[3] = NULL;
2734     map22 = map_new(&parent, attrs);
2735 zoff99 2 if (map22)
2736     {
2737 zoff99 27 //DBG dbg(0, "*add* map name=%s\n", map_file);
2738     map22_attr.u.data = map22;
2739     map22_attr.type = attr_map;
2740     // mapset_add_attr_name(ms, &map22_attr);
2741     char *map_name_str;
2742     map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_00%d.bin", i);
2743     mapset_add_attr_name_str(ms, &map22_attr, map_name_str);
2744     struct attr active;
2745     active.type = attr_active;
2746     active.u.num = 0;
2747     //map_set_attr(map22, &active);
2748     g_free(map_name_str);
2749 zoff99 2 }
2750     g_free(map_file);
2751     }
2752    
2753 zoff99 27 i = 10;
2754     for (i = 10; i < 21; i++)
2755 zoff99 2 {
2756 zoff99 27 parent.type = attr_navit;
2757     parent.u.navit = this_;
2758     type.type = attr_type;
2759     type.u.str = "binfile";
2760     data.type = attr_data;
2761     map_file = g_strdup_printf("%snavitmap_0%d.bin", navit_maps_dir, i);
2762     data.u.str = map_file;
2763     ////DBG dbg(0,"map name=%s",map_file);
2764     flags.type = attr_flags;
2765     flags.u.num = 0;
2766     attrs[0] = &type;
2767     attrs[1] = &data;
2768     attrs[2] = &flags;
2769     attrs[3] = NULL;
2770     map2 = map_new(&parent, attrs);
2771 zoff99 2 if (map2)
2772     {
2773 zoff99 27 map2_attr.u.data = map2;
2774     map2_attr.type = attr_map;
2775     // mapset_add_attr_name(ms, &map2_attr);
2776     char *map_name_str;
2777     map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_0%d.bin", i);
2778     mapset_add_attr_name_str(ms, &map2_attr, map_name_str);
2779     struct attr active;
2780     active.type = attr_active;
2781     active.u.num = 0;
2782     //map_set_attr(map2, &active);
2783     g_free(map_name_str);
2784 zoff99 2 }
2785     g_free(map_file);
2786     }
2787     }
2788 zoff99 27
2789     /*
2790     if (this_->mapsets)
2791     {
2792     struct mapset_handle *msh;
2793     struct map *map;
2794     struct mapset *ms;
2795    
2796     //DBG dbg(0,"xx ms callbacks xx\n");
2797    
2798     ms=this_->mapsets->data;
2799     this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2800     msh=mapset_open(ms);
2801     while (msh && (map=mapset_next(msh, 0)))
2802     {
2803     //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
2804     struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2805     map_add_callback(map, pcb);
2806     }
2807     mapset_close(msh);
2808     }
2809     */
2810    
2811 zoff99 28 /*
2812 zoff99 27 struct attr parent;
2813     parent.type = attr_navit;
2814     parent.u.navit = global_navit;
2815    
2816     struct attr *attrs_r[2];
2817     attrs_r[0] = NULL;
2818     attrs_r[1] = NULL;
2819 zoff99 28 */
2820 zoff99 27
2821     //***this_->route = route_new(&parent, attrs_r);
2822    
2823    
2824     //int async = 0;
2825     //transform_setup_source_rect(this_->trans);
2826     //graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
2827    
2828     struct displaylist *dl = navit_get_displaylist(this_);
2829     dl->ms = this_->mapsets->data;
2830     dl->m = NULL;
2831     dl->msh = NULL;
2832    
2833     if (this_->route)
2834     {
2835     struct mapset *ms;
2836     ms = this_->mapsets->data;
2837     route_set_mapset(this_->route, ms);
2838    
2839     struct attr callback;
2840 zoff99 28 this_->route_cb = callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
2841     callback.type = attr_callback;
2842     callback.u.callback = this_->route_cb;
2843 zoff99 27 route_add_attr(this_->route, &callback);
2844     // ***** route_set_projection(this_->route, transform_get_projection(this_->trans));
2845     }
2846    
2847     if (this_->tracking)
2848     {
2849     struct mapset *ms;
2850     ms = this_->mapsets->data;
2851    
2852     tracking_set_mapset(this_->tracking, ms);
2853     if (this_->route)
2854     {
2855     tracking_set_route(this_->tracking, this_->route);
2856     }
2857     }
2858    
2859 zoff99 28 // ready for drawing map
2860     // this_->ready = 3;
2861 zoff99 27
2862 zoff99 28 // draw map
2863     // navit_draw(this_);
2864 zoff99 2 }
2865    
2866 zoff99 27 void navit_reload_maps(struct navit *this_)
2867 zoff99 2 {
2868 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2869     dbg(0,"+#+:enter\n");
2870     #endif
2871 zoff99 2 navit_remove_all_maps(this_);
2872     navit_add_all_maps(this_);
2873     }
2874    
2875 zoff99 27 void navit_init(struct navit *this_)
2876 zoff99 2 {
2877 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
2878     dbg(0,"+#+:enter\n");
2879     #endif
2880 zoff99 27 ////DBG dbg(0,"EEnter\n");
2881 zoff99 2 struct mapset *ms;
2882     struct map *map;
2883     int callback;
2884     char *center_file;
2885    
2886 zoff99 27 // default value
2887     navit_maps_dir = "/sdcard/zanavi/maps/";
2888 zoff99 2
2889 zoff99 27 global_img_waypoint = NULL;
2890    
2891     //DBG dbg(0, "enter gui %p graphics %p\n", this_->gui, this_->gra);
2892    
2893     if (!this_->gui && !(this_->flags & 2))
2894     {
2895     dbg(0, "no gui\n");
2896 zoff99 2 navit_destroy(this_);
2897     return;
2898     }
2899 zoff99 27
2900     if (!this_->gra && !(this_->flags & 1))
2901     {
2902     dbg(0, "no graphics\n");
2903 zoff99 2 navit_destroy(this_);
2904     return;
2905     }
2906 zoff99 27
2907     //DBG dbg(0, "Connecting gui to graphics\n");
2908    
2909     if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra))
2910     {
2911 zoff99 2 struct attr attr_type_gui, attr_type_graphics;
2912     gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
2913     graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
2914 zoff99 27 //DBG dbg(0, "failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
2915     // //DBG dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
2916     // //DBG dbg(0," for explanations and solutions\n");
2917 zoff99 2
2918 zoff99 28 dbg(0, "failed to connect to graphics\n");
2919 zoff99 2 navit_destroy(this_);
2920     return;
2921     }
2922 zoff99 27
2923     if (this_->speech && this_->navigation)
2924     {
2925 zoff99 2 struct attr speech;
2926 zoff99 27 speech.type = attr_speech;
2927     speech.u.speech = this_->speech;
2928 zoff99 2 navigation_set_attr(this_->navigation, &speech);
2929     }
2930 zoff99 27
2931     //DBG dbg(0, "Initializing graphics\n");
2932     //DBG dbg(0, "Setting Vehicle\n");
2933 zoff99 2 navit_set_vehicle(this_, this_->vehicle);
2934 zoff99 28
2935 zoff99 27 //DBG dbg(0, "Adding dynamic maps to mapset %p\n", this_->mapsets);
2936     if (this_->mapsets)
2937     {
2938 zoff99 2 struct mapset_handle *msh;
2939 zoff99 27 ms = this_->mapsets->data;
2940     // **D** // this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2941     msh = mapset_open(ms);
2942     while (msh && (map = mapset_next(msh, 0)))
2943     {
2944 zoff99 2 //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
2945 zoff99 27 // **D** // struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
2946     // **D** // map_add_callback(map, pcb);
2947 zoff99 2 }
2948     mapset_close(msh);
2949 zoff99 27
2950     if (this_->route)
2951     {
2952     if ((map = route_get_map(this_->route)))
2953     {
2954     struct attr map_a, map_name;
2955     map_a.type = attr_map;
2956     map_a.u.map = map;
2957     map_name.type = attr_name;
2958     map_name.u.str = "_ms_route";
2959 zoff99 2 map_set_attr(map_a.u.map, &map_name);
2960     mapset_add_attr(ms, &map_a);
2961     }
2962 zoff99 27
2963     if ((map = route_get_graph_map(this_->route)))
2964     {
2965     struct attr map_a, active, map_name;
2966     map_a.type = attr_map;
2967     map_a.u.map = map;
2968     active.type = attr_active;
2969     active.u.num = 0;
2970     map_name.type = attr_name;
2971     map_name.u.str = "_ms_route_graph";
2972 zoff99 2 map_set_attr(map_a.u.map, &map_name);
2973     mapset_add_attr(ms, &map_a);
2974     map_set_attr(map, &active);
2975     }
2976     route_set_mapset(this_->route, ms);
2977     route_set_projection(this_->route, transform_get_projection(this_->trans));
2978     }
2979 zoff99 27
2980     if (this_->tracking)
2981     {
2982 zoff99 2 tracking_set_mapset(this_->tracking, ms);
2983     if (this_->route)
2984 zoff99 27 {
2985 zoff99 2 tracking_set_route(this_->tracking, this_->route);
2986 zoff99 27 }
2987 zoff99 2 }
2988 zoff99 27
2989     if (this_->navigation)
2990     {
2991     if ((map = navigation_get_map(this_->navigation)))
2992     {
2993     struct attr map_a, active, map_name;
2994     map_a.type = attr_map;
2995     map_a.u.map = map;
2996     active.type = attr_active;
2997     active.u.num = 0;
2998     map_name.type = attr_name;
2999     map_name.u.str = "_ms_navigation";
3000 zoff99 2 map_set_attr(map_a.u.map, &map_name);
3001     mapset_add_attr(ms, &map_a);
3002     map_set_attr(map, &active);
3003     }
3004     }
3005 zoff99 27
3006     if (this_->tracking)
3007     {
3008     if ((map = tracking_get_map(this_->tracking)))
3009     {
3010     struct attr map_a, active, map_name;
3011     map_a.type = attr_map;
3012     map_a.u.map = map;
3013     active.type = attr_active;
3014     active.u.num = 0;
3015     map_name.type = attr_name;
3016     map_name.u.str = "_ms_tracking";
3017 zoff99 14 map_set_attr(map_a.u.map, &map_name);
3018 zoff99 2 mapset_add_attr(ms, &map_a);
3019     map_set_attr(map, &active);
3020     }
3021     }
3022 zoff99 14 // *DISABLED* navit_add_former_destinations_from_file(this_);
3023 zoff99 2 }
3024 zoff99 27
3025     if (this_->route)
3026     {
3027 zoff99 2 struct attr callback;
3028 zoff99 27 this_->route_cb = callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
3029     callback.type = attr_callback;
3030     callback.u.callback = this_->route_cb;
3031 zoff99 2 route_add_attr(this_->route, &callback);
3032     }
3033 zoff99 27
3034     if (this_->navigation)
3035     {
3036     if (this_->speech)
3037     {
3038     this_->nav_speech_cb = callback_new_1(callback_cast(navit_speak), this_);
3039 zoff99 2 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
3040     }
3041 zoff99 27
3042 zoff99 2 if (this_->route)
3043 zoff99 27 {
3044 zoff99 2 navigation_set_route(this_->navigation, this_->route);
3045 zoff99 27 }
3046 zoff99 2 }
3047 zoff99 27
3048     dbg(0, "Setting Center\n");
3049 zoff99 2 center_file = bookmarks_get_center_file(FALSE);
3050 zoff99 27 //dbg(0, "g0\n");
3051 zoff99 2 bookmarks_set_center_from_file(this_->bookmarks, center_file);
3052     g_free(center_file);
3053     #if 0
3054 zoff99 27 if (this_->menubar)
3055     {
3056 zoff99 2 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
3057 zoff99 27 if (men)
3058     {
3059 zoff99 2 navit_add_menu_windows_items(this_, men);
3060     }
3061     }
3062     #endif
3063 zoff99 27 global_navit = this_;
3064 zoff99 2 #if 0
3065     navit_window_roadbook_new(this_);
3066     navit_window_items_new(this_);
3067     #endif
3068    
3069 zoff99 27 //dbg(0, "g1\n");
3070     //messagelist_init(this_->messages);
3071 zoff99 2
3072 zoff99 27 //dbg(0, "g2\n");
3073 zoff99 2 navit_set_cursors(this_);
3074    
3075     callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
3076 zoff99 27 callback = (this_->ready == 2);
3077 zoff99 28 dbg(0, "pre this_->ready=%d\n", this_->ready);
3078     this_->ready = this_->ready | 1;
3079     dbg(0, "set this_->ready=%d\n", this_->ready);
3080 zoff99 27 ////DBG dbg(0,"ready=%d\n",this_->ready);
3081    
3082 zoff99 28
3083     //if (this_->ready == 3)
3084     //{
3085     // ////DBG dbg(0,"navit_draw_async_003\n");
3086     // navit_draw_async(this_, 1);
3087     //}
3088    
3089     dbg(0,"init ready=%d\n", this_->ready);
3090    
3091     // draw???????
3092     // dbg(0,"init DRAW 11\n");
3093     // ready to draw map
3094     // navit_draw(this_);
3095     // dbg(0,"init DRAW 22\n");
3096     // draw???????
3097    
3098 zoff99 2 if (callback)
3099 zoff99 27 {
3100 zoff99 2 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
3101 zoff99 27 }
3102 zoff99 2 #if 0
3103     routech_test(this_);
3104     #endif
3105 zoff99 27 //dbg(0, "1111111111\n");
3106 zoff99 2 }
3107    
3108 zoff99 27 void navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
3109 zoff99 2 {
3110 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3111     dbg(0,"+#+:enter\n");
3112     #endif
3113 zoff99 27 ////DBG dbg(0,"EEnter\n");
3114 zoff99 2 struct coord c;
3115 zoff99 27 int scale = 16;
3116 zoff99 2
3117 zoff99 27 c.x = (r->rl.x + r->lu.x) / 2;
3118     c.y = (r->rl.y + r->lu.y) / 2;
3119 zoff99 2 transform_set_center(this_->trans, &c);
3120 zoff99 27 // dbg(1, "%x,%x-%x,%x\n", r->rl.x, r->rl.y, r->lu.x, r->lu.y);
3121     while (scale < 1 << 20)
3122     {
3123     struct point p1, p2;
3124 zoff99 2 transform_set_scale(this_->trans, scale);
3125     transform_setup_source_rect(this_->trans);
3126     transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
3127     transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
3128 zoff99 27 // dbg(1, "%d,%d-%d,%d\n", p1.x, p1.y, p2.x, p2.y);
3129     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)
3130     scale *= 2;
3131 zoff99 2 else
3132     break;
3133 zoff99 27
3134 zoff99 2 }
3135     if (this_->ready == 3)
3136     {
3137 zoff99 27 ////DBG dbg(0,"navit_draw_async_004\n");
3138     navit_draw_async(this_, 0);
3139 zoff99 2 }
3140     }
3141    
3142 zoff99 27 void navit_zoom_to_route(struct navit *this_, int orientation)
3143 zoff99 2 {
3144 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3145     dbg(0,"+#+:enter\n");
3146     #endif
3147 zoff99 27 ////DBG dbg(0,"EEnter\n");
3148 zoff99 2 struct map *map;
3149 zoff99 27 struct map_rect *mr = NULL;
3150 zoff99 2 struct item *item;
3151     struct coord c;
3152     struct coord_rect r;
3153 zoff99 27 int count = 0;
3154     if (!this_->route)
3155 zoff99 2 return;
3156 zoff99 27 // dbg(1, "enter\n");
3157     map = route_get_map(this_->route);
3158     // dbg(1, "map=%p\n", map);
3159 zoff99 2 if (map)
3160 zoff99 27 mr = map_rect_new(map, NULL);
3161     // dbg(1, "mr=%p\n", mr);
3162     if (mr)
3163     {
3164     while ((item = map_rect_get_item(mr)))
3165     {
3166     // dbg(1, "item=%s\n", item_to_name(item->type));
3167     while (item_coord_get(item, &c, 1))
3168     {
3169     // dbg(1, "coord\n");
3170     if (!count)
3171     r.lu = r.rl = c;
3172 zoff99 2 else
3173 zoff99 27 coord_rect_extend(&r, &c);
3174 zoff99 2 count++;
3175     }
3176     }
3177     map_rect_destroy(mr);
3178     }
3179 zoff99 27 if (!count)
3180 zoff99 2 return;
3181     if (orientation != -1)
3182     transform_set_yaw(this_->trans, orientation);
3183     navit_zoom_to_rect(this_, &r);
3184     }
3185    
3186 zoff99 27 static void navit_cmd_zoom_to_route(struct navit *this)
3187 zoff99 2 {
3188 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3189     dbg(0,"+#+:enter\n");
3190     #endif
3191 zoff99 27 ////DBG dbg(0,"EEnter\n");
3192 zoff99 2 navit_zoom_to_route(this, 0);
3193     }
3194    
3195     /**
3196     * show point on map
3197     *
3198     * @param navit The navit instance
3199     * @param center The point where to center the map, including its projection
3200     * @returns nothing
3201     */
3202 zoff99 27 void navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
3203 zoff99 2 {
3204 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3205     dbg(0,"+#+:enter\n");
3206     #endif
3207 zoff99 27 ////DBG dbg(0,"EEnter\n");
3208     struct coord *c = transform_center(this_->trans);
3209     struct coord c1, c2;
3210 zoff99 2 enum projection pro = transform_get_projection(this_->trans);
3211 zoff99 27 if (pro != center->pro)
3212     {
3213 zoff99 2 c1.x = center->x;
3214     c1.y = center->y;
3215     transform_from_to(&c1, center->pro, &c2, pro);
3216 zoff99 27 }
3217     else
3218     {
3219 zoff99 2 c2.x = center->x;
3220     c2.y = center->y;
3221     }
3222 zoff99 27 *c = c2;
3223     if (set_timeout)
3224     {
3225 zoff99 2 navit_set_timeout(this_);
3226 zoff99 27 }
3227 zoff99 2 if (this_->ready == 3)
3228 zoff99 27 {
3229 zoff99 2 navit_draw(this_);
3230 zoff99 27 }
3231 zoff99 2 }
3232    
3233 zoff99 27 static void navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
3234 zoff99 2 {
3235 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3236     dbg(0,"+#+:enter\n");
3237     #endif
3238 zoff99 27 ////DBG dbg(0,"EEnter\n");
3239 zoff99 2 int width, height;
3240     struct point po;
3241     transform_set_center(this_->trans, c);
3242     transform_get_size(this_->trans, &width, &height);
3243 zoff99 27 po.x = width / 2;
3244     po.y = height / 2;
3245 zoff99 2 update_transformation(this_->trans, &po, p, NULL);
3246     if (set_timeout)
3247 zoff99 27 {
3248 zoff99 2 navit_set_timeout(this_);
3249 zoff99 27 }
3250 zoff99 2 }
3251    
3252     /**
3253     * Links all vehicles to a cursor depending on the current profile.
3254     *
3255     * @param this_ A navit instance
3256     * @author Ralph Sennhauser (10/2009)
3257     */
3258 zoff99 27 void navit_set_cursors(struct navit *this_)
3259 zoff99 2 {
3260 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3261     dbg(0,"+#+:enter\n");
3262     #endif
3263 zoff99 2 struct attr name;
3264     struct navit_vehicle *nv;
3265     struct cursor *c;
3266     GList *v;
3267    
3268 zoff99 27 //dbg(0, "Enter\n");
3269    
3270     v = g_list_first(this_->vehicles); // GList of navit_vehicles
3271     while (v)
3272     {
3273     dbg(0, "* found vehicle *\n");
3274     nv = v->data;
3275     if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL))
3276     {
3277     if (!strcmp(name.u.str, "none"))
3278     {
3279     c = NULL;
3280     }
3281 zoff99 2 else
3282 zoff99 27 {
3283     c = layout_get_cursor(this_->layout_current, name.u.str);
3284     }
3285     }
3286     else
3287     {
3288     c = layout_get_cursor(this_->layout_current, "default");
3289     }
3290 zoff99 2 vehicle_set_cursor(nv->vehicle, c, 0);
3291 zoff99 27 v = g_list_next(v);
3292 zoff99 2 }
3293     return;
3294     }
3295    
3296 zoff99 27 void navit_remove_cursors(struct navit *this_)
3297 zoff99 2 {
3298 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3299     dbg(0,"+#+:enter\n");
3300     #endif
3301 zoff99 27 struct attr name;
3302     struct navit_vehicle *nv;
3303     struct cursor *c;
3304     GList *v;
3305    
3306     //dbg(0, "Enter\n");
3307     name.type = attr_cursor;
3308    
3309     v = g_list_first(this_->vehicles); // GList of navit_vehicles
3310     while (v)
3311     {
3312     dbg(0, "* found vehicle *\n");
3313     nv = v->data;
3314     vehicle_remove_attr(nv->vehicle, &name);
3315     v = g_list_next(v);
3316     }
3317     return;
3318     }
3319    
3320     static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
3321     {
3322 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3323     dbg(0,"+#+:enter\n");
3324     #endif
3325 zoff99 27 ////DBG dbg(0,"EEnter\n");
3326 zoff99 2 int width, height;
3327 zoff99 27 struct navit_vehicle *nv = this_->vehicle;
3328 zoff99 2
3329 zoff99 27 float offset = this_->radius; // Cursor offset from the center of the screen (percent).
3330 zoff99 2 #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 */
3331 zoff99 27 float min_offset = 0.; // Percent offset at min_offset_speed.
3332     float max_offset = 30.; // Percent offset at max_offset_speed.
3333     int min_offset_speed = 2; // Speed in km/h
3334     int max_offset_speed = 50; // Speed ini km/h
3335     // Calculate cursor offset from the center of the screen, upon speed.
3336     if (nv->speed <= min_offset_speed)
3337     {
3338     offset = min_offset;
3339     }
3340     else if (nv->speed > max_offset_speed)
3341     {
3342     offset = max_offset;
3343     }
3344     else
3345     {
3346     offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
3347     }
3348 zoff99 2 #endif
3349    
3350     transform_get_size(this_->trans, &width, &height);
3351 zoff99 27 if (this_->orientation == -1 || keep_orientation)
3352     {
3353     p->x = 50 * width / 100;
3354     p->y = (50 + offset) * height / 100;
3355     if (dir)
3356     *dir = keep_orientation ? this_->orientation : nv->dir;
3357     }
3358     else
3359     {
3360 zoff99 2 int mdir;
3361 zoff99 27 if (this_->tracking && this_->tracking_flag)
3362     {
3363 zoff99 2 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
3364     }
3365 zoff99 27 else
3366     {
3367     mdir = nv->dir - this_->orientation;
3368     }
3369 zoff99 2
3370 zoff99 27 p->x = (50 - offset * sin(M_PI * mdir / 180.)) * width / 100;
3371     p->y = (50 + offset * cos(M_PI * mdir / 180.)) * height / 100;
3372 zoff99 2 if (dir)
3373 zoff99 27 *dir = this_->orientation;
3374 zoff99 2 }
3375     return 1;
3376     }
3377    
3378 zoff99 27 void navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
3379 zoff99 2 {
3380 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3381     dbg(0,"+#+:enter\n");
3382     #endif
3383 zoff99 27 ////DBG dbg(0,"EEnter\n");
3384 zoff99 2 int dir;
3385     struct point pn;
3386 zoff99 27 struct navit_vehicle *nv = this_->vehicle;
3387 zoff99 2 navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
3388     transform_set_yaw(this_->trans, dir);
3389     navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
3390     if (autozoom)
3391     navit_autozoom(this_, &nv->coord, nv->speed, 0);
3392     }
3393    
3394 zoff99 27 static void navit_set_center_cursor_draw(struct navit *this_)
3395 zoff99 2 {
3396 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3397     dbg(0,"+#+:enter\n");
3398     #endif
3399     //dbg(0,"EEnter\n");
3400 zoff99 27 navit_set_center_cursor(this_, 1, 0);
3401 zoff99 2 if (this_->ready == 3)
3402     {
3403 zoff99 28 //dbg(0,"navit_draw_async_005\n");
3404 zoff99 2 navit_draw_async(this_, 1);
3405     }
3406     }
3407    
3408 zoff99 27 static void navit_cmd_set_center_cursor(struct navit *this_)
3409 zoff99 2 {
3410 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3411     dbg(0,"+#+:enter\n");
3412     #endif
3413 zoff99 27 ////DBG dbg(0,"EEnter\n");
3414 zoff99 2 navit_set_center_cursor_draw(this_);
3415     }
3416    
3417 zoff99 27 void navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
3418 zoff99 2 {
3419 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3420     dbg(0,"+#+:enter\n");
3421     #endif
3422 zoff99 27 ////DBG dbg(0,"EEnter\n");
3423 zoff99 2 struct coord c;
3424     struct pcoord pc;
3425     transform_reverse(this_->trans, p, &c);
3426     pc.x = c.x;
3427     pc.y = c.y;
3428     pc.pro = transform_get_projection(this_->trans);
3429     navit_set_center(this_, &pc, set_timeout);
3430     }
3431    
3432     #if 0
3433 zoff99 27 switch((*attrs)->type)
3434     {
3435     case attr_zoom:
3436     zoom=(*attrs)->u.num;
3437     break;
3438     case attr_center:
3439     g=*((*attrs)->u.coord_geo);
3440     break;
3441 zoff99 2 #endif
3442    
3443 zoff99 27 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
3444 zoff99 2 {
3445 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3446     dbg(0,"+#+:enter\n");
3447     #endif
3448 zoff99 27 ////DBG dbg(0,"EEnter\n");
3449     int dir = 0, orient_old = 0, attr_updated = 0;
3450 zoff99 2 struct coord co;
3451     long zoom;
3452     GList *l;
3453     struct navit_vehicle *nv;
3454     struct layout *lay;
3455     struct attr active;
3456 zoff99 27 active.type = attr_active;
3457     active.u.num = 0;
3458 zoff99 2
3459 zoff99 27 switch (attr->type)
3460     {
3461     case attr_autozoom:
3462     attr_updated = (this_->autozoom_secs != attr->u.num);
3463     this_->autozoom_secs = attr->u.num;
3464     break;
3465     case attr_autozoom_active:
3466     attr_updated = (this_->autozoom_active != attr->u.num);
3467     this_->autozoom_active = attr->u.num;
3468     break;
3469     case attr_center:
3470     transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
3471     // dbg(1, "0x%x,0x%x\n", co.x, co.y);
3472     transform_set_center(this_->trans, &co);
3473     break;
3474     case attr_drag_bitmap:
3475     attr_updated = (this_->drag_bitmap != !!attr->u.num);
3476     this_->drag_bitmap = !!attr->u.num;
3477     break;
3478     case attr_flags:
3479     attr_updated = (this_->flags != attr->u.num);
3480     this_->flags = attr->u.num;
3481     break;
3482     case attr_flags_graphics:
3483     attr_updated = (this_->graphics_flags != attr->u.num);
3484     this_->graphics_flags = attr->u.num;
3485     break;
3486     case attr_follow:
3487     if (!this_->vehicle)
3488     return 0;
3489     attr_updated = (this_->vehicle->follow_curr != attr->u.num);
3490     this_->vehicle->follow_curr = attr->u.num;
3491     break;
3492     case attr_layout:
3493     if (this_->layout_current != attr->u.layout)
3494     {
3495     this_->layout_current = attr->u.layout;
3496     graphics_font_destroy_all(this_->gra);
3497     navit_set_cursors(this_);
3498     if (this_->ready == 3)
3499     navit_draw(this_);
3500     attr_updated = 1;
3501     }
3502     break;
3503     case attr_layout_name:
3504     l = this_->layouts;
3505     while (l)
3506     {
3507     lay = l->data;
3508     if (!strcmp(lay->name, attr->u.str))
3509     {
3510     struct attr attr;
3511     attr.type = attr_layout;
3512     attr.u.layout = lay;
3513     return navit_set_attr_do(this_, &attr, init);
3514     }
3515     l = g_list_next(l);
3516     }
3517 zoff99 2 return 0;
3518 zoff99 27 case attr_map_border:
3519     if (this_->border != attr->u.num)
3520     {
3521     this_->border = attr->u.num;
3522     attr_updated = 1;
3523 zoff99 2 }
3524 zoff99 27 break;
3525     case attr_orientation:
3526     orient_old = this_->orientation;
3527     this_->orientation = attr->u.num;
3528     if (!init)
3529     {
3530     if (this_->orientation != -1)
3531     {
3532     dir = this_->orientation;
3533 zoff99 2 }
3534 zoff99 27 else
3535     {
3536     if (this_->vehicle)
3537     {
3538     dir = this_->vehicle->dir;
3539     }
3540     }
3541     transform_set_yaw(this_->trans, dir);
3542     if (orient_old != this_->orientation)
3543     {
3544 zoff99 2 #if 0
3545 zoff99 27 if (this_->ready == 3)
3546 zoff99 2 navit_draw(this_);
3547     #endif
3548 zoff99 27 attr_updated = 1;
3549     }
3550 zoff99 2 }
3551 zoff99 27 break;
3552     case attr_osd_configuration:
3553     //DBG dbg(0, "setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
3554     attr_updated = (this_->osd_configuration != attr->u.num);
3555     this_->osd_configuration = attr->u.num;
3556     break;
3557     case attr_pitch:
3558     attr_updated = (this_->pitch != attr->u.num);
3559     this_->pitch = attr->u.num;
3560     transform_set_pitch(this_->trans, this_->pitch);
3561     if (!init && attr_updated && this_->ready == 3)
3562     navit_draw(this_);
3563     break;
3564     case attr_projection:
3565     if (this_->trans && transform_get_projection(this_->trans) != attr->u.projection)
3566     {
3567     navit_projection_set(this_, attr->u.projection, !init);
3568     attr_updated = 1;
3569     }
3570     break;
3571     case attr_radius:
3572     attr_updated = (this_->radius != attr->u.num);
3573     this_->radius = attr->u.num;
3574     break;
3575     case attr_recent_dest:
3576     attr_updated = (this_->recentdest_count != attr->u.num);
3577     this_->recentdest_count = attr->u.num;
3578     break;
3579     case attr_speech:
3580     if (this_->speech && this_->speech != attr->u.speech)
3581     {
3582     attr_updated = 1;
3583     this_->speech = attr->u.speech;
3584     }
3585     break;
3586     case attr_timeout:
3587     attr_updated = (this_->center_timeout != attr->u.num);
3588     this_->center_timeout = attr->u.num;
3589     break;
3590     case attr_tracking:
3591     attr_updated = (this_->tracking_flag != !!attr->u.num);
3592     this_->tracking_flag = !!attr->u.num;
3593     break;
3594     case attr_transformation:
3595     this_->trans = attr->u.transformation;
3596     break;
3597     case attr_use_mousewheel:
3598     attr_updated = (this_->use_mousewheel != !!attr->u.num);
3599     this_->use_mousewheel = !!attr->u.num;
3600     break;
3601     case attr_vehicle:
3602     l = this_->vehicles;
3603     while (l)
3604     {
3605     nv = l->data;
3606     if (nv->vehicle == attr->u.vehicle)
3607     {
3608     if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle)
3609     {
3610     if (this_->vehicle)
3611 zoff99 28 {
3612 zoff99 27 vehicle_set_attr(this_->vehicle->vehicle, &active);
3613 zoff99 28 }
3614 zoff99 27 active.u.num = 1;
3615     vehicle_set_attr(nv->vehicle, &active);
3616     attr_updated = 1;
3617     }
3618     navit_set_vehicle(this_, nv);
3619 zoff99 2 }
3620 zoff99 27 l = g_list_next(l);
3621 zoff99 2 }
3622 zoff99 27 break;
3623     case attr_zoom:
3624     zoom = transform_get_scale(this_->trans);
3625     attr_updated = (zoom != attr->u.num);
3626     transform_set_scale(this_->trans, attr->u.num);
3627     if (attr_updated && !init)
3628     navit_draw(this_);
3629     break;
3630     case attr_zoom_min:
3631     attr_updated = (attr->u.num != this_->zoom_min);
3632     this_->zoom_min = attr->u.num;
3633     break;
3634     case attr_zoom_max:
3635     attr_updated = (attr->u.num != this_->zoom_max);
3636     this_->zoom_max = attr->u.num;
3637     break;
3638     case attr_message:
3639     //navit_add_message(this_, attr->u.str);
3640     break;
3641     case attr_follow_cursor:
3642     attr_updated = (this_->follow_cursor != !!attr->u.num);
3643     this_->follow_cursor = !!attr->u.num;
3644     break;
3645     case attr_imperial:
3646     attr_updated = (this_->imperial != attr->u.num);
3647     this_->imperial = attr->u.num;
3648     break;
3649     default:
3650     return 0;
3651 zoff99 2 }
3652 zoff99 27 if (attr_updated && !init)
3653     {
3654 zoff99 2 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
3655     if (attr->type == attr_osd_configuration)
3656 zoff99 28 {
3657 zoff99 2 graphics_draw_mode(this_->gra, draw_mode_end);
3658 zoff99 28 }
3659 zoff99 2 }
3660 zoff99 28
3661     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3662     dbg(0,"+#+:leave\n");
3663     #endif
3664    
3665 zoff99 2 return 1;
3666     }
3667    
3668 zoff99 27 int navit_set_attr(struct navit *this_, struct attr *attr)
3669 zoff99 2 {
3670 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3671     dbg(0,"+#+:enter\n");
3672     #endif
3673 zoff99 27 ////DBG dbg(0,"EEnter\n");
3674 zoff99 2 return navit_set_attr_do(this_, attr, 0);
3675     }
3676    
3677 zoff99 27 int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
3678 zoff99 2 {
3679 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3680     dbg(0,"+#+:enter\n");
3681     #endif
3682 zoff99 27 ////DBG dbg(0,"EEnter\n");
3683 zoff99 2 struct message *msg;
3684 zoff99 27 int len, offset;
3685     int ret = 1;
3686 zoff99 2
3687 zoff99 27 switch (type)
3688     {
3689     case attr_message:
3690 zoff99 2 return 0;
3691 zoff99 27 /*
3692     msg = navit_get_messages(this_);
3693 zoff99 2
3694 zoff99 27 if (!msg)
3695     {
3696     return 0;
3697     }
3698 zoff99 2
3699 zoff99 27 len = 0;
3700     while (msg)
3701     {
3702     len += strlen(msg->text) + 1;
3703     msg = msg->next;
3704     }
3705     attr->u.str = g_malloc(len + 1);
3706 zoff99 2
3707 zoff99 27 msg = navit_get_messages(this_);
3708     offset = 0;
3709     while (msg)
3710     {
3711     g_stpcpy((attr->u.str + offset), msg->text);
3712     offset += strlen(msg->text);
3713     attr->u.str[offset] = '\n';
3714     offset++;
3715    
3716     msg = msg->next;
3717     }
3718    
3719     attr->u.str[len] = '\0';
3720     */
3721     break;
3722     case attr_imperial:
3723     attr->u.num = this_->imperial;
3724     break;
3725     case attr_bookmark_map:
3726     attr->u.map = bookmarks_get_map(this_->bookmarks);
3727     break;
3728     case attr_bookmarks:
3729     attr->u.bookmarks = this_->bookmarks;
3730     break;
3731     case attr_callback_list:
3732     attr->u.callback_list = this_->attr_cbl;
3733     break;
3734     case attr_destination:
3735     if (!this_->destination_valid)
3736     return 0;
3737     attr->u.pcoord = &this_->destination;
3738     break;
3739     case attr_displaylist:
3740     attr->u.displaylist = this_->displaylist;
3741     return (attr->u.displaylist != NULL);
3742     case attr_follow:
3743     if (!this_->vehicle)
3744     return 0;
3745     attr->u.num = this_->vehicle->follow_curr;
3746     break;
3747     case attr_former_destination_map:
3748     attr->u.map = this_->former_destination;
3749     break;
3750     case attr_graphics:
3751     attr->u.graphics = this_->gra;
3752     ret = (attr->u.graphics != NULL);
3753     break;
3754     case attr_gui:
3755     attr->u.gui = this_->gui;
3756     ret = (attr->u.gui != NULL);
3757     break;
3758     case attr_layout:
3759     if (iter)
3760 zoff99 2 {
3761 zoff99 27 if (iter->u.list)
3762     {
3763     iter->u.list = g_list_next(iter->u.list);
3764     }
3765     else
3766     {
3767     iter->u.list = this_->layouts;
3768     }
3769     if (!iter->u.list)
3770     {
3771     return 0;
3772     }
3773     attr->u.layout = (struct layout *) iter->u.list->data;
3774 zoff99 2 }
3775     else
3776     {
3777 zoff99 27 attr->u.layout = this_->layout_current;
3778 zoff99 2 }
3779 zoff99 27 break;
3780     case attr_map:
3781     if (iter && this_->mapsets)
3782 zoff99 2 {
3783 zoff99 27 if (!iter->u.mapset_handle)
3784     {
3785     iter->u.mapset_handle = mapset_open((struct mapset *) this_->mapsets->data);
3786     }
3787     attr->u.map = mapset_next(iter->u.mapset_handle, 0);
3788     if (!attr->u.map)
3789     {
3790     mapset_close(iter->u.mapset_handle);
3791     return 0;
3792     }
3793     }
3794     else
3795     {
3796 zoff99 2 return 0;
3797     }
3798 zoff99 27 break;
3799     case attr_mapset:
3800     attr->u.mapset = this_->mapsets->data;
3801     ret = (attr->u.mapset != NULL);
3802     break;
3803     case attr_navigation:
3804     attr->u.navigation = this_->navigation;
3805     break;
3806     case attr_orientation:
3807     attr->u.num = this_->orientation;
3808     break;
3809     case attr_osd_configuration:
3810     attr->u.num = this_->osd_configuration;
3811     break;
3812     case attr_pitch:
3813     attr->u.num = transform_get_pitch(this_->trans);
3814     break;
3815     case attr_projection:
3816     if (this_->trans)
3817     {
3818     attr->u.num = transform_get_projection(this_->trans);
3819 zoff99 2 }
3820 zoff99 27 else
3821     {
3822 zoff99 2 return 0;
3823     }
3824 zoff99 27 break;
3825     case attr_route:
3826     attr->u.route = this_->route;
3827     break;
3828     case attr_speech:
3829     attr->u.speech = this_->speech;
3830     break;
3831     case attr_tracking:
3832     attr->u.num = this_->tracking_flag;
3833     break;
3834     case attr_trackingo:
3835     attr->u.tracking = this_->tracking;
3836     break;
3837     case attr_transformation:
3838     attr->u.transformation = this_->trans;
3839     break;
3840     case attr_vehicle:
3841     if (iter)
3842     {
3843     if (iter->u.list)
3844     {
3845     iter->u.list = g_list_next(iter->u.list);
3846     }
3847     else
3848     {
3849     iter->u.list = this_->vehicles;
3850     }
3851     if (!iter->u.list)
3852     return 0;
3853     attr->u.vehicle = ((struct navit_vehicle*) iter->u.list->data)->vehicle;
3854 zoff99 2 }
3855 zoff99 27 else
3856     {
3857     if (this_->vehicle)
3858     {
3859     attr->u.vehicle = this_->vehicle->vehicle;
3860     }
3861     else
3862     {
3863     return 0;
3864     }
3865 zoff99 2 }
3866 zoff99 27 break;
3867     case attr_vehicleprofile:
3868     attr->u.vehicleprofile = this_->vehicleprofile;
3869     break;
3870     case attr_zoom:
3871     attr->u.num = transform_get_scale(this_->trans);
3872     break;
3873     case attr_autozoom_active:
3874     attr->u.num = this_->autozoom_active;
3875     break;
3876     case attr_follow_cursor:
3877     attr->u.num = this_->follow_cursor;
3878     break;
3879     default:
3880     return 0;
3881 zoff99 2 }
3882 zoff99 27 attr->type = type;
3883 zoff99 28
3884     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3885     dbg(0,"+#+:leave\n");
3886     #endif
3887    
3888 zoff99 2 return ret;
3889     }
3890    
3891 zoff99 27 static int navit_add_log(struct navit *this_, struct log *log)
3892 zoff99 2 {
3893 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3894     dbg(0,"+#+:enter\n");
3895     #endif
3896 zoff99 2 struct attr type_attr;
3897     if (!log_get_attr(log, attr_type, &type_attr, NULL))
3898     return 0;
3899 zoff99 27 if (!strcmp(type_attr.u.str, "textfile_debug"))
3900     {
3901 zoff99 2 char *header = "type=track_tracked\n";
3902     if (this_->textfile_debug_log)
3903     return 0;
3904     log_set_header(log, header, strlen(header));
3905 zoff99 27 this_->textfile_debug_log = log;
3906 zoff99 2 return 1;
3907     }
3908     return 0;
3909     }
3910    
3911 zoff99 27 static int navit_add_layout(struct navit *this_, struct layout *layout)
3912 zoff99 2 {
3913 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3914     dbg(0,"+#+:enter\n");
3915     #endif
3916 zoff99 27 ////DBG dbg(0,"EEnter\n");
3917 zoff99 2 struct attr active;
3918     this_->layouts = g_list_append(this_->layouts, layout);
3919     layout_get_attr(layout, attr_active, &active, NULL);
3920 zoff99 27 if (active.u.num || !this_->layout_current)
3921     {
3922     this_->layout_current = layout;
3923 zoff99 2 return 1;
3924     }
3925     return 0;
3926     }
3927    
3928 zoff99 27 int navit_add_attr(struct navit *this_, struct attr *attr)
3929 zoff99 2 {
3930 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3931     dbg(0,"+#+:enter\n");
3932     #endif
3933 zoff99 27 ////DBG dbg(0,"EEnter\n");
3934 zoff99 2
3935 zoff99 27 int ret = 1;
3936     switch (attr->type)
3937     {
3938     case attr_callback:
3939     navit_add_callback(this_, attr->u.callback);
3940     break;
3941     case attr_log:
3942     ret = navit_add_log(this_, attr->u.log);
3943     break;
3944     case attr_gui:
3945     ret = navit_set_gui(this_, attr->u.gui);
3946     break;
3947     case attr_graphics:
3948     ret = navit_set_graphics(this_, attr->u.graphics);
3949     break;
3950     case attr_layout:
3951     ret = navit_add_layout(this_, attr->u.layout);
3952     break;
3953     case attr_route:
3954     this_->route = attr->u.route;
3955     break;
3956     case attr_mapset:
3957     this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
3958     break;
3959     case attr_navigation:
3960     this_->navigation = attr->u.navigation;
3961     break;
3962     case attr_recent_dest:
3963     this_->recentdest_count = attr->u.num;
3964     break;
3965     case attr_speech:
3966     this_->speech = attr->u.speech;
3967     break;
3968     case attr_tracking:
3969     this_->tracking = attr->u.tracking;
3970     break;
3971     case attr_vehicle:
3972     ret = navit_add_vehicle(this_, attr->u.vehicle);
3973     break;
3974     case attr_vehicleprofile:
3975     this_->vehicleprofiles = g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
3976     break;
3977     case attr_autozoom_min:
3978     this_->autozoom_min = attr->u.num;
3979     break;
3980     default:
3981     return 0;
3982 zoff99 2 }
3983     callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
3984 zoff99 28
3985     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3986     dbg(0,"+#+:leave\n");
3987     #endif
3988    
3989 zoff99 2 return ret;
3990     }
3991    
3992 zoff99 27 int navit_remove_attr(struct navit *this_, struct attr *attr)
3993 zoff99 2 {
3994 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
3995     dbg(0,"+#+:enter\n");
3996     #endif
3997 zoff99 27 int ret = 1;
3998     switch (attr->type)
3999     {
4000     case attr_callback:
4001     navit_remove_callback(this_, attr->u.callback);
4002     break;
4003     default:
4004     return 0;
4005 zoff99 2 }
4006 zoff99 28
4007     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4008     dbg(0,"+#+:leave\n");
4009     #endif
4010    
4011 zoff99 2 return ret;
4012     }
4013    
4014     struct attr_iter *
4015     navit_attr_iter_new(void)
4016     {
4017 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4018     dbg(0,"+#+:enter\n");
4019     #endif
4020 zoff99 27 return g_new0(struct attr_iter, 1);
4021 zoff99 2 }
4022    
4023 zoff99 27 void navit_attr_iter_destroy(struct attr_iter *iter)
4024 zoff99 2 {
4025 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4026     dbg(0,"+#+:enter\n");
4027     #endif
4028 zoff99 2 g_free(iter);
4029     }
4030    
4031 zoff99 27 void navit_add_callback(struct navit *this_, struct callback *cb)
4032 zoff99 2 {
4033 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4034     dbg(0,"+#+:enter\n");
4035     #endif
4036 zoff99 27 ////DBG dbg(0,"EEnter\n");
4037 zoff99 2
4038     callback_list_add(this_->attr_cbl, cb);
4039     }
4040    
4041 zoff99 27 void navit_remove_callback(struct navit *this_, struct callback *cb)
4042 zoff99 2 {
4043 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4044     dbg(0,"+#+:enter\n");
4045     #endif
4046 zoff99 27 ////DBG dbg(0,"EEnter\n");
4047 zoff99 2
4048     callback_list_remove(this_->attr_cbl, cb);
4049     }
4050    
4051     /**
4052     * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
4053     *
4054     * @param navit The navit instance
4055     * @returns nothing
4056     */
4057    
4058 zoff99 27 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
4059 zoff99 2 {
4060 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4061     dbg(0,"+#+:enter\n");
4062     #endif
4063 zoff99 27 ////DBG dbg(0,"EEnter\n");
4064 zoff99 2
4065     struct point cursor_pnt;
4066     enum projection pro;
4067    
4068     if (this_->blocked)
4069     return;
4070     if (pnt)
4071     {
4072 zoff99 27 cursor_pnt = *pnt;
4073 zoff99 2 }
4074     else
4075     {
4076 zoff99 27 pro = transform_get_projection(this_->trans_cursor);
4077 zoff99 2 if (!pro)
4078     return;
4079     transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
4080     }
4081 zoff99 27 ////DBG dbg(0,"xx=%d\n",cursor_pnt.x);
4082     ////DBG dbg(0,"yy=%d\n",cursor_pnt.y);
4083 zoff99 2
4084 zoff99 27 global_vehicle_pos_onscreen.x = cursor_pnt.x;
4085     global_vehicle_pos_onscreen.y = cursor_pnt.y;
4086 zoff99 2
4087 zoff99 27 ////DBG dbg(0,"xx=%d\n",pnt->x);
4088     ////DBG dbg(0,"yy=%d\n",pnt->y);
4089     ////DBG dbg(0,"vehicle_draw_001\n");
4090     vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0 : 1, nv->dir - transform_get_yaw(this_->trans_cursor), nv->speed);
4091 zoff99 2 #if 0
4092     if (pnt)
4093 zoff99 27 pnt2=*pnt;
4094     else
4095     {
4096 zoff99 2 pro=transform_get_projection(this_->trans);
4097     transform(this_->trans, pro, &nv->coord, &pnt2, 1);
4098     }
4099     #if 1
4100     cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
4101     #else
4102     cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
4103     #endif
4104     #endif
4105     }
4106    
4107 zoff99 27 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
4108 zoff99 2 {
4109 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4110     dbg(0,"+#+:enter\n");
4111     #endif
4112 zoff99 2
4113 zoff99 28 #ifdef NAVIT_MEASURE_TIME_DEBUG
4114     clock_t s_ = debug_measure_start();
4115     #endif
4116    
4117 zoff99 2 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
4118     struct pcoord cursor_pc;
4119 zoff99 27 struct point cursor_pnt, *pnt = &cursor_pnt;
4120     struct tracking *tracking = NULL;
4121 zoff99 2 struct pcoord pc[16];
4122 zoff99 27 enum projection pro = transform_get_projection(this_->trans_cursor);
4123 zoff99 2 int count;
4124     int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
4125     void *attr_object;
4126     char *destination_file;
4127    
4128 zoff99 27 if (this_->ready != 3)
4129     {
4130 zoff99 2 //profile(0,"return 1\n");
4131     return;
4132     }
4133 zoff99 28
4134 zoff99 2 navit_layout_switch(this_);
4135     if (this_->vehicle == nv && this_->tracking_flag)
4136 zoff99 28 {
4137 zoff99 27 tracking = this_->tracking;
4138 zoff99 28 }
4139    
4140 zoff99 27 if (tracking)
4141     {
4142 zoff99 2 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
4143 zoff99 27 attr_object = tracking;
4144     get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) tracking_get_attr;
4145 zoff99 2 }
4146 zoff99 27 else
4147     {
4148     attr_object = nv->vehicle;
4149     get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) vehicle_get_attr;
4150     }
4151 zoff99 28
4152 zoff99 2 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
4153 zoff99 28 {
4154 zoff99 2 if (!attr_valid.u.num != attr_position_valid_invalid)
4155 zoff99 28 {
4156 zoff99 2 return;
4157 zoff99 28 }
4158     }
4159    
4160 zoff99 27 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))
4161     {
4162 zoff99 2 return;
4163     }
4164 zoff99 28
4165 zoff99 27 nv->dir = *attr_dir.u.numd;
4166     nv->speed = *attr_speed.u.numd;
4167 zoff99 2 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
4168     if (nv != this_->vehicle)
4169     {
4170 zoff99 28 if (hold_drawing == 0)
4171     {
4172     navit_vehicle_draw(this_, nv, NULL);
4173     }
4174 zoff99 2 return;
4175     }
4176     cursor_pc.x = nv->coord.x;
4177     cursor_pc.y = nv->coord.y;
4178     cursor_pc.pro = pro;
4179 zoff99 27 if (this_->route)
4180     {
4181 zoff99 2 if (tracking)
4182 zoff99 28 {
4183 zoff99 2 route_set_position_from_tracking(this_->route, tracking, pro);
4184 zoff99 28 }
4185 zoff99 2 else
4186 zoff99 28 {
4187 zoff99 2 route_set_position(this_->route, &cursor_pc);
4188 zoff99 28 }
4189 zoff99 2 }
4190 zoff99 28
4191 zoff99 2 callback_list_call_attr_0(this_->attr_cbl, attr_position);
4192 zoff99 28
4193 zoff99 27 // navit_textfile_debug_log(this_, "type=trackpoint_tracked");
4194 zoff99 28 /*
4195 zoff99 2 if (this_->gui && nv->speed > MYSTERY_SPEED)
4196 zoff99 28 {
4197     // stupid!!!! this gets called every second!!! fixme!!!!!!
4198 zoff99 2 navit_disable_suspend();
4199 zoff99 28 // stupid!!!! this gets called every second!!! fixme!!!!!!
4200     }
4201     */
4202    
4203 zoff99 2 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
4204 zoff99 27 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)))
4205 zoff99 2 {
4206 zoff99 28 if (hold_drawing == 0)
4207     {
4208     //dbg(0,"call:navit_set_center_cursor_draw:start\n");
4209     navit_set_center_cursor_draw(this_);
4210     //dbg(0,"call:navit_set_center_cursor_draw:end\n");
4211     }
4212 zoff99 2 }
4213     else
4214     {
4215 zoff99 28 if (hold_drawing == 0)
4216     {
4217     navit_vehicle_draw(this_, nv, pnt);
4218     }
4219 zoff99 2 }
4220    
4221     if (nv->follow_curr > 1)
4222 zoff99 28 {
4223 zoff99 2 nv->follow_curr--;
4224 zoff99 28 }
4225 zoff99 2 else
4226 zoff99 28 {
4227 zoff99 27 nv->follow_curr = nv->follow;
4228 zoff99 28 }
4229    
4230 zoff99 2 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
4231    
4232     /* Finally, if we reached our destination, stop navigation. */
4233 zoff99 27 if (this_->route)
4234     {
4235     switch (route_destination_reached(this_->route))
4236     {
4237     case 1:
4238     route_remove_waypoint(this_->route);
4239     count = route_get_destinations(this_->route, pc, 16);
4240    
4241     // destination_file = bookmarks_get_destination_file(TRUE);
4242     // bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
4243    
4244 zoff99 14 #ifdef HAVE_API_ANDROID
4245 zoff99 27 // waypoint reached
4246     android_return_generic_int(5, 1);
4247 zoff99 28 #ifdef NAVIT_SAY_DEBUG_PRINT
4248 zoff99 27 android_send_generic_text(1,"+*#O:Waypoint reached\n");
4249 zoff99 28 #endif
4250 zoff99 27 // say it
4251     navit_say(this_, _("Waypoint reached"));
4252 zoff99 14 #endif
4253 zoff99 27 break;
4254     case 2:
4255     navit_set_destination(this_, NULL, NULL, 0);
4256     // ** inform java that we reached our destination **
4257 zoff99 14 #ifdef HAVE_API_ANDROID
4258 zoff99 27 android_return_generic_int(4, 1);
4259 zoff99 28 #ifdef NAVIT_SAY_DEBUG_PRINT
4260 zoff99 27 android_send_generic_text(1,"+*#O:You have reached your destination\n");
4261 zoff99 28 #endif
4262 zoff99 27 // say it
4263     navit_say(this_, _("You have reached your destination"));
4264 zoff99 14 #endif
4265 zoff99 27 break;
4266 zoff99 2 }
4267     }
4268 zoff99 28
4269     if (hold_drawing == 0)
4270     {
4271     // draw???????
4272     // navit_draw(this_);
4273     if (this_->ready == 3)
4274     {
4275     //dbg(0,"location update:draw:start\n");
4276     //navit_draw_async(this_, 1);
4277     //dbg(0,"location update:draw:end\n");
4278     }
4279     // draw???????
4280     }
4281    
4282     //dbg(0,"navit_vehicle_update_999\n");
4283    
4284     #ifdef NAVIT_MEASURE_TIME_DEBUG
4285     debug_mrp("navit_vehicle_update:", debug_measure_end(s_));
4286     #endif
4287    
4288     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4289     dbg(0,"+#+:leave\n");
4290     #endif
4291 zoff99 2 }
4292    
4293     /**
4294     * Set the position of the vehicle
4295     *
4296     * @param navit The navit instance
4297     * @param c The coordinate to set as position
4298     * @returns nothing
4299     */
4300    
4301 zoff99 27 void navit_set_position(struct navit *this_, struct pcoord *c)
4302 zoff99 2 {
4303 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4304     dbg(0,"+#+:enter\n");
4305     #endif
4306 zoff99 27 //DBG dbg(0,"EEnter\n");
4307 zoff99 2
4308 zoff99 27 if (this_->route)
4309     {
4310 zoff99 2 route_set_position(this_->route, c);
4311     callback_list_call_attr_0(this_->attr_cbl, attr_position);
4312     }
4313 zoff99 28
4314 zoff99 2 if (this_->ready == 3)
4315 zoff99 28 {
4316 zoff99 2 navit_draw(this_);
4317 zoff99 28 }
4318 zoff99 2 }
4319    
4320 zoff99 27 static int navit_set_vehicleprofile(struct navit *this_, char *name)
4321 zoff99 2 {
4322 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4323     dbg(0,"+#+:enter\n");
4324     #endif
4325 zoff99 27 ////DBG dbg(0,"EEnter\n");
4326 zoff99 2
4327     struct attr attr;
4328     GList *l;
4329 zoff99 27 l = this_->vehicleprofiles;
4330     while (l)
4331     {
4332     if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL))
4333     {
4334     if (!strcmp(attr.u.str, name))
4335     {
4336     this_->vehicleprofile = l->data;
4337 zoff99 2 if (this_->route)
4338     route_set_profile(this_->route, this_->vehicleprofile);
4339     return 1;
4340     }
4341     }
4342 zoff99 27 l = g_list_next(l);
4343 zoff99 2 }
4344     return 0;
4345     }
4346    
4347 zoff99 27 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
4348 zoff99 2 {
4349 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4350     dbg(0,"+#+:enter\n");
4351     #endif
4352 zoff99 27 ////DBG dbg(0,"EEnter\n");
4353 zoff99 2
4354     struct attr attr;
4355 zoff99 27 this_->vehicle = nv;
4356 zoff99 28
4357 zoff99 27 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL))
4358     {
4359 zoff99 2 if (navit_set_vehicleprofile(this_, attr.u.str))
4360 zoff99 27 {
4361 zoff99 2 return;
4362 zoff99 27 }
4363 zoff99 2 }
4364 zoff99 28
4365 zoff99 27 if (!navit_set_vehicleprofile(this_, "car"))
4366     {
4367 zoff99 2 /* We do not have a fallback "car" profile
4368 zoff99 27 * so lets set any profile */
4369 zoff99 2 GList *l;
4370 zoff99 27 l = this_->vehicleprofiles;
4371     if (l)
4372     {
4373     this_->vehicleprofile = l->data;
4374     if (this_->route)
4375     {
4376     route_set_profile(this_->route, this_->vehicleprofile);
4377     }
4378 zoff99 2 }
4379     }
4380     }
4381    
4382     /**
4383     * Register a new vehicle
4384     *
4385     * @param navit The navit instance
4386     * @param v The vehicle instance
4387     * @returns 1 for success
4388     */
4389 zoff99 27 int navit_add_vehicle(struct navit *this_, struct vehicle *v)
4390 zoff99 2 {
4391 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4392     dbg(0,"+#+:enter\n");
4393     #endif
4394 zoff99 2
4395     struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
4396     struct attr follow, active, animate;
4397 zoff99 27 nv->vehicle = v;
4398     nv->follow = 0;
4399 zoff99 2 nv->last.x = 0;
4400     nv->last.y = 0;
4401 zoff99 27 nv->animate_cursor = 0;
4402 zoff99 2 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
4403 zoff99 27 nv->follow = follow.u.num;
4404     nv->follow_curr = nv->follow;
4405     this_->vehicles = g_list_append(this_->vehicles, nv);
4406 zoff99 2 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
4407     navit_set_vehicle(this_, nv);
4408     if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
4409 zoff99 27 nv->animate_cursor = animate.u.num;
4410     nv->callback.type = attr_callback;
4411 zoff99 28
4412     // gets called via this callback in vehicle_android.c [in function: vehicle_android_callback]
4413 zoff99 27 nv->callback.u.callback = callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
4414 zoff99 28
4415     //dbg(0,"EEnter 11\n");
4416 zoff99 2 vehicle_add_attr(nv->vehicle, &nv->callback);
4417 zoff99 28 //dbg(0,"EEnter 22\n");
4418 zoff99 2 vehicle_set_attr(nv->vehicle, &this_->self);
4419 zoff99 28 //dbg(0,"EEnter 33\n");
4420    
4421     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4422     dbg(0,"+#+:leave\n");
4423     #endif
4424    
4425 zoff99 2 return 1;
4426     }
4427    
4428     struct gui *
4429     navit_get_gui(struct navit *this_)
4430     {
4431 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4432     dbg(0,"+#+:enter\n");
4433     #endif
4434 zoff99 2 return this_->gui;
4435     }
4436    
4437     struct transformation *
4438     navit_get_trans(struct navit *this_)
4439     {
4440 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4441     dbg(0,"+#+:enter\n");
4442     #endif
4443 zoff99 2 return this_->trans;
4444     }
4445    
4446     struct route *
4447     navit_get_route(struct navit *this_)
4448     {
4449 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4450     dbg(0,"+#+:enter\n");
4451     #endif
4452 zoff99 2 return this_->route;
4453     }
4454    
4455     struct navigation *
4456     navit_get_navigation(struct navit *this_)
4457     {
4458 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4459     dbg(0,"+#+:enter\n");
4460     #endif
4461 zoff99 2 return this_->navigation;
4462     }
4463    
4464     struct displaylist *
4465     navit_get_displaylist(struct navit *this_)
4466     {
4467 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4468     dbg(0,"+#+:enter\n");
4469     #endif
4470 zoff99 2 return this_->displaylist;
4471     }
4472    
4473 zoff99 27 void navit_layout_switch(struct navit *n)
4474 zoff99 2 {
4475 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4476     dbg(0,"+#+:enter\n");
4477     #endif
4478 zoff99 27 ////DBG dbg(0,"EEnter\n");
4479 zoff99 2
4480 zoff99 27 int currTs = 0;
4481     struct attr iso8601_attr, geo_attr, valid_attr, layout_attr;
4482     double trise, tset, trise_actual;
4483     struct layout *l;
4484     int year, month, day;
4485    
4486     if (navit_get_attr(n, attr_layout, &layout_attr, NULL) != 1)
4487     {
4488     return; //No layout - nothing to switch
4489 zoff99 2 }
4490 zoff99 27 if (!n->vehicle)
4491 zoff99 2 return;
4492 zoff99 27 l = layout_attr.u.layout;
4493    
4494     if (l->dayname || l->nightname)
4495     {
4496     //Ok, we know that we have profile to switch
4497    
4498     //Check that we aren't calculating too fast
4499     if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601, &iso8601_attr, NULL) == 1)
4500     {
4501     currTs = iso8601_to_secs(iso8601_attr.u.str);
4502     // dbg(1, "currTs: %u:%u\n", currTs % 86400 / 3600, ((currTs % 86400) % 3600) / 60);
4503 zoff99 2 }
4504 zoff99 27 if (currTs - (n->prevTs) < 60)
4505     {
4506     //We've have to wait a little
4507     return;
4508 zoff99 2 }
4509 zoff99 27 if (sscanf(iso8601_attr.u.str, "%d-%02d-%02dT", &year, &month, &day) != 3)
4510     return;
4511     if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr, NULL) && valid_attr.u.num == attr_position_valid_invalid)
4512     {
4513     return; //No valid fix yet
4514     }
4515     if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo, &geo_attr, NULL) != 1)
4516     {
4517     //No position - no sun
4518     return;
4519     }
4520    
4521     //We calculate sunrise anyway, cause it is needed both for day and for night
4522     if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0)
4523     {
4524     //near the pole sun never rises/sets, so we should never switch profiles
4525     // dbg(1, "trise: %u:%u, sun never visible, never switch profile\n", HOURS(trise), MINUTES(trise));
4526     n->prevTs = currTs;
4527     return;
4528     }
4529    
4530     trise_actual = trise;
4531     // dbg(1, "trise: %u:%u\n", HOURS(trise), MINUTES(trise));
4532     if (l->dayname)
4533     {
4534    
4535     if ((HOURS(trise) * 60 + MINUTES(trise) == (currTs % 86400) / 60) || (n->prevTs == 0 && ((HOURS(trise) * 60 + MINUTES(trise) < (currTs % 86400) / 60))))
4536     {
4537     //The sun is rising now!
4538     if (strcmp(l->name, l->dayname))
4539     {
4540     navit_set_layout_by_name(n, l->dayname);
4541     }
4542     }
4543     }
4544     if (l->nightname)
4545     {
4546     if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0)
4547     {
4548     //near the pole sun never rises/sets, so we should never switch profiles
4549     // dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset), MINUTES(tset));
4550     n->prevTs = currTs;
4551     return;
4552     }
4553     // dbg(1, "tset: %u:%u\n", HOURS(tset), MINUTES(tset));
4554     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)))))
4555     {
4556     //Time to sleep
4557     if (strcmp(l->name, l->nightname))
4558     {
4559     navit_set_layout_by_name(n, l->nightname);
4560     }
4561     }
4562     }
4563    
4564     n->prevTs = currTs;
4565 zoff99 2 }
4566     }
4567    
4568 zoff99 27 int navit_set_vehicle_by_name(struct navit *n, const char *name)
4569 zoff99 2 {
4570 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4571     dbg(0,"+#+:enter\n");
4572     #endif
4573 zoff99 27 ////DBG dbg(0,"EEnter\n");
4574 zoff99 2
4575 zoff99 27 struct vehicle *v;
4576     struct attr_iter *iter;
4577     struct attr vehicle_attr, name_attr;
4578 zoff99 2
4579 zoff99 27 iter = navit_attr_iter_new();
4580 zoff99 2
4581 zoff99 27 while (navit_get_attr(n, attr_vehicle, &vehicle_attr, iter))
4582     {
4583     v = vehicle_attr.u.vehicle;
4584     vehicle_get_attr(v, attr_name, &name_attr, NULL);
4585     if (name_attr.type == attr_name)
4586     {
4587     if (!strcmp(name, name_attr.u.str))
4588     {
4589     navit_set_attr(n, &vehicle_attr);
4590 zoff99 2 navit_attr_iter_destroy(iter);
4591     return 1;
4592     }
4593     }
4594     }
4595 zoff99 27 navit_attr_iter_destroy(iter);
4596     return 0;
4597 zoff99 2 }
4598    
4599 zoff99 27 int navit_set_layout_by_name(struct navit *n, const char *name)
4600 zoff99 2 {
4601 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4602     dbg(0,"+#+:enter\n");
4603     #endif
4604 zoff99 27 ////DBG dbg(0,"EEnter\n");
4605 zoff99 2
4606 zoff99 27 struct layout *l;
4607     struct attr_iter iter;
4608     struct attr layout_attr;
4609 zoff99 2
4610 zoff99 27 iter.u.list = 0x00;
4611 zoff99 2
4612 zoff99 27 if (navit_get_attr(n, attr_layout, &layout_attr, &iter) != 1)
4613     {
4614     return 0; //No layouts - nothing to do
4615 zoff99 2 }
4616 zoff99 27 if (iter.u.list == NULL)
4617     {
4618     return 0;
4619     }
4620 zoff99 2
4621 zoff99 27 iter.u.list = g_list_first(iter.u.list);
4622    
4623     while (iter.u.list)
4624     {
4625     l = (struct layout*) iter.u.list->data;
4626     if (!strcmp(name, l->name))
4627     {
4628     layout_attr.u.layout = l;
4629     layout_attr.type = attr_layout;
4630     navit_set_attr(n, &layout_attr);
4631     iter.u.list = g_list_first(iter.u.list);
4632     return 1;
4633     }
4634     iter.u.list = g_list_next(iter.u.list);
4635     }
4636    
4637     iter.u.list = g_list_first(iter.u.list);
4638     return 0;
4639 zoff99 2 }
4640    
4641 zoff99 27 void navit_disable_suspend()
4642     {
4643 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4644     dbg(0,"+#+:enter\n");
4645     #endif
4646 zoff99 27 ////DBG dbg(0,"EEnter\n");
4647 zoff99 2
4648     gui_disable_suspend(global_navit->gui);
4649 zoff99 27 callback_list_call_attr_0(global_navit->attr_cbl, attr_unsuspend);
4650 zoff99 2 }
4651    
4652 zoff99 28
4653     /**
4654     * @brief Finds the nearest street to a given coordinate
4655     *
4656     * @param ms The mapset to search in for the street
4657     * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
4658     * @return The nearest street
4659     */
4660     char*
4661     navit_find_nearest_street(struct mapset *ms, struct pcoord *pc)
4662     {
4663     int max_dist = 1; // smallest rectangle possible
4664     int dist, mindist = 0, pos;
4665     struct mapset_handle *h;
4666     struct map *m;
4667     struct map_rect *mr;
4668     struct item *item;
4669     struct coord lp;
4670     struct street_data *sd;
4671     struct coord c;
4672     struct coord_geo g;
4673     struct map_selection sel;
4674     struct attr street_name_attr;
4675     char *street_name = NULL;
4676    
4677     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4678     dbg(0,"+#+:enter\n");
4679     #endif
4680    
4681     mindist = 10000; // start with small radius at the beginning!
4682     street_name = g_strdup_printf(" ");
4683    
4684     h = mapset_open(ms);
4685    
4686     if (!h)
4687     {
4688     return street_name;
4689     }
4690    
4691     while ((m = mapset_next(h, 0)))
4692     {
4693     c.x = pc->x;
4694     c.y = pc->y;
4695     if (map_projection(m) != pc->pro)
4696     {
4697     transform_to_geo(pc->pro, &c, &g);
4698     transform_from_geo(map_projection(m), &g, &c);
4699     }
4700    
4701     sel.next = NULL;
4702     sel.order = 18;
4703     sel.range.min = type_line;
4704     sel.range.max = type_area;
4705     sel.u.c_rect.lu.x = c.x - max_dist;
4706     sel.u.c_rect.lu.y = c.y + max_dist;
4707     sel.u.c_rect.rl.x = c.x + max_dist;
4708     sel.u.c_rect.rl.y = c.y - max_dist;
4709    
4710     mr = map_rect_new(m, &sel);
4711     if (!mr)
4712     {
4713     continue;
4714     }
4715    
4716     while ((item = map_rect_get_item(mr)))
4717     {
4718     if (item_get_default_flags(item->type))
4719     {
4720     sd = street_get_data(item);
4721     if (!sd)
4722     {
4723     continue;
4724     }
4725     //dbg(0,"6 sd x:%d sd y:%d count:%d\n", sd->c->x, sd->c->y, sd->count);
4726     //dbg(0,"6 c x:%d c y:%d\n", c.x, c.y);
4727     dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
4728     //dbg(0,"mindist:%d dist:%d\n", mindist, dist);
4729     if (dist < mindist)
4730     {
4731     //dbg(0,"6.a\n");
4732     mindist = dist;
4733    
4734     if (item_attr_get(item, attr_label, &street_name_attr))
4735     {
4736     if (street_name)
4737     {
4738     g_free(street_name);
4739     street_name = NULL;
4740     }
4741     street_name = g_strdup_printf("%s", street_name_attr.u.str);
4742     //dbg(0,"r1 %s\n", street_name);
4743     }
4744     /*
4745     else if (item_attr_get(&sd->item, attr_street_name, &street_name_attr))
4746     {
4747     if (street_name)
4748     {
4749     dbg(0,"6.b\n");
4750     g_free(street_name);
4751     street_name = NULL;
4752     dbg(0,"6.c\n");
4753     }
4754     street_name = g_strdup_printf("%s", street_name_attr.u.str);
4755     dbg(0,"r2 %s\n", street_name);
4756     }
4757     */
4758     else if (item_attr_get(item, attr_street_name, &street_name_attr))
4759     {
4760     if (street_name)
4761     {
4762     g_free(street_name);
4763     street_name = NULL;
4764     }
4765     street_name = g_strdup_printf("%s", street_name_attr.u.str);
4766     //dbg(0,"r3 %s\n", street_name);
4767     }
4768     else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
4769     {
4770     if (street_name)
4771     {
4772     g_free(street_name);
4773     street_name = NULL;
4774     }
4775     street_name = g_strdup_printf("%s", street_name_attr.u.str);
4776     //dbg(0,"r4 %s\n", street_name);
4777     }
4778     else
4779     {
4780     //if (street_name)
4781     //{
4782     // g_free(street_name);
4783     // street_name = NULL;
4784     //}
4785     //street_name = g_strdup_printf("---");
4786     }
4787     }
4788     street_data_free(sd);
4789     }
4790     }
4791    
4792     if (mr)
4793     {
4794     map_rect_destroy(mr);
4795     }
4796     }
4797     mapset_close(h);
4798     return street_name;
4799     }
4800    
4801    
4802     /**
4803     * @brief Finds the nearest street to a given coordinate
4804     *
4805     * @param ms The mapset to search in for the street
4806     * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
4807     * @return The nearest street (as a string of coords "0xFFF 0xFFF\n..." seperated by "\n")
4808     */
4809     char*
4810     navit_find_nearest_street_coords(struct mapset *ms, struct pcoord *pc)
4811     {
4812     int max_dist = 1; // smallest rectangle possible
4813     int dist, mindist = 0, pos;
4814     struct mapset_handle *h;
4815     struct map *m;
4816     struct map_rect *mr;
4817     struct item *item;
4818     struct coord lp;
4819     struct street_data *sd = NULL;
4820     struct street_data *sd_copy = NULL;
4821     struct coord c;
4822     struct coord_geo g;
4823     struct map_selection sel;
4824     int i;
4825     int found_good = 0;
4826     struct attr street_name_attr;
4827     char *street_coords = NULL;
4828     char *street_coords_tmp = NULL;
4829    
4830     #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4831     dbg(0,"+#+:enter\n");
4832     #endif
4833    
4834     mindist = 10000; // start with small radius at the beginning!
4835     street_coords = g_strdup_printf("");
4836    
4837     h = mapset_open(ms);
4838    
4839     if (!h)
4840     {
4841     return street_coords;
4842     }
4843    
4844     while ((m = mapset_next(h, 0)))
4845     {
4846     c.x = pc->x;
4847     c.y = pc->y;
4848     if (map_projection(m) != pc->pro)
4849     {
4850     transform_to_geo(pc->pro, &c, &g);
4851     transform_from_geo(map_projection(m), &g, &c);
4852     }
4853    
4854     sel.next = NULL;
4855     sel.order = 18;
4856     sel.range.min = type_line;
4857     sel.range.max = type_area;
4858     sel.u.c_rect.lu.x = c.x - max_dist;
4859     sel.u.c_rect.lu.y = c.y + max_dist;
4860     sel.u.c_rect.rl.x = c.x + max_dist;
4861     sel.u.c_rect.rl.y = c.y - max_dist;
4862    
4863     mr = map_rect_new(m, &sel);
4864     if (!mr)
4865     {
4866     continue;
4867     }
4868    
4869     while ((item = map_rect_get_item(mr)))
4870     {
4871     if (item_get_default_flags(item->type))
4872     {
4873     sd = street_get_data(item);
4874     if (!sd)
4875     {
4876     continue;
4877     }
4878     found_good = 0;
4879     dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
4880     if (dist < mindist)
4881     {
4882     mindist = dist;
4883    
4884     /*
4885     if (item_attr_get(item, attr_label, &street_name_attr))
4886     {
4887     found_good = 1;
4888     }
4889     else if (item_attr_get(item, attr_street_name, &street_name_attr))
4890     {
4891     found_good = 1;
4892     }
4893     else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
4894     {
4895     found_good = 1;
4896     }
4897     */
4898    
4899     // allow any street/line, so you can select streets without name also!
4900     found_good = 1;
4901     }
4902    
4903     if (found_good == 1)
4904     {
4905     if (sd_copy)
4906     {
4907     street_data_free(sd_copy);
4908     }
4909     sd_copy = street_data_dup(sd);
4910     }
4911     street_data_free(sd);
4912     }
4913     }
4914    
4915     if (mr)
4916     {
4917     map_rect_destroy(mr);
4918     }
4919     }
4920     mapset_close(h);
4921    
4922     if (sd_copy)
4923     {
4924     //struct coord ca[sd_copy->count];
4925     //item_coord_get(&sd_copy->item, ca, sd_copy->count);
4926    
4927     // dbg(0,"sd_copy->count=%d\n", sd_copy->count);
4928    
4929     for (i = 0; i < sd_copy->count; i++)
4930     {
4931     /*
4932     unsigned int x;
4933     unsigned int y;
4934     char *sign_x = "";
4935     char *sign_y = "";
4936    
4937     if ( c->x < 0 ) {
4938     x = -c->x;
4939     sign_x = "-";
4940     } else {
4941     x = c->x;
4942     }
4943     if ( c->y < 0 ) {
4944     y = -c->y;
4945     sign_y = "-";
4946     } else {
4947     y = c->y;
4948     }
4949     */
4950    
4951     street_coords_tmp = street_coords;
4952     if (street_coords == NULL)
4953     {
4954     street_coords = g_strdup_printf("0x%x 0x%x\n", sd_copy->c[i].x, sd_copy->c[i].y);
4955     }
4956     else
4957     {
4958     char *tmp2 = g_strdup_printf("0x%x 0x%x\n", sd_copy->c[i].x, sd_copy->c[i].y);
4959     street_coords = g_strconcat(street_coords_tmp, tmp2, NULL);
4960     g_free(street_coords_tmp);
4961     g_free(tmp2);
4962     }
4963     }
4964    
4965     street_data_free(sd_copy);
4966     }
4967    
4968     return street_coords;
4969     }
4970    
4971    
4972 zoff99 27 int navit_block(struct navit *this_, int block)
4973 zoff99 2 {
4974 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4975     dbg(0,"+#+:enter\n");
4976     #endif
4977 zoff99 27 ////DBG dbg(0,"EEnter\n");
4978 zoff99 2
4979 zoff99 27 if (block > 0)
4980     {
4981 zoff99 2 this_->blocked |= 1;
4982     if (graphics_draw_cancel(this_->gra, this_->displaylist))
4983     this_->blocked |= 2;
4984     return 0;
4985     }
4986 zoff99 27 if ((this_->blocked & 2) || block < 0)
4987     {
4988     this_->blocked = 0;
4989 zoff99 2 navit_draw(this_);
4990     return 1;
4991     }
4992 zoff99 27 this_->blocked = 0;
4993 zoff99 2 return 0;
4994     }
4995    
4996 zoff99 27 void navit_destroy(struct navit *this_)
4997 zoff99 2 {
4998 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4999     dbg(0,"+#+:enter\n");
5000     #endif
5001     dbg(0, "EEnter\n");
5002 zoff99 2
5003     struct mapset*ms;
5004     callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
5005    
5006 zoff99 27 // //DBG dbg(0,"enter");
5007 zoff99 2
5008     /* TODO: destroy objects contained in this_ */
5009     if (this_->vehicle)
5010 zoff99 28 {
5011 zoff99 2 vehicle_destroy(this_->vehicle->vehicle);
5012 zoff99 28 }
5013    
5014     /*
5015 zoff99 2 if (this_->bookmarks)
5016     {
5017 zoff99 27 dbg(0, "save position to file\n");
5018 zoff99 2 char *center_file = bookmarks_get_center_file(TRUE);
5019     bookmarks_write_center_to_file(this_->bookmarks, center_file);
5020     g_free(center_file);
5021     bookmarks_destroy(this_->bookmarks);
5022 zoff99 27 dbg(0, "save position to file -> ready\n");
5023 zoff99 2 }
5024 zoff99 28 */
5025    
5026     dbg(0, "ex 001\n");
5027 zoff99 2 callback_destroy(this_->nav_speech_cb);
5028 zoff99 28 dbg(0, "ex 002\n");
5029 zoff99 2 callback_destroy(this_->roadbook_callback);
5030 zoff99 28 dbg(0, "ex 003\n");
5031 zoff99 2 callback_destroy(this_->popup_callback);
5032 zoff99 28 dbg(0, "ex 004\n");
5033 zoff99 2 callback_destroy(this_->motion_timeout_callback);
5034 zoff99 28 dbg(0, "ex 005\n");
5035 zoff99 2 callback_destroy(this_->progress_cb);
5036 zoff99 28 dbg(0, "ex 006\n");
5037     /*
5038 zoff99 27 if (this_->gra)
5039     graphics_remove_callback(this_->gra, this_->resize_callback);
5040 zoff99 2 callback_destroy(this_->resize_callback);
5041 zoff99 28 */
5042     dbg(0, "ex 007\n");
5043     /*
5044 zoff99 27 if (this_->gra)
5045     graphics_remove_callback(this_->gra, this_->button_callback);
5046 zoff99 2 callback_destroy(this_->button_callback);
5047 zoff99 28 */
5048     dbg(0, "ex 008\n");
5049     /*
5050 zoff99 27 if (this_->gra)
5051     graphics_remove_callback(this_->gra, this_->motion_callback);
5052 zoff99 2 callback_destroy(this_->motion_callback);
5053 zoff99 28 */
5054     dbg(0, "ex 009\n");
5055 zoff99 27 if (this_->gra)
5056 zoff99 28 {
5057 zoff99 27 graphics_remove_callback(this_->gra, this_->predraw_callback);
5058 zoff99 28 }
5059 zoff99 2 callback_destroy(this_->predraw_callback);
5060 zoff99 28 dbg(0, "ex 010\n");
5061 zoff99 2 route_destroy(this_->route);
5062 zoff99 28 dbg(0, "ex 011\n");
5063 zoff99 2 ms = navit_get_mapset(this_);
5064 zoff99 28 dbg(0, "ex 012\n");
5065 zoff99 27 if (ms)
5066 zoff99 28 {
5067 zoff99 2 mapset_destroy(ms);
5068 zoff99 28 }
5069     dbg(0, "ex 013\n");
5070 zoff99 2 graphics_free(this_->gra);
5071 zoff99 28 dbg(0, "ex 014\n");
5072 zoff99 2 g_free(this_);
5073 zoff99 28 dbg(0, "ex 015\n");
5074 zoff99 2 }
5075    
5076     /** @} */

   
Visit the ZANavi Wiki