1 |
zoff99 |
2 |
/**
|
2 |
zoff99 |
27 |
* ZANavi, Zoff Android Navigation system.
|
3 |
|
|
* Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
|
4 |
|
|
*
|
5 |
|
|
* This program is free software; you can redistribute it and/or
|
6 |
|
|
* modify it under the terms of the GNU General Public License
|
7 |
|
|
* version 2 as published by the Free Software Foundation.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the
|
16 |
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
|
|
* Boston, MA 02110-1301, USA.
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
zoff99 |
2 |
* 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 |
|
|
#include <stdio.h>
|
40 |
|
|
#include <string.h>
|
41 |
|
|
#include <glib.h>
|
42 |
|
|
#include <time.h>
|
43 |
|
|
#include "config.h"
|
44 |
|
|
#include "debug.h"
|
45 |
|
|
#include "coord.h"
|
46 |
|
|
#include "item.h"
|
47 |
|
|
#include "log.h"
|
48 |
|
|
#include "plugin.h"
|
49 |
|
|
#include "transform.h"
|
50 |
|
|
#include "util.h"
|
51 |
|
|
#include "event.h"
|
52 |
|
|
#include "coord.h"
|
53 |
zoff99 |
30 |
#include "navit.h"
|
54 |
zoff99 |
2 |
#include "transform.h"
|
55 |
|
|
#include "projection.h"
|
56 |
|
|
#include "point.h"
|
57 |
|
|
#include "graphics.h"
|
58 |
|
|
#include "callback.h"
|
59 |
|
|
#include "color.h"
|
60 |
|
|
#include "layout.h"
|
61 |
|
|
#include "vehicle.h"
|
62 |
|
|
|
63 |
zoff99 |
30 |
// forward rev
|
64 |
|
|
struct navit *global_navit;
|
65 |
|
|
|
66 |
|
|
|
67 |
zoff99 |
27 |
struct vehicle
|
68 |
|
|
{
|
69 |
zoff99 |
2 |
struct vehicle_methods meth;
|
70 |
|
|
struct vehicle_priv *priv;
|
71 |
|
|
struct callback_list *cbl;
|
72 |
|
|
struct log *nmea_log, *gpx_log;
|
73 |
|
|
char *gpx_desc;
|
74 |
|
|
struct attr **attrs;
|
75 |
|
|
|
76 |
|
|
// cursor
|
77 |
|
|
struct cursor *cursor;
|
78 |
|
|
int cursor_fixed;
|
79 |
|
|
struct callback *animate_callback;
|
80 |
|
|
struct event_timeout *animate_timer;
|
81 |
|
|
struct point cursor_pnt;
|
82 |
|
|
struct graphics *gra;
|
83 |
|
|
struct graphics_gc *bg;
|
84 |
|
|
struct transformation *trans;
|
85 |
|
|
int angle;
|
86 |
|
|
int speed;
|
87 |
|
|
int sequence;
|
88 |
|
|
GHashTable *log_to_cb;
|
89 |
|
|
};
|
90 |
|
|
|
91 |
|
|
static void vehicle_draw_do(struct vehicle *this_, int lazy);
|
92 |
|
|
static void vehicle_log_nmea(struct vehicle *this_, struct log *log);
|
93 |
|
|
static void vehicle_log_gpx(struct vehicle *this_, struct log *log);
|
94 |
|
|
static void vehicle_log_textfile(struct vehicle *this_, struct log *log);
|
95 |
|
|
static void vehicle_log_binfile(struct vehicle *this_, struct log *log);
|
96 |
|
|
static int vehicle_add_log(struct vehicle *this_, struct log *log);
|
97 |
zoff99 |
27 |
void vehicle_remove_cursor(struct vehicle *this_);
|
98 |
zoff99 |
28 |
extern int hold_drawing; // in navit.c
|
99 |
zoff99 |
2 |
|
100 |
|
|
/**
|
101 |
|
|
* Creates a new vehicle
|
102 |
|
|
*/
|
103 |
|
|
struct vehicle *
|
104 |
|
|
vehicle_new(struct attr *parent, struct attr **attrs)
|
105 |
|
|
{
|
106 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
107 |
|
|
dbg(0,"+#+:enter\n");
|
108 |
|
|
#endif
|
109 |
zoff99 |
2 |
struct vehicle *this_;
|
110 |
|
|
struct attr *source;
|
111 |
zoff99 |
27 |
struct vehicle_priv *(*vehicletype_new)(struct vehicle_methods * meth, struct callback_list * cbl, struct attr ** attrs);
|
112 |
zoff99 |
2 |
char *type, *colon;
|
113 |
|
|
struct pcoord center;
|
114 |
|
|
|
115 |
zoff99 |
27 |
//DBG dbg(0, "enter\n");
|
116 |
zoff99 |
2 |
source = attr_search(attrs, NULL, attr_source);
|
117 |
zoff99 |
27 |
if (!source)
|
118 |
|
|
{
|
119 |
|
|
//DBG dbg(0, "no source\n");
|
120 |
zoff99 |
2 |
return NULL;
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
type = g_strdup(source->u.str);
|
124 |
|
|
colon = strchr(type, ':');
|
125 |
|
|
if (colon)
|
126 |
zoff99 |
27 |
{
|
127 |
zoff99 |
2 |
*colon = '\0';
|
128 |
zoff99 |
27 |
}
|
129 |
|
|
////DBG dbg(0, "source='%s' type='%s'\n", source->u.str, type);
|
130 |
zoff99 |
2 |
|
131 |
|
|
vehicletype_new = plugin_get_vehicle_type(type);
|
132 |
zoff99 |
27 |
if (!vehicletype_new)
|
133 |
|
|
{
|
134 |
|
|
//DBG dbg(0, "invalid type '%s'\n", type);
|
135 |
zoff99 |
2 |
g_free(type);
|
136 |
|
|
return NULL;
|
137 |
|
|
}
|
138 |
|
|
g_free(type);
|
139 |
|
|
this_ = g_new0(struct vehicle, 1);
|
140 |
|
|
this_->cbl = callback_list_new();
|
141 |
|
|
this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
|
142 |
zoff99 |
27 |
//DBG dbg(0, "veh new 2\n");
|
143 |
|
|
if (!this_->priv)
|
144 |
|
|
{
|
145 |
|
|
//DBG dbg(0, "vehicletype_new failed\n");
|
146 |
zoff99 |
2 |
callback_list_destroy(this_->cbl);
|
147 |
|
|
g_free(this_);
|
148 |
|
|
return NULL;
|
149 |
|
|
}
|
150 |
zoff99 |
27 |
//DBG dbg(0, "veh new 3\n");
|
151 |
|
|
this_->attrs = attr_list_dup(attrs);
|
152 |
|
|
//DBG dbg(0, "veh new 4\n");
|
153 |
|
|
this_->trans = transform_new();
|
154 |
zoff99 |
2 |
|
155 |
|
|
// set bad 0/0 location ??? i dont know really
|
156 |
|
|
/*
|
157 |
zoff99 |
27 |
struct coord_geo g;
|
158 |
|
|
struct coord co;
|
159 |
|
|
enum projection pro=projection_mg;
|
160 |
|
|
g.lat=53.13;
|
161 |
|
|
g.lng=11.70;
|
162 |
|
|
transform_from_geo(pro, &g, &co);
|
163 |
|
|
center.x=co.x;
|
164 |
|
|
center.y=co.y;
|
165 |
|
|
center.pro = pro;
|
166 |
|
|
*/
|
167 |
zoff99 |
2 |
|
168 |
zoff99 |
27 |
center.pro = projection_screen;
|
169 |
|
|
center.x = 0;
|
170 |
|
|
center.y = 0;
|
171 |
|
|
//DBG dbg(0, "veh new 5\n");
|
172 |
zoff99 |
2 |
transform_setup(this_->trans, ¢er, 16, 0);
|
173 |
zoff99 |
27 |
//DBG dbg(0, "veh new 6\n");
|
174 |
zoff99 |
2 |
|
175 |
zoff99 |
27 |
this_->log_to_cb = g_hash_table_new(NULL, NULL);
|
176 |
|
|
//DBG dbg(0, "leave\n");
|
177 |
zoff99 |
2 |
return this_;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
/**
|
181 |
|
|
* Destroys a vehicle
|
182 |
|
|
*
|
183 |
|
|
* @param this_ The vehicle to destroy
|
184 |
|
|
*/
|
185 |
zoff99 |
27 |
void vehicle_destroy(struct vehicle *this_)
|
186 |
zoff99 |
2 |
{
|
187 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
188 |
|
|
dbg(0,"+#+:enter\n");
|
189 |
|
|
#endif
|
190 |
zoff99 |
27 |
if (this_->animate_callback)
|
191 |
|
|
{
|
192 |
zoff99 |
2 |
callback_destroy(this_->animate_callback);
|
193 |
|
|
event_remove_timeout(this_->animate_timer);
|
194 |
|
|
}
|
195 |
|
|
transform_destroy(this_->trans);
|
196 |
|
|
this_->meth.destroy(this_->priv);
|
197 |
|
|
callback_list_destroy(this_->cbl);
|
198 |
|
|
attr_list_free(this_->attrs);
|
199 |
|
|
if (this_->bg)
|
200 |
|
|
graphics_gc_destroy(this_->bg);
|
201 |
|
|
if (this_->gra)
|
202 |
|
|
graphics_free(this_->gra);
|
203 |
|
|
g_free(this_);
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
/**
|
207 |
|
|
* Creates an attribute iterator to be used with vehicles
|
208 |
|
|
*/
|
209 |
|
|
struct attr_iter *
|
210 |
|
|
vehicle_attr_iter_new(void)
|
211 |
|
|
{
|
212 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
213 |
|
|
dbg(0,"+#+:enter\n");
|
214 |
|
|
#endif
|
215 |
zoff99 |
27 |
return (struct attr_iter *)g_new0(void *,1);
|
216 |
zoff99 |
2 |
}
|
217 |
|
|
|
218 |
|
|
/**
|
219 |
|
|
* Destroys a vehicle attribute iterator
|
220 |
|
|
*
|
221 |
|
|
* @param iter a vehicle attr_iter
|
222 |
|
|
*/
|
223 |
zoff99 |
27 |
void vehicle_attr_iter_destroy(struct attr_iter *iter)
|
224 |
zoff99 |
2 |
{
|
225 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
226 |
|
|
dbg(0,"+#+:enter\n");
|
227 |
|
|
#endif
|
228 |
zoff99 |
2 |
g_free(iter);
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
/**
|
232 |
|
|
* Generic get function
|
233 |
|
|
*
|
234 |
|
|
* @param this_ Pointer to a vehicle structure
|
235 |
|
|
* @param type The attribute type to look for
|
236 |
|
|
* @param attr Pointer to an attr structure to store the attribute
|
237 |
|
|
* @param iter A vehicle attr_iter
|
238 |
|
|
*/
|
239 |
zoff99 |
27 |
int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
|
240 |
zoff99 |
2 |
{
|
241 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
242 |
|
|
dbg(0,"+#+:enter\n");
|
243 |
|
|
#endif
|
244 |
zoff99 |
27 |
////DBG dbg(0,"enter\n");
|
245 |
zoff99 |
2 |
int ret;
|
246 |
zoff99 |
27 |
if (this_->meth.position_attr_get)
|
247 |
|
|
{
|
248 |
|
|
ret = this_->meth.position_attr_get(this_->priv, type, attr);
|
249 |
zoff99 |
2 |
if (ret)
|
250 |
zoff99 |
28 |
{
|
251 |
zoff99 |
2 |
return ret;
|
252 |
zoff99 |
28 |
}
|
253 |
zoff99 |
2 |
}
|
254 |
zoff99 |
27 |
if (type == attr_log_gpx_desc)
|
255 |
|
|
{
|
256 |
zoff99 |
2 |
attr->u.str = this_->gpx_desc;
|
257 |
|
|
return 1;
|
258 |
|
|
}
|
259 |
zoff99 |
27 |
////DBG dbg(0,"before return\n");
|
260 |
zoff99 |
28 |
|
261 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
262 |
|
|
dbg(0,"+#+:leave\n");
|
263 |
|
|
#endif
|
264 |
|
|
|
265 |
zoff99 |
2 |
return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
/**
|
269 |
|
|
* Generic set function
|
270 |
|
|
*
|
271 |
|
|
* @param this_ Pointer to a vehicle structure
|
272 |
|
|
* @param attr Pointer to an attr structure for the attribute to be set
|
273 |
|
|
* @return nonzero on success, zero on failure
|
274 |
|
|
*/
|
275 |
zoff99 |
27 |
int vehicle_set_attr(struct vehicle *this_, struct attr *attr)
|
276 |
zoff99 |
2 |
{
|
277 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
278 |
|
|
dbg(0,"+#+:enter\n");
|
279 |
|
|
#endif
|
280 |
zoff99 |
27 |
int ret = 1;
|
281 |
zoff99 |
2 |
if (this_->meth.set_attr)
|
282 |
zoff99 |
28 |
{
|
283 |
|
|
//dbg(0,"xx 1\n");
|
284 |
zoff99 |
27 |
ret = this_->meth.set_attr(this_->priv, attr);
|
285 |
zoff99 |
28 |
//dbg(0,"xx 1.1\n");
|
286 |
|
|
}
|
287 |
|
|
|
288 |
zoff99 |
27 |
if (ret == 1 && attr->type == attr_log_gpx_desc)
|
289 |
|
|
{
|
290 |
zoff99 |
2 |
g_free(this_->gpx_desc);
|
291 |
|
|
this_->gpx_desc = attr->u.str;
|
292 |
|
|
}
|
293 |
zoff99 |
28 |
|
294 |
zoff99 |
2 |
if (ret == 1 && attr->type != attr_navit && attr->type != attr_pdl_gps_update)
|
295 |
zoff99 |
28 |
{
|
296 |
zoff99 |
30 |
//dbg(0,"xx 3\n");
|
297 |
zoff99 |
27 |
this_->attrs = attr_generic_set_attr(this_->attrs, attr);
|
298 |
zoff99 |
28 |
}
|
299 |
|
|
|
300 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
301 |
|
|
dbg(0,"+#+:leave\n");
|
302 |
|
|
#endif
|
303 |
|
|
|
304 |
zoff99 |
2 |
return ret != 0;
|
305 |
|
|
}
|
306 |
|
|
|
307 |
|
|
/**
|
308 |
|
|
* Generic add function
|
309 |
|
|
*
|
310 |
|
|
* @param this_ A vehicle
|
311 |
|
|
* @param attr A struct attr
|
312 |
|
|
*/
|
313 |
zoff99 |
27 |
int vehicle_add_attr(struct vehicle *this_, struct attr *attr)
|
314 |
zoff99 |
2 |
{
|
315 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
316 |
|
|
dbg(0,"+#+:enter\n");
|
317 |
|
|
#endif
|
318 |
zoff99 |
27 |
int ret = 1;
|
319 |
|
|
switch (attr->type)
|
320 |
|
|
{
|
321 |
|
|
case attr_callback:
|
322 |
|
|
callback_list_add(this_->cbl, attr->u.callback);
|
323 |
|
|
break;
|
324 |
|
|
case attr_log:
|
325 |
|
|
ret = vehicle_add_log(this_, attr->u.log);
|
326 |
|
|
break;
|
327 |
|
|
// currently supporting oldstyle cursor config.
|
328 |
|
|
case attr_cursor:
|
329 |
|
|
this_->cursor_fixed = 1;
|
330 |
|
|
vehicle_set_cursor(this_, attr->u.cursor, 1);
|
331 |
|
|
break;
|
332 |
|
|
default:
|
333 |
|
|
break;
|
334 |
zoff99 |
2 |
}
|
335 |
|
|
if (ret)
|
336 |
zoff99 |
28 |
{
|
337 |
zoff99 |
27 |
this_->attrs = attr_generic_add_attr(this_->attrs, attr);
|
338 |
zoff99 |
28 |
}
|
339 |
|
|
|
340 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
341 |
|
|
dbg(0,"+#+:leave\n");
|
342 |
|
|
#endif
|
343 |
|
|
|
344 |
zoff99 |
2 |
return ret;
|
345 |
|
|
}
|
346 |
|
|
|
347 |
|
|
/**
|
348 |
|
|
* @brief Generic remove function.
|
349 |
|
|
*
|
350 |
|
|
* Used to remove a callback from the vehicle.
|
351 |
|
|
* @param this_ A vehicle
|
352 |
|
|
* @param attr
|
353 |
|
|
*/
|
354 |
zoff99 |
27 |
int vehicle_remove_attr(struct vehicle *this_, struct attr *attr)
|
355 |
zoff99 |
2 |
{
|
356 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
357 |
|
|
dbg(0,"+#+:enter\n");
|
358 |
|
|
#endif
|
359 |
zoff99 |
2 |
struct callback *cb;
|
360 |
zoff99 |
27 |
switch (attr->type)
|
361 |
|
|
{
|
362 |
|
|
case attr_callback:
|
363 |
|
|
callback_list_remove(this_->cbl, attr->u.callback);
|
364 |
|
|
break;
|
365 |
|
|
case attr_log:
|
366 |
|
|
cb = g_hash_table_lookup(this_->log_to_cb, attr->u.log);
|
367 |
|
|
if (!cb)
|
368 |
|
|
return 0;
|
369 |
|
|
g_hash_table_remove(this_->log_to_cb, attr->u.log);
|
370 |
|
|
callback_list_remove(this_->cbl, cb);
|
371 |
|
|
break;
|
372 |
|
|
case attr_cursor:
|
373 |
|
|
vehicle_remove_cursor(this_);
|
374 |
|
|
break;
|
375 |
|
|
default:
|
376 |
|
|
this_->attrs = attr_generic_remove_attr(this_->attrs, attr);
|
377 |
zoff99 |
2 |
return 0;
|
378 |
|
|
}
|
379 |
|
|
return 1;
|
380 |
|
|
}
|
381 |
|
|
|
382 |
|
|
/**
|
383 |
|
|
* Sets the cursor of a vehicle.
|
384 |
|
|
*
|
385 |
|
|
* @param this_ A vehicle
|
386 |
|
|
* @param cursor A cursor
|
387 |
|
|
* @author Ralph Sennhauser (10/2009)
|
388 |
zoff99 |
27 |
*/
|
389 |
|
|
void vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor, int overwrite)
|
390 |
zoff99 |
2 |
{
|
391 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
392 |
|
|
dbg(0,"+#+:enter\n");
|
393 |
|
|
#endif
|
394 |
zoff99 |
2 |
struct point sc;
|
395 |
|
|
if (this_->cursor_fixed && !overwrite)
|
396 |
zoff99 |
27 |
{
|
397 |
zoff99 |
2 |
return;
|
398 |
zoff99 |
27 |
}
|
399 |
zoff99 |
30 |
|
400 |
|
|
#if 0
|
401 |
zoff99 |
27 |
if (this_->animate_callback)
|
402 |
|
|
{
|
403 |
zoff99 |
2 |
event_remove_timeout(this_->animate_timer);
|
404 |
zoff99 |
27 |
this_->animate_timer = NULL; // dangling pointer! prevent double freeing.
|
405 |
zoff99 |
2 |
callback_destroy(this_->animate_callback);
|
406 |
zoff99 |
27 |
this_->animate_callback = NULL; // dangling pointer! prevent double freeing.
|
407 |
zoff99 |
2 |
}
|
408 |
zoff99 |
30 |
|
409 |
zoff99 |
27 |
if (cursor && cursor->interval)
|
410 |
|
|
{
|
411 |
|
|
this_->animate_callback = callback_new_2(callback_cast(vehicle_draw_do), this_, 0);
|
412 |
zoff99 |
30 |
//dbg(0, "event_add_timeout %d,%d,%p", cursor->interval, 1, this_->animate_callback);
|
413 |
zoff99 |
27 |
this_->animate_timer = event_add_timeout(cursor->interval, 1, this_->animate_callback);
|
414 |
zoff99 |
2 |
}
|
415 |
|
|
|
416 |
zoff99 |
27 |
if (cursor && this_->gra && this_->cursor)
|
417 |
|
|
{
|
418 |
|
|
this_->cursor_pnt.x += (this_->cursor->w - cursor->w) / 2;
|
419 |
|
|
this_->cursor_pnt.y += (this_->cursor->h - cursor->h) / 2;
|
420 |
zoff99 |
2 |
graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 65535, 0);
|
421 |
|
|
}
|
422 |
zoff99 |
30 |
#endif
|
423 |
zoff99 |
2 |
|
424 |
zoff99 |
30 |
// ###############################################
|
425 |
|
|
// ###############################################
|
426 |
|
|
// set fixed size of navigation cursor to 50,50 !!
|
427 |
zoff99 |
27 |
if (cursor)
|
428 |
|
|
{
|
429 |
zoff99 |
30 |
cursor->w = 50;
|
430 |
|
|
cursor->h = 50;
|
431 |
|
|
}
|
432 |
|
|
|
433 |
|
|
if (this_->cursor)
|
434 |
|
|
{
|
435 |
|
|
this_->cursor->w = 50;
|
436 |
|
|
this_->cursor->h = 50;
|
437 |
|
|
}
|
438 |
|
|
// set fixed size of navigation cursor to 50,50 !!
|
439 |
|
|
// ###############################################
|
440 |
|
|
// ###############################################
|
441 |
|
|
|
442 |
|
|
|
443 |
|
|
if (cursor)
|
444 |
|
|
{
|
445 |
zoff99 |
27 |
sc.x = cursor->w / 2;
|
446 |
|
|
sc.y = cursor->h / 2;
|
447 |
zoff99 |
30 |
//if (!this_->cursor && this_->gra)
|
448 |
|
|
//{
|
449 |
|
|
// graphics_overlay_disable(this_->gra, 0);
|
450 |
|
|
//}
|
451 |
zoff99 |
27 |
}
|
452 |
|
|
else
|
453 |
|
|
{
|
454 |
|
|
sc.x = sc.y = 0;
|
455 |
zoff99 |
30 |
//if (this_->cursor && this_->gra)
|
456 |
|
|
//{
|
457 |
|
|
// graphics_overlay_disable(this_->gra, 1);
|
458 |
|
|
//}
|
459 |
zoff99 |
2 |
}
|
460 |
zoff99 |
30 |
|
461 |
zoff99 |
2 |
transform_set_screen_center(this_->trans, &sc);
|
462 |
|
|
|
463 |
zoff99 |
27 |
this_->cursor = cursor;
|
464 |
zoff99 |
28 |
|
465 |
|
|
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
466 |
|
|
dbg(0,"+#+:leave\n");
|
467 |
|
|
#endif
|
468 |
|
|
|
469 |
zoff99 |
2 |
}
|
470 |
|
|
|
471 |
zoff99 |
27 |
void vehicle_remove_cursor(struct vehicle *this_)
|
472 |
|
|
{
|
473 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
474 |
|
|
dbg(0,"+#+:enter\n");
|
475 |
|
|
#endif
|
476 |
zoff99 |
27 |
struct point sc;
|
477 |
|
|
|
478 |
|
|
if (this_->animate_callback)
|
479 |
|
|
{
|
480 |
|
|
event_remove_timeout(this_->animate_timer);
|
481 |
|
|
this_->animate_timer = NULL; // dangling pointer! prevent double freeing.
|
482 |
|
|
callback_destroy(this_->animate_callback);
|
483 |
|
|
this_->animate_callback = NULL; // dangling pointer! prevent double freeing.
|
484 |
|
|
}
|
485 |
|
|
|
486 |
|
|
if (this_->cursor && this_->gra)
|
487 |
|
|
{
|
488 |
|
|
}
|
489 |
|
|
|
490 |
|
|
if (this_->cursor && this_->gra)
|
491 |
|
|
{
|
492 |
|
|
graphics_overlay_disable(this_->gra, 1);
|
493 |
|
|
}
|
494 |
|
|
|
495 |
|
|
this_->cursor = NULL;
|
496 |
|
|
}
|
497 |
|
|
|
498 |
zoff99 |
2 |
/**
|
499 |
|
|
* Draws a vehicle on top of a graphics.
|
500 |
|
|
*
|
501 |
|
|
* @param this_ The vehicle
|
502 |
|
|
* @param gra The graphics
|
503 |
|
|
* @param pnt Screen coordinates of the vehicle.
|
504 |
|
|
* @param lazy use lazy draw mode.
|
505 |
|
|
* @param angle The angle relative to the map.
|
506 |
|
|
* @param speed The speed of the vehicle.
|
507 |
|
|
*/
|
508 |
zoff99 |
27 |
void vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int lazy, int angle, int speed)
|
509 |
zoff99 |
2 |
{
|
510 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
511 |
|
|
dbg(0,"+#+:enter\n");
|
512 |
|
|
#endif
|
513 |
|
|
|
514 |
zoff99 |
30 |
//if (hold_drawing > 0)
|
515 |
|
|
//{
|
516 |
|
|
// return;
|
517 |
|
|
//}
|
518 |
|
|
|
519 |
|
|
if (angle < 0)
|
520 |
zoff99 |
28 |
{
|
521 |
zoff99 |
30 |
angle += 360;
|
522 |
zoff99 |
28 |
}
|
523 |
|
|
|
524 |
zoff99 |
27 |
//// dbg(1, "enter this=%p gra=%p pnt=%p lazy=%d dir=%d speed=%d\n", this_, gra,
|
525 |
|
|
// pnt, lazy, angle, speed);
|
526 |
zoff99 |
30 |
//dbg(0, "point %d,%d\n", pnt->x, pnt->y);
|
527 |
zoff99 |
27 |
this_->cursor_pnt = *pnt;
|
528 |
|
|
this_->angle = angle;
|
529 |
|
|
this_->speed = speed;
|
530 |
zoff99 |
2 |
if (!this_->cursor)
|
531 |
zoff99 |
30 |
{
|
532 |
zoff99 |
2 |
return;
|
533 |
zoff99 |
30 |
}
|
534 |
|
|
|
535 |
|
|
//dbg(0,"cpx:%d, cpy:%d, cw:%d, ch:%d\n", this_->cursor_pnt.x, this_->cursor_pnt.y, this_->cursor->w, this_->cursor->h);
|
536 |
|
|
|
537 |
|
|
//*** this_->cursor_pnt.x -= this_->cursor->w / 2;
|
538 |
|
|
//*** this_->cursor_pnt.y -= this_->cursor->h / 2;
|
539 |
|
|
|
540 |
|
|
#if 0
|
541 |
zoff99 |
27 |
if (!this_->gra)
|
542 |
|
|
{
|
543 |
zoff99 |
2 |
struct color c;
|
544 |
zoff99 |
30 |
dbg(0,"Create new Vehicle Overlay Graphics\n");
|
545 |
|
|
this_->gra = graphics_overlay_new("type:vehicle",gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 65535, 0);
|
546 |
zoff99 |
27 |
if (this_->gra)
|
547 |
|
|
{
|
548 |
|
|
this_->bg = graphics_gc_new(this_->gra);
|
549 |
|
|
c.r = 0;
|
550 |
|
|
c.g = 0;
|
551 |
|
|
c.b = 0;
|
552 |
|
|
c.a = 0;
|
553 |
zoff99 |
2 |
graphics_gc_set_foreground(this_->bg, &c);
|
554 |
|
|
graphics_background_gc(this_->gra, this_->bg);
|
555 |
|
|
}
|
556 |
|
|
}
|
557 |
zoff99 |
30 |
#endif
|
558 |
zoff99 |
28 |
|
559 |
zoff99 |
30 |
|
560 |
|
|
// ++++++++++ // transform_set_yaw(this_->trans, -this_->angle);
|
561 |
|
|
// vehicle_draw_do(this_, lazy);
|
562 |
|
|
|
563 |
|
|
#ifdef HAVE_API_ANDROID
|
564 |
|
|
//dbg(0,"x=%d y=%d angle=%d speed=%d\n",this_->cursor_pnt.x, this_->cursor_pnt.y, angle, speed);
|
565 |
|
|
|
566 |
|
|
//int dx = 0;
|
567 |
|
|
//int dy = 0;
|
568 |
|
|
//int dangle = 0;
|
569 |
|
|
|
570 |
|
|
//struct navit_vehicle *nv2 = global_navit->vehicle;
|
571 |
|
|
//struct point pnt2;
|
572 |
|
|
//dbg(0,"dir=%d dx=%d, dy=%d\n", nv2->dir, dx, dy);
|
573 |
|
|
//transform(this_->trans, projection_mg, &nv2->coord, &pnt2, 1, 0, 0, NULL);
|
574 |
|
|
//dbg(0,"px=%d, py=%d\n", pnt2.x, pnt2.y);
|
575 |
|
|
|
576 |
|
|
set_vehicle_values_to_java(this_->cursor_pnt.x, this_->cursor_pnt.y, angle, speed);
|
577 |
|
|
#endif
|
578 |
|
|
|
579 |
zoff99 |
2 |
}
|
580 |
|
|
|
581 |
zoff99 |
27 |
int vehicle_get_cursor_data(struct vehicle *this, struct point *pnt, int *angle, int *speed)
|
582 |
zoff99 |
2 |
{
|
583 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
584 |
|
|
dbg(0,"+#+:enter\n");
|
585 |
|
|
#endif
|
586 |
zoff99 |
27 |
*pnt = this->cursor_pnt;
|
587 |
|
|
*angle = this->angle;
|
588 |
|
|
*speed = this->speed;
|
589 |
zoff99 |
2 |
return 1;
|
590 |
|
|
}
|
591 |
|
|
|
592 |
zoff99 |
27 |
static void vehicle_draw_do(struct vehicle *this_, int lazy)
|
593 |
zoff99 |
2 |
{
|
594 |
zoff99 |
30 |
// UNUSED ---------
|
595 |
zoff99 |
2 |
}
|
596 |
|
|
|
597 |
|
|
/**
|
598 |
|
|
* Writes to an NMEA log.
|
599 |
|
|
*
|
600 |
|
|
* @param this_ Pointer to the vehicle structure of the data source
|
601 |
|
|
* @param log Pointer to a log structure for the log file
|
602 |
|
|
*/
|
603 |
zoff99 |
27 |
static void vehicle_log_nmea(struct vehicle *this_, struct log *log)
|
604 |
zoff99 |
2 |
{
|
605 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
606 |
|
|
dbg(0,"+#+:enter\n");
|
607 |
|
|
#endif
|
608 |
zoff99 |
2 |
struct attr pos_attr;
|
609 |
|
|
if (!this_->meth.position_attr_get)
|
610 |
|
|
return;
|
611 |
|
|
if (!this_->meth.position_attr_get(this_->priv, attr_position_nmea, &pos_attr))
|
612 |
|
|
return;
|
613 |
|
|
log_write(log, pos_attr.u.str, strlen(pos_attr.u.str), 0);
|
614 |
|
|
}
|
615 |
|
|
|
616 |
zoff99 |
27 |
void vehicle_log_gpx_add_tag(char *tag, char **logstr)
|
617 |
zoff99 |
2 |
{
|
618 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
619 |
|
|
dbg(0,"+#+:enter\n");
|
620 |
|
|
#endif
|
621 |
zoff99 |
27 |
char *ext_start = "\t<extensions>\n";
|
622 |
|
|
char *ext_end = "\t</extensions>\n";
|
623 |
|
|
char *trkpt_end = "</trkpt>";
|
624 |
|
|
char *start = NULL, *end = NULL;
|
625 |
|
|
if (!*logstr)
|
626 |
|
|
{
|
627 |
|
|
start = g_strdup(ext_start);
|
628 |
|
|
end = g_strdup(ext_end);
|
629 |
|
|
}
|
630 |
|
|
else
|
631 |
|
|
{
|
632 |
|
|
char *str = strstr(*logstr, ext_start);
|
633 |
zoff99 |
2 |
int len;
|
634 |
zoff99 |
27 |
if (str)
|
635 |
|
|
{
|
636 |
|
|
len = str - *logstr + strlen(ext_start);
|
637 |
|
|
start = g_strdup(*logstr);
|
638 |
|
|
start[len] = '\0';
|
639 |
|
|
end = g_strdup(str + strlen(ext_start));
|
640 |
|
|
}
|
641 |
|
|
else
|
642 |
|
|
{
|
643 |
|
|
str = strstr(*logstr, trkpt_end);
|
644 |
|
|
len = str - *logstr;
|
645 |
|
|
end = g_strdup_printf("%s%s", ext_end, str);
|
646 |
|
|
str = g_strdup(*logstr);
|
647 |
|
|
str[len] = '\0';
|
648 |
|
|
start = g_strdup_printf("%s%s", str, ext_start);
|
649 |
zoff99 |
2 |
g_free(str);
|
650 |
|
|
}
|
651 |
|
|
}
|
652 |
zoff99 |
27 |
*logstr = g_strdup_printf("%s%s%s", start, tag, end);
|
653 |
zoff99 |
2 |
g_free(start);
|
654 |
|
|
g_free(end);
|
655 |
|
|
}
|
656 |
|
|
|
657 |
|
|
/**
|
658 |
|
|
* Writes to a GPX log.
|
659 |
|
|
*
|
660 |
|
|
* @param this_ Pointer to the vehicle structure of the data source
|
661 |
|
|
* @param log Pointer to a log structure for the log file
|
662 |
|
|
*/
|
663 |
zoff99 |
27 |
static void vehicle_log_gpx(struct vehicle *this_, struct log *log)
|
664 |
zoff99 |
2 |
{
|
665 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
666 |
|
|
dbg(0,"+#+:enter\n");
|
667 |
|
|
#endif
|
668 |
zoff99 |
27 |
struct attr attr, *attrp, fix_attr;
|
669 |
zoff99 |
2 |
enum attr_type *attr_types;
|
670 |
|
|
char *logstr;
|
671 |
zoff99 |
27 |
char *extensions = "\t<extensions>\n";
|
672 |
zoff99 |
2 |
|
673 |
|
|
if (!this_->meth.position_attr_get)
|
674 |
|
|
return;
|
675 |
|
|
if (log_get_attr(log, attr_attr_types, &attr, NULL))
|
676 |
zoff99 |
27 |
attr_types = attr.u.attr_types;
|
677 |
zoff99 |
2 |
else
|
678 |
zoff99 |
27 |
attr_types = NULL;
|
679 |
|
|
if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr))
|
680 |
|
|
{
|
681 |
|
|
if (fix_attr.u.num == 0)
|
682 |
|
|
return;
|
683 |
zoff99 |
2 |
}
|
684 |
|
|
if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &attr))
|
685 |
|
|
return;
|
686 |
zoff99 |
27 |
logstr = g_strdup_printf("<trkpt lat=\"%f\" lon=\"%f\">\n", attr.u.coord_geo->lat, attr.u.coord_geo->lng);
|
687 |
|
|
if (attr_types && attr_types_contains_default(attr_types, attr_position_time_iso8601, 0))
|
688 |
|
|
{
|
689 |
|
|
if (this_->meth.position_attr_get(this_->priv, attr_position_time_iso8601, &attr))
|
690 |
|
|
{
|
691 |
|
|
logstr = g_strconcat_printf(logstr, "\t<time>%s</time>\n", attr.u.str);
|
692 |
|
|
}
|
693 |
|
|
else
|
694 |
|
|
{
|
695 |
zoff99 |
2 |
char *timep = current_to_iso8601();
|
696 |
zoff99 |
27 |
logstr = g_strconcat_printf(logstr, "\t<time>%s</time>\n", timep);
|
697 |
zoff99 |
2 |
g_free(timep);
|
698 |
|
|
}
|
699 |
|
|
}
|
700 |
zoff99 |
27 |
if (this_->gpx_desc)
|
701 |
|
|
{
|
702 |
|
|
logstr = g_strconcat_printf(logstr, "\t<desc>%s</desc>\n", this_->gpx_desc);
|
703 |
zoff99 |
2 |
g_free(this_->gpx_desc);
|
704 |
|
|
this_->gpx_desc = NULL;
|
705 |
|
|
}
|
706 |
zoff99 |
27 |
if (attr_types_contains_default(attr_types, attr_position_height, 0) && this_->meth.position_attr_get(this_->priv, attr_position_height, &attr))
|
707 |
|
|
logstr = g_strconcat_printf(logstr, "\t<ele>%.6f</ele>\n", *attr.u.numd);
|
708 |
zoff99 |
2 |
// <magvar> magnetic variation in degrees; we might use position_magnetic_direction and position_direction to figure it out
|
709 |
|
|
// <geoidheight> Height (in meters) of geoid (mean sea level) above WGS84 earth ellipsoid. As defined in NMEA GGA message (field 11, which vehicle_wince.c ignores)
|
710 |
|
|
// <name> GPS name (arbitrary)
|
711 |
|
|
// <cmt> comment
|
712 |
|
|
// <src> Source of data
|
713 |
|
|
// <link> Link to additional information (URL)
|
714 |
|
|
// <sym> Text of GPS symbol name
|
715 |
|
|
// <type> Type (classification)
|
716 |
|
|
// <fix> Type of GPS fix {'none'|'2d'|'3d'|'dgps'|'pps'}, leave out if unknown. Similar to position_fix_type but more detailed.
|
717 |
zoff99 |
27 |
if (attr_types_contains_default(attr_types, attr_position_sats_used, 0) && this_->meth.position_attr_get(this_->priv, attr_position_sats_used, &attr))
|
718 |
|
|
logstr = g_strconcat_printf(logstr, "\t<sat>%d</sat>\n", attr.u.num);
|
719 |
|
|
if (attr_types_contains_default(attr_types, attr_position_hdop, 0) && this_->meth.position_attr_get(this_->priv, attr_position_hdop, &attr))
|
720 |
|
|
logstr = g_strconcat_printf(logstr, "\t<hdop>%.6f</hdop>\n", *attr.u.numd);
|
721 |
zoff99 |
2 |
// <vdop>, <pdop> Vertical and position dilution of precision, no corresponding attribute
|
722 |
zoff99 |
27 |
if (attr_types_contains_default(attr_types, attr_position_direction, 0) && this_->meth.position_attr_get(this_->priv, attr_position_direction, &attr))
|
723 |
|
|
logstr = g_strconcat_printf(logstr, "\t<course>%.1f</course>\n", *attr.u.numd);
|
724 |
zoff99 |
2 |
if (attr_types_contains_default(attr_types, attr_position_speed, 0) && this_->meth.position_attr_get(this_->priv, attr_position_speed, &attr))
|
725 |
zoff99 |
27 |
logstr = g_strconcat_printf(logstr, "\t<speed>%.2f</speed>\n", (*attr.u.numd / 3.6));
|
726 |
|
|
if (attr_types_contains_default(attr_types, attr_profilename, 0) && (attrp = attr_search(this_->attrs, NULL, attr_profilename)))
|
727 |
|
|
{
|
728 |
|
|
logstr = g_strconcat_printf(logstr, "%s\t\t<navit:profilename>%s</navit:profilename>\n", extensions, attrp->u.str);
|
729 |
|
|
extensions = "";
|
730 |
zoff99 |
2 |
}
|
731 |
zoff99 |
27 |
if (attr_types_contains_default(attr_types, attr_position_radius, 0) && this_->meth.position_attr_get(this_->priv, attr_position_radius, &attr))
|
732 |
|
|
{
|
733 |
|
|
logstr = g_strconcat_printf(logstr, "%s\t\t<navit:radius>%.2f</navit:radius>\n", extensions, *attr.u.numd);
|
734 |
|
|
extensions = "";
|
735 |
zoff99 |
2 |
}
|
736 |
zoff99 |
27 |
if (!strcmp(extensions, ""))
|
737 |
|
|
{
|
738 |
|
|
logstr = g_strconcat_printf(logstr, "\t</extensions>\n");
|
739 |
zoff99 |
2 |
}
|
740 |
zoff99 |
27 |
logstr = g_strconcat_printf(logstr, "</trkpt>\n");
|
741 |
zoff99 |
2 |
callback_list_call_attr_1(this_->cbl, attr_log_gpx, &logstr);
|
742 |
|
|
log_write(log, logstr, strlen(logstr), 0);
|
743 |
|
|
g_free(logstr);
|
744 |
|
|
}
|
745 |
|
|
|
746 |
|
|
/**
|
747 |
|
|
* Writes to a text log.
|
748 |
|
|
*
|
749 |
|
|
* @param this_ Pointer to the vehicle structure of the data source
|
750 |
|
|
* @param log Pointer to a log structure for the log file
|
751 |
|
|
*/
|
752 |
zoff99 |
27 |
static void vehicle_log_textfile(struct vehicle *this_, struct log *log)
|
753 |
zoff99 |
2 |
{
|
754 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
755 |
|
|
dbg(0,"+#+:enter\n");
|
756 |
|
|
#endif
|
757 |
zoff99 |
27 |
struct attr pos_attr, fix_attr;
|
758 |
zoff99 |
2 |
char *logstr;
|
759 |
|
|
if (!this_->meth.position_attr_get)
|
760 |
|
|
return;
|
761 |
zoff99 |
27 |
if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr))
|
762 |
|
|
{
|
763 |
|
|
if (fix_attr.u.num == 0)
|
764 |
|
|
return;
|
765 |
zoff99 |
2 |
}
|
766 |
|
|
if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
|
767 |
|
|
return;
|
768 |
zoff99 |
27 |
logstr = g_strdup_printf("%f %f type=trackpoint\n", pos_attr.u.coord_geo->lng, pos_attr.u.coord_geo->lat);
|
769 |
zoff99 |
2 |
callback_list_call_attr_1(this_->cbl, attr_log_textfile, &logstr);
|
770 |
|
|
log_write(log, logstr, strlen(logstr), 0);
|
771 |
|
|
}
|
772 |
|
|
|
773 |
|
|
/**
|
774 |
|
|
* Writes to a binary log.
|
775 |
|
|
*
|
776 |
|
|
* @param this_ Pointer to the vehicle structure of the data source
|
777 |
|
|
* @param log Pointer to a log structure for the log file
|
778 |
|
|
*/
|
779 |
zoff99 |
27 |
static void vehicle_log_binfile(struct vehicle *this_, struct log *log)
|
780 |
zoff99 |
2 |
{
|
781 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
782 |
|
|
dbg(0,"+#+:enter\n");
|
783 |
|
|
#endif
|
784 |
zoff99 |
2 |
struct attr pos_attr, fix_attr;
|
785 |
|
|
int *buffer;
|
786 |
|
|
int *buffer_new;
|
787 |
zoff99 |
27 |
int len, limit = 1024, done = 0, radius = 25;
|
788 |
zoff99 |
2 |
struct coord c;
|
789 |
|
|
enum log_flags flags;
|
790 |
|
|
|
791 |
|
|
if (!this_->meth.position_attr_get)
|
792 |
|
|
return;
|
793 |
zoff99 |
27 |
if (this_->meth.position_attr_get(this_->priv, attr_position_fix_type, &fix_attr))
|
794 |
|
|
{
|
795 |
|
|
if (fix_attr.u.num == 0)
|
796 |
|
|
return;
|
797 |
zoff99 |
2 |
}
|
798 |
|
|
if (!this_->meth.position_attr_get(this_->priv, attr_position_coord_geo, &pos_attr))
|
799 |
|
|
return;
|
800 |
|
|
transform_from_geo(projection_mg, pos_attr.u.coord_geo, &c);
|
801 |
|
|
if (!c.x || !c.y)
|
802 |
|
|
return;
|
803 |
zoff99 |
27 |
while (!done)
|
804 |
|
|
{
|
805 |
|
|
buffer = log_get_buffer(log, &len);
|
806 |
|
|
if (!buffer || !len)
|
807 |
|
|
{
|
808 |
|
|
buffer_new = g_malloc(5 * sizeof(int));
|
809 |
|
|
buffer_new[0] = 2;
|
810 |
|
|
buffer_new[1] = type_track;
|
811 |
|
|
buffer_new[2] = 0;
|
812 |
zoff99 |
2 |
}
|
813 |
zoff99 |
27 |
else
|
814 |
|
|
{
|
815 |
|
|
buffer_new = g_malloc((buffer[0] + 3) * sizeof(int));
|
816 |
|
|
memcpy(buffer_new, buffer, (buffer[0] + 1) * sizeof(int));
|
817 |
zoff99 |
2 |
}
|
818 |
zoff99 |
27 |
//// dbg(1, "c=0x%x,0x%x\n", c.x, c.y);
|
819 |
|
|
buffer_new[buffer_new[0] + 1] = c.x;
|
820 |
|
|
buffer_new[buffer_new[0] + 2] = c.y;
|
821 |
|
|
buffer_new[0] += 2;
|
822 |
|
|
buffer_new[2] += 2;
|
823 |
|
|
if (buffer_new[2] > limit)
|
824 |
|
|
{
|
825 |
|
|
int count = buffer_new[2] / 2;
|
826 |
|
|
struct coord *out = g_alloca(sizeof(struct coord) * (count));
|
827 |
|
|
struct coord *in = (struct coord *) (buffer_new + 3);
|
828 |
|
|
int count_out = transform_douglas_peucker(in, count, radius, out);
|
829 |
|
|
memcpy(in, out, count_out * 2 * sizeof(int));
|
830 |
|
|
buffer_new[0] += (count_out - count) * 2;
|
831 |
|
|
buffer_new[2] += (count_out - count) * 2;
|
832 |
|
|
flags = log_flag_replace_buffer | log_flag_force_flush | log_flag_truncate;
|
833 |
|
|
}
|
834 |
|
|
else
|
835 |
|
|
{
|
836 |
|
|
flags = log_flag_replace_buffer | log_flag_keep_pointer | log_flag_keep_buffer | log_flag_force_flush;
|
837 |
|
|
done = 1;
|
838 |
|
|
}
|
839 |
|
|
log_write(log, (char *) buffer_new, (buffer_new[0] + 1) * sizeof(int), flags);
|
840 |
zoff99 |
2 |
}
|
841 |
|
|
}
|
842 |
|
|
|
843 |
|
|
/**
|
844 |
|
|
* Register a new log to receive data.
|
845 |
|
|
*
|
846 |
|
|
* @param this_ Pointer to the vehicle structure of the data source
|
847 |
|
|
* @param log Pointer to a log structure for the log file
|
848 |
|
|
*/
|
849 |
zoff99 |
27 |
static int vehicle_add_log(struct vehicle *this_, struct log *log)
|
850 |
zoff99 |
2 |
{
|
851 |
zoff99 |
28 |
#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
|
852 |
|
|
dbg(0,"+#+:enter\n");
|
853 |
|
|
#endif
|
854 |
zoff99 |
2 |
struct callback *cb;
|
855 |
|
|
struct attr type_attr;
|
856 |
|
|
if (!log_get_attr(log, attr_type, &type_attr, NULL))
|
857 |
zoff99 |
27 |
return 1;
|
858 |
zoff99 |
2 |
|
859 |
zoff99 |
27 |
if (!strcmp(type_attr.u.str, "nmea"))
|
860 |
|
|
{
|
861 |
|
|
cb = callback_new_attr_2(callback_cast(vehicle_log_nmea), attr_position_coord_geo, this_, log);
|
862 |
|
|
}
|
863 |
|
|
else if (!strcmp(type_attr.u.str, "gpx"))
|
864 |
|
|
{
|
865 |
zoff99 |
2 |
char *header = "<?xml version='1.0' encoding='UTF-8'?>\n"
|
866 |
|
|
"<gpx version='1.1' creator='Navit http://navit.sourceforge.net'\n"
|
867 |
|
|
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"
|
868 |
|
|
" xmlns:navit='http://www.navit-project.org/schema/navit'\n"
|
869 |
|
|
" xmlns='http://www.topografix.com/GPX/1/1'\n"
|
870 |
|
|
" xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
|
871 |
|
|
"<trk>\n"
|
872 |
|
|
"<trkseg>\n";
|
873 |
|
|
char *trailer = "</trkseg>\n</trk>\n</gpx>\n";
|
874 |
|
|
log_set_header(log, header, strlen(header));
|
875 |
|
|
log_set_trailer(log, trailer, strlen(trailer));
|
876 |
zoff99 |
27 |
cb = callback_new_attr_2(callback_cast(vehicle_log_gpx), attr_position_coord_geo, this_, log);
|
877 |
|
|
}
|
878 |
|
|
else if (!strcmp(type_attr.u.str, "textfile"))
|
879 |
|
|
{
|
880 |
zoff99 |
2 |
char *header = "type=track\n";
|
881 |
|
|
log_set_header(log, header, strlen(header));
|
882 |
zoff99 |
27 |
cb = callback_new_attr_2(callback_cast(vehicle_log_textfile), attr_position_coord_geo, this_, log);
|
883 |
|
|
}
|
884 |
|
|
else if (!strcmp(type_attr.u.str, "binfile"))
|
885 |
|
|
{
|
886 |
|
|
cb = callback_new_attr_2(callback_cast(vehicle_log_binfile), attr_position_coord_geo, this_, log);
|
887 |
|
|
}
|
888 |
|
|
else
|
889 |
zoff99 |
2 |
return 1;
|
890 |
|
|
g_hash_table_insert(this_->log_to_cb, log, cb);
|
891 |
|
|
callback_list_add(this_->cbl, cb);
|
892 |
|
|
return 0;
|
893 |
|
|
}
|
894 |
|
|
|
895 |
zoff99 |
28 |
void vehicle_update_(struct vehicle *this_, jobject location)
|
896 |
|
|
{
|
897 |
|
|
#ifdef HAVE_API_ANDROID
|
898 |
|
|
if (this_->meth.update_location_direct)
|
899 |
|
|
{
|
900 |
|
|
// dbg(0,"location=%p\n", location);
|
901 |
|
|
this_->meth.update_location_direct(location);
|
902 |
|
|
}
|
903 |
|
|
#endif
|
904 |
|
|
}
|
905 |
|
|
|