8 #include "mapper-types.h"
14 void path_resize(Path * path, guint size)
16 printf("%s()\n", __PRETTY_FUNCTION__);
18 if (path->head + size != path->cap) {
19 Point *old_head = path->head;
21 path->head = g_renew(Point, old_head, size);
22 path->cap = path->head + size;
23 if (path->head != old_head) {
24 path->tail = path->head + (path->tail - old_head);
26 /* Adjust all of the waypoints. */
27 for (curr = path->whead - 1; curr++ != path->wtail;)
29 path->head + (curr->point - old_head);
33 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
36 void path_wresize(Path * path, guint wsize)
38 printf("%s()\n", __PRETTY_FUNCTION__);
40 if (path->whead + wsize != path->wcap) {
41 WayPoint *old_whead = path->whead;
42 path->whead = g_renew(WayPoint, old_whead, wsize);
43 path->wtail = path->whead + (path->wtail - old_whead);
44 path->wcap = path->whead + wsize;
47 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
54 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window),
55 _("Really clear the track?"));
57 if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
58 _track.tail = _track.head;
62 gtk_widget_destroy(confirm);
65 gfloat track_calculate_distance_from(Point * point)
67 gfloat lat1, lon1, lat2, lon2;
70 unit2latlon(_pos.unitx, _pos.unity, lat1, lon1);
72 /* Skip _track.tail because that should be _pos. */
73 for (curr = _track.tail; curr > point; --curr) {
75 unit2latlon(curr->unitx, curr->unity, lat2, lon2);
76 g_printf("B:[%f %f %f %f (%f)]\n", lat1, lon1, lat2,
78 sum += calculate_distance(lat1, lon1, lat2, lon2);
86 void track_show_distance_from(Point * point)
91 sum = track_calculate_distance_from(point);
93 snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"),
94 sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
95 MACRO_BANNER_SHOW_INFO(_window, buffer);
98 void track_show_distance_from_last()
100 printf("%s()\n", __PRETTY_FUNCTION__);
102 /* Find last zero point. */
103 if (_track.head != _track.tail) {
105 /* Find last zero point. */
106 for (point = _track.tail; point->unity; point--) {
108 track_show_distance_from(point);
110 MACRO_BANNER_SHOW_INFO(_window,
111 _("The current track is empty."));
113 printf("%s(): return\n", __PRETTY_FUNCTION__);
116 void track_show_distance_from_first()
118 printf("%s()\n", __PRETTY_FUNCTION__);
120 /* Find last zero point. */
121 if (_track.head != _track.tail) {
122 track_show_distance_from(_track.head);
124 MACRO_BANNER_SHOW_INFO(_window,
125 _("The current track is empty."));
127 printf("%s(): return\n", __PRETTY_FUNCTION__);
131 * Add a point to the _track list. This function is slightly overloaded,
132 * since it is what houses the check for "have we moved
133 * significantly": it also initiates the re-calculation of the _near_point
134 * data, as well as calling osso_display_state_on() when we have the focus.
136 * If a non-zero time is given, then the current position (as taken from the
137 * _pos variable) is appended to _track with the given time. If time is zero,
138 * then _point_null is appended to _track with time zero (this produces a "break"
141 void track_add(time_t time, gboolean newly_fixed)
143 gboolean show_directions = TRUE;
144 gint announce_thres_unsquared;
145 printf("%s(%u, %u)\n", __PRETTY_FUNCTION__, _pos.unitx, _pos.unity);
147 if (abs((gint) _pos.unitx - _track.tail->unitx) > _draw_width
148 || abs((gint) _pos.unity - _track.tail->unity) > _draw_width) {
150 /* If time != 0, update the nearest-waypoint data. */
151 if (time && _route.head != _route.tail &&
152 (newly_fixed ? (route_find_nearest_point(), TRUE) : route_update_nears(TRUE))) {
153 /* Nearest waypoint has changed - re-render paths. */
155 MACRO_QUEUE_DRAW_AREA();
158 if (_show_tracks & TRACKS_MASK) {
159 gint tx1, ty1, tx2, ty2;
161 /* Instead of calling map_render_paths(), we'll draw the new line
162 * ourselves and call gtk_widget_queue_draw_area(). */
163 map_render_segment(_gc[COLORABLE_TRACK],
164 _gc[COLORABLE_TRACK_BREAK],
166 _track.tail->unity, _pos.unitx,
169 if (time && _track.tail->unity) {
170 tx1 = unit2x(_track.tail->unitx);
171 ty1 = unit2y(_track.tail->unity);
172 tx2 = unit2x(_pos.unitx);
173 ty2 = unit2y(_pos.unity);
174 gtk_widget_queue_draw_area(_map_widget,
175 MIN(tx1, tx2) - _draw_width,
176 MIN(ty1, ty2) - _draw_width,
177 abs(tx1 - tx2) + (2 * _draw_width),
178 abs(ty1 - ty2) + (2 * _draw_width));
182 MACRO_PATH_INCREMENT_TAIL(_track);
187 *_track.tail = _point_null;
189 if (_autoroute_data.enabled && !_autoroute_data.in_progress && _near_point_dist_squared > 400) {
190 MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions..."));
191 _autoroute_data.in_progress = TRUE;
192 show_directions = FALSE;
193 g_idle_add((GSourceFunc) auto_route_dl_idle, NULL);
196 /* Keep the display on. */
200 announce_thres_unsquared = (20 + (guint) _gps.speed) * _announce_notice_ratio * 3;
202 /* Check if we should announce upcoming waypoints. */
203 if (show_directions && time && _next_way_dist_squared
204 < (announce_thres_unsquared * announce_thres_unsquared)) {
205 if (_enable_voice && strcmp(_next_way->desc, _last_spoken_phrase)) {
206 g_free(_last_spoken_phrase);
207 _last_spoken_phrase = g_strdup(_next_way->desc);
208 speak_text(_last_spoken_phrase);
210 MACRO_BANNER_SHOW_INFO(_window, _next_way->desc);
213 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
216 void track_insert_break(void)
218 printf("%s()\n", __PRETTY_FUNCTION__);
220 if (_track.tail->unity) {
223 /* To mark a "waypoint" in a track, we'll add a (0, 0) point and then
224 * another instance of the most recent track point. */
225 MACRO_PATH_INCREMENT_TAIL(_track);
226 *_track.tail = _point_null;
227 MACRO_PATH_INCREMENT_TAIL(_track);
228 *_track.tail = _track.tail[-2];
230 /** Instead of calling map_render_paths(), we'll just add the waypoint
232 x1 = unit2bufx(_track.tail->unitx);
233 y1 = unit2bufy(_track.tail->unity);
234 /* Make sure this circle will be visible. */
235 if ((x1 < BUF_WIDTH_PIXELS) && ((unsigned)y1 < BUF_HEIGHT_PIXELS))
236 gdk_draw_arc(_map_pixmap, _gc[COLORABLE_TRACK_BREAK], FALSE, /* FALSE: not filled. */
237 x1 - _draw_width, y1 - _draw_width, 2 * _draw_width, 2 * _draw_width, 0, /* start at 0 degrees. */
240 MACRO_BANNER_SHOW_INFO(_window, _("Break already inserted."));
243 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
246 gboolean track_open(void)
252 if (open_file(&buffer, NULL, &size, NULL, &_track_file_uri, GTK_FILE_CHOOSER_ACTION_OPEN)) {
253 if (parse_gpx(&_track, buffer, size, -1)) {
255 MACRO_BANNER_SHOW_INFO(_window, _("Track Opened"));
258 popup_error(_window, _("Error parsing GPX file."));
265 gboolean track_save(void)
267 GnomeVFSHandle *handle;
270 if (file_save(&_track_file_uri, &_track_file_uri, &handle)) {
271 if (write_gpx(&_track, handle)) {
272 MACRO_BANNER_SHOW_INFO(_window, _("Track Saved"));
275 popup_error(_window, _("Error writing GPX file."));
277 gnome_vfs_close(handle);
283 * Add a text description at current point
286 void track_insert_mark_text(gchar *text)
288 MACRO_PATH_INCREMENT_WTAIL(_track);
289 _track.wtail->point = _track.tail;
290 _track.wtail->desc = text;
294 * Ask for a text description for the current point
298 gboolean track_insert_mark(void)
301 gchar tmp1[16], tmp2[16], *p_latlon;
305 GtkWidget *txt_scroll;
308 printf("%s()\n", __PRETTY_FUNCTION__);
310 dialog = gtk_dialog_new_with_buttons(_("Insert Mark"),
312 GTK_DIALOG_MODAL, GTK_STOCK_OK,
315 GTK_RESPONSE_REJECT, NULL);
317 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
318 table = gtk_table_new(2, 2, FALSE), TRUE, TRUE, 0);
320 gtk_table_attach(GTK_TABLE(table),
321 label = gtk_label_new(_("Lat, Lon")),
322 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
323 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
325 unit2latlon(_pos.unitx, _pos.unity, lat, lon);
326 lat_format(lat, tmp1);
327 lon_format(lon, tmp2);
328 p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
329 gtk_table_attach(GTK_TABLE(table),
330 label = gtk_label_new(p_latlon),
331 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
332 gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
335 gtk_table_attach(GTK_TABLE(table),
336 label = gtk_label_new(_("Description")),
337 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
338 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
340 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
341 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
343 gtk_table_attach(GTK_TABLE(table),
345 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
347 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
348 GTK_POLICY_AUTOMATIC,
349 GTK_POLICY_AUTOMATIC);
351 txt_desc = gtk_text_view_new();
352 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
354 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
355 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 450, 80);
357 gtk_widget_show_all(dialog);
359 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
361 GtkTextIter ti1, ti2;
363 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
364 gtk_text_buffer_get_iter_at_offset(tbuf, &ti1, 0);
365 gtk_text_buffer_get_end_iter(tbuf, &ti2);
367 if (gtk_text_buffer_get_char_count(tbuf)>0) {
368 track_insert_mark_text(gtk_text_buffer_get_text(tbuf, &ti1, &ti2, TRUE));
370 popup_error(dialog, _("Please provide a description for the mark."));
375 MACRO_QUEUE_DRAW_AREA();
378 gtk_widget_destroy(dialog);