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

Contents of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki