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

Contents of /navit/navit/navit.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki