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