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

Contents of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki