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

Contents of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 50 - (show annotations) (download)
Wed Jun 22 07:33:35 2016 UTC (7 years, 9 months ago) by zoff99
File MIME type: text/plain
File size: 172325 byte(s)
v2.0.51
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2014 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2009 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 #define _USE_MATH_DEFINES 1
40 #include "config.h"
41 #ifdef HAVE_UNISTD_H
42 #include <unistd.h>
43 #endif
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <signal.h>
47 #include <string.h>
48 #include <fcntl.h>
49 #include <glib.h>
50 #include <math.h>
51 #include <time.h>
52 #include "debug.h"
53 #include "navit.h"
54 #include "callback.h"
55 #include "gui.h"
56 #include "item.h"
57 #include "projection.h"
58 #include "map.h"
59 #include "mapset.h"
60 #include "main.h"
61 #include "coord.h"
62 #include "point.h"
63 #include "transform.h"
64 #include "param.h"
65 #include "menu.h"
66 #include "graphics.h"
67 #include "popup.h"
68 #include "data_window.h"
69 #include "route.h"
70 #include "navigation.h"
71 #include "speech.h"
72 #include "track.h"
73 #include "vehicle.h"
74 #include "layout.h"
75 #include "log.h"
76 #include "attr.h"
77 #include "event.h"
78 #include "file.h"
79 #include "profile.h"
80 #include "command.h"
81 #include "navit_nls.h"
82 #include "map.h"
83 #include "util.h"
84 #include "messages.h"
85 #include "vehicleprofile.h"
86 #include "sunriset.h"
87 #include "bookmarks.h"
88 #include "map.h"
89 #ifdef HAVE_API_WIN32_BASE
90 #include <windows.h>
91 #include "util.h"
92 #endif
93 #ifdef HAVE_API_WIN32_CE
94 #include "libc.h"
95 #endif
96
97
98
99
100
101
102
103
104
105
106
107
108
109 // #define NAVIT_FUNC_CALLS_DEBUG_PRINT 1
110
111
112 // --------------- debug function calls ------------------
113 // --------------- debug function calls ------------------
114 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
115 #undef return2
116 #define return2 dbg_func(0, global_func_indent_counter, "return(%d)\n", __LINE__);global_func_indent_counter--;return
117
118 #define __F_START__ global_func_indent_counter++;dbg_func(0, global_func_indent_counter, "enter\n");
119 #define __F_END__ dbg_func(0, global_func_indent_counter, "leave\n");global_func_indent_counter--;
120 #else
121 #undef return2
122 #define return2 return
123
124 #define __F_START__
125 #define __F_END__
126 #endif
127 // --------------- debug function calls ------------------
128 // --------------- debug function calls ------------------
129
130
131
132
133
134
135 /**
136 * @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
137 * @{
138 */
139
140 struct gui *main_loop_gui;
141
142 struct attr_iter
143 {
144 union
145 {
146 GList *list;
147 struct mapset_handle *mapset_handle;
148 } u;
149 };
150
151 static int dist_to_street = 100000;
152
153 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
154 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
155 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
156 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
157 static void navit_cmd_zoom_to_route(struct navit *this);
158 static void navit_cmd_set_center_cursor(struct navit *this_);
159 static void navit_cmd_announcer_toggle(struct navit *this_);
160 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
161
162 int allow_gui_internal = 0; // disable old GUI internal. it will not work anymore!
163 int routing_mode = 0;
164 int MYSTERY_SPEED = 2;
165 int offline_search_filter_duplicates = 0;
166 int offline_search_break_searching = 0;
167 char *navit_maps_dir;
168 char *navit_share_dir;
169 char *navit_data_dir;
170 int cancel_drawing_global = 0;
171 int global_speak_streetnames = 1;
172 int allow_large_mapfiles = 1; // allow the use of large (>2GB) mapfiles // -> value unused for now
173 int cache_size_file = 1024 * 1024 * 10; // default value was: 20971520 (~20 MB)
174 int draw_polylines_fast = 0; // default: 0
175 int limit_order_corrected = 4; // remain at this order level for drawing streets etc.
176 int shift_order = 0; // shift order level (for displaying objects) by this values (should only be bigger than zero!!)
177 int global_search_street_size_factor = 1; // make search radius for streets bigger (not used on indexsearch)
178 int disable_map_drawing = 0; // dont draw the map and dont read data from file (hopefully saving resources)
179 int hold_drawing = 0; // 0 -> draw normal , 1 -> dont do any drawing
180 int global_stop_demo_vehicle = 0; // 0 -> demo vehicle can move, 1 -> demo vehicle stands still
181 int global_show_route_rectangles = 0; // 1 -> show route rectangles, 0 -> dont show route rectangles
182 int global_traffic_light_delay = 0; // 0 -> dont account for traffic lights in route, >0 -> calc a delay for each traffic light
183 int global_clinedrawing_active = 0; // 0 -> java line drawing, 1 -> C line drawing
184 int global_draw_multipolygons = 1; // 0 -> dont draw lines and triangles from multipolygons, 1 -> draw them
185 int global_have_dpi_value = 240;
186 float global_dpi_factor = 1.0f;
187 int global_order_level_for_fast_draw = 13;
188 int global_show_english_labels = 1; // 0 -> only "normal" names/labels shown on map
189 // 1 -> show "normal, english"
190 // 2 -> show only "english" labels
191 int global_routing_engine = 0; // 0 -> offline ZANavi, 1 -> online OSRM
192 float global_overspill_factor = 1.0f; // overspill factor from Java code
193 int global_avoid_sharp_turns_flag = 0; // 0 -> normal routing, 1 -> try to avoid sharp turns / u-turns
194 int global_avoid_sharp_turns_min_angle = 40; // at what angle is it a sharp turn?
195 int global_avoid_sharp_turns_min_penalty = 1000; // routing penalty for sharp turns (DEFAULT = 1000)
196
197 int global_search_radius_for_housenumbers = 300; // search this far around street-coord to find potential housenumbers for this street
198 int global_vehicle_profile = 0; // 0 -> car, 1 -> bicycle, 2 -> bicylce no one-ways
199 int global_cycle_lanes_prio = 5; // how much prio weight will be subtracted from prio weight if a road has a cycle lane (painted white line for bicycles)
200 int global_cycle_track_prio = 1; // unused for now!!
201
202 double global_v_pos_lat = 0.0; // global vehicle position
203 double global_v_pos_lng = 0.0; // global vehicle position
204 double global_v_pos_dir = 0.0; // global vehicle direction
205
206 struct coord global_vehicle_pos_onscreen;
207 struct coord_geo global_last_vehicle_pos_geo;
208 double ggggg_lat = 0;
209 double ggggg_lon = 0;
210
211
212 int global_demo_vehicle = 0;
213 int global_demo_vehicle_short_switch = 0;
214 long global_last_spoken = -1;
215 long global_last_spoken_base = 0;
216 float global_road_speed_factor = 0.85f;
217
218 float global_level0_announcement = 5.0f;
219 float global_level1_announcement = 11.0f;
220 float global_level2_announcement = 24.3f;
221 float global_levelx_announcement_factor = 6.0f / 4.0f;
222
223 float global_b_level0_announcement = 4.8f;
224 float global_b_level1_announcement = 11.1f;
225 float global_b_level2_announcement = 21.1f;
226 float global_b_levelx_announcement_factor = 6.0f / 4.0f;
227
228 int global_driven_away_from_route = 0;
229
230 int global_enhance_cycleway = 0;
231 int global_tracking_show_real_gps_pos = 0;
232 int global_show_maps_debug_view = 0;
233 int global_cancel_preview_map_drawing = 0;
234
235 GList *global_all_cbs = NULL;
236
237 struct coord global_debug_route_seg_winner_start;
238 struct coord global_debug_route_seg_winner_end;
239 struct coord global_debug_seg_winner_start;
240 struct coord global_debug_seg_winner_end;
241 struct coord global_debug_route_seg_winner_p_start;
242 struct coord global_debug_route_seg_winner_p_end;
243 struct coord global_debug_seg_winner_p_start;
244 struct coord global_debug_seg_route_start;
245 struct coord global_debug_seg_route_end;
246 struct coord global_debug_trlast_start;
247 struct coord global_debug_trlast_end;
248
249 struct coord *global_debug_coord_list;
250 int global_debug_coord_list_items = 0;
251 int global_has_gpsfix = 0;
252 int global_pos_is_underground = 0;
253
254
255 int global_sharp_turn_list_count = 0;
256 struct global_sharp_turn *global_sharp_turn_list = NULL;
257
258 int global_freetext_list_count = 0;
259 struct global_freetext *global_freetext_list = NULL;
260
261
262 GHashTable *global_transform_hash = NULL;
263 GHashTable *global_transform_hash2 = NULL;
264
265 long long draw_lines_count_2 = 0;
266 long long draw_lines_count_3 = 0;
267 long long draw_lines_count_4 = 0;
268 int poi_on_map_count = 0;
269 int label_on_map_count = 0;
270 int label_district_on_map_count = 0;
271 int label_major_on_map_count = 0;
272 int poi_icon_on_map_count = 0;
273
274 int mapdraw_time[11 + 5]; // time to draw map on screen (in 1/1000 of a second) [add 5, just in case we inc it 2 times at same time because of threads]
275 int cur_mapdraw_time_index = 0;
276
277 int route_status_previous = 0;
278 long long global_route_memory_size = 0;
279 int global_old_vehicle_speed = -1;
280 int global_old_vehicle_speed_for_autozoom = -1;
281
282 void navit_add_mapset(struct navit *this_, struct mapset *ms)
283 {
284 this_->mapsets = g_list_append(this_->mapsets, ms);
285 }
286
287 struct mapset *
288 navit_get_mapset(struct navit *this_)
289 {
290 if (this_->mapsets)
291 {
292 return this_->mapsets->data;
293 }
294 else
295 {
296 //DBG dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
297 }
298 return NULL;
299 }
300
301 struct tracking *
302 navit_get_tracking(struct navit *this_)
303 {
304 return this_->tracking;
305 }
306
307 /**
308 * @brief Get the user data directory.
309 * @param[in] create - create the directory if it does not exist
310 *
311 * @return char * to the data directory string.
312 *
313 * returns the directory used to store user data files (center.txt,
314 * destination.txt, bookmark.txt, ...)
315 *
316 */
317 char*
318 navit_get_user_data_directory(int create)
319 {
320 char *dir;
321 // dir = getenv("NAVIT_USER_DATADIR");
322 dir = navit_share_dir;
323 if (create && !file_exists(dir))
324 {
325 //DBG dbg(0, "creating dir %s\n", dir);
326 if (file_mkdir(dir, 0))
327 {
328 //DBG dbg(0, "failed creating dir %s\n", dir);
329 return NULL;
330 }
331 }
332 return dir;
333 } /* end: navit_get_user_data_directory(gboolean create) */
334
335 void navit_draw_async(struct navit *this_, int async)
336 {
337 __F_START__
338
339 //dbg(0,"EEnter this_->blocked=%d\n",this_->blocked);
340 if (this_->blocked)
341 {
342 this_->blocked |= 2;
343 //dbg(0,"set this_->blocked=%d\n",this_->blocked);
344 // dbg(0,"DO__DRAW:ndasync return 001\n");
345 return2;
346 }
347
348 transform_setup_source_rect(this_->trans);
349 //dbg(0,"call graphics_draw\n");
350
351 // dbg(0,"DO__DRAW:gras_draw call\n");
352 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags | 1);
353 // dbg(0,"DO__DRAW:ndasync leave\n");
354
355 __F_END__
356 }
357
358 void navit_draw(struct navit *this_)
359 {
360 __F_START__
361
362 //dbg(0,"EEnter this_->ready=%d\n",this_->ready);
363 if (this_->ready == 3)
364 {
365 // dbg(0,"navit_draw_async_001\n");
366 // dbg(0,"DO__DRAW:navit_draw_async call\n");
367 navit_draw_async(this_, 0);
368 }
369
370 __F_END__
371 }
372
373 int navit_get_ready(struct navit *this_)
374 {
375 return this_->ready;
376 }
377
378 // UNUSED -----
379 // UNUSED -----
380 void navit_draw_displaylist(struct navit *this_)
381 {
382 if (this_->ready == 3)
383 {
384 // //DBG dbg(0,"call graphics_displaylist_draw 2")
385 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags | 1);
386 }
387 }
388
389 static void navit_map_progress(struct navit *this_)
390 {
391 struct map *map;
392 struct mapset *ms;
393 struct mapset_handle *msh;
394 struct attr attr;
395 struct point p;
396 if (this_->ready != 3)
397 return;
398 p.x = 10;
399 p.y = 32;
400
401 ms = this_->mapsets->data;
402 msh = mapset_open(ms);
403 while (msh && (map = mapset_next(msh, 0)))
404 {
405 if (map_get_attr(map, attr_progress, &attr, NULL))
406 {
407 char *str = g_strdup_printf("%s ", attr.u.str);
408 graphics_draw_mode(this_->gra, draw_mode_begin);
409 graphics_draw_text_std(this_->gra, 16, str, &p);
410 g_free(str);
411 p.y += 32;
412 graphics_draw_mode(this_->gra, draw_mode_end);
413 }
414 }
415 mapset_close(msh);
416 }
417
418 static void navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
419 {
420 __F_START__
421
422 int updated;
423
424 if ((this_->route) && (this_->route->route_status_was_updated == 1))
425 {
426 this_->route->route_status_was_updated = 0;
427 // send route_status to java
428 #ifdef HAVE_API_ANDROID
429 android_return_generic_int(1, this_->route->route_status);
430 #endif
431 }
432
433 if (attr->type != attr_route_status)
434 {
435 return2;
436 }
437
438 updated = attr->u.num;
439
440 if (this_->ready != 3)
441 {
442 return2;
443 }
444
445 if (updated != route_status_path_done_new)
446 {
447 return2;
448 }
449
450 if (this_->vehicle)
451 {
452 if (this_->vehicle->follow_curr == 1)
453 {
454 ////DBG dbg(0,"disabled -> we want redraw!!\n");
455 // return2;
456 }
457
458 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
459 {
460 this_->vehicle->follow_curr = this_->vehicle->follow;
461 }
462 }
463
464 // *++*-- DISABLED --*++* // navit_draw(this_);
465
466 __F_END__
467 }
468
469 void navit_handle_resize(struct navit *this_, int w, int h)
470 {
471 __F_START__
472
473 struct map_selection sel;
474
475 int callback = (this_->ready == 1);
476 this_->ready = this_->ready | 2;
477
478 memset(&sel, 0, sizeof(sel));
479
480 this_->w = w;
481 this_->h = h;
482 sel.u.p_rect.rl.x = w;
483 sel.u.p_rect.rl.y = h;
484 transform_set_screen_selection(this_->trans, &sel);
485 graphics_init(this_->gra);
486 graphics_set_rect(this_->gra, &sel.u.p_rect);
487
488 if (callback)
489 {
490 // HINT: this triggers all the OSD drawing (next turn, ETA, etc.)
491 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
492 }
493
494 if (this_->ready == 3)
495 {
496 // dbg(0,"navit_draw_async_007\n");
497 navit_draw_async(this_, 0);
498 }
499
500 __F_END__
501 }
502
503 void navit_resize(void *data, int w, int h)
504 {
505 struct navit *this = data;
506 if (!this->ignore_graphics_events)
507 {
508 //DBG dbg(0,"11\n");
509 navit_handle_resize(this, w, h);
510 }
511 }
512
513 int navit_get_width(struct navit *this_)
514 {
515 return this_->w;
516 }
517
518 int navit_get_height(struct navit *this_)
519 {
520 return this_->h;
521 }
522
523 static void navit_popup(void *data)
524 {
525 struct navit *this_ = data;
526 popup(this_, 1, &this_->pressed);
527 this_->button_timeout = NULL;
528 this_->popped = 1;
529 }
530
531 int navit_ignore_button(struct navit *this_)
532 {
533 if (this_->ignore_button)
534 return 1;
535
536 this_->ignore_button = 1;
537 return 0;
538 }
539
540 void navit_ignore_graphics_events(struct navit *this_, int ignore)
541 {
542 this_->ignore_graphics_events = ignore;
543 }
544
545 void update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
546 {
547 struct coord co, cn;
548 struct coord c, *cp;
549 int yaw;
550 double angleo, anglen;
551
552 if (!transform_reverse(tr, old, &co))
553 return;
554 if (rot)
555 {
556 angleo = atan2(old->y - rot->y, old->x - rot->x) * 180 / M_PI;
557 anglen = atan2(new->y - rot->y, new->x - rot->x) * 180 / M_PI;
558 yaw = transform_get_yaw(tr) + angleo - anglen;
559 transform_set_yaw(tr, yaw % 360);
560 }
561 if (!transform_reverse(tr, new, &cn))
562 return;
563 cp = transform_get_center(tr);
564 c.x = cp->x + co.x - cn.x;
565 c.y = cp->y + co.y - cn.y;
566 // dbg(1, "from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
567 transform_set_center(tr, &c);
568 }
569
570 void navit_set_timeout(struct navit *this_)
571 {
572 // --------- DISABLE -----------
573 return;
574 // --------- DISABLE -----------
575 }
576
577 int navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
578 {
579 int border = 16;
580
581 // dbg(1, "enter %d %d (ignore %d)\n", pressed, button, this_->ignore_button);
582 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
583 if (this_->ignore_button)
584 {
585 this_->ignore_button = 0;
586 return 0;
587 }
588 if (pressed)
589 {
590 this_->pressed = *p;
591 this_->last = *p;
592 this_->zoomed = 0;
593 if (button == 1)
594 {
595 this_->button_pressed = 1;
596 this_->moved = 0;
597 this_->popped = 0;
598 // ---- DISBALED --------
599 /*
600 if (popup_callback)
601 this_->button_timeout = event_add_timeout(500, 0, popup_callback);
602 */
603 }
604 if (button == 2)
605 navit_set_center_screen(this_, p, 1);
606 if (button == 3)
607 popup(this_, button, p);
608 if (button == 4 && this_->use_mousewheel)
609 {
610 this_->zoomed = 1;
611 navit_zoom_in(this_, 2, p);
612 }
613 if (button == 5 && this_->use_mousewheel)
614 {
615 this_->zoomed = 1;
616 navit_zoom_out(this_, 2, p);
617 }
618 }
619 else
620 {
621
622 this_->button_pressed = 0;
623 if (this_->button_timeout)
624 {
625 event_remove_timeout(this_->button_timeout);
626 this_->button_timeout = NULL;
627 if (!this_->moved && !transform_within_border(this_->trans, p, border))
628 {
629 navit_set_center_screen(this_, p, !this_->zoomed);
630 }
631 }
632 if (this_->motion_timeout)
633 {
634 event_remove_timeout(this_->motion_timeout);
635 this_->motion_timeout = NULL;
636 }
637 if (this_->moved)
638 {
639 struct point pr;
640 pr.x = this_->w / 2;
641 pr.y = this_->h;
642 #if 0
643 update_transformation(this_->trans, &this_->pressed, p, &pr);
644 #else
645 update_transformation(this_->trans, &this_->pressed, p, NULL);
646 #endif
647 graphics_draw_drag(this_->gra, NULL);
648 transform_copy(this_->trans, this_->trans_cursor);
649 graphics_overlay_disable(this_->gra, 0);
650 if (!this_->zoomed)
651 {
652 navit_set_timeout(this_);
653 }
654 navit_draw(this_);
655 }
656 else
657 return 1;
658 }
659 return 0;
660 }
661
662 static void navit_button(void *data, int pressed, int button, struct point *p)
663 {
664 struct navit *this = data;
665 // dbg(1, "enter %d %d ignore %d\n", pressed, button, this->ignore_graphics_events);
666 if (!this->ignore_graphics_events)
667 {
668 if (!this->popup_callback)
669 {
670 this->popup_callback = callback_new_1(callback_cast(navit_popup), this);
671 callback_add_names(this->popup_callback, "navit_button", "navit_popup");
672 }
673 navit_handle_button(this, pressed, button, p, this->popup_callback);
674 }
675 }
676
677 // UNUSED ---
678 // UNUSED ---
679 static void navit_motion_timeout(struct navit *this_)
680 {
681 int dx, dy;
682
683 if (this_->drag_bitmap)
684 {
685 struct point point;
686 point.x = (this_->current.x - this_->pressed.x);
687 point.y = (this_->current.y - this_->pressed.y);
688 if (graphics_draw_drag(this_->gra, &point))
689 {
690 graphics_overlay_disable(this_->gra, 1);
691 graphics_draw_mode(this_->gra, draw_mode_end);
692 this_->moved = 1;
693 this_->motion_timeout = NULL;
694 return;
695 }
696 }
697 dx = (this_->current.x - this_->last.x);
698 dy = (this_->current.y - this_->last.y);
699 if (dx || dy)
700 {
701 struct transformation *tr;
702 struct point pr;
703 this_->last = this_->current;
704 graphics_overlay_disable(this_->gra, 1);
705 tr = transform_dup(this_->trans);
706 pr.x = this_->w / 2;
707 pr.y = this_->h;
708 #if 0
709 update_transformation(tr, &this_->pressed, &this_->current, &pr);
710 #else
711 update_transformation(tr, &this_->pressed, &this_->current, NULL);
712 #endif
713 #if 0
714 graphics_displaylist_move(this_->displaylist, dx, dy);
715 #endif
716 graphics_draw_cancel(this_->gra, this_->displaylist); // --> calls "do_draw" normally
717 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
718
719 transform_destroy(tr);
720 this_->moved = 1;
721 }
722 this_->motion_timeout = NULL;
723 return;
724 }
725
726 void navit_handle_motion(struct navit *this_, struct point *p)
727 {
728 __F_START__
729
730 int dx, dy;
731
732 if (this_->button_pressed && !this_->popped)
733 {
734 dx = (p->x - this_->pressed.x);
735 dy = (p->y - this_->pressed.y);
736 if (dx < -8 || dx > 8 || dy < -8 || dy > 8)
737 {
738 this_->moved = 1;
739 if (this_->button_timeout)
740 {
741 event_remove_timeout(this_->button_timeout);
742 this_->button_timeout = NULL;
743 }
744 this_->current = *p;
745
746 // -------- DISABLE -------
747 // -------- DISABLE -------
748 // -------- DISABLE -------
749 /*
750 if (!this_->motion_timeout_callback)
751 this_->motion_timeout_callback = callback_new_1(callback_cast(navit_motion_timeout), this_);
752 if (!this_->motion_timeout)
753 this_->motion_timeout = event_add_timeout(100, 0, this_->motion_timeout_callback);
754 */
755 // -------- DISABLE -------
756 // -------- DISABLE -------
757 // -------- DISABLE -------
758 }
759 }
760
761 __F_END__
762 }
763
764 void navit_motion(void *data, struct point *p)
765 {
766 struct navit *this = data;
767 if (!this->ignore_graphics_events)
768 {
769 navit_handle_motion(this, p);
770 }
771 }
772
773 void navit_predraw(struct navit *this_)
774 {
775 __F_START__
776
777 GList *l;
778 struct navit_vehicle *nv;
779 transform_copy(this_->trans, this_->trans_cursor);
780 l = this_->vehicles;
781 while (l)
782 {
783 nv = l->data;
784 ////DBG dbg(0,"* here *\n");
785 ////DBG dbg(0,"vehicle_draw_004\n");
786 navit_vehicle_draw(this_, nv, NULL);
787 l = g_list_next(l);
788 }
789
790 __F_END__
791 }
792
793 static void navit_scale(struct navit *this_, long scale, struct point *p, int draw)
794 {
795 struct coord c1, c2, *center;
796
797 if (scale < this_->zoom_min)
798 {
799 scale = this_->zoom_min;
800 }
801
802 if (scale > this_->zoom_max)
803 {
804 scale = this_->zoom_max;
805 }
806
807 // return scale value to android
808 #ifdef HAVE_API_ANDROID
809 android_return_generic_int(3, (int)scale);
810 #endif
811
812 //dbg(0, "zoom to scale=%d", (int)scale);
813
814
815 if (p)
816 {
817 transform_reverse(this_->trans, p, &c1);
818 }
819
820 transform_set_scale(this_->trans, scale);
821
822 if (p)
823 {
824 transform_reverse(this_->trans, p, &c2);
825 center = transform_center(this_->trans);
826 center->x += c1.x - c2.x;
827 center->y += c1.y - c2.y;
828 }
829
830 //DBG dbg(0,"aa331\n");
831
832 if (draw)
833 {
834 navit_draw(this_);
835 }
836
837 //DBG dbg(0,"leave\n");
838 }
839
840 /**
841 * @brief Automatically adjusts zoom level
842 *
843 * This function automatically adjusts the current
844 * zoom level according to the current speed.
845 *
846 * @param this_ The navit struct
847 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
848 * @param speed The vehicles speed in meters per second
849 * @param dir The direction into which the vehicle moves
850 */
851 static long navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw, int *lold, int *lnew)
852 {
853 struct point pc;
854 int w, h;
855 float distance;
856 long new_scale;
857 long scale;
858
859 if (!this_->autozoom_active)
860 {
861 return -1;
862 }
863
864 if (global_old_vehicle_speed < 1)
865 {
866 return -1;
867 }
868
869 // --- no autozoom at slow speed ---
870 //if (speed < 20)
871 //{
872 // return -1;
873 //}
874 // --- no autozoom at slow speed ---
875
876
877
878 // this is kaputt!!
879 #if 0
880 if (global_old_vehicle_speed_for_autozoom > 0)
881 {
882 if (abs(global_old_vehicle_speed_for_autozoom - speed) < 10)
883 {
884 // change in speed not significant
885 return;
886 }
887 }
888 global_old_vehicle_speed_for_autozoom = speed;
889 #endif
890 // this is kaputt!!
891
892
893
894 // distance = speed * this_->autozoom_secs;
895 if (speed > 109)
896 {
897 distance = (float)speed * 16.4f;
898 }
899 else if (speed > 75)
900 {
901 distance = (float)speed * 10.3f;
902 }
903 else
904 {
905 distance = (float)speed * 7.3f;
906 }
907
908 // dbg(0,"autozoom: dis1=%f\n", distance);
909
910 // if overspill > 1 ?
911 if (global_overspill_factor > 1.0f)
912 {
913 distance = distance * global_overspill_factor;
914 }
915
916
917 // scale = this_->trans->scale * 16;
918 scale = transform_get_scale(this_->trans);
919
920 transform_get_size(this_->trans, &w, &h);
921 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
922
923 #if 0
924 // dbg(0,"autozoom:ovrspll=%f\n", global_overspill_factor);
925 dbg(0,"autozoom: dist=%f\n", distance);
926 dbg(0,"autozoom: scale=%d\n", (int)scale);
927 dbg(0,"autozoom:o speed=%d\n", speed);
928 dbg(0,"autozoom:n speed=%d\n", global_old_vehicle_speed);
929 #endif
930
931 /* We make sure that the point we want to see is within a certain range
932 * around the vehicle. The radius of this circle is the size of the
933 * screen. This doesn't necessarily mean the point is visible because of
934 * perspective etc. Quite rough, but should be enough. */
935
936 if (w > h)
937 {
938 new_scale = (long)( (distance / (float)h) * 16);
939 }
940 else
941 {
942 new_scale = (long)( (distance / (float)w) * 16);
943 }
944
945 if (new_scale < this_->autozoom_min)
946 {
947 new_scale = this_->autozoom_min;
948 }
949
950 #if 0
951 dbg(0,"autozoom:w n.scale=%d o.scale=%d\n", (int)new_scale, (int)scale);
952 #endif
953
954 //if (abs(new_scale - scale) < 2)
955 //{
956 // return; // Smoothing
957 //}
958
959 if (new_scale > scale)
960 {
961 // zoom out
962 if (new_scale > (scale + 20))
963 {
964 scale = scale + 10;
965 }
966 else if (new_scale > (scale + 5))
967 {
968 scale = scale + 4;
969 }
970 else
971 {
972 scale = scale + 1;
973 }
974 }
975 else if (new_scale < scale)
976 {
977 // zoom in
978 if ((new_scale + 220500) < scale) // lower threshold
979 {
980 scale = (int)((float)scale * 0.85f);
981 // dbg(0,"autozoom:step 8\n");
982 }
983 else if ((new_scale + 130500) < scale) // lower threshold
984 {
985 scale = (int)((float)scale * 0.85f);
986 // dbg(0,"autozoom:step 7\n");
987 }
988 else if ((new_scale + 4000) < scale) // lower threshold
989 {
990 scale = (int)((float)scale * 0.85f);
991 // dbg(0,"autozoom:step 6\n");
992 }
993 else if ((new_scale + 1850) < scale) // lower threshold
994 {
995 // scale = scale - 1000;
996 scale = (int)((float)scale * 0.85f);
997 // dbg(0,"autozoom:step 5\n");
998 }
999 else if ((new_scale + 90) < scale) // lower threshold
1000 {
1001 // scale = scale - 200;
1002 scale = (int)((float)scale * 0.85f);
1003 // dbg(0,"autozoom:step 4\n");
1004 }
1005 else if ((new_scale + 25) < scale) // lower threshold
1006 {
1007 scale = scale - 8;
1008 // dbg(0,"autozoom:step 3\n");
1009 }
1010 else if ((new_scale + 7) < scale) // lower threshold
1011 {
1012 scale = scale - 2;
1013 // dbg(0,"autozoom:step 2\n");
1014 }
1015 else
1016 {
1017 scale = scale - 1;
1018 // dbg(0,"autozoom:step 1\n");
1019 }
1020 }
1021 else
1022 {
1023 // no change
1024 return -1;
1025 }
1026
1027 // dbg(0,"autozoom:n scale=%d\n", (int)scale);
1028
1029 // OLD zoom is applied here -------------------------
1030 struct coord c_left;
1031 struct point p_left;
1032 p_left.x = 0;
1033 p_left.y = 200;
1034 transform_reverse(this_->trans, &p_left, &c_left);
1035 struct coord c_right;
1036 struct point p_right;
1037 p_right.x = 200;
1038 p_right.y = 200;
1039 transform_reverse(this_->trans, &p_right, &c_right);
1040 // OLD zoom is applied here -------------------------
1041
1042
1043 if (scale >= this_->autozoom_min)
1044 {
1045 navit_scale(this_, (long) scale, &pc, 0);
1046 }
1047 else
1048 {
1049 //if (scale != this_->autozoom_min)
1050 //{
1051 navit_scale(this_, this_->autozoom_min, &pc, 0);
1052 //}
1053 }
1054
1055 // new zoom is applied here already -----------------
1056 struct point p_new_left;
1057 transform(global_navit->trans, transform_get_projection(this_->trans), &c_left, &p_new_left, 1, 0, 0, NULL);
1058 struct point p_new_right;
1059 transform(global_navit->trans, transform_get_projection(this_->trans), &c_right, &p_new_right, 1, 0, 0, NULL);
1060
1061 *lold = 200;
1062 *lnew = abs(p_new_right.x - p_new_left.x);
1063 // new zoom is applied here already -----------------
1064
1065
1066 // return new scale value
1067 return scale;
1068 }
1069
1070 /**
1071 * Change the current zoom level, zooming closer to the ground
1072 *
1073 * @param navit The navit instance
1074 * @param factor The zoom factor, usually 2
1075 * @param p The invariant point (if set to NULL, default to center)
1076 * @returns nothing
1077 */
1078 void navit_zoom_in(struct navit *this_, int factor, struct point *p)
1079 {
1080 long scale = transform_get_scale(this_->trans) / factor;
1081 if (scale < 1)
1082 {
1083 scale = 1;
1084 }
1085 ////DBG dbg(0,"zoom in -> scale=%d",scale);
1086 navit_scale(this_, scale, p, 1);
1087 }
1088
1089 /**
1090 * Change the current zoom level
1091 *
1092 * @param navit The navit instance
1093 * @param factor The zoom factor, usually 2
1094 * @param p The invariant point (if set to NULL, default to center)
1095 * @returns nothing
1096 */
1097 void navit_zoom_out(struct navit *this_, int factor, struct point *p)
1098 {
1099 long scale = transform_get_scale(this_->trans) * factor;
1100 ////DBG dbg(0,"zoom out -> scale=%d",scale);
1101 navit_scale(this_, scale, p, 1);
1102 }
1103
1104 int navit_get_cur_pnt(struct navit *this_, struct point *p)
1105 {
1106 return navit_get_cursor_pnt(this_, p, 0, NULL);
1107 }
1108
1109 void navit_zoom_in_cursor(struct navit *this_, int factor)
1110 {
1111 struct point p;
1112 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL))
1113 {
1114 navit_zoom_in(this_, factor, &p);
1115 this_->vehicle->follow_curr = this_->vehicle->follow;
1116 }
1117 else
1118 {
1119 navit_zoom_in(this_, factor, NULL);
1120 }
1121 }
1122
1123 void navit_zoom_to_scale_no_draw(struct navit *this_, int new_scale)
1124 {
1125 long scale = transform_get_scale(this_->trans);
1126 long new_scale_long = new_scale;
1127
1128 // only do something if scale changed!
1129 if (scale != new_scale_long)
1130 {
1131 navit_scale(this_, new_scale_long, NULL, 0);
1132 }
1133 }
1134
1135
1136 void navit_zoom_to_scale(struct navit *this_, int new_scale)
1137 {
1138 long scale = transform_get_scale(this_->trans);
1139 long new_scale_long = new_scale;
1140 //DBG dbg(0,"zoom to scale -> old scale=%d",scale);
1141 //DBG dbg(0,"zoom to scale -> want scale=%d",new_scale_long);
1142
1143 // only do something if scale changed!
1144 if (scale != new_scale_long)
1145 {
1146 navit_scale(this_, new_scale_long, NULL, 1);
1147 }
1148 }
1149
1150 void navit_zoom_to_scale_with_center_point(struct navit *this_, int new_scale, struct point *p)
1151 {
1152 long scale = transform_get_scale(this_->trans);
1153 long new_scale_long = new_scale;
1154
1155 //dbg(0, "zoom to scale -> old scale=%d", scale);
1156 //dbg(0, "zoom to scale -> want scale=%d", new_scale_long);
1157
1158 // only do something if scale changed!
1159 if (scale != new_scale_long)
1160 {
1161 navit_scale(this_, new_scale_long, p, 1);
1162 }
1163 }
1164
1165 void navit_zoom_out_cursor(struct navit *this_, int factor)
1166 {
1167 struct point p;
1168 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL))
1169 {
1170 navit_zoom_out(this_, 2, &p);
1171 this_->vehicle->follow_curr = this_->vehicle->follow;
1172 }
1173 else
1174 {
1175 navit_zoom_out(this_, 2, NULL);
1176 }
1177 }
1178
1179 static int navit_cmd_zoom_in(struct navit *this_)
1180 {
1181 navit_zoom_in_cursor(this_, 2);
1182 return 0;
1183 }
1184
1185 static int navit_cmd_zoom_out(struct navit *this_)
1186 {
1187 navit_zoom_out_cursor(this_, 2);
1188 return 0;
1189 }
1190
1191 static void navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1192 {
1193 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1194 {
1195 navit_say(this, in[0]->u.str);
1196 }
1197 }
1198
1199 static GHashTable *cmd_int_var_hash = NULL;
1200 static GHashTable *cmd_attr_var_hash = NULL;
1201
1202 /**
1203 * Store key value pair for the command system (for int typed values)
1204 *
1205 * @param navit The navit instance
1206 * @param function unused (needed to match command function signiture)
1207 * @param in input attributes in[0] is the key string, in[1] is the integer value to store
1208 * @param out output attributes, unused
1209 * @param valid unused
1210 * @returns nothing
1211 */
1212 static void navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1213 {
1214 char*key;
1215 struct attr*val;
1216 if (!cmd_int_var_hash)
1217 {
1218 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1219 }
1220
1221 if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1] && ATTR_IS_NUMERIC(in[1]->type)))
1222 {
1223 val = g_new(struct attr,1);
1224 attr_dup_content(in[1], val);
1225 key = g_strdup(in[0]->u.str);
1226 g_hash_table_insert(cmd_int_var_hash, key, val);
1227 }
1228 }
1229
1230 /**
1231 * Store key value pair for the command system (for attr typed values, can be used as opaque handles)
1232 *
1233 * @param navit The navit instance
1234 * @param function unused (needed to match command function signiture)
1235 * @param in input attributes in[0] is the key string, in[1] is the attr* value to store
1236 * @param out output attributes, unused
1237 * @param valid unused
1238 * @returns nothing
1239 */
1240 //TODO free stored attributes on navit_destroy
1241 static void navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1242 {
1243 char*key;
1244 struct attr*val;
1245 if (!cmd_attr_var_hash)
1246 {
1247 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
1248 }
1249
1250 if ((in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) && (in && in[1]))
1251 {
1252 val = attr_dup(in[1]);
1253 //val = in[1];
1254 key = g_strdup(in[0]->u.str);
1255 g_hash_table_insert(cmd_attr_var_hash, key, val);
1256 }
1257 }
1258
1259 /**
1260 * command to toggle the active state of a named layer of the current layout
1261 *
1262 * @param navit The navit instance
1263 * @param function unused (needed to match command function signiture)
1264 * @param in input attribute in[0] is the name of the layer
1265 * @param out output unused
1266 * @param valid unused
1267 * @returns nothing
1268 */
1269 static void navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1270 {
1271 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1272 {
1273 if (this->layout_current && this->layout_current->layers)
1274 {
1275 GList* layers = this->layout_current->layers;
1276 while (layers)
1277 {
1278 struct layer*l = layers->data;
1279 if (l && !strcmp(l->name, in[0]->u.str))
1280 {
1281 l->active ^= 1;
1282 navit_draw(this);
1283 return;
1284 }
1285 layers = g_list_next(layers);
1286 }
1287 }
1288 }
1289 }
1290
1291
1292 void navit_enhance_cycleway(struct navit *this)
1293 {
1294 GList *itms;
1295 struct itemgra *itm;
1296 struct element *e;
1297 GList *es, *types;
1298 int found = 0;
1299 GList* layers = this->layout_current->layers;
1300
1301 global_enhance_cycleway = 1;
1302
1303 while (layers)
1304 {
1305
1306 struct layer*l = layers->data;
1307 if (l)
1308 {
1309
1310 itms = l->itemgras;
1311 while (itms)
1312 {
1313 itm = itms->data;
1314 found = 0;
1315
1316 types = itm->type;
1317 while (types)
1318 {
1319 if (GPOINTER_TO_INT(types->data) == type_cycleway)
1320 {
1321 found = 1;
1322 }
1323 types = g_list_next(types);
1324 }
1325
1326 if (found == 1)
1327 {
1328
1329 dbg(0, "CYC:001:min=%d max=%d\n", itm->order.min, itm->order.max);
1330
1331 if (itm->order.min == 14)
1332 {
1333 itm->order.min = 10;
1334 }
1335
1336 es = itm->elements;
1337 while (es)
1338 {
1339 e = es->data;
1340
1341 if (e->type == element_polyline)
1342 {
1343 e->u.polyline.width = e->u.polyline.width * 2;
1344 }
1345
1346 es = g_list_next(es);
1347 }
1348 }
1349
1350 itms = g_list_next(itms);
1351 }
1352
1353 }
1354 layers = g_list_next(layers);
1355
1356 }
1357
1358 }
1359
1360
1361 void navit_reset_cycleway(struct navit *this)
1362 {
1363 GList *itms;
1364 struct itemgra *itm;
1365 struct element *e;
1366 GList *es, *types;
1367 int found = 0;
1368 GList* layers = this->layout_current->layers;
1369
1370 global_enhance_cycleway = 0;
1371
1372 while (layers)
1373 {
1374
1375 struct layer*l = layers->data;
1376 if (l)
1377 {
1378
1379 itms = l->itemgras;
1380 while (itms)
1381 {
1382 itm = itms->data;
1383 found = 0;
1384
1385 types = itm->type;
1386 while (types)
1387 {
1388 if (GPOINTER_TO_INT(types->data) == type_cycleway)
1389 {
1390 found = 1;
1391 }
1392 types = g_list_next(types);
1393 }
1394
1395 if (found == 1)
1396 {
1397 if (itm->order.min == 10)
1398 {
1399 itm->order.min = 14;
1400 }
1401
1402 es = itm->elements;
1403 while (es)
1404 {
1405 e = es->data;
1406
1407 if (e->type == element_polyline)
1408 {
1409 e->u.polyline.width = e->u.polyline.width / 2;
1410 }
1411
1412 es = g_list_next(es);
1413 }
1414 }
1415
1416 itms = g_list_next(itms);
1417 }
1418
1419 }
1420 layers = g_list_next(layers);
1421
1422 }
1423
1424 }
1425
1426
1427 void navit_layer_toggle_active(struct navit *this, char *name, int draw)
1428 {
1429 if (name)
1430 {
1431 if (this->layout_current && this->layout_current->layers)
1432 {
1433 GList* layers = this->layout_current->layers;
1434 while (layers)
1435 {
1436 struct layer *l = layers->data;
1437 if (l && !strcmp(l->name, name))
1438 {
1439 l->active ^= 1;
1440 if (draw == 1)
1441 {
1442 navit_draw(this);
1443 }
1444 return;
1445 }
1446 layers = g_list_next(layers);
1447 }
1448 }
1449 }
1450 }
1451
1452
1453
1454 /**
1455 * command to set the active state of a named layer of the current layout
1456 *
1457 * @param navit The navit instance
1458 * @param name name of the layer
1459 * @param active 0 -> inactive, 1 -> active
1460 * @param draw 0 -> dont redraw, 1 -> redraw
1461 * @returns nothing
1462 */
1463 void navit_layer_set_active(struct navit *this, char *name, int active, int draw)
1464 {
1465 if (name)
1466 {
1467 if (this->layout_current && this->layout_current->layers)
1468 {
1469 GList* layers = this->layout_current->layers;
1470 while (layers)
1471 {
1472 struct layer *l = layers->data;
1473 if (l && !strcmp(l->name, name))
1474 {
1475 l->active = active;
1476 if (draw == 1)
1477 {
1478 navit_draw(this);
1479 }
1480 return;
1481 }
1482 layers = g_list_next(layers);
1483 }
1484 }
1485 }
1486 }
1487
1488 /**
1489 * adds an item with the current coordinate of the vehicle to a named map
1490 *
1491 * @param navit The navit instance
1492 * @param function unused (needed to match command function signiture)
1493 * @param in input attribute in[0] is the name of the map
1494 * @param out output attribute, 0 on error or the id of the created item on success
1495 * @param valid unused
1496 * @returns nothing
1497 */
1498 static void navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1499 {
1500 struct attr **list = g_new0(struct attr *,2);
1501 struct attr*val = g_new0(struct attr,1);
1502 struct mapset* ms;
1503 struct map_selection sel;
1504 const int selection_range = 10;
1505 enum item_type item_type;
1506 struct item *it;
1507 struct map* curr_map = NULL;
1508 struct coord curr_coord;
1509 struct map_rect *mr;
1510
1511 val->type = attr_type_item_begin;
1512 val->u.item = NULL; //return invalid item on error
1513 list[0] = val;
1514 list[1] = NULL;
1515 *out = list;
1516 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
1517 in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
1518 )
1519 {
1520
1521 if (!(ms = navit_get_mapset(this)))
1522 {
1523 return;
1524 }
1525
1526 if ((item_type = item_from_name(in[1]->u.str)) == type_none)
1527 {
1528 return;
1529 }
1530
1531 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
1532
1533 //no map with the given name found
1534 if (!curr_map)
1535 {
1536 return;
1537 }
1538
1539 if (this->vehicle && this->vehicle->vehicle)
1540 {
1541 struct attr pos_attr;
1542 if (vehicle_get_attr(this->vehicle->vehicle, attr_position_coord_geo, &pos_attr, NULL))
1543 {
1544 transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
1545 }
1546 else
1547 {
1548 return;
1549 }
1550 }
1551 else
1552 {
1553 return;
1554 }
1555
1556 sel.next = NULL;
1557 sel.order = 18;
1558 sel.range.min = type_none;
1559 sel.range.max = type_tec_common;
1560 sel.u.c_rect.lu.x = curr_coord.x - selection_range;
1561 sel.u.c_rect.lu.y = curr_coord.y + selection_range;
1562 sel.u.c_rect.rl.x = curr_coord.x + selection_range;
1563 sel.u.c_rect.rl.y = curr_coord.y - selection_range;
1564
1565 mr = map_rect_new(curr_map, &sel);
1566 if (mr)
1567 {
1568 it = map_rect_create_item(mr, item_type);
1569 item_coord_set(it, &curr_coord, 1, change_mode_modify);
1570 val->u.item = it;
1571 }
1572 map_rect_destroy(mr);
1573 }
1574 }
1575
1576 /**
1577 * sets an attribute (name value pair) of a map item specified by map name and item id
1578 *
1579 * @param navit The navit instance
1580 * @param function unused (needed to match command function signiture)
1581 * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
1582 * @param out output attribute, 0 on error, 1 on success
1583 * @param valid unused
1584 * @returns nothing
1585 */
1586 static void navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1587 {
1588 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
1589 in[1] && ATTR_IS_ITEM(in[1]->type) && //item
1590 in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
1591 in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
1592 )
1593 {
1594 struct attr attr_to_set;
1595 struct map* curr_map = NULL;
1596 struct mapset *ms;
1597 struct map_selection sel;
1598 const int selection_range = 500;
1599 struct coord curr_coord;
1600 struct item *it;
1601
1602 if (ATTR_IS_STRING(attr_from_name(in[2]->u.str)))
1603 {
1604 attr_to_set.u.str = in[3]->u.str;
1605 attr_to_set.type = attr_from_name(in[2]->u.str);
1606 }
1607 else if (ATTR_IS_INT(attr_from_name(in[2]->u.str)))
1608 {
1609 attr_to_set.u.num = atoi(in[3]->u.str);
1610 attr_to_set.type = attr_from_name(in[2]->u.str);
1611 }
1612 else if (ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str)))
1613 {
1614 double* val = g_new0(double,1);
1615 *val = atof(in[3]->u.str);
1616 attr_to_set.u.numd = val;
1617 attr_to_set.type = attr_from_name(in[2]->u.str);
1618 }
1619
1620 ms = navit_get_mapset(this);
1621
1622 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
1623
1624 if (!curr_map)
1625 {
1626 return;
1627 }
1628 sel.next = NULL;
1629 sel.order = 18;
1630 sel.range.min = type_none;
1631 sel.range.max = type_tec_common;
1632 sel.u.c_rect.lu.x = curr_coord.x - selection_range;
1633 sel.u.c_rect.lu.y = curr_coord.y + selection_range;
1634 sel.u.c_rect.rl.x = curr_coord.x + selection_range;
1635 sel.u.c_rect.rl.y = curr_coord.y - selection_range;
1636
1637 it = in[1]->u.item;
1638 if (it)
1639 {
1640 item_attr_set(it, &attr_to_set, change_mode_modify);
1641 }
1642 }
1643 }
1644
1645 /**
1646 * Get attr variable given a key string for the command system (for opaque usage)
1647 *
1648 * @param navit The navit instance
1649 * @param function unused (needed to match command function signiture)
1650 * @param in input attribute in[0] is the key string
1651 * @param out output attribute, the attr for the given key string if exists or NULL
1652 * @param valid unused
1653 * @returns nothing
1654 */
1655 static void navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1656 {
1657 struct attr **list = g_new0(struct attr *,2);
1658 if (!cmd_int_var_hash)
1659 {
1660 struct attr*val = g_new0(struct attr,1);
1661 val->type = attr_type_item_begin;
1662 val->u.item = NULL;
1663 list[0] = val;
1664 }
1665 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1666 {
1667 struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
1668 if (ret)
1669 {
1670 list[0] = attr_dup(ret);
1671 }
1672 else
1673 {
1674 struct attr*val = g_new0(struct attr,1);
1675 val->type = attr_type_int_begin;
1676 val->u.item = NULL;
1677 list[0] = val;
1678 }
1679 }
1680 list[1] = NULL;
1681 *out = list;
1682 }
1683
1684 /**
1685 * Get value given a key string for the command system
1686 *
1687 * @param navit The navit instance
1688 * @param function unused (needed to match command function signiture)
1689 * @param in input attribute in[0] is the key string
1690 * @param out output attribute, the value for the given key string if exists or 0
1691 * @param valid unused
1692 * @returns nothing
1693 */
1694 static void navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1695 {
1696 struct attr **list = g_new0(struct attr *,2);
1697 if (!cmd_int_var_hash)
1698 {
1699 struct attr*val = g_new0(struct attr,1);
1700 val->type = attr_type_int_begin;
1701 val->u.num = 0;
1702 list[0] = val;
1703 }
1704 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
1705 {
1706 struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
1707 if (ret)
1708 {
1709 list[0] = ret;
1710 }
1711 else
1712 {
1713 struct attr*val = g_new0(struct attr,1);
1714 val->type = attr_type_int_begin;
1715 val->u.num = 0;
1716 list[0] = val;
1717 }
1718 }
1719 list[1] = NULL;
1720 *out = list;
1721 }
1722
1723 GList *cmd_int_var_stack = NULL;
1724
1725 /**
1726 * Push an integer to the stack for the command system
1727 *
1728 * @param navit The navit instance
1729 * @param function unused (needed to match command function signiture)
1730 * @param in input attribute in[0] is the integer attibute to push
1731 * @param out output attributes, unused
1732 * @param valid unused
1733 * @returns nothing
1734 */
1735 static void navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1736 {
1737 if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type))
1738 {
1739 struct attr*val = g_new(struct attr,1);
1740 attr_dup_content(in[0], val);
1741 cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
1742 }
1743 }
1744
1745 /**
1746 * Pop an integer from the command system's integer stack
1747 *
1748 * @param navit The navit instance
1749 * @param function unused (needed to match command function signiture)
1750 * @param in input attributes unused
1751 * @param out output attribute, the value popped if stack isn't empty or 0
1752 * @param valid unused
1753 * @returns nothing
1754 */
1755 static void navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1756 {
1757 struct attr **list = g_new0(struct attr *,2);
1758 if (!cmd_int_var_stack)
1759 {
1760 struct attr*val = g_new0(struct attr,1);
1761 val->type = attr_type_int_begin;
1762 val->u.num = 0;
1763 list[0] = val;
1764 }
1765 else
1766 {
1767 list[0] = cmd_int_var_stack->data;
1768 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack);
1769 }
1770 list[1] = NULL;
1771 *out = list;
1772 }
1773
1774 /**
1775 * Get current size of command system's integer stack
1776 *
1777 * @param navit The navit instance
1778 * @param function unused (needed to match command function signiture)
1779 * @param in input attributes unused
1780 * @param out output attribute, the size of stack
1781 * @param valid unused
1782 * @returns nothing
1783 */
1784 static void navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1785 {
1786 struct attr **list;
1787 struct attr *attr = g_new0(struct attr ,1);
1788 attr->type = attr_type_int_begin;
1789 if (!cmd_int_var_stack)
1790 {
1791 attr->u.num = 0;
1792 }
1793 else
1794 {
1795 attr->u.num = g_list_length(cmd_int_var_stack);
1796 }list = g_new0(struct attr *,2);
1797 list[0] = attr;
1798 list[1] = NULL;
1799 *out = list;
1800 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack, cmd_int_var_stack);
1801 }
1802
1803 static void navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1804 {
1805 struct pcoord pc;
1806 char *description = NULL;
1807 if (!in)
1808 return;
1809 if (!in[0])
1810 return;
1811 pc.pro = transform_get_projection(this->trans);
1812 if (ATTR_IS_COORD(in[0]->type))
1813 {
1814 pc.x = in[0]->u.coord->x;
1815 pc.y = in[0]->u.coord->y;
1816 in++;
1817 }
1818 else if (ATTR_IS_PCOORD(in[0]->type))
1819 {
1820 pc = *in[0]->u.pcoord;
1821 in++;
1822 }
1823 else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type))
1824 {
1825 pc.pro = in[0]->u.num;
1826 pc.x = in[1]->u.num;
1827 pc.y = in[2]->u.num;
1828 in += 3;
1829 }
1830 else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type))
1831 {
1832 pc.x = in[0]->u.num;
1833 pc.y = in[1]->u.num;
1834 in += 2;
1835 }
1836 else
1837 {
1838 return;
1839 }
1840 if (in[0] && ATTR_IS_STRING(in[0]->type))
1841 {
1842 description = in[0]->u.str;
1843 }
1844 navit_set_destination(this, &pc, description, 1);
1845 }
1846
1847 static void navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1848 {
1849 struct attr attr;
1850 attr.type = attr_type_string_begin;
1851 attr.u.str = "Fix me";
1852 if (out)
1853 {
1854 *out = attr_generic_add_attr(*out, &attr);
1855 }
1856 }
1857
1858 /**
1859 * Join several string attributes into one
1860 *
1861 * @param navit The navit instance
1862 * @param function unused (needed to match command function signiture)
1863 * @param in input attributes in[0] - separator, in[1..] - attributes to join
1864 * @param out output attribute joined attribute as string
1865 * @param valid unused
1866 * @returns nothing
1867 */
1868 static void navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1869 {
1870 struct attr attr;
1871 gchar *ret, *sep;
1872 int i;
1873 attr.type = attr_type_string_begin;
1874 attr.u.str = NULL;
1875 if (in[0] && in[1])
1876 {
1877 sep = attr_to_text(in[0], NULL, 1);
1878 ret = attr_to_text(in[1], NULL, 1);
1879 for (i = 2; in[i]; i++)
1880 {
1881 gchar *in_i = attr_to_text(in[i], NULL, 1);
1882 gchar *r = g_strjoin(sep, ret, in_i, NULL);
1883 g_free(in_i);
1884 g_free(ret);
1885 ret = r;
1886 }
1887 g_free(sep);
1888 attr.u.str = ret;
1889 if (out)
1890 {
1891 *out = attr_generic_add_attr(*out, &attr);
1892 }
1893 g_free(ret);
1894 }
1895 }
1896
1897 /**
1898 * Call external program
1899 *
1900 * @param navit The navit instance
1901 * @param function unused (needed to match command function signiture)
1902 * @param in input attributes in[0] - name of executable, in[1..] - parameters
1903 * @param out output attribute unused
1904 * @param valid unused
1905 * @returns nothing
1906 */
1907 static void navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1908 {
1909 int i, j, nparms, nvalid;
1910 const char ** argv = NULL;
1911 struct spawn_process_info *pi;
1912
1913 nparms = 0;
1914 nvalid = 0;
1915 if (in)
1916 {
1917 while (in[nparms])
1918 {
1919 if (in[nparms]->type != attr_none)
1920 nvalid++;
1921 nparms++;
1922 }
1923 }
1924
1925 if (nvalid > 0)
1926 {
1927 argv=g_new(char*,nvalid+1);
1928 for (i = 0, j = 0; in[i]; i++)
1929 {
1930 if (in[i]->type != attr_none)
1931 {
1932 argv[j++] = attr_to_text(in[i], NULL, 1);
1933 }
1934 else
1935 {
1936 //DBG dbg(0, "Parameter #%i is attr_none - skipping\n", i);
1937 }
1938 }
1939 argv[j] = NULL;
1940 pi = spawn_process(argv);
1941
1942 // spawn_process() testing suite - uncomment following code to test.
1943 //sleep(3);
1944 // example of non-blocking wait
1945 //int st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st);
1946 // example of blocking wait
1947 //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st);
1948 // example of wait after process is finished and status is
1949 // already tested
1950 //st=spawn_process_check_status(pi,1);//DBG dbg(0,"status %i\n",st);
1951 // example of wait after process is finished and status is
1952 // already tested - unblocked
1953 //st=spawn_process_check_status(pi,0);//DBG dbg(0,"status %i\n",st);
1954
1955 // End testing suite
1956 spawn_process_info_free(pi);
1957 for (i = 0; argv[i]; i++)
1958 g_free(argv[i]);
1959 g_free(argv);
1960 }
1961 }
1962
1963 static struct command_table
1964 commands[] =
1965 { { "zoom_in", command_cast(navit_cmd_zoom_in) }, { "zoom_out", command_cast(navit_cmd_zoom_out) }, { "zoom_to_route", command_cast(navit_cmd_zoom_to_route) }, { "say", command_cast(navit_cmd_say) }, { "set_center_cursor", command_cast(navit_cmd_set_center_cursor) }, { "set_destination", command_cast(navit_cmd_set_destination) }, { "announcer_toggle", command_cast(navit_cmd_announcer_toggle) }, { "fmt_coordinates", command_cast(navit_cmd_fmt_coordinates) }, { "set_int_var", command_cast(navit_cmd_set_int_var) }, { "get_int_var", command_cast(navit_cmd_get_int_var) }, { "push_int", command_cast(navit_cmd_push_int) }, { "pop_int", command_cast(navit_cmd_pop_int) }, { "int_stack_size", command_cast(navit_cmd_int_stack_size) }, { "toggle_layer", command_cast(navit_cmd_toggle_layer) }, { "strjoin", command_cast(navit_cmd_strjoin) }, { "spawn", command_cast(navit_cmd_spawn) }, { "map_add_curr_pos", command_cast(navit_cmd_map_add_curr_pos) }, { "map_item_set_attr", command_cast(navit_cmd_map_item_set_attr) }, { "set_attr_var", command_cast(navit_cmd_set_attr_var) }, { "get_attr_var", command_cast(navit_cmd_get_attr_var) }, };
1966
1967 void navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
1968 {
1969 command_add_table(this_->attr_cbl, commands, count, this_);
1970 }
1971
1972
1973 struct navit *
1974 navit_new(struct attr *parent, struct attr **attrs)
1975 {
1976 struct navit *this_=g_new0(struct navit, 1);
1977 struct pcoord center;
1978 struct coord co;
1979 struct coord_geo g;
1980 enum projection pro = projection_mg;
1981 int zoom = 256;
1982 g.lat = 53.13;
1983 g.lng = 11.70;
1984
1985
1986 global_demo_vehicle = 0;
1987 global_demo_vehicle_short_switch = 0;
1988
1989
1990 // set base for timestamps
1991 struct timeval tv2;
1992 if (gettimeofday(&tv2, NULL) == -1)
1993 {
1994 global_last_spoken_base = 0;
1995 }
1996 else
1997 {
1998 global_last_spoken_base = (long)tv2.tv_sec;
1999 }
2000
2001 global_debug_coord_list = g_new0(struct coord, (2 * (MAX_DEBUG_COORDS + 2)));
2002 global_debug_coord_list_items = 0;
2003
2004 global_debug_route_seg_winner_start.x = 0;
2005 global_debug_route_seg_winner_start.y = 0;
2006 global_debug_route_seg_winner_end.x = 0;
2007 global_debug_route_seg_winner_end.y = 0;
2008
2009 global_debug_seg_winner_start.x = 0;
2010 global_debug_seg_winner_start.y = 0;
2011 global_debug_seg_winner_end.x = 0;
2012 global_debug_seg_winner_end.y = 0;
2013
2014 global_debug_route_seg_winner_p_start.x = 0;
2015 global_debug_route_seg_winner_p_start.y = 0;
2016
2017 global_debug_seg_winner_p_start.x = 0;
2018 global_debug_seg_winner_p_start.y = 0;
2019
2020 global_debug_seg_route_start.x = 0;
2021 global_debug_seg_route_start.y = 0;
2022
2023 global_debug_seg_route_end.x = 0;
2024 global_debug_seg_route_end.y = 0;
2025
2026
2027
2028 this_->self.type = attr_navit;
2029 this_->self.u.navit = this_;
2030 this_->attr_cbl = callback_list_new("navit_new:this_->attr_cbl");
2031
2032 this_->orientation = -1;
2033 this_->tracking_flag = 1;
2034 this_->recentdest_count = 10;
2035 this_->osd_configuration = -1;
2036
2037 // changed default to 1
2038 this_->center_timeout = 1;
2039 this_->use_mousewheel = 1;
2040 this_->autozoom_secs = 10;
2041 this_->autozoom_min = 5;
2042 this_->autozoom_active = 0;
2043 this_->zoom_min = 1;
2044 this_->zoom_max = 1048576; //-> order=-2 // 2097152 -> order=-3;
2045 this_->follow_cursor = 1;
2046 this_->radius = 30;
2047 this_->border = 16;
2048
2049 // dbg(0, "GGGGG:set global_navit\n");
2050 global_navit = this_;
2051
2052 this_->trans = transform_new();
2053 this_->trans_cursor = transform_new();
2054 transform_from_geo(pro, &g, &co);
2055 center.x = co.x;
2056 center.y = co.y;
2057 center.pro = pro;
2058
2059 transform_init();
2060
2061 //DBG dbg(0, "setting center from xmlfile [hardcoded]\n");
2062 transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
2063
2064 // initialze trans_cursor here
2065 transform_copy(this_->trans, this_->trans_cursor);
2066 // initialze trans_cursor here
2067
2068
2069 dbg(0, "ii 001\n");
2070 this_->bookmarks = bookmarks_new(&this_->self, NULL, this_->trans);
2071 //this_->bookmarks = NULL;
2072 dbg(0, "ii 002\n");
2073
2074 this_->prevTs = 0;
2075
2076 for (; *attrs; attrs++)
2077 {
2078 navit_set_attr_do(this_, *attrs, 1);
2079 }
2080 this_->displaylist = graphics_displaylist_new();
2081 command_add_table(this_->attr_cbl, commands, sizeof(commands) / sizeof(struct command_table), this_);
2082
2083 dbg(0, "ii 009\n");
2084
2085 // this_->messages = messagelist_new(attrs);
2086
2087 dbg(0, "111111\n");
2088
2089 return this_;
2090 }
2091
2092 static int navit_set_gui(struct navit *this_, struct gui *gui)
2093 {
2094 if (this_->gui)
2095 return 0;
2096
2097 this_->gui = gui;
2098
2099 if (gui_has_main_loop(this_->gui))
2100 {
2101 if (!main_loop_gui)
2102 {
2103 main_loop_gui = this_->gui;
2104 }
2105 else
2106 {
2107 //DBG dbg(0, "gui with main loop already active, ignoring this instance");
2108 return 0;
2109 }
2110 }
2111 return 1;
2112 }
2113
2114 void navit_add_message(struct navit *this_, char *message)
2115 {
2116 // message_new(this_->messages, message);
2117 }
2118
2119 struct message *navit_get_messages(struct navit *this_)
2120 {
2121 // return message_get(this_->messages);
2122 }
2123
2124 static int navit_set_graphics(struct navit *this_, struct graphics *gra)
2125 {
2126 if (this_->gra)
2127 {
2128 return 0;
2129 }
2130
2131 this_->gra = gra;
2132
2133 /*
2134 this_->resize_callback = callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
2135 graphics_add_callback(gra, this_->resize_callback);
2136 this_->button_callback = callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
2137 graphics_add_callback(gra, this_->button_callback);
2138 this_->motion_callback = callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
2139 graphics_add_callback(gra, this_->motion_callback);
2140 */
2141
2142 // this draw the vehicle // very stupid
2143 this_->predraw_callback = callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
2144 callback_add_names(this_->predraw_callback, "navit_set_graphics", "navit_predraw");
2145 graphics_add_callback(gra, this_->predraw_callback);
2146
2147 return 1;
2148 }
2149
2150 struct graphics *
2151 navit_get_graphics(struct navit *this_)
2152 {
2153 return this_->gra;
2154 }
2155
2156 struct vehicleprofile *
2157 navit_get_vehicleprofile(struct navit *this_)
2158 {
2159 return this_->vehicleprofile;
2160 }
2161
2162 GList *
2163 navit_get_vehicleprofiles(struct navit *this_)
2164 {
2165 return this_->vehicleprofiles;
2166 }
2167
2168 static void navit_projection_set(struct navit *this_, enum projection pro, int draw)
2169 {
2170
2171
2172 ////DBG dbg(0,"EEnter\n");
2173 struct coord_geo g;
2174 struct coord *c;
2175
2176 c = transform_center(this_->trans);
2177 transform_to_geo(transform_get_projection(this_->trans), c, &g);
2178 transform_set_projection(this_->trans, pro);
2179 transform_from_geo(pro, &g, c);
2180 if (draw)
2181 {
2182 navit_draw(this_);
2183 }
2184 }
2185
2186 /**
2187 * Start the route computing to a given set of coordinates
2188 *
2189 * @param navit The navit instance
2190 * @param c The coordinate to start routing to
2191 * @param description A label which allows the user to later identify this destination in the former destinations selection
2192 * @returns nothing
2193 */
2194 void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
2195 {
2196
2197
2198 ////DBG dbg(0,"EEnter\n");
2199 char *destination_file;
2200 if (c)
2201 {
2202 this_->destination = *c;
2203 this_->destination_valid = 1;
2204 //dbg(0, "navit->navit_set_destination %i\n", c->x);
2205 //dbg(0, "navit->navit_set_destination %i\n", c->y);
2206 }
2207 else
2208 {
2209 this_->destination_valid = 0;
2210 }
2211 //destination_file = bookmarks_get_destination_file(TRUE);
2212 //bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
2213 //g_free(destination_file);
2214 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
2215 if (this_->route)
2216 {
2217 //dbg(0, "navit->navit_set_destination 2: %i %i\n", c->x, c->y);
2218
2219 route_set_destination(this_->route, c, async);
2220 if (this_->ready == 3)
2221 {
2222 navit_draw(this_);
2223 }
2224 }
2225 }
2226
2227 /**
2228 * add a waypoint to an active route
2229 *
2230 * @param navit The navit instance
2231 * @param c The coordinate of the waypoint
2232 * @param description A dummy string
2233 * @returns nothing
2234 */
2235 void navit_add_waypoint_to_route(struct navit *this_, struct pcoord *c, const char *description, int async)
2236 {
2237
2238
2239 if (this_->destination_valid == 1)
2240 {
2241 //int count = 0;
2242 //count = g_list_length(this_->route->destinations);
2243 //DBG dbg(0, "count=%d\n", count);
2244
2245 //dbg(0, "navit->navit_add_waypoint_to_route 1: %i %i\n", c->x, c->y);
2246
2247 route_add_destination(this_->route, c, async);
2248
2249 this_->destination = *c;
2250 this_->destination_valid = 1;
2251 }
2252 else
2253 {
2254 //dbg(0, "navit->navit_add_waypoint_to_route 2: %i %i\n", c->x, c->y);
2255 navit_set_destination(this_, c, description, async);
2256 }
2257 }
2258
2259 /**
2260 * Start the route computing to a given set of coordinates including waypoints
2261 *
2262 * @param navit The navit instance
2263 * @param c The coordinate to start routing to
2264 * @param description A label which allows the user to later identify this destination in the former destinations selection
2265 * @returns nothing
2266 */
2267 void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
2268 {
2269
2270
2271 ////DBG dbg(0,"EEnter\n");
2272 char *destination_file;
2273 if (c && count)
2274 {
2275 this_->destination = c[count - 1];
2276 this_->destination_valid = 1;
2277 //dbg(0, "navit->navit_set_destinations 1: %i %i\n", c[count-1].x, c[count-1].y);
2278 }
2279 else
2280 {
2281 this_->destination_valid = 0;
2282 }
2283 //destination_file = bookmarks_get_destination_file(TRUE);
2284 //bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
2285 //g_free(destination_file);
2286 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
2287 if (this_->route)
2288 {
2289 route_set_destinations(this_->route, c, count, async);
2290 if (this_->ready == 3)
2291 {
2292 navit_draw(this_);
2293 }
2294 }
2295 }
2296
2297 /**
2298 * @brief Checks if a route is calculated
2299 *
2300 * This function checks if a route is calculated.
2301 *
2302 * @param this_ The navit struct whose route should be checked.
2303 * @return True if the route is set, false otherwise.
2304 */
2305 int navit_check_route(struct navit *this_)
2306 {
2307
2308
2309 ////DBG dbg(0,"EEnter\n");
2310 if (this_->route)
2311 {
2312 return route_get_path_set(this_->route);
2313 }
2314
2315 return 0;
2316 }
2317
2318 static int navit_former_destinations_active(struct navit *this_)
2319 {
2320
2321
2322 ////DBG dbg(0,"EEnter\n");
2323
2324 return 0;
2325 // disable this function!!
2326
2327
2328 char *destination_file = bookmarks_get_destination_file(FALSE);
2329 FILE *f;
2330 int active = 0;
2331 char buffer[3];
2332 f = fopen(destination_file, "r");
2333 if (f)
2334 {
2335 if (!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0] != '\n' || buffer[1] != '\n'))
2336 {
2337 active = 1;
2338 }
2339 fclose(f);
2340 }
2341 g_free(destination_file);
2342
2343 return active;
2344 }
2345
2346 static void navit_add_former_destinations_from_file(struct navit *this_)
2347 {
2348
2349
2350 ////DBG dbg(0,"EEnter\n");
2351 char *destination_file = bookmarks_get_destination_file(FALSE);
2352 struct attr *attrs[4];
2353 struct map_rect *mr;
2354 struct item *item;
2355 int i, valid = 0, count = 0;
2356 struct coord c[16];
2357 struct pcoord pc[16];
2358 struct attr parent;
2359 struct attr type;
2360 struct attr data;
2361 struct attr flags;
2362
2363 parent.type = attr_navit;
2364 parent.u.navit = this_;
2365
2366 type.type = attr_type;
2367 type.u.str = "textfile";
2368
2369 data.type = attr_data;
2370 data.u.str = destination_file;
2371
2372 flags.type = attr_flags;
2373 flags.u.num = 1;
2374
2375 attrs[0] = &type;
2376 attrs[1] = &data;
2377 attrs[2] = &flags;
2378 attrs[3] = NULL;
2379
2380 this_->former_destination = map_new(&parent, attrs);
2381 g_free(destination_file);
2382 if (!this_->route || !navit_former_destinations_active(this_))
2383 return;
2384 mr = map_rect_new(this_->former_destination, NULL);
2385 while ((item = map_rect_get_item(mr)))
2386 {
2387 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count = item_coord_get(item, c, 16)))
2388 valid = 1;
2389 }
2390 map_rect_destroy(mr);
2391 if (valid && count > 0)
2392 {
2393 for (i = 0; i < count; i++)
2394 {
2395 pc[i].pro = map_projection(this_->former_destination);
2396 pc[i].x = c[i].x;
2397 pc[i].y = c[i].y;
2398 }
2399 if (count == 1)
2400 {
2401 route_set_destination(this_->route, &pc[0], 1);
2402 }
2403 else
2404 {
2405 route_set_destinations(this_->route, pc, count, 1);
2406 }
2407 this_->destination = pc[count - 1];
2408 this_->destination_valid = 1;
2409 }
2410 }
2411
2412 void navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
2413 {
2414
2415
2416 ////DBG dbg(0,"EEnter\n");
2417 va_list ap;
2418 char *str1, *str2;
2419 va_start(ap, fmt);
2420 if (this_->textfile_debug_log && this_->vehicle)
2421 {
2422 str1 = g_strdup_vprintf(fmt, ap);
2423 str2 = g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
2424 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
2425 g_free(str2);
2426 g_free(str1);
2427 }
2428 va_end(ap);
2429 }
2430
2431 void navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
2432 {
2433
2434
2435 ////DBG dbg(0,"EEnter\n");
2436 va_list ap;
2437 char *str1, *str2;
2438 va_start(ap, fmt);
2439 if (this_->textfile_debug_log && this_->vehicle)
2440 {
2441 str1 = g_strdup_vprintf(fmt, ap);
2442 str2 = g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
2443 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
2444 g_free(str2);
2445 g_free(str1);
2446 }
2447 va_end(ap);
2448 }
2449
2450 void navit_say(struct navit *this_, char *text)
2451 {
2452
2453
2454 ////DBG dbg(0,"EEnter\n");
2455 if (this_->speech)
2456 {
2457 //dbg(0,"say(1) s=%s\n", text);
2458 speech_say(this_->speech, text);
2459 }
2460 }
2461
2462 /**
2463 * @brief Toggles the navigation announcer for navit
2464 * @param this_ The navit object
2465 */
2466 static void navit_cmd_announcer_toggle(struct navit *this_)
2467 {
2468
2469
2470 struct attr attr, speechattr;
2471
2472 // search for the speech attribute
2473 if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2474 return;
2475 // find out if the corresponding attribute attr_active has been set
2476 if (speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL))
2477 {
2478 // flip it then...
2479 attr.u.num = !attr.u.num;
2480 }
2481 else
2482 {
2483 // otherwise disable it because voice is enabled by default
2484 attr.type = attr_active;
2485 attr.u.num = 0;
2486 }
2487
2488 // apply the new state
2489 if (!speech_set_attr(speechattr.u.speech, &attr))
2490 return;
2491
2492 // announce that the speech attribute has changed
2493 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2494 }
2495
2496 void navit_cmd_announcer_on(struct navit *this_)
2497 {
2498
2499
2500 struct attr attr, speechattr;
2501
2502 // search for the speech attribute
2503 if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2504 return;
2505
2506 attr.type = attr_active;
2507 attr.u.num = 1;
2508
2509 // apply the new state
2510 if (!speech_set_attr(speechattr.u.speech, &attr))
2511 return;
2512
2513 // announce that the speech attribute has changed
2514 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2515 }
2516
2517 void navit_cmd_announcer_off(struct navit *this_)
2518 {
2519
2520
2521 struct attr attr, speechattr;
2522
2523 // search for the speech attribute
2524 if (!navit_get_attr(this_, attr_speech, &speechattr, NULL))
2525 return;
2526
2527 attr.type = attr_active;
2528 attr.u.num = 0;
2529
2530 // apply the new state
2531 if (!speech_set_attr(speechattr.u.speech, &attr))
2532 return;
2533
2534 // announce that the speech attribute has changed
2535 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
2536 }
2537
2538 void navit_speak(struct navit *this_)
2539 {
2540
2541
2542 ////DBG dbg(0,"EEnter\n");
2543 struct navigation *nav = this_->navigation;
2544 struct map *map = NULL;
2545 struct map_rect *mr = NULL;
2546 struct item *item;
2547 struct attr attr;
2548
2549 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
2550 {
2551 attr.u.num = 1;
2552 }
2553
2554 // dbg(1, "this_.speech->active %i\n", attr.u.num);
2555
2556 dbg(0, "NAV_TURNAROUND:008:enter\n");
2557
2558 if (!attr.u.num)
2559 {
2560 return;
2561 }
2562
2563 if (nav)
2564 map = navigation_get_map(nav);
2565
2566 if (map)
2567 mr = map_rect_new(map, NULL);
2568
2569 if (mr)
2570 {
2571 while ((item = map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none))
2572 {
2573 dbg(0, "NAV_TURNAROUND:008a:%s\n", item_to_name(item->type));
2574 }
2575
2576 dbg(0, "NAV_TURNAROUND:008b:item=%p\n", item);
2577
2578 if (item && item_attr_get(item, attr_navigation_speech, &attr)) // this calls --> navigation_map_item_attr_get(...) --> show_next_maneuvers(...)
2579 {
2580 //dbg(0,"say(2) s=X%sX\n", attr.u.str);
2581
2582 dbg(0, "NAV_TURNAROUND:009:%s\n", attr.u.str);
2583
2584 if (strlen(attr.u.str) > 0)
2585 {
2586 speech_say(this_->speech, attr.u.str);
2587 }
2588 //navit_add_message(this_, attr.u.str);
2589 // navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
2590 }
2591 map_rect_destroy(mr);
2592 }
2593 }
2594
2595 static void navit_window_roadbook_update(struct navit *this_)
2596 {
2597
2598
2599 ////DBG dbg(0,"EEnter\n");
2600 struct navigation *nav = this_->navigation;
2601 struct map *map = NULL;
2602 struct map_rect *mr = NULL;
2603 struct item *item;
2604 struct attr attr;
2605 struct param_list param[5];
2606 int secs;
2607
2608 // dbg(1, "enter\n");
2609 datawindow_mode(this_->roadbook_window, 1);
2610 if (nav)
2611 map = navigation_get_map(nav);
2612 if (map)
2613 mr = map_rect_new(map, NULL);
2614 ////DBG dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
2615 if (mr)
2616 {
2617 ////DBG dbg(0,"while loop\n");
2618 while ((item = map_rect_get_item(mr)))
2619 {
2620 ////DBG dbg(0,"item=%p\n", item);
2621 attr.u.str = NULL;
2622 if (item->type != type_nav_position)
2623 {
2624 item_attr_get(item, attr_navigation_long, &attr);
2625 if (attr.u.str == NULL)
2626 {
2627 continue;
2628 }
2629 dbg(2, "Command='%s'\n", attr.u.str);
2630 param[0].value = g_strdup(attr.u.str);
2631 }
2632 else
2633 param[0].value = _("Position");
2634 param[0].name = _("Command");
2635
2636 item_attr_get(item, attr_length, &attr);
2637 dbg(2, "Length=%d\n", attr.u.num);
2638 param[1].name = _("Length");
2639
2640 if (attr.u.num >= 2000)
2641 {
2642 param[1].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km"));
2643 }
2644 else
2645 {
2646 param[1].value = g_strdup_printf("%7d %s", attr.u.num, _("m"));
2647 }
2648
2649 item_attr_get(item, attr_time, &attr);
2650 dbg(2, "Time=%d\n", attr.u.num);
2651 secs = attr.u.num / 10;
2652 param[2].name = _("Time");
2653 if (secs >= 3600)
2654 {
2655 param[2].value = g_strdup_printf("%d:%02d:%02d", secs / 60, (secs / 60) % 60, secs % 60);
2656 }
2657 else
2658 {
2659 param[2].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60);
2660 }
2661
2662 item_attr_get(item, attr_destination_length, &attr);
2663 dbg(2, "Destlength=%d\n", attr.u.num);
2664 param[3].name = _("Destination Length");
2665 if (attr.u.num >= 2000)
2666 {
2667 param[3].value = g_strdup_printf("%5.1f %s", (float) attr.u.num / 1000, _("km"));
2668 }
2669 else
2670 {
2671 param[3].value = g_strdup_printf("%d %s", attr.u.num, _("m"));
2672 }
2673
2674 item_attr_get(item, attr_destination_time, &attr);
2675 dbg(2, "Desttime=%d\n", attr.u.num);
2676 secs = attr.u.num / 10;
2677 param[4].name = _("Destination Time");
2678 if (secs >= 3600)
2679 {
2680 param[4].value = g_strdup_printf("%d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60);
2681 }
2682 else
2683 {
2684 param[4].value = g_strdup_printf("%d:%02d", secs / 60, secs % 60);
2685 }
2686 datawindow_add(this_->roadbook_window, param, 5);
2687 }
2688 map_rect_destroy(mr);
2689 }
2690 datawindow_mode(this_->roadbook_window, 0);
2691 }
2692
2693 void navit_window_roadbook_destroy(struct navit *this_)
2694 {
2695
2696
2697 ////DBG dbg(0, "enter\n");
2698 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
2699 this_->roadbook_window = NULL;
2700 this_->roadbook_callback = NULL;
2701 }
2702
2703 void navit_window_roadbook_new(struct navit *this_)
2704 {
2705
2706
2707 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window)
2708 {
2709 return;
2710 }
2711
2712 this_->roadbook_callback = callback_new_1(callback_cast(navit_window_roadbook_update), this_);
2713 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
2714 this_->roadbook_window = gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
2715 navit_window_roadbook_update(this_);
2716 }
2717
2718 void navit_remove_all_maps(struct navit *this_)
2719 {
2720
2721
2722
2723 dbg(0,"ROUTExxPOSxx:navit_remove_all_maps:enter\n");
2724
2725 struct mapset *ms;
2726 struct map *map3;
2727
2728 // hold map drawing
2729 // this_->ready = 1;
2730
2731 // first: stop navigation!
2732 //if (global_navit->destination_valid != 0)
2733 //{
2734 navit_set_destination(global_navit, NULL, NULL, 0);
2735 //}
2736
2737
2738 if (this_->tracking)
2739 {
2740 tracking_flush(this_->tracking);
2741 }
2742
2743 if (this_->route)
2744 {
2745 struct attr callback;
2746 // this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
2747
2748
2749 callback.type = attr_callback;
2750 callback.u.callback = this_->route_cb;
2751 route_remove_attr(this_->route, &callback);
2752
2753 this_->route->ms = NULL;
2754 // route_set_mapset(this_->route, ms);
2755 // route_set_projection(this_->route, transform_get_projection(this_->trans));
2756
2757 //*********route_destroy(this_->route);
2758
2759 //route_path_destroy(this_->route->path2,1);
2760 //this_->route->path2 = NULL;
2761 //route_graph_destroy(this_->route->graph);
2762 //this_->route->graph=NULL;
2763 }
2764
2765 /*
2766 map_rect_destroy(displaylist->mr);
2767 if (!route_selection)
2768 map_selection_destroy(displaylist->sel);
2769 mapset_close(displaylist->msh);
2770 displaylist->mr=NULL;
2771 displaylist->sel=NULL;
2772 displaylist->m=NULL;
2773 displaylist->msh=NULL;
2774 profile(1,"callback\n");
2775 callback_call_1(displaylist->cb, cancel);
2776 */
2777
2778 struct displaylist *dl = navit_get_displaylist(this_);
2779 dl->m = NULL;
2780 dl->msh = NULL;
2781
2782 if (this_->mapsets)
2783 {
2784 struct mapset_handle *msh;
2785 ms = this_->mapsets->data;
2786 msh = mapset_open(ms);
2787 ////DBG dbg(0,"removing map bb0\n");
2788 while (msh && (map3 = mapset_next(msh, 0)))
2789 {
2790 ////DBG dbg(0,"removing map bb1\n");
2791 struct attr map_name_attr;
2792 if (map_get_attr(map3, attr_name, &map_name_attr, NULL))
2793 {
2794 //DBG dbg(0, "map name=%s", map_name_attr.u.str);
2795 if (strncmp("_ms_sdcard_map:", map_name_attr.u.str, 15) == 0)
2796 {
2797 dbg(0, "removing map name=%s", map_name_attr.u.str);
2798 //DBG dbg(0, "removing map a0\n");
2799 struct attr active;
2800 active.type = attr_active;
2801 active.u.num = 0;
2802 //map_set_attr(map3, &active);
2803
2804 //DBG dbg(0, "removing map a1\n");
2805 struct attr map_attr;
2806 map_attr.u.map = map3;
2807 map_attr.type = attr_map;
2808 mapset_remove_attr(ms, &map_attr);
2809
2810 //DBG dbg(0, "removing map a2\n");
2811 map3->refcount = 1;
2812 map_destroy(map3);
2813 //DBG dbg(0, "removing map a3\n");
2814 map3 = NULL;
2815 }
2816 else if (strncmp("-special-:", map_name_attr.u.str, 10) == 0)
2817 {
2818 dbg(0, "removing (special) map name=%s", map_name_attr.u.str);
2819 struct attr active;
2820 active.type = attr_active;
2821 active.u.num = 0;
2822
2823 struct attr map_attr;
2824 map_attr.u.map = map3;
2825 map_attr.type = attr_map;
2826 mapset_remove_attr(ms, &map_attr);
2827
2828 map3->refcount = 1;
2829 map_destroy(map3);
2830 map3 = NULL;
2831 }
2832 }
2833 }
2834 mapset_close(msh);
2835 //DBG dbg(0, "removing map bb4\n");
2836 }
2837
2838 dl->ms = this_->mapsets->data;
2839
2840 // int async = 0;
2841 // transform_setup_source_rect(this_->trans);
2842 // graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
2843 //this_->displaylist->ms=this_->mapsets->data;
2844
2845 }
2846
2847 void navit_map_active_flag(struct navit *this_, int activate, const char *mapname)
2848 {
2849 // activate = 0 -> deactivate
2850 // activate = 1 -> activate
2851
2852
2853
2854 struct mapset *ms;
2855 struct map *map3;
2856
2857 if (this_->mapsets)
2858 {
2859 struct mapset_handle *msh;
2860 ms = this_->mapsets->data;
2861 msh = mapset_open(ms);
2862 while (msh && (map3 = mapset_next(msh, 0)))
2863 {
2864 struct attr map_name_attr;
2865 if (map_get_attr(map3, attr_name, &map_name_attr, NULL))
2866 {
2867 dbg(0, "map name=%s\n", map_name_attr.u.str);
2868 if (strcmp(mapname, map_name_attr.u.str) == 0)
2869 {
2870 dbg(0, "setting active flag on map:%s\n", map_name_attr.u.str);
2871
2872 struct attr active;
2873 active.type = attr_active;
2874 active.u.num = activate;
2875 map_set_attr(map3, &active);
2876 }
2877 }
2878 }
2879 mapset_close(msh);
2880 }
2881
2882 }
2883
2884 void navit_add_all_maps(struct navit *this_)
2885 {
2886 __F_START__
2887
2888 struct map *map3;
2889
2890 if (this_->mapsets)
2891 {
2892 //DBG dbg(0, "xADDx all maps - start\n");
2893
2894 struct mapset *ms;
2895 ms = this_->mapsets->data;
2896
2897 struct attr type;
2898 struct attr parent;
2899 struct attr data;
2900 struct attr flags;
2901 struct map *map2;
2902 struct attr map2_attr;
2903 struct attr *attrs[4];
2904 char *map_file;
2905
2906 dbg(0, "001\n");
2907
2908 parent.type = attr_navit;
2909 parent.u.navit = this_;
2910 type.type = attr_type;
2911 type.u.str = "binfile";
2912 data.type = attr_data;
2913 map_file = g_strdup_printf("%sborders.bin", navit_maps_dir);
2914 data.u.str = map_file;
2915
2916 ////DBG dbg(0,"map name=%s",map_file);
2917
2918 flags.type = attr_flags;
2919 flags.u.num = 0;
2920 attrs[0] = &type;
2921 attrs[1] = &data;
2922 attrs[2] = &flags;
2923 attrs[3] = NULL;
2924 map2 = map_new(&parent, attrs);
2925 if (map2)
2926 {
2927 map2_attr.u.data = map2;
2928 map2_attr.type = attr_map;
2929 // mapset_add_attr_name(ms, &map2_attr);
2930 mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/borders.bin");
2931 struct attr active;
2932 active.type = attr_active;
2933 active.u.num = 0;
2934 //map_set_attr(map2, &active);
2935
2936 active.type = attr_route_active;
2937 active.u.num = 0; // by default deactivate rounting on this map
2938 map_set_attr(map2, &active);
2939 }
2940 g_free(map_file);
2941
2942
2943
2944 /*
2945 parent.type = attr_navit;
2946 parent.u.navit = this_;
2947 type.type = attr_type;
2948 type.u.str = "binfile";
2949 data.type = attr_data;
2950 map_file = g_strdup_printf("%scoastline.bin", navit_maps_dir);
2951 data.u.str = map_file;
2952
2953 ////DBG dbg(0,"map name=%s",map_file);
2954
2955 flags.type = attr_flags;
2956 flags.u.num = 0;
2957 attrs[0] = &type;
2958 attrs[1] = &data;
2959 attrs[2] = &flags;
2960 attrs[3] = NULL;
2961 map2 = map_new(&parent, attrs);
2962 if (map2)
2963 {
2964 map2_attr.u.data = map2;
2965 map2_attr.type = attr_map;
2966 // mapset_add_attr_name(ms, &map2_attr);
2967 mapset_add_attr_name_str(ms, &map2_attr, "/sdcard/zanavi/maps/coastline.bin");
2968 struct attr active;
2969 active.type = attr_active;
2970 active.u.num = 0;
2971 //map_set_attr(map2, &active);
2972
2973 active.type = attr_route_active;
2974 active.u.num = 0; // by default deactivate rounting on this map
2975 map_set_attr(map2, &active);
2976 }
2977 g_free(map_file);
2978
2979
2980 */
2981
2982
2983 // gpx tracks map --------------------
2984 parent.type = attr_navit;
2985 parent.u.navit = this_;
2986 type.type = attr_type;
2987 type.u.str = "textfile";
2988 data.type = attr_data;
2989 map_file = g_strdup_printf("%sgpxtracks.txt", navit_maps_dir);
2990 data.u.str = map_file;
2991
2992 flags.type = attr_flags;
2993 flags.u.num = 0;
2994 attrs[0] = &type;
2995 attrs[1] = &data;
2996 attrs[2] = &flags;
2997 attrs[3] = NULL;
2998 map2 = map_new(&parent, attrs);
2999 if (map2)
3000 {
3001 map2_attr.u.data = map2;
3002 map2_attr.type = attr_map;
3003 mapset_add_attr_name_str(ms, &map2_attr, "-special-:gpxtracks.txt");
3004 struct attr active;
3005 active.type = attr_active;
3006 active.u.num = 0;
3007 //map_set_attr(map2, &active);
3008 }
3009 g_free(map_file);
3010 // gpx tracks map --------------------
3011
3012
3013 // traffic map --------------------
3014 parent.type = attr_navit;
3015 parent.u.navit = this_;
3016 type.type = attr_type;
3017 type.u.str = "textfile";
3018 data.type = attr_data;
3019 map_file = g_strdup_printf("%straffic.txt", navit_maps_dir);
3020 data.u.str = map_file;
3021
3022 flags.type = attr_flags;
3023 flags.u.num = 0;
3024 attrs[0] = &type;
3025 attrs[1] = &data;
3026 attrs[2] = &flags;
3027 attrs[3] = NULL;
3028 map2 = map_new(&parent, attrs);
3029 if (map2)
3030 {
3031 map2_attr.u.data = map2;
3032 map2_attr.type = attr_map;
3033 mapset_add_attr_name_str(ms, &map2_attr, "-special-:traffic.txt");
3034 struct attr active;
3035 active.type = attr_active;
3036 active.u.num = 0;
3037 //map_set_attr(map2, &active);
3038 }
3039 g_free(map_file);
3040 // traffic map --------------------
3041
3042
3043 dbg(0, "002\n");
3044
3045
3046 // world map2 --------------------
3047 parent.type = attr_navit;
3048 parent.u.navit = this_;
3049 type.type = attr_type;
3050 type.u.str = "textfile";
3051 data.type = attr_data;
3052 map_file = g_strdup_printf("%sworldmap2.txt", navit_maps_dir);
3053 data.u.str = map_file;
3054
3055 dbg(0, "activate map:%s\n", map_file);
3056
3057 flags.type = attr_flags;
3058 flags.u.num = 0;
3059 attrs[0] = &type;
3060 attrs[1] = &data;
3061 attrs[2] = &flags;
3062 attrs[3] = NULL;
3063 map2 = map_new(&parent, attrs);
3064 if (map2)
3065 {
3066 map2_attr.u.data = map2;
3067 map2_attr.type = attr_map;
3068 mapset_add_attr_name_str(ms, &map2_attr, "-special-:worldmap2.txt");
3069 struct attr active;
3070 active.type = attr_active;
3071 active.u.num = 1; // by default activate map
3072 // map_set_attr(map2, &active);
3073
3074 active.type = attr_route_active;
3075 active.u.num = 0; // by default deactivate routing on this map
3076 map_set_attr(map2, &active);
3077
3078 }
3079 g_free(map_file);
3080 // world map2 --------------------
3081
3082
3083 // world map5 --------------------
3084 parent.type = attr_navit;
3085 parent.u.navit = this_;
3086 type.type = attr_type;
3087 type.u.str = "textfile";
3088 data.type = attr_data;
3089 map_file = g_strdup_printf("%sworldmap5.txt", navit_maps_dir);
3090 data.u.str = map_file;
3091
3092 dbg(0, "activate map:%s\n", map_file);
3093
3094 flags.type = attr_flags;
3095 flags.u.num = 0;
3096 attrs[0] = &type;
3097 attrs[1] = &data;
3098 attrs[2] = &flags;
3099 attrs[3] = NULL;
3100 map2 = map_new(&parent, attrs);
3101 if (map2)
3102 {
3103 map2_attr.u.data = map2;
3104 map2_attr.type = attr_map;
3105 mapset_add_attr_name_str(ms, &map2_attr, "-special-:worldmap5.txt");
3106 struct attr active;
3107 active.type = attr_active;
3108 active.u.num = 1; // by default activate map
3109 // map_set_attr(map2, &active);
3110
3111 active.type = attr_route_active;
3112 active.u.num = 0; // by default deactivate routing on this map
3113 map_set_attr(map2, &active);
3114 }
3115 g_free(map_file);
3116 // world map5 --------------------
3117
3118 dbg(0, "003\n");
3119
3120
3121 #if 0
3122 // world map6 --------------------
3123 parent.type = attr_navit;
3124 parent.u.navit = this_;
3125 type.type = attr_type;
3126 type.u.str = "textfile";
3127 data.type = attr_data;
3128 map_file = g_strdup_printf("%sworldmap6.txt", navit_maps_dir);
3129 data.u.str = map_file;
3130
3131 dbg(0, "activate map:%s\n", map_file);
3132
3133 flags.type = attr_flags;
3134 flags.u.num = 0;
3135 attrs[0] = &type;
3136 attrs[1] = &data;
3137 attrs[2] = &flags;
3138 attrs[3] = NULL;
3139 map2 = map_new(&parent, attrs);
3140 if (map2)
3141 {
3142 map2_attr.u.data = map2;
3143 map2_attr.type = attr_map;
3144 mapset_add_attr_name_str(ms, &map2_attr, "-special-:worldmap6.txt");
3145 struct attr active;
3146 active.type = attr_active;
3147 active.u.num = 1; // by default activate map
3148 // map_set_attr(map2, &active);
3149
3150 active.type = attr_route_active;
3151 active.u.num = 0; // by default deactivate routing on this map
3152 map_set_attr(map2, &active);
3153 }
3154 g_free(map_file);
3155 // world map6 --------------------
3156 #endif
3157
3158 dbg(0, "004\n");
3159
3160
3161 int i = 1;
3162 for (i = 1; i < 10; i++)
3163 {
3164 struct map *map22;
3165 struct attr map22_attr;
3166 parent.type = attr_navit;
3167 parent.u.navit = this_;
3168 type.type = attr_type;
3169 type.u.str = "binfile";
3170 data.type = attr_data;
3171 map_file = g_strdup_printf("%snavitmap_00%d.bin", navit_maps_dir, i);
3172 data.u.str = map_file;
3173 flags.type = attr_flags;
3174 flags.u.num = 0;
3175 attrs[0] = &type;
3176 attrs[1] = &data;
3177 attrs[2] = &flags;
3178 attrs[3] = NULL;
3179 map22 = map_new(&parent, attrs);
3180 if (map22)
3181 {
3182 //DBG dbg(0, "*add* map name=%s\n", map_file);
3183 map22_attr.u.data = map22;
3184 map22_attr.type = attr_map;
3185 // mapset_add_attr_name(ms, &map22_attr);
3186 char *map_name_str;
3187 map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_00%d.bin", i);
3188 mapset_add_attr_name_str(ms, &map22_attr, map_name_str);
3189 struct attr active;
3190 active.type = attr_active;
3191 active.u.num = 0;
3192 //map_set_attr(map22, &active);
3193 g_free(map_name_str);
3194 }
3195 g_free(map_file);
3196 }
3197
3198 i = 10;
3199 for (i = 10; i < 61; i++)
3200 {
3201 parent.type = attr_navit;
3202 parent.u.navit = this_;
3203 type.type = attr_type;
3204 type.u.str = "binfile";
3205 data.type = attr_data;
3206 map_file = g_strdup_printf("%snavitmap_0%d.bin", navit_maps_dir, i);
3207 data.u.str = map_file;
3208 ////DBG dbg(0,"map name=%s",map_file);
3209 flags.type = attr_flags;
3210 flags.u.num = 0;
3211 attrs[0] = &type;
3212 attrs[1] = &data;
3213 attrs[2] = &flags;
3214 attrs[3] = NULL;
3215 map2 = map_new(&parent, attrs);
3216 if (map2)
3217 {
3218 map2_attr.u.data = map2;
3219 map2_attr.type = attr_map;
3220 // mapset_add_attr_name(ms, &map2_attr);
3221 char *map_name_str;
3222 map_name_str = g_strdup_printf("/sdcard/zanavi/maps/navitmap_0%d.bin", i);
3223 mapset_add_attr_name_str(ms, &map2_attr, map_name_str);
3224 struct attr active;
3225 active.type = attr_active;
3226 active.u.num = 0;
3227 //map_set_attr(map2, &active);
3228 g_free(map_name_str);
3229 }
3230 g_free(map_file);
3231 }
3232 }
3233
3234 /*
3235 if (this_->mapsets)
3236 {
3237 struct mapset_handle *msh;
3238 struct map *map;
3239 struct mapset *ms;
3240
3241 //DBG dbg(0,"xx ms callbacks xx\n");
3242
3243 ms=this_->mapsets->data;
3244 this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
3245 msh=mapset_open(ms);
3246 while (msh && (map=mapset_next(msh, 0)))
3247 {
3248 //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
3249 struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
3250 map_add_callback(map, pcb);
3251 }
3252 mapset_close(msh);
3253 }
3254 */
3255
3256 /*
3257 struct attr parent;
3258 parent.type = attr_navit;
3259 parent.u.navit = global_navit;
3260
3261 struct attr *attrs_r[2];
3262 attrs_r[0] = NULL;
3263 attrs_r[1] = NULL;
3264 */
3265
3266 //***this_->route = route_new(&parent, attrs_r);
3267
3268
3269 //int async = 0;
3270 //transform_setup_source_rect(this_->trans);
3271 //graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
3272
3273 if (this_->mapsets)
3274 {
3275 dbg(0, "005\n");
3276
3277 struct displaylist *dl = navit_get_displaylist(this_);
3278 dbg(0, "005a dl=%p\n", dl);
3279 dbg(0, "005a1 ms=%p\n", this_->mapsets);
3280 dbg(0, "005a2 ms=%p\n", this_->mapsets->data);
3281 dl->ms = this_->mapsets->data;
3282 dbg(0, "005b\n");
3283 dl->m = NULL;
3284 dbg(0, "005c\n");
3285 dl->msh = NULL;
3286
3287 dbg(0, "005.1\n");
3288
3289 if (this_->route)
3290 {
3291 dbg(0, "005.2\n");
3292
3293 struct mapset *ms;
3294 dbg(0, "005.3\n");
3295 ms = this_->mapsets->data;
3296 dbg(0, "005.4\n");
3297 route_set_mapset(this_->route, ms);
3298
3299 dbg(0, "005.5\n");
3300
3301 struct attr callback;
3302 this_->route_cb = callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
3303 dbg(0, "005.6\n");
3304 callback_add_names(this_->route_cb, "navit_add_all_maps", "navit_redraw_route");
3305 dbg(0, "005.7\n");
3306 callback.type = attr_callback;
3307 dbg(0, "005.8\n");
3308 callback.u.callback = this_->route_cb;
3309 dbg(0, "005.9\n");
3310 route_add_attr(this_->route, &callback);
3311 dbg(0, "005.10\n");
3312 // ***** route_set_projection(this_->route, transform_get_projection(this_->trans));
3313
3314
3315 }
3316
3317
3318 dbg(0, "006\n");
3319
3320
3321 if (this_->tracking)
3322 {
3323 struct mapset *ms;
3324 ms = this_->mapsets->data;
3325
3326 tracking_set_mapset(this_->tracking, ms);
3327 if (this_->route)
3328 {
3329 tracking_set_route(this_->tracking, this_->route);
3330 }
3331 }
3332
3333 }
3334
3335 // ready for drawing map
3336 // this_->ready = 3;
3337
3338 // draw map
3339 // navit_draw(this_);
3340
3341 __F_END__
3342 }
3343
3344 void navit_reload_maps(struct navit *this_)
3345 {
3346
3347
3348
3349 dbg(0,"ROUTExxPOSxx:navit_reload_maps:enter\n");
3350
3351 navit_remove_all_maps(this_);
3352 navit_add_all_maps(this_);
3353 }
3354
3355
3356 // --- forward def ----
3357 void navit_set_vehicle_position_to_screen_center(struct navit *this_);
3358 // --- forward def ----
3359
3360 void navit_init(struct navit *this_)
3361 {
3362
3363
3364 ////DBG dbg(0,"EEnter\n");
3365 struct mapset *ms;
3366 struct map *map;
3367 int callback;
3368 char *center_file;
3369
3370 // dbg(0,"GGGGG:set global_navit\n");
3371 // global_navit = this_;
3372
3373 // default value
3374 navit_maps_dir = "/sdcard/zanavi/maps/";
3375
3376 global_img_waypoint = NULL;
3377
3378 //DBG dbg(0, "enter gui %p graphics %p\n", this_->gui, this_->gra);
3379
3380 if (!this_->gui && !(this_->flags & 2))
3381 {
3382 dbg(0, "no gui\n");
3383 navit_destroy(this_);
3384 return;
3385 }
3386
3387 if (!this_->gra && !(this_->flags & 1))
3388 {
3389 dbg(0, "no graphics\n");
3390 navit_destroy(this_);
3391 return;
3392 }
3393
3394
3395 #ifdef NAVIT_FREE_TEXT_DEBUG_PRINT
3396 dbg(0, "DEST::route_clear_freetext_list(000)\n");
3397 route_clear_freetext_list();
3398 #endif
3399
3400
3401 //DBG dbg(0, "Connecting gui to graphics\n");
3402
3403 if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra))
3404 {
3405 struct attr attr_type_gui, attr_type_graphics;
3406 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
3407 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
3408
3409 dbg(0, "failed to connect to graphics\n");
3410 navit_destroy(this_);
3411 return;
3412 }
3413
3414 if (this_->speech && this_->navigation)
3415 {
3416 struct attr speech;
3417 speech.type = attr_speech;
3418 speech.u.speech = this_->speech;
3419 navigation_set_attr(this_->navigation, &speech);
3420 }
3421
3422 //DBG dbg(0, "Initializing graphics\n");
3423 //DBG dbg(0, "Setting Vehicle\n");
3424 navit_set_vehicle(this_, this_->vehicle);
3425
3426 //DBG dbg(0, "Adding dynamic maps to mapset %p\n", this_->mapsets);
3427 if (this_->mapsets)
3428 {
3429 struct mapset_handle *msh;
3430 ms = this_->mapsets->data;
3431 // **D** // this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
3432 msh = mapset_open(ms);
3433 while (msh && (map = mapset_next(msh, 0)))
3434 {
3435 //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
3436 // **D** // struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
3437 // **D** // map_add_callback(map, pcb);
3438 }
3439 mapset_close(msh);
3440
3441 if (this_->route)
3442 {
3443 if ((map = route_get_map(this_->route)))
3444 {
3445 struct attr map_a, map_name;
3446 map_a.type = attr_map;
3447 map_a.u.map = map;
3448 map_name.type = attr_name;
3449 map_name.u.str = "_ms_route";
3450 map_set_attr(map_a.u.map, &map_name);
3451 mapset_add_attr(ms, &map_a);
3452 }
3453
3454 if ((map = route_get_graph_map(this_->route)))
3455 {
3456 struct attr map_a, active, map_name;
3457 map_a.type = attr_map;
3458 map_a.u.map = map;
3459 active.type = attr_active;
3460 active.u.num = 0;
3461 map_name.type = attr_name;
3462 map_name.u.str = "_ms_route_graph";
3463 map_set_attr(map_a.u.map, &map_name);
3464 mapset_add_attr(ms, &map_a);
3465 map_set_attr(map, &active);
3466 }
3467 route_set_mapset(this_->route, ms);
3468 route_set_projection(this_->route, transform_get_projection(this_->trans));
3469 }
3470
3471 if (this_->tracking)
3472 {
3473 tracking_set_mapset(this_->tracking, ms);
3474 if (this_->route)
3475 {
3476 tracking_set_route(this_->tracking, this_->route);
3477 }
3478 }
3479
3480 if (this_->navigation)
3481 {
3482 if ((map = navigation_get_map(this_->navigation)))
3483 {
3484 struct attr map_a, active, map_name;
3485 map_a.type = attr_map;
3486 map_a.u.map = map;
3487 active.type = attr_active;
3488 active.u.num = 0;
3489 map_name.type = attr_name;
3490 map_name.u.str = "_ms_navigation";
3491 map_set_attr(map_a.u.map, &map_name);
3492 mapset_add_attr(ms, &map_a);
3493 map_set_attr(map, &active);
3494 }
3495 }
3496
3497 if (this_->tracking)
3498 {
3499 if ((map = tracking_get_map(this_->tracking)))
3500 {
3501 struct attr map_a, active, map_name;
3502 map_a.type = attr_map;
3503 map_a.u.map = map;
3504 active.type = attr_active;
3505 active.u.num = 0;
3506 map_name.type = attr_name;
3507 map_name.u.str = "_ms_tracking";
3508 map_set_attr(map_a.u.map, &map_name);
3509 mapset_add_attr(ms, &map_a);
3510 map_set_attr(map, &active);
3511 }
3512 }
3513 // *DISABLED* navit_add_former_destinations_from_file(this_);
3514 }
3515
3516 if (this_->route)
3517 {
3518 /*
3519 *DISABLED* done in "navit_add_all_maps"
3520
3521 struct attr callback;
3522 this_->route_cb = callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
3523 callback_add_names(this_->route_cb, "navit_init", "navit_redraw_route");
3524 callback.type = attr_callback;
3525 callback.u.callback = this_->route_cb;
3526 route_add_attr(this_->route, &callback);
3527 */
3528 }
3529
3530 if (this_->navigation)
3531 {
3532 if (this_->speech)
3533 {
3534 this_->nav_speech_cb = callback_new_1(callback_cast(navit_speak), this_);
3535 callback_add_names(this_->nav_speech_cb, "navit_init", "navit_speak");
3536 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
3537 }
3538
3539 if (this_->route)
3540 {
3541 navigation_set_route(this_->navigation, this_->route);
3542 }
3543 }
3544
3545 dbg(0, "Setting Center\n");
3546 center_file = bookmarks_get_center_file(FALSE);
3547 //dbg(0, "g0\n");
3548 bookmarks_set_center_from_file(this_->bookmarks, center_file);
3549 g_free(center_file);
3550
3551 dbg(0, "Set Vehicle Position to Center\n");
3552 navit_set_vehicle_position_to_screen_center(this_);
3553
3554 #if 0
3555 if (this_->menubar)
3556 {
3557 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
3558 if (men)
3559 {
3560 navit_add_menu_windows_items(this_, men);
3561 }
3562 }
3563 #endif
3564
3565 #if 0
3566 navit_window_roadbook_new(this_);
3567 navit_window_items_new(this_);
3568 #endif
3569
3570 //dbg(0, "g1\n");
3571 //messagelist_init(this_->messages);
3572
3573 //dbg(0, "g2\n");
3574 navit_set_cursors(this_);
3575
3576 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
3577 callback = (this_->ready == 2);
3578 dbg(0, "pre this_->ready=%d\n", this_->ready);
3579 this_->ready = this_->ready | 1;
3580 dbg(0, "set this_->ready=%d\n", this_->ready);
3581 ////DBG dbg(0,"ready=%d\n",this_->ready);
3582
3583
3584 //if (this_->ready == 3)
3585 //{
3586 // ////DBG dbg(0,"navit_draw_async_003\n");
3587 // navit_draw_async(this_, 1);
3588 //}
3589
3590 dbg(0, "init ready=%d\n", this_->ready);
3591
3592 // draw???????
3593 // dbg(0,"init DRAW 11\n");
3594 // ready to draw map
3595 // navit_draw(this_);
3596 // dbg(0,"init DRAW 22\n");
3597 // draw???????
3598
3599 if (callback)
3600 {
3601 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
3602 }
3603 #if 0
3604 routech_test(this_);
3605 #endif
3606 //dbg(0, "1111111111\n");
3607 }
3608
3609
3610
3611 // ----- forward def! -----
3612 void navit_set_position_without_map_drawing(struct navit *this_, struct pcoord *c);
3613 // ----- forward def! -----
3614
3615 void navit_set_vehicle_position_to_screen_center_only_for_route_struct(struct navit *this_)
3616 {
3617 struct coord c;
3618 char *center_file;
3619 center_file = bookmarks_get_center_file(FALSE);
3620 bookmarks_get_center_from_file(this_->bookmarks, center_file, &c);
3621 g_free(center_file);
3622
3623 struct pcoord pc;
3624 pc.x = c.x;
3625 pc.y = c.y;
3626 pc.pro = transform_get_projection(this_->trans);
3627 // result: pc.x, pc.y
3628
3629 // set position
3630 navit_set_position_without_map_drawing(this_, &pc);
3631 }
3632
3633 void navit_set_vehicle_position_to_screen_center(struct navit *this_)
3634 {
3635
3636 // map center to pixel x,y on screen
3637 // enum projection pro = transform_get_projection(this_->trans);
3638 // struct point pnt;
3639 // struct coord *c992;
3640 // c992 = transform_get_center(this_->trans);
3641 // transform(this_->trans, pro, c992, &pnt, 1, 0, 0, NULL);
3642 // dbg(0, "navit_set_vehicle_position_to_screen_center pnt.x=%d pnt.y=%d\n", pnt.x, pnt.y);
3643 // result: pnt.x, pnt.y
3644
3645
3646 // geo to pixel-on-screen
3647 // struct coord c99;
3648 // struct coord_geo g99;
3649 // g99.lat = lat;
3650 // g99.lng = lon;
3651 // dbg(0,"zzzzz %f, %f\n",a, b);
3652 // dbg(0,"yyyyy %f, %f\n",g99.lat, g99.lng);
3653 // transform_from_geo(projection_mg, &g99, &c99);
3654 // dbg(0,"%d %d %f %f\n",c99.x, c99.y, g99.lat, g99.lng);
3655
3656 // enum projection pro = transform_get_projection(global_navit->trans_cursor);
3657 // struct point pnt;
3658 // transform(global_navit->trans, pro, &c99, &pnt, 1, 0, 0, NULL);
3659 // dbg(0,"x=%d\n",pnt.x);
3660 // dbg(0,"y=%d\n",pnt.y);
3661
3662
3663 struct coord c;
3664 char *center_file;
3665 center_file = bookmarks_get_center_file(FALSE);
3666 bookmarks_get_center_from_file(this_->bookmarks, center_file, &c);
3667 g_free(center_file);
3668
3669
3670 // coord to geo
3671 struct coord_geo g22;
3672 // struct coord c22;
3673 ////DBG // dbg(0,"%f, %f\n",a, b);
3674 ////DBG // dbg(0,"%d, %d\n",p.x, p.y);
3675 transform_to_geo(projection_mg, &c, &g22);
3676 dbg(0,"navit_set_vehicle_position_to_screen_center: %d, %d, %f, %f\n",c.x, c.y, g22.lat, g22.lng);
3677 // result = g_strdup_printf("%f:%f", g22.lat, g22.lng);
3678
3679
3680 // set vehicle position to pixel x,y
3681 //struct point p;
3682 //struct coord c;
3683
3684 // pixel-x
3685 //p.x = pnt.x;
3686 // pixel-y
3687 //p.y = pnt.y;
3688
3689 //transform_reverse(this_->trans, &p, &c);
3690
3691 struct pcoord pc;
3692 pc.x = c.x;
3693 pc.y = c.y;
3694 pc.pro = transform_get_projection(this_->trans);
3695 // result: pc.x, pc.y
3696
3697 // set position
3698 navit_set_position_without_map_drawing(this_, &pc);
3699
3700
3701 //center.pro = projection_screen;
3702 //center.x = 0;
3703 //center.y = 0;
3704 //DBG dbg(0, "veh new 5\n");
3705 // transform_setup(this_->vehicle->vehicle->trans, &pc, 16, 0);
3706 // transform_set_center(this_->vehicle->vehicle->trans, &c);
3707 // zzzzzzzzzzzzzz int vehicle_set_cursor_data_01(struct vehicle *this, struct point *pnt)
3708
3709 if ((this_) && (this_->vehicle))
3710 {
3711 this_->vehicle->coord.x = c.x;
3712 this_->vehicle->coord.y = c.y;
3713 }
3714
3715 if ((this_) && (this_->vehicle) && (this_->vehicle->vehicle))
3716 {
3717 float speed = 0;
3718 float direction = 0;
3719 double height = 0;
3720 float radius = 0;
3721 long gpstime = 0;
3722 vehicle_update_(this_->vehicle->vehicle, g22.lat, g22.lng, speed, direction, height, radius, gpstime);
3723 }
3724 else
3725 {
3726 dbg(0, "navit_set_vehicle_position_to_screen_center: no vehicle set !!\n");
3727 }
3728 }
3729
3730
3731
3732
3733 void navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
3734 {
3735 struct coord c;
3736 int scale = 16;
3737
3738 c.x = (r->rl.x + r->lu.x) / 2;
3739 c.y = (r->rl.y + r->lu.y) / 2;
3740 transform_set_center(this_->trans, &c);
3741
3742 while (scale < 1 << 20)
3743 {
3744 struct point p1, p2;
3745 transform_set_scale(this_->trans, scale);
3746 transform_setup_source_rect(this_->trans);
3747 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
3748 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
3749
3750 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w || p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
3751 {
3752 scale *= 2;
3753 }
3754 else
3755 {
3756 break;
3757 }
3758 }
3759
3760 dbg(0, "scale=%d\n", scale);
3761 dbg(0, "this_->ready=%d\n", this_->ready);
3762
3763 if (this_->ready == 3)
3764 {
3765 // dbg(0,"navit_draw_async_004\n");
3766 //dbg(0,"DO__DRAW:navit_draw_async call\n");
3767 navit_draw_async(this_, 0);
3768 }
3769 }
3770
3771 void navit_zoom_to_route(struct navit *this_, int orientation)
3772 {
3773 struct map *map;
3774 struct map_rect *mr = NULL;
3775 struct item *item;
3776 struct coord c;
3777 struct coord_rect r;
3778 int count = 0;
3779
3780 if (!this_->route)
3781 {
3782 return;
3783 }
3784
3785 map = route_get_map(this_->route);
3786
3787 if (map)
3788 {
3789 mr = map_rect_new(map, NULL);
3790 }
3791
3792 if (mr)
3793 {
3794 while ((item = map_rect_get_item(mr)))
3795 {
3796 while (item_coord_get(item, &c, 1))
3797 {
3798 if (!count)
3799 {
3800 r.lu = r.rl = c;
3801 }
3802 else
3803 {
3804 coord_rect_extend(&r, &c);
3805 }
3806 count++;
3807 }
3808 }
3809 map_rect_destroy(mr);
3810 }
3811
3812 if (!count)
3813 {
3814 return;
3815 }
3816
3817 if (orientation != -1)
3818 {
3819 transform_set_yaw(this_->trans, orientation);
3820 }
3821
3822 // if overspill > 1 ?
3823 if (global_overspill_factor > 1.0f)
3824 {
3825 coord_rect_extend_by_percent(&r, (global_overspill_factor - 1.0f));
3826 }
3827
3828 navit_zoom_to_rect(this_, &r);
3829 }
3830
3831 static void navit_cmd_zoom_to_route(struct navit *this)
3832 {
3833
3834
3835 ////DBG dbg(0,"EEnter\n");
3836 navit_zoom_to_route(this, 0);
3837 }
3838
3839 /**
3840 * show point on map
3841 *
3842 * @param navit The navit instance
3843 * @param center The point where to center the map, including its projection
3844 * @returns nothing
3845 */
3846 void navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
3847 {
3848
3849
3850 ////DBG dbg(0,"EEnter\n");
3851 struct coord *c = transform_center(this_->trans);
3852 struct coord c1, c2;
3853 enum projection pro = transform_get_projection(this_->trans);
3854
3855 if (pro != center->pro)
3856 {
3857 c1.x = center->x;
3858 c1.y = center->y;
3859 transform_from_to(&c1, center->pro, &c2, pro);
3860 }
3861 else
3862 {
3863 c2.x = center->x;
3864 c2.y = center->y;
3865 }
3866
3867 *c = c2;
3868 if (set_timeout)
3869 {
3870 navit_set_timeout(this_);
3871 }
3872
3873 if (this_->ready == 3)
3874 {
3875 navit_draw(this_);
3876 }
3877 }
3878
3879
3880 void navit_set_center_no_draw(struct navit *this_, struct pcoord *center, int set_timeout)
3881 {
3882
3883
3884 ////DBG dbg(0,"EEnter\n");
3885 struct coord *c = transform_center(this_->trans);
3886 struct coord c1, c2;
3887 enum projection pro = transform_get_projection(this_->trans);
3888
3889 if (pro != center->pro)
3890 {
3891 c1.x = center->x;
3892 c1.y = center->y;
3893 transform_from_to(&c1, center->pro, &c2, pro);
3894 }
3895 else
3896 {
3897 c2.x = center->x;
3898 c2.y = center->y;
3899 }
3900
3901 *c = c2;
3902 if (set_timeout)
3903 {
3904 navit_set_timeout(this_);
3905 }
3906 }
3907
3908 static void navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
3909 {
3910
3911
3912 ////DBG dbg(0,"EEnter\n");
3913 int width, height;
3914 struct point po;
3915 transform_set_center(this_->trans, c);
3916 transform_get_size(this_->trans, &width, &height);
3917 po.x = width / 2;
3918 po.y = height / 2;
3919 update_transformation(this_->trans, &po, p, NULL);
3920 if (set_timeout)
3921 {
3922 navit_set_timeout(this_);
3923 }
3924 }
3925
3926 /**
3927 * Links all vehicles to a cursor depending on the current profile.
3928 *
3929 * @param this_ A navit instance
3930 * @author Ralph Sennhauser (10/2009)
3931 */
3932 void navit_set_cursors(struct navit *this_)
3933 {
3934
3935
3936 struct attr name;
3937 struct navit_vehicle *nv;
3938 struct cursor *c;
3939 GList *v;
3940
3941 //dbg(0, "Enter\n");
3942
3943 v = g_list_first(this_->vehicles); // GList of navit_vehicles
3944 while (v)
3945 {
3946 dbg(0, "* found vehicle *\n");
3947 nv = v->data;
3948 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL))
3949 {
3950 if (!strcmp(name.u.str, "none"))
3951 {
3952 c = NULL;
3953 }
3954 else
3955 {
3956 c = layout_get_cursor(this_->layout_current, name.u.str);
3957 }
3958 }
3959 else
3960 {
3961 c = layout_get_cursor(this_->layout_current, "default");
3962 }
3963 vehicle_set_cursor(nv->vehicle, c, 0);
3964 v = g_list_next(v);
3965 }
3966 return;
3967 }
3968
3969 void navit_remove_cursors(struct navit *this_)
3970 {
3971
3972
3973 struct attr name;
3974 struct navit_vehicle *nv;
3975 struct cursor *c;
3976 GList *v;
3977
3978 //dbg(0, "Enter\n");
3979 name.type = attr_cursor;
3980
3981 v = g_list_first(this_->vehicles); // GList of navit_vehicles
3982 while (v)
3983 {
3984 dbg(0, "* found vehicle *\n");
3985 nv = v->data;
3986 vehicle_remove_attr(nv->vehicle, &name);
3987 v = g_list_next(v);
3988 }
3989 return;
3990 }
3991
3992 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
3993 {
3994 //// dbg(0,"EEnter\n");
3995
3996 int width, height;
3997 struct navit_vehicle *nv = this_->vehicle;
3998
3999 // valid values: 0 - 50 (0 -> center of screen, 50 -> bottom of screen)
4000 // float offset = this_->radius; // Cursor offset from the center of the screen (percent). // percent of what??
4001
4002 float offset = 0;
4003
4004
4005 #if 0
4006
4007 /* 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 */
4008 float min_offset = 0.; // Percent offset at min_offset_speed.
4009 float max_offset = 30.; // Percent offset at max_offset_speed.
4010 int min_offset_speed = 2; // Speed in km/h
4011 int max_offset_speed = 50; // Speed ini km/h
4012 // Calculate cursor offset from the center of the screen, upon speed.
4013 if (nv->speed <= min_offset_speed)
4014 {
4015 offset = min_offset;
4016 }
4017 else if (nv->speed > max_offset_speed)
4018 {
4019 offset = max_offset;
4020 }
4021 else
4022 {
4023 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
4024 }
4025
4026 #endif
4027
4028 transform_get_size(this_->trans, &width, &height);
4029
4030 if (height == 0)
4031 {
4032 offset = 0;
4033 }
4034 else
4035 {
4036 // dbg(0, "VEHICLE_OFFSET:a:r=%d %d %d\n", (int)this_->radius, (int)(height - this_->radius), (int)((height - this_->radius) - (height / 2)));
4037 offset = (float)((height - this_->radius) - (height / 2)) / (float)height * (float)50.0;
4038 // dbg(0, "VEHICLE_OFFSET:b:o=%d\n", (int)offset);
4039 }
4040
4041
4042 // dbg(0, "VEHICLE_OFFSET:or=%d keep_or=%d\n", this_->orientation, keep_orientation);
4043
4044 if (this_->orientation == -1 || keep_orientation)
4045 {
4046 p->x = 50 * width / 100; // = (width / 2) // why doesnt it just say that?
4047 p->y = (50 + (int)offset) * height / 100;
4048
4049 // dbg(0, "VEHICLE_OFFSET:2:%d %d %d\n", p->y, width, height);
4050
4051 if (dir)
4052 {
4053 *dir = keep_orientation ? this_->orientation : nv->dir;
4054 }
4055 }
4056 else
4057 {
4058 int mdir;
4059 if (this_->tracking && this_->tracking_flag)
4060 {
4061 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
4062 // dbg(0, "+++++tr angle=%d\n", tracking_get_angle(this_->tracking));
4063 // dbg(0, "+++++this ori=%d\n", this_->orientation);
4064 }
4065 else
4066 {
4067 mdir = nv->dir - this_->orientation;
4068 }
4069
4070 p->x = (50 - offset * sin(M_PI * mdir / 180.)) * width / 100;
4071 p->y = (50 + offset * cos(M_PI * mdir / 180.)) * height / 100;
4072
4073 // dbg(0, "VEHICLE_OFFSET:3:%d %d %d\n", p->y, width, height);
4074
4075 if (dir)
4076 {
4077 *dir = this_->orientation;
4078 }
4079 }
4080 return 1;
4081 }
4082
4083 void navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
4084 {
4085
4086
4087 ////DBG dbg(0,"EEnter\n");
4088 int dir;
4089 struct point pn;
4090 struct navit_vehicle *nv = this_->vehicle;
4091 navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
4092 transform_set_yaw(this_->trans, dir);
4093 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
4094 // OLD // navit_aXXutozoom(this_, &nv->coord, nv->speed, 0);
4095 }
4096
4097 static void navit_set_center_cursor_draw(struct navit *this_)
4098 {
4099
4100
4101 //dbg(0,"EEnter\n");
4102 navit_set_center_cursor(this_, 1, 0);
4103 if (this_->ready == 3)
4104 {
4105 // dbg(0,"navit_draw_async_005\n");
4106 //dbg(0,"DO__DRAW:navit_draw_async call (AS)\n");
4107 // zzz554 // navit_draw_async(this_, 1);
4108 }
4109 }
4110
4111 static void navit_cmd_set_center_cursor(struct navit *this_)
4112 {
4113
4114
4115 ////DBG dbg(0,"EEnter\n");
4116 navit_set_center_cursor_draw(this_);
4117 }
4118
4119 void navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
4120 {
4121
4122
4123 ////DBG dbg(0,"EEnter\n");
4124 struct coord c;
4125 struct pcoord pc;
4126 transform_reverse(this_->trans, p, &c);
4127 pc.x = c.x;
4128 pc.y = c.y;
4129 pc.pro = transform_get_projection(this_->trans);
4130 navit_set_center(this_, &pc, set_timeout);
4131 }
4132
4133 #if 0
4134 switch((*attrs)->type)
4135 {
4136 case attr_zoom:
4137 zoom=(*attrs)->u.num;
4138 break;
4139 case attr_center:
4140 g=*((*attrs)->u.coord_geo);
4141 break;
4142 #endif
4143
4144 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
4145 {
4146
4147 int dir = 0, orient_old = 0, attr_updated = 0;
4148 struct coord co;
4149 long zoom;
4150 GList *l;
4151 struct navit_vehicle *nv;
4152 struct layout *lay;
4153 struct attr active;
4154 active.type = attr_active;
4155 active.u.num = 0;
4156
4157 switch (attr->type)
4158 {
4159 case attr_autozoom:
4160 attr_updated = (this_->autozoom_secs != attr->u.num);
4161 this_->autozoom_secs = attr->u.num;
4162 break;
4163 case attr_autozoom_active:
4164 attr_updated = (this_->autozoom_active != attr->u.num);
4165 this_->autozoom_active = attr->u.num;
4166 break;
4167 case attr_center:
4168 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
4169 // dbg(1, "0x%x,0x%x\n", co.x, co.y);
4170 transform_set_center(this_->trans, &co);
4171 break;
4172 case attr_drag_bitmap:
4173 attr_updated = (this_->drag_bitmap != !!attr->u.num);
4174 this_->drag_bitmap = !!attr->u.num;
4175 break;
4176 case attr_flags:
4177 attr_updated = (this_->flags != attr->u.num);
4178 this_->flags = attr->u.num;
4179 break;
4180 case attr_flags_graphics:
4181 attr_updated = (this_->graphics_flags != attr->u.num);
4182 this_->graphics_flags = attr->u.num;
4183 break;
4184 case attr_follow:
4185 if (!this_->vehicle)
4186 return 0;
4187 attr_updated = (this_->vehicle->follow_curr != attr->u.num);
4188 this_->vehicle->follow_curr = attr->u.num;
4189 break;
4190 case attr_layout:
4191 if (this_->layout_current != attr->u.layout)
4192 {
4193 this_->layout_current = attr->u.layout;
4194 graphics_font_destroy_all(this_->gra);
4195 navit_set_cursors(this_);
4196 if (this_->ready == 3)
4197 navit_draw(this_);
4198 attr_updated = 1;
4199 }
4200 break;
4201 case attr_layout_name:
4202 l = this_->layouts;
4203 while (l)
4204 {
4205 lay = l->data;
4206 if (!strcmp(lay->name, attr->u.str))
4207 {
4208 struct attr attr;
4209 attr.type = attr_layout;
4210 attr.u.layout = lay;
4211 return navit_set_attr_do(this_, &attr, init);
4212 }
4213 l = g_list_next(l);
4214 }
4215 return 0;
4216 case attr_map_border:
4217 if (this_->border != attr->u.num)
4218 {
4219 this_->border = attr->u.num;
4220 attr_updated = 1;
4221 }
4222 break;
4223 case attr_orientation:
4224 orient_old = this_->orientation;
4225 this_->orientation = attr->u.num;
4226 if (!init)
4227 {
4228 if (this_->orientation != -1)
4229 {
4230 dir = this_->orientation;
4231 }
4232 else
4233 {
4234 if (this_->vehicle)
4235 {
4236 dir = this_->vehicle->dir;
4237 }
4238 }
4239 transform_set_yaw(this_->trans, dir);
4240 if (orient_old != this_->orientation)
4241 {
4242 #if 0
4243 if (this_->ready == 3)
4244 navit_draw(this_);
4245 #endif
4246 attr_updated = 1;
4247 }
4248 }
4249 break;
4250 case attr_osd_configuration:
4251 //DBG dbg(0, "setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
4252 attr_updated = (this_->osd_configuration != attr->u.num);
4253 this_->osd_configuration = attr->u.num;
4254 break;
4255 case attr_pitch:
4256 attr_updated = (this_->pitch != attr->u.num);
4257 this_->pitch = attr->u.num;
4258 transform_set_pitch(this_->trans, this_->pitch);
4259 if (!init && attr_updated && this_->ready == 3)
4260 navit_draw(this_);
4261 break;
4262 case attr_projection:
4263 if (this_->trans && transform_get_projection(this_->trans) != attr->u.projection)
4264 {
4265 navit_projection_set(this_, attr->u.projection, !init);
4266 attr_updated = 1;
4267 }
4268 break;
4269 case attr_radius:
4270 attr_updated = (this_->radius != attr->u.num);
4271 this_->radius = attr->u.num;
4272 break;
4273 case attr_recent_dest:
4274 attr_updated = (this_->recentdest_count != attr->u.num);
4275 this_->recentdest_count = attr->u.num;
4276 break;
4277 case attr_speech:
4278 if (this_->speech && this_->speech != attr->u.speech)
4279 {
4280 attr_updated = 1;
4281 this_->speech = attr->u.speech;
4282 }
4283 break;
4284 case attr_timeout:
4285 attr_updated = (this_->center_timeout != attr->u.num);
4286 this_->center_timeout = attr->u.num;
4287 break;
4288 case attr_tracking:
4289 attr_updated = (this_->tracking_flag != !!attr->u.num);
4290 // dbg(0, "set attr:attr_tracking old=%d\n", this_->tracking_flag);
4291 this_->tracking_flag = !!attr->u.num;
4292 // dbg(0, "set attr:attr_tracking new=%d\n", this_->tracking_flag);
4293 break;
4294 case attr_transformation:
4295 this_->trans = attr->u.transformation;
4296 break;
4297 case attr_use_mousewheel:
4298 attr_updated = (this_->use_mousewheel != !!attr->u.num);
4299 this_->use_mousewheel = !!attr->u.num;
4300 break;
4301 case attr_vehicle:
4302 l = this_->vehicles;
4303 while (l)
4304 {
4305 nv = l->data;
4306 if (nv->vehicle == attr->u.vehicle)
4307 {
4308 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle)
4309 {
4310 if (this_->vehicle)
4311 {
4312 vehicle_set_attr(this_->vehicle->vehicle, &active);
4313 }
4314 active.u.num = 1;
4315 vehicle_set_attr(nv->vehicle, &active);
4316 attr_updated = 1;
4317 }
4318 navit_set_vehicle(this_, nv);
4319 }
4320 l = g_list_next(l);
4321 }
4322 break;
4323 case attr_zoom:
4324 zoom = transform_get_scale(this_->trans);
4325 attr_updated = (zoom != attr->u.num);
4326 transform_set_scale(this_->trans, attr->u.num);
4327 if (attr_updated && !init)
4328 navit_draw(this_);
4329 break;
4330 case attr_zoom_min:
4331 attr_updated = (attr->u.num != this_->zoom_min);
4332 this_->zoom_min = attr->u.num;
4333 break;
4334 case attr_zoom_max:
4335 attr_updated = (attr->u.num != this_->zoom_max);
4336 this_->zoom_max = attr->u.num;
4337 break;
4338 case attr_message:
4339 //navit_add_message(this_, attr->u.str);
4340 break;
4341 case attr_follow_cursor:
4342 attr_updated = (this_->follow_cursor != !!attr->u.num);
4343 this_->follow_cursor = !!attr->u.num;
4344 break;
4345 case attr_imperial:
4346 attr_updated = (this_->imperial != attr->u.num);
4347 this_->imperial = attr->u.num;
4348 break;
4349 default:
4350 return 0;
4351 }
4352
4353 if (attr_updated && !init)
4354 {
4355 // dbg(0, "set attr:call callback_list_call_attr_2\n");
4356 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
4357
4358 if (attr->type == attr_osd_configuration)
4359 {
4360 graphics_draw_mode(this_->gra, draw_mode_end);
4361 }
4362 }
4363
4364 return 1;
4365 }
4366
4367 int navit_set_attr(struct navit *this_, struct attr *attr)
4368 {
4369 return navit_set_attr_do(this_, attr, 0);
4370 }
4371
4372 int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
4373 {
4374
4375 struct message *msg;
4376 int len, offset;
4377 int ret = 1;
4378
4379 switch (type)
4380 {
4381 case attr_message:
4382 return 0;
4383 /*
4384 msg = navit_get_messages(this_);
4385
4386 if (!msg)
4387 {
4388 return 0;
4389 }
4390
4391 len = 0;
4392 while (msg)
4393 {
4394 len += strlen(msg->text) + 1;
4395 msg = msg->next;
4396 }
4397 attr->u.str = g_malloc(len + 1);
4398
4399 msg = navit_get_messages(this_);
4400 offset = 0;
4401 while (msg)
4402 {
4403 g_stpcpy((attr->u.str + offset), msg->text);
4404 offset += strlen(msg->text);
4405 attr->u.str[offset] = '\n';
4406 offset++;
4407
4408 msg = msg->next;
4409 }
4410
4411 attr->u.str[len] = '\0';
4412 */
4413 break;
4414 case attr_imperial:
4415 attr->u.num = this_->imperial;
4416 break;
4417 case attr_bookmark_map:
4418 attr->u.map = bookmarks_get_map(this_->bookmarks);
4419 break;
4420 case attr_bookmarks:
4421 attr->u.bookmarks = this_->bookmarks;
4422 break;
4423 case attr_callback_list:
4424 attr->u.callback_list = this_->attr_cbl;
4425 break;
4426 case attr_destination:
4427 if (!this_->destination_valid)
4428 return 0;
4429 attr->u.pcoord = &this_->destination;
4430 break;
4431 case attr_displaylist:
4432 attr->u.displaylist = this_->displaylist;
4433 return (attr->u.displaylist != NULL);
4434 case attr_follow:
4435 if (!this_->vehicle)
4436 return 0;
4437 attr->u.num = this_->vehicle->follow_curr;
4438 break;
4439 case attr_former_destination_map:
4440 attr->u.map = this_->former_destination;
4441 break;
4442 case attr_graphics:
4443 attr->u.graphics = this_->gra;
4444 ret = (attr->u.graphics != NULL);
4445 break;
4446 case attr_gui:
4447 attr->u.gui = this_->gui;
4448 ret = (attr->u.gui != NULL);
4449 break;
4450 case attr_layout:
4451 if (iter)
4452 {
4453 if (iter->u.list)
4454 {
4455 iter->u.list = g_list_next(iter->u.list);
4456 }
4457 else
4458 {
4459 iter->u.list = this_->layouts;
4460 }
4461 if (!iter->u.list)
4462 {
4463 return 0;
4464 }
4465 attr->u.layout = (struct layout *) iter->u.list->data;
4466 }
4467 else
4468 {
4469 attr->u.layout = this_->layout_current;
4470 }
4471 break;
4472 case attr_map:
4473 if (iter && this_->mapsets)
4474 {
4475 if (!iter->u.mapset_handle)
4476 {
4477 iter->u.mapset_handle = mapset_open((struct mapset *) this_->mapsets->data);
4478 }
4479 attr->u.map = mapset_next(iter->u.mapset_handle, 0);
4480 if (!attr->u.map)
4481 {
4482 mapset_close(iter->u.mapset_handle);
4483 return 0;
4484 }
4485 }
4486 else
4487 {
4488 return 0;
4489 }
4490 break;
4491 case attr_mapset:
4492 attr->u.mapset = this_->mapsets->data;
4493 ret = (attr->u.mapset != NULL);
4494 break;
4495 case attr_navigation:
4496 attr->u.navigation = this_->navigation;
4497 break;
4498 case attr_orientation:
4499 attr->u.num = this_->orientation;
4500 break;
4501 case attr_osd_configuration:
4502 attr->u.num = this_->osd_configuration;
4503 break;
4504 case attr_pitch:
4505 attr->u.num = transform_get_pitch(this_->trans);
4506 break;
4507 case attr_projection:
4508 if (this_->trans)
4509 {
4510 attr->u.num = transform_get_projection(this_->trans);
4511 }
4512 else
4513 {
4514 return 0;
4515 }
4516 break;
4517 case attr_route:
4518 attr->u.route = this_->route;
4519 break;
4520 case attr_speech:
4521 attr->u.speech = this_->speech;
4522 break;
4523 case attr_tracking:
4524 attr->u.num = this_->tracking_flag;
4525 break;
4526 case attr_trackingo:
4527 attr->u.tracking = this_->tracking;
4528 break;
4529 case attr_transformation:
4530 attr->u.transformation = this_->trans;
4531 break;
4532 case attr_vehicle:
4533 if (iter)
4534 {
4535 if (iter->u.list)
4536 {
4537 iter->u.list = g_list_next(iter->u.list);
4538 }
4539 else
4540 {
4541 iter->u.list = this_->vehicles;
4542 }
4543 if (!iter->u.list)
4544 return 0;
4545 attr->u.vehicle = ((struct navit_vehicle*) iter->u.list->data)->vehicle;
4546 }
4547 else
4548 {
4549 if (this_->vehicle)
4550 {
4551 attr->u.vehicle = this_->vehicle->vehicle;
4552 }
4553 else
4554 {
4555 return 0;
4556 }
4557 }
4558 break;
4559 case attr_vehicleprofile:
4560 attr->u.vehicleprofile = this_->vehicleprofile;
4561 break;
4562 case attr_zoom:
4563 attr->u.num = transform_get_scale(this_->trans);
4564 break;
4565 case attr_autozoom_active:
4566 attr->u.num = this_->autozoom_active;
4567 break;
4568 case attr_follow_cursor:
4569 attr->u.num = this_->follow_cursor;
4570 break;
4571 default:
4572 return 0;
4573 }
4574 attr->type = type;
4575
4576 return ret;
4577 }
4578
4579 void displaylist_shift_order_in_map_layers(struct navit *this_, int shift_value)
4580 {
4581
4582
4583
4584 GList *l;
4585 struct layout *lay;
4586 GList *l2;
4587 struct layer *layer;
4588 GList *ig;
4589 struct itemgra *itemgr;
4590 GList *elements;
4591 struct element *e;
4592
4593 // loop through all the layouts
4594 l = this_->layouts;
4595 while (l)
4596 {
4597 lay = l->data;
4598 //dbg(0,"layout name=%s\n", lay->name);
4599 if (!strcmp(lay->name, "Android-Car"))
4600 {
4601 //dbg(0,"layout found\n");
4602 l2 = lay->layers;
4603 while (l2)
4604 {
4605 layer = l2->data;
4606 //dbg(0,"layer name=%s\n", layer->name);
4607 // only change the zoom of these layers
4608 if ((!strcmp(layer->name, "polygons001"))
4609 || (!strcmp(layer->name, "polygons"))
4610 || (!strcmp(layer->name, "streets"))
4611 || (!strcmp(layer->name, "streets_STR_ONLY"))
4612 || (!strcmp(layer->name, "streets_1"))
4613 || (!strcmp(layer->name, "streets_1_STR_ONLY"))
4614 || (!strcmp(layer->name, "streets_2"))
4615 || (!strcmp(layer->name, "streets_2_STR_ONLY"))
4616 || (!strcmp(layer->name, "route_001"))
4617 || (!strcmp(layer->name, "route_002"))
4618 || (!strcmp(layer->name, "route_003"))
4619 )
4620 {
4621 //dbg(0,"layer found\n");
4622 ig = layer->itemgras;
4623 while (ig)
4624 {
4625 //dbg(0,"*itgr*\n");
4626 itemgr = ig->data;
4627
4628 // now shift "order"-value of itemgra by "shift_value"
4629 // ! max order == 18 !
4630 // ! min order == -2 !
4631
4632
4633 int was_shifted = 0;
4634
4635 //if (itemgr->order.min < 20)
4636 //{
4637 itemgr->order.min = itemgr->order.min - shift_value;
4638 was_shifted = 1;
4639 //}
4640 //if (itemgr->order.min < -2)
4641 //{
4642 // itemgr->order.min = -2;
4643 //}
4644 if (itemgr->order.min > 18)
4645 {
4646 itemgr->order.min = 18;
4647 }
4648
4649 // ------------------------------
4650
4651 if (itemgr->order.max < 18)
4652 {
4653 itemgr->order.max = itemgr->order.max - shift_value;
4654 was_shifted = 1;
4655 }
4656 //
4657 //if (itemgr->order.max < -2)
4658 //{
4659 // itemgr->order.max = -2;
4660 //}
4661 if (itemgr->order.max > 18)
4662 {
4663 itemgr->order.max = 18;
4664 }
4665
4666 float sv_001 = ((float) shift_value * 1.34f);
4667 float sv_002 = ((float) shift_value * 0.75f);
4668
4669 if (was_shifted == 1)
4670 {
4671 // loop thru all the elements in this "itemgra"
4672 elements = itemgr->elements;
4673 while (elements)
4674 {
4675 e = elements->data;
4676
4677 if (e->type == element_polyline)
4678 {
4679 // shift polyline width
4680 e->u.polyline.width = ((float) e->u.polyline.width / sv_001) + 0;
4681 if (e->u.polyline.width < 1)
4682 {
4683 e->u.polyline.width = 1;
4684 }
4685 }
4686
4687 if (e->type == element_circle)
4688 {
4689 // shift circle witdh
4690 e->u.circle.width = ((float) e->u.circle.width / sv_001) + 0;
4691 if (e->u.circle.width < 1)
4692 {
4693 e->u.circle.width = 1;
4694 }
4695
4696 e->u.circle.radius = ((float) e->u.circle.radius / sv_001) + 0;
4697 if (e->u.circle.radius < 1)
4698 {
4699 e->u.circle.radius = 1;
4700 }
4701 }
4702
4703 if (e->type == element_text)
4704 {
4705 // shift text size
4706 e->text_size = (float) e->text_size / sv_002;
4707 if (e->text_size < 1)
4708 {
4709 e->text_size = 1;
4710 }
4711 }
4712 elements = g_list_next(elements);
4713 }
4714 // loop thru all the elements in this "itemgra"
4715 }
4716
4717 ig = g_list_next(ig);
4718 }
4719 }
4720 l2 = g_list_next(l2);
4721 }
4722 }
4723 l = g_list_next(l);
4724 }
4725
4726 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4727 dbg(0,"+#+:leave\n");
4728 #endif
4729 }
4730
4731 void displaylist_shift_for_dpi_value_in_layers(struct navit *this_, double factor)
4732 {
4733
4734
4735
4736 GList *l;
4737 struct layout *lay;
4738 GList *l2;
4739 struct layer *layer;
4740 GList *ig;
4741 struct itemgra *itemgr;
4742 GList *elements;
4743 struct element *e;
4744
4745 // loop through all the layouts
4746 l = this_->layouts;
4747 while (l)
4748 {
4749 lay = l->data;
4750 //dbg(0,"layout name=%s\n", lay->name);
4751 if (!strcmp(lay->name, "Android-Car"))
4752 {
4753 //dbg(0,"layout found\n");
4754 l2 = lay->layers;
4755 while (l2)
4756 {
4757 layer = l2->data;
4758 //dbg(0,"layer name=%s\n", layer->name);
4759 // only change the zoom of these layers
4760 /*
4761 if ((!strcmp(layer->name, "polygons001"))
4762 || (!strcmp(layer->name, "polygons"))
4763 || (!strcmp(layer->name, "streets"))
4764 || (!strcmp(layer->name, "streets_1"))
4765 || (!strcmp(layer->name, "streets_2"))
4766 || (!strcmp(layer->name, "route_001"))
4767 || (!strcmp(layer->name, "route_002"))
4768 || (!strcmp(layer->name, "route_003"))
4769 )
4770 */
4771 //{
4772 //dbg(0,"layer found\n");
4773 ig = layer->itemgras;
4774 while (ig)
4775 {
4776 //dbg(0,"*itgr*\n");
4777 itemgr = ig->data;
4778
4779 // loop thru all the elements in this "itemgra"
4780 elements = itemgr->elements;
4781 while (elements)
4782 {
4783 e = elements->data;
4784
4785 if (e->type == element_polyline)
4786 {
4787 // polyline width
4788 e->u.polyline.width = (int)((float)e->u.polyline.width * factor) + 0;
4789 if (e->u.polyline.width < 1)
4790 {
4791 e->u.polyline.width = 1;
4792 }
4793 }
4794
4795 if (e->type == element_circle)
4796 {
4797 // circle witdh
4798 e->u.circle.width = (int)((float)e->u.circle.width * factor) + 0;
4799 if (e->u.circle.width < 1)
4800 {
4801 e->u.circle.width = 1;
4802 }
4803
4804 e->u.circle.radius = (int)((float)e->u.circle.radius * factor) + 0;
4805 if (e->u.circle.radius < 1)
4806 {
4807 e->u.circle.radius = 1;
4808 }
4809
4810 // text size
4811 e->text_size = (int)((float)(e->text_size * factor));
4812 if (e->text_size < 1)
4813 {
4814 e->text_size = 1;
4815 }
4816
4817 }
4818
4819 if (e->type == element_text)
4820 {
4821 // text size
4822 e->text_size = (int)((float)(e->text_size * factor));
4823 if (e->text_size < 1)
4824 {
4825 e->text_size = 1;
4826 }
4827 }
4828 elements = g_list_next(elements);
4829 }
4830 // loop thru all the elements in this "itemgra"
4831 ig = g_list_next(ig);
4832 }
4833 //}
4834 l2 = g_list_next(l2);
4835 }
4836 }
4837 l = g_list_next(l);
4838 }
4839
4840 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4841 dbg(0,"+#+:leave\n");
4842 #endif
4843 }
4844
4845
4846 static int navit_add_log(struct navit *this_, struct log *log)
4847 {
4848
4849
4850 struct attr type_attr;
4851 if (!log_get_attr(log, attr_type, &type_attr, NULL))
4852 return 0;
4853 if (!strcmp(type_attr.u.str, "textfile_debug"))
4854 {
4855 char *header = "type=track_tracked\n";
4856 if (this_->textfile_debug_log)
4857 return 0;
4858 log_set_header(log, header, strlen(header));
4859 this_->textfile_debug_log = log;
4860 return 1;
4861 }
4862 return 0;
4863 }
4864
4865 static int navit_add_layout(struct navit *this_, struct layout *layout)
4866 {
4867
4868
4869 ////DBG dbg(0,"EEnter\n");
4870 struct attr active;
4871 this_->layouts = g_list_append(this_->layouts, layout);
4872 layout_get_attr(layout, attr_active, &active, NULL);
4873 if (active.u.num || !this_->layout_current)
4874 {
4875 this_->layout_current = layout;
4876 return 1;
4877 }
4878 return 0;
4879 }
4880
4881 int navit_add_attr(struct navit *this_, struct attr *attr)
4882 {
4883
4884
4885 ////DBG dbg(0,"EEnter\n");
4886
4887 int ret = 1;
4888 switch (attr->type)
4889 {
4890 case attr_callback:
4891 navit_add_callback(this_, attr->u.callback);
4892 break;
4893 case attr_log:
4894 ret = navit_add_log(this_, attr->u.log);
4895 break;
4896 case attr_gui:
4897 ret = navit_set_gui(this_, attr->u.gui);
4898 break;
4899 case attr_graphics:
4900 ret = navit_set_graphics(this_, attr->u.graphics);
4901 break;
4902 case attr_layout:
4903 ret = navit_add_layout(this_, attr->u.layout);
4904 break;
4905 case attr_route:
4906 this_->route = attr->u.route;
4907 break;
4908 case attr_mapset:
4909 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
4910 break;
4911 case attr_navigation:
4912 this_->navigation = attr->u.navigation;
4913 break;
4914 case attr_recent_dest:
4915 this_->recentdest_count = attr->u.num;
4916 break;
4917 case attr_speech:
4918 this_->speech = attr->u.speech;
4919 break;
4920 case attr_tracking:
4921 this_->tracking = attr->u.tracking;
4922 break;
4923 case attr_vehicle:
4924 ret = navit_add_vehicle(this_, attr->u.vehicle);
4925 break;
4926 case attr_vehicleprofile:
4927 this_->vehicleprofiles = g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
4928 break;
4929 case attr_autozoom_min:
4930 this_->autozoom_min = attr->u.num;
4931 break;
4932 default:
4933 return 0;
4934 }
4935 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
4936
4937 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4938 dbg(0,"+#+:leave\n");
4939 #endif
4940
4941 return ret;
4942 }
4943
4944 int navit_remove_attr(struct navit *this_, struct attr *attr)
4945 {
4946
4947
4948 int ret = 1;
4949 switch (attr->type)
4950 {
4951 case attr_callback:
4952 navit_remove_callback(this_, attr->u.callback);
4953 break;
4954 default:
4955 return 0;
4956 }
4957
4958 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
4959 dbg(0,"+#+:leave\n");
4960 #endif
4961
4962 return ret;
4963 }
4964
4965 struct attr_iter *
4966 navit_attr_iter_new(void)
4967 {
4968
4969
4970 return g_new0(struct attr_iter, 1);
4971 }
4972
4973 void navit_attr_iter_destroy(struct attr_iter *iter)
4974 {
4975
4976
4977 g_free(iter);
4978 }
4979
4980 void navit_add_callback(struct navit *this_, struct callback *cb)
4981 {
4982
4983
4984 ////DBG dbg(0,"EEnter\n");
4985
4986 callback_list_add(this_->attr_cbl, cb);
4987 }
4988
4989 void navit_remove_callback(struct navit *this_, struct callback *cb)
4990 {
4991
4992
4993 ////DBG dbg(0,"EEnter\n");
4994
4995 callback_list_remove(this_->attr_cbl, cb);
4996 }
4997
4998 /**
4999 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
5000 *
5001 * @param navit The navit instance
5002 * @returns nothing
5003 */
5004 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
5005 {
5006 __F_START__
5007
5008 struct point cursor_pnt;
5009 enum projection pro;
5010
5011 if (this_->blocked)
5012 {
5013 return2;
5014 }
5015
5016 if (pnt)
5017 {
5018 cursor_pnt = *pnt;
5019 }
5020 else
5021 {
5022 pro = transform_get_projection(this_->trans_cursor);
5023 if (!pro)
5024 {
5025 return2;
5026 }
5027 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
5028 }
5029
5030 //dbg(0,"xx=%d\n",cursor_pnt.x);
5031 //dbg(0,"yy=%d\n",cursor_pnt.y);
5032
5033 global_vehicle_pos_onscreen.x = cursor_pnt.x;
5034 global_vehicle_pos_onscreen.y = cursor_pnt.y;
5035
5036 //dbg(0,"xx=%d\n",cursor_pnt.x);
5037 //dbg(0,"yy=%d\n",cursor_pnt.y);
5038 //dbg(0,"vehicle_draw_001\n");
5039 vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, 0, nv->dir - transform_get_yaw(this_->trans_cursor), nv->speed);
5040 #if 0
5041 if (pnt)
5042 pnt2=*pnt;
5043 else
5044 {
5045 pro=transform_get_projection(this_->trans);
5046 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
5047 }
5048 #if 1
5049 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
5050 #else
5051 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
5052 #endif
5053 #endif
5054
5055 __F_END__
5056 }
5057
5058
5059
5060 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5061 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5062 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5063 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
5064 {
5065
5066 __F_START__
5067
5068 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5069 dbg(0, "\n");
5070 dbg(0, "==================================================================================\n");
5071 dbg(0, "==================================================================================\n");
5072 dbg(0, "\n");
5073 #endif
5074
5075
5076 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5077 dbg(0, "ROUTExxPOSxx:navit_vehicle_update:enter\n");
5078 #endif
5079
5080 #ifdef NAVIT_MEASURE_TIME_DEBUG
5081 clock_t s_ = debug_measure_start();
5082 #endif
5083
5084 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
5085 struct pcoord cursor_pc;
5086 struct point cursor_pnt, *pnt = &cursor_pnt;
5087 struct point old_cursor_pnt;
5088 struct tracking *tracking = NULL;
5089 struct pcoord pc[16];
5090
5091 enum projection pro = transform_get_projection(this_->trans_cursor);
5092
5093 int count;
5094 int old_dir;
5095 int old_pos_invalid;
5096 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
5097 void *attr_object;
5098 char *destination_file;
5099 long new_scale_value;
5100 long old_scale_value;
5101 int l_old;
5102 int l_new;
5103
5104 if (this_->ready != 3)
5105 {
5106 //profile(0,"return 1\n");
5107 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5108 dbg(0, "ROUTExxPOSxx:return 003\n");
5109 #endif
5110
5111
5112 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5113 dbg(0, "\n");
5114 dbg(0, "==================================================================================\n");
5115 dbg(0, "==================================================================================\n");
5116 dbg(0, "\n");
5117 #endif
5118
5119 return2;
5120 }
5121
5122 // **OLD** navit_layout_switch(this_);
5123 if (this_->vehicle == nv && this_->tracking_flag)
5124 {
5125 tracking = this_->tracking;
5126 }
5127 //// else tracking = NULL !! -> important for next "if" clause!!
5128
5129 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5130 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5131 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5132 struct attr attr_pos_unchanged;
5133 if (vehicle_get_attr(nv->vehicle, attr_position_coord_geo, &attr_pos_unchanged, NULL))
5134 {
5135 if (attr_pos_unchanged.u.coord_geo)
5136 {
5137 global_v_pos_lat = attr_pos_unchanged.u.coord_geo->lat;
5138 global_v_pos_lng = attr_pos_unchanged.u.coord_geo->lng;
5139
5140 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5141 struct coord cc999;
5142 transform_from_geo(pro, attr_pos_unchanged.u.coord_geo, &cc999);
5143 dbg(0, "ROUTExxPOSxx:navit_vehicle_update: %d %d\n", cc999.x, cc999.y);
5144 #endif
5145
5146 }
5147 }
5148
5149 if (vehicle_get_attr(nv->vehicle, attr_position_direction, &attr_pos_unchanged, NULL))
5150 {
5151 global_v_pos_dir = *attr_pos_unchanged.u.numd;
5152
5153 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5154 dbg(0, "ROUTExxPOSxx:navit_vehicle_update: dir=%f\n", (float)global_v_pos_dir);
5155 #endif
5156 }
5157 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5158 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5159 // ------ DEBUG ------ remember real GPS postion (unchanged) -------
5160
5161
5162 if (tracking)
5163 {
5164 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5165 dbg(0, "ROUTExxPOSxx:tracking_update: 001\n");
5166 #endif
5167
5168 // set postition from tracking (changing it to nearest street)
5169 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
5170 attr_object = tracking;
5171 get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) tracking_get_attr;
5172
5173 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5174 dbg(0, "ROUTExxPOSxx:tracking_update: 001-a\n");
5175 #endif
5176 }
5177 else
5178 {
5179 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5180 dbg(0, "ROUTExxPOSxx:tracking_update (unchanged): 001.bb\n");
5181 #endif
5182
5183 // set position from vehicle (unchanged)
5184 attr_object = nv->vehicle;
5185 get_attr = (int(*)(void *, enum attr_type, struct attr *, struct attr_iter *)) vehicle_get_attr;
5186
5187 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5188 dbg(0, "ROUTExxPOSxx:tracking_update (unchanged): 001.bb-a\n");
5189 #endif
5190 }
5191
5192 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
5193 {
5194 if (!attr_valid.u.num != attr_position_valid_invalid)
5195 {
5196 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5197 dbg(0, "ROUTExxPOSxx:return 001\n");
5198 #endif
5199
5200 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5201 dbg(0, "\n");
5202 dbg(0, "==================================================================================\n");
5203 dbg(0, "==================================================================================\n");
5204 dbg(0, "\n");
5205 #endif
5206
5207 return2;
5208 }
5209 }
5210
5211
5212 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5213 struct attr attr_pos_99;
5214 if (get_attr(attr_object, attr_position_coord_geo, &attr_pos_99, NULL))
5215 {
5216 if (attr_pos_99.u.coord_geo)
5217 {
5218 struct coord cc999;
5219 transform_from_geo(pro, attr_pos_99.u.coord_geo, &cc999);
5220 dbg(0, "ROUTExxPOSxx:get pos: %d %d\n", cc999.x, cc999.y);
5221 }
5222 }
5223 #endif
5224
5225
5226 // load attrs with data from vehicle
5227 if (!get_attr(attr_object, attr_position_direction, &attr_dir, NULL) || !get_attr(attr_object, attr_position_speed, &attr_speed, NULL) || !get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL))
5228 {
5229 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5230 dbg(0, "ROUTExxPOSxx:return 002\n");
5231 #endif
5232
5233 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5234 dbg(0, "\n");
5235 dbg(0, "==================================================================================\n");
5236 dbg(0, "==================================================================================\n");
5237 dbg(0, "\n");
5238 #endif
5239
5240 return2;
5241 }
5242 // load attrs with data from vehicle
5243
5244
5245 // save old value
5246 old_dir = nv->dir;
5247 global_old_vehicle_speed = nv->speed;
5248 old_scale_value = transform_get_scale(this_->trans);
5249
5250 nv->dir = *attr_dir.u.numd;
5251 nv->speed = *attr_speed.u.numd;
5252
5253 // old values ---------
5254 if ((global_last_vehicle_pos_geo.lat != 0.0) && (global_last_vehicle_pos_geo.lng != 0.0))
5255 {
5256 transform_from_geo(pro, &global_last_vehicle_pos_geo, &nv->coord);
5257 transform(this_->trans_cursor, pro, &nv->coord, &old_cursor_pnt, 1, 0, 0, NULL);
5258 old_pos_invalid = 0;
5259
5260 // XXX // dbg(0,"old values lat:%f lon:%f px:%d py:%d\n", global_last_vehicle_pos_geo.lat, global_last_vehicle_pos_geo.lng, old_cursor_pnt.x, old_cursor_pnt.y);
5261 }
5262 else
5263 {
5264 old_pos_invalid = 1;
5265 }
5266 // old values ---------
5267
5268 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
5269
5270 // save this position
5271 global_last_vehicle_pos_geo.lat = attr_pos.u.coord_geo->lat;
5272 global_last_vehicle_pos_geo.lng = attr_pos.u.coord_geo->lng;
5273
5274 ggggg_lat = attr_pos.u.coord_geo->lat;
5275 ggggg_lon = attr_pos.u.coord_geo->lng;
5276 // dbg(0, "PPPOS:%f %f lll=%f", global_last_vehicle_pos_geo.lat, global_last_vehicle_pos_geo.lng, ggggg_lat);
5277
5278 // save this position
5279
5280
5281 // XXX // dbg(0,"v1 lat:%f lon:%f x:%d y:%d\n",attr_pos.u.coord_geo->lat, attr_pos.u.coord_geo->lng, nv->coord.x, nv->coord.y);
5282
5283 //if (nv != this_->vehicle)
5284 //{
5285 // if (hold_drawing == 0)
5286 // {
5287 // navit_vehicle_draw(this_, nv, NULL);
5288 // }
5289 // return;
5290 //}
5291 cursor_pc.x = nv->coord.x;
5292 cursor_pc.y = nv->coord.y;
5293 cursor_pc.pro = pro;
5294
5295 if (this_->route)
5296 {
5297 if (tracking)
5298 {
5299 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5300 dbg(0, "ROUTExxPOSxx:navit_vehicle_update: 001\n");
5301 #endif
5302 route_set_position_from_tracking(this_->route, tracking, pro);
5303 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5304 dbg(0, "ROUTExxPOSxx:navit_vehicle_update: 001-a\n");
5305 #endif
5306 }
5307 else
5308 {
5309 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5310 dbg(0, "ROUTExxPOSxx:YYYYY:navit_vehicle_update: 002\n");
5311 #endif
5312 route_set_position(this_->route, &cursor_pc);
5313 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5314 dbg(0, "ROUTExxPOSxx:navit_vehicle_update: 002-a\n");
5315 #endif
5316 }
5317 }
5318
5319 // --------------------------------------------------------------
5320 // --------------------------------------------------------------
5321 // this calls: graphics_load_mapset (and draws the map)
5322 // --------------------------------------------------------------
5323 /// -------**++**-- DISABLE --**++**---- callback_list_call_attr_0(this_->attr_cbl, attr_position);
5324 // --------------------------------------------------------------
5325 // --------------------------------------------------------------
5326
5327 // navit_textfile_debug_log(this_, "type=trackpoint_tracked");
5328 /*
5329 if (this_->gui && nv->speed > MYSTERY_SPEED)
5330 {
5331 // stupid!!!! this gets called every second!!! fixme!!!!!!
5332 navit_disable_suspend();
5333 // stupid!!!! this gets called every second!!! fixme!!!!!!
5334 }
5335 */
5336
5337 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
5338 // XXX // dbg(0,"v2 px:%d py:%d x:%d y:%d\n", cursor_pnt.x, cursor_pnt.y, nv->coord.x, nv->coord.y);
5339
5340 // ------- AUTOZOOM ---------
5341 l_old = 0;
5342 l_new = 0;
5343 new_scale_value = navit_autozoom(this_, &nv->coord, nv->speed, 0, &l_old, &l_new);
5344 // dbg(0, "l_old=%d l_new=%d\n", l_old, l_new);
5345 // ------- AUTOZOOM ---------
5346
5347 if (old_pos_invalid == 0)
5348 {
5349 int delta_x = cursor_pnt.x - old_cursor_pnt.x;
5350 int delta_y = cursor_pnt.y - old_cursor_pnt.y;
5351 int delta_angle = nv->dir - old_dir;
5352 int delta_zoom = 0;
5353
5354 if (new_scale_value != -1)
5355 {
5356 delta_zoom = (int)(new_scale_value - old_scale_value);
5357 }
5358
5359 #ifdef HAVE_API_ANDROID
5360 //dbg(0,"delta x=%d, y=%d, angle=%d\n", delta_x, delta_y, delta_angle);
5361 set_vehicle_values_to_java_delta(delta_x, delta_y, delta_angle, delta_zoom, l_old, l_new);
5362 #endif
5363 }
5364
5365
5366
5367 // -------- ??????????
5368 // -------- ??????????
5369 // -------- ??????????
5370 // -------- ??????????
5371 // -------- ??????????
5372 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow && (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
5373 {
5374 if (hold_drawing == 0)
5375 {
5376 //dbg(0,"call:navit_set_center_cursor_draw:start\n");
5377 navit_set_center_cursor_draw(this_);
5378 //dbg(0,"call:navit_set_center_cursor_draw:end\n");
5379 }
5380 }
5381 else
5382 {
5383 if (hold_drawing == 0)
5384 {
5385 navit_vehicle_draw(this_, nv, pnt);
5386 }
5387 }
5388 // -------- ??????????
5389 // -------- ??????????
5390 // -------- ??????????
5391 // -------- ??????????
5392 // -------- ??????????
5393
5394
5395
5396
5397 if (nv->follow_curr > 1)
5398 {
5399 nv->follow_curr--;
5400 }
5401 else
5402 {
5403 nv->follow_curr = nv->follow;
5404 }
5405
5406
5407
5408 // where does this go????? ----------
5409 // where does this go????? ----------
5410 //
5411 // i think this updates the OSD GUIs
5412 //
5413 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
5414 // where does this go????? ----------
5415 // where does this go????? ----------
5416
5417
5418
5419 /* Finally, if we reached our destination, stop navigation. */
5420 if (this_->route)
5421 {
5422 switch (route_destination_reached(this_->route))
5423 {
5424 case 1:
5425 route_remove_waypoint(this_->route);
5426 count = route_get_destinations(this_->route, pc, 16);
5427
5428 // destination_file = bookmarks_get_destination_file(TRUE);
5429 // bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
5430
5431 #ifdef HAVE_API_ANDROID
5432 // waypoint reached
5433 android_return_generic_int(5, 1);
5434 #ifdef NAVIT_SAY_DEBUG_PRINT
5435 android_send_generic_text(1,"+*#O:Waypoint reached\n");
5436 #endif
5437 if (global_routing_engine != 1) // not OSRM routing
5438 {
5439 // say it
5440 navit_say(this_, _("Waypoint reached"));
5441 }
5442 #endif
5443 break;
5444 case 2:
5445 navit_set_destination(this_, NULL, NULL, 0);
5446 // ** inform java that we reached our destination **
5447 #ifdef HAVE_API_ANDROID
5448 android_return_generic_int(4, 1);
5449 #ifdef NAVIT_SAY_DEBUG_PRINT
5450 android_send_generic_text(1,"+*#O:You have reached your destination\n");
5451 #endif
5452 // say it
5453 navit_say(this_, _("You have reached your destination"));
5454 #endif
5455 break;
5456 }
5457 }
5458
5459 if (hold_drawing == 0)
5460 {
5461 // draw???????
5462 // navit_draw(this_);
5463 if (this_->ready == 3)
5464 {
5465 //dbg(0,"location update:draw:start\n");
5466 // dbg(0,"navit_draw_async_006\n");
5467 // zzz554 //
5468 navit_draw_async(this_, 0);
5469 //dbg(0,"location update:draw:end\n");
5470 }
5471 // draw???????
5472 }
5473
5474 #ifdef NAVIT_MEASURE_TIME_DEBUG
5475 debug_mrp("navit_vehicle_update:", debug_measure_end(s_));
5476 #endif
5477
5478 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5479 dbg(0, "ROUTExxPOSxx:navit_vehicle_update:leave\n");
5480 #endif
5481
5482 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5483 dbg(0, "\n");
5484 dbg(0, "==================================================================================\n");
5485 dbg(0, "==================================================================================\n");
5486 dbg(0, "\n");
5487 #endif
5488
5489 __F_END__
5490
5491 }
5492 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5493 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5494 // --- this gets called at every positon update (from GPS, or demo vehicle!!) !! ------
5495
5496
5497
5498 int navit_is_demo_vehicle()
5499 {
5500 if (global_demo_vehicle == 1)
5501 {
5502 return 1;
5503 }
5504
5505 return 0;
5506 }
5507
5508
5509 /**
5510 * Set the position of the vehicle
5511 *
5512 * @param navit The navit instance
5513 * @param c The coordinate to set as position
5514 * @returns nothing
5515 */
5516 void navit_set_position(struct navit *this_, struct pcoord *c)
5517 {
5518 __F_START__
5519
5520 //DBG dbg(0,"EEnter\n");
5521
5522 if (this_->route)
5523 {
5524 //#ifdef NAVIT_ROUTING_DEBUG_PRINT
5525 // dbg(0, "ROUTExxPOSxx:YYYYY:navit_set_position: 001\n");
5526 //#endif
5527 // ******* NOT USE ******** // route_set_position(this_->route, c);
5528 // ******* NOT USE ******** // callback_list_call_attr_0(this_->attr_cbl, attr_position);
5529 }
5530
5531 if (this_->ready == 3)
5532 {
5533 navit_draw(this_);
5534 }
5535
5536 __F_END__
5537 }
5538
5539 /**
5540 * Set the position of the vehicle, without drawing the map
5541 *
5542 */
5543 void navit_set_position_without_map_drawing(struct navit *this_, struct pcoord *c)
5544 {
5545
5546
5547
5548 if (this_->route)
5549 {
5550 #ifdef NAVIT_ROUTING_DEBUG_PRINT
5551 dbg(0, "ROUTExxPOSxx:YYYYY:navit_set_position_without_map_drawing: 001\n");
5552 #endif
5553 route_set_position(this_->route, c);
5554 callback_list_call_attr_0(this_->attr_cbl, attr_position);
5555 }
5556 }
5557
5558
5559 int navit_set_vehicleprofile(struct navit *this_, char *name)
5560 {
5561
5562
5563 ////DBG dbg(0,"EEnter\n");
5564
5565 struct attr attr;
5566 GList *l;
5567 l = this_->vehicleprofiles;
5568 while (l)
5569 {
5570 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL))
5571 {
5572 if (!strcmp(attr.u.str, name))
5573 {
5574 this_->vehicleprofile = l->data;
5575 if (this_->route)
5576 {
5577 route_set_profile(this_->route, this_->vehicleprofile);
5578 }
5579 return 1;
5580 }
5581 }
5582 l = g_list_next(l);
5583 }
5584 return 0;
5585 }
5586
5587 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
5588 {
5589
5590
5591 ////DBG dbg(0,"EEnter\n");
5592
5593 struct attr attr;
5594 this_->vehicle = nv;
5595
5596 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL))
5597 {
5598 if (navit_set_vehicleprofile(this_, attr.u.str))
5599 {
5600 return;
5601 }
5602 }
5603
5604 if (!navit_set_vehicleprofile(this_, "car"))
5605 {
5606 /* We do not have a fallback "car" profile
5607 * so lets set any profile */
5608 GList *l;
5609 l = this_->vehicleprofiles;
5610 if (l)
5611 {
5612 this_->vehicleprofile = l->data;
5613 if (this_->route)
5614 {
5615 route_set_profile(this_->route, this_->vehicleprofile);
5616 }
5617 }
5618 }
5619 }
5620
5621 /**
5622 * Register a new vehicle
5623 *
5624 * @param navit The navit instance
5625 * @param v The vehicle instance
5626 * @returns 1 for success
5627 */
5628 int navit_add_vehicle(struct navit *this_, struct vehicle *v)
5629 {
5630
5631
5632
5633 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
5634 struct attr follow, active, animate;
5635 nv->vehicle = v;
5636 nv->follow = 0;
5637 nv->last.x = 0;
5638 nv->last.y = 0;
5639
5640 global_last_vehicle_pos_geo.lat = 0;
5641 global_last_vehicle_pos_geo.lng = 0;
5642
5643 // global_cur_vehicle_pos_geo.lat = 0;
5644 // global_cur_vehicle_pos_geo.lon = 0;
5645
5646 nv->animate_cursor = 0;
5647 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
5648 nv->follow = follow.u.num;
5649
5650 nv->follow_curr = nv->follow;
5651 this_->vehicles = g_list_append(this_->vehicles, nv);
5652
5653 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
5654 navit_set_vehicle(this_, nv);
5655
5656 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
5657 nv->animate_cursor = animate.u.num;
5658
5659 nv->callback.type = attr_callback;
5660
5661 // gets called via this callback in vehicle_android.c [in function: vehicle_android_callback]
5662 nv->callback.u.callback = callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
5663 callback_add_names(nv->callback.u.callback, "navit_add_vehicle", "navit_vehicle_update");
5664
5665 //dbg(0,"EEnter 11\n");
5666 vehicle_add_attr(nv->vehicle, &nv->callback);
5667 //dbg(0,"EEnter 22\n");
5668 vehicle_set_attr(nv->vehicle, &this_->self);
5669 //dbg(0,"EEnter 33\n");
5670
5671 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
5672 dbg(0,"+#+:leave\n");
5673 #endif
5674
5675 return 1;
5676 }
5677
5678 struct gui *
5679 navit_get_gui(struct navit *this_)
5680 {
5681 return this_->gui;
5682 }
5683
5684 struct transformation *
5685 navit_get_trans(struct navit *this_)
5686 {
5687 return this_->trans;
5688 }
5689
5690 struct route *
5691 navit_get_route(struct navit *this_)
5692 {
5693 return this_->route;
5694 }
5695
5696 struct navigation *
5697 navit_get_navigation(struct navit *this_)
5698 {
5699 return this_->navigation;
5700 }
5701
5702 struct displaylist *
5703 navit_get_displaylist(struct navit *this_)
5704 {
5705 return this_->displaylist;
5706 }
5707
5708 void navit_layout_switch(struct navit *n)
5709 {
5710
5711
5712 ////DBG dbg(0,"EEnter\n");
5713
5714 int currTs = 0;
5715 struct attr iso8601_attr, geo_attr, valid_attr, layout_attr;
5716 double trise, tset, trise_actual;
5717 struct layout *l;
5718 int year, month, day;
5719
5720 if (navit_get_attr(n, attr_layout, &layout_attr, NULL) != 1)
5721 {
5722 return; //No layout - nothing to switch
5723 }
5724 if (!n->vehicle)
5725 return;
5726 l = layout_attr.u.layout;
5727
5728 if (l->dayname || l->nightname)
5729 {
5730 //Ok, we know that we have profile to switch
5731
5732 //Check that we aren't calculating too fast
5733 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601, &iso8601_attr, NULL) == 1)
5734 {
5735 currTs = iso8601_to_secs(iso8601_attr.u.str);
5736 // dbg(1, "currTs: %u:%u\n", currTs % 86400 / 3600, ((currTs % 86400) % 3600) / 60);
5737 }
5738 if (currTs - (n->prevTs) < 60)
5739 {
5740 //We've have to wait a little
5741 return;
5742 }
5743 if (sscanf(iso8601_attr.u.str, "%d-%02d-%02dT", &year, &month, &day) != 3)
5744 return;
5745 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr, NULL) && valid_attr.u.num == attr_position_valid_invalid)
5746 {
5747 return; //No valid fix yet
5748 }
5749 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo, &geo_attr, NULL) != 1)
5750 {
5751 //No position - no sun
5752 return;
5753 }
5754
5755 //We calculate sunrise anyway, cause it is needed both for day and for night
5756 if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0)
5757 {
5758 //near the pole sun never rises/sets, so we should never switch profiles
5759 // dbg(1, "trise: %u:%u, sun never visible, never switch profile\n", HOURS(trise), MINUTES(trise));
5760 n->prevTs = currTs;
5761 return;
5762 }
5763
5764 trise_actual = trise;
5765 // dbg(1, "trise: %u:%u\n", HOURS(trise), MINUTES(trise));
5766 if (l->dayname)
5767 {
5768
5769 if ((HOURS(trise) * 60 + MINUTES(trise) == (currTs % 86400) / 60) || (n->prevTs == 0 && ((HOURS(trise) * 60 + MINUTES(trise) < (currTs % 86400) / 60))))
5770 {
5771 //The sun is rising now!
5772 if (strcmp(l->name, l->dayname))
5773 {
5774 navit_set_layout_by_name(n, l->dayname);
5775 }
5776 }
5777 }
5778 if (l->nightname)
5779 {
5780 if (__sunriset__(year, month, day, geo_attr.u.coord_geo->lng, geo_attr.u.coord_geo->lat, -5, 1, &trise, &tset) != 0)
5781 {
5782 //near the pole sun never rises/sets, so we should never switch profiles
5783 // dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset), MINUTES(tset));
5784 n->prevTs = currTs;
5785 return;
5786 }
5787 // dbg(1, "tset: %u:%u\n", HOURS(tset), MINUTES(tset));
5788 if (HOURS(tset) * 60 + MINUTES(tset) == ((currTs % 86400) / 60) || (n->prevTs == 0 && (((HOURS(tset) * 60 + MINUTES(tset) < (currTs % 86400) / 60)) || ((HOURS(trise_actual) * 60 + MINUTES(trise_actual) > (currTs % 86400) / 60)))))
5789 {
5790 //Time to sleep
5791 if (strcmp(l->name, l->nightname))
5792 {
5793 navit_set_layout_by_name(n, l->nightname);
5794 }
5795 }
5796 }
5797
5798 n->prevTs = currTs;
5799 }
5800 }
5801
5802 int navit_set_vehicle_by_name(struct navit *n, const char *name)
5803 {
5804
5805
5806 ////DBG dbg(0,"EEnter\n");
5807
5808 struct vehicle *v;
5809 struct attr_iter *iter;
5810 struct attr vehicle_attr, name_attr;
5811
5812 iter = navit_attr_iter_new();
5813
5814 while (navit_get_attr(n, attr_vehicle, &vehicle_attr, iter))
5815 {
5816 v = vehicle_attr.u.vehicle;
5817 vehicle_get_attr(v, attr_name, &name_attr, NULL);
5818 if (name_attr.type == attr_name)
5819 {
5820 if (!strcmp(name, name_attr.u.str))
5821 {
5822 navit_set_attr(n, &vehicle_attr);
5823 navit_attr_iter_destroy(iter);
5824 return 1;
5825 }
5826 }
5827 }
5828 navit_attr_iter_destroy(iter);
5829 return 0;
5830 }
5831
5832 int navit_set_layout_by_name(struct navit *n, const char *name)
5833 {
5834
5835
5836 ////DBG dbg(0,"EEnter\n");
5837
5838 struct layout *l;
5839 struct attr_iter iter;
5840 struct attr layout_attr;
5841
5842 iter.u.list = 0x00;
5843
5844 if (navit_get_attr(n, attr_layout, &layout_attr, &iter) != 1)
5845 {
5846 return 0; //No layouts - nothing to do
5847 }
5848 if (iter.u.list == NULL)
5849 {
5850 return 0;
5851 }
5852
5853 iter.u.list = g_list_first(iter.u.list);
5854
5855 while (iter.u.list)
5856 {
5857 l = (struct layout*) iter.u.list->data;
5858 if (!strcmp(name, l->name))
5859 {
5860 layout_attr.u.layout = l;
5861 layout_attr.type = attr_layout;
5862 navit_set_attr(n, &layout_attr);
5863 iter.u.list = g_list_first(iter.u.list);
5864 return 1;
5865 }
5866 iter.u.list = g_list_next(iter.u.list);
5867 }
5868
5869 iter.u.list = g_list_first(iter.u.list);
5870 return 0;
5871 }
5872
5873 void navit_disable_suspend()
5874 {
5875
5876
5877 ////DBG dbg(0,"EEnter\n");
5878
5879 gui_disable_suspend(global_navit->gui);
5880 callback_list_call_attr_0(global_navit->attr_cbl, attr_unsuspend);
5881 }
5882
5883 /**
5884 * @brief Dumps item attrs to string
5885 *
5886 * @param item item
5887 * @param pretty 0 -> normal, 1 -> pretty output
5888 * @return string with attrs separated by '\n'
5889 */
5890 char* navit_item_dump(struct item *item, int pretty)
5891 {
5892 char *temp_str = NULL;
5893 char *ret_value = NULL;
5894 struct attr attr;
5895 struct attr attr2;
5896 int had_flags = 0;
5897 int *f;
5898 int flags;
5899
5900 if (item == NULL)
5901 {
5902 ret_value = g_strdup("");
5903 return ret_value;
5904 }
5905
5906 if (pretty == 1)
5907 {
5908 ret_value = g_strdup_printf("+*TYPE*+:%s", item_to_name(item->type));
5909 }
5910 else
5911 {
5912 ret_value = g_strdup_printf("type=%s", item_to_name(item->type));
5913 }
5914
5915 while (item_attr_get(item, attr_any, &attr))
5916 {
5917 if (attr.type == attr_flags)
5918 {
5919 had_flags = 1;
5920
5921 flags = attr.u.num;
5922 if (flags == 0)
5923 {
5924 f = item_get_default_flags(item->type);
5925 if (f)
5926 {
5927 flags = *f;
5928 }
5929 else
5930 {
5931 flags = 0;
5932 }
5933 }
5934
5935 if (pretty == 1)
5936 {
5937 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr.type), flags_to_text(flags));
5938 }
5939 else
5940 {
5941 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr.type), flags_to_text(flags));
5942 }
5943 }
5944 else
5945 {
5946 if (pretty == 1)
5947 {
5948 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr.type), attr_to_text(&attr, NULL, 1));
5949 }
5950 else
5951 {
5952 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr.type), attr_to_text(&attr, NULL, 1));
5953 }
5954 }
5955 g_free(ret_value);
5956 ret_value = g_strdup(temp_str);
5957 g_free(temp_str);
5958 }
5959
5960 if (had_flags == 0)
5961 {
5962 f = item_get_default_flags(item->type);
5963 if (f)
5964 {
5965 flags = *f;
5966
5967 if (pretty == 1)
5968 {
5969 temp_str = g_strdup_printf("%s\n%s=%s", ret_value, attr_to_name(attr_flags), flags_to_text(flags));
5970 }
5971 else
5972 {
5973 temp_str = g_strdup_printf("%s\n%s='%s'", ret_value, attr_to_name(attr_flags), flags_to_text(flags));
5974 }
5975
5976 g_free(ret_value);
5977 ret_value = g_strdup(temp_str);
5978 g_free(temp_str);
5979 }
5980 }
5981
5982 // g_free(item);
5983
5984 return ret_value;
5985 }
5986
5987 int navit_normal_item(enum item_type type)
5988 {
5989 if ((type > type_none) && (type < type_waypoint))
5990 {
5991 return 1;
5992 }
5993 else if ((type >= type_poi_land_feature) && (type <= type_poi_zoo))
5994 {
5995 return 1;
5996 }
5997 else if ((type >= type_traffic_signals) && (type <= type_poi_cafe))
5998 {
5999 return 1;
6000 }
6001 else if ((type >= type_poi_peak) && (type <= type_poi_ruins))
6002 {
6003 return 1;
6004 }
6005 else if ((type >= type_poi_post_box) && (type <= type_house_number))
6006 {
6007 return 1;
6008 }
6009 else if ((type >= type_poi_playground) && (type <= type_poi_shop_photo))
6010 {
6011 return 1;
6012 }
6013 else if (type == type_place_label)
6014 {
6015 return 1;
6016 }
6017 else if ((type >= type_line) && (type <= type_ferry))
6018 {
6019 return 1;
6020 }
6021 else if (type == type_street_unkn)
6022 {
6023 return 1;
6024 }
6025 else if (type == type_street_service)
6026 {
6027 return 1;
6028 }
6029 else if (type == type_street_pedestrian)
6030 {
6031 return 1;
6032 }
6033 else if (type == type_street_parking_lane)
6034 {
6035 return 1;
6036 }
6037 else if (type == type_ramp_highway_land)
6038 {
6039 return 1;
6040 }
6041 else if (type == type_ramp_street_4_city)
6042 {
6043 return 1;
6044 }
6045 else if (type == type_ramp_street_3_city)
6046 {
6047 return 1;
6048 }
6049 else if (type == type_ramp_street_2_city)
6050 {
6051 return 1;
6052 }
6053 else if ((type >= type_aeroway_runway) && (type <= type_footway_and_piste_nordic))
6054 {
6055 return 1;
6056 }
6057 else if ((type >= type_house_number_interpolation_even) && (type <= type_city_wall))
6058 {
6059 return 1;
6060 }
6061 else if ((type >= type_border_city) && (type <= type_border_county))
6062 {
6063 return 1;
6064 }
6065 else if ((type >= type_forest_way_1) && (type <= type_forest_way_4))
6066 {
6067 return 1;
6068 }
6069 else if ((type >= type_area) && (type <= type_poly_museum))
6070 {
6071 return 1;
6072 }
6073 else if ((type >= type_poly_commercial_center) && (type <= type_tundra))
6074 {
6075 return 1;
6076 }
6077 else if ((type >= type_poly_building) && (type <= type_poly_terminal))
6078 {
6079 return 1;
6080 }
6081 else if ((type >= type_poly_sports_centre) && (type <= type_poly_aeroway_runway))
6082 {
6083 return 1;
6084 }
6085
6086 return 0;
6087 }
6088
6089 char* navit_find_nearest_item_dump(struct mapset *ms, struct pcoord *pc, int pretty)
6090 {
6091 int max_dist = 0; // smallest rectangle possible
6092 int dist, mindist = 0, pos;
6093 int mindist_hn = 0;
6094 struct mapset_handle *h;
6095 struct map *m;
6096 struct map_rect *mr;
6097 struct item *item;
6098 struct coord lp;
6099 struct street_data *sd;
6100 struct coord c;
6101 struct coord_geo g;
6102 struct map_selection sel;
6103 struct attr street_name_attr;
6104 struct attr hn_attr;
6105 char *ret_str = NULL;
6106
6107
6108
6109
6110 mindist = 1000;
6111
6112 h = mapset_open(ms);
6113 if (!h)
6114 {
6115 // dbg(0,"return 1\n");
6116 ret_str = g_strdup("");
6117 return ret_str;
6118 }
6119
6120 while ((m = mapset_next(h, 0)))
6121 {
6122 c.x = pc->x;
6123 c.y = pc->y;
6124 if (map_projection(m) != pc->pro)
6125 {
6126 transform_to_geo(pc->pro, &c, &g);
6127 transform_from_geo(map_projection(m), &g, &c);
6128 }
6129
6130 sel.next = NULL;
6131 sel.order = 18;
6132 sel.range.min = type_none;
6133 sel.range.max = type_last;
6134 sel.u.c_rect.lu.x = c.x - max_dist;
6135 sel.u.c_rect.lu.y = c.y + max_dist;
6136 sel.u.c_rect.rl.x = c.x + max_dist;
6137 sel.u.c_rect.rl.y = c.y - max_dist;
6138
6139 mr = map_rect_new(m, &sel);
6140 if (!mr)
6141 {
6142 continue;
6143 }
6144
6145 while ((item = map_rect_get_item(mr)))
6146 {
6147 if (navit_normal_item(item->type) == 1)
6148 {
6149 //dbg(0,"*type=%s\n", item_to_name(item->type));
6150
6151 struct coord c2[101];
6152 int count22 = item_coord_get(item, c2, 100);
6153 if (count22 == 0)
6154 {
6155 continue;
6156 }
6157 else if (count22 > 1)
6158 {
6159 dist = transform_distance_polyline_sq__v2(c2, count22, &c);
6160 if (dist < mindist)
6161 {
6162 mindist = dist;
6163 if (ret_str != NULL)
6164 {
6165 g_free(ret_str);
6166 }
6167 ret_str = navit_item_dump(item, pretty);
6168 }
6169 }
6170 else
6171 {
6172 dist = transform_distance_sq(&c, &c2);
6173 if (dist <= (mindist + 4))
6174 {
6175 mindist = dist;
6176 if (ret_str != NULL)
6177 {
6178 g_free(ret_str);
6179 }
6180 ret_str = navit_item_dump(item, pretty);
6181 }
6182 }
6183 // dbg(0,"*end\n");
6184 }
6185 }
6186
6187 if (mr)
6188 {
6189 map_rect_destroy(mr);
6190 }
6191 }
6192 mapset_close(h);
6193
6194 if (ret_str == NULL)
6195 {
6196 // dbg(0,"was NULL\n");
6197 ret_str = g_strdup("");
6198 }
6199
6200 return ret_str;
6201 }
6202
6203 /**
6204 * @brief Finds the nearest street to a given coordinate
6205 *
6206 * @param ms The mapset to search in for the street
6207 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
6208 * @return The nearest street
6209 */
6210 char*
6211 navit_find_nearest_street(struct mapset *ms, struct pcoord *pc)
6212 {
6213 int max_dist = 0; // smallest rectangle possible
6214 int dist, mindist = 0, pos;
6215 struct mapset_handle *h;
6216 struct map *m;
6217 struct map_rect *mr;
6218 struct item *item;
6219 struct coord lp;
6220 struct street_data *sd;
6221 struct coord c;
6222 struct coord_geo g;
6223 struct map_selection sel;
6224 struct attr street_name_attr;
6225 char *street_name = NULL;
6226
6227
6228
6229
6230 mindist = 10000; // start with small radius at the beginning!
6231 street_name = g_strdup(" ");
6232
6233 h = mapset_open(ms);
6234
6235 if (!h)
6236 {
6237 // set global value :-(
6238 dist_to_street = mindist;
6239 return street_name;
6240 }
6241
6242 while ((m = mapset_next(h, 0)))
6243 {
6244 c.x = pc->x;
6245 c.y = pc->y;
6246 if (map_projection(m) != pc->pro)
6247 {
6248 transform_to_geo(pc->pro, &c, &g);
6249 transform_from_geo(map_projection(m), &g, &c);
6250 }
6251
6252 sel.next = NULL;
6253 sel.order = 18;
6254 sel.range.min = type_line;
6255 sel.range.max = type_area;
6256 sel.u.c_rect.lu.x = c.x - max_dist;
6257 sel.u.c_rect.lu.y = c.y + max_dist;
6258 sel.u.c_rect.rl.x = c.x + max_dist;
6259 sel.u.c_rect.rl.y = c.y - max_dist;
6260
6261 mr = map_rect_new(m, &sel);
6262 if (!mr)
6263 {
6264 continue;
6265 }
6266
6267 while ((item = map_rect_get_item(mr)))
6268 {
6269 if (item_get_default_flags(item->type))
6270 {
6271 sd = street_get_data(item);
6272 if (!sd)
6273 {
6274 continue;
6275 }
6276
6277 //dbg(0,"6 sd x:%d sd y:%d count:%d\n", sd->c->x, sd->c->y, sd->count);
6278 //dbg(0,"6 c x:%d c y:%d\n", c.x, c.y);
6279 dist = transform_distance_polyline_sq__v2(sd->c, sd->count, &c);
6280 //dbg(0,"mindist:%d dist:%d\n", mindist, dist);
6281 if (dist < mindist)
6282 {
6283 //dbg(0,"6.a\n");
6284 mindist = dist;
6285
6286 if (item_attr_get(item, attr_street_name, &street_name_attr))
6287 {
6288 if (street_name)
6289 {
6290 g_free(street_name);
6291 street_name = NULL;
6292 }
6293 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6294 //dbg(0,"r3 %s\n", street_name);
6295 }
6296 else if (item_attr_get(item, attr_label, &street_name_attr))
6297 {
6298 if (street_name)
6299 {
6300 g_free(street_name);
6301 street_name = NULL;
6302 }
6303 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6304 //dbg(0,"r1 %s\n", street_name);
6305 }
6306 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
6307 {
6308 if (street_name)
6309 {
6310 g_free(street_name);
6311 street_name = NULL;
6312 }
6313 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6314 //dbg(0,"r4 %s\n", street_name);
6315 }
6316 else
6317 {
6318 //if (street_name)
6319 //{
6320 // g_free(street_name);
6321 // street_name = NULL;
6322 //}
6323 //street_name = g_strdup_printf("---");
6324 }
6325 }
6326 street_data_free(sd);
6327 }
6328 }
6329
6330 if (mr)
6331 {
6332 map_rect_destroy(mr);
6333 }
6334 }
6335 mapset_close(h);
6336 // set global value :-(
6337 dist_to_street = mindist;
6338 return street_name;
6339 }
6340
6341 /**
6342 * @brief Finds the nearest street or housenumber to a given coordinate
6343 *
6344 * @param ms The mapset to search in for the street
6345 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
6346 * @return The nearest street or housenumber
6347 */
6348 char*
6349 navit_find_nearest_street_hn(struct mapset *ms, struct pcoord *pc)
6350 {
6351 int max_dist = 0; // smallest rectangle possible
6352 int dist, mindist = 0, pos;
6353 int mindist_hn = 0;
6354 struct mapset_handle *h;
6355 struct map *m;
6356 struct map_rect *mr;
6357 struct item *item;
6358 struct coord lp;
6359 struct street_data *sd;
6360 struct coord c;
6361 struct coord_geo g;
6362 struct map_selection sel;
6363 struct attr street_name_attr;
6364 struct attr hn_attr;
6365 char *street_name = NULL;
6366 char *street_name_saved = NULL;
6367
6368
6369
6370
6371 // first find a street
6372 street_name_saved = navit_find_nearest_street(ms, pc);
6373 // street_name = g_strdup_printf(" ");
6374 street_name = g_strdup(street_name_saved);
6375 // first find a street
6376
6377 mindist = dist_to_street; // start with small radius at the beginning! (only use housenumber of different street, if we are really close to it!!)
6378 // global value -> this is naughty :-)
6379
6380 if (mindist < 8)
6381 {
6382 // so we can find other housenumbers if we are very close
6383 mindist = 8;
6384 }
6385
6386 mindist_hn = 10000;
6387
6388 //dbg(0,"given streetname %s %s dist %d\n", street_name, street_name_saved, dist_to_street);
6389
6390
6391 h = mapset_open(ms);
6392
6393 if (!h)
6394 {
6395 if (street_name_saved)
6396 {
6397 g_free(street_name_saved);
6398 street_name_saved = NULL;
6399 }
6400 return street_name;
6401 }
6402
6403 while ((m = mapset_next(h, 0)))
6404 {
6405 c.x = pc->x;
6406 c.y = pc->y;
6407 if (map_projection(m) != pc->pro)
6408 {
6409 transform_to_geo(pc->pro, &c, &g);
6410 transform_from_geo(map_projection(m), &g, &c);
6411 }
6412
6413 sel.next = NULL;
6414 sel.order = 18;
6415 sel.range.min = type_none;
6416 sel.range.max = type_area;
6417 sel.u.c_rect.lu.x = c.x - max_dist;
6418 sel.u.c_rect.lu.y = c.y + max_dist;
6419 sel.u.c_rect.rl.x = c.x + max_dist;
6420 sel.u.c_rect.rl.y = c.y - max_dist;
6421
6422 mr = map_rect_new(m, &sel);
6423 if (!mr)
6424 {
6425 continue;
6426 }
6427
6428 while ((item = map_rect_get_item(mr)))
6429 {
6430 if (item->type == type_house_number)
6431 {
6432 //dbg(0,"hn found\n");
6433 struct coord c2;
6434 int rrr = item_coord_get(item, &c2, 1);
6435 if (rrr)
6436 {
6437 dist = transform_distance_sq(&c, &c2);
6438 //dbg(0,"dist=%d\n", dist);
6439 if (dist < mindist)
6440 {
6441 if (item_attr_get(item, attr_street_name, &street_name_attr))
6442 {
6443 if (item_attr_get(item, attr_house_number, &hn_attr))
6444 {
6445 if (street_name)
6446 {
6447 g_free(street_name);
6448 street_name = NULL;
6449 }
6450 street_name = g_strdup_printf("%s %s", street_name_attr.u.str, hn_attr.u.str);
6451 //dbg(0,"sn 1\n");
6452 mindist = dist;
6453 mindist_hn = dist;
6454 }
6455 }
6456 }
6457 // else try to find housenumbers for our current street
6458 // just take the nearest housenumber for our current street
6459 else if (dist < mindist_hn)
6460 {
6461 //dbg(0,"sn 2.1\n");
6462 if (item_attr_get(item, attr_street_name, &street_name_attr))
6463 {
6464 //dbg(0,"sn 2.2\n");
6465 if (item_attr_get(item, attr_house_number, &hn_attr))
6466 {
6467 //dbg(0,"sn 2.3\n");
6468 if ((street_name != NULL) && (street_name_saved != NULL))
6469 {
6470 // dbg(0,"sn 2.4 -%s- -%s-\n", street_name_saved, street_name_attr.u.str);
6471 if (!strcmp(street_name_saved, street_name_attr.u.str))
6472 {
6473 g_free(street_name);
6474 street_name = NULL;
6475
6476 // dbg(0,"sn 2.99\n");
6477
6478 street_name = g_strdup_printf("%s %s", street_name_attr.u.str, hn_attr.u.str);
6479 mindist_hn = dist;
6480 }
6481 }
6482 }
6483 }
6484 }
6485 }
6486 }
6487
6488 #if 0
6489 //else if (item->type > type_line)
6490 if (1 == 0) // DISABLED !!!!!!
6491
6492 {
6493 if (item_get_default_flags(item->type))
6494 {
6495 sd = street_get_data(item);
6496 if (!sd)
6497 {
6498 continue;
6499 }
6500 dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
6501 if (dist < mindist)
6502 {
6503 mindist = dist;
6504
6505 if (item_attr_get(item, attr_label, &street_name_attr))
6506 {
6507 if (street_name)
6508 {
6509 g_free(street_name);
6510 street_name = NULL;
6511 }
6512 if (street_name_saved)
6513 {
6514 g_free(street_name_saved);
6515 street_name_saved = NULL;
6516 }
6517 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6518 street_name_saved = g_strdup(street_name);
6519 }
6520 else if (item_attr_get(item, attr_street_name, &street_name_attr))
6521 {
6522 if (street_name)
6523 {
6524 g_free(street_name);
6525 street_name = NULL;
6526 }
6527 if (street_name_saved)
6528 {
6529 g_free(street_name_saved);
6530 street_name_saved = NULL;
6531 }
6532 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6533 street_name_saved = g_strdup(street_name);
6534 }
6535 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
6536 {
6537 if (street_name)
6538 {
6539 g_free(street_name);
6540 street_name = NULL;
6541 }
6542 if (street_name_saved)
6543 {
6544 g_free(street_name_saved);
6545 street_name_saved = NULL;
6546 }
6547 street_name = g_strdup_printf("%s", street_name_attr.u.str);
6548 street_name_saved = g_strdup(street_name);
6549 }
6550 }
6551 street_data_free(sd);
6552 }
6553 }
6554 #endif
6555 }
6556
6557 if (mr)
6558 {
6559 map_rect_destroy(mr);
6560 }
6561 }
6562
6563 if (street_name_saved)
6564 {
6565 g_free(street_name_saved);
6566 street_name_saved = NULL;
6567 }
6568
6569 mapset_close(h);
6570 return street_name;
6571 }
6572
6573 /**
6574 * @brief Finds the nearest street to a given coordinate
6575 *
6576 * @param ms The mapset to search in for the street
6577 * @param pc The coordinate to find a street nearby [ input in pcoord(x,y) ]
6578 * @return The nearest street (as a string of coords "0xFFF 0xFFF\n..." seperated by "\n")
6579 */
6580 char*
6581 navit_find_nearest_street_coords(struct mapset *ms, struct pcoord *pc)
6582 {
6583 int max_dist = 0; // smallest rectangle possible
6584 int dist, mindist = 0, pos;
6585 struct mapset_handle *h;
6586 struct map *m;
6587 struct map_rect *mr;
6588 struct item *item;
6589 struct coord lp;
6590 struct street_data *sd = NULL;
6591 struct street_data *sd_copy = NULL;
6592 struct coord c;
6593 struct coord_geo g;
6594 struct map_selection sel;
6595 int i;
6596 int found_good = 0;
6597 struct attr street_name_attr;
6598 char *street_coords = NULL;
6599 char *street_coords_tmp = NULL;
6600
6601
6602
6603
6604 mindist = 10000; // start with small radius at the beginning!
6605 street_coords = g_strdup_printf("", "");
6606
6607 h = mapset_open(ms);
6608
6609 if (!h)
6610 {
6611 return street_coords;
6612 }
6613
6614 while ((m = mapset_next(h, 0)))
6615 {
6616 c.x = pc->x;
6617 c.y = pc->y;
6618 if (map_projection(m) != pc->pro)
6619 {
6620 transform_to_geo(pc->pro, &c, &g);
6621 transform_from_geo(map_projection(m), &g, &c);
6622 }
6623
6624 sel.next = NULL;
6625 sel.order = 18;
6626 sel.range.min = type_line;
6627 sel.range.max = type_area;
6628 sel.u.c_rect.lu.x = c.x - max_dist;
6629 sel.u.c_rect.lu.y = c.y + max_dist;
6630 sel.u.c_rect.rl.x = c.x + max_dist;
6631 sel.u.c_rect.rl.y = c.y - max_dist;
6632
6633 mr = map_rect_new(m, &sel);
6634 if (!mr)
6635 {
6636 continue;
6637 }
6638
6639 while ((item = map_rect_get_item(mr)))
6640 {
6641 if (item_get_default_flags(item->type))
6642 {
6643 sd = street_get_data(item);
6644 if (!sd)
6645 {
6646 continue;
6647 }
6648 found_good = 0;
6649 // OLD // dist = transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
6650 dist = transform_distance_polyline_sq__v2(sd->c, sd->count, &c);
6651 if (dist < mindist)
6652 {
6653 mindist = dist;
6654
6655 /*
6656 if (item_attr_get(item, attr_label, &street_name_attr))
6657 {
6658 found_good = 1;
6659 }
6660 else if (item_attr_get(item, attr_street_name, &street_name_attr))
6661 {
6662 found_good = 1;
6663 }
6664 else if (item_attr_get(item, attr_street_name_systematic, &street_name_attr))
6665 {
6666 found_good = 1;
6667 }
6668 */
6669
6670 // allow any street/line, so you can select streets without name also!
6671 found_good = 1;
6672 }
6673
6674 if (found_good == 1)
6675 {
6676 if (sd_copy)
6677 {
6678 street_data_free(sd_copy);
6679 }
6680 sd_copy = street_data_dup(sd);
6681 }
6682 street_data_free(sd);
6683 }
6684 }
6685
6686 if (mr)
6687 {
6688 map_rect_destroy(mr);
6689 }
6690 }
6691 mapset_close(h);
6692
6693 if (sd_copy)
6694 {
6695 //struct coord ca[sd_copy->count];
6696 //item_coord_get(&sd_copy->item, ca, sd_copy->count);
6697
6698 // dbg(0,"sd_copy->count=%d\n", sd_copy->count);
6699
6700 for (i = 0; i < sd_copy->count; i++)
6701 {
6702 /*
6703 unsigned int x;
6704 unsigned int y;
6705 char *sign_x = "";
6706 char *sign_y = "";
6707
6708 if ( c->x < 0 ) {
6709 x = -c->x;
6710 sign_x = "-";
6711 } else {
6712 x = c->x;
6713 }
6714 if ( c->y < 0 ) {
6715 y = -c->y;
6716 sign_y = "-";
6717 } else {
6718 y = c->y;
6719 }
6720 */
6721
6722 street_coords_tmp = street_coords;
6723 if (street_coords == NULL)
6724 {
6725 street_coords = g_strdup_printf("0x%x 0x%x\n", sd_copy->c[i].x, sd_copy->c[i].y);
6726 }
6727 else
6728 {
6729 char *tmp2 = g_strdup_printf("0x%x 0x%x\n", sd_copy->c[i].x, sd_copy->c[i].y);
6730 street_coords = g_strconcat(street_coords_tmp, tmp2, NULL);
6731 g_free(street_coords_tmp);
6732 g_free(tmp2);
6733 }
6734 }
6735
6736 street_data_free(sd_copy);
6737 }
6738
6739 return street_coords;
6740 }
6741
6742 // UNUSDED -------
6743 // UNUSDED -------
6744 int navit_block(struct navit *this_, int block)
6745 {
6746
6747
6748 ////DBG dbg(0,"EEnter\n");
6749
6750 if (block > 0)
6751 {
6752 this_->blocked |= 1;
6753 if (graphics_draw_cancel(this_->gra, this_->displaylist))
6754 this_->blocked |= 2;
6755 return 0;
6756 }
6757 if ((this_->blocked & 2) || block < 0)
6758 {
6759 this_->blocked = 0;
6760 navit_draw(this_);
6761 return 1;
6762 }
6763 this_->blocked = 0;
6764 return 0;
6765 }
6766
6767 FILE * navit_start_gpx_file(char *filename)
6768 {
6769 char *header1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
6770 "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n"
6771 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
6772 " xmlns=\"http://www.topografix.com/GPX/1/1\"\n"
6773 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
6774 "<metadata>\n"
6775 " <name>ZANavi Debug log</name>\n"
6776 " <desc>ZANavi</desc>\n"
6777 " <author>\n"
6778 " <name>ZANavi</name>\n"
6779 " </author>\n"
6780 "</metadata>\n"
6781 "<trk>\n"
6782 "<trkseg>\n"
6783 " <name>ACTIVE LOG</name>\n";
6784
6785 FILE *fp;
6786
6787 if (filename)
6788 {
6789 fp = fopen(filename,"w");
6790 }
6791 else
6792 {
6793 fp = fopen("/sdcard/zanavi_debug_001.gpx","w");
6794 }
6795
6796 fprintf(fp, "%s", header1);
6797
6798 return fp;
6799 }
6800
6801 void navit_add_trkpoint_to_gpx_file(FILE *fp, struct coord *c)
6802 {
6803 struct coord_geo g;
6804 transform_to_geo(projection_mg, c, &g);
6805 fprintf(fp, " <trkpt lat='%4.6f' lon='%4.6f'><time>2014-10-02T09:30:10Z</time></trkpt>\n", g.lat, g.lng);
6806 }
6807
6808
6809 void navit_end_gpx_track_seg(FILE *fp)
6810 {
6811 fprintf(fp,"</trkseg>\n</trk>\n");
6812 }
6813
6814 void navit_start_gpx_track_seg(FILE *fp)
6815 {
6816 fprintf(fp,"<trk>\n<trkseg>\n");
6817 }
6818
6819
6820 void navit_end_gpx_file(FILE *fp)
6821 {
6822 char *trailer1= "</trkseg>\n"
6823 "</trk>\n"
6824 "</gpx>\n";
6825
6826 fprintf(fp,"%s",trailer1);
6827 fclose(fp);
6828 }
6829
6830 GList* navit_route_export_to_java_string(struct navit *this_, int result_id)
6831 {
6832 struct point p;
6833 struct map *map=NULL;
6834 struct navigation *nav = NULL;
6835 struct map_rect *mr=NULL;
6836 struct item *item =NULL;
6837 struct attr attr,route;
6838 struct coord c;
6839 // struct coord c_end;
6840 struct coord_geo g;
6841 struct transformation *trans;
6842 char *d = NULL;
6843 char *result_string = NULL;
6844 GList* result = NULL;
6845
6846 nav = navit_get_navigation(this_);
6847
6848 if (!nav)
6849 {
6850 return NULL;
6851 }
6852
6853 map = navigation_get_map(nav);
6854
6855 if (map)
6856 {
6857 mr = map_rect_new(map,NULL);
6858 }
6859 else
6860 {
6861 return;
6862 }
6863
6864 trans = navit_get_trans(this_);
6865
6866 mr = map_rect_new(map,NULL);
6867 while ((item = map_rect_get_item(mr)))
6868 {
6869
6870 // dbg(0, "005 ============== = %s : %d\n", item_to_name(item->type), item->id_lo);
6871
6872 //if (item_attr_get(item, attr_navigation_short, &attr))
6873 //{
6874 // dbg(0, "005.c.01:%s\n", attr.u.str);
6875 //}
6876
6877 if (item_attr_get(item, attr_length, &attr))
6878 {
6879 if (attr.u.num > 0)
6880 {
6881 d = get_distance(nav, attr.u.num, attr_navigation_short, 1);
6882 }
6883
6884 // dbg(0, "005.c.02:%d %s\n", attr.u.num, d); // dist to next turn in meters! (take care when in imperial mode!)
6885 }
6886 else
6887 {
6888 d = NULL;
6889 }
6890
6891 if ((item_attr_get(item, attr_navigation_long_exact, &attr)) || (item->type == type_nav_waypoint))
6892 {
6893 dbg(0, "NAVICG:call type=%s\n", item_to_name(item->type));
6894 item_coord_get(item, &c, 1);
6895 dbg(0, "NAVICG:call END\n");
6896
6897 //int num_coords = 0;
6898 //while (item_coord_get(item, &c_end, 1))
6899 //{
6900 // num_coords++;
6901 //}
6902
6903 transform_to_geo(projection_mg, &c, &g);
6904
6905 if (result)
6906 {
6907 }
6908 else
6909 {
6910 // 1st line is the ID
6911 result = g_list_append(result, g_strdup_printf("%d", result_id));
6912 if (result_id == 9990001)
6913 {
6914 // 2nd line is distance to target in meters
6915 int len_meters_to_target = 0;
6916 if (nav)
6917 {
6918 if (nav->first)
6919 {
6920 len_meters_to_target = nav->first->dest_length;
6921 }
6922 }
6923 result = g_list_append(result, g_strdup_printf("meters:%d", len_meters_to_target));
6924 }
6925 }
6926
6927 dbg(0, "013 %s %s\n", item_to_name(item->type), map_convert_string(item->map, attr.u.str));
6928
6929 if (item->type == type_nav_waypoint)
6930 {
6931 result = g_list_append(result, g_strdup_printf("%s:%4.8f:%4.8f:%s:%s", d ? d : "", g.lat, g.lng, item_to_name(item->type), _("Waypoint")));
6932 }
6933 else
6934 {
6935 result = g_list_append(result, g_strdup_printf("%s:%4.8f:%4.8f:%s:%s", d ? d : "", g.lat, g.lng, item_to_name(item->type), map_convert_string(item->map,attr.u.str)));
6936 }
6937 }
6938 else
6939 {
6940 // must be the start point (without navigation command)
6941 item_coord_get(item, &c, 1);
6942 transform_to_geo(projection_mg, &c, &g);
6943
6944 if (result)
6945 {
6946 }
6947 else
6948 {
6949 // 1st line is the ID
6950 result = g_list_append(result, g_strdup_printf("%d", result_id));
6951 if (result_id == 9990001)
6952 {
6953 // 2nd line is distance to target in meters
6954 int len_meters_to_target = 0;
6955 if (nav)
6956 {
6957 if (nav->first)
6958 {
6959 len_meters_to_target = nav->first->dest_length;
6960 }
6961 }
6962 result = g_list_append(result, g_strdup_printf("meters:%d", len_meters_to_target));
6963 }
6964 }
6965
6966 // dbg(0, "019.0 %p\n", attr.u.str);
6967 // dbg(0, "019.b %d\n", item->type);
6968 // dbg(0, "019.c %s\n", item_to_name(item->type));
6969 result = g_list_append(result, g_strdup_printf("%s:%4.8f:%4.8f:+start+:", d ? d : "", g.lat, g.lng));
6970 }
6971
6972 if (d)
6973 {
6974 g_free(d);
6975 d = NULL;
6976 }
6977
6978 }
6979
6980 map_rect_destroy(mr);
6981
6982 return result;
6983
6984 }
6985
6986 void navit_route_export_gpx_to_file(struct navit *this_, char *filename)
6987 {
6988
6989
6990
6991 dbg(0,"Dumping route to %s\n", filename);
6992
6993 struct point p;
6994 struct map *map=NULL;
6995 struct navigation *nav = NULL;
6996 struct map_rect *mr=NULL;
6997 struct item *item =NULL;
6998 struct attr attr,route;
6999 struct coord c;
7000 struct coord_geo g;
7001 struct transformation *trans;
7002
7003 char *header1 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
7004 "<gpx version=\"1.1\" creator=\"ZANavi http://zanavi.cc\"\n"
7005 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
7006 " xmlns=\"http://www.topografix.com/GPX/1/1\"\n"
7007 " xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"
7008 "<metadata>\n"
7009 " <name>ZANavi Track log</name>\n"
7010 " <desc>ZANavi</desc>\n"
7011 " <author>\n"
7012 " <name>ZANavi</name>\n"
7013 " </author>\n"
7014 "</metadata>\n"
7015 "<trk>\n"
7016 "<trkseg>\n"
7017 " <name>ACTIVE LOG</name>\n";
7018
7019 char *trailer1= "</trkseg>\n"
7020 "</trk>\n";
7021
7022 // char *trkcolor= "<extensions>\n"
7023 // " <gpxx:TrackExtension>\n"
7024 // " <gpxx:DisplayColor>Magenta</gpxx:DisplayColor>\n"
7025 // " </gpxx:TrackExtension>\n"
7026 // "</extensions>\n";
7027
7028 char *header2 = "<rte>\n";
7029
7030 char *trailer2= "</rte>\n"
7031 "</gpx>\n";
7032
7033
7034 // -------- full route ---------
7035 // -------- full route ---------
7036 struct route *route2 = NULL;
7037 struct map *route_map2 = NULL;
7038 struct map_rect *mr2 = NULL;
7039 struct item *item2 = NULL;
7040 struct coord c2;
7041
7042 route2 = navit_get_route(this_);
7043
7044 if (route2)
7045 {
7046 route_map2 = route_get_map(route2);
7047 }
7048
7049 if (route_map2)
7050 {
7051 mr2 = map_rect_new(route_map2, NULL);
7052 }
7053
7054 if (mr2)
7055 {
7056 item2 = map_rect_get_item(mr2);
7057 }
7058
7059 if (item2 && item2->type == type_route_start)
7060 {
7061 item2 = map_rect_get_item(mr2);
7062 }
7063
7064 FILE *fp;
7065 fp = fopen(filename,"w");
7066 fprintf(fp, "%s", header1);
7067 int first3 = 0;
7068
7069 if (item2 && item_coord_get(item2, &c2, 1))
7070 {
7071 transform_to_geo(projection_mg, &c2, &g);
7072 fprintf(fp, " <trkpt lat='%4.16f' lon='%4.16f'><time>2014-10-02T09:30:10Z</time></trkpt>\n", g.lat, g.lng);
7073
7074 while (item2)
7075 {
7076 if (!item_coord_get(item2, &c2, 1))
7077 {
7078 item2 = map_rect_get_item(mr2);
7079 first3 = 1;
7080 continue;
7081 }
7082
7083 if (first3 == 0)
7084 {
7085 transform_to_geo(projection_mg, &c2, &g);
7086 fprintf(fp, " <trkpt lat='%4.16f' lon='%4.16f'><time>2014-10-02T09:30:10Z</time></trkpt>\n", g.lat, g.lng);
7087 }
7088 else
7089 {
7090 first3 = 0;
7091 // fprintf(fp, "Y**********\n");
7092 }
7093 }
7094 }
7095
7096 map_rect_destroy(mr2);
7097
7098 // -------- full route ---------
7099 // -------- full route ---------
7100
7101
7102
7103
7104
7105 nav = navit_get_navigation(this_);
7106
7107 if (!nav)
7108 {
7109 return;
7110 }
7111
7112 map = navigation_get_map(nav);
7113
7114 if (map)
7115 {
7116 mr = map_rect_new(map,NULL);
7117 }
7118 else
7119 {
7120 return;
7121 }
7122
7123 trans = navit_get_trans(this_);
7124
7125
7126 //while((item = map_rect_get_item(mr)))
7127 //{
7128 // item_coord_get(item, &c, 1);
7129 // transform_to_geo(projection_mg, &c, &g);
7130 // fprintf(fp, " <trkpt lon='%4.16f' lat='%4.16f'><time>2014-10-02T09:30:10Z</time></trkpt>\n", g.lng, g.lat);
7131 //}
7132 map_rect_destroy(mr);
7133
7134
7135
7136 fprintf(fp,"%s",trailer1);
7137
7138
7139
7140 mr = map_rect_new(map,NULL);
7141 while ((item = map_rect_get_item(mr)))
7142 {
7143 if (item_attr_get(item, attr_navigation_long, &attr))
7144 {
7145 item_coord_get(item, &c, 1);
7146 transform_to_geo(projection_mg, &c, &g);
7147 fprintf(fp, "<wpt lat=\"%4.16f\" lon=\"%4.16f\"><time>2014-10-02T09:30:10Z</time><name>%s:%s</name><sym>Dot</sym><type>Dot></type></wpt>\n", g.lat, g.lng, item_to_name(item->type), map_convert_string(item->map,attr.u.str));
7148 }
7149 else
7150 {
7151 // must be the start point (without navigation command)
7152 item_coord_get(item, &c, 1);
7153 transform_to_geo(projection_mg, &c, &g);
7154 fprintf(fp, "<wpt lat=\"%4.16f\" lon=\"%4.16f\"><time>2014-10-02T09:30:10Z</time><name>START</name><sym>Dot</sym><type>Dot></type></wpt>\n", g.lat, g.lng);
7155 }
7156 }
7157 map_rect_destroy(mr);
7158
7159
7160
7161 fprintf(fp,"%s",header2);
7162
7163
7164
7165 mr = map_rect_new(map,NULL);
7166 while ((item = map_rect_get_item(mr)))
7167 {
7168 if (item_attr_get(item, attr_navigation_long, &attr))
7169 {
7170 item_coord_get(item, &c, 1);
7171 transform_to_geo(projection_mg, &c, &g);
7172 fprintf(fp, "<rtept lat='%4.16f' lon='%4.16f'><name>%s:%s</name></rtept>\n", g.lat, g.lng, item_to_name(item->type), map_convert_string(item->map,attr.u.str));
7173 }
7174 else
7175 {
7176 // must be the start point (without navigation command)
7177 item_coord_get(item, &c, 1);
7178 transform_to_geo(projection_mg, &c, &g);
7179 fprintf(fp, "<rtept lat='%4.16f' lon='%4.16f'><name>START</name></rtept>\n", g.lat, g.lng);
7180 }
7181 }
7182 map_rect_destroy(mr);
7183
7184 fprintf(fp,"%s",trailer2);
7185
7186 fclose(fp);
7187
7188 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
7189 dbg(0,"+#+:leave\n");
7190 #endif
7191
7192 }
7193
7194
7195 void navit_destroy(struct navit *this_)
7196 {
7197
7198
7199 dbg(0, "EEnter\n");
7200
7201 struct mapset*ms;
7202 callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
7203
7204 // //DBG dbg(0,"enter");
7205
7206 /* TODO: destroy objects contained in this_ */
7207 if (this_->vehicle)
7208 {
7209 vehicle_destroy(this_->vehicle->vehicle);
7210 }
7211
7212 /*
7213 if (this_->bookmarks)
7214 {
7215 dbg(0, "save position to file\n");
7216 char *center_file = bookmarks_get_center_file(TRUE);
7217 bookmarks_write_center_to_file(this_->bookmarks, center_file);
7218 g_free(center_file);
7219 bookmarks_destroy(this_->bookmarks);
7220 dbg(0, "save position to file -> ready\n");
7221 }
7222 */
7223
7224 dbg(0, "ex 001\n");
7225 callback_destroy(this_->nav_speech_cb);
7226 dbg(0, "ex 002\n");
7227 callback_destroy(this_->roadbook_callback);
7228 dbg(0, "ex 003\n");
7229 callback_destroy(this_->popup_callback);
7230 dbg(0, "ex 004\n");
7231 callback_destroy(this_->motion_timeout_callback);
7232 dbg(0, "ex 005\n");
7233 callback_destroy(this_->progress_cb);
7234 dbg(0, "ex 006\n");
7235 /*
7236 if (this_->gra)
7237 graphics_remove_callback(this_->gra, this_->resize_callback);
7238 callback_destroy(this_->resize_callback);
7239 */
7240 dbg(0, "ex 007\n");
7241 /*
7242 if (this_->gra)
7243 graphics_remove_callback(this_->gra, this_->button_callback);
7244 callback_destroy(this_->button_callback);
7245 */
7246 dbg(0, "ex 008\n");
7247 /*
7248 if (this_->gra)
7249 graphics_remove_callback(this_->gra, this_->motion_callback);
7250 callback_destroy(this_->motion_callback);
7251 */
7252 dbg(0, "ex 009\n");
7253 if (this_->gra)
7254 {
7255 graphics_remove_callback(this_->gra, this_->predraw_callback);
7256 }
7257 callback_destroy(this_->predraw_callback);
7258 dbg(0, "ex 010\n");
7259 route_destroy(this_->route);
7260 dbg(0, "ex 011\n");
7261 ms = navit_get_mapset(this_);
7262 dbg(0, "ex 012\n");
7263
7264 if (ms)
7265 {
7266 mapset_destroy(ms);
7267 }
7268
7269 dbg(0, "ex 013\n");
7270 graphics_free(this_->gra);
7271 dbg(0, "ex 014\n");
7272 g_free(this_);
7273 dbg(0, "ex 015\n");
7274 }
7275
7276 /** @} */
7277

   
Visit the ZANavi Wiki